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 - 2011 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: 6210 $
 * Last Changed:    $Date: 2011-02-18 16:02:56 -0500 (Fri, 18 Feb 2011) $
 * 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.Set;
import java.util.Map.Entry;

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 6210 2011-02-18 21:02:56Z [email protected] $
 */
public class RootObject
    extends AbstractObject
{
    /**
     * Logger for this class.
     */
    private static final Logger LOG = LoggerFactory.getLogger(RootObject.class);

    private final static Map ORDER = new HashMap();

    //default is yyyy-MM-dd'T'HH:mm:ss.SSSZZ
    static String DATEFORMAT;

    private final List childs = new ArrayList();


    public static void setDateFormat(final String _DateFormat)
    {
        RootObject.DATEFORMAT = _DateFormat;
    }

    public static void addOrder(final OrderObject _order)
    {
        RootObject.ORDER.put(_order.getType(), _order);
    }

    public static OrderObject getOrder(final String _type)
    {
        return RootObject.ORDER.get(_type);
    }


    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);
            } catch (final Exception e) {
                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