use of com.autentia.tnt.tracking.EntityChange in project TNTConcept by autentia.
the class ContactPositionManager method recoverChangesFromContact.
/**
* TODO
*/
private List<ContactPosition> recoverChangesFromContact(final AdvancedSearchContactSearch advancedSearch) {
final List<EntityChange> changes = contactDAO.contactAdvancedSearchChanges(advancedSearch);
final List<Contact> contacts = new ArrayList<Contact>(changes.size());
final List<ContactPosition> contactPositions = new ArrayList<ContactPosition>(contacts.size());
String changeValueDescription;
for (EntityChange entityChange : changes) {
final ContactPosition contactPosition = new ContactPosition();
final Contact contact = contactDAO.loadById(entityChange.getEntityId());
contactPosition.setName(contact.getName());
// recovers the text to show in the description of the change
if (!(entityChange.getNewValue() == null || entityChange.getNewValue().equals(""))) {
changeValueDescription = entityChange.getOldValue() + " [" + entityChange.getNewValue() + "]";
} else {
changeValueDescription = entityChange.getOldValue();
}
// add the description by field
if (entityChange.getField().equals(Contact.FIELD_POSITION)) {
contactPosition.setPosition(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_ORGANIZATION)) {
contactPosition.setOrganization(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_NAME)) {
contactPosition.setName(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_DEPARTMENT)) {
contactPosition.setDepartment(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_EMAIL)) {
contactPosition.setEmail(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_PHONE)) {
contactPosition.setPhone(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_FAX)) {
contactPosition.setFax(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_COUNTRY)) {
contactPosition.setCountry(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_PROVINCE)) {
contactPosition.setProvince(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_CITY)) {
contactPosition.setCity(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_POSTALCODE)) {
contactPosition.setPostalCode(changeValueDescription);
} else if (entityChange.getField().equals(Contact.FIELD_ADDRESS)) {
contactPosition.setAddress(changeValueDescription);
}
contactPositions.add(contactPosition);
}
return contactPositions;
}
use of com.autentia.tnt.tracking.EntityChange in project TNTConcept by autentia.
the class TagManager method trackContactChanges.
private void trackContactChanges(Tag tag) {
// tracking associated Contacts
for (Contact contact : tag.getContactTags()) {
final Contact contactBD = ContactManager.getDefault().getEntityById(contact.getId());
if (!contactBD.getTags().contains(tag)) {
// FIXME aqui debería bastar con añadir el cambio o el tag al contacto y salvar el contacto
// para que se actualizase con los listener de hibernate. Por algún motivo, sólo cuando se da de alta
// una nueva clave y se asocia a un contacto antes de guardar no funciona correctamente.
EntityChange entityChange = contactBD.getEntityChange(Contact.FIELD_TAGS, "", tag.getName(), tag.getId().toString());
contactBD.addEntityChange(Contact.FIELD_TAGS, "", tag.getName(), tag.getId().toString());
if (entityChange != null) {
entityChangeDAO.insert(entityChange);
}
}
}
// tracking deassociated Contacts
if (tag.getId() != null) {
Tag tagDB = getEntityById(tag.getId());
for (Contact contactDB : tagDB.getContactTags()) {
if (!tag.getContactTags().contains(contactDB)) {
contactDB.addEntityChange(Contact.FIELD_TAGS, tag.getName(), "", tag.getId().toString());
contactDAO.update(contactDB);
}
}
}
}
use of com.autentia.tnt.tracking.EntityChange 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());
}
}
use of com.autentia.tnt.tracking.EntityChange in project TNTConcept by autentia.
the class TrackChangesMailService method composeMessage.
private String composeMessage(String entityTextKey, String entityUserFriendlyName, Collection<EntityChange> entityChanges) {
StringBuilder sb = new StringBuilder();
if (entityChanges != null) {
for (EntityChange entityChange : entityChanges) {
String key = entityChange.getField();
sb.append(getProperty(key));
sb.append(" [");
sb.append(getChangesMailBefore());
sb.append(": ");
sb.append(entityChange.getOldValue());
sb.append("] [");
sb.append(getChangesMailAfter());
sb.append(": ");
sb.append(entityChange.getNewValue());
sb.append("]");
sb.append(System.getProperty("line.separator"));
}
}
return getChangesMailBody(entityTextKey, entityUserFriendlyName, sb.toString());
}
use of com.autentia.tnt.tracking.EntityChange in project TNTConcept by autentia.
the class ContactPositionManagerTest method testDoAdvancedSearchHistoricalSimpleValue.
/**
* Buscar por en historico y en activo
*/
@Test
public void testDoAdvancedSearchHistoricalSimpleValue() {
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 trabajaba en Italia
final EntityChange changePosition = new EntityChange();
changePosition.setField(Contact.FIELD_COUNTRY);
changePosition.setNewValue("España");
changePosition.setOldValue("Italia");
changePosition.setEntityId(pilarSancho.getId());
changePosition.setEntityName("com.autentia.tnt.businessobject.Contact");
entityChangeDAO.insert(changePosition);
final AdvancedSearchContactSearch advancedSearch = new AdvancedSearchContactSearch();
advancedSearch.setCountry("Italia");
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() != 1) {
fail("Deberia haber salido 1 resultado, pero han salido " + contactPositions.size());
}
}
Aggregations