Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.labkey.api.data.ContainerManager;
import org.labkey.api.security.User;

public class AnnouncementContainerListener extends ContainerManager.AbstractContainerListener
public class AnnouncementContainerListener implements ContainerManager.ContainerListener
{
// Note: Attachments are purged by AttachmentServiceImpl.containerDeleted()
@Override
Expand Down
6 changes: 0 additions & 6 deletions api/src/org/labkey/api/data/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,6 @@ public void containerMoved(Container c, Container oldParent, User user)
REQUIRED_MODULES_CACHE.clear();
}

@Override
public @NotNull Collection<String> canMove(Container c, Container newParent, User user)
{
return Collections.emptyList();
}

@Override
public void propertyChange(PropertyChangeEvent evt)
{
Expand Down
103 changes: 19 additions & 84 deletions api/src/org/labkey/api/data/ContainerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public static Container createContainer(Container parent, String name, @Nullable
SecurityManager.setInheritPermissions(c);
}

// NOTE parent caches some info about children (e.g. hasWorkbookChildren)
// NOTE parent caches some info about children (e.g., hasWorkbookChildren)
// since mutating cached objects is frowned upon, just uncache parent
// CONSIDER: we could perhaps only uncache if the child is a workbook, but I think this reasonable
_removeFromCache(parent, true);
Expand Down Expand Up @@ -1165,7 +1165,6 @@ public static Container getChild(Container c, String name)
return map.get(name);
}


public static Container getForURL(@NotNull ActionURL url)
{
Container ret = getForPath(url.getExtraPath());
Expand All @@ -1174,7 +1173,6 @@ public static Container getForURL(@NotNull ActionURL url)
return ret;
}


public static Container getForPath(@NotNull String path)
{
if (GUID.isGUID(path))
Expand Down Expand Up @@ -1448,7 +1446,7 @@ public static NavTree getFolderListForUser(final Container project, ViewContext

NavTree t = new NavTree(name);

// 34137: Support folder path expansion for containers where label != name
// Issue 34137: Support folder path expansion for containers where label != name
t.setId(f.getId());
if (hasPolicyRead)
{
Expand All @@ -1464,7 +1462,7 @@ public static NavTree getFolderListForUser(final Container project, ViewContext
}
else
{
// 32718: If navigation access is not open then hide projects that aren't directly
// Issue 32718: If navigation access is not open then hide projects that aren't directly
// accessible in site folder navigation.

if (f.equals(c) || f.isRoot() || (hasPolicyRead && f.isProject()))
Expand Down Expand Up @@ -1689,7 +1687,7 @@ public static boolean move(Container c, final Container newParent, User user) th

boolean changedProjects = !oldProject.getId().equals(newProject.getId());

// Synchronize the transaction, but not the listeners -- see #9901
// Issue 9901: Synchronize the transaction, but not the listeners
try (DbScope.Transaction t = ensureTransaction())
{
new SqlExecutor(CORE.getSchema()).execute("UPDATE " + CORE.getTableInfoContainers() + " SET Parent = ? WHERE EntityId = ?", newParent.getId(), c.getId());
Expand Down Expand Up @@ -1752,7 +1750,7 @@ public static Container rename(@NotNull Container c, User user, String name, @Nu
// Rename
if (isRenaming)
{
// Issue 16221: Don't allow renaming of system reserved folders (e.g. /Shared, home, root, etc).
// Issue 16221: Don't allow renaming of system reserved folders (e.g., /Shared, home, root, etc).
if (!isRenameable(c))
throw new ApiUsageException("This folder may not be renamed as it is reserved by the system.");

Expand Down Expand Up @@ -1949,8 +1947,7 @@ private static boolean delete(final Container c, User user, @Nullable String com
if (experimentService != null)
experimentService.removeContainerDataTypeExclusions(c.getId());

// After we've committed the transaction, be sure that we remove this container from the cache
// See https://www.labkey.org/issues/home/Developer/issues/details.view?issueId=17015
// Issue 17015: After we've committed the transaction, be sure that we remove this container from the cache
tx.addCommitTask(() ->
{
// Be sure that we've waited until any threads that might be populating the cache have finished
Expand Down Expand Up @@ -2141,7 +2138,6 @@ public static void notifyContainerChange(String id, Property prop, @Nullable Use
}
}


/** Recursive, including root node */
public static Set<Container> getAllChildren(Container root)
{
Expand Down Expand Up @@ -2192,7 +2188,6 @@ public static long getAuditCommentRequiredCount()
return new SqlSelector(CORE.getSchema(), sql).getObject(Long.class);
}


/** Retrieve entire container hierarchy */
public static MultiValuedMap<Container, Container> getContainerTree()
{
Expand Down Expand Up @@ -2264,7 +2259,6 @@ public static Set<Container> getContainerSet(MultiValuedMap<Container, Container
.collect(Collectors.toSet());
}


public static SQLFragment getIdsAsCsvList(Set<Container> containers, SqlDialect d)
{
if (containers.isEmpty())
Expand All @@ -2283,7 +2277,6 @@ public static SQLFragment getIdsAsCsvList(Set<Container> containers, SqlDialect
return csvList;
}


public static List<String> getIds(User user, Class<? extends Permission> perm)
{
Set<Container> containers = getContainerSet(getContainerTree(), user, perm);
Expand All @@ -2296,67 +2289,38 @@ public static List<String> getIds(User user, Class<? extends Permission> perm)
return ids;
}


//
// ContainerListener
//

public interface ContainerListener extends PropertyChangeListener
{
enum Order {First, Last}

/** Called after a new container has been created */
void containerCreated(Container c, User user);
default void containerCreated(Container c, User user) { }

default void containerCreated(Container c, User user, @Nullable String auditMsg)
{
containerCreated(c, user);
}

/** Called immediately prior to deleting the row from core.containers */
void containerDeleted(Container c, User user);
/** Called immediately before deleting the row from core.containers */
default void containerDeleted(Container c, User user) { }

/** Called after the container has been moved to its new parent */
void containerMoved(Container c, Container oldParent, User user);
/** Called after the container has been moved to its new parent (post-commit) */
default void containerMoved(Container c, Container oldParent, User user) { }

/**
* Called prior to moving a container, to find out if there are any issues that would prevent a successful move
* Called before moving a container, to find out if there are any issues that would prevent a successful move
* @return a list of errors that should prevent the move from happening, if any
*/
@NotNull
Collection<String> canMove(Container c, Container newParent, User user);

@Override
void propertyChange(PropertyChangeEvent evt);
}

public static abstract class AbstractContainerListener implements ContainerListener
{
@Override
public void containerCreated(Container c, User user)
{}

@Override
public void containerDeleted(Container c, User user)
{}

@Override
public void containerMoved(Container c, Container oldParent, User user)
{}

@NotNull
@Override
public Collection<String> canMove(Container c, Container newParent, User user)
default Collection<String> canMove(Container c, Container newParent, User user)
{
return Collections.emptyList();
}

@Override
public void propertyChange(PropertyChangeEvent evt)
{}
default void propertyChange(PropertyChangeEvent evt) { }
}


public static class ContainerPropertyChangeEvent extends PropertyChangeEvent implements PropertyChange<Property, Object>
{
public final Property property;
Expand All @@ -2383,7 +2347,6 @@ public Property getProperty()
}
}


// Thread-safe list implementation that allows iteration and modifications without external synchronization
private static final List<ContainerListener> _listeners = new CopyOnWriteArrayList<>();
private static final List<ContainerListener> _laterListeners = new CopyOnWriteArrayList<>();
Expand All @@ -2394,7 +2357,6 @@ public static void addContainerListener(ContainerListener listener)
addContainerListener(listener, ContainerListener.Order.First);
}


// Explicitly request "Last" ordering via this method. "Last" listeners execute after all "First" listeners.
public static void addContainerListener(ContainerListener listener, ContainerListener.Order order)
{
Expand All @@ -2404,14 +2366,12 @@ public static void addContainerListener(ContainerListener listener, ContainerLis
_laterListeners.add(listener);
}


public static void removeContainerListener(ContainerListener listener)
{
_listeners.remove(listener);
_laterListeners.remove(listener);
}


private static List<ContainerListener> getListeners()
{
List<ContainerListener> combined = new ArrayList<>(_listeners.size() + _laterListeners.size());
Expand All @@ -2421,7 +2381,6 @@ private static List<ContainerListener> getListeners()
return combined;
}


private static List<ContainerListener> getListenersReversed()
{
List<ContainerListener> combined = new LinkedList<>();
Expand All @@ -2431,7 +2390,7 @@ private static List<ContainerListener> getListenersReversed()
ListIterator<ContainerListener> iter = copy.listIterator(copy.size());

// Iterate in reverse
while(iter.hasPrevious())
while (iter.hasPrevious())
combined.add(iter.previous());

// Copy to guarantee consistency between .listIterator() and .size()
Expand All @@ -2440,13 +2399,12 @@ private static List<ContainerListener> getListenersReversed()
ListIterator<ContainerListener> laterIter = laterCopy.listIterator(laterCopy.size());

// Iterate in reverse
while(laterIter.hasPrevious())
while (laterIter.hasPrevious())
combined.add(laterIter.previous());

return combined;
}


protected static void fireCreateContainer(Container c, User user, @Nullable String auditMsg)
{
List<ContainerListener> list = getListeners();
Expand All @@ -2464,7 +2422,6 @@ protected static void fireCreateContainer(Container c, User user, @Nullable Stri
}
}


protected static void fireDeleteContainer(Container c, User user)
{
List<ContainerListener> list = getListenersReversed();
Expand All @@ -2480,21 +2437,19 @@ protected static void fireDeleteContainer(Container c, User user)
{
LOG.error("fireDeleteContainer for " + l.getClass().getName(), e);

// Fail fast (first Throwable aborts iteration), #17560
// Issue 17560: Fail fast (first Throwable aborts iteration)
throw e;
}
}
}


protected static void fireRenameContainer(Container c, User user, String oldValue)
private static void fireRenameContainer(Container c, User user, String oldValue)
{
ContainerPropertyChangeEvent evt = new ContainerPropertyChangeEvent(c, user, Property.Name, oldValue, c.getName());
firePropertyChangeEvent(evt);
}


protected static void fireMoveContainer(Container c, Container oldParent, User user)
private static void fireMoveContainer(Container c, Container oldParent, User user)
{
List<ContainerListener> list = getListeners();

Expand All @@ -2512,7 +2467,6 @@ protected static void fireMoveContainer(Container c, Container oldParent, User u
firePropertyChangeEvent(evt);
}


public static void firePropertyChangeEvent(ContainerPropertyChangeEvent evt)
{
if (_constructing.contains(evt.container.getEntityId()))
Expand Down Expand Up @@ -2986,12 +2940,6 @@ private static void logNode(MultiValuedMap<String, String> mm, String name, int
}
}

// ContainerListener
@Override
public void propertyChange(PropertyChangeEvent evt)
{
}

@Override
public void containerCreated(Container c, User user)
{
Expand All @@ -3000,24 +2948,11 @@ public void containerCreated(Container c, User user)
_containers.put(c.getParsedPath(), c);
}


@Override
public void containerDeleted(Container c, User user)
{
_containers.remove(c.getParsedPath());
}

@Override
public void containerMoved(Container c, Container oldParent, User user)
{
}

@NotNull
@Override
public Collection<String> canMove(Container c, Container newParent, User user)
{
return Collections.emptyList();
}
}

static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@
import java.util.Collections;
import java.util.List;

/**
* User: bimber
* Date: 3/4/13
* Time: 10:45 AM
*/
public class SimpleModuleContainerListener extends ContainerManager.AbstractContainerListener
public class SimpleModuleContainerListener implements ContainerManager.ContainerListener
{
private final Module _owner;

Expand Down
6 changes: 1 addition & 5 deletions api/src/org/labkey/api/reports/model/ReportPropsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@
import java.util.List;
import java.util.Map;

/**
* User: klum
* Date: Feb 13, 2012
*/
public class ReportPropsManager extends ContainerManager.AbstractContainerListener
public class ReportPropsManager implements ContainerManager.ContainerListener
{
private static final Logger _log = LogManager.getLogger(ReportPropsManager.class);
private static final String PROPERTIES_DOMAIN = "Report Properties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* User: klum
* Date: Oct 12, 2011
* Time: 7:13:20 PM
*/
public class ViewCategoryManager extends ContainerManager.AbstractContainerListener
public class ViewCategoryManager implements ContainerManager.ContainerListener
{
private static final ViewCategoryManager _instance = new ViewCategoryManager();
private static final List<ViewCategoryListener> _listeners = new CopyOnWriteArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/security/SecurityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private static void scrubTables()
}

/** Move is handled by direct call from ContainerManager into SecurityManager */
private static class SecurityContainerListener extends ContainerManager.AbstractContainerListener
private static class SecurityContainerListener implements ContainerManager.ContainerListener
{
@Override
public void containerDeleted(Container c, User user)
Expand Down
Loading