-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTargetedMSUpgradeCode.java
More file actions
111 lines (100 loc) · 4.46 KB
/
TargetedMSUpgradeCode.java
File metadata and controls
111 lines (100 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright (c) 2013-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.targetedms;
import org.apache.logging.log4j.Logger;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.DeferredUpgrade;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.SqlExecutor;
import org.labkey.api.data.UpgradeCode;
import org.labkey.api.module.Module;
import org.labkey.api.module.ModuleContext;
import org.labkey.api.module.ModuleLoader;
import org.labkey.api.security.User;
import org.labkey.api.targetedms.TargetedMSService;
import org.labkey.api.util.logging.LogHelper;
import org.labkey.targetedms.query.QCAnnotationTypeTable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* User: jeckels
* Date: 5/13/13
*/
public class TargetedMSUpgradeCode implements UpgradeCode
{
private static final Logger LOG = LogHelper.getLogger(TargetedMSUpgradeCode.class, "TargetedMS schema upgrade operations");
// called at every bootstrap to initialize annotation types
@SuppressWarnings({"UnusedDeclaration"})
public void populateDefaultAnnotationTypes(final ModuleContext moduleContext)
{
if (ModuleLoader.getInstance().shouldInsertData())
{
insertAnnotationType("Instrumentation Change", "FF0000", moduleContext.getUpgradeUser());
insertAnnotationType("Reagent Change", "00FF00", moduleContext.getUpgradeUser());
insertAnnotationType("Technician Change", "0000FF", moduleContext.getUpgradeUser());
insertAnnotationType(QCAnnotationTypeTable.INSTRUMENT_DOWNTIME, "CCCC00", moduleContext.getUpgradeUser());
// Enable the module in the /Shared container so that it can be resolved
Set<Module> activeModules = new HashSet<>(ContainerManager.getSharedContainer().getActiveModules());
activeModules.add(ModuleLoader.getInstance().getModule(TargetedMSModule.class));
ContainerManager.getSharedContainer().setActiveModules(activeModules);
}
}
private void insertAnnotationType(String name, String color, User user)
{
SQLFragment sql = new SQLFragment("INSERT INTO ");
sql.append(TargetedMSManager.getTableInfoQCAnnotationType());
sql.append(" (Container, Created, Modified, CreatedBy, ModifiedBy, Name, Color) VALUES (?, ?, ?, ?, ?, ?, ?)");
sql.add(ContainerManager.getSharedContainer());
Date now = new Date();
sql.add(now);
sql.add(now);
sql.add(user.getUserId());
sql.add(user.getUserId());
sql.add(name);
sql.add(color);
new SqlExecutor(TargetedMSManager.getSchema()).execute(sql);
}
/** Populate PTMPercentsGroupedPrepivotCache for all runs in existing ExperimentMAM folders */
@SuppressWarnings("UnusedDeclaration")
@DeferredUpgrade
public void populatePTMPercentsGroupedPrepivotCache(final ModuleContext moduleContext)
{
if (moduleContext.isNewInstall())
{
return;
}
User user = moduleContext.getUpgradeUser();
LOG.info("Populating PTMPercentsGroupedPrepivotCache for existing ExperimentMAM folders");
for (TargetedMSRun run : TargetedMSManager.getAllNonDeletedRuns())
{
Container container = run.getContainer();
if (container != null && TargetedMSManager.getFolderType(container) == TargetedMSService.FolderType.ExperimentMAM)
{
try
{
TargetedMSManager.populatePTMPercentsGroupedPrepivotCache(run, user, container);
}
catch (Exception e)
{
LOG.error("Error populating PTMPercentsGroupedPrepivotCache for run " + run.getId() + " in " + container.getPath(), e);
}
}
}
LOG.info("Finished populating PTMPercentsGroupedPrepivotCache for existing ExperimentMAM folders");
}
}