Skip to content
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
80 changes: 37 additions & 43 deletions ehr/src/org/labkey/ehr/EHRManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,21 +488,20 @@ public List<String> ensureDatasetPropertyDescriptors(Container c, User u, boolea

List<? extends Dataset> datasets = study.getDatasets();

// Hack - adding a shared EHR property to a domain ends up reparenting it to the EHR folder. They
// need to keep living in the /Shared project. Rather than introducing a brand new API for adding a shared
// PD to an existing domain, we'll directly update the owning container afterwards
Set<PropertyDescriptor> pdsToReparentInShared = new HashSet<>();

for (Dataset dataset : datasets)
{
Domain domain = dataset.getDomain();
List<? extends DomainProperty> dprops = domain.getProperties();
if (dprops == null)
{
_log.error("domain.getProperties() was null for: " + domain.getName());
continue;
}

boolean changed = false;
List<PropertyDescriptor> toUpdate = new ArrayList<>();

List<PropertyDescriptor> props = new ArrayList<>();
props.addAll(properties);
List<PropertyDescriptor> props = new ArrayList<>(properties);
if (dataset.getCategory() != null && dataset.getCategory().equals("ClinPath") && !dataset.getName().equalsIgnoreCase("Clinpath Runs"))
{
String propertyURI = EHRProperties.RUNID.getPropertyDescriptor().getPropertyURI();
Expand Down Expand Up @@ -555,11 +554,6 @@ public List<String> ensureDatasetPropertyDescriptors(Container c, User u, boolea
}
}

// if (!pd.getContainer().equals(dp.getContainer()) && !pd.getProject().equals(ContainerManager.getSharedContainer()))
// {
// messages.add("Containers do not match for: " + dp.getName() + ". Expected: " + dp.getContainer().getPath() + ", but was: " + pd.getContainer().getPath() + ".");
// }

if (!dp.getName().equals(pd.getName()))
{
messages.add("Case mismatch for property in dataset: " + dataset.getName() + ". Expected: " + pd.getName() + ", but was: " + dp.getName() + ". This has not been automatically changed");
Expand All @@ -576,6 +570,7 @@ public List<String> ensureDatasetPropertyDescriptors(Container c, User u, boolea
d.setPropertyURI(pd.getPropertyURI());
d.setRangeURI(pd.getRangeURI());
d.setName(pd.getName());
pdsToReparentInShared.add(pd);
changed = true;
}
}
Expand Down Expand Up @@ -611,19 +606,27 @@ public List<String> ensureDatasetPropertyDescriptors(Container c, User u, boolea
}
}

if (commitChanges)
{
for (PropertyDescriptor sharedPD : pdsToReparentInShared)
{
sharedPD.setContainer(ContainerManager.getSharedContainer());
sharedPD.setProject(ContainerManager.getSharedContainer());
OntologyManager.updatePropertyDescriptor(sharedPD);
}
}

//ensure keymanagement type
if (commitChanges)
{
DbSchema studySchema = DbSchema.get("study");
SQLFragment sql = new SQLFragment("UPDATE study.dataset SET keymanagementtype=?, keypropertyname=? WHERE demographicdata=? AND container=?", "GUID", "objectid", false, c.getEntityId());
long total = new SqlExecutor(studySchema).execute(sql);
long total = new SqlExecutor(StudyService.get().getDatasetSchema()).execute(sql);
messages.add("Non-demographics datasets updated to use objectId as a managed key: "+ total);
}
else
{
DbSchema studySchema = DbSchema.get("study");
SQLFragment sql = new SQLFragment("SELECT * FROM study.dataset WHERE keymanagementtype!=? AND demographicdata=? AND container=?", "GUID", false, c.getEntityId());
long total = new SqlExecutor(studySchema).execute(sql);
long total = new SqlExecutor(StudyService.get().getDatasetSchema()).execute(sql);
if (total > 0)
messages.add("Non-demographics datasets that are not using objectId as a managed key: " + total);
}
Expand Down Expand Up @@ -1127,8 +1130,7 @@ private void rebuildIndex(String table, String indexName)
//NOTE: this assumes the property already exists
private void updatePropertyURI(Domain d, PropertyDescriptor pd) throws SQLException
{
DbSchema expSchema = DbSchema.get(ExpSchema.SCHEMA_NAME);
TableInfo propertyDomain = expSchema.getTable("propertydomain");
DbSchema expSchema = ExperimentService.get().getSchema();
TableInfo propertyDescriptor = expSchema.getTable("propertydescriptor");

//find propertyId
Expand Down Expand Up @@ -1279,47 +1281,39 @@ public int discardTask(Container c, User u, String taskId) throws SQLException
@Override
public void exec(Map<String, Object> map)
{
Map<String, Object> row = new CaseInsensitiveHashMap<>();
row.putAll(map);
Map<String, Object> row = new CaseInsensitiveHashMap<>();
row.putAll(map);

if (row.containsKey("requestid") && row.get("requestid") != null)
{
row.put("requestid", null);
row.put("qcstate", null);
row.put("taskid", null);
row.put("qcstateLabel", "Request: Approved");
if (row.containsKey("requestid") && row.get("requestid") != null)
{
row.put("requestid", null);
row.put("qcstate", null);
row.put("taskid", null);
row.put("qcstateLabel", "Request: Approved");

requestsToQueue.add(row);
}
else
{
keysToDelete.add(row);
}
requestsToQueue.add(row);
}
else
{
keysToDelete.add(row);
}
}
});

try
{
if (!keysToDelete.isEmpty())
{
ti.getUpdateService().deleteRows(u, c, keysToDelete, null, new HashMap<String, Object>());
ti.getUpdateService().deleteRows(u, c, keysToDelete, null, new HashMap<>());
}


if (!requestsToQueue.isEmpty())
{
ti.getUpdateService().updateRows(u, c, requestsToQueue, requestsToQueue, null, new HashMap<String, Object>());
ti.getUpdateService().updateRows(u, c, requestsToQueue, requestsToQueue, null, new HashMap<>());
}
}
catch (InvalidKeyException e)
{
throw new RuntimeException(e);
}
catch (QueryUpdateServiceException e)
{
throw new RuntimeException(e);
}
catch (BatchValidationException e)
catch (InvalidKeyException | QueryUpdateServiceException | BatchValidationException e)
{
throw new RuntimeException(e);
}
Expand Down