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; ...@@ -43,6 +43,7 @@ import edu.umiacs.util.Strings;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException; import javax.servlet.ServletException;
...@@ -56,7 +57,7 @@ import java.util.Set; ...@@ -56,7 +57,7 @@ import java.util.Set;
/** /**
* Remove an item from list of actively monitored items. This will not remove * Remove an item from list of actively monitored items. This will not remove
* log entries for the file. It will log the delete. * log entries for the file. It will log the delete.
* *
* @author toaster * @author toaster
*/ */
public class RemoveItemServlet extends EntityManagerServlet { public class RemoveItemServlet extends EntityManagerServlet {
...@@ -79,18 +80,27 @@ public class RemoveItemServlet extends EntityManagerServlet { ...@@ -79,18 +80,27 @@ public class RemoveItemServlet extends EntityManagerServlet {
long itemId = getParameter(request, PARAM_ITEM_ID, 0); long itemId = getParameter(request, PARAM_ITEM_ID, 0);
long eventSession = System.currentTimeMillis(); long eventSession = System.currentTimeMillis();
if ( itemId > 0 ) { if ( itemId > 0 ) {
item = em.getReference(MonitoredItem.class, itemId); try {
removeItem(item, em, eventSession, dt); item = em.getReference(MonitoredItem.class, itemId);
mutations = ImmutableSet.of(item.getParentCollection()); 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 { } else {
itemIds = getParameterList(request,REMOVAL, 0); itemIds = getParameterList(request,REMOVAL, 0);
mutations = new HashSet<>(); mutations = new HashSet<>();
if(itemIds != null){ if(itemIds != null) {
for(long l:itemIds){ for(long l:itemIds) {
if(l > 0){ if(l > 0) {
item = em.getReference(MonitoredItem.class, l); try {
removeItem(item, em, eventSession, dt); item = em.getReference(MonitoredItem.class, l);
mutations.add(item.getParentCollection()); 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 { ...@@ -110,7 +120,7 @@ public class RemoveItemServlet extends EntityManagerServlet {
dispatcher.forward(request, response); 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 ) { if ( item != null ) {
LogEventManager lem = new LogEventManager(session, item.getParentCollection()); LogEventManager lem = new LogEventManager(session, item.getParentCollection());
lem.persistItemEvent(LogEnum.REMOVE_ITEM, item.getPath(), null, em); lem.persistItemEvent(LogEnum.REMOVE_ITEM, item.getPath(), null, em);
...@@ -131,8 +141,10 @@ public class RemoveItemServlet extends EntityManagerServlet { ...@@ -131,8 +141,10 @@ public class RemoveItemServlet extends EntityManagerServlet {
} }
} }
private static void reloadTree( DirectoryTree dt, String parent, private static void reloadTree(DirectoryTree dt,
Collection c, EntityManager em ) { String parent,
Collection c,
EntityManager em ) {
if ( dt == null ) { if ( dt == null ) {
return; 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