@GET
@Path("contacts/pending")
public Response getPending(@Context SecurityContext sc, @Context UriInfo uriInfo) {
try {
String userId = getUserId(sc, uriInfo);
if (userId == null) {
return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build();
}
Identity identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId);
List<Relationship> relations = relationshipManager.getPending(identity);
JSONArray jsonArray = new JSONArray();
for (Relationship relation : relations) {
Identity senderId = relation.getSender();
Profile senderProfile = senderId.getProfile();
Identity receiverId = relation.getReceiver();
Profile receiverProfile = receiverId.getProfile();
JSONObject json = new JSONObject();
json.put("senderName", senderProfile.getFullName());
json.put("senderId", senderId.getId());
json.put("receiverName", receiverProfile.getFullName());
json.put("receiverId", receiverId.getId());
json.put("status", relation.getStatus());
jsonArray.put(json);
}
return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON).cacheControl(cacheControl).build();
} catch (Exception e) {
log.error("Error in people pending rest service: " + e.getMessage(), e);
return Response.ok("error").cacheControl(cacheControl).build();
}
}