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
035 /**
036 * The servlet store the MCREditorServlet output XML in a file of a MCR type
037 * dependencies directory, check it dependence of the MCR type and store the XML
038 * in a file in this directory or if an error was occured start the editor again
039 * with <b>todo </b> <em>repair</em>.
040 *
041 * @author Jens Kupferschmidt
042 * @version $Revision: 15202 $ $Date: 2009-05-15 17:00:44 +0200 (Fri, 15 May 2009) $
043 */
044 public class MCRCheckEditDataServlet extends MCRCheckDataBase {
045
046 private static final long serialVersionUID = 1L;
047 private static Logger LOGGER = Logger.getLogger(MCRCheckEditDataServlet.class);
048
049 /**
050 * The method return an URL with the next working step. If okay flag is
051 * true, the object will present else it shows the error page.
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 protected String getNextURL(MCRObjectID ID, boolean okay) throws MCRActiveLinkException {
060 StringBuffer sb = new StringBuffer();
061 if (okay) {
062 sb.append(WFM.getWorkflowFile(pagedir, ID.getBase()));
063 } else {
064
065 sb.append(pagedir).append(MCRConfiguration.instance().getString("MCR.SWF.PageErrorStore", "editor_error_store.xml"));
066 }
067 return sb.toString();
068 }
069
070 /**
071 * The method send a message to the mail address for the MCRObjectType.
072 *
073 * @param ID
074 * the MCRObjectID of the MCRObject
075 */
076 public final void sendMail(MCRObjectID ID) {
077 List<String> addr = WFM.getMailAddress(ID.getTypeId(), "weditobj");
078
079 if (addr.size() == 0) {
080 return;
081 }
082
083 String sender = WFM.getMailSender();
084 String appl = MCRConfiguration.instance().getString("MCR.SWF.Mail.ApplicationID", "DocPortal");
085 String subject = "Automatically generated message from " + appl;
086 StringBuffer text = new StringBuffer();
087 text.append("An object with type ").append(ID.getTypeId()).append(" and ID ").append(ID.getId()).append(" was changed in the workflow.");
088 LOGGER.info(text.toString());
089
090 try {
091 MCRMailer.send(sender, addr, subject, text.toString(), false);
092 } catch (Exception ex) {
093 LOGGER.error("Can't send a mail to " + addr);
094 }
095 }
096
097 /**
098 * check the access permission
099 * @param ID the mycore ID
100 * @return true if the access is set
101 */
102 protected boolean checkAccess(MCRObjectID ID) {
103 if (MCRAccessManager.checkPermission("create-"+ID.getBase())) {
104 return true;
105 }
106 if (MCRAccessManager.checkPermission("create-"+ID.getTypeId())) {
107 return true;
108 }
109 return false;
110 }
111
112 }