001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.lenya.cms.workflow.usecases;
019:
020: import org.apache.cocoon.components.ContextHelper;
021: import org.apache.cocoon.environment.Request;
022: import org.apache.lenya.ac.AccessControlException;
023: import org.apache.lenya.ac.User;
024: import org.apache.lenya.cms.ac.PolicyUtil;
025: import org.apache.lenya.cms.observation.RepositoryEvent;
026: import org.apache.lenya.cms.observation.RepositoryEventFactory;
027: import org.apache.lenya.cms.publication.Document;
028: import org.apache.lenya.cms.publication.DocumentException;
029: import org.apache.lenya.cms.publication.Proxy;
030: import org.apache.lenya.cms.publication.Publication;
031: import org.apache.lenya.notification.NotificationException;
032: import org.apache.lenya.cms.workflow.usecases.InvokeWorkflow;
033: import org.apache.lenya.notification.Message;
034: import org.apache.lenya.notification.NotificationEventDescriptor;
035:
036: /**
037: * Submit usecase handler.
038: */
039: public class Submit extends InvokeWorkflow {
040:
041: protected static final String MESSAGE_SUBJECT = "notification-message";
042: protected static final String MESSAGE_DOCUMENT_SUBMITTED = "document-submitted";
043: protected static final String SEND_NOTIFICATION = "sendNotification";
044:
045: /**
046: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
047: */
048: protected void doExecute() throws Exception {
049:
050: super .doExecute();
051:
052: if (Boolean.valueOf(
053: getBooleanCheckboxParameter(SEND_NOTIFICATION))
054: .booleanValue()) {
055: sendNotification(getSourceDocument());
056: }
057: }
058:
059: protected void sendNotification(Document authoringDocument)
060: throws NotificationException, DocumentException,
061: AccessControlException {
062:
063: User sender = getSession().getIdentity().getUser();
064:
065: User[] recipients = PolicyUtil.getUsersWithRole(this .manager,
066: authoringDocument.getCanonicalWebappURL(), "review",
067: getLogger());
068:
069: // check to see if current user can review their own submission
070: for (int i = 0; i < recipients.length; i++) {
071: if (recipients[i].equals(sender))
072: return;
073: }
074:
075: String url;
076: Document authoringVersion = authoringDocument
077: .getAreaVersion(Publication.AUTHORING_AREA);
078: Proxy proxy = authoringVersion.getPublication().getProxy(
079: authoringVersion, false);
080:
081: if (proxy != null) {
082: url = proxy.getURL(authoringVersion);
083: } else {
084: Request request = ContextHelper.getRequest(this .context);
085: final String serverUrl = "http://"
086: + request.getServerName() + ":"
087: + request.getServerPort();
088: final String webappUrl = authoringVersion
089: .getCanonicalWebappURL();
090: url = serverUrl + request.getContextPath() + webappUrl;
091: }
092:
093: String[] params = { url };
094:
095: Message message = new Message(MESSAGE_SUBJECT, new String[0],
096: MESSAGE_DOCUMENT_SUBMITTED, params, sender, recipients);
097: NotificationEventDescriptor descriptor = new NotificationEventDescriptor(
098: message);
099: RepositoryEvent event = RepositoryEventFactory.createEvent(
100: this.manager, getSession(), getLogger(), descriptor);
101: getSession().enqueueEvent(event);
102: }
103: }
|