From: rkv Date: Fri, 23 Nov 2012 06:27:17 +0000 (+0000) Subject: The checkin from SALOME operation is updated (ScenarioService.checkin()). Versioning... X-Git-Tag: Root_Delivery1_2012_12_06~50 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f14d0cbc29a7347dc197650114562cceffe504ca;p=tools%2Fsiman.git The checkin from SALOME operation is updated (ScenarioService.checkin()). Versioning operation is fixed. Unit tests for checkin and project settings loading are updated. Project settings loading is fixed for the case of empty initial database - loading of default document types is fixed. Document type name is checked now for duplication when a document type is created. --- diff --git a/Workspace/Siman-Common/proj_settings_testng.xml b/Workspace/Siman-Common/proj_settings_testng.xml new file mode 100644 index 0000000..e8f7046 --- /dev/null +++ b/Workspace/Siman-Common/proj_settings_testng.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + 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 bb5d140..1713dc2 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 @@ -25,7 +25,7 @@ import org.splat.som.Revision; import org.splat.som.Step; /** - * Document persistent class. + * Document persistent class. */ public class Document extends Entity { @@ -50,7 +50,7 @@ public class Document extends Entity { // ============================================================================================================================== /** - * Fields initialization class. + * Fields initialization class. */ public static class Properties extends Persistent.Properties { // ------------------------------------------------------------ @@ -143,6 +143,7 @@ public class Document extends Entity { /** * Get the date. + * * @return the date */ public Date getDate() { @@ -158,7 +159,17 @@ public class Document extends Entity { return this; } - public Properties setDocument(final Document base, final ProjectSettingsService.Step aStep) { + /** + * Copy base properties from the given original document for versioning. + * + * @param base + * the original document + * @param aStep + * study step + * @return document properties + */ + public Properties setDocument(final Document base, + final ProjectSettingsService.Step aStep) { type = base.type; step = aStep; name = base.name; @@ -199,14 +210,15 @@ public class Document extends Entity { return this; } - public Properties setName(final String name) throws InvalidPropertyException { + public Properties setName(final String name) + throws InvalidPropertyException { if (name.length() == 0) { throw new InvalidPropertyException("name"); } this.name = name; return this; } - + public String getName() { return this.name; } @@ -219,6 +231,7 @@ public class Document extends Entity { public ProjectElement getOwner() { return this.owner; } + // Required only for passing search arguments public Properties setReference(final String did) throws InvalidPropertyException { @@ -289,14 +302,22 @@ public class Document extends Entity { } } + /** + * Database fetch constructor. + */ protected Document() { - // Database fetch constructor + super(); } - // Internal constructor + /** + * Initialization constructor. + * @param dprop + * @throws MissedPropertyException + * @throws InvalidPropertyException + * @throws MultiplyDefinedException + */ public Document(final Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException { - // ------------------------------------- super(dprop); // Throws one of the above exception if not valid myfile = new File(null, dprop.format, dprop.date); // The path is initialized below type = dprop.type; @@ -324,7 +345,6 @@ public class Document extends Entity { // ============================================================================================================================== public File getAttachedFile(final String format) { - // ------------------------------------------- List exports = getRelations(ConvertsRelation.class); for (Iterator i = exports.iterator(); i.hasNext();) { @@ -337,31 +357,26 @@ public class Document extends Entity { } public User getAuthor() { - // ------------------------ return author; } public Date getCreationDate() { - // ------------------------------ return myfile.getDate(); } public Date getLastModificationDate() { - // -------------------------------------- return lasdate; } - + public void setLastModificationDate(final Date aDate) { lasdate = aDate; } public String getFormat() { - // -------------------------- return myfile.getFormat(); } public Document getPreviousVersion() { - // ------------------------------------- Relation previous = getFirstRelation(VersionsRelation.class); if (previous == null) { return null; @@ -371,7 +386,6 @@ public class Document extends Entity { } public ProgressState getProgressState() { - // ---------------------------------------- return state; } @@ -382,7 +396,6 @@ public class Document extends Entity { * @return the path of the document */ public String getRelativePath() { - // -------------------------------- String[] table = myfile.getRelativePath().split("\\x2E"); StringBuffer path = new StringBuffer(table[0]); for (int i = 1; i < table.length - 1; i++) { @@ -399,12 +412,10 @@ public class Document extends Entity { * @return the document reference */ public String getReference() { - // ----------------------------- return did; } public File getSourceFile() { - // ---------------------------- return myfile; } @@ -415,7 +426,6 @@ public class Document extends Entity { * @return the stamps of the document in ascending order of dates, or an empty array if no stamp exist. */ public Timestamp[] getStamps() { - // ------------------------------- Vector stamps = new Vector(); for (Iterator i = this.getAllRelations().iterator(); i @@ -446,17 +456,18 @@ public class Document extends Entity { return name; } } - + /** * Set document title. - * @param aTitle document title to set + * + * @param aTitle + * document title to set */ public void setTitle(final String aTitle) { this.name = aTitle; } public DocumentType getType() { - // ------------------------------ return type; } @@ -469,7 +480,6 @@ public class Document extends Entity { * @see #isUndefined() */ public String getVersion() { - // --------------------------- return version; } @@ -483,32 +493,28 @@ public class Document extends Entity { * @see #initialize(Properties) */ public boolean isUndefined() { - // ----------------------------- return (history == -1); } public boolean isInto(final Step container) { - // -------------------------------------- return (step == container.getNumber()); } public boolean isPublished() { - // ----------------------------- return (countag > 0); } public boolean isShared() { - // -------------------------- return (countag + history > 1); } public boolean isVersioned() { - // ----------------------------- return (history > 0); } /** * Get the step. + * * @return the step */ public int getStep() { @@ -517,7 +523,9 @@ public class Document extends Entity { /** * Set the step. - * @param step the step to set + * + * @param step + * the step to set */ public void setStep(final int step) { this.step = step; @@ -525,6 +533,7 @@ public class Document extends Entity { /** * Get the did. + * * @return the did */ public String getDid() { @@ -533,7 +542,9 @@ public class Document extends Entity { /** * Set the did. - * @param did the did to set + * + * @param did + * the did to set */ public void setDid(final String did) { this.did = did; @@ -541,6 +552,7 @@ public class Document extends Entity { /** * Get the myfile. + * * @return the myfile */ public File getFile() { @@ -549,7 +561,9 @@ public class Document extends Entity { /** * Set the myfile. - * @param myfile the myfile to set + * + * @param myfile + * the myfile to set */ public void setFile(final File myfile) { this.myfile = myfile; @@ -557,6 +571,7 @@ public class Document extends Entity { /** * Get the history. + * * @return the history */ public int getHistory() { @@ -565,7 +580,9 @@ public class Document extends Entity { /** * Set the history. - * @param history the history to set + * + * @param history + * the history to set */ public void setHistory(final int history) { this.history = history; @@ -573,7 +590,9 @@ public class Document extends Entity { /** * Set the version. - * @param version the version to set + * + * @param version + * the version to set */ public void setVersion(final String version) { this.version = version; @@ -581,7 +600,9 @@ public class Document extends Entity { /** * Set the state. - * @param state the state to set + * + * @param state + * the state to set */ public void setProgressState(final ProgressState state) { this.state = state; @@ -589,6 +610,7 @@ public class Document extends Entity { /** * Get the countag. + * * @return the countag */ public int getCountag() { @@ -597,7 +619,9 @@ public class Document extends Entity { /** * Set the countag. - * @param countag the countag to set + * + * @param countag + * the countag to set */ public void setCountag(final int countag) { this.countag = countag; diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/DocumentType.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/DocumentType.java index 707ae66..4e285ec 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/DocumentType.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/DocumentType.java @@ -1,10 +1,12 @@ package org.splat.dal.bo.som; + /** * * @author Daniel Brunier-Coulin * @copyright OPEN CASCADE 2012 */ +import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -14,208 +16,292 @@ import org.splat.kernel.MissedPropertyException; import org.splat.kernel.MultiplyDefinedException; import org.splat.service.technical.ProjectSettingsService; - +/** + * Persistent document type. + */ public class DocumentType extends Persistent { - -// Persistent fields - private String name; - private ProgressState state; - private String step; // List of (dash separated) steps (numbers) containing this type - private String result; // Step (number ) having this type as result - private final Set uses = new HashSet(); - -// ============================================================================================================================== -// Construction -// ============================================================================================================================== - -// Fields initialization class - public static class Properties extends Persistent.Properties { -// ------------------------------------------------------------ - private String name = null; - private String step = null; - private String result = null; - private DocumentType[] uses = null; - -// - Public services - - @Override - public void clear () { - super.clear(); - name = null; - step = null; - result = null; - uses = null; - } -// - Setters of DocumentType properties - - public Properties setName (final String name) throws InvalidPropertyException - { - if (name.length() == 0) { - throw new InvalidPropertyException("name"); + + // Persistent fields + /** + * Type name. + */ + private String name; + /** + * Type progress state. + */ + private ProgressState state; + /** + * List of (dash separated) steps (numbers) containing this type. + */ + private String step; + /** + * Step (number) having this type as result. + */ + private String result; + /** + * Set of "parent" document types, which are used by this type. + */ + private final Set uses = new HashSet(); + + // ============================================================================================================================== + // Construction + // ============================================================================================================================== + + /** + * Fields initialization class. + */ + public static class Properties extends Persistent.Properties { + /** + * {@inheritDoc} + * + * @see DocumentType#name + */ + private String name = null; + /** + * {@inheritDoc} + * + * @see DocumentType#step + */ + private String step = null; + /** + * {@inheritDoc} + * + * @see DocumentType#result + */ + private String result = null; + /** + * {@inheritDoc} + * + * @see DocumentType#uses + */ + private DocumentType[] uses = null; + + // - Public services + + /** + * {@inheritDoc} + * + * @see org.splat.dal.bo.kernel.Persistent.Properties#clear() + */ + @Override + public void clear() { + super.clear(); + name = null; + step = null; + result = null; + uses = null; + } + + // - Setters of DocumentType properties + + public Properties setName(final String name) + throws InvalidPropertyException { + if (name.length() == 0) { + throw new InvalidPropertyException("name"); + } + this.name = name; + return this; } - this.name = name; - return this; - } - public Properties setResult (final ProjectSettingsService.Step step) - { - this.result = String.valueOf(step.getNumber()); - return this; - } - public Properties setStep (final ProjectSettingsService.Step... step) - { - this.step = "-"; - for (int i=0; i getDefaultUses () { -// ------------------------------------------- - return getUses(); - } - - public boolean isApproved () { -// ---------------------------- - return (state == ProgressState.APPROVED); - } -/** - * Checks if documents of this type are attached to the given study step, either as result or content. - * - * @param step the involved study step - * @return true if documents of this type are attached to the given step. - * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step) - */ - public boolean isContentInto (final ProjectSettingsService.Step step) { -// -------------------------------------------------------- - String[] path = this.step.split("-"); - for (int i=0; i getDefaultUses() { + return getUses(); + } + + public boolean isApproved() { + return (state == ProgressState.APPROVED); + } + + /** + * Checks if documents of this type are attached to the given study step, either as result or content. + * + * @param step + * the involved study step + * @return true if documents of this type are attached to the given step. + * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step) + */ + public boolean isContentInto(final ProjectSettingsService.Step step) { + String[] path = this.step.split("-"); + for (int i = 0; i < path.length; i++) { + String value = path[i]; + if (value.length() == 0) { + continue; + } + if (Integer.valueOf(value) == step.getNumber()) { + return true; + } + } return false; } - return (Integer.valueOf(result) == step.getNumber()); - } - - /** + + /** + * Checks if documents of this type are result of any study step. + * + * @return true if documents of this type are result of a step. + * @see #isStudyResult() + * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step) + */ + public boolean isStepResult() { + return (result != null); + } + + /** + * Checks if documents of this type are result of the given study step. + * + * @param step + * the involved study step + * @return true if documents of this type are result of the given step. + * @see #isContentInto(org.splat.service.technical.ProjectSettingsServiceImpl.Step) + * @see #isStepResult() + * @see #isStudyResult() + */ + public boolean isResultOf(final ProjectSettingsService.Step step) { + if (result == null) { + return false; + } + return (Integer.valueOf(result) == step.getNumber()); + } + + /** * Get the state. + * * @return the state */ public ProgressState getState() { return state; } + /** * Set the state. - * @param state the state to set + * + * @param state + * the state to set */ public void setState(final ProgressState state) { this.state = state; } + /** * Get the uses. + * * @return the uses */ protected Set getUses() { return uses; } + + /** + * Set properties of document type except persistent id and name. + * + * @param tprop + * type properties + */ + public void setProperties(final Properties tprop) { + this.step = tprop.step; + this.result = tprop.result; + this.uses.clear(); + this.uses.addAll(Arrays.asList(tprop.uses)); + } } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java index cae063c..71c5402 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java @@ -56,14 +56,21 @@ public abstract class ProjectElement extends Entity { // Constructors // ============================================================================================================================== -// Database fetch constructor + /** + * Database fetch constructor. + */ protected ProjectElement () { -// --------------------------- - folders = null; + super(); + folders = null; } -// Initialization constructor + /** + * Initialization constructor. + * @param oprop + * @throws MissedPropertyException + * @throws InvalidPropertyException + * @throws MultiplyDefinedException + */ protected ProjectElement (final ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException { -// ------------------------------------------------- super(oprop); // Throws one of the above exception if not valid title = null; // Initialized by subclasses credate = null; // Initialized by subclasses @@ -79,7 +86,6 @@ public abstract class ProjectElement extends Entity { // ============================================================================================================================== public User getAuthor () { -// ------------------------ return manager; } @@ -87,12 +93,10 @@ public abstract class ProjectElement extends Entity { * Returns the creation date of this Project Element. */ public Date getDate () { -// ---------------------- return credate; } public String getDescription () { -// ------------------------------- String summary = null; DescriptionAttribute field = (DescriptionAttribute)this.getAttribute(DescriptionAttribute.class); if (field != null) { @@ -117,7 +121,6 @@ public abstract class ProjectElement extends Entity { * @return the publication of the document version, or null if the given document version is not published into this Project Element */ public Publication getPublication (final Document doc) { -// ------------------------------------------------ long index = doc.getIndex(); for (Iterator i=docums.iterator(); i.hasNext(); ) { Publication found = i.next(); @@ -129,7 +132,6 @@ public abstract class ProjectElement extends Entity { } public String getTitle () { -// ------------------------- return title; } @@ -138,7 +140,6 @@ public abstract class ProjectElement extends Entity { } public boolean publishes (final Document doc) { -// --------------------------------------- long index = doc.getIndex(); for (Iterator i=docums.iterator(); i.hasNext(); ) { Document found = i.next().value(); @@ -150,12 +151,10 @@ public abstract class ProjectElement extends Entity { } public Iterator PublicationIterator () { -// --------------------------------------------------- return Collections.unmodifiableSet(docums).iterator(); } public Iterator SimulationContextIterator () { -// --------------------------------------------------------------- return Collections.unmodifiableList(contex).iterator(); } @@ -164,22 +163,18 @@ public abstract class ProjectElement extends Entity { // ============================================================================================================================== public boolean add (final Publication newdoc) { -// ------------------------------------------ return docums.add(newdoc); } public boolean add (final SimulationContext newdoc) { -// ------------------------------------------------ return contex.add(newdoc); } public boolean remove (final Publication oldoc) { -// -------------------------------------------- return docums.remove(oldoc); // The removed tag becoming orphan, it is supposed automatically deleted from the data store } public boolean remove (final SimulationContext oldoc) { -// -------------------------------------------------- return contex.remove(oldoc); } /** diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml index 997ffc7..d5e6f08 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml @@ -13,7 +13,7 @@ - + diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java index 91f4ce1..4b782ca 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java @@ -126,6 +126,10 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase { return (_uplevel >= 0); } + public void reset() { + _uplevel = -1; + } + public void initialize() throws IOException, SQLException { LOG.info("Creation of the database."); diff --git a/Workspace/Siman-Common/src/org/splat/kernel/InvalidPropertyException.java b/Workspace/Siman-Common/src/org/splat/kernel/InvalidPropertyException.java index 68b60be..a22d58e 100644 --- a/Workspace/Siman-Common/src/org/splat/kernel/InvalidPropertyException.java +++ b/Workspace/Siman-Common/src/org/splat/kernel/InvalidPropertyException.java @@ -37,7 +37,6 @@ public class InvalidPropertyException extends BusinessException { public InvalidPropertyException(final String messageKey, final Object... context) { super(messageKey, context); - // TODO auto-generated constructor } /** diff --git a/Workspace/Siman-Common/src/org/splat/kernel/MismatchException.java b/Workspace/Siman-Common/src/org/splat/kernel/MismatchException.java index 956932f..aa6b8ca 100644 --- a/Workspace/Siman-Common/src/org/splat/kernel/MismatchException.java +++ b/Workspace/Siman-Common/src/org/splat/kernel/MismatchException.java @@ -22,6 +22,18 @@ public class MismatchException extends BusinessException { super(); } + /** + * Create a MismatchException. + * + * @param messageKey + * error message key + * @param context + * parameters + */ + public MismatchException(final String messageKey, final Object... context) { + super(messageKey, context); + } + /** * Create a MismatchException. * @param message the error message. diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java index cfa4983..ff9d5e1 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java @@ -29,7 +29,6 @@ import org.splat.dal.bo.som.StampRelation; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.Timestamp; import org.splat.dal.bo.som.ValidationStep; -import org.splat.dal.bo.som.VersionsRelation; import org.splat.dal.bo.som.Document.Properties; import org.splat.dal.dao.som.DocumentDAO; import org.splat.dal.dao.som.DocumentTypeDAO; @@ -539,27 +538,20 @@ public class DocumentServiceImpl implements DocumentService { } else { Revision myvers = new Revision(aDoc.getVersion()); if (!myvers.isNull()) { // Versionning context - for (Iterator i = aDoc.getAllRelations().iterator(); i - .hasNext();) { - Relation link = i.next(); - if (link.getClass().equals(VersionsRelation.class)) { - previous = (Document) link.getTo(); // Versioned document - break; - } - } + previous = aDoc.getPreviousVersion(); } if (aDoc.getProgressState() != null) { myvers.incrementAs(state); // Incrementation if the reversion number is not imposed } aDoc.setVersion(myvers.toString()); } - // Update this document and the previous version, if exit + // Update this document and the previous version, if exist if (previous != null) { previous.setHistory(previous.getHistory() + 1); getDocumentDAO().merge(previous); } aDoc.setProgressState(state); - getDocumentDAO().update(aDoc); + //RKV: getDocumentDAO().update(aDoc); } // protected void upgrade () { diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java index 5fa287e..63f511f 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java @@ -26,7 +26,7 @@ import org.springframework.transaction.annotation.Transactional; /** * Document type service implementation. - * + * * @author Roman Kozlov (RKV) */ public class DocumentTypeServiceImpl implements DocumentTypeService { @@ -41,7 +41,7 @@ public class DocumentTypeServiceImpl implements DocumentTypeService { * * @return the list of all document types */ -// @Transactional(readOnly = true) + // @Transactional(readOnly = true) @Transactional public List selectAllTypes() { List types = getDocumentTypeDAO().getAll(); @@ -104,9 +104,14 @@ public class DocumentTypeServiceImpl implements DocumentTypeService { public DocumentType createType(final DocumentType.Properties tprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException { - // TODO: Check for duplicate definition - DocumentType type = new DocumentType(tprop); - getDocumentTypeDAO().create(type); + DocumentType type = getDocumentTypeDAO().findByCriteria( + Restrictions.eq("name", tprop.getName())); + if (type == null) { + type = new DocumentType(tprop); + getDocumentTypeDAO().create(type); + } else { + type.setProperties(tprop); // Update properties of persistent type + } return type; } @@ -118,7 +123,8 @@ public class DocumentTypeServiceImpl implements DocumentTypeService { * @return the list of found document types */ @Transactional(readOnly = true) - public List selectTypesOf(final ProjectSettingsService.Step step) { + public List selectTypesOf( + final ProjectSettingsService.Step step) { Integer number = step.getNumber(); String sampleStr = new StringBuffer("%-").append(number).append("-%") .toString(); @@ -132,11 +138,13 @@ public class DocumentTypeServiceImpl implements DocumentTypeService { /** * Approve the document type. - * @param aType the document type to approve + * + * @param aType + * the document type to approve * @return true if approval succeeded */ @Transactional - public boolean approve(final DocumentType aType) { + public boolean approve(final DocumentType aType) { boolean res = (aType.getState() == ProgressState.inCHECK); if (res) { aType.setState(ProgressState.APPROVED); // The type name is supposed being localized diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index 9e3a570..a47e1dc 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -450,11 +450,12 @@ public class PublicationServiceImpl implements PublicationService { if (previous != null) { Publication oldoc = step.getDocument(previous.getIndex()); boolean done = getStepService().remove(step, oldoc); // Decrements the configuration tag count of document - if (done) { +/* if (done) { oldoc = getPublicationDAO().merge(oldoc); //RKV: to avoid: NonUniqueObjectException: a different object with the same identifier value was already associated with the session - getPublicationDAO().delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object + //RKV: use delete-orphan by removing from project element, see StepService.remove + //RKV: getPublicationDAO().delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object } - } +*/ } getStepService().add(step, aPublication); // Increments the configuration tag count of document // Import the document properties and update of the study diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index 4dc0648..0337209 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -395,8 +395,6 @@ public class ScenarioServiceImpl implements ScenarioService { // For each processed existing document keep its new version Map newVersion = new HashMap(); - // For each processed existing document keep its previous version - Map prevVersion = new HashMap(); // Keep newly created documents to create uses relations to results of a previous step. List newVers = new ArrayList(); List newDocs = new ArrayList(); @@ -406,6 +404,9 @@ public class ScenarioServiceImpl implements ScenarioService { Document.Properties dprop = new Document.Properties(); Date aDate = new Date(); for (StepDTO stepDTO : scInfo) { + if (LOG.isDebugEnabled()) { + LOG.debug("Checkin the step:\n" + stepDTO); + } // Find a result document type of the step int i = 0; resType = null; @@ -447,14 +448,17 @@ public class ScenarioServiceImpl implements ScenarioService { MessageKeyEnum.SCN_000002.toString(), doc .getId()); } + if (pub.value() == null) { + throw new MismatchException( + MessageKeyEnum.SCN_000002.toString(), doc + .getId()); + } newPub = getStepService().versionDocument(step, pub, dprop); // Remeber the link from the old document to the new document version newVersion.put(pub.value(), newPub.value()); // Remember the new version publication newVers.add(newPub); - // Remember the previouse document version for the new publication - prevVersion.put(newPub, pub.value()); } else { // Otherwise create a new document of the result type @@ -495,8 +499,14 @@ public class ScenarioServiceImpl implements ScenarioService { // For each new version copy uses relations from the previous version. for (Publication newVer : newVers) { // For each Uses relation of the previous version - for (Relation rel : prevVersion.get(newVer).getRelations( - UsesRelation.class)) { + Document prevDoc = newVer.value().getPreviousVersion();//prevVersion.get(newVer); + if (LOG.isDebugEnabled()) { + LOG.debug("Previous version for publication #" + + newVer.getIndex() + " is found: " + prevDoc); + } + List usesRelations = prevDoc + .getRelations(UsesRelation.class); + for (Relation rel : usesRelations) { // If used document has been also versioned then refer to its new version. Document usedDoc = ((UsesRelation) rel).getTo(); if (newVersion.containsKey(usedDoc)) { @@ -514,10 +524,10 @@ public class ScenarioServiceImpl implements ScenarioService { for (Publication newDoc : newDocs) { // Find used document type according to the configuration. // Find documents of used type in the previous study step. - - // Create uses relation from the new document + + // Create uses relation from the new document // to the found document in the previous step. - //newDoc.addDependency(to); + // newDoc.addDependency(to); } // Mark the scenario as checked in diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 281d57c..934b296 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -21,6 +21,7 @@ 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; @@ -438,6 +439,10 @@ public class StepServiceImpl implements StepService { boolean res = aStep.getOwner().remove(oldoc); // Updates the study in memory if (res) { aStep.getDocuments().remove(oldoc); // Updates this step + ProjectElement owner = aStep.getOwner(); + if (owner != null) { + owner.remove(oldoc); + } getDocumentService().release(oldoc.value()); // Decrements the configuration tag count of document // The publication becoming orphan, it should automatically be removed from the database when updating of owner scenario. } diff --git a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java index c9498f5..6830946 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java @@ -87,8 +87,18 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { * Document type mappings to file formats which should be imported into SALOME during check-out. */ private transient final Map> _mapimport = new HashMap>(); + /** + * Default document types structured by step.formats. + */ + private transient final Map _defdoctype = new LinkedHashMap(); // Temporary attributes initialized from the configuration file for populating the database with object types + /** + * Step.format keys structured by Default document types names. This map is used for loading config before document types are created in + * the database. When document types are created then _defdoctype is filled. + */ + private transient final Map> _defdoctypeKeys = new HashMap>(); + /** * Document type names and uses mapping. */ @@ -128,11 +138,6 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { */ private DocumentTypeService _documentTypeService; - /** - * Default document types structured by step.formats. - */ - private transient final Map _defdoctype = new LinkedHashMap(); - /** * File naming strategy enumeration. */ @@ -354,6 +359,10 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { public DocumentType getDefaultDocumentType(final Step step, final String format) { String[] table = format.split("\\x2E"); + if (LOG.isDebugEnabled()) { + LOG.debug("Trying to get default type: " + step.getNumber() + "." + + table[table.length - 1]); + } return _defdoctype .get(step.getNumber() + "." + table[table.length - 1]); // May be null } @@ -543,33 +552,53 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { */ private void loadDefaultDocTypes(final Map children) { _defdoctype.clear(); + _defdoctypeKeys.clear(); Node child = children.get("default-doctypes"); - NodeList nlist = child.getChildNodes(); + if (child != null) { + NodeList nlist = child.getChildNodes(); - List listype = getDocumentTypeService().selectAllTypes(); - Map maptype = new HashMap(); - for (Iterator i = listype.iterator(); i.hasNext();) { - DocumentType type = i.next(); - maptype.put(type.getName(), type); - } - for (int i = 0; i < nlist.getLength(); i++) { - child = nlist.item(i); - if (!child.getNodeName().equals("step")) { - continue; + List listype = getDocumentTypeService() + .selectAllTypes(); + Map maptype = new HashMap(); + for (Iterator i = listype.iterator(); i.hasNext();) { + DocumentType type = i.next(); + maptype.put(type.getName(), type); } - - String nstep = child.getAttributes().getNamedItem("number") - .getNodeValue(); - NodeList map = child.getChildNodes(); - for (int j = 0; j < map.getLength(); j++) { - child = map.item(j); - if (!child.getNodeName().equals("mapping")) { + for (int i = 0; i < nlist.getLength(); i++) { + child = nlist.item(i); + if (!child.getNodeName().equals("step")) { continue; } - NamedNodeMap natr = child.getAttributes(); - String dext = natr.getNamedItem("extension").getNodeValue(); - String type = natr.getNamedItem(TYPE_ATTR).getNodeValue(); - _defdoctype.put(nstep + "." + dext, maptype.get(type)); + + String nstep = child.getAttributes().getNamedItem("number") + .getNodeValue(); + NodeList map = child.getChildNodes(); + for (int j = 0; j < map.getLength(); j++) { + child = map.item(j); + if (!child.getNodeName().equals("mapping")) { + continue; + } + NamedNodeMap natr = child.getAttributes(); + String dext = natr.getNamedItem("extension").getNodeValue(); + String type = natr.getNamedItem(TYPE_ATTR).getNodeValue(); + if (LOG.isDebugEnabled()) { + LOG.debug("Map default type: " + nstep + "." + dext + + ": (type name = " + type + ")" + + maptype.get(type)); + } + _defdoctype.put(nstep + "." + dext, maptype.get(type)); + // Remember the key if type is not created yet + if (maptype.get(type) == null) { + List keys; + if (_defdoctypeKeys.containsKey(type)) { + keys = _defdoctypeKeys.get(type); + } else { + keys = new ArrayList(); + _defdoctypeKeys.put(type, keys); + } + keys.add(nstep + "." + dext); + } + } } } } @@ -777,6 +806,16 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService { tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types getDocumentTypeService().approve(tdoc); maptype.put(type, tdoc); + // Remember default type if it is + if (_defdoctypeKeys.containsKey(type)) { + for (String key : _defdoctypeKeys.get(type)) { + if (LOG.isDebugEnabled()) { + LOG.debug("Put mapping for default type: " + + key + ": " + tdoc); + } + _defdoctype.put(key, tdoc); + } + } } } } catch (Exception error) { diff --git a/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java b/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java index da005b3..cfc6fe2 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java @@ -14,6 +14,7 @@ import java.sql.SQLException; import java.util.List; import org.splat.dal.bo.som.Scenario; +import org.splat.dal.dao.som.Database; import org.splat.log.AppLogger; import org.splat.service.DocumentTypeService; import org.splat.service.technical.ProjectSettingsService; @@ -216,6 +217,7 @@ public class TestProjectSettingsService extends BaseTest { /* * geometry: brep model: med loads: c3m results: med */ + Database.getInstance().reset(); _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again try { _projectSettings.configure(ClassLoader.getSystemResource( @@ -223,6 +225,8 @@ public class TestProjectSettingsService extends BaseTest { } catch (FileNotFoundException e) { Assert.fail("Can't find configuration file: ", e); } + Assert.assertTrue(_documentTypeService.selectAllTypes().size() > 0, + "No document types are created."); List steps = _projectSettings.getStepsOf(Scenario.class); Assert.assertTrue(steps.size() > 0, "No steps are created."); @@ -258,11 +262,6 @@ public class TestProjectSettingsService extends BaseTest { Assert.assertEquals(defTypes.size(), 3); Assert.assertNull(_projectSettings.getDefaultDocumentType( step, "pdf")); - Assert.assertNotNull(_projectSettings - .getDefaultDocumentType(step, "xml")); - Assert.assertEquals(_projectSettings - .getDefaultDocumentType(step, "xml").getName(), - "design"); Assert.assertNotNull(_projectSettings .getDefaultDocumentType(step, "doc")); Assert.assertEquals(_projectSettings @@ -273,6 +272,11 @@ public class TestProjectSettingsService extends BaseTest { Assert.assertEquals(_projectSettings .getDefaultDocumentType(step, "docx").getName(), "design"); + Assert.assertNotNull(_projectSettings + .getDefaultDocumentType(step, "xml")); + Assert.assertEquals(_projectSettings + .getDefaultDocumentType(step, "xml").getName(), + "design"); break; case 3: Assert.assertEquals(defTypes.size(), 7); diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index cb12d2b..6b8d6c7 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -8,7 +8,9 @@ *****************************************************************************/ package test.splat.service; +import java.io.File; import java.io.FileNotFoundException; +import java.io.FileWriter; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; @@ -21,6 +23,7 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.Study; +import org.splat.dal.dao.som.Database; import org.splat.dal.dao.som.ScenarioDAO; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MismatchException; @@ -36,6 +39,7 @@ import org.splat.service.dto.DocumentDTO; import org.splat.service.dto.FileDTO; import org.splat.service.dto.StepDTO; import org.splat.service.technical.ProjectSettingsService; +import org.splat.service.technical.RepositoryService; import org.splat.service.technical.ProjectSettingsService.Step; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -66,6 +70,13 @@ public class TestScenarioService extends BaseTest { @Qualifier("scenarioService") private transient ScenarioService _scenarioService; + /** + * The RepositoryService. Later injected by Spring. + */ + @Autowired + @Qualifier("repositoryService") + private transient RepositoryService _repositoryService; + /** * The Scenario DAO. Later injected by Spring. */ @@ -284,20 +295,42 @@ public class TestScenarioService extends BaseTest { MissedPropertyException, MultiplyDefinedException, IOException, SQLException, MismatchException, NotApplicableException { LOG.debug(">>>>> BEGIN testCheckin()"); + _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again _projectSettings.configure(ClassLoader .getSystemResource("test/som.xml").getPath()); long scenarioId = createScenario(); Scenario aScen = _scenarioDAO.get(scenarioId); User user = aScen.getAuthor(); - long userId = user.getIndex(); // TODO: get id of a test user + long userId = user.getIndex(); + + // Prepare download directory + File tmpDir = _repositoryService.getDownloadDirectory(userId); + if (!tmpDir.exists()) { + Assert.assertTrue(tmpDir.mkdir(), + "Can't create temporary directory: " + + tmpDir.getAbsolutePath()); + } + // Call DAO's create method for a good transient knowledge element. - List steps = new ArrayList(); - _scenarioService.checkin(scenarioId, userId, steps); + // Simulate checkout + List steps = _scenarioService.getScenarioInfo(scenarioId); + _scenarioService.checkout(aScen, user); + + // Prepare test data for checkin + // Checkin only two first steps (geom and mesh) + List stepsToCheckin = new ArrayList(); + for (StepDTO step : steps) { + // Prepare GEOM: checkin actual brep + createDocForModule("GEOM", "brep", tmpDir, step, stepsToCheckin); + createDocForModule("SMESH", "med", tmpDir, step, stepsToCheckin); + } + // Do test checkin + _scenarioService.checkin(scenarioId, userId, stepsToCheckin); // Call DAO's get method for a not existing id. try { - _scenarioService.checkin(-1, userId, steps); + _scenarioService.checkin(-1, userId, stepsToCheckin); Assert .fail("Check in for scenario with not existing id must be failed."); } catch (Exception e) { @@ -307,6 +340,50 @@ public class TestScenarioService extends BaseTest { LOG.debug(">>>>> END testCheckin()"); } + /** + * Prepare a document with a file for check-in. + * + * @param module + * SALOME module name + * @param format + * file extension + * @param tmpDir + * download directory + * @param step + * checked out stepDTO + * @param stepsToCheckin + * DTO for check-in + * @throws IOException + * if file creation failed + */ + private void createDocForModule(final String module, final String format, + final File tmpDir, final StepDTO step, + final List stepsToCheckin) throws IOException { + if (module.equals(step.getModule())) { + StepDTO stepToCheckin = new StepDTO(); + stepsToCheckin.add(stepToCheckin); + stepToCheckin.setNumber(step.getNumber()); + for (DocumentDTO doc : step.getDocs()) { + if (doc.getFiles().get(0).getState() != 'O') { + DocumentDTO docToCheckin = stepToCheckin.addDoc( + doc.getId(), doc.getTitle()); + for (FileDTO file : doc.getFiles()) { + if (file.getPath().endsWith(format)) { + // Create a file in the download directory + String filePath = tmpDir.getAbsolutePath() + + "/" + doc.getTitle() + "_result." + format; + FileWriter fw = new FileWriter(filePath); + fw.write("Simulation of " + format + " file for checkin at " + new Date()); + fw.close(); + FileDTO fileToCheckin = new FileDTO(filePath); + docToCheckin.addFile(fileToCheckin); + } + } + } + } + } + } + /** * Create a persistent scenario for tests. * @@ -328,6 +405,8 @@ public class TestScenarioService extends BaseTest { // Create a scenario for tests HibernateTemplate ht = getHibernateTemplate(); + Database.getInstance().reset(); + _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again // Load workflow customization try { _projectSettings.configure(ClassLoader.getSystemResource( @@ -356,7 +435,7 @@ public class TestScenarioService extends BaseTest { // Create a test scenario Scenario.Properties sprops = new Scenario.Properties().setTitle( - "TST_Study").setManager(anAuthor).setOwnerStudy(aStudy); + "TST_Scenario").setManager(anAuthor).setOwnerStudy(aStudy); Scenario aScenario = new Scenario(sprops); aStudy.getScenariiList().add(aScenario); ht.saveOrUpdate(anAuthor); @@ -374,8 +453,12 @@ public class TestScenarioService extends BaseTest { List dtypes = _documentTypeService .selectTypesOf(step); for (DocumentType dtype : dtypes) { - dprop.setName("document" + i++).setType(dtype) - .setFormat("brep"); + dprop.setName("document" + i++).setType(dtype); + if (step.getNumber() > 3) { + dprop.setFormat("med"); + } else { + dprop.setFormat("brep"); + } // Create a document published in the scenario // document: document type[0] - first type used on the step // .brep @@ -391,7 +474,7 @@ public class TestScenarioService extends BaseTest { ht.saveOrUpdate(pub); // Attach a file - ht.saveOrUpdate(pub.value()); + ht.save(pub.value()); ht.saveOrUpdate(_publicationService.attach(pub, "med")); // Create a document with outdated publication @@ -413,7 +496,7 @@ public class TestScenarioService extends BaseTest { ht.saveOrUpdate(pub); // Attach a file - ht.saveOrUpdate(pub.value()); + ht.save(pub.value()); ht.saveOrUpdate(_publicationService.attach(pub, "med")); }