Package models.entities

Examples of models.entities.Contact


    public void baseDaoTest() {
        running(fakeApplication(inMemoryDatabase()), new Runnable() {
            public void run() {
                try {
                    ContactDao dao = DaoManager.getContactDao();
                    Contact c1 = new Contact();
                    c1.setFirstName("Jack");
                    c1.setLastName("Jones");
                    dao.persist(c1);

                    assertNotNull("saved contact id is null", c1.getId());
                    Contact c2 = dao.findById(c1.getId());
                    assertEquals("names are not equal", c2.getFirstName(), c1.getFirstName());
                    dao.remove(c2);
                    Contact c3 = dao.findById(c1.getId());
                    assertNull("removed contact is not null", c3);
                } catch (DataAccessException e) {
                    e.printStackTrace();
                }
            }
View Full Code Here


    public void getBatchTest() {
        running(fakeApplication(inMemoryDatabase()), new Runnable() {
            public void run() {
                ContactDao dao = DaoManager.getContactDao();
                for (int i = 0; i < 18; i++) {
                    Contact c = new Contact();
                    c.setFirstName("Contact" + i);
                    c.setLastName("Jones" + i);
                    try {
                        dao.persist(c);
                    } catch (DataAccessException e) {
                        e.printStackTrace();
                    }
View Full Code Here

    }

    @Transactional
    public static Result getAllByContactId(int pageNumber, int pageSize, int id) {
        try {
            Contact contact = DaoManager.getContactDao().findById(id);
            if (contact == null) {
                return notFound("Can't find contact with id " + id);
            }
            List<Order> orders = DaoManager.getOrderDao().getAllByContact(contact, pageNumber - 1, pageSize);
            if (orders == null) {
View Full Code Here

    @Test
    public void addNewTest() {
        running(fakeApplication(), new Runnable() {
            public void run() {
                final Contact c1 = new Contact();
                c1.setFirstName("Jack");
                c1.setLastName("Jones");
                JPA.withTransaction(new F.Callback0() {
                    @Override
                    public void invoke() throws Throwable {
                        try {
                            DaoManager.getContactDao().persist(c1);
                        } catch (DataAccessException e) {
                            e.printStackTrace();
                        }
                    }
                });
                Integer contactId = c1.getId();

                ObjectNode userNode = Json.newObject();
                userNode.put("login", "login1");
                userNode.put("password", "password");
                userNode.put("contactId", contactId);
View Full Code Here

    public static Result addContact() {
        String reqBody = request().body().asJson().toString();
        Logger.debug("addContact request body: " + reqBody);
        try {
            ContactDTO contactDTO = new ObjectMapper().readValue(reqBody, ContactDTO.class);
            Contact contact = new Contact();
            contactDTO.mapBack(contact);
            for(Phone p: contact.getPhones()) {
                DaoManager.getPhoneDao().persist(p);
            }
            DaoManager.getContactDao().persist(contact);
            Logger.info("new contact added: " + contact.getLastName() + " " +
                    contact.getFirstName() + " ID = " + contact.getId());
        } catch (IOException e) {
            Logger.error("failed to parse new contact json", e);
            return badRequest(Utilities.getJsonErrorNode("failed to parse new contact json"));
        } catch (DataAccessException e) {
            Logger.error("failed to save new contact", e);
View Full Code Here

    @Transactional
    public static Result editContact(Integer contactID) {
        String reqBody = request().body().asJson().toString();
        try {
            Contact contact = DaoManager.getContactDao().findById(contactID);
            List<Phone> contactPhones = contact.getPhones();
            List<PhoneListItemDTO> phones = PhoneListItemDTO.createList(contactPhones);
            if (contact == null) {
                return notFound(Utilities.getJsonErrorNode("Can't find contact with ID: " + contactID));
            }
            Logger.debug("editContact request body: " + reqBody);
            ContactDTO contactDTO = new ObjectMapper().readValue(reqBody, ContactDTO.class);
            contactDTO.mapBack(contact);
            DaoManager.getContactDao().persist(contact);
            List<Phone> editedPhones = new ArrayList<Phone>();
            Phone p;
            Logger.info("1");
            for(PhoneListItemDTO phone: contactDTO.getPhones()) {
                p = new Phone();
                phone.mapBack(p);
                p.setContact(contact);
                editedPhones.add(p);
                DaoManager.getPhoneDao().persist(p);
            }
            Logger.info("3");
            loop: for(PhoneListItemDTO ph1: phones) {
                Logger.info("4 "+ph1.getId());
                for(Phone ph: editedPhones) {
                    Logger.info("5 "+ph.getId());
                    if(ph.getId()==ph1.getId())
                        continue loop;
                }
                Logger.info("6");
                p = DaoManager.getPhoneDao().findById(ph1.getId());
                DaoManager.getPhoneDao().remove(p);
            }
            Logger.info("contact edited : " + contact.getLastName() + " " +
                    contact.getFirstName() + " ID = " + contact.getId());
        } catch (DataAccessException e) {
            Logger.error("editContact method failed (find or save contact)", e);
            return badRequest(Utilities.getJsonErrorNode("editContact method failed (find or save contact)"));
        } catch (IOException e) {
            Logger.error("failed to parse edited contact json", e);
View Full Code Here

    @Transactional
    public static Result deleteContact(Integer contactID) {
        String reqBody = request().body().asJson().toString();
        try {
            Contact contact = DaoManager.getContactDao().findById(contactID);
            if (contact == null) {
                return notFound(Utilities.getJsonErrorNode("can't find contact with ID: " + contactID));
            }
            DaoManager.getContactDao().remove(contact);
            Logger.info("contact deleted : " + contact.getLastName() + " " +
                    contact.getFirstName() + " ID = " + contact.getId());

        } catch (DataAccessException e) {
            Logger.error("deleteContact method failed (save or edit contact)", e);
            return badRequest("deleteContact method failed (save or edit contact)");
        }
View Full Code Here

    }

    @Transactional
    public static Result getContact(Integer id, boolean shortFormat) {
        try {
            Contact contact = DaoManager.getContactDao().findById(id);
            if (shortFormat) {
                return ok(toJson(ContactListItemDTO.createFrom(contact)));
            }
            return ok(toJson(ContactDTO.createFrom(contact)));
View Full Code Here

        }
    }

    @Transactional
    public static Result getContactPhones(Integer id) {
        Contact contact=null;
        try {
            contact = DaoManager.getContactDao().findById(id);
            List<Phone> contactPhones = contact.getPhones();
            List<PhoneListItemDTO> phones = PhoneListItemDTO.createList(contactPhones);
            return ok(toJson(phones));

        } catch (DataAccessException e) {
            Logger.error("Failed to get contact's phones. Contact: "+contact.getLastName()+" "+
                    contact.getFirstName()+", id = "+contact.getId(), e);
            return notFound("Failed to get contact's phones. Contact: "+contact.getLastName()+" "+
                    contact.getFirstName()+", id = "+contact.getId());
        }
    }
View Full Code Here

    }

    @Transactional
    public static Result getMails(String ids) {
        Logger.debug("Mails request IDs: " + ids);
        Contact contact;
        String stemp;
        List<String> mails = new ArrayList<String>();
        try {
//            Integer[] selectedIds = new ObjectMapper().readValue(ids, Integer[].class);
            StringTokenizer st = new StringTokenizer(ids,",");
            List<Integer> selectedIds = new ArrayList<Integer>();
            while (st.hasMoreTokens()) {
                selectedIds.add(Integer.valueOf(st.nextToken()));
            }
            for(Integer id: selectedIds) {
                contact = DaoManager.getContactDao().findById(id);
                stemp = contact.getEmail();
                if(stemp != null && !stemp.equals(""))
                    mails.add(contact.getEmail());
            }
            Logger.info("Mail addresses: "+mails);
            return ok(toJson(mails));
        } catch (DataAccessException e) {
            Logger.error("failed to find contact by ID", e);
View Full Code Here

TOP

Related Classes of models.entities.Contact

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.