Skip to content

Commit ccbf4c8

Browse files
committed
Add auditing of what method was used for data imports, updates, deletes
1 parent 2efd0f1 commit ccbf4c8

2 files changed

Lines changed: 486 additions & 485 deletions

File tree

Lines changed: 136 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,136 @@
1-
/*
2-
* Copyright (c) 2012-2018 LabKey Corporation
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.labkey.luminex;
17-
18-
import org.jetbrains.annotations.NotNull;
19-
import org.jetbrains.annotations.Nullable;
20-
import org.labkey.api.data.Container;
21-
import org.labkey.api.exp.ExperimentException;
22-
import org.labkey.api.exp.ObjectProperty;
23-
import org.labkey.api.exp.OntologyManager;
24-
import org.labkey.api.exp.OntologyObject;
25-
import org.labkey.api.exp.api.ExpData;
26-
import org.labkey.api.exp.api.ExpExperiment;
27-
import org.labkey.api.exp.api.ExpRun;
28-
import org.labkey.api.exp.api.ExperimentService;
29-
import org.labkey.api.exp.property.DomainProperty;
30-
import org.labkey.api.query.BatchValidationException;
31-
import org.labkey.api.query.ValidationException;
32-
import org.labkey.api.security.permissions.DeletePermission;
33-
import org.labkey.api.assay.AssayRunUploadContext;
34-
import org.labkey.api.assay.DefaultAssayRunCreator;
35-
import org.labkey.luminex.model.Analyte;
36-
37-
import java.util.List;
38-
import java.util.Map;
39-
40-
/**
41-
* Saves analyte specific properties and handles re-run
42-
* User: jeckels
43-
* Date: Feb 13, 2012
44-
*/
45-
public class LuminexRunCreator extends DefaultAssayRunCreator<LuminexAssayProvider>
46-
{
47-
/** Lock object to only allow one thread to be running a Luminex transform script and importing its results at a time, issue 17424 */
48-
public static final Object LOCK_OBJECT = new Object();
49-
50-
public LuminexRunCreator(LuminexAssayProvider provider)
51-
{
52-
super(provider);
53-
}
54-
55-
@Override
56-
public ExpExperiment saveExperimentRun(AssayRunUploadContext<LuminexAssayProvider> uploadContext, @Nullable ExpExperiment batch, @NotNull ExpRun run, boolean forceSaveBatchProps) throws ExperimentException, ValidationException
57-
{
58-
// Only allow one thread to be running a Luminex transform script and importing its results at a time
59-
// See issue 17424
60-
synchronized (LOCK_OBJECT)
61-
{
62-
LuminexRunContext context = (LuminexRunContext)uploadContext;
63-
batch = super.saveExperimentRun(context, batch, run, forceSaveBatchProps);
64-
Container container = context.getContainer();
65-
66-
// Save the analyte properties
67-
List<ExpData> outputs = run.getDataOutputs();
68-
for (ExpData output : outputs)
69-
{
70-
var dataId = output.getRowId();
71-
72-
for (Analyte analyte : LuminexManager.get().getAnalytes(dataId))
73-
{
74-
Map<DomainProperty, String> properties = context.getAnalyteProperties(analyte.getName());
75-
76-
ObjectProperty[] objProperties = new ObjectProperty[properties.size()];
77-
int i = 0;
78-
for (Map.Entry<DomainProperty, String> entry : properties.entrySet())
79-
{
80-
ObjectProperty property = new ObjectProperty(analyte.getLsid(),
81-
container, entry.getKey().getPropertyURI(),
82-
entry.getValue(), entry.getKey().getPropertyDescriptor().getPropertyType());
83-
objProperties[i++] = property;
84-
}
85-
removeExistingAnalyteProperties(container, analyte);
86-
OntologyManager.insertProperties(container, analyte.getLsid(), objProperties);
87-
}
88-
}
89-
}
90-
91-
try
92-
{
93-
handleReRun(uploadContext, run);
94-
}
95-
catch (BatchValidationException e)
96-
{
97-
throw new ExperimentException(e);
98-
}
99-
return batch;
100-
}
101-
102-
private void handleReRun(AssayRunUploadContext<LuminexAssayProvider> uploadContext, ExpRun run) throws ValidationException, BatchValidationException
103-
{
104-
if (uploadContext.getReRunId() != null)
105-
{
106-
ExpRun replacedRun = ExperimentService.get().getExpRun(uploadContext.getReRunId().intValue());
107-
108-
if (replacedRun != null)
109-
{
110-
// Migrate the original Created and CreatedBy values from the old run to the new run
111-
run.setCreated(replacedRun.getCreated());
112-
run.setCreatedBy(replacedRun.getCreatedBy());
113-
run.save(uploadContext.getUser());
114-
115-
if (uploadContext instanceof LuminexRunContext && ((LuminexRunContext)uploadContext).getRetainExclusions())
116-
LuminexManager.get().retainExclusions((LuminexRunContext)uploadContext, replacedRun, run);
117-
118-
// Delete the old run, which has been replaced
119-
if (replacedRun.getContainer().hasPermission(uploadContext.getUser(), DeletePermission.class))
120-
{
121-
replacedRun.delete(uploadContext.getUser());
122-
}
123-
}
124-
}
125-
}
126-
127-
private void removeExistingAnalyteProperties(Container container, Analyte analyte)
128-
{
129-
OntologyObject analyteObject = OntologyManager.getOntologyObject(container, analyte.getLsid());
130-
if (analyteObject != null)
131-
{
132-
OntologyManager.deleteProperties(container, analyteObject.getObjectId());
133-
}
134-
}
135-
}
1+
/*
2+
* Copyright (c) 2012-2018 LabKey Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.labkey.luminex;
17+
18+
import org.jetbrains.annotations.NotNull;
19+
import org.jetbrains.annotations.Nullable;
20+
import org.labkey.api.audit.TransactionAuditProvider;
21+
import org.labkey.api.data.Container;
22+
import org.labkey.api.exp.ExperimentException;
23+
import org.labkey.api.exp.ObjectProperty;
24+
import org.labkey.api.exp.OntologyManager;
25+
import org.labkey.api.exp.OntologyObject;
26+
import org.labkey.api.exp.api.ExpData;
27+
import org.labkey.api.exp.api.ExpExperiment;
28+
import org.labkey.api.exp.api.ExpRun;
29+
import org.labkey.api.exp.api.ExperimentService;
30+
import org.labkey.api.exp.property.DomainProperty;
31+
import org.labkey.api.query.BatchValidationException;
32+
import org.labkey.api.query.ValidationException;
33+
import org.labkey.api.security.permissions.DeletePermission;
34+
import org.labkey.api.assay.AssayRunUploadContext;
35+
import org.labkey.api.assay.DefaultAssayRunCreator;
36+
import org.labkey.luminex.model.Analyte;
37+
38+
import java.util.List;
39+
import java.util.Map;
40+
41+
/**
42+
* Saves analyte specific properties and handles re-run
43+
* User: jeckels
44+
* Date: Feb 13, 2012
45+
*/
46+
public class LuminexRunCreator extends DefaultAssayRunCreator<LuminexAssayProvider>
47+
{
48+
/** Lock object to only allow one thread to be running a Luminex transform script and importing its results at a time, issue 17424 */
49+
public static final Object LOCK_OBJECT = new Object();
50+
51+
public LuminexRunCreator(LuminexAssayProvider provider)
52+
{
53+
super(provider);
54+
}
55+
56+
@Override
57+
public ExpExperiment saveExperimentRun(AssayRunUploadContext<LuminexAssayProvider> uploadContext, @Nullable ExpExperiment batch, @NotNull ExpRun run, boolean forceSaveBatchProps, @Nullable Map<TransactionAuditProvider.TransactionDetail, Object> transactionDetails) throws ExperimentException, ValidationException
58+
{
59+
// Only allow one thread to be running a Luminex transform script and importing its results at a time
60+
// See issue 17424
61+
synchronized (LOCK_OBJECT)
62+
{
63+
LuminexRunContext context = (LuminexRunContext)uploadContext;
64+
batch = super.saveExperimentRun(context, batch, run, forceSaveBatchProps, transactionDetails);
65+
Container container = context.getContainer();
66+
67+
// Save the analyte properties
68+
List<ExpData> outputs = run.getDataOutputs();
69+
for (ExpData output : outputs)
70+
{
71+
var dataId = output.getRowId();
72+
73+
for (Analyte analyte : LuminexManager.get().getAnalytes(dataId))
74+
{
75+
Map<DomainProperty, String> properties = context.getAnalyteProperties(analyte.getName());
76+
77+
ObjectProperty[] objProperties = new ObjectProperty[properties.size()];
78+
int i = 0;
79+
for (Map.Entry<DomainProperty, String> entry : properties.entrySet())
80+
{
81+
ObjectProperty property = new ObjectProperty(analyte.getLsid(),
82+
container, entry.getKey().getPropertyURI(),
83+
entry.getValue(), entry.getKey().getPropertyDescriptor().getPropertyType());
84+
objProperties[i++] = property;
85+
}
86+
removeExistingAnalyteProperties(container, analyte);
87+
OntologyManager.insertProperties(container, analyte.getLsid(), objProperties);
88+
}
89+
}
90+
}
91+
92+
try
93+
{
94+
handleReRun(uploadContext, run);
95+
}
96+
catch (BatchValidationException e)
97+
{
98+
throw new ExperimentException(e);
99+
}
100+
return batch;
101+
}
102+
103+
private void handleReRun(AssayRunUploadContext<LuminexAssayProvider> uploadContext, ExpRun run) throws ValidationException, BatchValidationException
104+
{
105+
if (uploadContext.getReRunId() != null)
106+
{
107+
ExpRun replacedRun = ExperimentService.get().getExpRun(uploadContext.getReRunId().intValue());
108+
109+
if (replacedRun != null)
110+
{
111+
// Migrate the original Created and CreatedBy values from the old run to the new run
112+
run.setCreated(replacedRun.getCreated());
113+
run.setCreatedBy(replacedRun.getCreatedBy());
114+
run.save(uploadContext.getUser());
115+
116+
if (uploadContext instanceof LuminexRunContext && ((LuminexRunContext)uploadContext).getRetainExclusions())
117+
LuminexManager.get().retainExclusions((LuminexRunContext)uploadContext, replacedRun, run);
118+
119+
// Delete the old run, which has been replaced
120+
if (replacedRun.getContainer().hasPermission(uploadContext.getUser(), DeletePermission.class))
121+
{
122+
replacedRun.delete(uploadContext.getUser());
123+
}
124+
}
125+
}
126+
}
127+
128+
private void removeExistingAnalyteProperties(Container container, Analyte analyte)
129+
{
130+
OntologyObject analyteObject = OntologyManager.getOntologyObject(container, analyte.getLsid());
131+
if (analyteObject != null)
132+
{
133+
OntologyManager.deleteProperties(container, analyteObject.getObjectId());
134+
}
135+
}
136+
}

0 commit comments

Comments
 (0)