}
public Representation get()
{
try {
Group group = fetch();
if (group!=null) {
if (facet!=null) {
if (facet.equals(USER_FACET)) {
if (facetId!=null) {
try {
UUID id = UUID.fromString(facetId);
User user = db.getUser(id);
if (user!=null) {
Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,user);
entity.setCharacterSet(CharacterSet.UTF_8);
return entity;
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation("Canot find user by id "+facetId);
}
} catch (SQLException ex) {
getContext().getLogger().log(Level.SEVERE,"Cannot get user with id "+facetId+" from database.",ex);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("Exception while processing, see logs.");
} catch (IllegalArgumentException ex) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Bad UUID value "+facetId);
}
} else if (facetName!=null) {
try {
User user = db.getUser(facetName);
if (user!=null) {
Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,user);
entity.setCharacterSet(CharacterSet.UTF_8);
return entity;
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation("Cannot find user by alias "+facetName);
}
} catch (SQLException ex) {
getContext().getLogger().log(Level.SEVERE,"Cannot get user with alias "+facetName+" from database.",ex);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("Exception during processing, see logs.");
}
} else {
try {
Representation entity = new DBIteratorRepresentation(MediaType.APPLICATION_XML,XML.USERS_NAME,group.getMembers());
entity.setCharacterSet(CharacterSet.UTF_8);
return entity;
} catch (SQLException ex) {
getContext().getLogger().log(Level.SEVERE,"Cannot get users from database.",ex);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("Exception during processing, see logs.");
}
}
} else if (facet.equals(ROLE_FACET)) {
if (facetId!=null) {
try {
UUID id = UUID.fromString(facetId);
Role role = db.getRole(id);
if (role!=null) {
Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,role);
entity.setCharacterSet(CharacterSet.UTF_8);
return entity;
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return null;
}
} catch (SQLException ex) {
getContext().getLogger().log(Level.SEVERE,"Cannot get role with id "+facetId+" from database.",ex);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("Exception during processing, see logs.");
} catch (IllegalArgumentException ex) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Bad UUID value "+facetId);
}
} else if (facetName!=null) {
try {
Role role = db.getRole(facetName);
if (role!=null) {
Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,role);
entity.setCharacterSet(CharacterSet.UTF_8);
return entity;
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return null;
}
} catch (SQLException ex) {
getContext().getLogger().log(Level.SEVERE,"Cannot get role with name "+facetName+" from database.",ex);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("Exception during processing, see logs.");
}
} else {
Representation entity = new DBIteratorRepresentation(MediaType.APPLICATION_XML,XML.ROLES_NAME,group.getRoles());
entity.setCharacterSet(CharacterSet.UTF_8);
return entity;
}
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);