001 /*
002 *
003 * $Revision: 15202 $ $Date: 2009-05-15 17:00:44 +0200 (Fri, 15 May 2009) $
004 *
005 * This file is part of *** M y C o R e ***
006 * See http://www.mycore.de/ for details.
007 *
008 * This program is free software; you can use it, redistribute it
009 * and / or modify it under the terms of the GNU General Public License
010 * (GPL) as published by the Free Software Foundation; either version 2
011 * of the License or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program, in a file called gpl.txt or license.txt.
020 * If not, write to the Free Software Foundation Inc.,
021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
022 */
023
024 package org.mycore.frontend.servlets;
025
026 import java.util.List;
027
028 import org.apache.log4j.Logger;
029 import org.mycore.access.MCRAccessManager;
030 import org.mycore.common.MCRConfiguration;
031 import org.mycore.common.MCRMailer;
032 import org.mycore.datamodel.common.MCRActiveLinkException;
033 import org.mycore.datamodel.metadata.MCRObjectID;
034 import org.mycore.frontend.workflow.MCRSimpleWorkflowManager;
035
036 /**
037 * The servlet store the MCREditorServlet output XML in a file of a MCR type
038 * dependencies directory, check it dependence of the MCR type and store the XML
039 * in a file in this directory or if an error was occured start the editor again
040 * with <b>todo </b> <em>repair</em>.
041 *
042 * @author Jens Kupferschmidt
043 * @version $Revision: 15202 $ $Date: 2009-05-15 17:00:44 +0200 (Fri, 15 May 2009) $
044 */
045 public class MCRCheckCommitDataServlet extends MCRCheckDataBase {
046
047 private static final long serialVersionUID = 1L;
048 private static Logger LOGGER = Logger.getLogger(MCRCheckCommitDataServlet.class);
049
050 /**
051 * The method is a dummy and return an URL with the next working step.
052 *
053 * @param ID
054 * the MCRObjectID of the MCRObject
055 * @param okay
056 * the return value of the store operation
057 * @return the next URL as String
058 */
059 public final String getNextURL(MCRObjectID ID, boolean okay) throws MCRActiveLinkException {
060 // commit to the server
061 MCRSimpleWorkflowManager wfm = MCRSimpleWorkflowManager.instance();
062 okay = wfm.commitMetadataObject(ID);
063
064 StringBuffer sb = new StringBuffer();
065 if (okay) {
066 // then delete the data
067 wfm.deleteMetadataObject(ID);
068 // return all is ready
069 sb.append("receive/").append(ID.getId());
070 } else {
071 sb.append(pagedir).append(MCRConfiguration.instance().getString("MCR.SWF.PageErrorStore", "editor_error_store.xml"));
072 }
073 return sb.toString();
074 }
075
076 /**
077 * The method send a message to the mail address for the MCRObjectType.
078 *
079 * @param ID
080 * the MCRObjectID of the MCRObject
081 */
082 public final void sendMail(MCRObjectID ID) {
083 List <String> addr = WFM.getMailAddress(ID.getTypeId(), "wcommit");
084
085 if (addr.size() == 0) {
086 return;
087 }
088
089 String sender = WFM.getMailSender();
090 String appl = MCRConfiguration.instance().getString("MCR.SWF.Mail.ApplicationID", "DocPortal");
091 String subject = "Automatically generated message from " + appl;
092 StringBuffer text = new StringBuffer();
093 text.append("An Object with type ").append(ID.getTypeId()).append(" and ID ").append(ID.getId()).append(" was stored in the system.");
094 LOGGER.info(text.toString());
095
096 try {
097 MCRMailer.send(sender, addr, subject, text.toString(), false);
098 } catch (Exception ex) {
099 LOGGER.error("Can't send a mail to " + addr);
100 }
101 }
102
103 /**
104 * check the access permission
105 * @param ID the mycore ID
106 * @return true if the access is set
107 */
108 protected boolean checkAccess(MCRObjectID ID) {
109 if (MCRAccessManager.checkPermission(ID, "writedb")) {
110 return true;
111 }
112 return false;
113 }
114
115 }