From 583ac58a353b3e73b52acf6bfb45356748e150fb Mon Sep 17 00:00:00 2001 From: Kevin Krouse Date: Wed, 2 Dec 2020 20:40:26 -0800 Subject: [PATCH 1/6] Issue 41675: deleting exp.object (#1741) - associate assay import background job with the resulting run - add FK from exp.data, exp.material, exp.experimentrun to exp.object by LSID and objectId - don't delete exp.object in assay ExperimentDataHandler subclasses; it will be cleaned up when the exp.data is deleted --- .../assay/AbstractAssayTsvDataHandler.java | 9 +- .../org/labkey/api/assay/TsvDataHandler.java | 8 - .../pipeline/AssayUploadPipelineJob.java | 3 + .../labkey/api/exp/ExperimentDataHandler.java | 4 +- .../org/labkey/api/exp/OntologyManager.java | 20 +- .../org/labkey/api/exp/OntologyObject.java | 13 +- .../assay/dilution/DilutionDataHandler.java | 3 +- .../assay/AssayIntegrationTestCase.java | 213 ++++++++++++++++++ assay/src/org/labkey/assay/AssayModule.java | 3 +- .../postgresql/exp-20.012-20.013.sql | 31 +++ .../dbscripts/sqlserver/exp-20.012-20.013.sql | 31 +++ .../labkey/experiment/ExperimentModule.java | 2 +- .../experiment/api/ExperimentServiceImpl.java | 42 ++-- 13 files changed, 332 insertions(+), 50 deletions(-) create mode 100644 assay/src/org/labkey/assay/AssayIntegrationTestCase.java create mode 100644 experiment/resources/schemas/dbscripts/postgresql/exp-20.012-20.013.sql create mode 100644 experiment/resources/schemas/dbscripts/sqlserver/exp-20.012-20.013.sql diff --git a/api/src/org/labkey/api/assay/AbstractAssayTsvDataHandler.java b/api/src/org/labkey/api/assay/AbstractAssayTsvDataHandler.java index 6371221045c..85f5c702c60 100644 --- a/api/src/org/labkey/api/assay/AbstractAssayTsvDataHandler.java +++ b/api/src/org/labkey/api/assay/AbstractAssayTsvDataHandler.java @@ -87,7 +87,6 @@ import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; import static java.util.stream.Collectors.toList; @@ -310,7 +309,7 @@ public void beforeDeleteData(List data, User user) throws ExperimentExc ExpProtocol protocol = run.getProtocol(); AssayProvider provider = AssayService.get().getProvider(protocol); - FieldKey assayResultLsidFieldKey = provider.getTableMetadata(protocol).getResultLsidFieldKey(); + FieldKey assayResultLsidFieldKey = provider != null ? provider.getTableMetadata(protocol).getResultLsidFieldKey() : null; SQLFragment assayResultLsidSql = null; @@ -340,7 +339,7 @@ public void beforeDeleteData(List data, User user) throws ExperimentExc // results/data domain for TSV-style assays try { - domain = AbstractAssayProvider.getDomainByPrefix(protocol, ExpProtocol.ASSAY_DOMAIN_DATA); + domain = AbstractAssayProvider.getDomainByPrefixIfExists(protocol, ExpProtocol.ASSAY_DOMAIN_DATA) ; } catch (IllegalStateException ignored) { @@ -354,7 +353,7 @@ public void beforeDeleteData(List data, User user) throws ExperimentExc // delete the assay result row exp.objects if (assayResultLsidSql != null) { - if (LOG.isTraceEnabled()) + if (LOG.isDebugEnabled()) { SQLFragment t = new SQLFragment("SELECT o.*") .append(" FROM ").append(OntologyManager.getTinfoObject(), "o") @@ -365,6 +364,7 @@ public void beforeDeleteData(List data, User user) throws ExperimentExc SqlSelector ss = new SqlSelector(ExperimentService.get().getSchema(), t); try (TableResultSet rs = ss.getResultSet()) { + LOG.debug("objects that will be deleted:"); ResultSetUtil.logData(rs, LOG); } catch (SQLException x) @@ -1144,7 +1144,6 @@ protected List> convertPropertyNamesToURIs(List datas, User user) throws ExperimentException; /** - * Completely delete all database rows attached to this data object. + * Completely delete all database rows attached to this data object but not the ExpData itself. + * When an experiment run is deleted, the ExpData is detached from the run since they usually represent an uploaded file. + * Some run types (e.g., Flow and TargetedMS) will also delete the ExpData. */ void deleteData(ExpData data, Container container, User user); diff --git a/api/src/org/labkey/api/exp/OntologyManager.java b/api/src/org/labkey/api/exp/OntologyManager.java index 5baada3d3a3..4619b07f732 100644 --- a/api/src/org/labkey/api/exp/OntologyManager.java +++ b/api/src/org/labkey/api/exp/OntologyManager.java @@ -17,7 +17,6 @@ import org.apache.commons.beanutils.ConversionException; import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -47,7 +46,6 @@ import org.labkey.api.query.PropertyValidationError; import org.labkey.api.query.ValidationError; import org.labkey.api.query.ValidationException; -import org.labkey.api.search.SearchService; import org.labkey.api.security.User; import org.labkey.api.security.permissions.ReadPermission; import org.labkey.api.test.TestTimeout; @@ -55,13 +53,9 @@ import org.labkey.api.util.CPUTimer; import org.labkey.api.util.GUID; import org.labkey.api.util.Pair; -import org.labkey.api.util.Path; import org.labkey.api.util.ResultSetUtil; import org.labkey.api.util.TestContext; -import org.labkey.api.view.ActionURL; import org.labkey.api.view.HttpView; -import org.labkey.api.webdav.SimpleDocumentResource; -import org.labkey.api.webdav.WebdavResource; import java.sql.Connection; import java.sql.PreparedStatement; @@ -84,7 +78,6 @@ import static java.util.Collections.unmodifiableCollection; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; -import static org.labkey.api.search.SearchService.PROPERTY; /** * Lots of static methods for dealing with domains and property descriptors. Tends to operate primarily on the bean-style @@ -855,10 +848,10 @@ public static int deleteOntologyObjects(DbSchema schema, SQLFragment sub, Contai public static void deleteOntologyObjects(Container c, boolean deleteOwnedObjects, int... objectIds) { - deleteOntologyObjects(c, deleteOwnedObjects, true, objectIds); + deleteOntologyObjects(c, deleteOwnedObjects, true, true, objectIds); } - private static void deleteOntologyObjects(Container c, boolean deleteOwnedObjects, boolean deleteObjects, int... objectIds) + public static void deleteOntologyObjects(Container c, boolean deleteOwnedObjects, boolean deleteObjectProperties, boolean deleteObjects, int... objectIds) { if (objectIds.length == 0) return; @@ -875,7 +868,7 @@ private static void deleteOntologyObjects(Container c, boolean deleteOwnedObject { int[] sub = new int[Math.min(lenBatch, objectIds.length - s)]; System.arraycopy(objectIds, s, sub, 0, sub.length); - deleteOntologyObjects(c, deleteOwnedObjects, deleteObjects, sub); + deleteOntologyObjects(c, deleteOwnedObjects, deleteObjectProperties, deleteObjects, sub); } return; @@ -907,10 +900,13 @@ private static void deleteOntologyObjects(Container c, boolean deleteOwnedObject new SqlExecutor(getExpSchema()).execute(sqlDeleteOwnedObjects); } - if (deleteObjects) + if (deleteObjectProperties) { deleteProperties(c, objectIds); + } + if (deleteObjects) + { StringBuilder sqlDeleteObjects = new StringBuilder(); sqlDeleteObjects.append("DELETE FROM ").append(getTinfoObject()).append(" WHERE Container = '").append(c.getId()).append("' AND ObjectId IN ("); sqlDeleteObjects.append(in); @@ -932,7 +928,7 @@ public static void deleteOntologyObject(String objectURI, Container container, b if (null != ontologyObject) { - deleteOntologyObjects(container, deleteOwnedObjects, true, ontologyObject.getObjectId()); + deleteOntologyObjects(container, deleteOwnedObjects, true, true, ontologyObject.getObjectId()); } } diff --git a/api/src/org/labkey/api/exp/OntologyObject.java b/api/src/org/labkey/api/exp/OntologyObject.java index 3722505b735..4db604f90a4 100644 --- a/api/src/org/labkey/api/exp/OntologyObject.java +++ b/api/src/org/labkey/api/exp/OntologyObject.java @@ -15,6 +15,7 @@ */ package org.labkey.api.exp; +import org.jetbrains.annotations.NotNull; import org.labkey.api.data.Container; /** @@ -25,8 +26,8 @@ public class OntologyObject { private int objectId; - private Container container; - private String objectURI; + private @NotNull Container container; + private @NotNull String objectURI; private Integer ownerObjectId; public int getObjectId() @@ -39,22 +40,22 @@ public void setObjectId(int objectId) this.objectId = objectId; } - public Container getContainer() + public @NotNull Container getContainer() { return container; } - public void setContainer(Container container) + public void setContainer(@NotNull Container container) { this.container = container; } - public String getObjectURI() + public @NotNull String getObjectURI() { return objectURI; } - public void setObjectURI(String objectURI) + public void setObjectURI(@NotNull String objectURI) { this.objectURI = objectURI; } diff --git a/assay/api-src/org/labkey/api/assay/dilution/DilutionDataHandler.java b/assay/api-src/org/labkey/api/assay/dilution/DilutionDataHandler.java index 69b886e395b..e85265aed31 100644 --- a/assay/api-src/org/labkey/api/assay/dilution/DilutionDataHandler.java +++ b/assay/api-src/org/labkey/api/assay/dilution/DilutionDataHandler.java @@ -643,7 +643,8 @@ public ActionURL getContentURL(ExpData data) @Override public void deleteData(ExpData data, Container container, User user) { - OntologyManager.deleteOntologyObject(data.getLSID(), container, true); + // delete owned objects and the object's properties, but leave the exp.object + OntologyManager.deleteOntologyObjects(container, true, true, false, data.getObjectId()); } public String getPropertyName(String prefix, int cutoff, StatsService.CurveFitType type) diff --git a/assay/src/org/labkey/assay/AssayIntegrationTestCase.java b/assay/src/org/labkey/assay/AssayIntegrationTestCase.java new file mode 100644 index 00000000000..851b0caad57 --- /dev/null +++ b/assay/src/org/labkey/assay/AssayIntegrationTestCase.java @@ -0,0 +1,213 @@ +package org.labkey.assay; + +import com.google.common.base.Charsets; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Test; +import org.labkey.api.assay.AssayDataCollector; +import org.labkey.api.assay.AssayDomainService; +import org.labkey.api.assay.AssayProvider; +import org.labkey.api.assay.AssayRunCreator; +import org.labkey.api.assay.AssayRunUploadContext; +import org.labkey.api.assay.AssayService; +import org.labkey.api.data.Container; +import org.labkey.api.data.JdbcType; +import org.labkey.api.data.PropertyStorageSpec; +import org.labkey.api.exp.OntologyManager; +import org.labkey.api.exp.OntologyObject; +import org.labkey.api.exp.PropertyDescriptor; +import org.labkey.api.exp.api.ExpData; +import org.labkey.api.exp.api.ExpExperiment; +import org.labkey.api.exp.api.ExpMaterial; +import org.labkey.api.exp.api.ExpProtocol; +import org.labkey.api.exp.api.ExpRun; +import org.labkey.api.exp.api.ExperimentService; +import org.labkey.api.exp.property.Domain; +import org.labkey.api.exp.property.DomainProperty; +import org.labkey.api.exp.property.PropertyService; +import org.labkey.api.exp.query.ExpSchema; +import org.labkey.api.files.FileContentService; +import org.labkey.api.files.FilesAdminOptions; +import org.labkey.api.gwt.client.assay.model.GWTProtocol; +import org.labkey.api.gwt.client.model.GWTDomain; +import org.labkey.api.gwt.client.model.GWTPropertyDescriptor; +import org.labkey.api.pipeline.PipelineService; +import org.labkey.api.security.User; +import org.labkey.api.util.JunitUtil; +import org.labkey.api.util.Pair; +import org.labkey.api.util.TestContext; +import org.labkey.api.view.ViewBackgroundInfo; +import org.labkey.api.view.ViewContext; + +import java.io.File; +import java.nio.file.Files; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + +public class AssayIntegrationTestCase +{ + public static final Logger LOG = LogManager.getLogger(AssayIntegrationTestCase.class); + + Container c; + + @Before + public void setUp() + { + JunitUtil.deleteTestContainer(); + c = JunitUtil.getTestContainer(); + } + + // Issue 41675: ERROR: insert or update on table "edge" violates foreign key constraint "fk_edge_to_object" + // - imports a file into an assay + // - sets some file properties + // - deletes the assay run + // - verifies the exp.data is detatched from the run, but the properties haven't been deleted + // - re-imports the same file again + @Test + public void testIssue41675() throws Exception + { + final User user = TestContext.get().getUser(); + final String ASSAY_NAME = "MyAssay"; + final var info = new ViewBackgroundInfo(c, user, null); + final var context = new ViewContext(info); + final var pipeRoot = PipelineService.get().findPipelineRoot(info.getContainer()); + + + // create a custom file property + FileContentService fileSvc = FileContentService.get(); + PropertyDescriptor someStuffProp = null; + if (fileSvc != null) + { + String domainUri = fileSvc.getDomainURI(c, FilesAdminOptions.fileConfig.useCustom); + Domain domain = PropertyService.get().createDomain(c, domainUri, "FileProps"); + domain.addProperty(new PropertyStorageSpec("SomeStuff", JdbcType.VARCHAR)); + domain.save(user); + + DomainProperty dp = domain.getPropertyByName("SomeStuff"); + someStuffProp = dp.getPropertyDescriptor(); + } + + // create assay design + AssayDomainService assayDomainService = new AssayDomainServiceImpl(context); + GWTProtocol assayTemplate = assayDomainService.getAssayTemplate("General"); + assayTemplate.setName(ASSAY_NAME); + List> domains = assayTemplate.getDomains(); + + // clear the batch domain fields + GWTDomain batchDomain = domains.stream().filter(d -> "Batch Fields".equals(d.getName())).findFirst().orElseThrow(); + batchDomain.getFields().clear(); + + // clear the run domain fields + GWTDomain runDomain = domains.stream().filter(d -> "Run Fields".equals(d.getName())).findFirst().orElseThrow(); + runDomain.getFields().clear(); + + // clear the result domain fields and add a sample lookup + GWTDomain resultDomain = domains.stream().filter(d -> "Data Fields".equals(d.getName())).findFirst().orElseThrow(); + resultDomain.getFields().clear(); + GWTPropertyDescriptor sampleLookup = new GWTPropertyDescriptor("SampleLookup", "int"); + sampleLookup.setLookupSchema(ExpSchema.SCHEMA_NAME); + sampleLookup.setLookupQuery(ExpSchema.TableType.Materials.name()); + resultDomain.getFields().add(sampleLookup); + + // create the assay + GWTProtocol savedAssayDesign = assayDomainService.saveChanges(assayTemplate, true); + ExpProtocol assayProtocol = ExperimentService.get().getExpProtocol(savedAssayDesign.getProtocolId()); + AssayProvider provider = AssayService.get().getProvider(assayProtocol); + + // create a sample that will be used as an input to the run + final String materialName = "TestMaterial"; + final String materialLsid = ExperimentService.get().generateLSID(c, ExpMaterial.class, "TestMaterial"); + ExpMaterial material = ExperimentService.get().createExpMaterial(c, materialLsid, materialName); + material.save(user); + + // create a file in the pipeline root to import + var file = File.createTempFile(getClass().getSimpleName(), ".tsv", pipeRoot.getRootPath()); + Files.writeString(file.toPath(), "SampleLookup\n" + materialName + "\n", Charsets.UTF_8); + + // create an upload context that imports the file + AssayRunUploadContext uploadContext = provider.createRunUploadFactory(assayProtocol, user, c) + .setName("New Run") + .setUploadedData(Map.of(AssayDataCollector.PRIMARY_FILE, file)) + .create(); + + // create a new run + AssayRunCreator runCreator = provider.getRunCreator(); + Pair pair = runCreator.saveExperimentRun(uploadContext, null); + ExpRun run = pair.second; + + // verify the exp.data is attached to the run + assertEquals(1, run.getDataOutputs().size()); + final ExpData originalOutputData = run.getDataOutputs().get(0); + assertEquals(file.getName(), originalOutputData.getName()); + + final int dataRowId = originalOutputData.getRowId(); + final String dataLsid = originalOutputData.getLSID(); + final Integer dataOID = originalOutputData.getObjectId(); + final OntologyObject oo1 = OntologyManager.getOntologyObject(originalOutputData.getObjectId()); + assertNotNull(oo1); + + // set some properties that will be verified later + originalOutputData.setComment(user, "hello world"); + if (someStuffProp != null) + originalOutputData.setProperty(user, someStuffProp, "SomeData"); + + // verify lineage + var parents = ExperimentService.get().getParents(c, user, originalOutputData); + assertThat(parents.second, CoreMatchers.hasItem(material)); + + // delete the run + run.delete(user); + + // verify the exp.data, exp.object, and the properties were not deleted + ExpData data2 = ExperimentService.get().getExpData(dataRowId); + assertNotNull(data2); + assertEquals(dataLsid, data2.getLSID()); + assertEquals(dataOID, data2.getObjectId()); + assertEquals("hello world", data2.getComment()); + if (someStuffProp != null) + assertEquals("SomeData", data2.getProperty(someStuffProp)); + + assertNull(data2.getRunId()); + parents = ExperimentService.get().getParents(c, user, data2); + assertThat(parents.second, CoreMatchers.not(CoreMatchers.hasItem(material))); + + OntologyObject oo2 = OntologyManager.getOntologyObject(data2.getObjectId()); + assertNotNull(oo2); + assertEquals(oo1.getObjectId(), oo2.getObjectId()); + assertEquals(oo1.getObjectURI(), oo2.getObjectURI()); + assertEquals(oo1.getContainer(), oo2.getContainer()); + assertEquals(oo1.getOwnerObjectId(), oo2.getOwnerObjectId()); + + // import the same file again + uploadContext = provider.createRunUploadFactory(assayProtocol, user, c) + .setName("New Run2") + .setUploadedData(Map.of(AssayDataCollector.PRIMARY_FILE, file)) + .create(); + + // create a new run + runCreator = provider.getRunCreator(); + pair = runCreator.saveExperimentRun(uploadContext, null); + ExpRun run2 = pair.second; + + // verify the exp.data and exp.object again + ExpData data3 = ExperimentService.get().getExpData(dataRowId); + assertNotNull(data3); + assertEquals(dataLsid, data3.getLSID()); + assertEquals(dataOID, data3.getObjectId()); + assertEquals("hello world", data3.getComment()); + if (someStuffProp != null) + assertEquals("SomeData", data3.getProperty(someStuffProp)); + + assertEquals(run2.getRowId(), data3.getRunId().intValue()); + parents = ExperimentService.get().getParents(c, user, data3); + assertThat(parents.second, CoreMatchers.hasItem(material)); + + } +} diff --git a/assay/src/org/labkey/assay/AssayModule.java b/assay/src/org/labkey/assay/AssayModule.java index 3dd694352f9..3d9d9abf75c 100644 --- a/assay/src/org/labkey/assay/AssayModule.java +++ b/assay/src/org/labkey/assay/AssayModule.java @@ -252,7 +252,8 @@ public Set getProvisionedSchemaNames() public @NotNull Set getIntegrationTests() { return Set.of( - ModuleAssayCache.TestCase.class + ModuleAssayCache.TestCase.class, + AssayIntegrationTestCase.class ); } diff --git a/experiment/resources/schemas/dbscripts/postgresql/exp-20.012-20.013.sql b/experiment/resources/schemas/dbscripts/postgresql/exp-20.012-20.013.sql new file mode 100644 index 00000000000..54dbf5ef553 --- /dev/null +++ b/experiment/resources/schemas/dbscripts/postgresql/exp-20.012-20.013.sql @@ -0,0 +1,31 @@ +-- create exp.object for exp.data without one +INSERT INTO exp.object (objecturi, container) +SELECT D.lsid as objecturi, D.container as container +FROM exp.data D LEFT OUTER JOIN exp.object O ON D.lsid = O.objecturi +WHERE O.objecturi IS NULL; + +-- fixup exp.data.objectid to be consistent with the lsid of the exp.object +UPDATE exp.data +SET objectid = (SELECT O.objectid FROM exp.object O WHERE O.objecturi = lsid) +WHERE rowid IN ( + SELECT rowid + FROM exp.data D + LEFT OUTER JOIN exp.object O ON D.lsid = O.objecturi + WHERE D.objectid != O.objectid +); + +-- add constraints for lsid -> exp.object +ALTER TABLE exp.data ADD CONSTRAINT FK_Data_Lsid + FOREIGN KEY (lsid) REFERENCES exp.object (objecturi); +ALTER TABLE exp.material ADD CONSTRAINT FK_Material_Lsid + FOREIGN KEY (lsid) REFERENCES exp.object (objecturi); +ALTER TABLE exp.experimentrun ADD CONSTRAINT FK_ExperimentRun_Lsid + FOREIGN KEY (lsid) REFERENCES exp.object (objecturi); + +-- add constraints for objectid -> exp.object +ALTER TABLE exp.data ADD CONSTRAINT FK_Data_ObjectId + FOREIGN KEY (objectid) REFERENCES exp.object (objectid); +ALTER TABLE exp.material ADD CONSTRAINT FK_Material_ObjectId + FOREIGN KEY (objectid) REFERENCES exp.object (objectid); +ALTER TABLE exp.experimentrun ADD CONSTRAINT FK_ExperimentRun_ObjectId + FOREIGN KEY (objectid) REFERENCES exp.object (objectid); diff --git a/experiment/resources/schemas/dbscripts/sqlserver/exp-20.012-20.013.sql b/experiment/resources/schemas/dbscripts/sqlserver/exp-20.012-20.013.sql new file mode 100644 index 00000000000..54dbf5ef553 --- /dev/null +++ b/experiment/resources/schemas/dbscripts/sqlserver/exp-20.012-20.013.sql @@ -0,0 +1,31 @@ +-- create exp.object for exp.data without one +INSERT INTO exp.object (objecturi, container) +SELECT D.lsid as objecturi, D.container as container +FROM exp.data D LEFT OUTER JOIN exp.object O ON D.lsid = O.objecturi +WHERE O.objecturi IS NULL; + +-- fixup exp.data.objectid to be consistent with the lsid of the exp.object +UPDATE exp.data +SET objectid = (SELECT O.objectid FROM exp.object O WHERE O.objecturi = lsid) +WHERE rowid IN ( + SELECT rowid + FROM exp.data D + LEFT OUTER JOIN exp.object O ON D.lsid = O.objecturi + WHERE D.objectid != O.objectid +); + +-- add constraints for lsid -> exp.object +ALTER TABLE exp.data ADD CONSTRAINT FK_Data_Lsid + FOREIGN KEY (lsid) REFERENCES exp.object (objecturi); +ALTER TABLE exp.material ADD CONSTRAINT FK_Material_Lsid + FOREIGN KEY (lsid) REFERENCES exp.object (objecturi); +ALTER TABLE exp.experimentrun ADD CONSTRAINT FK_ExperimentRun_Lsid + FOREIGN KEY (lsid) REFERENCES exp.object (objecturi); + +-- add constraints for objectid -> exp.object +ALTER TABLE exp.data ADD CONSTRAINT FK_Data_ObjectId + FOREIGN KEY (objectid) REFERENCES exp.object (objectid); +ALTER TABLE exp.material ADD CONSTRAINT FK_Material_ObjectId + FOREIGN KEY (objectid) REFERENCES exp.object (objectid); +ALTER TABLE exp.experimentrun ADD CONSTRAINT FK_ExperimentRun_ObjectId + FOREIGN KEY (objectid) REFERENCES exp.object (objectid); diff --git a/experiment/src/org/labkey/experiment/ExperimentModule.java b/experiment/src/org/labkey/experiment/ExperimentModule.java index 8d6b5a15c75..ed4cb2391e9 100644 --- a/experiment/src/org/labkey/experiment/ExperimentModule.java +++ b/experiment/src/org/labkey/experiment/ExperimentModule.java @@ -134,7 +134,7 @@ public String getName() @Override public Double getSchemaVersion() { - return 20.012; + return 20.013; } @Nullable diff --git a/experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java b/experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java index 16d9aae694c..b7a575ac217 100644 --- a/experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java +++ b/experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java @@ -2965,6 +2965,13 @@ private void syncRunEdges(int runId, Integer runObjectId, String runLsid, Contai else toDataLsids.add(row); }); + if (LOG.isDebugEnabled()) + { + if (!fromDataLsids.isEmpty()) + LOG.debug(" fromDataLsids:\n " + StringUtils.join(fromDataLsids, "\n ")); + if (!toDataLsids.isEmpty()) + LOG.debug(" toDataLsids:\n " + StringUtils.join(toDataLsids, "\n ")); + } SQLFragment materials = new SQLFragment() .append("SELECT m.Container, m.LSID, m.CpasType, m.ObjectId, pa.CpasType AS pa_cpas_type FROM exp.material m\n") @@ -3002,8 +3009,8 @@ private void syncRunEdges(int runId, Integer runObjectId, String runLsid, Contai removeEdgesForRun(runId); int edgeCount = fromDataLsids.size() + fromMaterialLsids.size() + toDataLsids.size() + toMaterialLsids.size() + provenanceStartingInputs.size() + provenanceFinalOutputs.size(); - LOG.debug(String.format(" edge counts: input data=%d, input materials=%d, output data=%d, output materials=%d, total=%d", - fromDataLsids.size(), fromMaterialLsids.size(), toDataLsids.size(), toMaterialLsids.size(), edgeCount)); + LOG.debug(String.format(" edge counts: input data=%d, input materials=%d, output data=%d, output materials=%d, input prov=%d, output prov=%d, total=%d", + fromDataLsids.size(), fromMaterialLsids.size(), toDataLsids.size(), toMaterialLsids.size(), provenanceStartingInputs.size(), provenanceFinalOutputs.size(), edgeCount)); if (edgeCount > 0) { @@ -3234,9 +3241,6 @@ private void deleteRun(int runId, List datasToDelete, User user) run.deleteProtocolApplications(datasToDelete, user); - //delete run properties and all children - OntologyManager.deleteOntologyObject(run.getLSID(), run.getContainer(), true); - SQLFragment sql = new SQLFragment("DELETE FROM exp.RunList WHERE ExperimentRunId = ?;\n"); sql.add(run.getRowId()); sql.append("UPDATE exp.ExperimentRun SET ReplacedByRunId = NULL WHERE ReplacedByRunId = ?;\n"); @@ -3248,6 +3252,9 @@ private void deleteRun(int runId, List datasToDelete, User user) new SqlExecutor(getExpSchema()).execute(sql); + // delete run properties and all children + OntologyManager.deleteOntologyObject(run.getLSID(), run.getContainer(), true); + ExpProtocolImpl protocol = run.getProtocol(); if (protocol == null) { @@ -4039,14 +4046,6 @@ public void deleteMaterialByRowIds(User user, Container container, Collection datas = new TableSelector(getTinfoData(), rowIdFilter, null).getArrayList(Data.class); + List allLsids = new ArrayList<>(datas.size()); Map> lsidsByClass = new LinkedHashMap<>(); for (Data data : datas) @@ -4316,13 +4324,12 @@ public void deleteDataByRowIds(User user, Container container, Collection byClass = lsidsByClass.computeIfAbsent(data.getClassId(), k -> new ArrayList<>(10)); byClass.add(data.getLSID()); } + allLsids.add(data.getLSID()); } SqlDialect dialect = getExpSchema().getSqlDialect(); @@ -4362,6 +4369,11 @@ public void deleteDataByRowIds(User user, Container container, Collection Date: Thu, 3 Dec 2020 07:13:27 -0800 Subject: [PATCH 2/6] Issue 41908: ETL columns with special characters (including Benchling WH columns) (#1743) - In ResultSetDataIterator constructor use Results columnInfos for metadata if Results type passed in for ResultSet. --- .../api/dataiterator/ResultSetDataIterator.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api/src/org/labkey/api/dataiterator/ResultSetDataIterator.java b/api/src/org/labkey/api/dataiterator/ResultSetDataIterator.java index 61816d4bcc0..43043e0312f 100644 --- a/api/src/org/labkey/api/dataiterator/ResultSetDataIterator.java +++ b/api/src/org/labkey/api/dataiterator/ResultSetDataIterator.java @@ -23,6 +23,7 @@ import org.labkey.api.data.ColumnInfo; import org.labkey.api.data.CoreSchema; import org.labkey.api.data.JdbcType; +import org.labkey.api.data.Results; import org.labkey.api.data.SqlSelector; import org.labkey.api.util.ResultSetUtil; @@ -62,7 +63,19 @@ protected ResultSetDataIterator(ResultSet rs, DataIteratorContext context) _columns = new ColumnInfo[rsmd.getColumnCount()+1]; _columns[0] = new BaseColumnInfo("_row", JdbcType.INTEGER); for (int i=1 ; i<=rsmd.getColumnCount() ; i++) - _columns[i] = new BaseColumnInfo(rsmd, i); + { + ColumnInfo ci = null; + if (rs instanceof Results) + { + // Use field map to get size of columnInfos which is field map size + 1 + if (i <= ((Results) rs).getFieldMap().size()) + { + ci = ((Results) rs).getColumn(i); + } + } + + _columns[i] = ci == null ? new BaseColumnInfo(rsmd, i) : ci; + } } catch (SQLException x) { From 8dff163f67929d14368ec02c090ddf899b27bf9f Mon Sep 17 00:00:00 2001 From: Kevin Krouse Date: Mon, 7 Dec 2020 13:25:44 +0800 Subject: [PATCH 3/6] Issue 41675: allow updating the LSID of an existing exp.data (#1758) - update LSID for existing exp.data by deleting and creating new exp.object --- .../org/labkey/api/exp/IdentifiableBase.java | 8 +++++ .../api/ExpIdentifiableBaseImpl.java | 30 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/api/src/org/labkey/api/exp/IdentifiableBase.java b/api/src/org/labkey/api/exp/IdentifiableBase.java index d2c153cf8df..c6a7c360514 100644 --- a/api/src/org/labkey/api/exp/IdentifiableBase.java +++ b/api/src/org/labkey/api/exp/IdentifiableBase.java @@ -86,6 +86,14 @@ public void setObjectId(Integer objectId) this.objectId = objectId; } + // allows updating objectId -- should only be used if there is an existing objectId that was updated + public void replaceExistingObjectId(int objectId) + { + if (this.objectId == null || this.objectId.equals(objectId)) + throw new IllegalStateException("only call this method if you are creating a new exp.object with a different LSID and need to update the objectId"); + this.objectId = objectId; + } + @Override public Container getContainer() { diff --git a/experiment/src/org/labkey/experiment/api/ExpIdentifiableBaseImpl.java b/experiment/src/org/labkey/experiment/api/ExpIdentifiableBaseImpl.java index feed409bbda..7df42dd43be 100644 --- a/experiment/src/org/labkey/experiment/api/ExpIdentifiableBaseImpl.java +++ b/experiment/src/org/labkey/experiment/api/ExpIdentifiableBaseImpl.java @@ -17,6 +17,7 @@ package org.labkey.experiment.api; import org.jetbrains.annotations.Nullable; +import org.labkey.api.data.DbScope; import org.labkey.api.data.Table; import org.labkey.api.data.TableInfo; import org.labkey.api.exp.IdentifiableBase; @@ -24,6 +25,8 @@ import org.labkey.api.exp.OntologyManager; import org.labkey.api.security.User; +import java.util.Objects; + /** * User: jeckels * Date: Sep 26, 2007 @@ -31,6 +34,7 @@ public abstract class ExpIdentifiableBaseImpl extends ExpObjectImpl { protected Type _object; + protected String _prevLsid = null; // For serialization protected ExpIdentifiableBaseImpl() {} @@ -64,6 +68,10 @@ public void setLSID(Lsid lsid) public void setLSID(String lsid) { ensureUnlocked(); + if (!Objects.equals(_object.getLSID(), lsid)) + { + _prevLsid = _object.getLSID(); + } _object.setLSID(lsid); } @@ -127,8 +135,28 @@ protected void save(User user, TableInfo table, boolean ensureObject, boolean is } else { - _object = Table.update(user, table, _object, getRowId()); + try (DbScope.Transaction tx = table.getSchema().getScope().ensureTransaction()) + { + // Create a new exp.object if the LSID changed + if (_prevLsid != null && ensureObject) + { + assert !Objects.equals(_prevLsid, getLSID()); + _objectId = OntologyManager.ensureObject(getContainer(), getLSID(), getParentObjectId()); + _object.replaceExistingObjectId(_objectId); + } + + _object = Table.update(user, table, _object, getRowId()); + + if (_prevLsid != null && ensureObject) + { + OntologyManager.deleteOntologyObject(_prevLsid, getContainer(), true); + } + + tx.commit(); + } } + + _prevLsid = null; } @Override From b09fa159185c18ffbfdf679b1f8eced8306cacb9 Mon Sep 17 00:00:00 2001 From: labkey-matthewb Date: Fri, 11 Dec 2020 13:48:00 -0800 Subject: [PATCH 4/6] 20.11 fb datasetqueryview (#1768) * allow controlling whether session participant group message shows up in dataregion (and client grid) --- .../ParticipantGroupController.java | 17 ++++++-- .../study/model/ParticipantGroupManager.java | 16 +++++++- .../labkey/study/query/DatasetQueryView.java | 41 ++++++++++--------- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/study/src/org/labkey/study/controllers/ParticipantGroupController.java b/study/src/org/labkey/study/controllers/ParticipantGroupController.java index 3fa5470a6c1..2e05e2a1f13 100644 --- a/study/src/org/labkey/study/controllers/ParticipantGroupController.java +++ b/study/src/org/labkey/study/controllers/ParticipantGroupController.java @@ -1128,6 +1128,7 @@ private static class UpdateParticipantGroupForm private String[] _participantIds; private String[] _ensureParticipantIds; private String[] _deleteParticipantIds; + private boolean _showDataRegionMessage = true; public int getRowId() { @@ -1198,6 +1199,16 @@ public void setDeleteParticipantIds(String[] deleteParticipantIds) { _deleteParticipantIds = deleteParticipantIds; } + + public boolean isShowDataRegionMessage() + { + return _showDataRegionMessage; + } + + public void setShowDataRegionMessage(boolean showDataRegionMessage) + { + _showDataRegionMessage = showDataRegionMessage; + } } @RequiresPermission(ReadPermission.class) @RequiresLogin @@ -1425,7 +1436,7 @@ public Object execute(UpdateParticipantGroupForm form, BindException errors) if (existing == null) throw new NotFoundException("Could not find participant group with rowId " + form.getRowId()); - ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), existing.getRowId()); + ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), existing.getRowId(), form.isShowDataRegionMessage()); return success(existing); } else @@ -1453,7 +1464,7 @@ else if (!group.isSession()) copy.setModified(copy.getModified()); copy.setModifiedBy(copy.getModifiedBy()); group = copy; - ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), group); + ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), group, form.isShowDataRegionMessage()); } Set participantIds = new HashSet<>(Arrays.asList(form.getParticipantIds() == null ? group.getParticipantIds() : form.getParticipantIds())); @@ -1473,7 +1484,7 @@ else if (!group.isSession()) if (form.getFilters() != null) group.setFilters(form.getFilters()); - group = ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), group); + group = ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), group, form.isShowDataRegionMessage()); return success(group); } } diff --git a/study/src/org/labkey/study/model/ParticipantGroupManager.java b/study/src/org/labkey/study/model/ParticipantGroupManager.java index 581acee37c6..969867945a6 100644 --- a/study/src/org/labkey/study/model/ParticipantGroupManager.java +++ b/study/src/org/labkey/study/model/ParticipantGroupManager.java @@ -55,6 +55,7 @@ import org.labkey.api.util.MemTracker; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.Pair; +import org.labkey.api.util.SessionHelper; import org.labkey.api.view.ActionURL; import org.labkey.api.view.NavTree; import org.labkey.api.view.ViewContext; @@ -659,16 +660,17 @@ private Map getParticipantIdMap(Container c, User user, Particip return participantIdMap; } - public void setSessionParticipantGroup(Container c, User user, HttpServletRequest request, Integer groupRowId) + public void setSessionParticipantGroup(Container c, User user, HttpServletRequest request, Integer groupRowId, boolean showDataRegionMessage) { HttpSession session = request.getSession(true); if (session == null) return; session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId(), groupRowId); + session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + ".showMessage", showDataRegionMessage); } - public ParticipantGroup setSessionParticipantGroup(Container c, User user, HttpServletRequest request, ParticipantGroup group) + public ParticipantGroup setSessionParticipantGroup(Container c, User user, HttpServletRequest request, ParticipantGroup group, boolean showDataRegionMessage) { assert group.isSession(); HttpSession session = request.getSession(true); @@ -676,11 +678,20 @@ public ParticipantGroup setSessionParticipantGroup(Container c, User user, HttpS return null; session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId(), group); + session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + ".showMessage", showDataRegionMessage); + // don't MemTrack track this one, since it's going in session MemTracker.get().remove(group); return group; } + public boolean getSessionParticipantGroupShowMessage(Container c, HttpServletRequest request) + { + Boolean b = (Boolean)SessionHelper.getAttribute(request, PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + ".showMessage", false); + + return b == Boolean.TRUE; + } + public ParticipantGroup getSessionParticipantGroup(Container c, User user, HttpServletRequest request) { HttpSession session = request.getSession(true); @@ -703,6 +714,7 @@ public void deleteSessionParticipantGroup(Container c, User user, HttpServletReq return; session.removeAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId()); + session.removeAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + ".showMessage"); } diff --git a/study/src/org/labkey/study/query/DatasetQueryView.java b/study/src/org/labkey/study/query/DatasetQueryView.java index a22c1cac2c9..2efc5ea5c76 100644 --- a/study/src/org/labkey/study/query/DatasetQueryView.java +++ b/study/src/org/labkey/study/query/DatasetQueryView.java @@ -696,29 +696,32 @@ protected void addHeaderMessage(StringBuilder headerMessage, RenderContext ctx) } } - ParticipantGroup sessionGroup = ParticipantGroupManager.getInstance().getSessionParticipantGroup(dqs.getContainer(), dqs.getUser(), ctx.getViewContext().getRequest()); - if (sessionGroup != null) + if (ParticipantGroupManager.getInstance().getSessionParticipantGroupShowMessage(dqs.getContainer(), ctx.getViewContext().getRequest())) { - if (msg.length() > 0) - msg.append("  "); - msg.append("Selected " + PageFlowUtil.filter(dqs.getStudy().getSubjectNounPlural()) + ": "); - msg.append(sessionGroup.getParticipantIds().length); - } + ParticipantGroup sessionGroup = ParticipantGroupManager.getInstance().getSessionParticipantGroup(dqs.getContainer(), dqs.getUser(), ctx.getViewContext().getRequest()); + if (sessionGroup != null) + { + if (msg.length() > 0) + msg.append("  "); + msg.append("Selected " + PageFlowUtil.filter(dqs.getStudy().getSubjectNounPlural()) + ": "); + msg.append(sessionGroup.getParticipantIds().length); + } - if (msg.length() == 0) - return; + if (msg.length() != 0) + { + // HACK -- link to immport/studyFinder.view + Module immport = ModuleLoader.getInstance().getModule("immport"); + Container project = ctx.getContainer().getProject(); + if (immport != null && project != null && project.getActiveModules().contains(immport)) + { + ActionURL finderURL = new ActionURL("immport", "dataFinderRedirect.view", project); + msg.append("  ").append(PageFlowUtil.button("Edit").href(finderURL.toString())); + } + msg.append(""); - // HACK -- link to immport/studyFinder.view - Module immport = ModuleLoader.getInstance().getModule("immport"); - Container project = ctx.getContainer().getProject(); - if (immport != null && project != null && project.getActiveModules().contains(immport)) - { - ActionURL finderURL = new ActionURL("immport", "dataFinderRedirect.view", project); - msg.append("  ").append(PageFlowUtil.button("Edit").href(finderURL.toString())); + headerMessage.append(msg); + } } - msg.append(""); - - headerMessage.append(msg); } } From 5a79742493f58b38d1cbb3f476e874307c50ce3a Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 14 Dec 2020 08:48:10 -0800 Subject: [PATCH 5/6] Issue 42062: Convert *Action to *Action to work around JDK-16 restriction (#1784) --- .../org/labkey/api/action/BaseViewAction.java | 25 ------------------- .../labkey/api/action/SimpleViewAction.java | 7 +----- .../org/labkey/api/view/FolderManagement.java | 4 +-- .../core/admin/sql/SqlScriptController.java | 4 +-- .../VisualizationController.java | 12 ++++----- 5 files changed, 11 insertions(+), 41 deletions(-) diff --git a/api/src/org/labkey/api/action/BaseViewAction.java b/api/src/org/labkey/api/action/BaseViewAction.java index 9d0cbeb5615..3e3b41f361c 100644 --- a/api/src/org/labkey/api/action/BaseViewAction.java +++ b/api/src/org/labkey/api/action/BaseViewAction.java @@ -63,12 +63,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -450,29 +448,6 @@ else if (!value.getClass().isArray()) return errors; } - protected Map _fixupPropertyMap(Map in) - { - Map out = new HashMap<>(in); - - /** see TableViewForm.setTypedValues() */ - for (Map.Entry entry : in.entrySet()) - { - String propName = entry.getKey(); - Object o = entry.getValue(); - - if (Character.isUpperCase(propName.charAt(0))) - { - out.remove(propName); - propName = Introspector.decapitalize(propName); - out.put(propName,o); - } - } - - out.remove("container"); - out.remove("user"); - return out; - } - @Override public boolean supports(Class clazz) { diff --git a/api/src/org/labkey/api/action/SimpleViewAction.java b/api/src/org/labkey/api/action/SimpleViewAction.java index db3563b3b0a..1a0cb481ed5 100644 --- a/api/src/org/labkey/api/action/SimpleViewAction.java +++ b/api/src/org/labkey/api/action/SimpleViewAction.java @@ -27,9 +27,6 @@ import org.springframework.validation.Errors; import org.springframework.web.servlet.ModelAndView; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; - /** * Base class for actions that want to display a single page in response to a GET, including * form parameters. Not intended for actions that may separately receive a POST. @@ -81,8 +78,7 @@ public ModelAndView handleRequest() throws Exception return v; } - - private static void validateUnicodePropertyValues(PropertyValues pvs) throws ServletException + private static void validateUnicodePropertyValues(PropertyValues pvs) { for (PropertyValue pv : pvs.getPropertyValues()) { @@ -112,7 +108,6 @@ else if (value.getClass().isArray()) } } - @Override protected String getCommandClassMethodName() { diff --git a/api/src/org/labkey/api/view/FolderManagement.java b/api/src/org/labkey/api/view/FolderManagement.java index ea00074086d..c63fe11aa84 100644 --- a/api/src/org/labkey/api/view/FolderManagement.java +++ b/api/src/org/labkey/api/view/FolderManagement.java @@ -190,7 +190,7 @@ private static void validateContainer(TYPE type, Class implements ManagementAction + private static abstract class ManagementViewAction extends SimpleViewAction implements ManagementAction { @Override public ModelAndView handleRequest() throws Exception @@ -201,7 +201,7 @@ public ModelAndView handleRequest() throws Exception } @Override - public ModelAndView getView(Void form, BindException errors) throws Exception + public ModelAndView getView(Object form, BindException errors) throws Exception { return wrapViewInTabStrip(this, getType(), getTabView(), errors); } diff --git a/core/src/org/labkey/core/admin/sql/SqlScriptController.java b/core/src/org/labkey/core/admin/sql/SqlScriptController.java index 308497eddd9..26d0b5cdcfb 100644 --- a/core/src/org/labkey/core/admin/sql/SqlScriptController.java +++ b/core/src/org/labkey/core/admin/sql/SqlScriptController.java @@ -885,10 +885,10 @@ private void deleteScripts(File dir, List scripts) @RequiresPermission(AdminOperationsPermission.class) - public class OrphanedScriptsAction extends SimpleViewAction + public class OrphanedScriptsAction extends SimpleViewAction { @Override - public ModelAndView getView(Void form, BindException errors) throws IOException + public ModelAndView getView(Object form, BindException errors) throws IOException { Set orphanedScripts = new TreeSet<>(); Set unclaimedFiles = new TreeSet<>(); diff --git a/visualization/src/org/labkey/visualization/VisualizationController.java b/visualization/src/org/labkey/visualization/VisualizationController.java index e535634d24a..af4cb067c24 100644 --- a/visualization/src/org/labkey/visualization/VisualizationController.java +++ b/visualization/src/org/labkey/visualization/VisualizationController.java @@ -583,12 +583,12 @@ private ApiQueryResponse getApiResponse(ViewContext context, UserSchema schema, @RequiresSiteAdmin - public class TestGetDataAction extends SimpleViewAction + public class TestGetDataAction extends SimpleViewAction { @Override - public ModelAndView getView(Void noform, BindException errors) + public ModelAndView getView(Object noform, BindException errors) { - return new JspView("/org/labkey/visualization/test/test.jsp"); + return new JspView<>("/org/labkey/visualization/test/test.jsp"); } @Override @@ -675,12 +675,12 @@ private ApiQueryResponse getApiResponse(ViewContext context, UserSchema schema, @RequiresSiteAdmin - public class cdsTestGetDataAction extends SimpleViewAction + public class cdsTestGetDataAction extends SimpleViewAction { @Override - public ModelAndView getView(Void noform, BindException errors) + public ModelAndView getView(Object noform, BindException errors) { - return new JspView("/org/labkey/visualization/test/test.jsp"); + return new JspView<>("/org/labkey/visualization/test/test.jsp"); } @Override From 0caeab62b15f6f1f8ecaa457708902e7571c38da Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 14 Dec 2020 10:28:57 -0800 Subject: [PATCH 6/6] Support within cube elements; parse & stash them. Introduce simple Hierarchy interface and return it (instead of Pair) from getOlapHierarchies(). (#1766) --- api/src/org/labkey/api/query/QueryService.java | 14 ++++++++++---- .../src/org/labkey/query/QueryServiceImpl.java | 6 ++---- .../labkey/query/olap/rolap/RolapCubeDef.java | 17 ++++++++++++++++- .../labkey/query/olap/rolap/RolapReader.java | 3 +++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/api/src/org/labkey/api/query/QueryService.java b/api/src/org/labkey/api/query/QueryService.java index 37e2cd90a79..17885ddf68f 100644 --- a/api/src/org/labkey/api/query/QueryService.java +++ b/api/src/org/labkey/api/query/QueryService.java @@ -45,7 +45,6 @@ import org.labkey.api.query.snapshot.QuerySnapshotDefinition; import org.labkey.api.security.User; import org.labkey.api.services.ServiceRegistry; -import org.labkey.api.util.Pair; import org.labkey.api.util.Path; import org.labkey.api.view.ActionURL; import org.labkey.api.view.ViewContext; @@ -473,11 +472,18 @@ public String getVerbPastTense() String cubeDataChangedAndRewarmCube(User user, Set containers, String schemaName, String configId, String cubeName); List getRolapConfigIds(Container c); + interface Hierarchy + { + String getName(); + String getTableName(); + Map getAnnotations(); + } + /** - * Returns a minimal amount of information about the specified cube dimension's hierarchies - * @return A Collection of Pair objects containing each hierarchy's name and primary table + * Returns information about the specified cube dimension's hierarchies + * @return A Collection of Hierarchy objects containing basic information about each hierarchy */ - Collection> getOlapHierarchies(String configId, Container c, String cubeName, String dimension); + Collection getOlapHierarchies(String configId, Container c, String cubeName, String dimension); void saveNamedSet(String setName, List setList); void deleteNamedSet(String setName); diff --git a/query/src/org/labkey/query/QueryServiceImpl.java b/query/src/org/labkey/query/QueryServiceImpl.java index 168d4903bd5..0d2bfc5fbfd 100644 --- a/query/src/org/labkey/query/QueryServiceImpl.java +++ b/query/src/org/labkey/query/QueryServiceImpl.java @@ -3103,7 +3103,7 @@ public List getRolapConfigIds(Container c) } @Override - public Collection> getOlapHierarchies(String configId, Container c, String cubeName, String dimension) + public Collection getOlapHierarchies(String configId, Container c, String cubeName, String dimension) { OlapSchemaDescriptor descriptor = ServerManager.getDescriptor(c, configId); @@ -3120,9 +3120,7 @@ public Collection> getOlapHierarchies(String configId, Cont if (null == def) throw new IllegalArgumentException("Unable to find dimension " + dimension); - return def.getHierarchies().stream() - .map(h->Pair.of(h.getName(), h.getLevels().get(0).getTableName())) - .collect(Collectors.toList()); + return new ArrayList<>(def.getHierarchies()); } /* diff --git a/query/src/org/labkey/query/olap/rolap/RolapCubeDef.java b/query/src/org/labkey/query/olap/rolap/RolapCubeDef.java index 59e9182013a..398580fa08f 100644 --- a/query/src/org/labkey/query/olap/rolap/RolapCubeDef.java +++ b/query/src/org/labkey/query/olap/rolap/RolapCubeDef.java @@ -25,6 +25,7 @@ import org.labkey.api.data.dialect.SqlDialect; import org.labkey.api.query.AliasManager; import org.labkey.api.query.DefaultSchema; +import org.labkey.api.query.QueryService; import org.labkey.api.util.DateUtil; import org.labkey.api.util.Path; import org.labkey.query.olap.metadata.CachedCube; @@ -574,7 +575,7 @@ static String toSqlLiteral(JdbcType type, Object value) - static public class HierarchyDef + static public class HierarchyDef implements QueryService.Hierarchy { protected RolapCubeDef cube; protected DimensionDef dimension; @@ -586,7 +587,9 @@ static public class HierarchyDef protected JoinOrTable join; protected boolean hasAll; protected ArrayList levels = new ArrayList<>(); + protected final Map annotations = new TreeMap<>(); + @Override public String getName() { return name; @@ -670,6 +673,18 @@ public void addJoins(@Nullable Map factTableAliases, Set jo } joins.add(j); } + + @Override + public Map getAnnotations() + { + return annotations; + } + + @Override + public String getTableName() + { + return getLevels().get(0).getTableName(); + } } diff --git a/query/src/org/labkey/query/olap/rolap/RolapReader.java b/query/src/org/labkey/query/olap/rolap/RolapReader.java index 320e6dd2031..6b480bb66c2 100644 --- a/query/src/org/labkey/query/olap/rolap/RolapReader.java +++ b/query/src/org/labkey/query/olap/rolap/RolapReader.java @@ -303,6 +303,9 @@ private void parseHierarchy(Node hierNode) case "Join": _currentHier.join = parseJoinOrTable(node); break; + case "Annotations": + parseAnnotations(node, _currentHier.annotations); + break; } } RolapCubeDef.LevelDef lowest = _currentHier.levels.get(_currentHier.levels.size()-1);