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

org.efaps.importer.OrderObject 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.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * 

This Class gives the possibility to specify an order for objects, in * which they will be inserted into the Database.

*

Example:
*

 * <order type="YDSS_DocumentVersion" direction="ascending">
 *      <attribute index="1" name="Version" criteria="numerical"/>
 * </order>
 * 

* * @author The eFaps Team * @version $Id: OrderObject.java 6210 2011-02-18 21:02:56Z [email protected] $ * */ public class OrderObject implements Comparator { /** * Contains the type of this order object. */ private final String type; /** * Contains the direction of the order, true if ascending, * false if descending. */ private final boolean ascending; /** * Contains the order attributes of this order object. */ private final Map orderAttributes = new TreeMap(); /** * Default constructor. */ public OrderObject() { this.type = null; this.ascending = true; } /** * Constructor for an order object. * * @param _type type of the order object * @param _direction direction of the order, if it equals "descending" * the value of this.ascending will be set to * false, in all other cases to true */ public OrderObject(final String _type, final String _direction) { this.type = _type; this.ascending = !"descending".equalsIgnoreCase(_direction); } /** * Return the type of this order object. * * @return type of this order object * @see #type */ public String getType() { return this.type; } /** * Adds an order attribute to this order object. * * @param _index index of the order attribute * @param _name name of the order attribute * @param _criteria criteria for comparing */ public void addAttribute(final Integer _index, final String _name, final String _criteria) { this.orderAttributes.put(_index, new OrderAttribute(_name, _criteria)); } /** * @param _arg0 first argument * @param _arg1 second argument */ public int compare(final AbstractObject _arg0, final AbstractObject _arg1) { // TODO 1 ersetzen int returnValue; if (this.orderAttributes.get(1).getCriteria().equalsIgnoreCase("numerical")) { final Long comp1 = Long.parseLong((String) _arg0.getAttribute(this.orderAttributes.get(1).getName())); final Long comp2 = Long.parseLong((String) _arg1.getAttribute(this.orderAttributes.get(1).getName())); if (comp1 > comp2) { returnValue = 1; } else if (comp1 < comp2) { returnValue = -1; } else { returnValue = 0; } } else { final String comp1 = (String) _arg0.getAttribute(this.orderAttributes.get(1).getName()); final String comp2 = (String) _arg1.getAttribute(this.orderAttributes.get(1).getName()); returnValue = comp1.compareToIgnoreCase(comp2); } if (!this.ascending) { returnValue *= -1; } return returnValue; } /** * Used to store an order attribute. */ private static class OrderAttribute { /** * Contains the name of the attribute. */ private final String name; /** * Defines the criteria how this attribute will be ordered, (e.g. * "numerical"). */ private final String criteria; /** * * @param _name name of the order attribute * @param _criteria order criteria */ public OrderAttribute(final String _name, final String _criteria) { this.name = _name; this.criteria = _criteria; } /** * Returns the name of this order attribute. * * @return name of this order attribute * @see #name */ public String getName() { return this.name; } /** * Returns the criteria for this order attribute. * * @return criteria * @see #criteria */ public String getCriteria() { return this.criteria; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy