Skip to content

Commit

Permalink
Assay: resolve a single provider/protocol before creating protocol sc…
Browse files Browse the repository at this point in the history
…hema (#6057)
  • Loading branch information
labkey-nicka authored Nov 15, 2024
1 parent f2585fb commit 0a989c8
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 237 deletions.
70 changes: 37 additions & 33 deletions api/src/org/labkey/api/assay/AbstractAssayProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -881,22 +881,37 @@ private Set<String> getPropertyDomains(ExpProtocol protocol)
}

@Override
public List<Pair<Domain, Map<DomainProperty, Object>>> getDomains(ExpProtocol protocol)
public @NotNull List<Domain> getDomains(ExpProtocol protocol)
{
List<Pair<Domain, Map<DomainProperty, Object>>> domains = new ArrayList<>();
List<Domain> domains = new ArrayList<>();
for (String uri : getPropertyDomains(protocol))
{
Domain domain = PropertyService.get().getDomain(protocol.getContainer(), uri);
if (domain != null)
{
Map<DomainProperty, Object> values = DefaultValueService.get().getDefaultValues(domain.getContainer(), domain);
domains.add(new Pair<>(domain, values));
}
domains.add(domain);
}
sortDomainList(domains);

// Rely on the assay provider to return a list of default domains in the right order (Collections.sort() is
// stable so that domains that haven't been inserted and have id 0 stay in the same order), and rely on the fact
// that they get inserted in the same order, so they will have ascending ids.
domains.sort(Comparator.comparing(Domain::getTypeId));

return domains;
}

@Override
public @NotNull List<Pair<Domain, Map<DomainProperty, Object>>> getDomainsAndDefaultValues(ExpProtocol protocol)
{
List<Pair<Domain, Map<DomainProperty, Object>>> domainAndDefaultValues = new ArrayList<>();
for (Domain domain : getDomains(protocol))
{
Map<DomainProperty, Object> values = DefaultValueService.get().getDefaultValues(domain.getContainer(), domain);
domainAndDefaultValues.add(Pair.of(domain, values));
}

return domainAndDefaultValues;
}

@Override
public Pair<ExpProtocol, List<Pair<Domain, Map<DomainProperty, Object>>>> getAssayTemplate(User user, Container targetContainer)
{
Expand All @@ -905,14 +920,6 @@ public Pair<ExpProtocol, List<Pair<Domain, Map<DomainProperty, Object>>>> getAss
return new Pair<>(copy, createDefaultDomains(targetContainer, user));
}

protected void sortDomainList(List<Pair<Domain, Map<DomainProperty, Object>>> domains)
{
// Rely on the assay provider to return a list of default domains in the right order (Collections.sort() is
// stable so that domains that haven't been inserted and have id 0 stay in the same order), and rely on the fact
// that they get inserted in the same order, so they will have ascending ids.
domains.sort(Comparator.comparingInt(pair -> pair.getKey().getTypeId()));
}

@Override
public Pair<ExpProtocol, List<Pair<Domain, Map<DomainProperty, Object>>>> getAssayTemplate(User user, Container targetContainer, ExpProtocol toCopy)
{
Expand All @@ -925,7 +932,7 @@ public Pair<ExpProtocol, List<Pair<Domain, Map<DomainProperty, Object>>>> getAss
}
copy.setObjectProperties(copiedProps);

List<Pair<Domain, Map<DomainProperty, Object>>> originalDomains = getDomains(toCopy);
List<Pair<Domain, Map<DomainProperty, Object>>> originalDomains = getDomainsAndDefaultValues(toCopy);
List<Pair<Domain, Map<DomainProperty, Object>>> copiedDomains = new ArrayList<>(originalDomains.size());
for (Pair<Domain, Map<DomainProperty, Object>> domainInfo : originalDomains)
{
Expand Down Expand Up @@ -1113,18 +1120,15 @@ public ModelAndView createResultDetailsView(ViewContext context, ExpProtocol pro
@Override
public void deleteProtocol(ExpProtocol protocol, User user, @Nullable final String auditUserComment) throws ExperimentException
{
List<Pair<Domain, Map<DomainProperty, Object>>> domainInfos = getDomains(protocol);
List<Domain> domains = new ArrayList<>();
for (Pair<Domain, Map<DomainProperty, Object>> domainInfo : domainInfos)
domains.add(domainInfo.getKey());
List<Domain> domains = getDomains(protocol);

Set<Container> defaultValueContainers = new HashSet<>();
defaultValueContainers.add(protocol.getContainer());
defaultValueContainers.addAll(protocol.getExpRunContainers());
clearDefaultValues(defaultValueContainers, domains);
for (Pair<Domain, Map<DomainProperty, Object>> domainInfo : domainInfos)

for (Domain domain : domains)
{
Domain domain = domainInfo.getKey();
for (DomainProperty prop : domain.getProperties())
{
prop.delete();
Expand Down Expand Up @@ -1537,12 +1541,14 @@ private NavTree getManageMenuNavTree(ViewContext context, ExpProtocol protocol)
{
Container protocolContainer = protocol.getContainer();
Container contextContainer = context.getContainer();

NavTree manageMenu = new NavTree(MANAGE_ASSAY_DESIGN_LINK);

final AssayUrls assayUrls = Objects.requireNonNull(PageFlowUtil.urlProvider(AssayUrls.class));
final ExperimentUrls experimentUrls = Objects.requireNonNull(PageFlowUtil.urlProvider(ExperimentUrls.class));

if (allowUpdate(context, protocol))
{
ActionURL editURL = PageFlowUtil.urlProvider(AssayUrls.class).getDesignerURL(protocolContainer, protocol, false, context.getActionURL());
ActionURL editURL = assayUrls.getDesignerURL(protocolContainer, protocol, false, context.getActionURL());
if (editURL != null)
{
var child = manageMenu.addChild("Edit assay design","");
Expand All @@ -1552,32 +1558,30 @@ private NavTree getManageMenuNavTree(ViewContext context, ExpProtocol protocol)
child.setScript("if (window.confirm('This assay is defined in the " + protocolContainer.getPath() + " folder. Would you still like to edit it?')) { window.location = " + jsString(editURL.toString()) + "; } return false;");
}

ActionURL copyURL = PageFlowUtil.urlProvider(AssayUrls.class).getChooseCopyDestinationURL(protocol, protocolContainer);
ActionURL copyURL = assayUrls.getChooseCopyDestinationURL(protocol, protocolContainer);
if (copyURL != null)
manageMenu.addChild("Copy assay design", copyURL.toString());
}

if (allowDelete(context, protocol))
{
manageMenu.addChild("Delete assay design", PageFlowUtil.urlProvider(ExperimentUrls.class).getDeleteProtocolURL(protocol, PageFlowUtil.urlProvider(AssayUrls.class).getAssayListURL(contextContainer)));
manageMenu.addChild("Delete assay design", experimentUrls.getDeleteProtocolURL(protocol, assayUrls.getAssayListURL(contextContainer)));
}

ActionURL exportURL = PageFlowUtil.urlProvider(ExperimentUrls.class).getExportProtocolURL(protocolContainer, protocol);
ActionURL exportURL = experimentUrls.getExportProtocolURL(protocolContainer, protocol);
manageMenu.addChild("Export assay design", exportURL.toString());

if (contextContainer.hasPermission(context.getUser(), AdminPermission.class))
{
List<Pair<Domain, Map<DomainProperty, Object>>> domainInfos = getDomains(protocol);
if (!domainInfos.isEmpty())
List<Domain> domains = getDomains(protocol);
if (!domains.isEmpty())
{
NavTree setDefaultsTree = new NavTree(SET_DEFAULT_VALUES_LINK);
AssayUrls urls = PageFlowUtil.urlProvider(AssayUrls.class);
for (Pair<Domain, Map<DomainProperty, Object>> domainInfo : domainInfos)
for (Domain domain : domains)
{
Domain domain = domainInfo.getKey();
if (allowDefaultValues(domain) && !domain.getProperties().isEmpty())
{
ActionURL url = urls.getSetDefaultValuesAssayURL(contextContainer, getName(), domain, context.getActionURL());
ActionURL url = assayUrls.getSetDefaultValuesAssayURL(contextContainer, getName(), domain, context.getActionURL());
setDefaultsTree.addChild(domain.getName(), url);
}
}
Expand Down
1 change: 0 additions & 1 deletion api/src/org/labkey/api/assay/AssayDomainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.labkey.api.assay;

import org.labkey.api.gwt.client.assay.AssayException;
import org.labkey.api.gwt.client.assay.model.GWTProtocol;
import org.labkey.api.query.ValidationException;

Expand Down
4 changes: 3 additions & 1 deletion api/src/org/labkey/api/assay/AssayProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ default String getLabel()

List<ParticipantVisitResolverType> getParticipantVisitResolverTypes();

List<Pair<Domain, Map<DomainProperty, Object>>> getDomains(ExpProtocol protocol);
@NotNull List<Domain> getDomains(ExpProtocol protocol);

@NotNull List<Pair<Domain, Map<DomainProperty, Object>>> getDomainsAndDefaultValues(ExpProtocol protocol);

Pair<ExpProtocol, List<Pair<Domain, Map<DomainProperty, Object>>>> getAssayTemplate(User user, Container targetContainer);

Expand Down
5 changes: 0 additions & 5 deletions api/src/org/labkey/api/assay/AssayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,6 @@ ParticipantVisitResolver createResolver(User user, ExpRun run, @Nullable ExpProt
*/
<FlagType extends ExpQCFlag> List<FlagType> getFlags(AssayProvider provider, int runId, Class<FlagType> cls);

/**
* Returns the TableInfo for the given assay domain based on the assay domain ID.
*/
TableInfo getTableInfoForDomainId(User user, Container container, int domainId, @Nullable ContainerFilter cf);

void onBeforeAssayResultDelete(Container container, User user, ExpRun run, Map<String, Object> resultRow);

/**
Expand Down
31 changes: 15 additions & 16 deletions api/src/org/labkey/api/exp/property/AbstractDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@
import static org.labkey.api.exp.api.ExpData.DATA_INPUTS_PREFIX;
import static org.labkey.api.exp.api.SampleTypeService.MATERIAL_INPUTS_PREFIX;

/**
* User: kevink
* Date: Jun 4, 2010
* Time: 3:29:46 PM
*/
public abstract class AbstractDomainKind<T> extends DomainKind<T>
{
public static final String OBJECT_URI_COLUMN_NAME = "lsid";
Expand Down Expand Up @@ -181,10 +176,8 @@ public boolean hasNullValues(Domain domain, DomainProperty prop)
long nonBlankRows = new SqlSelector(ExperimentService.get().getSchema(), nonBlankRowsSQL).getRowCount();
return totalRows != nonBlankRows;
}
else
{
return false;
}

return false;
}

protected boolean getTotalAndNonBlankSql(Domain domain, DomainProperty prop, SQLFragment allRowsSQL, SQLFragment nonBlankRowsSQL)
Expand All @@ -205,7 +198,8 @@ protected boolean getTotalAndNonBlankSql(Domain domain, DomainProperty prop, SQL

return true;
}
else if (domain.getStorageTableName() != null)

if (domain.getStorageTableName() != null)
{
String table = domain.getStorageTableName();
allRowsSQL.append("SELECT * FROM " + getStorageSchemaName() + "." + table);
Expand All @@ -224,12 +218,11 @@ else if (domain.getStorageTableName() != null)
nonBlankRowsSQL.append(mvColumn.getName().toLowerCase());
nonBlankRowsSQL.append(" IS NOT NULL");
}

return true;
}
else
{
return false;
}

return false;
}

@Override
Expand All @@ -252,7 +245,6 @@ protected DomainTemplate getDomainTemplate(Domain domain)
return DomainTemplate.findTemplate(domain.getTemplateInfo(), getKindName());
}


@Override
public Set<String> getNonProvisionedTableNames()
{
Expand Down Expand Up @@ -315,10 +307,17 @@ public boolean exceedsMaxLength(Domain domain, DomainProperty prop)
}

@Override
@Nullable
public List<String> getDomainNamePreviews(String schemaName, String queryName, Container container, User user)
{
String domainURI = PropertyService.get().getDomainURI(schemaName, queryName, container, user);
GWTDomain gwtDomain = DomainUtil.getDomainDescriptor(user, domainURI, container, true);
if (domainURI == null)
return null;

GWTDomain<?> gwtDomain = DomainUtil.getDomainDescriptor(user, domainURI, container, true);
if (gwtDomain == null)
return null;

Domain domain = PropertyService.get().getDomain(container, gwtDomain.getDomainURI());
if (null != domain && null != domain.getDomainKind())
{
Expand Down
20 changes: 9 additions & 11 deletions api/src/org/labkey/api/exp/property/DomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import java.util.Set;
import java.util.stream.Collectors;

abstract public class DomainKind<T> implements Handler<String>
abstract public class DomainKind<T> implements Handler<String>
{
abstract public String getKindName();

Expand Down Expand Up @@ -110,6 +110,7 @@ public Map<String, Object> processArguments(Container container, User user, Map<
* @return set of strings containing the names. This will be compared ignoring case
*/
abstract public Set<String> getReservedPropertyNames(Domain domain, User user);

public Set<String> getReservedPropertyNames(Domain domain, User user, boolean forCreate)
{
return getReservedPropertyNames(domain, user);
Expand Down Expand Up @@ -256,19 +257,18 @@ public boolean hasPropertiesIncludeBaseProperties()

/**
* Default for all domain kinds is to not delete data. Lists and Datasets override this.
* @return
*/
public boolean isDeleteAllDataOnFieldImport()
{
return false;
}

public TableInfo getTableInfo(User user, Container container, String name, @Nullable ContainerFilter cf)
public @Nullable TableInfo getTableInfo(User user, Container container, String name, @Nullable ContainerFilter cf)
{
return null;
}

public TableInfo getTableInfo(User user, Container container, Domain domain, @Nullable ContainerFilter cf)
public @Nullable TableInfo getTableInfo(User user, Container container, Domain domain, @Nullable ContainerFilter cf)
{
return getTableInfo(user, container, domain.getName(), cf);
}
Expand Down Expand Up @@ -348,6 +348,7 @@ public DefaultValueType getDefaultDefaultType(Domain domain)
{
return DefaultValueType.FIXED_EDITABLE;
}

public String getObjectUriColumnName()
{
return null;
Expand Down Expand Up @@ -385,14 +386,11 @@ public NameExpressionValidationResult validateNameExpressions(T options, GWTDoma
}

/**
* @param schemaName
* @param queryName
* @param container
* @param user
* @return Return preview name(s) based on the name expression configured for the designer. For DataClass, up to one preview names is returned.
* For samples, up to 2 names can be returned, with the 1st one being the sample preview name and the 2nd being the aliquot preview name.
* @return Return preview name(s) based on the name expression configured for the designer. For DataClass,
* up to one preview names is returned. For samples, up to 2 names can be returned, with the 1st one being
* the sample preview name and the 2nd being the aliquot preview name.
*/
public List<String> getDomainNamePreviews(String schemaName, String queryName, Container container, User user)
public @Nullable List<String> getDomainNamePreviews(String schemaName, String queryName, Container container, User user)
{
return null;
}
Expand Down
Loading

0 comments on commit 0a989c8

Please sign in to comment.