You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/05/26 14:44:24 UTC

svn commit: r178627 - in /lenya/trunk/src/java/org/apache/lenya/cms/site/usecases: Archive.java Delete.java MoveSubsite.java Restore.java

Author: andreas
Date: Thu May 26 05:44:24 2005
New Revision: 178627

URL: http://svn.apache.org/viewcvs?rev=178627&view=rev
Log:
added archive and restore usecase handlers

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Archive.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/MoveSubsite.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Restore.java
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Archive.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Archive.java?rev=178627&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Archive.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Archive.java Thu May 26 05:44:24 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.site.usecases;
+
+import org.apache.lenya.cms.publication.Publication;
+
+/**
+ * Archive usecase handler.
+ * 
+ * @version $Id:$
+ */
+public class Archive extends MoveSubsite {
+
+    /**
+     * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getSourceAreas()
+     */
+    protected String[] getSourceAreas() {
+        return new String[] { Publication.AUTHORING_AREA };
+    }
+
+    /**
+     * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getTargetArea()
+     */
+    protected String getTargetArea() {
+        return Publication.ARCHIVE_AREA;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getEvent()
+     */
+    protected String getEvent() {
+        return "delete";
+    }
+
+
+}
\ No newline at end of file

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java?rev=178627&r1=178626&r2=178627&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Delete.java Thu May 26 05:44:24 2005
@@ -16,19 +16,7 @@
  */
 package org.apache.lenya.cms.site.usecases;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentIdentityMap;
-import org.apache.lenya.cms.publication.DocumentManager;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.util.DocumentSet;
-import org.apache.lenya.cms.site.SiteUtil;
-import org.apache.lenya.cms.usecase.DocumentUsecase;
-import org.apache.lenya.cms.usecase.UsecaseException;
-import org.apache.lenya.transaction.Transactionable;
 
 /**
  * Delete a document and all its descendants, including all language versions. The documents are
@@ -36,99 +24,27 @@
  * 
  * @version $Id$
  */
-public class Delete extends DocumentUsecase {
+public class Delete extends MoveSubsite {
 
     /**
-     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
+     * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getSourceAreas()
      */
-    protected void doCheckPreconditions() throws Exception {
-        super.doCheckPreconditions();
-        if (hasErrors()) {
-            return;
-        }
-
-        if (!getSourceDocument().getArea().equals(Publication.AUTHORING_AREA)) {
-            addErrorMessage("This usecase can only be invoked in the authoring area!");
-        }
-
-        Document document = getSourceDocument();
-        DocumentIdentityMap identityMap = getDocumentIdentityMap();
-
-        DocumentSet set = SiteUtil.getSubSite(this.manager, document);
-        Document[] documents = set.getDocuments();
-        for (int i = 0; i < documents.length; i++) {
-            Document liveVersion = identityMap.getAreaVersion(documents[i], Publication.LIVE_AREA);
-            if (liveVersion.exists()) {
-                addErrorMessage("delete-doc-live", new String[]{liveVersion.getId()});
-            }
-        }
+    protected String[] getSourceAreas() {
+        return new String[] { Publication.AUTHORING_AREA };
     }
 
     /**
-     * Lock the following objects:
-     * <ul>
-     * <li>all involved documents in the document's area</li>
-     * <li>the trash versions of these documents</li>
-     * <li>the document area's site structure</li>
-     * <li>the trash site structure</li>
-     * </ul>
-     * @see org.apache.lenya.cms.usecase.AbstractUsecase#getObjectsToLock()
+     * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getTargetArea()
      */
-    protected Transactionable[] getObjectsToLock() throws UsecaseException {
-        List nodes = new ArrayList();
-        Document doc = getSourceDocument();
-        try {
-            DocumentSet sources = SiteUtil.getSubSite(this.manager, doc);
-            Document[] docs = sources.getDocuments();
-            for (int i = 0; i < docs.length; i++) {
-                nodes.addAll(Arrays.asList(docs[i].getRepositoryNodes()));
-            }
-
-            DocumentSet targets = SiteUtil.getTransferedSubSite(this.manager,
-                    doc,
-                    Publication.TRASH_AREA,
-                    SiteUtil.MODE_CHANGE_ID);
-            docs = targets.getDocuments();
-            for (int i = 0; i < docs.length; i++) {
-                nodes.addAll(Arrays.asList(docs[i].getRepositoryNodes()));
-            }
-
-            nodes.add(SiteUtil.getSiteStructure(this.manager, doc).getRepositoryNode());
-            nodes.add(SiteUtil.getSiteStructure(this.manager, targets.getDocuments()[0]).getRepositoryNode());
-        } catch (Exception e) {
-            throw new UsecaseException(e);
-        }
-        return (Transactionable[]) nodes.toArray(new Transactionable[nodes.size()]);
+    protected String getTargetArea() {
+        return Publication.TRASH_AREA;
     }
 
     /**
-     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+     * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getEvent()
      */
-    protected void doExecute() throws Exception {
-        super.doExecute();
-
-        Document doc = getSourceDocument();
-        Document target = doc.getIdentityMap().getAreaVersion(doc, Publication.TRASH_AREA);
-        target = SiteUtil.getAvailableDocument(this.manager, target);
-
-        DocumentManager documentManager = null;
-        try {
-            documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
-
-            DocumentSet sources = SiteUtil.getSubSite(this.manager, doc);
-            DocumentSet targets = SiteUtil.getTransferedSubSite(this.manager,
-                    doc,
-                    Publication.TRASH_AREA,
-                    SiteUtil.MODE_CHANGE_ID);
-
-            documentManager.move(sources, targets);
-        } finally {
-            if (documentManager != null) {
-                this.manager.release(documentManager);
-            }
-        }
-
-        setTargetDocument(target);
+    protected String getEvent() {
+        return "delete";
     }
 
-}
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/MoveSubsite.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/MoveSubsite.java?rev=178627&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/MoveSubsite.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/MoveSubsite.java Thu May 26 05:44:24 2005
@@ -0,0 +1,171 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.site.usecases;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.util.DocumentSet;
+import org.apache.lenya.cms.site.SiteUtil;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+import org.apache.lenya.cms.workflow.WorkflowManager;
+import org.apache.lenya.transaction.Transactionable;
+
+/**
+ * Usecase to move a subsite to another area.
+ * 
+ * @version $Id:$
+ */
+public abstract class MoveSubsite extends DocumentUsecase {
+
+    /**
+     * @return The possible source areas.
+     */
+    protected abstract String[] getSourceAreas();
+
+    /**
+     * @return The target area.
+     */
+    protected abstract String getTargetArea();
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
+     */
+    protected void doCheckPreconditions() throws Exception {
+        super.doCheckPreconditions();
+        if (hasErrors()) {
+            return;
+        }
+
+        List sourceAreas = Arrays.asList(getSourceAreas());
+        if (!sourceAreas.contains(getSourceDocument().getArea())) {
+            addErrorMessage("This usecase can only be invoked in the authoring area!");
+        } else {
+
+            Document document = getSourceDocument();
+            DocumentIdentityMap identityMap = getDocumentIdentityMap();
+
+            DocumentSet set = SiteUtil.getSubSite(this.manager, document);
+            Document[] documents = set.getDocuments();
+            for (int i = 0; i < documents.length; i++) {
+                Document liveVersion = identityMap.getAreaVersion(documents[i],
+                        Publication.LIVE_AREA);
+                if (liveVersion.exists()) {
+                    addErrorMessage("delete-doc-live", new String[] { liveVersion.getId() });
+                }
+            }
+            WorkflowManager wfManager = null;
+            try {
+                wfManager = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
+                if (!wfManager.canInvoke(set, getEvent())) {
+                    addErrorMessage("The workflow event cannot be invoked on all documents.");
+                }
+            } finally {
+                if (wfManager != null) {
+                    this.manager.release(wfManager);
+                }
+            }
+        }
+    }
+
+    /**
+     * @return The workflow event.
+     */
+    protected abstract String getEvent();
+
+    /**
+     * Lock the following objects:
+     * <ul>
+     * <li>all involved documents in the document's area</li>
+     * <li>the trash versions of these documents</li>
+     * <li>the document area's site structure</li>
+     * <li>the trash site structure</li>
+     * </ul>
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#getObjectsToLock()
+     */
+    protected Transactionable[] getObjectsToLock() throws UsecaseException {
+        List nodes = new ArrayList();
+        Document doc = getSourceDocument();
+        try {
+            DocumentSet sources = SiteUtil.getSubSite(this.manager, doc);
+            Document[] docs = sources.getDocuments();
+            for (int i = 0; i < docs.length; i++) {
+                nodes.addAll(Arrays.asList(docs[i].getRepositoryNodes()));
+            }
+
+            DocumentSet targets = SiteUtil.getTransferedSubSite(this.manager,
+                    doc,
+                    getTargetArea(),
+                    SiteUtil.MODE_CHANGE_ID);
+            docs = targets.getDocuments();
+            for (int i = 0; i < docs.length; i++) {
+                nodes.addAll(Arrays.asList(docs[i].getRepositoryNodes()));
+            }
+
+            nodes.add(SiteUtil.getSiteStructure(this.manager, doc).getRepositoryNode());
+            nodes.add(SiteUtil.getSiteStructure(this.manager, targets.getDocuments()[0])
+                    .getRepositoryNode());
+        } catch (Exception e) {
+            throw new UsecaseException(e);
+        }
+        return (Transactionable[]) nodes.toArray(new Transactionable[nodes.size()]);
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+     */
+    protected void doExecute() throws Exception {
+
+        Document doc = getSourceDocument();
+        DocumentSet sources = SiteUtil.getSubSite(this.manager, doc);
+
+        Document target = doc.getIdentityMap().getAreaVersion(doc, getTargetArea());
+        target = SiteUtil.getAvailableDocument(this.manager, target);
+
+        WorkflowManager wfManager = null;
+        DocumentManager documentManager = null;
+        try {
+            wfManager = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
+            wfManager.invoke(sources, getEvent(), true);
+
+            documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
+            DocumentSet targets = SiteUtil.getTransferedSubSite(this.manager,
+                    doc,
+                    getTargetArea(),
+                    SiteUtil.MODE_CHANGE_ID);
+            documentManager.move(sources, targets);
+
+        } finally {
+            if (wfManager != null) {
+                this.manager.release(wfManager);
+            }
+            if (documentManager != null) {
+                this.manager.release(documentManager);
+            }
+        }
+
+        setTargetDocument(target);
+
+    }
+
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Restore.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Restore.java?rev=178627&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Restore.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Restore.java Thu May 26 05:44:24 2005
@@ -0,0 +1,28 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.site.usecases;
+
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+
+/**
+ * Restore usecase handler.
+ *
+ * @version $Id:$
+ */
+public class Restore extends DocumentUsecase {
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org