/** * Delete a group with the provided group ID. * * @param messageContext ESB message context. */ public void connect(final MessageContext messageContext) { final String groupId = (String) getParameter(messageContext, Constants.GROUP_ID); try { // If group ID is not provided entire group list is returned. if (groupId != null && !groupId.isEmpty()) { // Add authentication specific parameters for message context final ContactsService contactService = getContactService(messageContext); final String requestUrl = getRequestURLBuilder(messageContext, Constants.REQUEST_URL_GROUPS) .append(Constants.REQUEST_URL_GENERIC_END) .append(Constants.FORWARD_SLASH) .append(groupId) .toString(); final ContactGroupEntry group = contactService.getEntry(new URL(requestUrl), ContactGroupEntry.class); group.setEtag(Constants.ETAG); group.delete(); messageContext.getEnvelope().detach(); // Build new SOAP envelope to return to client. messageContext.setEnvelope( buildResultEnvelope( Constants.URN_DELETE_CONTACT_GROUP, Constants.DELETE_CONTACT_GROUP_RESULT)); } else { final ValidationException ve = new ValidationException("Group ID is not found."); log.error("Failed to validate group id: ", ve); storeErrorResponseStatus( messageContext, ve, Constants.ERROR_CODE_CONNECTOR_VALIDATION_EXCEPTION); handleException("Failed to validate group id: ", ve, messageContext); } } catch (MalformedURLException mue) { log.error("Error reading contact group entry from built URL: ", mue); storeErrorResponseStatus(messageContext, mue, Constants.ERROR_CODE_MALFORMED_URL_EXCEPTION); handleException("Error reading contact group entry from built URL: ", mue, messageContext); } catch (ServiceException se) { log.error("Service unavailable: ", se); storeErrorResponseStatus(messageContext, se, Constants.ERROR_CODE_SERVICE_EXCEPTION); handleException("Service unavailable: ", se, messageContext); } catch (IOException io) { log.error("Failed to access entry: ", io); storeErrorResponseStatus(messageContext, io, Constants.ERROR_CODE_IO_EXCEPTION); handleException("Failed to access entry: ", io, messageContext); } catch (RuntimeException re) { log.error("Error occured in connector: ", re); storeErrorResponseStatus(messageContext, re, Constants.ERROR_CODE_RUNTIME_EXCEPTION); handleException("Error occured in connector: ", re, messageContext); } }
public ContactsHandlerImpl(String user, String password, int cachelimit) throws AuthenticationException { myService = new ContactsService("kostaskar-testContacts-1"); myService.setUserCredentials(user, password); resetCacheLimit(cachelimit); }
public void addContact(Contact c, String[] groups) { try { // Create the entry to insert ContactEntry contact = new ContactEntry(); Name name = new Name(); final String NO_YOMI = null; name.setFullName(new FullName(c.getName(), NO_YOMI)); name.setGivenName(new GivenName(c.getName(), NO_YOMI)); name.setFamilyName(new FamilyName(c.getSurname(), NO_YOMI)); contact.setName(name); Email primaryMail = new Email(); primaryMail.setAddress(c.getEmail()); primaryMail.setPrimary(true); contact.addEmailAddress(primaryMail); URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full"); try { myService.insert(postUrl, contact); } catch (IOException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (ServiceException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } } catch (MalformedURLException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } }
public void importAllContacts() throws IOException, ServiceException { // import contacts setService(); URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/[email protected]/full"); Query myQuery = new Query(feedUrl); myQuery.setMaxResults(10); ContactFeed resultFeed = myService.query(myQuery, ContactFeed.class); // Print the results System.out.println(resultFeed.getTitle().getPlainText()); for (int i = 0; i < resultFeed.getEntries().size(); i++) { ContactEntry entry = resultFeed.getEntries().get(i); // Determine if this contact entry already exists in database (check Google ID): System.out.println(entry.getEtag()); System.out.println(entry.getId()); // if individual exists with Google ID, check to see if that invididual has all the emails // listed: // People tryPerosn = peopleRepo.findByPropertyValue("googleId", "googleId", entry.getId()); if (peopleRepo.findByPropertyValue("googleId", "googleId", entry.getEtag()) != null) { System.out.println( peopleRepo .findByPropertyValue("googleId", "googleId", entry.getId()) .getNodeId() .toString() + " He exists!"); } else { importContact(entry); } entry.getEmailAddresses(); } // If entry exists, check to see if entry }
public Contact[] getContacts() { if (cacheExpired() || numOfOperations == 0) { try { URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full"); resultFeed = myService.getFeed(feedUrl, ContactFeed.class); } catch (IOException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (ServiceException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } contacts = new Contact[resultFeed.getEntries().size()]; for (int i = 0; i < contacts.length; i++) { ContactEntry contact = resultFeed.getEntries().get(i); contacts[i] = new Contact(contact); } } return contacts; }
public void setService() throws AuthenticationException { myService = new ContactsService("exampleCo-exampleApp-1"); myService.setUserCredentials(user, pass); }
public void printAllContacts() throws ServiceException, IOException { // Request the feed setService(); URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/[email protected]/full"); Query myQuery = new Query(feedUrl); myQuery.setMaxResults(8); myQuery.setStringCustomParameter("group", "Business Contacts"); ContactFeed resultFeed = myService.query(myQuery, ContactFeed.class); // Print the results System.out.println(resultFeed.getTitle().getPlainText()); for (int i = 0; i < resultFeed.getEntries().size(); i++) { ContactEntry entry = resultFeed.getEntries().get(i); Name test = entry.getName(); FullName namee = test.getFullName(); People person = peopleRepo.save( new People(23, entry.getTitle().getPlainText(), entry.getTitle().getPlainText())); System.out.println(person.getNodeId().toString()); System.out.println("\t" + entry.getTitle().getPlainText()); System.out.println("Email addresses:"); for (com.google.gdata.data.extensions.Email email : entry.getEmailAddresses()) { System.out.print(" " + email.getAddress()); if (email.getRel() != null) { System.out.print(" rel:" + email.getRel()); } if (email.getLabel() != null) { System.out.print(" label:" + email.getLabel()); } if (email.getPrimary()) { System.out.print(" (primary) "); } System.out.print("\n"); } System.out.println("IM addresses:"); for (Im im : entry.getImAddresses()) { System.out.print(" " + im.getAddress()); if (im.getLabel() != null) { System.out.print(" label:" + im.getLabel()); } if (im.getRel() != null) { System.out.print(" rel:" + im.getRel()); } if (im.getProtocol() != null) { System.out.print(" protocol:" + im.getProtocol()); } if (im.getPrimary()) { System.out.print(" (primary) "); } System.out.print("\n"); } System.out.println("Groups:"); for (GroupMembershipInfo group : entry.getGroupMembershipInfos()) { String groupHref = group.getHref(); System.out.println(" Id: " + groupHref); } System.out.println("Extended Properties:"); for (ExtendedProperty property : entry.getExtendedProperties()) { if (property.getValue() != null) { System.out.println(" " + property.getName() + "(value) = " + property.getValue()); } else if (property.getXmlBlob() != null) { System.out.println( " " + property.getName() + "(xmlBlob)= " + property.getXmlBlob().getBlob()); } } String photoLink = entry.getContactPhotoLink().getHref(); System.out.println("Photo Link: " + photoLink); System.out.println("Contact's ETag: " + entry.getEtag()); } }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { UserService userService = UserServiceFactory.getUserService(); RequestDispatcher disp = null; if (userService.isUserLoggedIn()) { User user = userService.getCurrentUser(); PersistenceManager pm = PMF.get(); ContactsToken token = null; try { token = pm.getObjectById(ContactsToken.class, user.getEmail()); String teamName = req.getParameter("teamName"); if (teamName != null) { Team team = TeamDAO.getTeam(teamName); if (team != null) { // Get contacts GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); oauthParameters.setOAuthConsumerKey("anonymous"); oauthParameters.setOAuthConsumerSecret("anonymous"); oauthParameters.setOAuthToken(token.getToken()); oauthParameters.setOAuthTokenSecret(token.getTokenSecret()); OAuthSigner signer = new OAuthHmacSha1Signer(); ContactsService service = new ContactsService("ContactFeedDemo"); List<ContactEntry> result = null; List<String> mails = null; try { service.setOAuthCredentials(oauthParameters, signer); ContactFeed resultFeed = service.getFeed( new URL("https://www.google.com/m8/feeds/contacts/default/full"), ContactFeed.class); result = new ArrayList<ContactEntry>(resultFeed.getEntries()); mails = new ArrayList<String>(); for (ContactEntry ce : result) { for (Email em : ce.getEmailAddresses()) { mails.add(em.getAddress()); } } for (TMember tm : team.getMembers()) { mails.remove(tm.getName()); } } catch (OAuthException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } // end get contact list req.setAttribute("teamName", teamName); // req.setAttribute("teamMembers", teamMembers); req.setAttribute("contacts", mails); RequestDispatcher rd = req.getRequestDispatcher("/AddMember.jsp"); rd.forward(req, resp); } else { String errText = "team with team name " + teamName + "doesnt exist."; req.setAttribute("err", errText); disp = req.getRequestDispatcher("err.jsp"); disp.forward(req, resp); } } else { String errText = "parametru teamName is null"; req.setAttribute("err", errText); disp = req.getRequestDispatcher("err.jsp"); disp.forward(req, resp); } } catch (JDOObjectNotFoundException e) { String consumerKey = "anonymous"; String consumerSecret = "anonymous"; String scope = "https://www.google.com/m8/feeds"; String callback = "http://vrchlpet-pc.appspot.com/callbackservlet"; GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); oauthParameters.setOAuthConsumerKey(consumerKey); oauthParameters.setOAuthConsumerSecret(consumerSecret); oauthParameters.setScope(scope); oauthParameters.setOAuthCallback(callback); OAuthSigner signer = new OAuthHmacSha1Signer(); GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer); try { oauthHelper.getUnauthorizedRequestToken(oauthParameters); String approvalPageUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters); req.getSession().setAttribute("tokenSecret", oauthParameters.getOAuthTokenSecret()); resp.sendRedirect(approvalPageUrl); return; } catch (OAuthException ee) { ee.printStackTrace(); } } } else { disp = req.getRequestDispatcher("/projectcontrol"); disp.forward(req, resp); } }