001    /*
002     * 
003     * $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
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.fileupload;
025    
026    import org.apache.log4j.Logger;
027    
028    import org.mycore.datamodel.metadata.MCRDerivate;
029    import org.mycore.datamodel.metadata.MCRObjectID;
030    import org.mycore.frontend.workflow.MCRSimpleWorkflowManager;
031    
032    /**
033     * handles uploads via the UploadApplet and store files directly into the IFS.
034     * 
035     * @author Thomas Scheffler (yagee)
036     * @author Jens Kupferschmidt
037     * 
038     * @version $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
039     * 
040     * @see MCRUploadHandler
041     */
042    public class MCRSWFUploadHandlerIFS extends MCRUploadHandlerIFS {
043        private static final Logger LOGGER = Logger.getLogger(MCRSWFUploadHandlerIFS.class);
044    
045        /**
046         * The constructor for this class. It set all data to handle with IFS upload
047         * store.
048         * 
049         * @param docId
050         *            the document ID
051         * @param derId
052         *            the derivate ID
053         * @param url
054         *            an URL string. Not used in this implementation.
055         */
056        public MCRSWFUploadHandlerIFS(String docId, String derId, String url) {
057            super(docId, derId, url);
058            init(docId, derId);
059        }
060    
061        @Override
062        protected void init(String docId, String derId) {
063            LOGGER.debug("MCRUploadHandlerMyCoRe DocID: " + docId + " DerId: " + derId);
064    
065            try {
066                new MCRObjectID(docId);
067            } catch (Exception e) {
068                LOGGER.debug("Error while creating MCRObjectID : " + docId, e);
069            }
070    
071            if (derId == null) {
072                derId = MCRSimpleWorkflowManager.instance().getNextDrivateID(new MCRObjectID(docId)).getId();
073            } else {
074                try {
075                    new MCRObjectID(derId);
076                } catch (Exception e) {
077                    LOGGER.debug("Error while creating MCRObjectID : " + derId, e);
078                }
079            }
080    
081            newDerivate = true;
082            if (MCRDerivate.existInDatastore(derId)) {
083                LOGGER.debug("Derivate allready exists: " + derId);
084                newDerivate = false;
085                derivate = new MCRDerivate();
086                derivate.receiveFromDatastore(derId);
087            } else {
088                // create new derivate with given ID
089                LOGGER.debug("Create derivate with ID: " + derId);
090                createNewDerivate(docId, new MCRObjectID(derId));
091            }
092        }
093    
094        @Override
095        public void finishUpload() throws Exception {
096            // existing files
097            if (!rootDir.hasChildren()) {
098                derivate.deleteFromDatastore(derivate.getId().getId());
099                LOGGER.warn("No file were uploaded, delete entry in database for " + derivate.getId().getId() + " and return.");
100                return;
101            }
102            super.finishUpload();
103        }
104    
105    }