Skip to content

Commit

Permalink
Implement the delete eperson method
Browse files Browse the repository at this point in the history
  • Loading branch information
abollini committed Jun 1, 2018
1 parent d698d3d commit d7aeff7
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
*/
package org.dspace.app.rest.repository;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.Parameter;
import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.converter.EPersonConverter;
import org.dspace.app.rest.exception.RESTAuthorizationException;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.EPersonRest;
import org.dspace.app.rest.model.hateoas.EPersonResource;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
Expand Down Expand Up @@ -107,6 +112,27 @@ public EPersonRest findByEmail(@Parameter(value = "email", required = true) Stri
return converter.fromModel(eperson);
}

@Override
protected void delete(Context context, UUID id) throws AuthorizeException, RepositoryMethodNotImplementedException {
EPerson eperson = null;
try {
eperson = es.find(context, id);
List<String> constraints = es.getDeleteConstraints(context, eperson);
if (constraints != null && constraints.size() > 0) {
throw new UnprocessableEntityException(
"The eperson cannot be deleted due to the following constraints: "
+ StringUtils.join(constraints, ", "));
}
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
try {
es.delete(context, eperson);
} catch (SQLException | IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}

@Override
public Class<EPersonRest> getDomainClass() {
return EPersonRest.class;
Expand Down

0 comments on commit d7aeff7

Please sign in to comment.