/** * @param newProfileSid * @return */ public ProfileAssociation setProfileSid(final Sid newProfileSid){ return new ProfileAssociation(newProfileSid, targetSid, dateCreated, Calendar.getInstance().getTime()); } @NotThreadSafe
private Map<String, Object> toMap(final ProfileAssociation profileAssociation) { final Map<String, Object> map = new HashMap<String, Object>(); map.put("profile_sid", DaoUtils.writeSid(profileAssociation.getProfileSid())); map.put("target_sid", DaoUtils.writeSid(profileAssociation.getTargetSid())); map.put("date_created", profileAssociation.getDateCreated()); map.put("date_updated", profileAssociation.getDateCreated()); return map; }
public ResponseBuilder getProfileBuilder(Profile profile , UriInfo info) { try { Response.ResponseBuilder ok = Response.ok(profile.getProfileDocument()); List<ProfileAssociation> profileAssociationsByProfileSid = profileAssociationsDao.getProfileAssociationsByProfileSid(profile.getSid()); for (ProfileAssociation assoc : profileAssociationsByProfileSid) { LinkHeader composeLink = composeLink(assoc.getTargetSid(), info); ok.header(LINK_HEADER, composeLink.toString()); } ok.header(LINK_HEADER, composeSchemaLink(info)); String profileStr = profile.getProfileDocument();// IOUtils.toString(profile.getProfileDocument(), PROFILE_ENCODING); ok.entity(profileStr); ok.lastModified(profile.getDateUpdated()); ok.type(PROFILE_CONTENT_TYPE); return ok; } catch (Exception ex) { logger.debug("getting profile", ex); return Response.serverError().entity(ex.getMessage()); } }
/** * @param targetSid * @return will return associated profile of provided target (account or * organization) */ @Override public Profile retrieveExplicitlyAssociatedProfile(Sid targetSid) { ProfileAssociation assoc = daoManager.getProfileAssociationsDao().getProfileAssociationByTargetSid(targetSid.toString()); Profile profile = null; if (assoc != null) { try { profile = daoManager.getProfilesDao().getProfile(assoc.getProfileSid().toString()); } catch (SQLException ex) { throw new RuntimeException("problem retrieving profile", ex); } } if (logger.isDebugEnabled()) { logger.debug("Returning profile:" + profile); } return profile; } }
public ProfileAssociation build() { return new ProfileAssociation(profileSid, targetSid, dateCreated, Calendar.getInstance().getTime()); }
private ProfileAssociation toProfileAssociation(final Map<String, Object> map) { final Sid profileSid = DaoUtils.readSid(map.get("profile_sid")); final Sid targetSid = DaoUtils.readSid(map.get("target_sid")); final DateTime dateCreated = DaoUtils.readDateTime(map.get("date_created")); final DateTime dateUpdated = DaoUtils.readDateTime(map.get("date_updated")); return new ProfileAssociation(profileSid, targetSid, dateCreated.toDate(), dateUpdated.toDate()); }
public Response linkProfile(String profileSidStr, HttpHeaders headers, UriInfo uriInfo) { checkProfileExists(profileSidStr); List<String> requestHeader = checkLinkHeader(headers); LinkHeader link = LinkHeader.valueOf(requestHeader.get(0)); checkRelType(link); String targetSidStr = retrieveSid(link.getUri()); Sid targetSid = new Sid(targetSidStr); checkTargetSid(targetSid); Sid profileSid = new Sid(profileSidStr); ProfileAssociation assoc = new ProfileAssociation(profileSid, targetSid, new Date(), new Date()); //remove previous link if any profileAssociationsDao.deleteProfileAssociationByTargetSid(targetSidStr); profileAssociationsDao.addProfileAssociation(assoc); return Response.ok().build(); }