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;
}
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() + "'");
}
}
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() + "'");
}
}
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;
}
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;
}
Aggregations