* @throws SimalAPIException
*/
public String getPerson(RESTCommand cmd) throws SimalAPIException {
String id = command.getPersonID();
String email = command.getPersonEMail();
IPerson person = null;
try {
if (id != null) {
person = SimalRepositoryFactory.getPersonService().findById(
getRepository().getUniqueSimalID(id));
if (person == null) {
throw new SimalAPIException("Person with Simal ID " + id
+ " does not exist");
}
} else if (email != null){
person = SimalRepositoryFactory.getPersonService().findBySha1Sum(RDFUtils.getSHA1(email));
if (person == null) {
throw new SimalAPIException("Person with email " + email
+ " does not exist");
}
} else {
throw new SimalAPIException("Must provide sufficient parameters to identify a person, see REST API documentation for more details");
}
} catch (SimalRepositoryException e) {
throw new SimalAPIException(
"Unable to get XML representation of project from the repository",
e);
} catch (NoSuchAlgorithmException e) {
throw new SimalAPIException(
"Unable to generate an SHA1 hash of email: " + email,
e);
}
if (command.isXML()) {
try {
return person.toXML();
} catch (SimalRepositoryException e) {
throw new SimalAPIException(
"Unable to get XML representation of project from the repository",
e);
}
} else if (command.isJSON()) {
try {
return person.toJSON();
} catch (SimalRepositoryException e) {
throw new SimalAPIException(
"Unable to get XML representation of project from the repository",
e);
}