public static ContactService createDemoService() { if (instance == null) { final ContactService contactService = new ContactService(); Random r = new Random(0); Calendar cal = Calendar.getInstance(); for (int i = 0; i < 100; i++) { Contact contact = new Contact(); contact.setFirstName(fnames[r.nextInt(fnames.length)]); contact.setLastName(lnames[r.nextInt(fnames.length)]); contact.setEmail( contact.getFirstName().toLowerCase() + "@" + contact.getLastName().toLowerCase() + ".com"); contact.setPhone("+ 358 555 " + (100 + r.nextInt(900))); cal.set(1930 + r.nextInt(70), r.nextInt(11), r.nextInt(28)); contact.setBirthDate(cal.getTime()); contactService.save(contact); } instance = contactService; } return instance; }
public static void main(String[] args) { Session session = null; try { session = HibernateUtility.getSession(); // Create new instance of Contact and set values in it by reading them from form object System.out.println("Inserting Record"); Transaction tx = session.beginTransaction(); Contact contact1 = new Contact(); contact1.setId(1L); contact1.setFirstName("poornima"); contact1.setLastName("baby"); contact1.setEmail("*****@*****.**"); session.save(contact1); Contact contact2 = new Contact(); contact2.setId(2L); contact2.setFirstName("Raj"); contact2.setLastName("Kapoor"); contact2.setEmail("*****@*****.**"); session.save(contact2); Contact contact3 = new Contact(); contact3.setId(3l); contact3.setFirstName("Boney"); contact3.setLastName("Kapoor"); contact3.setEmail("*****@*****.**"); session.save(contact3); Contact contact4 = new Contact(); contact4.setId(4l); contact4.setFirstName("Raj"); contact4.setLastName("babbar"); contact4.setEmail("*****@*****.**"); session.save(contact4); tx.commit(); System.out.println("Done"); } catch (Exception e) { // tx.rollback(); System.out.println(e.getMessage()); } finally { // Actual contact insertion will happen at this step session.flush(); session.close(); } }
@Test @Transactional public void testAddContactToGroupAndGroupConstituent() throws Exception { groupService.create(group); groupService.addAggregation(committee, group); Contact contact = new Contact(); contact.setFirstName("Test Contact"); contact.setEmail("*****@*****.**"); contactService.create(contact); contactService.addContactToCommittee(contact, committee); contactService.addToGroup(contact, group); contact = contactService.findById(contact.getId()); assertTrue(contact.getGroups().contains(group)); assertTrue(contact.getCommittees().contains(committee)); committee = committeeService.findById(committee.getId()); assertTrue(committee.getMembers().contains(contact)); group = groupService.findById(group.getId()); assertTrue(group.getTopLevelMembers().contains(contact)); }
@Test @Transactional public void testRemoveContactFromEventMultipleGroups() throws Exception { groupService.create(group); groupService.addAggregation(event, group); Group secondGroup = new Group(); secondGroup.setGroupName("Second Group"); groupService.create(secondGroup); groupService.addAggregation(event, secondGroup); Contact newContact = new Contact(); newContact.setFirstName("Fresh Contact"); newContact.setEmail("Fresh email"); contactService.create(newContact); event = eventService.findById(event.getId()); contactService.attendEvent(newContact, event); newContact = contactService.findById(newContact.getId()); contactService.unattendEvent(newContact, event); event = eventService.findById(event.getId()); assertFalse(event.getAttendees().contains(newContact)); newContact = contactService.findById(newContact.getId()); assertFalse(newContact.getAttendedEvents().contains(event)); }
@Test @Transactional public void testAddContactToOrganizationMultipleGroups() throws Exception { groupService.create(group); groupService.addAggregation(organization, group); Group secondGroup = new Group(); secondGroup.setGroupName("Second Group"); groupService.create(secondGroup); groupService.addAggregation(organization, secondGroup); Contact newContact = new Contact(); newContact.setFirstName("Fresh Contact"); newContact.setEmail("Fresh email"); contactService.create(newContact); contactService.addContactToOrganization(newContact, organization); newContact = contactService.findById(newContact.getId()); assertTrue(newContact.getOrganizations().contains(organization)); group = groupService.findById(group.getId()); assertTrue(group.getAggregations().contains(organization)); secondGroup = groupService.findById(secondGroup.getId()); assertTrue(secondGroup.getAggregations().contains(organization)); organization = organizationService.findById(organization.getId()); assertTrue(organization.getMembers().contains(newContact)); }
@Test public void testAddMultipleContacts() throws Exception { groupService.create(group); groupService.addAggregation(committee, group); group = groupService.findById(group.getId()); contactService.addToGroup(topLevel, group); Contact anotherContact = new Contact(); anotherContact.setFirstName("Another"); anotherContact.setEmail("*****@*****.**"); contactService.create(anotherContact); contactService.addToGroup(anotherContact, group); group = groupService.findById(group.getId()); assertEquals(2, group.getTopLevelMembers().size()); anotherContact = contactService.findById(anotherContact.getId()); topLevel = contactService.findById(topLevel.getId()); assertEquals(1, anotherContact.getGroups().size()); assertEquals(1, topLevel.getGroups().size()); groupService.delete(group); anotherContact = contactService.findById(anotherContact.getId()); topLevel = contactService.findById(topLevel.getId()); assertEquals(0, anotherContact.getGroups().size()); assertEquals(0, topLevel.getGroups().size()); }
public static void main(String[] args) { FileHandler fh = new FileHandler(); Contact c = new Contact(); List<Contact> contactList = new ArrayList<Contact>(); String[] fields = fh.readFile(new File("/names.txt")); for (int i = 0; i < fields.length; i++) { if (!(fields[i].equals("-----"))) { c.setFirstName(fields[i++]); c.setLastName(fields[i++]); c.setAddress(fields[i++]); c.setCity(fields[i++]); c.setState(fields[i++]); c.setZip(fields[i++]); c.setEmail(fields[i++]); c.setPhone(fields[i++]); } contactList.add(c); } for (int i = 0; i < contactList.size(); i++) { System.out.println( contactList.get(i).getFirstName() + " " + contactList.get(i).getLastName()); System.out.println(contactList.get(i).getAddress()); System.out.println( contactList.get(i).getCity() + ", " + contactList.get(i).getState() + " " + contactList.get(i).getZip()); System.out.println(contactList.get(i).getPhone()); System.out.println(contactList.get(i).getEmail()); System.out.println(); } }
private void createContacts() throws ConstraintViolation { first = new Contact(); first.setFirstName("First"); first.setEmail("*****@*****.**"); second = new Contact(); second.setFirstName("Second"); second.setEmail("*****@*****.**"); topLevel = new Contact(); topLevel.setFirstName("Top Level"); topLevel.setEmail("*****@*****.**"); contactService.create(first); contactService.create(second); contactService.create(topLevel); }
/** * Gets contact from view. * * @return a Contact */ public Contact getContact() { Contact c = new Contact(personView.get()); c.setAddress(getAddress()); c.setTele(getTele()); c.setEmail(getEmail()); c.setWebSites(getSites()); return c; }
@Test @Transactional public void testAddContactToMultipleGroupsMultipleConstituents() throws Exception { groupService.create(group); groupService.addAggregation(committee, group); groupService.addAggregation(event, group); Group secondGroup = new Group(); secondGroup.setGroupName("Second Group"); groupService.create(secondGroup); groupService.addAggregation(committee, secondGroup); groupService.addAggregation(event, secondGroup); Contact contact = new Contact(); contact.setFirstName("Test Contact"); contact.setEmail("*****@*****.**"); contactService.create(contact); contactService.addContactToCommittee(contact, committee); contactService.attendEvent(contact, event); contactService.addToGroup(contact, group); contactService.addToGroup(contact, secondGroup); contact = contactService.findById(contact.getId()); group = groupService.findById(group.getId()); secondGroup = groupService.findById(secondGroup.getId()); event = eventService.findById(event.getId()); committee = committeeService.findById(committee.getId()); assertTrue(contact.getGroups().contains(group)); assertTrue(contact.getGroups().contains(secondGroup)); assertTrue(contact.getCommittees().contains(committee)); assertTrue(contact.getAttendedEvents().contains(event)); assertTrue(event.getAttendees().contains(contact)); assertTrue(event.getGroups().contains(group)); assertTrue(event.getGroups().contains(secondGroup)); assertTrue(committee.getMembers().contains(contact)); assertTrue(committee.getGroups().contains(group)); assertTrue(committee.getGroups().contains(secondGroup)); assertTrue(group.getTopLevelMembers().contains(contact)); assertTrue(group.getAggregations().contains(committee)); assertTrue(group.getAggregations().contains(event)); assertTrue(secondGroup.getTopLevelMembers().contains(contact)); assertTrue(secondGroup.getAggregations().contains(committee)); assertTrue(secondGroup.getAggregations().contains(event)); }
public void action() { Contact contact = new Contact(); String name, phone; name = JOptionPane.showInputDialog("Ange namn"); contact.setName(name); phone = JOptionPane.showInputDialog("Ange hemtelefon"); contact.setPhone(phone); contact.setMobile(JOptionPane.showInputDialog("Ange mobil")); contact.setEmail(JOptionPane.showInputDialog("Ange mail-adress")); JOptionPane.showMessageDialog(null, contact.toString()); JOptionPane.showMessageDialog( null, contact.getName() + "\n" + contact.getPhone() + "\n" + contact.getMobile() + "\n" + contact.getEmail()); }
private void getUpdatedContactInfo(Contact currentContact) { EditText editText = (EditText) this.findViewById(R.id.contactName); currentContact.setName(editText.getText().toString()); EditText aliasText = (EditText) this.findViewById(R.id.alias); currentContact.setAlias(aliasText.getText().toString()); EditText businessText = (EditText) this.findViewById(R.id.business_edit); currentContact.setBusiness(businessText.getText().toString()); final EditText phoneText = (EditText) this.findViewById(R.id.phone_edit); final Spinner phoneOptions = (Spinner) this.findViewById(R.id.phone_spinner); currentContact.setPhone(new HashMap<String, String>()); currentContact .getPhone() .put(phoneOptions.getSelectedItem().toString(), phoneText.getText().toString()); final EditText emailText = (EditText) this.findViewById(R.id.email_edit); final Spinner emailOptions = (Spinner) this.findViewById(R.id.email_spinner); currentContact.setEmail(new HashMap<String, String>()); currentContact .getEmail() .put(emailOptions.getSelectedItem().toString(), emailText.getText().toString()); final EditText streetText = (EditText) this.findViewById(R.id.address1_edit); final EditText cityText = (EditText) this.findViewById(R.id.address_city_edit); final EditText zipText = (EditText) this.findViewById(R.id.zip_code_edit); final Spinner stateOptions = (Spinner) this.findViewById(R.id.state_spinner); final Spinner addressOptions = (Spinner) this.findViewById(R.id.address_spinner); currentContact.setAddresses(new HashMap<String, Address>()); currentContact .getAddresses() .put( addressOptions.getSelectedItem().toString(), new Address( streetText.getText().toString(), cityText.getText().toString(), stateOptions.getSelectedItem().toString(), zipText.getText().toString())); }
public static Contact createContact(String firstName, String lastName) { Contact contact = new Contact(firstName, lastName); String email = contact.getLastName() + (contactEmailNum++) + "@test.com"; contact.setEmail(email.toLowerCase()); return contact; }
public void getAndroidContacts() { String phoneNumber = null; String email = null; Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI; String _ID = ContactsContract.Contacts._ID; String DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME; String HAS_PHONE_NUMBER = ContactsContract.Contacts.HAS_PHONE_NUMBER; Uri PhoneCONTENT_URI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String Phone_CONTACT_ID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID; String NUMBER = ContactsContract.CommonDataKinds.Phone.NUMBER; Uri EmailCONTENT_URI = ContactsContract.CommonDataKinds.Email.CONTENT_URI; String EmailCONTACT_ID = ContactsContract.CommonDataKinds.Email.CONTACT_ID; String DATA = ContactsContract.CommonDataKinds.Email.DATA; StringBuffer output = new StringBuffer(); ContentResolver contentResolver = getContentResolver(); Cursor cursor = contentResolver.query(CONTENT_URI, null, null, null, null); { // Loop for every contact in the phone if (cursor.getCount() > 0) { while (cursor.moveToNext()) { Contact newContact = new Contact(); String contact_id = cursor.getString(cursor.getColumnIndex(_ID)); String name = cursor.getString(cursor.getColumnIndex(DISPLAY_NAME)); // debugging Log.d("Pulling from contacts: ", "Working .."); int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(HAS_PHONE_NUMBER))); if (hasPhoneNumber > 0) { // Query and loop for every phone number of the contact Cursor phoneCursor = contentResolver.query( PhoneCONTENT_URI, null, Phone_CONTACT_ID + " = ?", new String[] {contact_id}, null); while (phoneCursor.moveToNext()) { phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER)); } phoneCursor.close(); // Query and loop for every email of the contact Cursor emailCursor = contentResolver.query( EmailCONTENT_URI, null, EmailCONTACT_ID + " = ?", new String[] {contact_id}, null); while (emailCursor.moveToNext()) { email = emailCursor.getString(emailCursor.getColumnIndex(DATA)); } emailCursor.close(); } // sends phone number to the Contact object newContact.setPhone_num(phoneNumber); String spliced[] = name.split("\\s"); // checks for an "@" symbol in the first name of the contact pulled from the // local phone contacts to see whether it is actually an email address. if (spliced[0].indexOf("\u0040") != -1) { newContact.setFirstName("unknown contact information"); email = spliced[0]; } else { newContact.setFirstName(spliced[0]); } // checks to see whether there is or is not a last name placed in the name // category if (spliced.length > 1) { newContact.setLastName(spliced[1]); } // sets the email in the local contact app to the contact object newContact.setEmail(email); Log.d("new Contact email: ", email); if (email != "") { // sends the newly created object to the local contact database only if // there is a valid email entered for that contact ---TODO implement // facebook syncing with these email addresses to pull first and last // names into the application. MainActivity.db.dbAddContact(newContact); } } } } }
public static void main(String[] args) { Contact testContact = new Contact(); String input = null; // variable for users input Scanner keyboard = new Scanner(System.in); // creates Scanner Object System.out.print("Enter the last name: "); input = keyboard.nextLine(); // changes value of input testContact.setLastName(input); // sends input to setLastName method to be validated System.out.println("Last name: " + testContact.getLastName()); // displays users input System.out.print("Enter the first name: "); input = keyboard.nextLine(); // changes value of input testContact.setFirstName(input); // sends input to setFirstName method to be validated System.out.println("First name: " + testContact.getFirstName()); // displays users input System.out.print("Enter the Middle name: "); input = keyboard.nextLine(); // changes value of input testContact.setMiddleName(input); // sends input to setMiddleName method to be validated System.out.println("Middle name: " + testContact.getMiddleName()); // displays users input System.out.print("Enter the prefix (if you have none, input none): "); input = keyboard.nextLine(); // changes value of input testContact.setPrefix(input); // sends input to setPrefix method to be validated System.out.println("Prefix: " + testContact.getPrefix()); // displays users input System.out.print("Enter the phone number: "); input = keyboard.nextLine(); // changes value of input testContact.setPhoneNum(input); // sends input to setPhoneNum method to be validated System.out.println("Phone number: " + testContact.getPhoneNum()); // displays users input System.out.print("Enter the Email: "); input = keyboard.nextLine(); // changes value of input testContact.setEmail(input); // sends input to setEmail method to be validated System.out.println("Email: " + testContact.getEmail()); // displays users input System.out.print("Enter the Street: "); input = keyboard.nextLine(); // changes value of input testContact.setStreet(input); // sends input to setStreet method to be validated System.out.println("Street: " + testContact.getEmail()); // displays users input System.out.print("Enter the City: "); input = keyboard.nextLine(); // changes value of input testContact.setCity(input); // sends input to setCity method to be validated System.out.println("City: " + testContact.getCity()); // displays users input System.out.print("Enter the State: "); input = keyboard.nextLine(); // changes value of input testContact.setState(input); // sends input to setState method to be validated System.out.println("State: " + testContact.getState()); // displays users input System.out.print("Enter the Zip Code: "); input = keyboard.nextLine(); // changes value of input testContact.setZipCode(input); // sends input to setZipCode method to be validated System.out.println("Zip code: " + testContact.getZipCode()); // displays users input System.out.print("Enter the Occupation: "); input = keyboard.nextLine(); // changes value of input testContact.setOcupation(input); // sends input to setOccupation method to be validated System.out.println("Occupation: " + testContact.getOccupation()); // displays users input }