From: rkv Date: Wed, 5 Dec 2012 11:49:21 +0000 (+0000) Subject: Keep file format when versioning a document if the new format is appropriate for... X-Git-Tag: Root_Delivery1_2012_12_06~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9a75d4fd968e0113e9b41ca4e30c06a0e4e34b19;p=tools%2Fsiman.git Keep file format when versioning a document if the new format is appropriate for the document type. --- diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java index 1713dc2..aa9b6dd 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java @@ -300,6 +300,14 @@ public class Document extends Entity { } } } + + /** + * Get the format. + * @return the format + */ + public String getFormat() { + return format; + } } /** diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index f66ef9a..b230749 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -570,7 +570,7 @@ public class ScenarioServiceImpl implements ScenarioService { upfile.getName().lastIndexOf('.') + 1); // Create a new document or a new version of the document - dprop.setAuthor(aUser).setDate(aDate); + dprop.setAuthor(aUser).setDate(aDate).setFormat(fileFormat); Publication pub, newPub; if (doc.getId() > 0) { @@ -610,8 +610,7 @@ public class ScenarioServiceImpl implements ScenarioService { } docname += "_" + i; // The generated new document title - dprop.setDescription("Checked in").setName(docname).setFormat( - fileFormat); + dprop.setDescription("Checked in").setName(docname); newPub = getStepService().createDocument(step, dprop); // Remeber the new document diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 934b296..9c2458d 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -104,8 +104,9 @@ public class StepServiceImpl implements StepService { * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext.Properties) */ public SimulationContext addSimulationContext(final Step aStep, - final SimulationContext.Properties dprop) throws MissedPropertyException, - InvalidPropertyException, MultiplyDefinedException { + final SimulationContext.Properties dprop) + throws MissedPropertyException, InvalidPropertyException, + MultiplyDefinedException { SimulationContext context = new SimulationContext(dprop.setStep(aStep .getStep())); return addSimulationContext(aStep, context); @@ -169,8 +170,7 @@ public class StepServiceImpl implements StepService { updateScenarioIndex(scene); } } catch (Exception error) { - LOG.error("Unable to re-index Knowledge Elements, reason:", - error); + LOG.error("Unable to re-index Knowledge Elements, reason:", error); } } @@ -203,7 +203,8 @@ public class StepServiceImpl implements StepService { * @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext) */ @Transactional - public boolean removeSimulationContext(final Step aStep, final SimulationContext context) { + public boolean removeSimulationContext(final Step aStep, + final SimulationContext context) { SimulationContext torem = aStep .getSimulationContext(context.getIndex()); @@ -228,9 +229,9 @@ public class StepServiceImpl implements StepService { * @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties) */ @Transactional - public Publication createDocument(final Step aStep, final Document.Properties dprop) - throws MissedPropertyException, InvalidPropertyException, - MultiplyDefinedException, IOException { + public Publication createDocument(final Step aStep, + final Document.Properties dprop) throws MissedPropertyException, + InvalidPropertyException, MultiplyDefinedException, IOException { Document newdoc = new Document(dprop.setOwner(aStep.getOwner()) .setStep(aStep.getStep())); getDocumentService().generateDocumentId(newdoc, dprop); @@ -317,10 +318,10 @@ public class StepServiceImpl implements StepService { * @throws MismatchException * if the document is not applicable to the given study step */ - public Publication versionDocument(final Step aStep, final Publication base, - final String reason) throws MissedPropertyException, - InvalidPropertyException, MultiplyDefinedException, IOException, - MismatchException { + public Publication versionDocument(final Step aStep, + final Publication base, final String reason) + throws MissedPropertyException, InvalidPropertyException, + MultiplyDefinedException, IOException, MismatchException { return versionDocument(aStep, base, new Document.Properties() .setDescription(reason)); } @@ -347,17 +348,28 @@ public class StepServiceImpl implements StepService { * if the document is not applicable to the given study step */ @Transactional - public Publication versionDocument(final Step aStep, final Publication base, - final Document.Properties dprop) throws MissedPropertyException, - InvalidPropertyException, MultiplyDefinedException, IOException, - MismatchException { + public Publication versionDocument(final Step aStep, + final Publication base, final Document.Properties dprop) + throws MissedPropertyException, InvalidPropertyException, + MultiplyDefinedException, IOException, MismatchException { Document previous = base.value(); - dprop.setDocument(previous, getProjectSettings().getStep(base.getStep().getNumber())); // Initializes the Step property + // RKV: Keep the new file format if it is related to the same document type on this step. + String newFormat = dprop.getFormat(); + + dprop.setDocument(previous, getProjectSettings().getStep( + base.getStep().getNumber())); // Initializes the Step property if (dprop.getStep().getNumber() != aStep.getNumber()) { throw new MismatchException(); } + if (newFormat != null + && previous.getTitle().equals( + getProjectSettings().getDefaultDocumentType( + aStep.getStep(), newFormat))) { + dprop.setFormat(newFormat); + } + if (dprop.getAuthor() == null) { dprop.setAuthor(previous.getAuthor()); } @@ -374,24 +386,16 @@ public class StepServiceImpl implements StepService { // Versioning VersionsRelation aRel; aRel = new VersionsRelation(newdoc, previous, summary); -// getVersionsRelationDAO().create(aRel); + // getVersionsRelationDAO().create(aRel); newdoc.addRelation(aRel); - + // Update of usedby relations, if exist -/* RKV: Consider the new version as not used by old dependent documents. - * So these documents must be marked as outdated then. - List relist = previous.getRelations(UsedByRelation.class); - Study scope = aStep.getOwnerStudy(); - for (Iterator i = relist.iterator(); i.hasNext();) { - UsedByRelation relation = (UsedByRelation) i.next(); - Document relatedoc = relation.getTo(); - if (scope.shares(relatedoc)) { - relatedoc.addRelation(new UsesRelation(relatedoc, newdoc)); - } else { - relation.moveTo(newdoc); - } - } -*/ + /* + * RKV: Consider the new version as not used by old dependent documents. So these documents must be marked as outdated then. List + * relist = previous.getRelations(UsedByRelation.class); Study scope = aStep.getOwnerStudy(); for (Iterator i = + * relist.iterator(); i.hasNext();) { UsedByRelation relation = (UsedByRelation) i.next(); Document relatedoc = relation.getTo(); if + * (scope.shares(relatedoc)) { relatedoc.addRelation(new UsesRelation(relatedoc, newdoc)); } else { relation.moveTo(newdoc); } } + */ return new Publication(newdoc, aStep.getOwner()); } @@ -638,12 +642,14 @@ public class StepServiceImpl implements StepService { * @param documentTypeService * the documentTypeService to set */ - public void setDocumentTypeService(final DocumentTypeService documentTypeService) { + public void setDocumentTypeService( + final DocumentTypeService documentTypeService) { _documentTypeService = documentTypeService; } /** * Get the versionsRelationDAO. + * * @return the versionsRelationDAO */ public VersionsRelationDAO getVersionsRelationDAO() { @@ -652,9 +658,12 @@ public class StepServiceImpl implements StepService { /** * Set the versionsRelationDAO. - * @param versionsRelationDAO the versionsRelationDAO to set + * + * @param versionsRelationDAO + * the versionsRelationDAO to set */ - public void setVersionsRelationDAO(final VersionsRelationDAO versionsRelationDAO) { + public void setVersionsRelationDAO( + final VersionsRelationDAO versionsRelationDAO) { _versionsRelationDAO = versionsRelationDAO; }