Skip to content

Introduce a subclass of DomainProps for Datasets #2483

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

Merged
merged 2 commits into from
Jun 11, 2025
Merged
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
131 changes: 131 additions & 0 deletions src/org/labkey/test/params/study/DatasetDefinition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package org.labkey.test.params.study;

import org.jetbrains.annotations.NotNull;
import org.labkey.remoteapi.domain.Domain;
import org.labkey.remoteapi.domain.PropertyDescriptor;
import org.labkey.test.params.property.DomainProps;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DatasetDefinition extends DomainProps
{
private String _name;
private String _description;
private List<PropertyDescriptor> _fields = new ArrayList<>();
private String _kindName;
private Boolean _demographics;
private Boolean _managedKeyField;
private String _keyPropertyName;
private Boolean _timeKeyField;

public static final String VISIT_BASED_STUDY = "StudyDatasetVisit";
public static final String DATE_BASED_STUDY = "StudyDatasetDate";

public static DatasetDefinition create(String name)
{
return new DatasetDefinition(name);
}
Comment on lines +27 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This static create method is a little confusing because DomainProps has a non-static create method that actually creates the domain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's true, I was thinking of maybe init, not sure if there is a better verb.


public DatasetDefinition(String name)
{
this(name, VISIT_BASED_STUDY);
}

public DatasetDefinition(String name, String kindName)
{
_name = name;
_kindName = kindName;
}

public DatasetDefinition setDescription(String description)
{
_description = description;
return this;
}

public DatasetDefinition setFields(List<PropertyDescriptor> fields)
{
_fields = fields;
return this;
}

public DatasetDefinition setKindName(String kindName)
{
_kindName = kindName;
return this;
}

public DatasetDefinition setDemographics(Boolean demographics)
{
_demographics = demographics;
return this;
}

public DatasetDefinition setKeyPropertyName(String keyPropertyName)
{
_keyPropertyName = keyPropertyName;
return this;
}

public DatasetDefinition setKeyPropertyName(String keyPropertyName, Boolean managedKeyField)
{
_keyPropertyName = keyPropertyName;
_managedKeyField = managedKeyField;
return this;
}

public DatasetDefinition setTimeKeyField(Boolean timeKeyField)
{
_timeKeyField = timeKeyField;
return this;
}

@Override
protected @NotNull Domain getDomainDesign()
{
Domain domain = new Domain(_name);

domain.setDescription(_description);
domain.setFields(_fields);

return domain;
}

@Override
protected @NotNull String getKind()
{
return _kindName;
}

@Override
protected @NotNull Map<String, Object> getOptions()
{
Map<String, Object> options = new HashMap<>();

if (_demographics != null)
options.put("demographics", _demographics);
if (_keyPropertyName != null)
options.put("keyPropertyName", _keyPropertyName);
if (_managedKeyField != null)
options.put("keyPropertyManaged", _managedKeyField);
if (_timeKeyField != null)
options.put("useTimeKeyField", _timeKeyField);

return options;
}

@Override
protected @NotNull String getSchemaName()
{
return "study";
}

@Override
protected @NotNull String getQueryName()
{
return _name;
}
}