Author: glandais Date: 2008-02-17 19:46:19 +0000 (Sun, 17 Feb 2008) New Revision: 1046 Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDelete.java trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementDelete.tml trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/WEB-INF/app.properties trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/WEB-INF/app_fr.properties Log: Delete action business rules Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDelete.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDelete.java 2008-02-17 19:45:33 UTC (rev 1045) +++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDelete.java 2008-02-17 19:46:19 UTC (rev 1046) @@ -17,16 +17,87 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.web.pages; +import java.util.HashSet; +import java.util.Set; + +import org.apache.tapestry.ComponentResources; import org.apache.tapestry.annotations.InjectPage; +import org.apache.tapestry.annotations.Persist; +import org.apache.tapestry.annotations.Retain; +import org.apache.tapestry.beaneditor.BeanModel; +import org.apache.tapestry.ioc.annotations.Inject; +import org.apache.tapestry.services.BeanModelSource; +import de.hsofttec.t5components.annotations.SetterGetter; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.entities.metadata.Version; import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; import fr.cemagref.simexplorer.is.ui.web.services.RemoteStorageService; +import fr.cemagref.simexplorer.is.ui.web.tools.MetaDataModelFactory; /** * The Class ElementDelete. */ -public class ElementDelete extends ElementPage { +public class ElementDelete extends ElementPageDetail { + /** The model. */ + @Retain + private BeanModel model; + + /** The bean model source. */ + @Inject + private BeanModelSource beanModelSource; + + /** The resources. */ + @Inject + private ComponentResources resources; + + /** The used by. */ + @Persist + private MetaData[] usedBy; + + /** The all used by list. */ + @Persist + private Set<MetaData> allUsedByList; + + /** The _element. */ + @SetterGetter + private MetaData _listMetadata; + + /** + * Page loaded. + */ + void pageLoaded() { + model = MetaDataModelFactory.getMetaDataModel(beanModelSource, resources, false); + } + + /* (non-Javadoc) + * @see fr.cemagref.simexplorer.is.ui.web.pages.ElementPage#setup(java.lang.String, java.lang.String) + */ + @Override + public void setup(String uuid, String version) throws SimExplorerException { + super.setup(uuid, version); + + // searching elements using element trying to be deleted + + usedBy = RemoteStorageService.getStorageService().getMetadatasUsedBy(getToken(), getMetadata().getUuid(), + getMetadata().getVersion().toString()); + if (usedBy.length == 0) { + allUsedByList = new HashSet<MetaData>(); + Version[] versions = RemoteStorageService.getStorageService().getVersions(getToken(), + getMetadata().getUuid()); + for (int i = 0; i < versions.length; i++) { + Version aVersion = versions[i]; + MetaData[] versionUsedBy = RemoteStorageService.getStorageService().getMetadatasUsedBy(getToken(), + getMetadata().getUuid(), aVersion.toString()); + for (int j = 0; j < versionUsedBy.length; j++) { + MetaData metaData = versionUsedBy[j]; + allUsedByList.add(metaData); + } + } + } + } + /** The element detail. */ @InjectPage private ElementDetail elementDetail; @@ -35,7 +106,8 @@ * On action from confirm. * * @return the object - * @throws SimExplorerException + * + * @throws SimExplorerException the sim explorer exception */ public Object onActionFromConfirm() throws SimExplorerException { RemoteStorageService.getStorageService().deleteElement(getToken(), getMetadata().getUuid(), @@ -47,16 +119,97 @@ * On action from confirm all. * * @return the object - * @throws SimExplorerException + * + * @throws SimExplorerException the sim explorer exception */ public Object onActionFromConfirmAll() throws SimExplorerException { RemoteStorageService.getStorageService().deleteElement(getToken(), getMetadata().getUuid()); return elementDetail; } + /** + * Can be deleted. + * + * @return true, if successful + */ + public boolean isCanBeDeleted() { + return (usedBy.length == 0); + } + + /** + * Can be deleted in all versions. + * + * @return true, if successful + */ + public boolean isCanBeDeletedInAllVersions() { + return (allUsedByList.size() == 0); + } + + /** + * Gets the detail element context. + * + * @return the detail element context + */ + public String getDetailElementContext() { + return _listMetadata.getUuid() + "," + _listMetadata.getVersion(); + } + + /** + * Gets the model. + * + * @return the model + */ + public BeanModel getModel() { + return model; + } + + /** + * On action from detail element using. + * + * @param context the context + * + * @return the object + * + * @throws SimExplorerException the sim explorer exception + */ + public Object onActionFromDetailElementUsedBy(String context) throws SimExplorerException { + return onDetails(context); + } + + /** + * On action from detail element used by any version. + * + * @param context the context + * + * @return the object + * + * @throws SimExplorerException the sim explorer exception + */ + public Object onActionFromDetailElementUsedByAnyVersion(String context) throws SimExplorerException { + return onDetails(context); + } + + /** + * Gets the used by. + * + * @return the used by + */ + public MetaData[] getUsedBy() { + return usedBy; + } + + /** + * Gets the all used by list. + * + * @return the all used by list + */ + public Set<MetaData> getAllUsedByList() { + return allUsedByList; + } + /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.ui.web.pages.security.ProtectedPage#getWindowTitle() - */ + * @see fr.cemagref.simexplorer.is.ui.web.pages.security.ProtectedPage#getWindowTitle() + */ @Override public String getWindowTitle() { return getMessages().get("simexplorer.ui.web.title.deleteelement"); Modified: trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementDelete.tml =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementDelete.tml 2008-02-17 19:45:33 UTC (rev 1045) +++ trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementDelete.tml 2008-02-17 19:46:19 UTC (rev 1046) @@ -1,18 +1,53 @@ <t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" title="${windowtitle}"> - <p>${message:simexplorer.ui.web.delete.confirmdelete}</p> - <p><t:actionlink t:id="confirm">${message:simexplorer.ui.web.confirm}</t:actionlink> - - <t:back label="${message:simexplorer.ui.web.cancel}" /></p> + <t:if test="canBeDeleted"> - <hr /> + <p>${message:simexplorer.ui.web.delete.confirmdelete}</p> + <p><t:actionlink t:id="confirm">${message:simexplorer.ui.web.confirm}</t:actionlink> + - <t:back label="${message:simexplorer.ui.web.cancel}" /></p> - <p>${message:simexplorer.ui.web.delete.confirmdeleteAll}</p> - <p><t:actionlink t:id="confirmall">${message:simexplorer.ui.web.confirm}</t:actionlink> - - <t:back label="${message:simexplorer.ui.web.cancel}" /></p> + <t:parameter name="else"> + {message:simexplorer.ui.web.delete.deleteimpossible} + + <table t:type="Grid" source="usedBy" row="listMetadata" model="model"> + <t:parameter name="uuidCell"> + <t:actionlink t:id="detailElementUsedBy" + context="${detailElementContext}">${message:simexplorer.ui.web.elementlist.details}</t:actionlink> + </t:parameter> + </table> + </t:parameter> + + </t:if> + <hr /> + <t:if test="canBeDeleted"> + <t:if test="canBeDeletedInAllVersions"> + + <p>${message:simexplorer.ui.web.delete.confirmdeleteAll}</p> + <p><t:actionlink t:id="confirmall">${message:simexplorer.ui.web.confirm}</t:actionlink> + - <t:back label="${message:simexplorer.ui.web.cancel}" /></p> + + <t:parameter name="else"> + {message:simexplorer.ui.web.delete.deleteimpossibleAll} + + <table t:type="Grid" source="allUsedByList" row="listMetadata" + model="model"> + <t:parameter name="uuidCell"> + <t:actionlink t:id="detailElementUsedByAnyVersion" + context="${detailElementContext}">${message:simexplorer.ui.web.elementlist.details}</t:actionlink> + </t:parameter> + </table> + + </t:parameter> + + </t:if> + + <hr /> + </t:if> + <p><t:back label="${message:simexplorer.ui.web.back}" /></p> </t:layout> Modified: trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/WEB-INF/app.properties =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/WEB-INF/app.properties 2008-02-17 19:45:33 UTC (rev 1045) +++ trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/WEB-INF/app.properties 2008-02-17 19:46:19 UTC (rev 1046) @@ -98,6 +98,8 @@ simexplorer.ui.web.delete.confirmdelete=Confirm deletion of element simexplorer.ui.web.delete.confirmdeleteAll=Confirm deletion of element in all versions +simexplorer.ui.web.delete.deleteimpossible=This item cannot be delete, as following elements are using this item : +simexplorer.ui.web.delete.deleteimpossibleAll=This item cannot be delete in all of its revisions, as following elements are using this item in a version : simexplorer.ui.web.export.downloadxml=Download XML simexplorer.ui.web.export.downloadfull=Download XML and all attachments as ZIP archive Modified: trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/WEB-INF/app_fr.properties =================================================================== --- trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/WEB-INF/app_fr.properties 2008-02-17 19:45:33 UTC (rev 1045) +++ trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/WEB-INF/app_fr.properties 2008-02-17 19:46:19 UTC (rev 1046) @@ -98,6 +98,8 @@ simexplorer.ui.web.delete.confirmdelete=Confirmer la suppression de l'élément simexplorer.ui.web.delete.confirmdeleteAll=Confirmer la suppression de l'élément dans toutes ses versions +simexplorer.ui.web.delete.deleteimpossible=Cet élément ne peut pas être supprimé, au moins un autre élément l'utilise : +simexplorer.ui.web.delete.deleteimpossibleAll=Cet élément ne peut pas être supprimé dans toutes ses versions, au moins un autre élément l'utilise dans une de ses versions : simexplorer.ui.web.export.downloadxml=Télécharger le fichier XML simexplorer.ui.web.export.downloadfull=Télécharger le fichier XML et tous ces fichiers dans une archive ZIP
participants (1)
-
glandais@users.labs.libre-entreprise.org