Search in sources :

Example 1 with Offer

use of com.autentia.tnt.businessobject.Offer in project TNTConcept by autentia.

the class OfferManager method duplicateOffer.

/* 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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Offer(com.autentia.tnt.businessobject.Offer) Interaction(com.autentia.tnt.businessobject.Interaction) OfferCost(com.autentia.tnt.businessobject.OfferCost) OfferRole(com.autentia.tnt.businessobject.OfferRole)

Example 2 with Offer

use of com.autentia.tnt.businessobject.Offer in project TNTConcept by autentia.

the class DuplicateOfferTest method testDuplicateOfferWithRolesAndCosts.

/**
 * Comprobacion de que se duplique la oferta con relaciones con costes, personal e interacciones
 */
@Test
public void testDuplicateOfferWithRolesAndCosts() {
    final OfferManager offerManager = (OfferManager) SpringUtilsForTesting.getSpringBean("managerOffer");
    final OfferDAO offerDAO = (OfferDAO) SpringUtilsForTesting.getSpringBean("daoOffer");
    insertInitialData();
    insertOfferCosts();
    insertOfferRoles();
    insertOfferInteraction();
    final Offer duplicated = offerManager.duplicateOffer(offer);
    duplicated.setNumber("123456");
    offerDAO.insert(duplicated);
    if (duplicated.getCosts().size() != 2) {
        fail("deberia haber 2 costes por materiales en el duplicado en vez de '" + duplicated.getCosts().size() + "'");
    }
    if (duplicated.getRoles().size() != 2) {
        fail("deberia haber 2 costes por roles en el duplicado en vez de '" + duplicated.getRoles().size() + "'");
    }
    if (duplicated.getInteractions().size() != 1) {
        fail("deberia haber 1 interacciones en el duplicado en vez de '" + duplicated.getInteractions().size() + "'");
    }
}
Also used : Offer(com.autentia.tnt.businessobject.Offer) OfferManager(com.autentia.tnt.manager.contacts.OfferManager) OfferDAO(com.autentia.tnt.dao.hibernate.OfferDAO) Test(org.junit.Test)

Example 3 with Offer

use of com.autentia.tnt.businessobject.Offer in project TNTConcept by autentia.

the class DuplicateOfferTest method testDuplicateOfferWithSimpleDataOnly.

/**
 * Comprobacion de que se duplique la oferta sin relaciones 1:N
 */
@Test
public void testDuplicateOfferWithSimpleDataOnly() {
    final OfferManager offerManager = (OfferManager) SpringUtilsForTesting.getSpringBean("managerOffer");
    final OfferDAO offerDAO = (OfferDAO) SpringUtilsForTesting.getSpringBean("daoOffer");
    insertInitialData();
    final Offer duplicated = offerManager.duplicateOffer(offer);
    if (duplicated.getId() != null) {
        fail("el id debe ser 'null' en vez de '" + duplicated.getId() + "'");
    }
    if (duplicated.getNumber() != null) {
        fail("el numero debe ser '" + offer.getNumber() + "' en vez de '" + duplicated.getNumber() + "'");
    }
    if (!duplicated.getContact().equals(offer.getContact())) {
        fail("el contacto debe ser '" + offer.getContact().getName() + "' en vez de '" + duplicated.getContact().getName() + "'");
    }
    if (!duplicated.getMaturityDate().equals(offer.getMaturityDate())) {
        fail("la fecha de madurez debe ser '" + offer.getMaturityDate() + "' en vez de '" + duplicated.getMaturityDate() + "'");
    }
    duplicated.setNumber("123456");
    offerDAO.insert(duplicated);
    if (offerManager.getAllEntities(new OfferSearch(), new SortCriteria()).size() != 2) {
        fail("deberia haber 2 ofertas en vez de '" + offerManager.getAllEntities(new OfferSearch(), new SortCriteria()).size() + "'");
    }
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) OfferSearch(com.autentia.tnt.dao.search.OfferSearch) Offer(com.autentia.tnt.businessobject.Offer) OfferManager(com.autentia.tnt.manager.contacts.OfferManager) OfferDAO(com.autentia.tnt.dao.hibernate.OfferDAO) Test(org.junit.Test)

Example 4 with Offer

use of com.autentia.tnt.businessobject.Offer in project TNTConcept by autentia.

the class InteractionBean method getOffers.

/**
 * Get the list of all offers
 * @return the list of all offers
 */
public List<SelectItem> getOffers() {
    List<Offer> refs = OfferManager.getDefault().getAllEntities(null, new SortCriteria("title"));
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
    for (Offer ref : refs) {
        ret.add(new SelectItem(ref, ref.getTitle()));
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) Offer(com.autentia.tnt.businessobject.Offer) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList)

Example 5 with Offer

use of com.autentia.tnt.businessobject.Offer in project TNTConcept by autentia.

the class OfferBean method create.

/**
 * Go to create page
 *
 * @return forward to CREATE page
 */
public String create() {
    offer = new Offer();
    offer.setUser(SpringUtils.getPrincipal().getUser());
    offer.setCreationDate(new Date());
    return NavigationResults.CREATE;
}
Also used : Offer(com.autentia.tnt.businessobject.Offer) Date(java.util.Date)

Aggregations

Offer (com.autentia.tnt.businessobject.Offer)5 SortCriteria (com.autentia.tnt.dao.SortCriteria)2 OfferDAO (com.autentia.tnt.dao.hibernate.OfferDAO)2 OfferManager (com.autentia.tnt.manager.contacts.OfferManager)2 Test (org.junit.Test)2 Interaction (com.autentia.tnt.businessobject.Interaction)1 OfferCost (com.autentia.tnt.businessobject.OfferCost)1 OfferRole (com.autentia.tnt.businessobject.OfferRole)1 OfferSearch (com.autentia.tnt.dao.search.OfferSearch)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 SelectItem (javax.faces.model.SelectItem)1