\r
//$Id$\r
- /**\r
- * Copyright (C) 2009 EDIT\r
- * European Distributed Institute of Taxonomy\r
- * http://www.e-taxonomy.eu\r
- *\r
- * The contents of this file are subject to the Mozilla Public License Version 1.1\r
- * See LICENSE.TXT at the top of this package for the full license terms.\r
- */\r
+/**\r
+ * Copyright (C) 2009 EDIT\r
+ * European Distributed Institute of Taxonomy\r
+ * http://www.e-taxonomy.eu\r
+ *\r
+ * The contents of this file are subject to the Mozilla Public License Version 1.1\r
+ * See LICENSE.TXT at the top of this package for the full license terms.\r
+ */\r
package eu.etaxonomy.cdm.api.service;\r
\r
import java.io.Serializable;\r
import org.apache.commons.collections.buffer.CircularFifoBuffer;\r
import org.apache.log4j.Logger;\r
\r
+import eu.etaxonomy.cdm.api.service.dto.CdmEntityIdentifier;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;\r
\r
- /**\r
- * This class represents the result of an update action.\r
- *\r
- * @author k.luther\r
- * @date 11.02.2015\r
- *\r
- */\r
+/**\r
+ * This class represents the result of an update action.\r
+ *\r
+ * @author k.luther\r
+ * @since 11.02.2015\r
+ *\r
+ */\r
public class UpdateResult implements Serializable{\r
\r
+ private static final long serialVersionUID = -7040027587709706700L;\r
\r
- private static final long serialVersionUID = 1L;\r
-\r
- @SuppressWarnings("unused")\r
- private static final Logger logger = Logger.getLogger(UpdateResult.class);\r
-\r
- private Status status = Status.OK;\r
-\r
- private final Collection<Exception> exceptions = new CircularFifoBuffer(10);\r
-\r
- private final Set<CdmBase> upatedObjects = new HashSet<CdmBase>();\r
-\r
- private final Set<CdmBase> unchangedObjects = new HashSet<CdmBase>();\r
-\r
- private CdmBase cdmEntity;\r
-\r
-// private Set<PersistPair> objectsToDelete = new HashSet<PersistPair>();\r
- //\r
-// private Set<PersistPair> objectsToSave = new HashSet<DeleteResult.PersistPair>();\r
-\r
-// protected class PersistPair{\r
-// protected CdmBase objectToPersist;\r
-// protected ICdmEntityDao<CdmBase> dao;\r
-// }\r
-\r
- public enum Status {\r
- OK(0),\r
- ABORT(1),\r
- ERROR(3),\r
- ;\r
-\r
- protected Integer severity;\r
- private Status(int severity){\r
- this.severity = severity;\r
- }\r
-\r
- public int compareSeverity(Status other){\r
- return this.severity.compareTo(other.severity);\r
- }\r
- }\r
-\r
- //***************************** GETTER /SETTER /ADDER *************************/\r
- /**\r
- * The resulting status of an update action.\r
- *\r
- * @see UpdateStatus\r
- * @return\r
- */\r
- public Status getStatus() {\r
- return status;\r
- }\r
- public void setStatus(Status status) {\r
- this.status = status;\r
- }\r
-\r
- /**\r
- * The highest exception that occurred during delete (if any).\r
- * @return\r
- */\r
- public Collection<Exception> getExceptions() {\r
- return exceptions;\r
- }\r
- public void addException(Exception exception) {\r
- this.exceptions.add(exception);\r
- }\r
- public void addExceptions(Collection<Exception> exceptions) {\r
- this.exceptions.addAll(exceptions);\r
- }\r
-\r
- /**\r
- * Related objects that prevent the delete action to take place.\r
- * @return\r
- */\r
- public Set<CdmBase> getUpdatedObjects() {\r
- return upatedObjects;\r
- }\r
- public void addUpdatedObject(CdmBase relatedObject) {\r
- this.upatedObjects.add(relatedObject);\r
- }\r
- public void addUpdatedObjects(Set<? extends CdmBase> updatedObjects) {\r
- this.upatedObjects.addAll(updatedObjects);\r
- }\r
-\r
-\r
-// /**\r
-// * @return\r
-// */\r
-// public Set<PersistPair> getObjectsToDelete() {\r
-// return objectsToDelete;\r
-// }\r
-// public void setObjectsToDelete(Set<PersistPair> objectsToDelete) {\r
-// this.objectsToDelete = objectsToDelete;\r
-// }\r
- //\r
-// /**\r
-// * @return\r
-// */\r
-// public Set<PersistPair> getObjectsToSave() {\r
-// return objectsToSave;\r
-// }\r
-// public void setObjectsToSave(Set<PersistPair> objectsToSave) {\r
-// this.objectsToSave = objectsToSave;\r
-// }\r
-\r
-\r
- //****************** CONVENIENCE *********************************************/\r
-\r
- /**\r
- * Sets the status to {@link DeleteStatus#ERROR} if not yet set to a more serious\r
- * status.\r
- */\r
- public void setError(){\r
- setMaxStatus(Status.ERROR);\r
- }\r
-\r
- /**\r
- * Sets the status to {@link DeleteStatus#ABORT} if not yet set to a more serious\r
- * status.\r
- */\r
- public void setAbort(){\r
- setMaxStatus(Status.ABORT);\r
- }\r
-\r
- /**\r
- * Sets status to most severe status. If maxStatus is more severe then existing status\r
- * existing status is set to maxStatus. Otherwise nothing changes.\r
- * If minStatus is more severe then given status minStatus will be the new status.\r
- * @param maxStatus\r
- */\r
- public void setMaxStatus(Status maxStatus) {\r
- if (this.status.compareSeverity(maxStatus) < 0){\r
- this.status = maxStatus;\r
- }\r
- }\r
-\r
- public void includeResult(UpdateResult includedResult){\r
- this.setMaxStatus(includedResult.getStatus());\r
- this.addExceptions(includedResult.getExceptions());\r
- this.addUpdatedObjects(includedResult.getUpdatedObjects());\r
- }\r
-\r
- public boolean isOk(){\r
- return this.status == Status.OK;\r
- }\r
-\r
- public boolean isAbort(){\r
- return this.status == Status.ABORT;\r
- }\r
-\r
- public boolean isError(){\r
- return this.status == Status.ERROR;\r
- }\r
-\r
-\r
-\r
- @Override\r
- public String toString(){\r
- String separator = ", ";\r
- String exceptionString = "";\r
- for (Exception exception : exceptions) {\r
- exceptionString += exception.getLocalizedMessage()+separator;\r
- }\r
- if(exceptionString.endsWith(separator)){\r
- exceptionString = exceptionString.substring(0, exceptionString.length()-separator.length());\r
- }\r
- String relatedObjectString = "";\r
- for (CdmBase upatedObject: upatedObjects) {\r
- if(upatedObject instanceof IIdentifiableEntity){\r
- relatedObjectString += ((IIdentifiableEntity) upatedObject).getTitleCache()+separator;\r
- }\r
- else{\r
- relatedObjectString += upatedObject.toString()+separator;\r
- }\r
- }\r
- if(relatedObjectString.endsWith(separator)){\r
- relatedObjectString = relatedObjectString.substring(0, relatedObjectString.length()-separator.length());\r
- }\r
- return "[DeleteResult]\n" +\r
- "Status: " + status.toString()+"\n" +\r
- "Exceptions: " + exceptionString+"\n" +\r
- "Related Objects: "+relatedObjectString;\r
- }\r
- public void setCdmEntity(CdmBase cdmBase) {\r
- this.cdmEntity = cdmBase;\r
-\r
- }\r
-\r
- public CdmBase getCdmEntity(){\r
- return cdmEntity;\r
- }\r
-\r
- public Set<CdmBase> getUnchangedObjects() {\r
- return unchangedObjects;\r
+ @SuppressWarnings("unused")\r
+ private static final Logger logger = Logger.getLogger(UpdateResult.class);\r
+\r
+ private Status status = Status.OK;\r
+\r
+ @SuppressWarnings("unchecked")\r
+ private final Collection<Exception> exceptions = new CircularFifoBuffer(10);\r
+\r
+ private Set<CdmBase> updatedObjects = new HashSet<>();\r
+\r
+ private final Set<CdmEntityIdentifier> updatedCdmIds = new HashSet<>();\r
+\r
+ private final Set<CdmBase> unchangedObjects = new HashSet<>();\r
+\r
+ private CdmBase cdmEntity;\r
+\r
+\r
+ // private Set<PersistPair> objectsToDelete = new HashSet<>();\r
+ //\r
+ // private Set<PersistPair> objectsToSave = new HashSet<>();\r
+\r
+ // protected class PersistPair{\r
+ // protected CdmBase objectToPersist;\r
+ // protected ICdmEntityDao<CdmBase> dao;\r
+ // }\r
+\r
+ public enum Status {\r
+ OK(0),\r
+ ABORT(1),\r
+ ERROR(3),\r
+ ;\r
+\r
+ protected Integer severity;\r
+ private Status(int severity){\r
+ this.severity = severity;\r
+ }\r
+\r
+ public int compareSeverity(Status other){\r
+ return this.severity.compareTo(other.severity);\r
}\r
+ }\r
+\r
+ //***************************** GETTER /SETTER /ADDER *************************/\r
+ /**\r
+ * The resulting status of an update action.\r
+ *\r
+ * @see UpdateStatus\r
+ * @return\r
+ */\r
+ public Status getStatus() {\r
+ return status;\r
+ }\r
+ public void setStatus(Status status) {\r
+ this.status = status;\r
+ }\r
+\r
+ /**\r
+ * The highest exception that occurred during delete (if any).\r
+ * @return\r
+ */\r
+ public Collection<Exception> getExceptions() {\r
+ return exceptions;\r
+ }\r
+ public void addException(Exception exception) {\r
+ this.exceptions.add(exception);\r
+ }\r
+ public void addExceptions(Collection<Exception> exceptions) {\r
+ this.exceptions.addAll(exceptions);\r
+ }\r
+\r
+ /**\r
+ * Related objects that prevent the delete action to take place.\r
+ * @return\r
+ */\r
+ public Set<CdmEntityIdentifier> getUpdatedCdmIds() {\r
+ return updatedCdmIds;\r
+ }\r
+ public void addUpdatedCdmId(CdmEntityIdentifier cdmId) {\r
+ this.updatedCdmIds.add(cdmId);\r
+ }\r
+ public void addUpdatedCdmIds(Set<CdmEntityIdentifier> updatedCdmIds) {\r
+ this.updatedCdmIds.addAll(updatedCdmIds);\r
+ }\r
+\r
+\r
+ public Set<CdmBase> getUpdatedObjects() {\r
+ return updatedObjects;\r
+ }\r
+ public void addUpdatedObject(CdmBase relatedObject) {\r
+ this.updatedObjects.add(relatedObject);\r
+ }\r
+ public void addUpdatedObjects(Set<? extends CdmBase> updatedObjects) {\r
+ this.updatedObjects.addAll(updatedObjects);\r
+ }\r
+\r
+ // /**\r
+ // * @return\r
+ // */\r
+ // public Set<PersistPair> getObjectsToDelete() {\r
+ // return objectsToDelete;\r
+ // }\r
+ // public void setObjectsToDelete(Set<PersistPair> objectsToDelete) {\r
+ // this.objectsToDelete = objectsToDelete;\r
+ // }\r
+ //\r
+ // /**\r
+ // * @return\r
+ // */\r
+ // public Set<PersistPair> getObjectsToSave() {\r
+ // return objectsToSave;\r
+ // }\r
+ // public void setObjectsToSave(Set<PersistPair> objectsToSave) {\r
+ // this.objectsToSave = objectsToSave;\r
+ // }\r
+\r
+\r
+ //****************** CONVENIENCE *********************************************/\r
+\r
+ /**\r
+ * Sets the status to {@link DeleteStatus#ERROR} if not yet set to a more serious\r
+ * status.\r
+ */\r
+ public void setError(){\r
+ setMaxStatus(Status.ERROR);\r
+ }\r
+\r
+ /**\r
+ * Sets the status to {@link DeleteStatus#ABORT} if not yet set to a more serious\r
+ * status.\r
+ */\r
+ public void setAbort(){\r
+ setMaxStatus(Status.ABORT);\r
+ }\r
+\r
+ /**\r
+ * Sets status to most severe status. If maxStatus is more severe then existing status\r
+ * existing status is set to maxStatus. Otherwise nothing changes.\r
+ * If minStatus is more severe then given status minStatus will be the new status.\r
+ * @param maxStatus\r
+ */\r
+ public void setMaxStatus(Status maxStatus) {\r
+ if (this.status.compareSeverity(maxStatus) < 0){\r
+ this.status = maxStatus;\r
+ }\r
+ }\r
+\r
+ public void includeResult(UpdateResult includedResult){\r
+\r
+ this.setMaxStatus(includedResult.getStatus());\r
+ this.addExceptions(includedResult.getExceptions());\r
+ this.addUpdatedObjects(includedResult.getUpdatedObjects());\r
+ //also add cdm entity of included result to updated objects\r
+ if(includedResult.getCdmEntity()!=null){\r
+ this.getUpdatedObjects().add(includedResult.getCdmEntity());\r
+ }\r
+ }\r
+\r
+ public boolean isOk(){\r
+ return this.status == Status.OK;\r
+ }\r
+\r
+ public boolean isAbort(){\r
+ return this.status == Status.ABORT;\r
+ }\r
+\r
+ public boolean isError(){\r
+ return this.status == Status.ERROR;\r
+ }\r
+\r
+\r
+\r
+ @Override\r
+ public String toString(){\r
+ String separator = ", ";\r
+ String exceptionString = "";\r
+ for (Exception exception : exceptions) {\r
+ exceptionString += exception.getLocalizedMessage()+separator;\r
+ }\r
+ if(exceptionString.endsWith(separator)){\r
+ exceptionString = exceptionString.substring(0, exceptionString.length()-separator.length());\r
+ }\r
+ String relatedObjectString = "";\r
+ for (CdmBase upatedObject: updatedObjects) {\r
+ if(upatedObject instanceof IIdentifiableEntity){\r
+ relatedObjectString += ((IIdentifiableEntity) upatedObject).getTitleCache()+separator;\r
+ }\r
+ else{\r
+ relatedObjectString += upatedObject.toString()+separator;\r
+ }\r
+ }\r
+ if(relatedObjectString.endsWith(separator)){\r
+ relatedObjectString = relatedObjectString.substring(0, relatedObjectString.length()-separator.length());\r
+ }\r
+ return "[UpdateResult]\n" +\r
+ "Status: " + status.toString()+"\n" +\r
+ "Exceptions: " + exceptionString+"\n" +\r
+ "Related Objects: "+relatedObjectString;\r
+ }\r
+ public void setCdmEntity(CdmBase cdmBase) {\r
+ this.cdmEntity = cdmBase;\r
+\r
+ }\r
+\r
+\r
+ public CdmBase getCdmEntity(){\r
+ return cdmEntity;\r
+ }\r
+\r
+ public Set<CdmBase> getUnchangedObjects() {\r
+ return unchangedObjects;\r
+ }\r
+\r
+ public void addUnchangedObjects(Set<? extends CdmBase> unchangedObjects) {\r
+ this.unchangedObjects.addAll(unchangedObjects);\r
+ }\r
+ public void addUnChangedObject(CdmBase unchangedObject) {\r
+ this.unchangedObjects.add(unchangedObject);\r
+ }\r
\r
- public void addUnchangedObjects(Set<? extends CdmBase> unchangedObjects) {\r
- this.unchangedObjects.addAll(unchangedObjects);\r
- }\r
- public void addUnChangedObject(CdmBase unchangedObject) {\r
- this.unchangedObjects.add(unchangedObject);\r
- }\r
\r
\r
}\r