Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WritablePropertyMap #971

Merged
merged 1 commit into from
Oct 2, 2024
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
31 changes: 17 additions & 14 deletions src/org/labkey/targetedms/TargetedMSController.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
import org.labkey.api.data.DataRegion;
import org.labkey.api.data.DbScope;
import org.labkey.api.data.PropertyManager;
import org.labkey.api.data.PropertyManager.PropertyMap;
import org.labkey.api.data.PropertyManager.WritablePropertyMap;
import org.labkey.api.data.RenderContext;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.SimpleFilter;
Expand Down Expand Up @@ -751,12 +753,12 @@ public Object execute(LeveyJenningsPlotOptions form, BindException errors)
{
ApiSimpleResponse response = new ApiSimpleResponse();

PropertyManager.PropertyMap properties = null;
PropertyMap properties = null;

// only stash and retrieve plot option properties for logged in users
// only stash and retrieve plot option properties for logged-in users
if (!getUser().isGuest())
{
properties = PropertyManager.getWritableProperties(getUser(), getContainer(), QCFolderConstants.CATEGORY, true);
WritablePropertyMap writable = PropertyManager.getWritableProperties(getUser(), getContainer(), QCFolderConstants.CATEGORY, true);

Map<String, String> valuesToPersist = form.getAsMapOfStrings();
if (!valuesToPersist.isEmpty())
Expand All @@ -766,20 +768,21 @@ public Object execute(LeveyJenningsPlotOptions form, BindException errors)
valuesToPersist.put("endDate", form.getEndDate());
valuesToPersist.put("selectedAnnotations", form.getSelectedAnnotationsString());

properties.putAll(valuesToPersist);
properties.save();
writable.putAll(valuesToPersist);
writable.save();
}
else
{
if (properties.containsKey("selectedAnnotations") && (ReplicateManager.getReplicateAnnotationNameValues(getContainer()).size() == 0))
if (writable.containsKey("selectedAnnotations") && (ReplicateManager.getReplicateAnnotationNameValues(getContainer()).isEmpty()))
{
// If there are no replicate annotations in this folder anymore, remove any saved annotation filters
// Issue 35726: No way to clear previously saved replicate annotation values in QC plots if folder no longer contains annotations
properties.remove("selectedAnnotations");
properties.save();
writable.remove("selectedAnnotations");
writable.save();
}
}

properties = writable;
}

if (properties == null || properties.isEmpty())
Expand All @@ -802,8 +805,8 @@ public static class SaveQCPlotSettingsAsDefaultAction extends MutatingApiAction<
@Override
public Object execute(LeveyJenningsPlotOptions form, BindException errors)
{
PropertyManager.PropertyMap current = PropertyManager.getProperties(getUser(), getContainer(), QCFolderConstants.CATEGORY);
PropertyManager.PropertyMap defaults = PropertyManager.getWritableProperties(getContainer(), QCFolderConstants.CATEGORY, true);
PropertyMap current = PropertyManager.getProperties(getUser(), getContainer(), QCFolderConstants.CATEGORY);
WritablePropertyMap defaults = PropertyManager.getWritableProperties(getContainer(), QCFolderConstants.CATEGORY, true);
defaults.clear(); // Clear the map. There may be properties that are no longer applicable (e.g. selectedAnnotations, startDate, endDate).
defaults.putAll(current);
defaults.save();
Expand All @@ -825,7 +828,7 @@ public static class RevertToDefaultQCPlotSettingsAction extends MutatingApiActio
@Override
public Object execute(LeveyJenningsPlotOptions form, BindException errors)
{
PropertyManager.PropertyMap current = PropertyManager.getWritableProperties(getUser(), getContainer(), QCFolderConstants.CATEGORY, false);
WritablePropertyMap current = PropertyManager.getWritableProperties(getUser(), getContainer(), QCFolderConstants.CATEGORY, false);
if (current != null)
{
current.delete();
Expand All @@ -837,7 +840,7 @@ public Object execute(LeveyJenningsPlotOptions form, BindException errors)
}
}

private static class LeveyJenningsPlotOptions
public static class LeveyJenningsPlotOptions
{
private String _metric;
private String _yAxisScale;
Expand Down Expand Up @@ -1306,7 +1309,7 @@ public Object execute(QCMetricOutliersForm form, BindException errors)
response.put("offlineAnnotationTypeId", ts2.getObject(Integer.class));
}

PropertyManager.PropertyMap properties = PropertyManager.getWritableProperties(getUser(), getContainer(), QCFolderConstants.CATEGORY, false);
WritablePropertyMap properties = PropertyManager.getWritableProperties(getUser(), getContainer(), QCFolderConstants.CATEGORY, false);
if (properties != null)
{
Map<String, Object> toSend = new HashMap<>(properties);
Expand Down Expand Up @@ -4158,7 +4161,7 @@ public static class PharmacokineticsOptionsAction extends MutatingApiAction<PKOp
@Override
public Object execute(PKOptions form, BindException errors)
{
PropertyManager.PropertyMap properties = PropertyManager.getWritableProperties(getContainer(), getPropMapName(form), true);
WritablePropertyMap properties = PropertyManager.getWritableProperties(getContainer(), getPropMapName(form), true);

// only stash option properties for users with editor role (i.e. UpdatePermissions)
if (form.getSubgroups() != null && getContainer().hasPermission(getUser(), UpdatePermission.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.Container;
import org.labkey.api.data.PropertyManager;
import org.labkey.api.data.PropertyManager.WritablePropertyMap;
import org.labkey.api.pipeline.LocalDirectory;
import org.labkey.api.pipeline.PipeRoot;
import org.labkey.api.pipeline.PipelineService;
Expand Down Expand Up @@ -119,7 +120,7 @@ else if (run.getCreated().after(new Date(Files.getLastModifiedTime(clibFile).toM

public static int incrementLibraryRevision(Container container, User user, LocalDirectory localDirectory)
{
PropertyManager.PropertyMap propMap = PropertyManager.getWritableProperties(container, "TargetedMS", true);
WritablePropertyMap propMap = PropertyManager.getWritableProperties(container, "TargetedMS", true);
String revisionVal = propMap.get(PROP_CHROM_LIB_REVISION);
int newRevision;
if(revisionVal == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.labkey.targetedms.folderImport;

import org.apache.commons.lang3.StringUtils;
import org.apache.jasper.tagplugins.jstl.core.Import;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.admin.FolderImportContext;
Expand All @@ -12,6 +11,7 @@
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.PropertyManager;
import org.labkey.api.data.PropertyManager.WritablePropertyMap;
import org.labkey.api.data.Results;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.SimpleFilter;
Expand Down Expand Up @@ -253,7 +253,7 @@ public int importSettingsFromFile(FolderImportContext ctx, VirtualFile panoramaQ
props.load(is);
if (!ctx.getUser().isGuest())
{
PropertyManager.PropertyMap properties = PropertyManager.getWritableProperties(ctx.getUser(), ctx.getContainer(), QCFolderConstants.CATEGORY, true);
WritablePropertyMap properties = PropertyManager.getWritableProperties(ctx.getUser(), ctx.getContainer(), QCFolderConstants.CATEGORY, true);
for (Map.Entry<Object, Object> entry : props.entrySet())
{
if (entry.getKey() instanceof String && entry.getValue() instanceof String)
Expand Down