/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
import java.util.Iterator;
import java.util.List;
-import org.hibernate.Session;
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.ProgressState;
import org.splat.dal.bo.som.Timestamp;
import org.splat.dal.bo.som.ValidationCycle;
import org.splat.dal.bo.som.ValidationStep;
-import org.splat.dal.dao.som.Database;
+import org.splat.dal.dao.som.ProjectElementDAO;
+import org.splat.dal.dao.som.PublicationDAO;
+import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.NotApplicableException;
import org.splat.manox.Reader;
import org.splat.manox.Toolbox;
import org.splat.som.Revision;
import org.splat.som.Step;
+import org.springframework.transaction.annotation.Transactional;
/**
* Publication service implementation.
*/
private StudyService _studyService;
/**
- * Injected study service.
+ * Injected step service.
*/
private StepService _stepService;
/**
- * Injected study service.
+ * Injected document service.
*/
- private DocumentTypeService _documentTypeService;
+ private DocumentService _documentService;
/**
- * Injected study service.
+ * Injected project element service.
*/
private ProjectElementService _projectElementService;
/**
* Injected simulation context service.
*/
private SimulationContextService _simulationContextService;
+ /**
+ * Injected publication DAO.
+ */
+ private PublicationDAO _publicationDAO;
+ /**
+ * Injected project element DAO.
+ */
+ private ProjectElementDAO _projectElementDAO;
/**
* {@inheritDoc}
* @see org.splat.service.PublicationService#approve(org.splat.dal.bo.som.Publication, java.util.Date)
*/
public Timestamp approve(Publication aPublication, Date adate) {
- // -------------------------------------
if (aPublication.isOutdated())
return null;
else if (aPublication.value().getProgressState() != ProgressState.inCHECK)
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- ValidationCycle cycle = owner.getValidationCycleOf(type);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(owner,
+ type);
User approver = cycle.getActor(ValidationStep.APPROVAL);
Timestamp stamp = new Timestamp(ValidationStep.APPROVAL, aPublication
.value(), approver, adate);
- if (!aPublication.value().promote(stamp))
+ if (!getDocumentService().promote(aPublication.value(), stamp))
return null;
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() == ProgressState.inCHECK)
getStudyService().promote(owner);
return stamp; // Hoping that promotion of the study succeeded
* @see org.splat.service.PublicationService#demote(org.splat.dal.bo.som.Publication)
*/
public boolean demote(Publication aPublication) {
- // ------------------------
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
if (aPublication.value().getProgressState() == ProgressState.inCHECK) {
- ValidationCycle cycle = owner.getValidationCycleOf(type);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ owner, type);
if (cycle.enables(ValidationStep.REVIEW)) {
- if (!aPublication.value().demote())
+ if (!getDocumentService().demote(aPublication.value()))
return false;
} else {
- if (!aPublication.value().demote())
+ if (!getDocumentService().demote(aPublication.value()))
return false;
- aPublication.value().demote();
+ getDocumentService().demote(aPublication.value());
}
} else if (aPublication.value().getProgressState() == ProgressState.inDRAFT) {
- if (!aPublication.value().demote())
+ if (!getDocumentService().demote(aPublication.value()))
return false;
} else {
return false;
}
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() != ProgressState.inWORK)
getStudyService().demote(owner);
return true;
* @see org.splat.service.PublicationService#invalidate(org.splat.dal.bo.som.Publication)
*/
public boolean invalidate(Publication aPublication) {
- // ----------------------------
if (aPublication.value().getProgressState() != ProgressState.inCHECK)
return false;
- if (!aPublication.value().demote()) // Removes the reviewer if this document is In-Check
+ if (!getDocumentService().demote(aPublication.value())) // Removes the reviewer if this document is In-Check
return false;
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() == ProgressState.inCHECK)
getStudyService().demote(owner);
return true;
else {
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- ValidationCycle cycle = owner.getValidationCycleOf(type);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ owner, type);
User promoter = cycle.getActor(ValidationStep.PROMOTION);
if (promoter == null)
promoter = getInvolvedStep(aPublication).getActor();
Timestamp stamp = new Timestamp(ValidationStep.PROMOTION,
aPublication.value(), promoter, pdate);
- if (!aPublication.value().promote(stamp)) // Promotion to being reviewed
+ if (!getDocumentService().promote(aPublication.value(), stamp)) // Promotion to being reviewed
return null;
if (!cycle.enables(ValidationStep.REVIEW)) {
- aPublication.value().promote(null);
+ getDocumentService().promote(aPublication.value(), null);
}
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() == ProgressState.inWORK)
getStudyService().promote(owner);
return stamp; // Hoping that promotion of the study succeeded
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- ValidationCycle cycle = owner.getValidationCycleOf(type);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(owner,
+ type);
User reviewer = cycle.getActor(ValidationStep.REVIEW);
Timestamp stamp = new Timestamp(ValidationStep.REVIEW, aPublication
.value(), reviewer, rdate);
- if (!aPublication.value().promote(stamp))
+ if (!getDocumentService().promote(aPublication.value(), stamp))
return null;
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() == ProgressState.inDRAFT)
getStudyService().promote(owner);
return stamp; // Hoping that promotion of the study succeeded
* @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.som.Revision)
* @deprecated
*/
+ @Transactional
public void saveAs(Publication aPublication, Revision newvers)
throws FileNotFoundException, NotApplicableException {
- // -------------------------------------
if (aPublication.value().isUndefined())
throw new NotApplicableException(
"Cannot save a Publication object refering an undefined Document");
if (!aPublication.value().getSourceFile().exists())
throw new FileNotFoundException();
- Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
- aPublication.value().updateAs(newvers); // May change the branch name of given revision
+ getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
+ getDocumentService().updateAs(aPublication.value(), newvers); // May change the branch name of given revision
updateOwner(aPublication);
}
*
* @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProgressState)
*/
+ @Transactional
public void saveAs(Publication aPublication, ProgressState state)
throws FileNotFoundException, NotApplicableException {
- // ----------------------------------------
if (aPublication.value().isUndefined())
throw new NotApplicableException(
"Cannot save a Publication object refering an undefined Document");
throw new FileNotFoundException();
if (state == ProgressState.inWORK || state == ProgressState.EXTERN) {
- Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
+ getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
// hascode
- aPublication.value().updateAs(state);
+ getDocumentService().updateAs(aPublication.value(), state);
} else {
DocumentType mytype = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- ValidationCycle cycle = owner.getValidationCycleOf(mytype);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ owner, mytype);
boolean review = cycle.enables(ValidationStep.REVIEW);
if (!(state == ProgressState.inDRAFT && review)
&& !(state == ProgressState.inCHECK && !review)) {
"Cannot save a result document in " + state.toString()
+ " state");
}
- Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
+ getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
// hascode
- aPublication.value().updateAs(ProgressState.inWORK);
+ getDocumentService().updateAs(aPublication.value(),
+ ProgressState.inWORK);
promote(aPublication, aPublication.value()
.getLastModificationDate()); // Promotes to the appropriate state in accordance to the validation cycle
* @param aPublication
* the document publication
*/
+ @Transactional
private void updateOwner(Publication aPublication) {
- Session session = Database.getSession();
Step step = getInvolvedStep(aPublication);
// Update of involved step
Document previous = aPublication.value().getPreviousVersion();
if (previous != null) {
Publication oldoc = step.getDocument(previous.getIndex());
- boolean done = step.remove(oldoc); // Decrements the configuration tag count of document
+ boolean done = getStepService().remove(step, oldoc); // Decrements the configuration tag count of document
if (done)
- session.delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object
+ getPublicationDAO().delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object
}
- step.add(aPublication); // Increments the configuration tag count of document
+ getStepService().add(step, aPublication); // Increments the configuration tag count of document
// Import the document properties and update of the study
forwardProperties(aPublication, aPublication.value().getSourceFile()
.asFile(), step);
- session.update(aPublication.getOwner());
+ getProjectElementDAO().update(aPublication.getOwner());
}
/**
*/
private void forwardProperties(Publication aPublication, java.io.File from,
Step to) {
- // -----------------------------------------------------------
Reader tool = Toolbox.getReader(from);
if (tool == null)
return; // No properties extractor available for this type of document
return aPublication.getStep();
}
+ /**
+ * Create "Converts" relation for the given document publication and format.
+ *
+ * @param aPublication
+ * the document publication
+ * @param format
+ * the format
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Publication aPublication, String format) {
+ return getDocumentService().attach(aPublication.value(), format);
+ }
+
+ /**
+ * Create "Converts" relation for the given document publication, format and description.
+ *
+ * @param aPublication
+ * the document publication
+ * @param format
+ * the format
+ * @param description
+ * the description of the relation
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Publication aPublication, String format,
+ String description) {
+ return getDocumentService().attach(aPublication.value(), format,
+ description);
+ }
+
+ /**
+ * Rename the published document.
+ *
+ * @param aPublication
+ * the publication of the document
+ * @param title
+ * the new document title
+ * @throws InvalidPropertyException
+ * if the new title is empty
+ */
+ public void rename(Publication aPublication, String title)
+ throws InvalidPropertyException {
+ getDocumentService().rename(aPublication.value(), title);
+ }
+
/**
* Get the projectElementService.
*
/**
* Get the studyService.
+ *
* @return the studyService
*/
public StudyService getStudyService() {
/**
* Set the studyService.
- * @param studyService the studyService to set
+ *
+ * @param studyService
+ * the studyService to set
*/
public void setStudyService(StudyService studyService) {
_studyService = studyService;
/**
* Get the stepService.
+ *
* @return the stepService
*/
public StepService getStepService() {
/**
* Set the stepService.
- * @param stepService the stepService to set
+ *
+ * @param stepService
+ * the stepService to set
*/
public void setStepService(StepService stepService) {
_stepService = stepService;
}
/**
- * Get the documentTypeService.
- * @return the documentTypeService
+ * Get the documentService.
+ *
+ * @return the documentService
+ */
+ public DocumentService getDocumentService() {
+ return _documentService;
+ }
+
+ /**
+ * Set the documentService.
+ *
+ * @param documentService
+ * the documentService to set
+ */
+ public void setDocumentService(DocumentService documentService) {
+ _documentService = documentService;
+ }
+
+ /**
+ * Get the publicationDAO.
+ *
+ * @return the publicationDAO
+ */
+ public PublicationDAO getPublicationDAO() {
+ return _publicationDAO;
+ }
+
+ /**
+ * Set the publicationDAO.
+ *
+ * @param publicationDAO
+ * the publicationDAO to set
*/
- public DocumentTypeService getDocumentTypeService() {
- return _documentTypeService;
+ public void setPublicationDAO(PublicationDAO publicationDAO) {
+ _publicationDAO = publicationDAO;
}
/**
- * Set the documentTypeService.
- * @param documentTypeService the documentTypeService to set
+ * Get the projectElementDAO.
+ *
+ * @return the projectElementDAO
+ */
+ public ProjectElementDAO getProjectElementDAO() {
+ return _projectElementDAO;
+ }
+
+ /**
+ * Set the projectElementDAO.
+ *
+ * @param projectElementDAO
+ * the projectElementDAO to set
*/
- public void setDocumentTypeService(DocumentTypeService documentTypeService) {
- _documentTypeService = documentTypeService;
+ public void setProjectElementDAO(ProjectElementDAO projectElementDAO) {
+ _projectElementDAO = projectElementDAO;
}
}