return null;
}
try {
Group group = fetch();
Element top = doc.getDocumentElement();
if (facet.equals(ROLE_FACET)) {
if (top.getName().equals(XML.ROLE_NAME)) {
String sid = top.getAttributeValue("id");
String name = top.getAttributeValue("name");
Role role = null;
if (sid!=null) {
role = db.getRole(UUID.fromString(sid));
}
if (name!=null && role==null) {
role = db.getRole(name);
}
if (role==null) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Cannot find role "+name);
} else {
group.addRole(role);
getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
return null;
}
} else {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Element "+top.getName()+" is not allowed.");
}
} else if (facet.equals(USER_FACET)) {
if (top.getName().equals(XML.USER_NAME)) {
String sid = top.getAttributeValue("id");
String alias = top.getAttributeValue("alias");
RealmUser user = null;
if (sid!=null) {
UUID id = UUID.fromString(sid);
user = fetchUser(id);
} else {
user = fetchUser(alias);
}
if (user==null) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Cannot find user.");
} else {
group.addMember(user);
getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
return null;
}
} else {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("Element "+top.getName()+" is not allowed.");
}
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return null;
}