All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.efaps.db.Checkin Maven / Gradle / Ivy

Go to download

eFaps is a framework used to map objects with or without attached files to a relational database and optional file systems (only for attaches files). Configurable access control can be provided down to object and attribute level depending on implementation and use case. Depending on requirements, events (like triggers) allow to implement business logic and to separate business logic from user interface. The framework includes integrations (e.g. webdav, full text search) and a web application as 'simple' configurable user interface. Some best practises, example web application modules (e.g. team work module) support administrators and implementers using this framework.

There is a newer version: 3.2.0
Show newest version
/*
 * Copyright 2003 - 2012 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:          tmo
 * Revision:        $Rev: 7483 $
 * Last Changed:    $Date: 2012-05-11 11:57:38 -0500 (Fri, 11 May 2012) $
 * Last Changed By: $Author: [email protected] $
 */

package org.efaps.db;
import java.io.InputStream;

import org.efaps.admin.access.AccessTypeEnums;
import org.efaps.admin.event.EventType;
import org.efaps.db.store.Resource;
import org.efaps.util.EFapsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The class is used to check in a file to a given attribute of an object.
 *
 * @author The eFaps Team
 * @version $Id: Checkin.java 7483 2012-05-11 16:57:38Z [email protected] $
 */
public class Checkin
    extends AbstractAction
{
    /**
     * Logging instance used in this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(Checkin.class);

    /**
     * Constructor with a string as object id.
     *
     * @param _oid      oid of object on which the check in is made
     */
    public Checkin(final String _oid)
    {
        this(Instance.get(_oid));
    }

    /**
     * Constructor with an instance object as object id.
     *
     * @param _instance     instance on which the check in is made
     */
    public Checkin(final Instance _instance)
    {
        super.setInstance(_instance);
    }

    /**
     * @param _fileName     file name to check in (could include also the path)
     * @param _in           input stream with the binary data
     * @param _size         size of file in stream to check in (negative size
     *                      means that all from the stream must be written)
     * @see #executeWithoutAccessCheck(String, InputStream, int)
     *@throws EFapsException on error
     */
    public void execute(final String _fileName,
                        final InputStream _in,
                        final int _size)
        throws EFapsException
    {
        final boolean hasAccess = super.getInstance().getType().hasAccess(super.getInstance(),
                                                                          AccessTypeEnums.CHECKIN.getAccessType());
        if (!hasAccess) {
            throw new EFapsException(this.getClass(), "execute.NoAccess");
        }
        executeWithoutAccessCheck(_fileName, _in, _size);
    }

    /**
     * Executes the check in without checking the access rights (but with
     * triggers).
     * 
    *
  1. executes the pre check in trigger (if exists)
  2. *
  3. executes the check in trigger (if exists)
  4. *
  5. executes if no check in trigger exists or the check in trigger is * not executed the update ({@see #executeWithoutTrigger})
  6. *
  7. executes the post check in trigger (if exists)
  8. *
* * @param _fileName file name to check in (could include also the path) * @param _in input stream with the binary data * @param _size size of file in stream to check in (negative size * means that all from the stream must be written) * @throws EFapsException if checkout action fails * TODO: history entries */ public void executeWithoutAccessCheck(final String _fileName, final InputStream _in, final int _size) throws EFapsException { executeEvents(EventType.CHECKIN_PRE); if (!executeEvents(EventType.CHECKIN_OVERRIDE)) { executeWithoutTrigger(_fileName, _in, _size); } executeEvents(EventType.CHECKIN_POST); } /** * The check in is done without calling triggers and check of access * rights. Executes the check in: *
    *
  • the file is checked in
  • *
  • the file name and file length is stored in with * {@link org.efaps.db.Update} (complete filename without path)
  • *
* * @param _fileName file name to check in (could include also the path) * @param _in input stream with the binary data * @param _size size of file in stream to check in (negative size means * that all from the stream must be written) * @throws EFapsException if checkout action fails */ public void executeWithoutTrigger(final String _fileName, final InputStream _in, final int _size) throws EFapsException { final Context context = Context.getThreadContext(); Resource storeRsrc = null; boolean ok = false; try { getInstance().getType(); storeRsrc = context.getStoreResource(getInstance(), Resource.StoreEvent.WRITE); storeRsrc.write(_in, _size, _fileName); storeRsrc.commit(); storeRsrc = null; ok = true; } catch (final EFapsException e) { Checkin.LOG.error("could not checkin " + super.getInstance(), e); throw e; } finally { if (!ok) { context.abort(); } if ((storeRsrc != null) && (storeRsrc.isOpened())) { storeRsrc.abort(); } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy