--- /dev/null
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="SimanCommonTests" verbose="1">
+ <test name="all">
+ <method-selectors>
+ <method-selector>
+ <script language="beanshell">
+ <![CDATA[
+ (groups.containsKey("business") || groups.containsKey("functional") || groups.containsKey("service") ) && method.getName().toUpperCase().startsWith("TEST")
+ ]]>
+ </script>
+ </method-selector>
+ </method-selectors>
+ <groups>
+ <!--
+ <define name="all">
+ <include name="business"/>
+ <include name="functional"/>
+ <include name="service"/>
+ </define>
+ <define name="new">
+ <include name="newservice"/>
+ </define>
+ <run>
+ <include name="all"/>
+ <exclude name="old"/>
+ </run>
+ -->
+
+ </groups>
+ <classes>
+ <class name="test.splat.service.TestProjectSettingsService"></class>
+ </classes>
+ </test>
+</suite>
import org.splat.som.Step;
/**
- * Document persistent class.
+ * Document persistent class.
*/
public class Document extends Entity {
// ==============================================================================================================================
/**
- * Fields initialization class.
+ * Fields initialization class.
*/
public static class Properties extends Persistent.Properties {
// ------------------------------------------------------------
/**
* Get the date.
+ *
* @return the date
*/
public Date getDate() {
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;
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;
}
public ProjectElement getOwner() {
return this.owner;
}
+
// Required only for passing search arguments
public Properties setReference(final String did)
throws InvalidPropertyException {
}
}
+ /**
+ * 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;
// ==============================================================================================================================
public File getAttachedFile(final String format) {
- // -------------------------------------------
List<Relation> exports = getRelations(ConvertsRelation.class);
for (Iterator<Relation> i = exports.iterator(); i.hasNext();) {
}
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;
}
public ProgressState getProgressState() {
- // ----------------------------------------
return state;
}
* @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++) {
* @return the document reference
*/
public String getReference() {
- // -----------------------------
return did;
}
public File getSourceFile() {
- // ----------------------------
return myfile;
}
* @return the stamps of the document in ascending order of dates, or an empty array if no stamp exist.
*/
public Timestamp[] getStamps() {
- // -------------------------------
Vector<Timestamp> stamps = new Vector<Timestamp>();
for (Iterator<Relation> i = this.getAllRelations().iterator(); i
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;
}
* @see #isUndefined()
*/
public String getVersion() {
- // ---------------------------
return version;
}
* @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() {
/**
* Set the step.
- * @param step the step to set
+ *
+ * @param step
+ * the step to set
*/
public void setStep(final int step) {
this.step = step;
/**
* Get the did.
+ *
* @return the did
*/
public String getDid() {
/**
* Set the did.
- * @param did the did to set
+ *
+ * @param did
+ * the did to set
*/
public void setDid(final String did) {
this.did = did;
/**
* Get the myfile.
+ *
* @return the myfile
*/
public File getFile() {
/**
* Set the myfile.
- * @param myfile the myfile to set
+ *
+ * @param myfile
+ * the myfile to set
*/
public void setFile(final File myfile) {
this.myfile = myfile;
/**
* Get the history.
+ *
* @return the history
*/
public int getHistory() {
/**
* Set the history.
- * @param history the history to set
+ *
+ * @param history
+ * the history to set
*/
public void setHistory(final int history) {
this.history = history;
/**
* Set the version.
- * @param version the version to set
+ *
+ * @param version
+ * the version to set
*/
public void setVersion(final String version) {
this.version = version;
/**
* Set the state.
- * @param state the state to set
+ *
+ * @param state
+ * the state to set
*/
public void setProgressState(final ProgressState state) {
this.state = state;
/**
* Get the countag.
+ *
* @return the countag
*/
public int getCountag() {
/**
* Set the countag.
- * @param countag the countag to set
+ *
+ * @param countag
+ * the countag to set
*/
public void setCountag(final int countag) {
this.countag = countag;
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;
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<DocumentType> uses = new HashSet<DocumentType>();
-
-// ==============================================================================================================================
-// 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<DocumentType> uses = new HashSet<DocumentType>();
+
+ // ==============================================================================================================================
+ // 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<step.length; i++) {
- this.step = this.step + String.valueOf(step[i].getNumber()) + "-";
+
+ public Properties setResult(final ProjectSettingsService.Step step) {
+ this.result = String.valueOf(step.getNumber());
+ return this;
}
- return this;
- }
- public Properties setUses (final DocumentType... type)
- {
- this.uses = type;
- return this;
- }
-// - Global validity check
-
- public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
- {
- if (name == null) {
- throw new MissedPropertyException("name");
+
+ public Properties setStep(final ProjectSettingsService.Step... step) {
+ this.step = "-";
+ for (int i = 0; i < step.length; i++) {
+ this.step = this.step + String.valueOf(step[i].getNumber())
+ + "-";
+ }
+ return this;
}
- if (step == null) {
- throw new MissedPropertyException("path");
+
+ public Properties setUses(final DocumentType... type) {
+ this.uses = type;
+ return this;
}
- }
- }
-// Database fetch constructor
- protected DocumentType () {
-// -------------------------
- }
-// Initialization constructor
- public DocumentType (final Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
-// -----------------------------------------
- super(dprop); // Throws one of the above exception if not valid
- name = dprop.name;
- state = ProgressState.inCHECK;
- step = dprop.step;
- result = dprop.result; // May be null
- if (dprop.uses != null) {
- for (int i=0; i<dprop.uses.length; i++) {
- getUses().add(dprop.uses[i]);
+
+ // - Global validity check
+
+ public void checkValidity() throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException {
+ if (name == null) {
+ throw new MissedPropertyException("name");
+ }
+ if (step == null) {
+ throw new MissedPropertyException("path");
+ }
+ }
+
+ /**
+ * Get the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
}
}
- }
-// ==============================================================================================================================
-// Public member functions
-// ==============================================================================================================================
+ /**
+ * Database fetch constructor.
+ */
+ protected DocumentType() {
+ super();
+ }
- @Override
- public boolean equals(final Object entity) {
-// ------------------------------------
- if (entity == null) {
- return false;
+ /**
+ * Initialization constructor.
+ *
+ * @param dprop
+ * type properties
+ * @throws MissedPropertyException
+ * if some mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property has invalid value
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ */
+ public DocumentType(final Properties dprop) throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException {
+ super(dprop); // Throws one of the above exception if not valid
+ name = dprop.name;
+ state = ProgressState.inCHECK;
+ step = dprop.step;
+ result = dprop.result; // May be null
+ if (dprop.uses != null) {
+ for (int i = 0; i < dprop.uses.length; i++) {
+ getUses().add(dprop.uses[i]);
+ }
+ }
}
- if (entity instanceof String) {
- return this.name.equals(entity); // Names are unique
- } else if (entity instanceof DocumentType) {
- DocumentType object = (DocumentType)entity;
- long he = object.getIndex();
- long me = this.getIndex();
- if (me*he != 0) {
- return (he == me);
- } else {
- return this.getName().equals(object.getName());
- }
- } else {
- return false;
- }
- }
-
- public String getName () {
-// ------------------------
- return name;
- }
-
- public Set<DocumentType> 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;
+ // ==============================================================================================================================
+ // Public member functions
+ // ==============================================================================================================================
+
+ @Override
+ public boolean equals(final Object entity) {
+ if (entity == null) {
+ return false;
}
- if (Integer.valueOf(value) == step.getNumber()) {
- return true;
+ if (entity instanceof String) {
+ return this.name.equals(entity); // Names are unique
+ } else if (entity instanceof DocumentType) {
+ DocumentType object = (DocumentType) entity;
+ long he = object.getIndex();
+ long me = this.getIndex();
+ if (me * he == 0) {
+ return this.getName().equals(object.getName());
+ } else {
+ return (he == me);
+ }
+ } else {
+ return false;
}
- }
- return false;
- }
+ }
-/**
- * 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);
- }
+ public String getName() {
+ return name;
+ }
-/**
- * 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) {
+ public Set<DocumentType> 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<DocumentType> 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
// 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
// ==============================================================================================================================
public User getAuthor () {
-// ------------------------
return manager;
}
* 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) {
* @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<Publication> i=docums.iterator(); i.hasNext(); ) {
Publication found = i.next();
}
public String getTitle () {
-// -------------------------
return title;
}
}
public boolean publishes (final Document doc) {
-// ---------------------------------------
long index = doc.getIndex();
for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
Document found = i.next().value();
}
public Iterator<Publication> PublicationIterator () {
-// ---------------------------------------------------
return Collections.unmodifiableSet(docums).iterator();
}
public Iterator<SimulationContext> SimulationContextIterator () {
-// ---------------------------------------------------------------
return Collections.unmodifiableList(contex).iterator();
}
// ==============================================================================================================================
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);
}
/**
<!-- Publication properties
-->
<!-- Document mydoc -->
- <many-to-one name="mydoc" column="doc" access="field" not-null="true" cascade="delete"/>
+ <many-to-one name="mydoc" column="doc" access="field" not-null="true"/>
<!-- ProjectElement owner -->
<many-to-one name="owner" column="owner" access="field" not-null="true" />
return (_uplevel >= 0);
}
+ public void reset() {
+ _uplevel = -1;
+ }
+
public void initialize() throws IOException, SQLException {
LOG.info("Creation of the database.");
public InvalidPropertyException(final String messageKey,
final Object... context) {
super(messageKey, context);
- // TODO auto-generated constructor
}
/**
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.
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;
} else {
Revision myvers = new Revision(aDoc.getVersion());
if (!myvers.isNull()) { // Versionning context
- for (Iterator<Relation> 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 () {
/**
* Document type service implementation.
- *
+ *
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public class DocumentTypeServiceImpl implements DocumentTypeService {
*
* @return the list of all document types
*/
-// @Transactional(readOnly = true)
+ // @Transactional(readOnly = true)
@Transactional
public List<DocumentType> selectAllTypes() {
List<DocumentType> types = getDocumentTypeDAO().getAll();
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;
}
* @return the list of found document types
*/
@Transactional(readOnly = true)
- public List<DocumentType> selectTypesOf(final ProjectSettingsService.Step step) {
+ public List<DocumentType> selectTypesOf(
+ final ProjectSettingsService.Step step) {
Integer number = step.getNumber();
String sampleStr = new StringBuffer("%-").append(number).append("-%")
.toString();
/**
* 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
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
// For each processed existing document keep its new version
Map<Document, Document> newVersion = new HashMap<Document, Document>();
- // For each processed existing document keep its previous version
- Map<Publication, Document> prevVersion = new HashMap<Publication, Document>();
// Keep newly created documents to create uses relations to results of a previous step.
List<Publication> newVers = new ArrayList<Publication>();
List<Publication> newDocs = new ArrayList<Publication>();
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;
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
// 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<Relation> 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)) {
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
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;
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.
}
* Document type mappings to file formats which should be imported into SALOME during check-out.
*/
private transient final Map<String, List<String>> _mapimport = new HashMap<String, List<String>>();
+ /**
+ * Default document types structured by step.formats.
+ */
+ private transient final Map<String, DocumentType> _defdoctype = new LinkedHashMap<String, DocumentType>();
// 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<String, List<String>> _defdoctypeKeys = new HashMap<String, List<String>>();
+
/**
* Document type names and uses mapping.
*/
*/
private DocumentTypeService _documentTypeService;
- /**
- * Default document types structured by step.formats.
- */
- private transient final Map<String, DocumentType> _defdoctype = new LinkedHashMap<String, DocumentType>();
-
/**
* File naming strategy enumeration.
*/
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
}
*/
private void loadDefaultDocTypes(final Map<String, Node> children) {
_defdoctype.clear();
+ _defdoctypeKeys.clear();
Node child = children.get("default-doctypes");
- NodeList nlist = child.getChildNodes();
+ if (child != null) {
+ NodeList nlist = child.getChildNodes();
- List<DocumentType> listype = getDocumentTypeService().selectAllTypes();
- Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
- for (Iterator<DocumentType> 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<DocumentType> listype = getDocumentTypeService()
+ .selectAllTypes();
+ Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
+ for (Iterator<DocumentType> 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<String> keys;
+ if (_defdoctypeKeys.containsKey(type)) {
+ keys = _defdoctypeKeys.get(type);
+ } else {
+ keys = new ArrayList<String>();
+ _defdoctypeKeys.put(type, keys);
+ }
+ keys.add(nstep + "." + dext);
+ }
+ }
}
}
}
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) {
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;
/*
* 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(
} catch (FileNotFoundException e) {
Assert.fail("Can't find configuration file: ", e);
}
+ Assert.assertTrue(_documentTypeService.selectAllTypes().size() > 0,
+ "No document types are created.");
List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
Assert.assertTrue(steps.size() > 0, "No steps are created.");
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
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);
*****************************************************************************/
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;
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;
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;
@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.
*/
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<StepDTO> steps = new ArrayList<StepDTO>();
- _scenarioService.checkin(scenarioId, userId, steps);
+ // Simulate checkout
+ List<StepDTO> steps = _scenarioService.getScenarioInfo(scenarioId);
+ _scenarioService.checkout(aScen, user);
+
+ // Prepare test data for checkin
+ // Checkin only two first steps (geom and mesh)
+ List<StepDTO> stepsToCheckin = new ArrayList<StepDTO>();
+ 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) {
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<StepDTO> 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.
*
// 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(
// 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);
List<DocumentType> 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<i>: document type[0] - first type used on the step
// <source-file>.brep
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
ht.saveOrUpdate(pub);
// Attach a file
- ht.saveOrUpdate(pub.value());
+ ht.save(pub.value());
ht.saveOrUpdate(_publicationService.attach(pub, "med"));
}