Skip to content

Commit 6c26a11

Browse files
authored
Issue 53586: Domain field with long name can result in "PropertyURI cannot exceed 300 characters, but was 302 characters long." (#6939)
- Update DomainUtil.createUniquePropertyURI() to use LsidManager.getLsidPrefixDbSeq() - Use DomainUtil.createUniquePropertyURI() in several places instead of appending encoded field name - PropertyController TestCase fix for setup and cleanup of Domain - Nab test fix for SQL selects that were looking for run properties by propertyURI instead of name - DataIteratorUtil._createTableMap to not include PropertyURI suffix as tableAliasMap option - VocabularyDomainKind propertyURI to continue using field name as suffix
1 parent 9e49f3c commit 6c26a11

24 files changed

Lines changed: 99 additions & 65 deletions

File tree

api/src/org/labkey/api/dataiterator/DataIteratorUtil.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,7 @@ protected static Map<String,Pair<ColumnInfo,MatchType>> _createTableMap(TableInf
247247
{
248248
String uri = col.getPropertyURI();
249249
if (null != uri)
250-
{
251250
targetAliasesMap.put(uri, new Pair<>(col, MatchType.propertyuri));
252-
String propName = uri.substring(uri.lastIndexOf('#')+1);
253-
targetAliasesMap.put(propName, new Pair<>(col, MatchType.alias));
254-
}
255251
}
256252

257253
for (ColumnInfo col : cols)

api/src/org/labkey/api/exp/ImportTypesHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.labkey.api.data.PHI;
3030
import org.labkey.api.data.PropertyStorageSpec;
3131
import org.labkey.api.exp.OntologyManager.ImportPropertyDescriptorsList;
32+
import org.labkey.api.exp.property.DomainUtil;
3233
import org.labkey.api.exp.property.IPropertyValidator;
3334
import org.labkey.api.exp.property.ValidatorKind;
3435
import org.labkey.api.gwt.client.DefaultScaleType;
@@ -49,6 +50,7 @@
4950
import java.util.Arrays;
5051
import java.util.Collection;
5152
import java.util.Date;
53+
import java.util.HashSet;
5254
import java.util.LinkedHashSet;
5355
import java.util.List;
5456
import java.util.Set;
@@ -244,7 +246,7 @@ public static ImportPropertyDescriptorsList getImportPropertyDescriptors(Collect
244246
String propertyURI = StringUtils.trimToEmpty(pd.getPropertyURI());
245247
if (propertyURI.isEmpty())
246248
{
247-
pd.setPropertyURI(domainURI + "." + Lsid.encodePart(columnName));
249+
pd.setPropertyURI(DomainUtil.createUniquePropertyURI(domainURI));
248250
}
249251

250252
// try use existing SystemProperty PropertyDescriptor from Shared container.

api/src/org/labkey/api/exp/property/Domain.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public interface Domain extends IPropertyType
7575
DomainProperty addProperty();
7676
DomainProperty addProperty(PropertyStorageSpec spec);
7777

78+
@Deprecated // Use addProperty(PropertyStorageSpec)
79+
DomainProperty addProperty(PropertyStorageSpec spec, @Nullable String propSuffix);
80+
7881
List<BaseColumnInfo> getColumns(TableInfo sourceTable, ColumnInfo lsidColumn, Container container, User user);
7982

8083
boolean isMutable();

api/src/org/labkey/api/exp/property/DomainUtil.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.labkey.api.exp.DomainDescriptor;
4848
import org.labkey.api.exp.ExperimentException;
4949
import org.labkey.api.exp.Lsid;
50+
import org.labkey.api.exp.LsidManager;
5051
import org.labkey.api.exp.OntologyManager;
5152
import org.labkey.api.exp.PropertyDescriptor;
5253
import org.labkey.api.exp.PropertyType;
@@ -1090,7 +1091,7 @@ public static DomainProperty addProperty(Domain domain, GWTPropertyDescriptor pd
10901091
LOG.debug("Adding property for " + pd.getName());
10911092
if (StringUtils.isEmpty(pd.getPropertyURI()))
10921093
{
1093-
String newPropertyURI = createUniquePropertyURI(domain.getTypeURI() + "#" + Lsid.encodePart(pd.getName()), propertyUrisInUse);
1094+
String newPropertyURI = createUniquePropertyURI(domain.getTypeURI(), null, propertyUrisInUse);
10941095
assert !propertyUrisInUse.contains(newPropertyURI) : "Attempting to assign an existing PropertyURI to a new property";
10951096
pd.setPropertyURI(newPropertyURI);
10961097
propertyUrisInUse.add(newPropertyURI);
@@ -1107,8 +1108,20 @@ public static DomainProperty addProperty(Domain domain, GWTPropertyDescriptor pd
11071108
return p;
11081109
}
11091110

1110-
private static String createUniquePropertyURI(String base, Set<String> propertyUrisInUse)
1111+
public static String createUniquePropertyURI(String typeURI)
11111112
{
1113+
return createUniquePropertyURI(typeURI, null, new CaseInsensitiveHashSet());
1114+
}
1115+
1116+
public static String createUniquePropertyURI(String typeURI, @Nullable String propSuffix, Set<String> propertyUrisInUse)
1117+
{
1118+
// Don't use long property names in URIs as it can create strings that are longer than the DB column length when encoded (Issue 53586)
1119+
if (propSuffix == null)
1120+
propSuffix = String.valueOf(LsidManager.getLsidPrefixDbSeq("Property", 1).next());
1121+
else
1122+
propSuffix = Lsid.encodePart(propSuffix);
1123+
1124+
String base = typeURI + "#" + propSuffix;
11121125
String candidateURI = base;
11131126
int i = 0;
11141127

api/src/org/labkey/api/issues/AbstractIssuesListDefDomainKind.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.commons.lang3.StringUtils;
2020
import org.jetbrains.annotations.NotNull;
2121
import org.jetbrains.annotations.Nullable;
22+
import org.labkey.api.collections.CaseInsensitiveHashSet;
2223
import org.labkey.api.data.Container;
2324
import org.labkey.api.data.ContainerFilter;
2425
import org.labkey.api.data.DbSchema;
@@ -325,7 +326,7 @@ public Domain createDomain(GWTDomain<GWTPropertyDescriptor> domain, IssuesDomain
325326
Set<String> lowerReservedNames = reservedNames.stream().map(String::toLowerCase).collect(Collectors.toSet());
326327
Set<String> existingProperties = newDomain.getProperties().stream().map(o -> o.getName().toLowerCase()).collect(Collectors.toSet());
327328
Map<DomainProperty, Object> defaultValues = new HashMap<>();
328-
Set<String> propertyUris = new HashSet<>();
329+
Set<String> propertyUris = new CaseInsensitiveHashSet();
329330

330331
for (GWTPropertyDescriptor pd : properties)
331332
{

api/src/org/labkey/api/query/ExtendedTableDomainKind.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.apache.commons.lang3.StringUtils;
1919
import org.json.JSONObject;
20+
import org.labkey.api.collections.CaseInsensitiveHashSet;
2021
import org.labkey.api.data.Container;
2122
import org.labkey.api.exp.ChangePropertyDescriptorException;
2223
import org.labkey.api.exp.Handler;
@@ -98,7 +99,7 @@ public Domain createDomain(GWTDomain<GWTPropertyDescriptor> gwtDomain, JSONObjec
9899
List<? extends GWTPropertyDescriptor> properties = gwtDomain.getFields();
99100
Domain newDomain = PropertyService.get().createDomain(container, domainURI, gwtDomain.getName(), templateInfo);
100101

101-
Set<String> propertyUris = new HashSet<>();
102+
Set<String> propertyUris = new CaseInsensitiveHashSet();
102103
Map<DomainProperty, Object> defaultValues = new HashMap<>();
103104
try
104105
{

api/src/org/labkey/api/query/snapshot/AbstractSnapshotProvider.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.labkey.api.exp.PropertyType;
2525
import org.labkey.api.exp.property.Domain;
2626
import org.labkey.api.exp.property.DomainProperty;
27+
import org.labkey.api.exp.property.DomainUtil;
2728
import org.labkey.api.exp.property.PropertyService;
2829
import org.labkey.api.query.CustomView;
2930
import org.labkey.api.query.QueryDefinition;
@@ -35,6 +36,7 @@
3536
import org.springframework.validation.BindException;
3637

3738
import java.util.HashMap;
39+
import java.util.HashSet;
3840
import java.util.List;
3941
import java.util.Map;
4042
/*
@@ -131,13 +133,15 @@ public static DomainProperty addAsDomainProperty(Domain domain, ColumnInfo colum
131133
if (name.contains("/"))
132134
name = name.replace('/', '.');
133135

136+
String propertyURI = DomainUtil.createUniquePropertyURI(domain.getTypeURI());
137+
134138
if (pd != null)
135139
{
136140
PropertyDescriptor newProp = pd.clone();
137141

138142
// initialize so the domain doesn't get upset
139143
newProp.setContainer(domain.getContainer());
140-
newProp.setPropertyURI(getPropertyURI(domain, column));
144+
newProp.setPropertyURI(propertyURI);
141145
newProp.setPropertyId(0);
142146
newProp.setName(name);
143147
newProp.setLabel(column.getLabel());
@@ -161,16 +165,11 @@ public static DomainProperty addAsDomainProperty(Domain domain, ColumnInfo colum
161165
prop.setType(PropertyService.get().getType(domain.getContainer(), type.getXmlName()));
162166
prop.setDescription(column.getDescription());
163167
prop.setFormat(column.getFormat());
164-
prop.setPropertyURI(getPropertyURI(domain, column));
168+
prop.setPropertyURI(propertyURI);
165169
}
166170
return prop;
167171
}
168172

169-
public static String getPropertyURI(Domain domain, ColumnInfo column)
170-
{
171-
return domain.getTypeURI() + "." + column.getName();
172-
}
173-
174173
@Override
175174
public TableInfo getTableInfoQuerySnapshotDef()
176175
{

api/src/org/labkey/api/reports/model/ReportPropsManager.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.labkey.api.exp.PropertyType;
3535
import org.labkey.api.exp.property.Domain;
3636
import org.labkey.api.exp.property.DomainProperty;
37+
import org.labkey.api.exp.property.DomainUtil;
3738
import org.labkey.api.exp.property.PropertyService;
3839
import org.labkey.api.query.ValidationException;
3940
import org.labkey.api.security.User;
@@ -46,6 +47,7 @@
4647

4748
import java.util.ArrayList;
4849
import java.util.HashMap;
50+
import java.util.HashSet;
4951
import java.util.List;
5052
import java.util.Map;
5153

@@ -84,11 +86,6 @@ public List<DomainProperty> getProperties(Container container)
8486
return properties;
8587
}
8688

87-
public void createProperty(Container container, User user, String name, String label, PropertyType type) throws Exception
88-
{
89-
ensureProperty(container, user, name, label, type);
90-
}
91-
9289
private Map<String, DomainProperty> getPropertyMap(Container container)
9390
{
9491
Domain domain = getDomain(container, false);
@@ -120,7 +117,7 @@ public synchronized DomainProperty ensureProperty(Container container, User user
120117
prop.setName(name);
121118
prop.setLabel(label);
122119
prop.setType(PropertyService.get().getType(domain.getContainer(), type.getXmlName()));
123-
prop.setPropertyURI(getPropertyURI(name, container));
120+
prop.setPropertyURI(DomainUtil.createUniquePropertyURI(getDomainURI(container)));
124121

125122
dp = prop;
126123
}
@@ -209,11 +206,6 @@ private String getDomainURI(@NotNull Container container)
209206
return new Lsid("urn:lsid:labkey.com:" + NAMESPACE_PREFIX + ".Folder-" + container.getRowId() + ':' + TYPE_PROPERTIES).toString();
210207
}
211208

212-
private String getPropertyURI(String propertyName, Container container)
213-
{
214-
return getDomainURI(container) + '#' + propertyName;
215-
}
216-
217209
@Override
218210
public void containerDeleted(Container container, User user)
219211
{

assay/api-src/org/labkey/api/assay/nab/RenderAssayBean.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ public Pair<PropertyDescriptor, Object> getFitError(DilutionAssayRun.SampleResul
328328
{
329329
try
330330
{
331-
Lsid fitErrorURI = new Lsid(DilutionDataHandler.NAB_PROPERTY_LSID_PREFIX, getAssay().getProtocol().getName(), DilutionDataHandler.FIT_ERROR_PROPERTY);
332331
PropertyDescriptor fitErrorPd =
333332
_assay.getDataHandler().getPropertyDescriptor(container, getAssay().getProtocol(), DilutionDataHandler.FIT_ERROR_PROPERTY, new HashMap<>());
334333
if (null != fitErrorPd)

assay/api-src/org/labkey/api/assay/nab/query/CutoffValueTable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ private SQLFragment getSelectedCurveFitIC(boolean oorIndicator)
8181
defaultICSQL.append(DilutionManager.getTableInfoNAbSpecimen(), "ns");
8282
defaultICSQL.append(", ");
8383
defaultICSQL.append(ExperimentService.get().getTinfoExperimentRun(), "er");
84-
defaultICSQL.append(" WHERE op.PropertyId = pd.PropertyId AND pd.PropertyURI LIKE '%#" + DilutionAssayProvider.CURVE_FIT_METHOD_PROPERTY_NAME + "' AND ns.RowId = ");
84+
defaultICSQL.append(" WHERE op.PropertyId = pd.PropertyId AND pd.Name = ? ");
85+
defaultICSQL.add(DilutionAssayProvider.CURVE_FIT_METHOD_PROPERTY_NAME);
86+
defaultICSQL.append("AND ns.RowId = ");
8587
defaultICSQL.append(ExprColumn.STR_TABLE_ALIAS);
8688
defaultICSQL.append(".NAbSpecimenID AND er.LSID = o.ObjectURI AND o.ObjectId = op.ObjectId AND er.RowId = ns.RunId)");
8789
defaultICSQL.append("\nWHEN 'Polynomial' THEN ");

0 commit comments

Comments
 (0)