Author: andreas
Date: Fri Dec 19 13:29:54 2008
New Revision: 728149
URL: http://svn.apache.org/viewvc?rev=728149&view=rev
Log:
Parameterize publish and deactivate usecases to skip check for missing live ancestors or live children, resp.
Modified:
lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Deactivate.java
lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java
Modified: lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Deactivate.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Deactivate.java?rev=728149&r1=728148&r2=728149&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Deactivate.java (original)
+++ lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Deactivate.java Fri Dec 19 13:29:54 2008
@@ -25,9 +25,11 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.lenya.cms.linking.LinkManager;
import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.DocumentManager;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.site.NodeSet;
+import org.apache.lenya.cms.site.SiteException;
import org.apache.lenya.cms.site.SiteNode;
import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.usecase.UsecaseException;
@@ -39,6 +41,12 @@
* @version $Id$
*/
public class Deactivate extends InvokeWorkflow {
+
+ /**
+ * If the usecase should check for live children in {@link #checkPreconditions()}.
+ * Type: {@link Boolean} or {@link String}
+ */
+ public static final String PARAM_CHECK_LIVE_CHILDREN = "checkLiveChildren";
protected static final String LINKS_TO_DOCUMENT = "linksToDocument";
@@ -63,20 +71,34 @@
if (!doc.existsAreaVersion(Publication.LIVE_AREA)) {
addErrorMessage("This usecase can only be invoked when the live version exists.");
} else {
- Document liveDoc = doc.getAreaVersion(Publication.LIVE_AREA);
- NodeSet subSite = SiteUtil.getSubSite(this.manager, liveDoc.getLink().getNode());
- SiteNode node = liveDoc.getLink().getNode();
- subSite.remove(node);
-
- if (!subSite.isEmpty()) {
- addErrorMessage("You can't deactivate this document because it has children.");
- }
+ checkChildren();
setParameter(LINKS_TO_DOCUMENT, new LinkList(this.manager, doc));
}
}
}
/**
+ * @see #PARAM_CHECK_LIVE_CHILDREN
+ * @throws Exception if an error occurs.
+ */
+ protected void checkChildren() throws Exception {
+
+ if (!getParameterAsBoolean(PARAM_CHECK_LIVE_CHILDREN, true)) {
+ return;
+ }
+
+ Document doc = getSourceDocument();
+ Document liveDoc = doc.getAreaVersion(Publication.LIVE_AREA);
+ NodeSet subSite = SiteUtil.getSubSite(this.manager, liveDoc.getLink().getNode());
+ SiteNode node = liveDoc.getLink().getNode();
+ subSite.remove(node);
+
+ if (!subSite.isEmpty()) {
+ addErrorMessage("You can't deactivate this document because it has children.");
+ }
+ }
+
+ /**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
*/
protected org.apache.lenya.cms.repository.Node[] getNodesToLock() throws UsecaseException {
Modified: lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java?rev=728149&r1=728148&r2=728149&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java (original)
+++ lenya/trunk/src/modules-core/workflow/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java Fri Dec 19 13:29:54 2008
@@ -39,6 +39,7 @@
import org.apache.lenya.cms.linking.LinkManager;
import org.apache.lenya.cms.linking.LinkResolver;
import org.apache.lenya.cms.linking.LinkTarget;
+import org.apache.lenya.cms.metadata.MetaDataException;
import org.apache.lenya.cms.metadata.dublincore.DublinCoreHelper;
import org.apache.lenya.cms.observation.RepositoryEvent;
import org.apache.lenya.cms.observation.RepositoryEventFactory;
@@ -73,6 +74,12 @@
*/
public class Publish extends InvokeWorkflow {
+ /**
+ * If the usecase should check for missing live ancestors in {@link #checkPreconditions()}.
+ * Type: {@link Boolean} or {@link String}
+ */
+ public static final String PARAM_CHECK_MISSING_ANCESTORS = "checkMissingAncestors";
+
protected static final String MESSAGE_SUBJECT = "notification-message";
protected static final String MESSAGE_DOCUMENT_PUBLISHED = "document-published";
protected static final String SCHEDULE = "schedule";
@@ -80,7 +87,7 @@
protected static final String CAN_SEND_NOTIFICATION = "canSendNotification";
protected static final String SEND_NOTIFICATION = "sendNotification";
protected static final String UNPUBLISHED_LINKS = "unpublishedLinks";
-
+
/**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
*/
@@ -187,69 +194,82 @@
if (!hasErrors()) {
Document document = getSourceDocument();
-
if (!document.getArea().equals(Publication.AUTHORING_AREA)) {
addErrorMessage("This usecase can only be invoked from the authoring area.");
return;
}
- Publication publication = document.getPublication();
- DocumentFactory map = document.getFactory();
- SiteStructure liveSite = publication.getArea(Publication.LIVE_AREA).getSite();
+ checkMissingAncestors();
+
+ if (hasBrokenLinks()) {
+ addInfoMessage("publish-broken-links");
+ }
+ }
+ }
- List missingDocuments = new ArrayList();
+ /**
+ * @see #PARAM_CHECK_MISSING_ANCESTORS
+ * @throws Exception if an error occurs.
+ */
+ protected void checkMissingAncestors() throws Exception {
+
+ if (!getParameterAsBoolean(PARAM_CHECK_MISSING_ANCESTORS, true)) {
+ return;
+ }
+
+ Document document = getSourceDocument();
+ Publication publication = document.getPublication();
+ DocumentFactory map = document.getFactory();
+ SiteStructure liveSite = publication.getArea(Publication.LIVE_AREA).getSite();
- ServiceSelector selector = null;
- SiteManager siteManager = null;
- try {
- selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
- siteManager = (SiteManager) selector.select(publication.getSiteManagerHint());
+ List missingDocuments = new ArrayList();
- if (!liveSite.contains(document.getPath())) {
- DocumentLocator liveLoc = document.getLocator().getAreaVersion(
- Publication.LIVE_AREA);
- DocumentLocator[] requiredNodes = siteManager
- .getRequiredResources(map, liveLoc);
- for (int i = 0; i < requiredNodes.length; i++) {
- String path = requiredNodes[i].getPath();
- if (!liveSite.contains(path)) {
- Link link = getExistingLink(path, document);
- if (link != null) {
- missingDocuments.add(link.getDocument());
- }
- }
+ ServiceSelector selector = null;
+ SiteManager siteManager = null;
+ try {
+ selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
+ siteManager = (SiteManager) selector.select(publication.getSiteManagerHint());
+ if (!liveSite.contains(document.getPath())) {
+ DocumentLocator liveLoc = document.getLocator().getAreaVersion(
+ Publication.LIVE_AREA);
+ DocumentLocator[] requiredNodes = siteManager
+ .getRequiredResources(map, liveLoc);
+ for (int i = 0; i < requiredNodes.length; i++) {
+ String path = requiredNodes[i].getPath();
+ if (!liveSite.contains(path)) {
+ Link link = getExistingLink(path, document);
+ if (link != null) {
+ missingDocuments.add(link.getDocument());
+ }
}
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (selector != null) {
- if (siteManager != null) {
- selector.release(siteManager);
- }
- this.manager.release(selector);
+
}
}
-
- if (!missingDocuments.isEmpty()) {
- addErrorMessage("publish-missing-documents");
- for (Iterator i = missingDocuments.iterator(); i.hasNext();) {
- Document doc = (Document) i.next();
- /*
- * This doesn't work yet, see
- * https://issues.apache.org/jira/browse/COCOON-2057
- * String[] params = { doc.getCanonicalWebappURL(),
- * doc.getPath() + " (" + doc.getLanguage() + ")" };
- */
- String[] params = { doc.getPath() + ":" + doc.getLanguage(),
- DublinCoreHelper.getTitle(doc, true) };
- addErrorMessage("missing-document", params);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (selector != null) {
+ if (siteManager != null) {
+ selector.release(siteManager);
}
+ this.manager.release(selector);
}
-
- if (hasBrokenLinks()) {
- addInfoMessage("publish-broken-links");
+ }
+
+ if (!missingDocuments.isEmpty()) {
+ addErrorMessage("publish-missing-documents");
+ for (Iterator i = missingDocuments.iterator(); i.hasNext();) {
+ Document doc = (Document) i.next();
+ /*
+ * This doesn't work yet, see
+ * https://issues.apache.org/jira/browse/COCOON-2057
+ * String[] params = { doc.getCanonicalWebappURL(),
+ * doc.getPath() + " (" + doc.getLanguage() + ")" };
+ */
+ String[] params = { doc.getPath() + ":" + doc.getLanguage(),
+ DublinCoreHelper.getTitle(doc, true) };
+ addErrorMessage("missing-document", params);
}
}
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.