Skip to content
Permalink
Browse files

#1135 Catch base exception (Exception) in create, update, delete actions

  • Loading branch information...
MPDLbrede committed Nov 5, 2019
1 parent d656345 commit c2e970b739df00e30c9726a459d2f84a9a2e3a28
Showing with 22 additions and 8 deletions.
  1. +22 −8 src/main/java/de/mpg/imeji/logic/db/writer/WriterFacade.java
@@ -102,19 +102,20 @@ public WriterFacade(String modelURI, SearchObjectTypes type) {
checkWorkflow(objects, "create");
checkSecurity(objects, user, true);
validate(objects, Validator.Method.CREATE);
// writer.create(objects, user);
// indexer.indexBatch(objects);
try {
List<Object> createdObjectsInJena = executor.submit(new CreateTask(objects, user)).get();
executor.submit(new IndexTask(createdObjectsInJena)).get();
return createdObjectsInJena;
} catch (ExecutionException | InterruptedException | CancellationException execExept) {
} catch (ExecutionException | InterruptedException | CancellationException execExept) {
if (execExept.getCause() instanceof ImejiException) {
throw (ImejiException) execExept.getCause();
} else {
throw new ImejiException(execExept.getMessage());
}
}
catch(Exception e) {
throw new ImejiException(e.getMessage());
}
}

/*
@@ -140,6 +141,9 @@ public void delete(List<Object> objects, User user) throws ImejiException {
throw new ImejiException(execExept.getMessage());
}
}
catch(Exception e) {
throw new ImejiException(e.getMessage());
}
}

/*
@@ -168,6 +172,9 @@ public void delete(List<Object> objects, User user) throws ImejiException {
throw new ImejiException(execExept.getMessage());
}
}
catch(Exception e) {
throw new ImejiException(e.getMessage());
}
}

/**
@@ -194,8 +201,9 @@ public void delete(List<Object> objects, User user) throws ImejiException {
throw new ImejiException(execExept.getMessage());
}
}


catch(Exception e) {
throw new ImejiException(e.getMessage());
}
}


@@ -231,6 +239,9 @@ public Object changeElement(ChangeMember changeMember, User user) throws ImejiEx
throw new ImejiException(execExept.getMessage());
}
}
catch(Exception e) {
throw new ImejiException(e.getMessage());
}
}

/**
@@ -254,7 +265,6 @@ public Object changeElement(ChangeMember changeMember, User user) throws ImejiEx
validate(valueToSet, Validator.Method.UPDATE);
}


try {
// write list of changes to Jena and get latest object version:
List<Object> dataObjectsFromStore = (List<Object>) executor.submit(new EditElementsTask(changeElements)).get();
@@ -275,6 +285,9 @@ public Object changeElement(ChangeMember changeMember, User user) throws ImejiEx
throw new ImejiException(execExept.getMessage());
}
}
catch(Exception e) {
throw new ImejiException(e.getMessage());
}
}


@@ -316,13 +329,13 @@ private void validate(List<Object> list, Validator.Method method) throws Unproce


private void validate(Object object, Validator.Method method) throws UnprocessableError {

final Validator<Object> validator = (Validator<Object>) ValidatorFactory.newValidator(object, method);
validator.validate(object, method);

}

private void checkWorkflow(List<Object> objects, String operation) throws WorkflowException {

for (final Object o : objects) {
if (o instanceof Properties) {
switch (operation) {
@@ -350,6 +363,7 @@ private void checkWorkflow(List<Object> objects, String operation) throws Workfl
* @throws AuthenticationError
*/
private void checkSecurity(List<Object> list, final User user, boolean create) throws NotAllowedError, AuthenticationError {

String message = user != null ? user.getEmail() : "";
for (final Object o : list) {
message += " not allowed to " + (create ? "create " : "edit ") + extractID(o);

0 comments on commit c2e970b

Please sign in to comment.
You can’t perform that action at this time.