Skip to content
Open
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
9 changes: 9 additions & 0 deletions api/schemas/domainTemplate.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
<xs:field xpath="@columnName"/>
</xs:unique>
</xs:element>
<xs:element name="reservedColumnNames" type="ColumnList" minOccurs="0" maxOccurs="1">
<xs:annotation>
<xs:documentation xml:lang="en">
Additional column names that should be considered reserved by the DomainKind for any
domain created from this template. These names are unioned with the DomainKind's
statically reserved set.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="indices" type="IndicesType" minOccurs="0" maxOccurs="1" />
<xs:element name="initialData" type="InitialDataType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public boolean hasNullValues(Domain domain, DomainProperty prop)
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user)
protected @NotNull Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
Set<String> names = new HashSet<>();

Expand Down
8 changes: 1 addition & 7 deletions api/src/org/labkey/api/exp/api/SampleTypeDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,7 @@ public Set<PropertyStorageSpec> getBaseProperties(Domain domain)
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user)
{
return getReservedPropertyNames(domain, user, false);
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user, boolean forCreate)
protected @NotNull Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
Set<String> reserved = new CaseInsensitiveHashSet(RESERVED_NAMES);

Expand Down
70 changes: 60 additions & 10 deletions api/src/org/labkey/api/exp/property/DomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ abstract public class DomainKind<T> implements Handler<String>
abstract public String getKindName();

/**
* Return a class of DomainKind's bean which carries domain specific properties.
* This class will be used when marshalling/unmarshalling via Jackson during Create and Save/Update Domain
* @return Class of DomainKind's bean with domain specific properties
* Return a class of DomainKind's bean which carries domain-specific properties.
* This class will be used when marshaling/unmarshaling via Jackson during Create and Save/Update Domain
* @return Class of DomainKind's bean with domain-specific properties
*/
abstract public Class<? extends T> getTypeClass();

Expand Down Expand Up @@ -108,15 +108,65 @@ public Map<String, Object> processArguments(Container container, User user, Map<
abstract public void deletePropertyDescriptor(Domain domain, User user, PropertyDescriptor pd);

/**
* Return the set of names that should not be allowed for properties. E.g.
* the names of columns from the hard table underlying this type
* Return the set of names that should not be allowed for properties. E.g., the names of columns
* from the hard table underlying this type, unioned with any names declared in the
* {@link DomainTemplate}'s {@code <reservedColumnNames>} element that this domain was created from.
* <p>
* This method is {@code final}; subclasses contribute their kind-specific reserved set by overriding
* {@link #getKindReservedPropertyNames(Domain, User, boolean)}. The base class always unions that
* set with the template-declared set.
*
* @return set of strings containing the names. This will be compared ignoring case
*/
abstract public Set<String> getReservedPropertyNames(Domain domain, User user);
@NotNull
public final Set<String> getReservedPropertyNames(Domain domain, User user)
{
return getReservedPropertyNames(domain, user, false);
}

@NotNull
public final Set<String> getReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
Set<String> reserved = new CaseInsensitiveHashSet(getKindReservedPropertyNames(domain, user, forCreate));
reserved.addAll(getTemplateReservedPropertyNames(domain));
return reserved;
}

/**
* Return the kind-specific set of names that should not be allowed for properties. Subclasses override
* this to contribute their static/hard-coded reserved names. The base class will automatically union
* the result with any names declared in the {@link DomainTemplate}'s {@code <reservedColumnNames>}
* element via {@link #getReservedPropertyNames(Domain, User, boolean)}.
*
* @param forCreate true when validating names during domain creation; some kinds reserve additional
* names only at creation time.
* @return set of strings containing the names.
*/
@NotNull
protected Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
return Collections.emptySet();
}

public Set<String> getReservedPropertyNames(Domain domain, User user, boolean forCreate)
/**
* Returns reserved column names declared in the {@link DomainTemplate} that this domain was created from
* (if any). These extend the kind's statically reserved set.
*/
@NotNull
protected Set<String> getTemplateReservedPropertyNames(@Nullable Domain domain)
{
return getReservedPropertyNames(domain, user);
if (domain == null)
return Collections.emptySet();

TemplateInfo info = domain.getTemplateInfo();
if (info == null)
return Collections.emptySet();

DomainTemplate template = DomainTemplate.findTemplate(info, getKindName());
if (template == null)
return Collections.emptySet();

return template.getReservedColumnNames();
}

public Set<String> getReservedPropertyNamePrefixes()
Expand All @@ -132,14 +182,14 @@ public Set<String> getReservedPropertyNamePrefixes()
abstract public Set<String> getMandatoryPropertyNames(Domain domain);

// CONSIDER: have DomainKind supply and IDomainInstance or similar
// so that it can hold instance data (e.g. a DatasetDefinition)
// so that it can hold instance data (e.g., a DatasetDefinition)

/**
* Get DomainKind specific properties.
* @param domain The domain design.
* @param container Container
* @param user User
* @return Return object that holds DomainKind specific properties.
* @return Return an object that holds DomainKind specific properties.
*/
abstract public @Nullable T getDomainKindProperties(GWTDomain<?> domain, Container container, User user);

Expand Down
60 changes: 41 additions & 19 deletions api/src/org/labkey/api/exp/property/DomainTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.exp.property;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
Expand Down Expand Up @@ -60,7 +61,6 @@
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -69,10 +69,6 @@
import java.util.Objects;
import java.util.Set;

/**
* User: kevink
* Date: 1/6/16
*/
public class DomainTemplate
{
private final String _moduleName;
Expand All @@ -83,6 +79,7 @@ public class DomainTemplate
private final String _domainKind;
private final GWTDomain _domain;
private final Map<String, Object> _options;
private final Set<String> _reservedColumnNames;
private final InitialDataSettings _initialData;

/**
Expand Down Expand Up @@ -132,7 +129,7 @@ public static DomainTemplate parse(String moduleName, String groupName, DomainTe
}
catch (IllegalArgumentException ex)
{
return new DomainTemplate(Objects.toString(templateName, "<unknown>"), moduleName, groupName, Arrays.asList(ex.getMessage()));
return new DomainTemplate(Objects.toString(templateName, "<unknown>"), moduleName, groupName, List.of(ex.getMessage()));
}
}

Expand All @@ -148,8 +145,9 @@ private static DomainTemplate _parse(String templateName, String moduleName, Str
throw new IllegalArgumentException("Unknown template domain kind");

List<GWTIndex> indices = getDomainTemplateUniqueIndices(templateName, template, properties);
Set<String> mandatoryFieldNames = getDomainTemplateMandatoryFields(templateName, template, properties);
Set<String> mandatoryFieldNames = getDomainTemplateMandatoryFields(template);
Map<String, Object> options = getDomainTemplateOptions(templateName, template, properties);
Set<String> reservedColumnNames = getDomainTemplateReservedColumnNames(template);

GWTDomain<GWTPropertyDescriptor> domain = new GWTDomain<>();
domain.setName(templateName);
Expand All @@ -162,17 +160,33 @@ private static DomainTemplate _parse(String templateName, String moduleName, Str

return new DomainTemplate(
templateName, groupName, moduleName,
domainKind, domain, options,
domainKind, domain, options, reservedColumnNames,
importData
);
}

private static Set<String> getDomainTemplateReservedColumnNames(DomainTemplateType template)
{
if (!template.isSetReservedColumnNames())
return Collections.emptySet();

CaseInsensitiveHashSet set = new CaseInsensitiveHashSet();
for (String name : template.getReservedColumnNames().getColumnArray())
{
String validName = StringUtils.trimToNull(name);
if (validName != null)
set.add(validName);
}

return Collections.unmodifiableSet(set);
}

@Nullable
private static String getDomainKind(String templateName, DomainTemplateType template, List<GWTPropertyDescriptor> properties)
{
List<DomainKind<?>> domainKinds = PropertyService.get().getDomainKinds();

for (DomainKind domainKind : domainKinds)
for (DomainKind<?> domainKind : domainKinds)
{
if (domainKind.matchesTemplateXML(templateName, template, properties))
{
Expand All @@ -198,7 +212,7 @@ private static List<GWTPropertyDescriptor> getDomainTemplateProperties(String te
}
}

return Collections.unmodifiableList(new ArrayList<>(properties.values()));
return List.copyOf(properties.values());
}

private static List<GWTIndex> getDomainTemplateUniqueIndices(String templateName, DomainTemplateType template, List<GWTPropertyDescriptor> properties)
Expand Down Expand Up @@ -227,7 +241,7 @@ private static List<GWTIndex> getDomainTemplateUniqueIndices(String templateName
return Collections.unmodifiableList(indices);
}

private static Set<String> getDomainTemplateMandatoryFields(String templateName, DomainTemplateType template, List<GWTPropertyDescriptor> properties)
private static Set<String> getDomainTemplateMandatoryFields(DomainTemplateType template)
{
CaseInsensitiveHashSet set = new CaseInsensitiveHashSet();

Expand Down Expand Up @@ -266,19 +280,19 @@ private static Map<String, Object> getDomainTemplateOptions(String templateName,
{
Map<String, Object> optionsMap = new HashMap<>();

if (template instanceof ListTemplateType)
if (template instanceof ListTemplateType listTemplate)
{
ListOptionsType options = ((ListTemplateType)template).getOptions();
ListOptionsType options = listTemplate.getOptions();
String keyName = options.getKeyCol();
optionsMap.put("keyName", keyName);

// The keyType value will be validated against the set of allowable types in ListDomainKind.createDomain()
if (options.isSetKeyType())
optionsMap.put("keyType", options.getKeyType());
}
else if (template instanceof DataClassTemplateType)
else if (template instanceof DataClassTemplateType dataClassTemplate)
{
DataClassOptionsType options = ((DataClassTemplateType)template).getOptions();
DataClassOptionsType options = dataClassTemplate.getOptions();
if (options != null)
{
optionsMap.put("nameExpression", options.getNameExpression());
Expand All @@ -288,9 +302,9 @@ else if (template instanceof DataClassTemplateType)
optionsMap.put("category", options.getCategory());
}
}
else if (template instanceof SampleSetTemplateType)
else if (template instanceof SampleSetTemplateType sampleTypeTemplate)
{
SampleSetOptionsType options = ((SampleSetTemplateType)template).getOptions();
SampleSetOptionsType options = sampleTypeTemplate.getOptions();
if (options != null)
{
optionsMap.put("nameExpression", options.getNameExpression());
Expand Down Expand Up @@ -338,8 +352,9 @@ private static InitialDataSettings getImportDataSettings(String templateName, Do
}

private DomainTemplate(@NotNull String name, @NotNull String groupName, @NotNull String moduleName,
@NotNull String domainKind, @NotNull GWTDomain domain,
@NotNull Map<String, Object> options, @Nullable InitialDataSettings initialData)
@NotNull String domainKind, @NotNull GWTDomain<GWTPropertyDescriptor> domain,
@NotNull Map<String, Object> options, @NotNull Set<String> reservedColumnNames,
@Nullable InitialDataSettings initialData)
{
_moduleName = moduleName;
_templateGroup = groupName;
Expand All @@ -348,6 +363,7 @@ private DomainTemplate(@NotNull String name, @NotNull String groupName, @NotNull
_errors = null;
_domain = domain;
_options = options;
_reservedColumnNames = reservedColumnNames;
_initialData = initialData;
}

Expand All @@ -361,6 +377,7 @@ private DomainTemplate(@NotNull String name, @NotNull String groupName, @NotNull
_domainKind = null;
_domain = null;
_options = null;
_reservedColumnNames = Collections.emptySet();
_initialData = null;
}

Expand Down Expand Up @@ -568,6 +585,11 @@ public Set<String> getMandatoryPropertyNames()
return _domain.getMandatoryFieldNames();
}

@NotNull
public Set<String> getReservedColumnNames()
{
return _reservedColumnNames;
}

private static class InitialDataSettings
{
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/exp/property/TestDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void deletePropertyDescriptor(Domain domain, User user, PropertyDescripto
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user)
protected @NotNull Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
throw new UnsupportedOperationException();
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/query/SimpleTableDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public boolean canCreateDefinition(User user, Container container)
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user)
protected @NotNull Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
SimpleUserSchema.SimpleTable table = domain != null ? getTable(domain, user) : null;
if (table != null)
Expand Down
6 changes: 1 addition & 5 deletions assay/api-src/org/labkey/api/assay/AssayBatchDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
import java.util.Arrays;
import java.util.Set;

/**
* User: jeckels
* Date: Jan 27, 2012
*/
public class AssayBatchDomainKind extends AssayDomainKind
{
private static final Set<String> RESERVED_NAMES;
Expand All @@ -50,7 +46,7 @@ public String getKindName()
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user)
protected @NotNull Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
return RESERVED_NAMES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public DbSchema getSchema()
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user)
protected @NotNull Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
return RESERVED_NAMES;
}
Expand Down
2 changes: 1 addition & 1 deletion assay/api-src/org/labkey/api/assay/AssayRunDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String getKindName()
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user)
protected @NotNull Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
return RESERVED_NAMES;
}
Expand Down
2 changes: 1 addition & 1 deletion assay/src/org/labkey/assay/DefaultAssayDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getKindName()
}

@Override
public @NotNull Set<String> getReservedPropertyNames(Domain domain, User user)
protected @NotNull Set<String> getKindReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
return getAssayReservedPropertyNames();
}
Expand Down
Loading