Skip to content

Commit

Permalink
Merge pull request #40 from bimberlabinternal/24.11_fb_species
Browse files Browse the repository at this point in the history
Convert species table to be container-scoped
  • Loading branch information
bbimber authored Dec 13, 2024
2 parents c570a60 + cb8a748 commit c0368c5
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE laboratory.species ADD rowid SERIAL;
ALTER TABLE laboratory.species ADD container entityid;
ALTER TABLE laboratory.species ADD created timestamp;
ALTER TABLE laboratory.species ADD createdby int;
ALTER TABLE laboratory.species ADD modified timestamp;
ALTER TABLE laboratory.species ADD modifiedby int;

UPDATE laboratory.species SET container = (SELECT entityid FROM core.containers WHERE name = 'Shared');

ALTER TABLE laboratory.species DROP CONSTRAINT PK_species;
ALTER TABLE laboratory.species ADD CONSTRAINT PK_species PRIMARY KEY (rowid);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE laboratory.species ADD rowid INT identity(1,1);
ALTER TABLE laboratory.species ADD container entityid;
ALTER TABLE laboratory.species ADD created datetime;
ALTER TABLE laboratory.species ADD createdby int;
ALTER TABLE laboratory.species ADD modified datetime;
ALTER TABLE laboratory.species ADD modifiedby int;
GO
UPDATE laboratory.species SET container = (SELECT entityid FROM core.containers WHERE name = 'Shared');

ALTER TABLE laboratory.species DROP CONSTRAINT PK_species;
ALTER TABLE laboratory.species ADD CONSTRAINT PK_species PRIMARY KEY (rowid);
26 changes: 26 additions & 0 deletions laboratory/resources/schemas/laboratory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@
<javaCustomizer class="org.labkey.ldk.query.DefaultTableCustomizer" />
<auditLogging>DETAILED</auditLogging>
<columns>
<column columnName="rowid">
<isHidden>true</isHidden>
</column>
<column columnName="common_name">
</column>
<column columnName="scientific_name">
Expand All @@ -850,6 +853,29 @@
<nullable>true</nullable>
<columnTitle>MHC Prefix</columnTitle>
</column>
<column columnName="container">
<isHidden>false</isHidden>
</column>
<column columnName="createdby">
<isHidden>true</isHidden>
</column>
<column columnName="created">
<isUserEditable>false</isUserEditable>
<shownInInsertView>false</shownInInsertView>
<shownInUpdateView>false</shownInUpdateView>
<nullable>true</nullable>
<isHidden>true</isHidden>
</column>
<column columnName="modifiedby">
<isHidden>true</isHidden>
</column>
<column columnName="modified">
<isUserEditable>false</isUserEditable>
<shownInInsertView>false</shownInInsertView>
<shownInUpdateView>false</shownInUpdateView>
<nullable>true</nullable>
<isHidden>true</isHidden>
</column>
</columns>
</table>
<table tableName="geographic_origins" tableDbType="TABLE" useColumnOrder="true">
Expand Down
2 changes: 1 addition & 1 deletion laboratory/resources/views/populateInitialValues.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
LABKEY.Ajax.request({
url : LABKEY.ActionURL.buildURL('laboratory', 'populateDefaults'),
params: {
tableNames: ['sample_type']
tableNames: ['sample_type', 'species']
},
method : 'POST',
scope: this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void containerCreated(Container c, User user)
{
try
{
LaboratoryManager.get().populateDefaultData(user, c, null);
LaboratoryManager.get().populateDefaultData(user, c);
}
catch (IllegalArgumentException e)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ private void possiblyInitializeOnActiveModuleChange(PropertyChangeEvent evt)

try
{
LaboratoryManager.get().populateDefaultData(u, ce.container, null);
LaboratoryManager.get().populateDefaultData(u, ce.container);
}
catch (Exception e)
{
Expand Down
24 changes: 16 additions & 8 deletions laboratory/src/org/labkey/laboratory/LaboratoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.assay.AssayProvider;
import org.labkey.api.assay.AssayService;
Expand Down Expand Up @@ -336,26 +337,33 @@ public void updateWorkbookTags(User u, Container c, Collection<String> tags, boo
}
}

public void populateDefaultData(User u, Container c)
{
populateDefaultData(u, c, Arrays.asList(LaboratorySchema.TABLE_SAMPLE_TYPE, LaboratorySchema.TABLE_SPECIES));
}

//pass null to populate all supported tables
public void populateDefaultData(User u, Container c, @Nullable List<String> tableNames)
public void populateDefaultData(User u, Container c, @NotNull List<String> tableNames)
{
if (c.isWorkbook())
{
return;
}

if (tableNames == null)
{
tableNames = new ArrayList<>();
tableNames.add(LaboratorySchema.TABLE_SAMPLE_TYPE);
}

for (String name : tableNames)
{
if (LaboratorySchema.TABLE_SAMPLE_TYPE.equalsIgnoreCase(name))
if (LaboratorySchema.TABLE_SAMPLE_TYPE.equalsIgnoreCase(name) )
{
populateDefaultDataForTable(u, c, "laboratory", LaboratorySchema.TABLE_SAMPLE_TYPE, PageFlowUtil.set("type"), "type");
}
else if (LaboratorySchema.TABLE_SPECIES.equalsIgnoreCase(name) )
{
populateDefaultDataForTable(u, c, "laboratory", LaboratorySchema.TABLE_SPECIES, PageFlowUtil.set("common_name", "scientific_name", "mhc_prefix"), "common_name");
}
else
{
throw new IllegalArgumentException("Unknown table: " + name);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion laboratory/src/org/labkey/laboratory/LaboratoryModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String getName()
@Override
public @Nullable Double getSchemaVersion()
{
return 12.305;
return 12.306;
}

@Override
Expand Down
1 change: 1 addition & 0 deletions laboratory/src/org/labkey/laboratory/LaboratorySchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class LaboratorySchema
public static final String TABLE_WORKBOOKS = "workbooks";
public static final String TABLE_WORKBOOK_TAGS = "workbook_tags";
public static final String TABLE_ASSAY_RUN_TEMPLATES = "assay_run_templates";
public static final String TABLE_SPECIES = "species";

public static LaboratorySchema getInstance()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ protected TableInfo createWrappedTable(String name, @NotNull TableInfo sourceTab
return getSubjectsTable(name, sourceTable, cf);
else if (LaboratorySchema.TABLE_FREEZERS.equalsIgnoreCase(name))
return getContainerScopedTable(name, sourceTable, cf, "name");
else if (LaboratorySchema.TABLE_SPECIES.equalsIgnoreCase(name))
return getContainerScopedTable(name, sourceTable, cf, "common_name");
else if (LaboratorySchema.TABLE_SAMPLE_TYPE.equalsIgnoreCase(name))
return getContainerScopedTable(name, sourceTable, cf, "type");
else if (LaboratorySchema.TABLE_DNA_OLIGOS.equalsIgnoreCase(name))
Expand Down

0 comments on commit c0368c5

Please sign in to comment.