import java.util.Iterator;
import java.util.List;
+import org.hibernate.criterion.Restrictions;
import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.File;
import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.ProjectElement;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.StepCommentAttribute;
import org.splat.dal.bo.som.UsedByRelation;
import org.splat.dal.bo.som.UsesRelation;
import org.splat.dal.bo.som.VersionsRelation;
import org.splat.dal.dao.kernel.RelationDAO;
+import org.splat.dal.dao.kernel.UserDAO;
import org.splat.dal.dao.som.DocumentDAO;
import org.splat.dal.dao.som.FileDAO;
import org.splat.dal.dao.som.ProjectElementDAO;
import org.splat.dal.dao.som.PublicationDAO;
import org.splat.dal.dao.som.SimulationContextDAO;
+import org.splat.dal.dao.som.StepCommentAttributeDAO;
import org.splat.dal.dao.som.VersionsRelationDAO;
import org.splat.exception.DocumentIsUsedException;
+import org.splat.exception.InvalidParameterException;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MismatchException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
import org.splat.kernel.NotApplicableException;
import org.splat.log.AppLogger;
+import org.splat.service.dto.StepCommentDTO;
import org.splat.service.technical.IndexService;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.som.Revision;
import org.splat.som.Step;
+import org.splat.util.BeanHelper;
import org.springframework.transaction.annotation.Transactional;
+
/**
* Step service implementation.
- *
+ *
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public class StepServiceImpl implements StepService {
*/
private PublicationDAO _publicationDAO;
+ /**
+ * Injected text attribute DAO.
+ */
+ private StepCommentAttributeDAO _stepCommentAttributeDAO;
+
+ /**
+ * Injected user DAO.
+ */
+ private UserDAO _userDAO;
+
+
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext.Properties)
*/
+ @Override
public SimulationContext addSimulationContext(final Step aStep,
final SimulationContext.Properties dprop)
throws MissedPropertyException, InvalidPropertyException,
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
*/
+ @Override
@Transactional
public SimulationContext addSimulationContext(final Step aStep,
final SimulationContext context) {
/**
* Update lucene index of knowledge elements of a scenario or a study which the given step is related to.
- *
+ *
* @param aStep
* the step (activity)
*/
/**
* Update lucene index for knowledge elements of the scenario.
- *
+ *
* @param scene
* the scenario
* @throws IOException
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
*/
+ @Override
@Transactional
public boolean removeSimulationContext(final Step aStep,
final SimulationContext context) {
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
*/
+ @Override
@Transactional
public Publication createDocument(final Step aStep,
final Document.Properties dprop) throws MissedPropertyException,
/**
* {@inheritDoc}
- *
+ *
* @see org.splat.service.StepService#assignDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
*/
+ @Override
public Publication assignDocument(final Step aStep,
final Document.Properties dprop) throws MissedPropertyException,
InvalidPropertyException, NotApplicableException {
/**
* Create a new version of a document in the given study step.
- *
+ *
* @param aStep
* the study step
* @param base
/**
* Create a new version of a document in the given study step.
- *
+ *
* @param aStep
* the study step
* @param base
/**
* Create a new version of a document in the given study step.
- *
+ *
* @param aStep
* the study step
* @param base
* @throws MismatchException
* if the document is not applicable to the given study step
*/
+ @Override
@Transactional
public Publication versionDocument(final Step aStep,
final Publication base, final Document.Properties dprop)
/**
* Get document types which are applicable for the given study step (activity).
- *
+ *
* @param aStep
* the study step
* @return the list of document types
*/
+ @Override
public List<DocumentType> getValidDocumentTypes(final Step aStep) {
return getDocumentTypeService().selectTypesOf(aStep.getStep());
}
/**
* Add a document publication to the given step.
- *
+ *
* @param aStep
* the target study step
* @param newdoc
* the document publication to add
* @return true if publication succeeded
*/
+ @Override
public boolean add(final Step aStep, final Publication newdoc) {
boolean res = aStep.getOwner().add(newdoc); // Updates the study in memory
if (res) {
/**
* Remove a document publication from the given step.
- *
+ *
* @param aStep
* the study step
* @param oldoc
* the document publication to remove
* @return true if removing of the publication succeeded
*/
+ @Override
public boolean remove(final Step aStep, final Publication oldoc) {
aStep.getDocuments().remove(oldoc); // Updates this step
aStep.getOwner().remove(oldoc); // remove from the parent project element
* @throws DocumentIsUsedException
* if the document is used by other documents
*/
+ @Override
@Transactional
public boolean removeDocument(final Step aStep, final long docId)
throws DocumentIsUsedException {
}
}
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 {
+
+ 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()));
+ }
+ 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.getDate() == null) {
+ throw new InvalidParameterException("date", String.valueOf(comment.getDate()));
+ }
+ 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);
+ 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 {
+ ProjectElement owner = _projectElementDAO.get(step.getOwner().getRid());
+ 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<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);
+ }
+ 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));
+ }
+ _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));
+ }
+ if(newTitle != null) {
+ comment.setTitle(newTitle);
+ }
+ 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));
+ }
+ return comment.getUser().getIndex() == userId;
+ }
+
/**
* Get the documentService.
- *
+ *
* @return the documentService
*/
public DocumentService getDocumentService() {
/**
* Set the documentService.
- *
+ *
* @param documentService
* the documentService to set
*/
/**
* Get the simulationContextService.
- *
+ *
* @return the simulationContextService
*/
public SimulationContextService getSimulationContextService() {
/**
* Set the simulationContextService.
- *
+ *
* @param simulationContextService
* the simulationContextService to set
*/
/**
* Get the documentDAO.
- *
+ *
* @return the documentDAO
*/
public DocumentDAO getDocumentDAO() {
/**
* Set the documentDAO.
- *
+ *
* @param documentDAO
* the documentDAO to set
*/
/**
* Get the simulationContextDAO.
- *
+ *
* @return the simulationContextDAO
*/
public SimulationContextDAO getSimulationContextDAO() {
/**
* Set the simulationContextDAO.
- *
+ *
* @param simulationContextDAO
* the simulationContextDAO to set
*/
/**
* Get the projectElementDAO.
- *
+ *
* @return the projectElementDAO
*/
public ProjectElementDAO getProjectElementDAO() {
/**
* Set the projectElementDAO.
- *
+ *
* @param projectElementDAO
* the projectElementDAO to set
*/
/**
* Get the indexService.
- *
+ *
* @return the indexService
*/
public IndexService getIndexService() {
/**
* Set the indexService.
- *
+ *
* @param indexService
* the indexService to set
*/
/**
* Get the fileDAO.
- *
+ *
* @return the fileDAO
*/
public FileDAO getFileDAO() {
/**
* Set the fileDAO.
- *
+ *
* @param fileDAO
* the fileDAO to set
*/
/**
* Get the documentTypeService.
- *
+ *
* @return the documentTypeService
*/
public DocumentTypeService getDocumentTypeService() {
/**
* Set the documentTypeService.
- *
+ *
* @param documentTypeService
* the documentTypeService to set
*/
/**
* Get the versionsRelationDAO.
- *
+ *
* @return the versionsRelationDAO
*/
public VersionsRelationDAO getVersionsRelationDAO() {
/**
* Set the versionsRelationDAO.
- *
+ *
* @param versionsRelationDAO
* the versionsRelationDAO to set
*/
/**
* Get project settings.
- *
+ *
* @return Project settings service
*/
private ProjectSettingsService getProjectSettings() {
/**
* Set project settings service.
- *
+ *
* @param projectSettingsService
* project settings service
*/
_projectSettings = projectSettingsService;
}
+ /**
+ * Get the stepCommentAttributeDAO.
+ * @return the stepCommentAttributeDAO
+ */
+ public StepCommentAttributeDAO getStepCommentAttributeDAO() {
+ return _stepCommentAttributeDAO;
+ }
+
+ /**
+ * Set the stepCommentAttributeDAO.
+ * @param commentAttributeDAO the stepCommentAttributeDAO to set
+ */
+ public void setStepCommentAttributeDAO(
+ final StepCommentAttributeDAO commentAttributeDAO) {
+ _stepCommentAttributeDAO = commentAttributeDAO;
+ }
+
+ /**
+ * Get the userDAO.
+ * @return the userDAO
+ */
+ public UserDAO getUserDAO() {
+ return _userDAO;
+ }
+ /**
+ * Set the userDAO.
+ * @param userDAO the userDAO to set
+ */
+ public void setUserDAO(final UserDAO userDAO) {
+ _userDAO = userDAO;
+ }
+
/**
* Get the publicationDAO.
*