Commit 3ab75c9a authored by Michael Ritter's avatar Michael Ritter
Browse files

Catch EntityNotFoundException when attempting to remove

parent 2d1943b6
......@@ -43,6 +43,7 @@ import edu.umiacs.util.Strings;
import org.apache.log4j.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.EntityTransaction;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
......@@ -79,18 +80,27 @@ public class RemoveItemServlet extends EntityManagerServlet {
long itemId = getParameter(request, PARAM_ITEM_ID, 0);
long eventSession = System.currentTimeMillis();
if ( itemId > 0 ) {
try {
item = em.getReference(MonitoredItem.class, itemId);
removeItem(item, em, eventSession, dt);
mutations = ImmutableSet.of(item.getParentCollection());
} catch (EntityNotFoundException exception) {
mutations = ImmutableSet.of();
LOG.warn("MonitoredItem " + itemId + " already removed. Ignoring.", exception);
}
} else {
itemIds = getParameterList(request,REMOVAL, 0);
mutations = new HashSet<>();
if(itemIds != null){
for(long l:itemIds){
if(l > 0){
if(itemIds != null) {
for(long l:itemIds) {
if(l > 0) {
try {
item = em.getReference(MonitoredItem.class, l);
removeItem(item, em, eventSession, dt);
mutations.add(item.getParentCollection());
} catch (EntityNotFoundException exception) {
LOG.warn("MonitoredItem " + itemId + " already removed. Ignoring.", exception);
}
}
}
}
......@@ -110,7 +120,7 @@ public class RemoveItemServlet extends EntityManagerServlet {
dispatcher.forward(request, response);
}
private void removeItem(MonitoredItem item, EntityManager em, Long session, DirectoryTree dt){
private void removeItem(MonitoredItem item, EntityManager em, Long session, DirectoryTree dt) {
if ( item != null ) {
LogEventManager lem = new LogEventManager(session, item.getParentCollection());
lem.persistItemEvent(LogEnum.REMOVE_ITEM, item.getPath(), null, em);
......@@ -131,8 +141,10 @@ public class RemoveItemServlet extends EntityManagerServlet {
}
}
private static void reloadTree( DirectoryTree dt, String parent,
Collection c, EntityManager em ) {
private static void reloadTree(DirectoryTree dt,
String parent,
Collection c,
EntityManager em ) {
if ( dt == null ) {
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment