com.autentia.tnt.manager.contacts.OfferManager.java Source code

Java tutorial

Introduction

Here is the source code for com.autentia.tnt.manager.contacts.OfferManager.java

Source

/**
 * TNTConcept Easy Enterprise Management by Autentia Real Bussiness Solution S.L.
 * Copyright (C) 2007 Autentia Real Bussiness Solution S.L.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.autentia.tnt.manager.contacts;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.SerializationUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.autentia.tnt.businessobject.Interaction;
import com.autentia.tnt.businessobject.Offer;
import com.autentia.tnt.businessobject.OfferCost;
import com.autentia.tnt.businessobject.OfferRole;
import com.autentia.tnt.dao.SortCriteria;
import com.autentia.tnt.dao.hibernate.OfferDAO;
import com.autentia.tnt.dao.search.OfferSearch;
import com.autentia.tnt.util.SpringUtils;

public class OfferManager {

    /* Offer - generated by stajanov (do not edit/delete) */

    public Offer duplicateOffer(final Offer offer) {

        final Set<Interaction> interactions = new LinkedHashSet<Interaction>();
        final Set<OfferRole> offerRoles = new LinkedHashSet<OfferRole>();
        final Set<OfferCost> offerCosts = new LinkedHashSet<OfferCost>();

        // copy simple data and delete identificative info
        final Offer duplicatedOffer = (Offer) SerializationUtils.clone(offer);
        duplicatedOffer.setId(null);
        duplicatedOffer.setNumber(null);

        // copy interactions
        if (offer.getInteractions() != null) {
            for (Interaction interaction : offer.getInteractions()) {
                Interaction duplicatedInteraction = (Interaction) SerializationUtils.clone(interaction);
                duplicatedInteraction.setId(null);
                duplicatedInteraction.setOffer(duplicatedOffer);
                interactions.add(duplicatedInteraction);
            }
        }
        duplicatedOffer.setInteractions(interactions);

        // copy roles
        if (offer.getRoles() != null) {
            for (OfferRole offerRole : offer.getRoles()) {
                OfferRole duplicatedRole = (OfferRole) SerializationUtils.clone(offerRole);
                duplicatedRole.setId(null);
                duplicatedRole.setOffer(duplicatedOffer);
                offerRoles.add(duplicatedRole);
            }
        }
        duplicatedOffer.setRoles(offerRoles);

        // copy costs
        if (offer.getCosts() != null) {
            for (OfferCost offerCost : offer.getCosts()) {
                OfferCost duplicatedCost = (OfferCost) SerializationUtils.clone(offerCost);
                duplicatedCost.setId(null);
                duplicatedCost.setOffer(duplicatedOffer);
                offerCosts.add(duplicatedCost);
            }
        }
        duplicatedOffer.setCosts(offerCosts);

        return duplicatedOffer;
    }

    /** Logger */
    private static final Log log = LogFactory.getLog(OfferManager.class);

    /** Offer DAO **/
    private OfferDAO offerDAO;

    /**
     * Get default OfferManager as defined in Spring's configuration file.
     * @return the default singleton OfferManager
     */
    public static OfferManager getDefault() {
        return (OfferManager) SpringUtils.getSpringBean("managerOffer");
    }

    /** 
     * Empty constructor needed by CGLIB (Spring AOP)
     */
    protected OfferManager() {
    }

    /** 
     * Default constructor 
     * @deprecated do not construct managers alone: use Spring's declared beans
     */
    public OfferManager(OfferDAO offerDAO) {
        this.offerDAO = offerDAO;
    }

    /**
     * List offers. 
     * @param search search filter to apply
     * @param sort sorting criteria
     * @return the list of all offers sorted by requested criterion
     */
    public List<Offer> getAllEntities(OfferSearch search, SortCriteria sort) {
        return offerDAO.search(search, sort);
    }

    /**
     * Get offer by primary key.
     * @return offer selected by id.
     */
    public Offer getEntityById(int id) {
        return offerDAO.getById(id);
    }

    /**
     * Insert offer. 
     */
    public void insertEntity(Offer offer) {
        offerDAO.insert(offer);
    }

    /**
     * Update offer. 
     */
    public void updateEntity(Offer offer) {
        offerDAO.update(offer);
    }

    /**
     * Delete offer. 
     */
    public void deleteEntity(Offer offer) {
        offerDAO.delete(offer);
    }

    /* Offer - generated by stajanov (do not edit/delete) */

}