r1254 - in trunk/simexplorer-is: simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine src/site/fr/rst
Author: glandais Date: 2008-02-26 14:50:42 +0000 (Tue, 26 Feb 2008) New Revision: 1254 Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java trunk/simexplorer-is/src/site/fr/rst/todo.rst Log: DeleteElement Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-26 14:07:15 UTC (rev 1253) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-26 14:50:42 UTC (rev 1254) @@ -43,6 +43,7 @@ import com.healthmarketscience.rmiio.SerializableInputStream; +import fr.cemagref.simexplorer.is.entities.EntityTypeEnum; import fr.cemagref.simexplorer.is.entities.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; @@ -493,37 +494,24 @@ * @throws SimExplorerException the sim explorer exception */ private boolean canBeDeleted(String token, String uuid, String version) throws SimExplorerException { - // check if element has some parents - MetaData[] metadatasUsedBy = getMetadatasUsedBy(token, uuid, version); - if (metadatasUsedBy.length > 1) { - // element is used somewhere - return false; - } else if (metadatasUsedBy.length == 1) { - // element can be delete if parent can be deleted - return canBeDeleted(token, metadatasUsedBy[0].getUuid(), metadatasUsedBy[0].getVersion().toString()); + MetaData metadata = getMetadata(token, uuid, version); + + // ExplorationApplication can always be deleted + if (metadata.getEntityType() == EntityTypeEnum.ExplorationApplication) { + return true; } - return true; - } - /** - * Can be deleted. - * - * @param token the token - * @param uuid the uuid - * - * @return true, if successful - * - * @throws SimExplorerException the sim explorer exception - */ - private boolean canBeDeleted(String token, String uuid) throws SimExplorerException { - Version[] versions = getVersions(token, uuid); - // element can be delete if all versions can be deleted - for (Version version : versions) { - if (!canBeDeleted(token, uuid, version.toString())) { - return false; - } + // get parent elements + MetaData[] metadatasUsedBy = getMetadatasUsedBy(token, uuid, version); + + // ED and Components can be delete only if they are used at most by one EA + if ((metadata.getEntityType() == EntityTypeEnum.ExplorationData) + || (metadata.getEntityType() == EntityTypeEnum.Component)) { + return (metadatasUsedBy.length <= 1); } - return true; + + // A element can be deleted only if it has not any parent + return (metadatasUsedBy.length == 0); } /** @@ -534,87 +522,52 @@ * @param version the version * @param set the set * - * @return is an orphan - * * @throws SimExplorerException the sim explorer exception */ - private boolean getOrphans(String token, String uuid, String version, Set<MetaData> set) - throws SimExplorerException { + private void getDeletableChildren(String token, String uuid, String version, Set<MetaData> set) throws SimExplorerException { + // this item is an orphan only if it has one parent maximum MetaData[] metadatasUsedBy = getMetadatasUsedBy(token, uuid, version); - if (metadatasUsedBy.length != 1) { - return false; - } + if (metadatasUsedBy.length <= 1) { + // mark as deletable + set.add(getMetadata(token, uuid, version)); - // list children - MetaData[] metadatasUsing = getMetadatasUsing(token, uuid, version); + // list children + MetaData[] metadatasUsing = getMetadatasUsing(token, uuid, version); - boolean result = true; - - for (MetaData childMetaData : metadatasUsing) { - if (getOrphans(token, childMetaData.getUuid(), childMetaData.getVersion().toString(), set)) { - set.add(childMetaData); - } else { - result = false; + // recursion + for (MetaData childMetaData : metadatasUsing) { + getDeletableChildren(token, childMetaData.getUuid(), childMetaData.getVersion().toString(), set); } } - - return result; } /** - * Gets the orphans (items that can be deleted). - * - * @param token the token - * @param uuid the uuid - * @param set the set - * - * @throws SimExplorerException the sim explorer exception - */ - private void getOrphans(String token, String uuid, Set<MetaData> set) throws SimExplorerException { - Version[] versions = getVersions(token, uuid); - for (Version version : versions) { - getOrphans(token, uuid, version.toString(), set); - } - } - - /** * Gets the parents. * * @param token the token * @param uuid the uuid * @param version the version - * @param set the set * + * @return the parent + * * @throws SimExplorerException the sim explorer exception */ - private void getParents(String token, String uuid, String version, Set<MetaData> set) throws SimExplorerException { + private MetaData getDeletableParent(String token, String uuid, String version) throws SimExplorerException { + MetaData metadata = getMetadata(token, uuid, version); - MetaData[] metadatasUsedBy = getMetadatasUsedBy(token, uuid, version); - - if (metadatasUsedBy.length == 1) { - set.add(metadatasUsedBy[0]); - getParents(token, metadatasUsedBy[0].getUuid(), metadatasUsedBy[0].getVersion().toString(), set); + // ED and Components can be delete only if they are used at most by one EA + if ((metadata.getEntityType() == EntityTypeEnum.ExplorationData) + || (metadata.getEntityType() == EntityTypeEnum.Component)) { + // get parent elements + MetaData[] metadatasUsedBy = getMetadatasUsedBy(token, uuid, version); + if (metadatasUsedBy.length == 1) { + return metadatasUsedBy[0]; + } } - + return null; } /** - * Gets the parents. - * - * @param token the token - * @param uuid the uuid - * @param set the set - * - * @throws SimExplorerException the sim explorer exception - */ - private void getParents(String token, String uuid, Set<MetaData> set) throws SimExplorerException { - Version[] versions = getVersions(token, uuid); - for (Version version : versions) { - getParents(token, uuid, version.toString(), set); - } - } - - /** * Raw delete element. * * @param token the token @@ -640,51 +593,35 @@ throw new SimExplorerBusinessException(_("simexplorer.service.business.notdeletable")); } + MetaData deletableParent = getDeletableParent(token, uuid, version); + if (deletableParent != null) { + deleteElement(token, deletableParent.getUuid(), deletableParent.getVersion().toString()); + return; + } + Set<MetaData> elementsToDelete = new HashSet<MetaData>(); - getOrphans(token, uuid, version, elementsToDelete); - getParents(token, uuid, version, elementsToDelete); + getDeletableChildren(token, uuid, version, elementsToDelete); for (MetaData orphan : elementsToDelete) { rawDeleteElement(token, orphan.getUuid(), orphan.getVersion().toString()); } - rawDeleteElement(token, uuid, version); getStorageEngine().commit(); } - /** - * Delete elements. - * - * @param token the token - * @param uuid the uuid - * - * @throws SimExplorerException the sim explorer exception - */ - private void deleteElements(String token, String uuid) throws SimExplorerException { - List<Version> versions = getStorageEngine().getVersions(token, uuid); - for (Version version : versions) { - rawDeleteElement(token, uuid, version.toString()); - } - } - /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.service.StorageService#deleteElement(java.lang.String, java.lang.String) */ public void deleteElement(String token, String uuid) throws SimExplorerException { - if (!canBeDeleted(token, uuid)) { - throw new SimExplorerBusinessException(_("simexplorer.service.business.notdeletable")); + Version[] versions = getVersions(token, uuid); + for (Version version : versions) { + if (!canBeDeleted(token, uuid, version.toString())) { + throw new SimExplorerBusinessException(_("simexplorer.service.business.notdeletable")); + } } - - Set<MetaData> elementsToDelete = new HashSet<MetaData>(); - getOrphans(token, uuid, elementsToDelete); - getParents(token, uuid, elementsToDelete); - - for (MetaData orphan : elementsToDelete) { - rawDeleteElement(token, orphan.getUuid(), orphan.getVersion().toString()); + for (Version version : versions) { + deleteElement(token, uuid, version.toString()); } - - deleteElements(token, uuid); - getStorageEngine().commit(); } /** Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-26 14:07:15 UTC (rev 1253) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-26 14:50:42 UTC (rev 1254) @@ -320,11 +320,6 @@ */ public void deleteElement(String token, String uuid, Version version) throws SimExplorerException { MetaData element = getMetadata(token, uuid, version); - // FIXME delete attachments - // List<Attachment> attachments = element.getAttachments(); - // for (Attachment attachment : attachments) { - // attachmentHandler.deleteData(element, attachment); - // } database.deleteElement(element); } Modified: trunk/simexplorer-is/src/site/fr/rst/todo.rst =================================================================== --- trunk/simexplorer-is/src/site/fr/rst/todo.rst 2008-02-26 14:07:15 UTC (rev 1253) +++ trunk/simexplorer-is/src/site/fr/rst/todo.rst 2008-02-26 14:50:42 UTC (rev 1254) @@ -40,10 +40,6 @@ Serveur ------- - - (NOK) Suppression : La règle de gestion "suppression d'un CE/DE entraîne la -suppression de l'AE (si elle est la seule à l'utiliser)" n'est pas -correctement implémentée (suppression récursive de tous les parents si -ils sont les seul à utiliser l'élément) - (NOK) Gestion du tri sur toutes les colonnes pour les recherches (tests) - (NOK) Créer les interfaces accessibles via d'autres protocoles que RMI (WebService, CORBA).
participants (1)
-
glandais@users.labs.libre-entreprise.org