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 @@ -16,8 +16,8 @@
package org.labkey.flow.controllers.attribute;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.labkey.api.action.ConfirmAction;
import org.labkey.api.action.FormViewAction;
Expand Down Expand Up @@ -255,15 +255,23 @@ public boolean handlePost(EditAttributeForm form, BindException errors)
String name = form.getName();
if (name == null || name.isBlank())
{
FlowManager.get().deleteAttribute(getContainer(),
_entry.getType(), _entry.getRowId(), true);
FlowManager.get().deleteAttribute(
getContainer(),
_entry.getType(),
_entry.getRowId(),
true
);
}
else
{
FlowManager.get().updateAttribute(getContainer(),
_entry.getType(), _entry.getRowId(), form.getName(),
_entry.getAliasedId() == null ? _entry.getRowId() : _entry.getAliasedId(),
true);
FlowManager.get().updateAttribute(
getContainer(),
_entry.getType(),
_entry.getRowId(),
form.getName(),
_entry.getAliasedId() == null ? _entry.getRowId() : _entry.getAliasedId(),
true
);
}

return true;
Expand Down
46 changes: 23 additions & 23 deletions flow/src/org/labkey/flow/persist/AttributeCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.labkey.api.cache.CacheLoader;
import org.labkey.api.cache.CacheManager;
import org.labkey.api.collections.CaseInsensitiveHashMap;
import org.labkey.api.collections.IntHashMap;
import org.labkey.api.collections.LongHashMap;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.DbScope;
Expand Down Expand Up @@ -81,17 +81,17 @@ private static class Attributes<Q extends Comparable<Q>, Z extends Entry<Q, Z>>
private final String _containerId;
private final Collection<Z> _entries;
private final Map<String, Z> _byName;
private final Map<Integer, Z> _byRowId;
private final MultiValuedMap<Integer, Integer> _aliases;
private final Map<Long, Z> _byRowId;
private final MultiValuedMap<Long, Long> _aliases;

private Attributes(String containerId, Collection<Z> all)
{
_containerId = containerId;
_entries = all;

Map<String, Z> byName = new CaseInsensitiveHashMap<>();
Map<Integer, Z> byRowId = new IntHashMap<>();
MultiValuedMap<Integer, Integer> aliases = new ArrayListValuedHashMap<>();
Map<Long, Z> byRowId = new LongHashMap<>();
MultiValuedMap<Long, Long> aliases = new ArrayListValuedHashMap<>();
for (Z entry : all)
{
byRowId.put(entry.getRowId(), entry);
Expand All @@ -112,13 +112,13 @@ private Attributes(String containerId, Collection<Z> all)
public static abstract class Entry<Q extends Comparable<Q>, Z extends Entry<Q, Z>> implements Comparable<Entry<Q, Z>>
{
private final AttributeType _type;
private final int _rowId;
private final long _rowId;
private final String _containerId;
private final String _name;
private final Q _attribute;
private final Integer _aliasedId;
private final Long _aliasedId;

protected Entry(@NotNull String containerId, @NotNull AttributeType type, int rowId, @NotNull String name, @NotNull Q attribute, @Nullable Integer aliasedId)
protected Entry(@NotNull String containerId, @NotNull AttributeType type, long rowId, @NotNull String name, @NotNull Q attribute, @Nullable Long aliasedId)
{
_containerId = containerId;
_type = type;
Expand All @@ -134,7 +134,7 @@ public AttributeType getType()
return _type;
}

public int getRowId()
public long getRowId()
{
return _rowId;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public int compareTo(@NotNull Entry<Q, Z> other)
}

/** Get the rowid of the aliased attribute or null if this is the preferred attribute. */
public Integer getAliasedId()
public Long getAliasedId()
{
return _aliasedId;
}
Expand All @@ -189,12 +189,12 @@ public Collection<Z> getAliases()
AttributeCache<Q, Z> cache = (AttributeCache<Q, Z>) AttributeCache.forType(_type);
Attributes<Q, Z> attributes = cache._cache.get(_containerId);

Collection<Integer> aliasIds = attributes._aliases.get(_rowId);
Collection<Long> aliasIds = attributes._aliases.get(_rowId);
if (aliasIds.isEmpty())
return Collections.emptyList();

ArrayList<Z> entries = new ArrayList<>(aliasIds.size());
for (Integer aliasId : aliasIds)
for (Long aliasId : aliasIds)
{
Z entry = cache.byRowId(_containerId, aliasId);
if (entry != null)
Expand All @@ -213,7 +213,7 @@ public Collection<FlowDataObject> getUsages()
/** Get a list of usages of this attribute, including usages of this attribute's aliases. */
public Map<Z, Collection<FlowDataObject>> getAllUsages()
{
Map<Integer, Collection<FlowDataObject>> usagesMap = FlowManager.get().getAllUsages(_type, _rowId);
Map<Long, Collection<FlowDataObject>> usagesMap = FlowManager.get().getAllUsages(_type, _rowId);
Map<Z, Collection<FlowDataObject>> ret = new HashMap<>();

// Include usages of this attribute
Expand All @@ -237,7 +237,7 @@ public Map<Z, Collection<FlowDataObject>> getAllUsages()

public static class KeywordEntry extends Entry<String, KeywordEntry>
{
protected KeywordEntry(@NotNull String containerId, int rowId, @NotNull String name, @Nullable Integer aliased)
protected KeywordEntry(@NotNull String containerId, long rowId, @NotNull String name, @Nullable Long aliased)
{
super(containerId, AttributeType.keyword, rowId, name, name, aliased);
}
Expand All @@ -257,7 +257,7 @@ public KeywordEntry getAliasedEntry()

public static class StatisticEntry extends Entry<StatisticSpec, StatisticEntry>
{
protected StatisticEntry(@NotNull String containerId, int rowId, @NotNull String name, @NotNull StatisticSpec spec, @Nullable Integer aliased)
protected StatisticEntry(@NotNull String containerId, long rowId, @NotNull String name, @NotNull StatisticSpec spec, @Nullable Long aliased)
{
super(containerId, AttributeType.statistic, rowId, name, spec, aliased);
}
Expand All @@ -277,7 +277,7 @@ public StatisticEntry getAliasedEntry()

public static class GraphEntry extends Entry<GraphSpec, GraphEntry>
{
protected GraphEntry(@NotNull String containerId, int rowId, @NotNull String name, @NotNull GraphSpec spec, @Nullable Integer aliased)
protected GraphEntry(@NotNull String containerId, long rowId, @NotNull String name, @NotNull GraphSpec spec, @Nullable Long aliased)
{
super(containerId, AttributeType.graph, rowId, name, spec, aliased);
}
Expand Down Expand Up @@ -312,14 +312,14 @@ private E createEntry(@Nullable FlowEntry entry)

assert entry._type == _type;

Integer aliasId = entry.isAlias() ? entry._aliasId : null;
Long aliasId = entry.isAlias() ? entry._aliasId : null;

A attribute = _createAttribute(entry._name);

return _createEntry(entry._containerId, entry._rowId, entry._name, attribute, aliasId);
}

protected abstract E _createEntry(@NotNull String containerId, int rowId, @NotNull String name, @NotNull A attribute, @Nullable Integer aliased);
protected abstract E _createEntry(@NotNull String containerId, long rowId, @NotNull String name, @NotNull A attribute, @Nullable Long aliased);

protected abstract A _createAttribute(@NotNull String name);

Expand Down Expand Up @@ -477,12 +477,12 @@ public E preferred(@NotNull Container c, @NotNull A attr)
* Get an AttributeEntry by rowid.
*/
@Nullable
public E byRowId(@NotNull Container container, int rowId)
public E byRowId(@NotNull Container container, long rowId)
{
return byRowId(container.getId(), rowId);
}

private E byRowId(@NotNull String containerId, int rowId)
private E byRowId(@NotNull String containerId, long rowId)
{
Attributes<A, E> attributes = _cache.get(containerId);
if (attributes == null)
Expand All @@ -505,7 +505,7 @@ protected String _createAttribute(@NotNull String name)
}

@Override
protected KeywordEntry _createEntry(@NotNull String containerId, int rowId, @NotNull String name, @NotNull String attribute, @Nullable Integer aliased)
protected KeywordEntry _createEntry(@NotNull String containerId, long rowId, @NotNull String name, @NotNull String attribute, @Nullable Long aliased)
{
return new KeywordEntry(containerId, rowId, name, aliased);
}
Expand All @@ -525,7 +525,7 @@ protected StatisticSpec _createAttribute(@NotNull String name)
}

@Override
protected StatisticEntry _createEntry(@NotNull String containerId, int rowId, @NotNull String name, @NotNull StatisticSpec attribute, @Nullable Integer aliased)
protected StatisticEntry _createEntry(@NotNull String containerId, long rowId, @NotNull String name, @NotNull StatisticSpec attribute, @Nullable Long aliased)
{
return new StatisticEntry(containerId, rowId, name, attribute, aliased);
}
Expand All @@ -545,7 +545,7 @@ protected GraphSpec _createAttribute(@NotNull String name)
}

@Override
protected GraphEntry _createEntry(@NotNull String containerId, int rowId, @NotNull String name, @NotNull GraphSpec attribute, @Nullable Integer aliased)
protected GraphEntry _createEntry(@NotNull String containerId, long rowId, @NotNull String name, @NotNull GraphSpec attribute, @Nullable Long aliased)
{
return new GraphEntry(containerId, rowId, name, attribute, aliased);
}
Expand Down
19 changes: 8 additions & 11 deletions flow/src/org/labkey/flow/persist/AttributeSetHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.collections.IntHashMap;
import org.labkey.api.collections.LongHashMap;
import org.labkey.api.data.Container;
import org.labkey.api.data.DbScope;
import org.labkey.api.data.SqlSelector;
Expand All @@ -42,9 +42,6 @@
import java.util.TreeMap;

/**
* User: kevink
* Date: Apr 15, 2011
*
* Static helper methods for reading and saving AttributeSet to/from the database.
*/
public class AttributeSetHelper
Expand Down Expand Up @@ -155,8 +152,8 @@ public static void doSave(AttributeSet attrs, User user, ExpData data, @Nullable
{
AttributeCache.Entry<?, ?> a = AttributeCache.KEYWORDS.byAttribute(c, entry.getKey());
assert a != null : "parepareForSave should have created an entry";
int preferredId = a.getAliasedId() == null ? a.getRowId() : a.getAliasedId();
int originalId = a.getRowId();
long preferredId = a.getAliasedId() == null ? a.getRowId() : a.getAliasedId();
long originalId = a.getRowId();
paramsList.add(Arrays.asList(obj.getRowId(), preferredId, originalId, entry.getValue()));
}
Table.batchExecute(mgr.getSchema(), sql, paramsList);
Expand All @@ -168,16 +165,16 @@ public static void doSave(AttributeSet attrs, User user, ExpData data, @Nullable
// Issue 41225: flow: import failure for duplicate aliased statistics
// Track the list of statistics and values for each preferredId key.
// If there is a duplicate statistic (e.g., two stats that are aliased) verify they have the same value.
Map<Integer, List<Map.Entry<StatisticSpec, Double>>> valuesForPreferredId = new IntHashMap<>();
Map<Long, List<Map.Entry<StatisticSpec, Double>>> valuesForPreferredId = new LongHashMap<>();

String sql = "INSERT INTO " + mgr.getTinfoStatistic() + " (ObjectId, StatisticId, OriginalStatisticId, Value) VALUES (?,?,?,?)";
List<List<?>> paramsList = new ArrayList<>();
for (Map.Entry<StatisticSpec, Double> entry : statistics.entrySet())
{
AttributeCache.Entry<?, ?> a = AttributeCache.STATS.byAttribute(c, entry.getKey());
assert a != null : "parepareForSave should have created an entry";
int preferredId = a.getAliasedId() == null ? a.getRowId() : a.getAliasedId();
int originalId = a.getRowId();
long preferredId = a.getAliasedId() == null ? a.getRowId() : a.getAliasedId();
long originalId = a.getRowId();

var duplicateValues = valuesForPreferredId.computeIfAbsent(preferredId, (k) -> new ArrayList<>());
if (duplicateValues.isEmpty())
Expand Down Expand Up @@ -215,8 +212,8 @@ public static void doSave(AttributeSet attrs, User user, ExpData data, @Nullable
{
AttributeCache.Entry<?, ?> a = AttributeCache.GRAPHS.byAttribute(c, entry.getKey());
assert a != null : "parepareForSave should have created an entry";
int preferredId = a.getAliasedId() == null ? a.getRowId() : a.getAliasedId();
int originalId = a.getRowId();
long preferredId = a.getAliasedId() == null ? a.getRowId() : a.getAliasedId();
long originalId = a.getRowId();
paramsList.add(Arrays.asList(obj.getRowId(), preferredId, originalId, entry.getValue()));
}
Table.batchExecute(mgr.getSchema(), sql, paramsList);
Expand Down
Loading
Loading