]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Satisfy some PMD requirements.
authorrkv <rkv@opencascade.com>
Tue, 19 Mar 2013 08:57:33 +0000 (08:57 +0000)
committerrkv <rkv@opencascade.com>
Tue, 19 Mar 2013 08:57:33 +0000 (08:57 +0000)
Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StudyService.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java

index eccbccca111591befb16658dc819c839a7f5deb6..2d2a2dbf091ccec2cbfa9890cdb1964ac986700e 100644 (file)
@@ -72,6 +72,10 @@ public class SearchServiceImpl implements SearchService {
         */
        public final static Logger LOG = Logger
                        .getLogger(org.splat.service.SearchServiceImpl.class);
+       /**
+        * "title" property name.
+        */
+       private final static String PROP_TITLE = "title";
 
        /**
         * Injected repository service.
@@ -185,7 +189,7 @@ public class SearchServiceImpl implements SearchService {
                // Group by study
                query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
                // Creation of the sort criteria
-               query.addOrder(Order.asc("title"));
+               query.addOrder(Order.asc(PROP_TITLE));
 
                if (LOG.isInfoEnabled()) {
                        LOG.info("Searching knowledge elements: \"" + query.toString());
@@ -226,7 +230,7 @@ public class SearchServiceImpl implements SearchService {
 
                        String[] word = title.split(" ");
                        for (int j = 0; j < word.length; j++) {
-                               critext.add(Restrictions.like("title", "%" + word[j] + "%"));
+                               critext.add(Restrictions.like(PROP_TITLE, "%" + word[j] + "%"));
                        }
                        topJunction.add(critext);
                }
@@ -272,7 +276,7 @@ public class SearchServiceImpl implements SearchService {
                // Group by study
                query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
                // Creation of the sort criteria
-               query.addOrder(Order.asc("title"));
+               query.addOrder(Order.asc(PROP_TITLE));
 
                if (LOG.isInfoEnabled()) {
                        LOG.info("Searching studies: \"" + query.toString());
@@ -578,7 +582,7 @@ public class SearchServiceImpl implements SearchService {
                        filter.add(new FilterClause(select, BooleanClause.Occur.SHOULD));
 
                        // Creation of the sort criteria
-                       Sort sort = new Sort(new SortField("title", SortField.STRING));
+                       Sort sort = new Sort(new SortField(PROP_TITLE, SortField.STRING));
 
                        // Search
                        TopFieldDocs found = searcher.search(fulquery, filter, hitsize,
index aed2ea4aad53386bfd4dd56e1fb52838b2892038..9d933d2b0780a5a1f72d61525118523191980943 100644 (file)
@@ -11,7 +11,6 @@ package org.splat.service;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.hibernate.criterion.Restrictions;
@@ -55,7 +54,6 @@ import org.splat.som.Step;
 import org.splat.util.BeanHelper;
 import org.springframework.transaction.annotation.Transactional;
 
-
 /**
  * Step service implementation.
  * 
@@ -126,8 +124,7 @@ public class StepServiceImpl implements StepService {
         * Injected user DAO.
         */
        private UserDAO _userDAO;
-       
-       
+
        /**
         * {@inheritDoc}
         * 
@@ -190,20 +187,10 @@ public class StepServiceImpl implements StepService {
                } else {
                        scenarii = aStep.getOwnerStudy().getScenarii();
                }
-//             try {
-                       for (int i = 0; i < scenarii.length; i++) {
-                               Scenario scene = scenarii[i];
-                               List<KnowledgeElement> knelm = scene.getAllKnowledgeElements();
-                               for (Iterator<KnowledgeElement> j = knelm.iterator(); j
-                                               .hasNext();) {
-                                       KnowledgeElement kelm = j.next();
-//                                     getIndexService().update(kelm);
-                               }
-                               updateScenarioIndex(scene);
-                       }
-//             } catch (Exception error) {
-//                     LOG.error("Unable to re-index Knowledge Elements, reason:", error);
-//             }
+               for (int i = 0; i < scenarii.length; i++) {
+                       Scenario scene = scenarii[i];
+                       updateScenarioIndex(scene);
+               }
        }
 
        /**
@@ -211,22 +198,16 @@ public class StepServiceImpl implements StepService {
         * 
         * @param scene
         *            the scenario
-        * @throws IOException
-        *             if can't update lucene index
         */
-       private void updateScenarioIndex(final Scenario scene) /*throws IOException*/ {
+       private void updateScenarioIndex(final Scenario scene) {
                if (scene.getUcase() == null) {
-                       for (Iterator<KnowledgeElement> i = scene.getKnowledgeElements()
-                                       .iterator(); i.hasNext();) {
-                               KnowledgeElement kelm = i.next();
-                               if (!kelm.getType().equals("usecase")) {
-                                       continue;
+                       for (KnowledgeElement kelm : scene.getKnowledgeElements()) {
+                               if (kelm.getType().equals("usecase")) {
+                                       scene.setUcase(kelm);
+                                       break;
                                }
-                               scene.setUcase(kelm);
-                               break;
                        }
                }
-//             getIndexService().update(scene.getUcase());
        }
 
        /**
@@ -407,9 +388,9 @@ public class StepServiceImpl implements StepService {
                }
 
                if (newFormat != null
-                               /*&& previous.getType().equals(
-                                               getProjectSettings().getDefaultDocumentType(
-                                                               aStep.getStep(), newFormat))*/) {
+               /*
+                * && previous.getType().equals( getProjectSettings().getDefaultDocumentType( aStep.getStep(), newFormat))
+                */) {
                        dprop.setFormat(newFormat);
                }
 
@@ -558,126 +539,142 @@ public class StepServiceImpl implements StepService {
                }
                return res;
        }
-       
+
        /**
         * {@inheritDoc}
-        *
+        * 
         * @see org.splat.service.StepService#addComment(org.splat.som.Step, org.splat.dal.bo.som.CommentAttribute)
         */
        @Override
        @Transactional
-       public void addStepComment(final StepCommentDTO comment) throws InvalidParameterException {
+       public void addStepComment(final StepCommentDTO comment)
+                       throws InvalidParameterException {
 
-               if(comment.getId()!= null) {
-                       throw new InvalidParameterException("id", String.valueOf(comment.getId()));
+               if (comment.getId() != null) {
+                       throw new InvalidParameterException("id", String.valueOf(comment
+                                       .getId()));
                }
                User user = getUserDAO().get(comment.getUserId());
                if (user == null) {
-                       throw new InvalidParameterException("userId", String.valueOf(comment.getUserId()));
+                       throw new InvalidParameterException("userId", String
+                                       .valueOf(comment.getUserId()));
                }
-               ProjectElement projectElement = getProjectElementDAO().get(comment.getProjectElementId());
-               if (projectElement==null) {
-                       throw new InvalidParameterException("projectElementId", comment.getProjectElementId().toString());
+               ProjectElement projectElement = getProjectElementDAO().get(
+                               comment.getProjectElementId());
+               if (projectElement == null) {
+                       throw new InvalidParameterException("projectElementId", comment
+                                       .getProjectElementId().toString());
                }
-               if(comment.getStep() == null || comment.getStep()<0) {
-                       throw new InvalidParameterException("step", String.valueOf(comment.getStep()));
+               if (comment.getStep() == null || comment.getStep() < 0) {
+                       throw new InvalidParameterException("step", String.valueOf(comment
+                                       .getStep()));
                }
-               if(comment.getDate() == null) {
-                       throw new InvalidParameterException("date", String.valueOf(comment.getDate()));
+               if (comment.getDate() == null) {
+                       throw new InvalidParameterException("date", String.valueOf(comment
+                                       .getDate()));
                }
-               if(comment.getTitle() == null) {
-                       throw new InvalidParameterException("title", String.valueOf(comment.getTitle()));
+               if (comment.getTitle() == null) {
+                       throw new InvalidParameterException("title", String.valueOf(comment
+                                       .getTitle()));
                }
 
                StepCommentAttribute newComment = new StepCommentAttribute(
-                               projectElement,
-                               comment.getText(),
-                               comment.getDate(),
-                               comment.getStep(),
-                               user,
-                               comment.getTitle()
-                               );
-
-               Long resultKey=getStepCommentAttributeDAO().create(newComment);
+                               projectElement, comment.getText(), comment.getDate(), comment
+                                               .getStep(), user, comment.getTitle());
+
+               Long resultKey = getStepCommentAttributeDAO().create(newComment);
                comment.setId(resultKey);
        }
 
        /**
         * {@inheritDoc}
+        * 
         * @see org.splat.service.StepService#getStepComments(org.splat.som.Step)
         */
        @Override
        @Transactional(readOnly = true)
-       public List<StepCommentDTO> getStepComments(final Step step) throws InvalidParameterException {
+       public List<StepCommentDTO> getStepComments(final Step step)
+                       throws InvalidParameterException {
                ProjectElement owner = _projectElementDAO.get(step.getOwner().getRid());
-               if(owner == null) {
-                       throw new InvalidParameterException("step owner id",
-                                       Long.valueOf(step.getOwner().getRid()).toString());
+               if (owner == null) {
+                       throw new InvalidParameterException("step owner id", Long.valueOf(
+                                       step.getOwner().getRid()).toString());
                }
-               List<StepCommentAttribute> comments = _stepCommentAttributeDAO.getFilteredList(
-                               Restrictions.and(
-                                               Restrictions.eq("step", Integer.valueOf(step.getNumber())),
-                                               Restrictions.eq("owner", owner)));
+               List<StepCommentAttribute> comments = _stepCommentAttributeDAO
+                               .getFilteredList(Restrictions.and(Restrictions.eq("step",
+                                               Integer.valueOf(step.getNumber())), Restrictions.eq(
+                                               "owner", owner)));
                List<StepCommentDTO> commentDTOs = new ArrayList<StepCommentDTO>();
-               for(StepCommentAttribute comment : comments) {
-                        StepCommentDTO stepCommentDTO = BeanHelper.copyBean(comment, StepCommentDTO.class);
-                        stepCommentDTO.setText(comment.getValue());
-                        stepCommentDTO.setId(Long.valueOf(comment.getRid()));
-                        commentDTOs.add(stepCommentDTO);
+               for (StepCommentAttribute comment : comments) {
+                       StepCommentDTO stepCommentDTO = BeanHelper.copyBean(comment,
+                                       StepCommentDTO.class);
+                       stepCommentDTO.setText(comment.getValue());
+                       stepCommentDTO.setId(Long.valueOf(comment.getRid()));
+                       commentDTOs.add(stepCommentDTO);
                }
                return commentDTOs;
        }
 
        /**
         * {@inheritDoc}
+        * 
         * @see org.splat.service.StepService#removeStepComment(long)
         */
        @Override
        @Transactional
-       public void removeStepComment(final long commentId) throws InvalidParameterException {
-               StepCommentAttribute stepComment = _stepCommentAttributeDAO.get(Long.valueOf(commentId));
-               if(stepComment == null) {
-                       throw new InvalidParameterException("commentId",String.valueOf(commentId));
+       public void removeStepComment(final long commentId)
+                       throws InvalidParameterException {
+               StepCommentAttribute stepComment = _stepCommentAttributeDAO.get(Long
+                               .valueOf(commentId));
+               if (stepComment == null) {
+                       throw new InvalidParameterException("commentId", String
+                                       .valueOf(commentId));
                }
                _stepCommentAttributeDAO.delete(stepComment);
        }
 
-       /** 
+       /**
         * {@inheritDoc}
+        * 
         * @see org.splat.service.StepService#editStepComment(long, java.lang.String, java.lang.String)
         */
        @Override
        @Transactional
-       public void editStepComment(final long commentId, final String newValue, final String newTitle)
-                       throws InvalidParameterException {
-               StepCommentAttribute comment = _stepCommentAttributeDAO.get(Long.valueOf(commentId));
-               if(comment == null) {
-                       throw new InvalidParameterException("commentId",String.valueOf(commentId));
+       public void editStepComment(final long commentId, final String newValue,
+                       final String newTitle) throws InvalidParameterException {
+               StepCommentAttribute comment = _stepCommentAttributeDAO.get(Long
+                               .valueOf(commentId));
+               if (comment == null) {
+                       throw new InvalidParameterException("commentId", String
+                                       .valueOf(commentId));
                }
-               if(newTitle != null) {
+               if (newTitle != null) {
                        comment.setTitle(newTitle);
                }
-               if(newValue != null) {
+               if (newValue != null) {
                        comment.setValue(newValue);
                }
                _stepCommentAttributeDAO.update(comment);
        }
 
-       /** 
+       /**
         * {@inheritDoc}
+        * 
         * @see org.splat.service.StepService#isCommentMadeByUser(long, long)
         */
        @Override
        @Transactional(readOnly = true)
        public boolean isCommentMadeByUser(final long commentId, final long userId)
                        throws InvalidParameterException {
-               StepCommentAttribute comment = _stepCommentAttributeDAO.get(Long.valueOf(commentId));
-               if(comment == null) {
-                       throw new InvalidParameterException("commentId", String.valueOf(commentId));
+               StepCommentAttribute comment = _stepCommentAttributeDAO.get(Long
+                               .valueOf(commentId));
+               if (comment == null) {
+                       throw new InvalidParameterException("commentId", String
+                                       .valueOf(commentId));
                }
                return comment.getUser().getIndex() == userId;
        }
-       
+
        /**
         * Get the documentService.
         * 
@@ -861,7 +858,7 @@ public class StepServiceImpl implements StepService {
        private ProjectSettingsService getProjectSettings() {
                return _projectSettings;
        }
-       
+
        /**
         * Set project settings service.
         * 
@@ -872,9 +869,10 @@ public class StepServiceImpl implements StepService {
                        final ProjectSettingsService projectSettingsService) {
                _projectSettings = projectSettingsService;
        }
-       
+
        /**
         * Get the stepCommentAttributeDAO.
+        * 
         * @return the stepCommentAttributeDAO
         */
        public StepCommentAttributeDAO getStepCommentAttributeDAO() {
@@ -883,7 +881,9 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the stepCommentAttributeDAO.
-        * @param commentAttributeDAO the stepCommentAttributeDAO to set
+        * 
+        * @param commentAttributeDAO
+        *            the stepCommentAttributeDAO to set
         */
        public void setStepCommentAttributeDAO(
                        final StepCommentAttributeDAO commentAttributeDAO) {
@@ -892,14 +892,18 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the userDAO.
+        * 
         * @return the userDAO
         */
        public UserDAO getUserDAO() {
                return _userDAO;
        }
+
        /**
         * Set the userDAO.
-        * @param userDAO the userDAO to set
+        * 
+        * @param userDAO
+        *            the userDAO to set
         */
        public void setUserDAO(final UserDAO userDAO) {
                _userDAO = userDAO;
index 347a0db89ff01f0803e66f352560fcf70affecda..3e644a7d4283482f38a1c25ee579aefc79a574e4 100644 (file)
@@ -9,7 +9,6 @@
 
 package org.splat.service;
 
-import java.util.Date;
 import java.util.List;
 
 import org.splat.dal.bo.kernel.User;
index fa31d394a1fa8bc22954cbd1c6cedac4f908ec7e..5cd8631a3b3d80d1c697355d9158751c4ada02f0 100644 (file)
@@ -107,6 +107,10 @@ public class StudyServiceImpl implements StudyService {
         */
        public final static AppLogger LOG = AppLogger
                        .getLogger(StudyServiceImpl.class);
+       /**
+        * "studyId" parameter name.
+        */
+       public final static String PARAM_STUDY_ID = "studyId";
 
        /**
         * Injected index service.
@@ -1168,11 +1172,11 @@ public class StudyServiceImpl implements StudyService {
        public String getDescription(final Long studyId)
                        throws InvalidParameterException {
                if (studyId == null) {
-                       throw new InvalidParameterException("studyId", "null");
+                       throw new InvalidParameterException(PARAM_STUDY_ID, "null");
                }
                Study study = _studyDAO.get(studyId);
                if (study == null) {
-                       throw new InvalidParameterException("studyId", studyId.toString());
+                       throw new InvalidParameterException(PARAM_STUDY_ID, studyId.toString());
                }
                return study.getDescription();
        }
@@ -1187,11 +1191,11 @@ public class StudyServiceImpl implements StudyService {
        public void setDescription(final Long studyId, final String descriptionText)
                        throws InvalidParameterException {
                if (studyId == null) {
-                       throw new InvalidParameterException("studyId", "null");
+                       throw new InvalidParameterException(PARAM_STUDY_ID, "null");
                }
                Study study = _studyDAO.get(studyId);
                if (study == null) {
-                       throw new InvalidParameterException("studyId", studyId.toString());
+                       throw new InvalidParameterException(PARAM_STUDY_ID, studyId.toString());
                }
                study.setAttribute(new DescriptionAttribute(study, descriptionText));
        }
@@ -1206,12 +1210,12 @@ public class StudyServiceImpl implements StudyService {
        public boolean removeDescription(final Long studyId)
                        throws InvalidParameterException {
                if (studyId == null) {
-                       throw new InvalidParameterException("studyId", String
+                       throw new InvalidParameterException(PARAM_STUDY_ID, String
                                        .valueOf(studyId));
                }
                Study study = _studyDAO.get(studyId);
                if (study == null) {
-                       throw new InvalidParameterException("studyId", String
+                       throw new InvalidParameterException(PARAM_STUDY_ID, String
                                        .valueOf(studyId));
                }
                return study.removeAttribute(study