@GET
@Path("contacts/incoming")
public Response getIncoming(@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.getIncoming(identity);
JSONArray jsonArray = new JSONArray();
for (Relationship relation : relations) {
Identity senderId = relation.getSender();
String avatar = senderId.getProfile().getAvatarImageSource();
if (avatar == null) {
avatar = "/eXoSkin/skin/images/system/Avatar.gif";
}
JSONObject json = new JSONObject();
json.put("senderName", senderId.getProfile().getFullName());
json.put("relationId", relation.getId());
json.put("avatar", avatar);
json.put("profile", senderId.getProfile().getUrl());
jsonArray.put(json);
}
return Response.ok(jsonArray.toString(), MediaType.APPLICATION_JSON).cacheControl(cacheControl).build();
} catch (Exception e) {
log.error("Error in people incoming rest service: " + e.getMessage(), e);
return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cacheControl).build();
}
}