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

org.efaps.importer.RootObject 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.
 *
 * 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.importer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.efaps.db.Insert;
import org.efaps.util.EFapsException;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This Class represents a simplified an specialized version of an InsertObject.
 * In this case the Object represents the Root and therefore can't be a child.
 * The Root means in this case the <import></import> of the
 * XML-File.
 *
 * @author The eFaps Team
 * @version $Id: RootObject.java 7483 2012-05-11 16:57:38Z [email protected] $
 */
public class RootObject
    extends AbstractObject
{
    /**
     * Logger for this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(RootObject.class);

    /**
     * Mapping for odered objects.
     */
    private static final Map ORDER = new HashMap();

    /**
     * Format for Date values.
     * default is yyyy-MM-dd'T'HH:mm:ss.SSSZZ
     */
    private static String DATEFORMAT;

    /**
     * Children for this rootobject.
     */
    private final List childs = new ArrayList();


    /**
     * Setter method for the variable {@link #${RootObject.DATEFORMAT}}.
     *
     * @param  _dateFormat value for variable {@link #${RootObject.DATEFORMAT}}
     */
    protected static void setDateFormat(final String _dateFormat)
    {
        RootObject.DATEFORMAT = _dateFormat;
    }

    /**
     * Getter method for the variable {@link #${RootObject.DATEFORMAT}}.
     *
     * @return value of variable {@link #${RootObject.DATEFORMAT}}
     */
    protected static String getDateFormat()
    {
        return RootObject.DATEFORMAT;
    }

    /**
     * @param _order add to the order
     */
    protected static void addOrder(final OrderObject _order)
    {
        RootObject.ORDER.put(_order.getType(), _order);
    }

    /**
     * @param _type tyep the order is wanted for
     * @return order
     */
    protected static OrderObject getOrder(final String _type)
    {
        return RootObject.ORDER.get(_type);
    }

    /**
     * @param _object add a child
     */
    public void addChild(final AbstractObject _object)
    {
        this.childs.add(_object);
    }

    @Override
    public void dbAddChilds()
    {
        for (final AbstractObject object : this.childs) {
            try {
                if (RootObject.LOG.isInfoEnabled()) {
                    RootObject.LOG.info("Inserting the Base-Objects '"
                            + object.getType() + "' to the Database");
                }
                final Insert insert = new Insert(object.getType());

                for (final Entry element : object.getAttributes().entrySet()) {
                    if (element.getValue() instanceof DateTime) {
                        insert.add(element.getKey().toString(), (DateTime) element.getValue());
                    } else {
                        insert.add(element.getKey().toString(), element.getValue().toString());
                    }
                }
                for (final ForeignObject link : object.getLinks()) {
                    insert.add(link.getLinkAttribute(), link.dbGetValue());
                }
                insert.executeWithoutAccessCheck();
                final long newId = insert.getId();
                insert.close();

                object.setID(newId);

            } catch (final EFapsException e) {
                RootObject.LOG.error("insertDB()", e);
                //CHECKSTYLE:OFF
            } catch (final Exception e) {
              //CHECKSTYLE:ON
                RootObject.LOG.error("insertDB()", e);
            }
        }

        for (final AbstractObject object : this.childs) {
            object.dbAddChilds();
        }
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @return always null
     */
    @Override
    public Map getAttributes()
    {
        return null;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @return always null
     */
    @Override
    public String getType()
    {
        return null;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @param _id       not used
     */
    @Override
    public void setID(final long _id)
    {
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @return always null
     */
    @Override
    public String getParrentAttribute()
    {
        return null;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @return always null
     */
    @Override
    public Set getLinks()
    {
        return null;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @return always false
     */
    @Override
    public boolean isCheckinObject()
    {
        return false;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     */
    @Override
    public void dbCheckObjectIn()
    {
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @return always null
     */
    @Override
    public Set getUniqueAttributes()
    {
        // not needed here
        return null;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @param _attribute    not used
     * @return always null
     */
    @Override
    public Object getAttribute(final String _attribute)
    {
        // not needed here
        return null;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @return always false
     */
    @Override
    public boolean hasChilds()
    {
        return false;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @param _parent   not used
     * @param _id       not used
     * @return always null
     */
    @Override
    public long dbUpdateOrInsert(final AbstractObject _parent,
                                   final long _id)
    {
        return 0;
    }

    /**
     * The method is not required for root objects and therefore the method is
     * only a stub method.
     *
     * @return always null
     */
    @Override
    public long getID()
    {
        return 0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy