Search in sources :

Example 1 with ContactPosition

use of com.autentia.tnt.manager.contacts.advancedsearch.ContactPosition in project TNTConcept by autentia.

the class AdvancedSearchContactCSVServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // se recuperan los contactos encontrados mediante busqueda avanzada y los textos
    final List<ContactPosition> contactPositions = (List<ContactPosition>) req.getSession().getAttribute(AdvancedSearchContactBean.CONTACTS_SESSION_KEY);
    final Map<String, String> texts = (Map<String, String>) req.getSession().getAttribute(AdvancedSearchContactBean.MESSAGES_SESSION_KEY);
    // se genera el contenido del csv
    final String csvBody = this.generateCSVBody(contactPositions, texts);
    // se manda el csv
    final PrintWriter writer = resp.getWriter();
    resp.setContentType("text/csv");
    resp.setContentLength(csvBody.length());
    writer.append(csvBody);
    writer.close();
    // se borran de la sesion http las variables que ya no necesitan ser utilizadas
    req.getSession().removeAttribute(AdvancedSearchContactBean.CONTACTS_SESSION_KEY);
}
Also used : ContactPosition(com.autentia.tnt.manager.contacts.advancedsearch.ContactPosition) List(java.util.List) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 2 with ContactPosition

use of com.autentia.tnt.manager.contacts.advancedsearch.ContactPosition in project TNTConcept by autentia.

the class AdvancedSearchContactCSVServletTest method testGenerateCSVBody.

@Test
public void testGenerateCSVBody() throws Exception {
    final ContactPosition contactPosition = new ContactPosition();
    contactPosition.setActive(true);
    contactPosition.setName("Ana Sánchez ");
    contactPosition.setPosition("Responsable de dirección ");
    contactPosition.setOrganization("A.T.R.I.L CB");
    contactPosition.setDepartment("Indefinido");
    final List<ContactPosition> contactPositions = new ArrayList<ContactPosition>();
    contactPositions.add(contactPosition);
    final Map<String, String> texts = new HashMap<String, String>();
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_NAME, "Nombre");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_POSITION, "Puesto");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_ORGANIZATION, "Organización");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_DEPARTMENT, "Departamento");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_EMAIL, "Correo-e");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_PHONE, "Teléfono");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_FAX, "Fax");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_COUNTRY, "Pais");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_PROVINCE, "Province");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_CITY, "Ciudad");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_POSTALCODE, "Código postal");
    texts.put(AdvancedSearchContactBean.MESSAGE_CONTACT_ADDRESS, "Dirección");
    final AdvancedSearchContactCSVServlet instance = new AdvancedSearchContactCSVServlet();
    final String content = instance.generateCSVBody(contactPositions, texts);
    if (!content.equals(CSV_CONTENT)) {
        fail("\n\nThe result must be:\n\n>>>" + CSV_CONTENT + "<<<\n\ninstead of:\n\n>>>" + content + "<<<");
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContactPosition(com.autentia.tnt.manager.contacts.advancedsearch.ContactPosition) Test(org.junit.Test)

Example 3 with ContactPosition

use of com.autentia.tnt.manager.contacts.advancedsearch.ContactPosition in project TNTConcept by autentia.

the class AdvancedSearchContactCSVServlet method generateCSVBody.

/**
 * Generates the content of the CSV file
 * @param contactPositions data about the contacts os the positions
 * @return the content of the CSV file
 */
protected String generateCSVBody(final List<ContactPosition> contactPositions, final Map<String, String> texts) {
    final StringBuilder body = new StringBuilder();
    body.append(this.generateCSVHeader(texts));
    for (ContactPosition contactPosition : contactPositions) {
        if (contactPosition.isActive()) {
            body.append(this.generateCSVItem(contactPosition));
        }
    }
    return body.toString();
}
Also used : ContactPosition(com.autentia.tnt.manager.contacts.advancedsearch.ContactPosition)

Aggregations

ContactPosition (com.autentia.tnt.manager.contacts.advancedsearch.ContactPosition)3 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1