Search in sources :

Example 1 with Position

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

the class PositionManager method trackEntityChanges.

/* Position - generated by stajanov (do not edit/delete) */
/**
 * Mira los campos de la entidad a ver si se han producido cambios
 *
 * @return true si se produjo algun cambio
 */
private boolean trackEntityChanges(Position position) {
    int previousHistorySize = position.getHistory().size();
    int finalHistorySize = previousHistorySize;
    final Position changes = position.getChanges();
    // TODO ¿podría ser por reflexion para obtener los atributos persistentes?
    if (changes != null) {
        if (changes.getName() != null && !changes.getName().equals(position.getName())) {
            position.getHistory().add(getChange(position, FIELD_NAME, changes.getName(), position.getName()));
            this.trackContactChanges(position);
        }
        position.getHistory().add(getChange(position, FIELD_DESCRIPTION, changes.getDescription(), position.getDescription()));
        position.getHistory().add(getChange(position, FIELD_EMAIL, changes.getEmail(), position.getEmail()));
        position.getHistory().add(getChange(position, FIELD_PHONE, changes.getPhone(), position.getPhone()));
        position.getHistory().add(getChange(position, FIELD_FAX, changes.getFax(), position.getFax()));
        position.getHistory().add(getChange(position, FIELD_COUNTRY, changes.getCountry(), position.getCountry()));
        position.getHistory().add(getChange(position, FIELD_POSTALCODE, changes.getPostalCode(), position.getPostalCode()));
        position.getHistory().add(getChange(position, FIELD_ADDRESS, changes.getAddress(), position.getAddress()));
        position.getHistory().add(getChange(position, FIELD_CITY, changes.getCity(), position.getCity()));
        position.getHistory().add(getProvinceChange(position));
        position.getHistory().addAll(getPositionTagChanges(position));
        finalHistorySize = position.getHistory().size();
    }
    // if has changes previousHistorySize != finalHistorySize
    return previousHistorySize != finalHistorySize;
}
Also used : Position(com.autentia.tnt.businessobject.Position)

Example 2 with Position

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

the class PositionManager method getProvinceChange.

private PositionChange getProvinceChange(Position position) {
    String previous = "";
    String now = "";
    Position changes = position.getChanges();
    // no está de más reflejarlo
    if (changes.getProvince() != null) {
        previous = StringUtils.defaultIfEmpty(changes.getProvince().getName(), "");
    }
    if (position.getProvince() != null) {
        now = StringUtils.defaultIfEmpty(position.getProvince().getName(), "");
    }
    return getChange(position, FIELD_PROVINCE, previous, now);
}
Also used : Position(com.autentia.tnt.businessobject.Position)

Example 3 with Position

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

the class ContactPositionManagerTest method testDoAdvancedSearchHistorical.

/**
 * Buscar por en historico y en activo
 */
@Test
public void testDoAdvancedSearchHistorical() {
    final PositionDAO positionDAO = (PositionDAO) SpringUtilsForTesting.getSpringBean("daoPosition");
    final ContactDAO contactDAO = (ContactDAO) SpringUtilsForTesting.getSpringBean("daoContact");
    final EntityChangeDAO entityChangeDAO = (EntityChangeDAO) SpringUtilsForTesting.getSpringBean("daoEntityChange");
    final ContactPositionManager contactPositionManager = new ContactPositionManager(contactDAO, positionDAO);
    this.insertInitialData();
    this.insertContactData();
    // añadimos que Pilar Sancho fue becaria
    final EntityChange changePosition = new EntityChange();
    changePosition.setField(Contact.FIELD_POSITION);
    changePosition.setNewValue("");
    changePosition.setOldValue("becario");
    changePosition.setEntityId(pilarSancho.getId());
    changePosition.setEntityName("com.autentia.tnt.businessobject.Contact");
    entityChangeDAO.insert(changePosition);
    final AdvancedSearchContactSearch advancedSearch = new AdvancedSearchContactSearch();
    final List<Position> positions = new ArrayList<Position>();
    positions.add(becario);
    advancedSearch.setPositions(positions);
    final List<ContactPosition> contactPositions = contactPositionManager.doAdvancedSearch(advancedSearch, ACTIVE_AND_HISTORICAL);
    // debe salir dos resultados, ya que hay uno que es becario actualmente y otro que lo fue
    if (contactPositions.size() != 2) {
        fail("Deberian haber salido 2 resultados, pero han salido " + contactPositions.size());
    }
}
Also used : PositionDAO(com.autentia.tnt.dao.hibernate.PositionDAO) AdvancedSearchContactSearch(com.autentia.tnt.dao.search.AdvancedSearchContactSearch) ContactDAO(com.autentia.tnt.dao.hibernate.ContactDAO) Position(com.autentia.tnt.businessobject.Position) EntityChange(com.autentia.tnt.tracking.EntityChange) ArrayList(java.util.ArrayList) EntityChangeDAO(com.autentia.tnt.tracking.hibernate.dao.EntityChangeDAO) Test(org.junit.Test)

Example 4 with Position

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

the class ContactBean method getAllPositionsOfDepartment.

public List<SelectItem> getAllPositionsOfDepartment() {
    final PositionSearch positionSearch = new PositionSearch();
    positionSearch.setDepartmentId(this.getSelectedDepartment().getId());
    positionSearch.setDeleted(false);
    final List<Position> refs = PositionManager.getDefault().getAllEntities(positionSearch, new SortCriteria("name"));
    final List<SelectItem> ret = new ArrayList<SelectItem>();
    ret.add(new SelectItem(null, FacesUtils.getMessage("contact.selectOnePosition")));
    for (Position ref : refs) {
        ret.add(new SelectItem(ref, ref.getName()));
    }
    return ret;
}
Also used : PositionSearch(com.autentia.tnt.dao.search.PositionSearch) SortCriteria(com.autentia.tnt.dao.SortCriteria) Position(com.autentia.tnt.businessobject.Position) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList)

Example 5 with Position

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

the class TagBean method createPositionTags.

/**
 * Create a new empty instance of the one-to-many field
 *
 * @return forward to the same page
 */
public String createPositionTags() {
    Position item = new Position();
    if (tag.getPositionTags() == null) {
        tag.setPositionTags(new HashSet());
    }
    tag.getPositionTags().add(item);
    return null;
}
Also used : Position(com.autentia.tnt.businessobject.Position) HashSet(java.util.HashSet)

Aggregations

Position (com.autentia.tnt.businessobject.Position)20 ArrayList (java.util.ArrayList)9 SortCriteria (com.autentia.tnt.dao.SortCriteria)7 SelectItem (javax.faces.model.SelectItem)6 PositionSearch (com.autentia.tnt.dao.search.PositionSearch)5 ContactDAO (com.autentia.tnt.dao.hibernate.ContactDAO)3 PositionDAO (com.autentia.tnt.dao.hibernate.PositionDAO)3 AdvancedSearchContactSearch (com.autentia.tnt.dao.search.AdvancedSearchContactSearch)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 Department (com.autentia.tnt.businessobject.Department)2 ContactPosition (com.autentia.tnt.manager.contacts.advancedsearch.ContactPosition)2 UIData (javax.faces.component.UIData)2 ContactInfo (com.autentia.tnt.businessobject.ContactInfo)1 DepartmentSearch (com.autentia.tnt.dao.search.DepartmentSearch)1 EntityChange (com.autentia.tnt.tracking.EntityChange)1 EntityChangeDAO (com.autentia.tnt.tracking.hibernate.dao.EntityChangeDAO)1 Date (java.util.Date)1 List (java.util.List)1