Skip to content

Commit

Permalink
support plateId and remove plate name from the plate cache
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-klum committed Jan 26, 2024
1 parent c9564ba commit 7c37c9b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 26 deletions.
2 changes: 2 additions & 0 deletions assay/api-src/org/labkey/api/assay/plate/Plate.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public interface Plate extends PropertySet, Identifiable

@Nullable PlateSet getPlateSet();

@NotNull String getPlateId();

/**
* Returns an existing well, or creates a new well if one
* had not previously existed.
Expand Down
16 changes: 16 additions & 0 deletions assay/api-src/org/labkey/api/assay/plate/PlateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ static PlateService get()
*/
@Nullable Plate getPlate(Container container, int rowId);

/**
* Gets a plate instance object by plate id.
* @param container The plate's container.
* @param plateId The plate id of the plate.
* @return The requested plate, or null if no plate exists with the specified plate id.
*/
@Nullable Plate getPlate(Container container, String plateId);

/**
* Gets a plate instance object by row id.
* @param cf The container filter to find the plate
Expand All @@ -146,6 +154,14 @@ static PlateService get()
*/
@Nullable Plate getPlate(ContainerFilter cf, Lsid lsid);

/**
* Gets a plate instance object by plate id.
* @param cf The container filter to find the plate
* @param plateId The plate id of the plate.
* @return The requested plate, or null if no plate exists with the specified plate id.
*/
@Nullable Plate getPlate(ContainerFilter cf, String plateId);

/**
* Gets all plate templates for the specified container. Plate templates are Plate instances
* which have their template field set to TRUE.
Expand Down
5 changes: 1 addition & 4 deletions assay/src/org/labkey/assay/AssayDomainServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.labkey.api.assay.AssayDomainService;
import org.labkey.api.assay.AssayProvider;
import org.labkey.api.assay.AssayQCService;
import org.labkey.api.assay.AssaySchema;
import org.labkey.api.assay.AssayService;
import org.labkey.api.assay.DetectionMethodAssayProvider;
import org.labkey.api.assay.plate.Plate;
Expand Down Expand Up @@ -58,9 +57,7 @@
import org.labkey.api.gwt.client.model.GWTContainer;
import org.labkey.api.gwt.client.model.GWTDomain;
import org.labkey.api.gwt.client.model.GWTPropertyDescriptor;
import org.labkey.api.query.QueryChangeListener;
import org.labkey.api.query.QueryService;
import org.labkey.api.query.SchemaKey;
import org.labkey.api.query.ValidationException;
import org.labkey.api.security.SecurityPolicy;
import org.labkey.api.security.User;
Expand Down Expand Up @@ -484,7 +481,7 @@ public GWTProtocol saveChanges(GWTProtocol assay, boolean replaceIfExisting) thr
if (provider instanceof PlateBasedAssayProvider && assay.getSelectedPlateTemplate() != null)
{
PlateBasedAssayProvider plateProvider = (PlateBasedAssayProvider)provider;
Plate plate = PlateManager.get().getPlate(getContainer(), assay.getSelectedPlateTemplate());
Plate plate = PlateManager.get().getPlateByName(getContainer(), assay.getSelectedPlateTemplate());
if (plate != null)
plateProvider.setPlate(getContainer(), protocol, plate);
else
Expand Down
2 changes: 1 addition & 1 deletion assay/src/org/labkey/assay/AssayUpgradeCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private static Plate getPlate(ExpProtocol protocol)
{
// resolve plate by the legacy deprecated plate name method
ObjectProperty prop = protocol.getObjectProperties().get(protocol.getLSID() + AbstractPlateBasedAssayProvider.PLATE_TEMPLATE_SUFFIX);
return prop != null ? PlateManager.get().getPlate(protocol.getContainer(), prop.getStringValue()) : null;
return prop != null ? PlateManager.get().getPlateByName(protocol.getContainer(), prop.getStringValue()) : null;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions assay/src/org/labkey/assay/PlateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ public static class CopyTemplateBean

public CopyTemplateBean(final Container container, final User user, final Integer plateId, final String selectedDestination)
{
if (plateId == null)
throw new IllegalArgumentException("Plate ID cannot be null");

_plate = PlateService.get().getPlate(container, plateId);
if (_plate == null)
throw new IllegalStateException("Could not resolve the plate with ID : " + plateId);
Expand Down
36 changes: 22 additions & 14 deletions assay/src/org/labkey/assay/plate/PlateCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ private void addCacheKeys(PlateCacheKey cacheKey, Plate plate)
{
if (plate != null)
{
if (plate.getName() == null)
throw new IllegalArgumentException("Plate cannot be cached, name is null");
if (plate.getPlateId() == null)
throw new IllegalArgumentException("Plate cannot be cached, plateId is null");
if (plate.getRowId() == null)
throw new IllegalArgumentException("Plate cannot be cached, rowId is null");
if (plate.getLSID() == null)
Expand All @@ -80,8 +80,8 @@ private void addCacheKeys(PlateCacheKey cacheKey, Plate plate)
PLATE_CACHE.put(PlateCacheKey.getCacheKey(plate.getContainer(), plate.getRowId()), plate);
if (cacheKey._type != PlateCacheKey.Type.lsid)
PLATE_CACHE.put(PlateCacheKey.getCacheKey(plate.getContainer(), Lsid.parse(plate.getLSID())), plate);
if (cacheKey._type != PlateCacheKey.Type.name)
PLATE_CACHE.put(PlateCacheKey.getCacheKey(plate.getContainer(), plate.getName()), plate);
if (cacheKey._type != PlateCacheKey.Type.plateId)
PLATE_CACHE.put(PlateCacheKey.getCacheKey(plate.getContainer(), plate.getPlateId()), plate);

_containerPlateMap.computeIfAbsent(cacheKey._container, k -> new ArrayList<>()).add(plate);
}
Expand Down Expand Up @@ -112,6 +112,14 @@ private void addCacheKeys(PlateCacheKey cacheKey, Plate plate)
return c != null ? PLATE_CACHE.get(PlateCacheKey.getCacheKey(c, lsid)) : null;
}

public static @Nullable Plate getPlate(ContainerFilter cf, String plateId)
{
SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("plateId"), plateId);
Container c = getContainerWithIdentifier(cf, filter);

return c != null ? PLATE_CACHE.get(PlateCacheKey.getCacheKey(c, plateId)) : null;
}

private static @Nullable Container getContainerWithIdentifier(ContainerFilter cf, SimpleFilter filter)
{
filter.addClause(cf.createFilterClause(AssayDbSchema.getInstance().getSchema(), FieldKey.fromParts("Container")));
Expand All @@ -129,9 +137,9 @@ private void addCacheKeys(PlateCacheKey cacheKey, Plate plate)
return null;
}

public static @Nullable Plate getPlate(Container c, String name)
public static @Nullable Plate getPlate(Container c, String plateId)
{
Plate plate = PLATE_CACHE.get(PlateCacheKey.getCacheKey(c, name));
Plate plate = PLATE_CACHE.get(PlateCacheKey.getCacheKey(c, plateId));
return plate != null ? plate.copy() : null;
}

Expand Down Expand Up @@ -187,14 +195,14 @@ public static void uncache(Container c, Plate plate)
{
LOG.info(String.format("Un-caching plate \"%s\" for folder %s", plate.getName(), c.getPath()));

if (plate.getName() == null)
throw new IllegalArgumentException("Plate cannot be uncached, name is null");
if (plate.getPlateId() == null)
throw new IllegalArgumentException("Plate cannot be uncached, plateId is null");
if (plate.getRowId() == null)
throw new IllegalArgumentException("Plate cannot be uncached, rowId is null");
if (plate.getLSID() == null)
throw new IllegalArgumentException("Plate cannot be uncached, LSID is null");

PLATE_CACHE.remove(PlateCacheKey.getCacheKey(c, plate.getName()));
PLATE_CACHE.remove(PlateCacheKey.getCacheKey(c, plate.getPlateId()));
PLATE_CACHE.remove(PlateCacheKey.getCacheKey(c, plate.getRowId()));
PLATE_CACHE.remove(PlateCacheKey.getCacheKey(c, Lsid.parse(plate.getLSID())));

Expand All @@ -212,7 +220,7 @@ private static class PlateCacheKey
enum Type
{
rowId,
name,
plateId,
lsid,
}
private Type _type;
Expand All @@ -228,14 +236,14 @@ enum Type
_identifier = json.get("identifier");
}

public static String getCacheKey(Container c, String name)
public static String getCacheKey(Container c, String plateId)
{
return _getCacheKey(c, Type.name, name);
return _getCacheKey(c, Type.plateId, plateId);
}

public static String getCacheKey(Container c, Integer plateId)
public static String getCacheKey(Container c, Integer rowId)
{
return _getCacheKey(c, Type.rowId, plateId);
return _getCacheKey(c, Type.rowId, rowId);
}

public static String getCacheKey(Container c, Lsid lsid)
Expand Down
2 changes: 1 addition & 1 deletion assay/src/org/labkey/assay/plate/PlateDataServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public int saveChanges(GWTPlate gwtPlate, boolean replaceIfExisting) throws Exce
else
{
// check another plate of the same name doesn't already exist
Plate other = PlateManager.get().getPlate(getContainer(), gwtPlate.getName());
Plate other = PlateManager.get().getPlateByName(getContainer(), gwtPlate.getName());
if (other != null)
{
if (!replaceIfExisting)
Expand Down
3 changes: 2 additions & 1 deletion assay/src/org/labkey/assay/plate/PlateImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ public Integer getPlateSetId()
}

@Override
//@JsonProperty("plateType")
public @NotNull PlateType getPlateType()
{
return _plateType;
Expand Down Expand Up @@ -674,6 +673,8 @@ public void setRunCount(Integer runCount)
_runCount = runCount;
}

@NotNull
@Override
public String getPlateId()
{
return _plateId;
Expand Down
35 changes: 30 additions & 5 deletions assay/src/org/labkey/assay/plate/PlateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,16 @@ public Position createPosition(Container container, int row, int column)
* Use the rowId or lsid variants instead.
*/
@Deprecated
public @Nullable Plate getPlate(Container container, String plateName)
public @Nullable Plate getPlateByName(Container container, String plateName)
{
return PlateCache.getPlate(container, plateName);
SimpleFilter filter = SimpleFilter.createContainerFilter(container);
filter.addCondition(FieldKey.fromParts("name"), plateName);

PlateBean bean = new TableSelector(AssayDbSchema.getInstance().getTableInfoPlate(), filter, null).getObject(PlateBean.class);
if (bean != null)
return populatePlate(bean);

return null;
}

@Override
Expand Down Expand Up @@ -445,6 +452,18 @@ public Plate createPlateTemplate(Container container, String templateType, @NotN
return PlateCache.getPlate(cf, lsid);
}

@Override
public @Nullable Plate getPlate(Container container, String plateId)
{
return PlateCache.getPlate(container, plateId);
}

@Override
public @Nullable Plate getPlate(ContainerFilter cf, String plateId)
{
return PlateCache.getPlate(cf, plateId);
}

/**
* Helper to create container filters to support assay import using cross folder
* plates
Expand Down Expand Up @@ -717,7 +736,7 @@ private int savePlateImpl(Container container, User user, PlateImpl plate) throw
plateId = (Integer) row.get("RowId");
plate.setRowId(plateId);
plate.setLsid((String) row.get("Lsid"));
plate.setName((String) row.get("Name"));
plate.setPlateId((String) row.get("PlateId"));
}
savePropertyBag(container, plate.getLSID(), plate.getProperties(), updateExisting);

Expand Down Expand Up @@ -1896,7 +1915,7 @@ public void createPlateTemplate() throws Exception

assertEquals(1, PlateManager.get().getPlateTemplates(container).size());

Plate savedTemplate = PlateManager.get().getPlate(container, "bob");
Plate savedTemplate = PlateManager.get().getPlateByName(container, "bob");
assertEquals(plateId, savedTemplate.getRowId().intValue());
assertEquals("bob", savedTemplate.getName());
assertEquals("yes", savedTemplate.getProperty("friendly")); assertNotNull(savedTemplate.getLSID());
Expand Down Expand Up @@ -1996,9 +2015,15 @@ public void testCreateAndSavePlate() throws Exception

// Assert
assertTrue("Expected plate to have been persisted and provided with a rowId", plate.getRowId() > 0);
assertTrue("Expected plate to have been persisted and provided with a plateId", plate.getPlateId() != null);

// verify access via plate ID
Plate savedPlate = PlateService.get().getPlate(container, plate.getPlateId());
assertTrue("Expected plate to be accessible via it's plate ID", savedPlate != null);
assertTrue("Plate retrieved by plate ID doesn't match the original plate.", savedPlate.getRowId().equals(plate.getRowId()));

// verify container filter access
Plate savedPlate = PlateService.get().getPlate(ContainerManager.getSharedContainer(), plate.getRowId());
savedPlate = PlateService.get().getPlate(ContainerManager.getSharedContainer(), plate.getRowId());
assertTrue("Saved plate should not exist in the shared container", savedPlate == null);

savedPlate = PlateService.get().getPlate(ContainerFilter.Type.CurrentAndSubfolders.create(ContainerManager.getSharedContainer(), user), plate.getRowId());
Expand Down

0 comments on commit 7c37c9b

Please sign in to comment.