|
| 1 | +package org.labkey.signaldata; |
| 2 | + |
| 3 | +import org.apache.logging.log4j.Logger; |
| 4 | +import org.labkey.api.assay.AssayProvider; |
| 5 | +import org.labkey.api.assay.AssayService; |
| 6 | +import org.labkey.api.data.Container; |
| 7 | +import org.labkey.api.data.ContainerManager; |
| 8 | +import org.labkey.api.data.UpgradeCode; |
| 9 | +import org.labkey.api.exp.api.ExpProtocol; |
| 10 | +import org.labkey.api.exp.api.ExperimentService; |
| 11 | +import org.labkey.api.exp.property.Domain; |
| 12 | +import org.labkey.api.exp.property.DomainProperty; |
| 13 | +import org.labkey.api.module.Module; |
| 14 | +import org.labkey.api.module.ModuleContext; |
| 15 | +import org.labkey.api.module.ModuleLoader; |
| 16 | +import org.labkey.api.security.User; |
| 17 | +import org.labkey.api.util.logging.LogHelper; |
| 18 | + |
| 19 | +public class SignalDataUpgradeCode implements UpgradeCode |
| 20 | +{ |
| 21 | + private static final Logger LOG = LogHelper.getLogger(SignalDataUpgradeCode.class, "SignalData upgrade code"); |
| 22 | + |
| 23 | + /** |
| 24 | + * Called from signaldata-25.000-25.001.sql |
| 25 | + * Updates SignalData assay protocols to make the result domain DataFile field not required. |
| 26 | + */ |
| 27 | + @SuppressWarnings({"UnusedDeclaration"}) |
| 28 | + public static void updateDataFileField(ModuleContext ctx) throws Exception |
| 29 | + { |
| 30 | + Module module = ModuleLoader.getInstance().getModule(SignalDataModule.NAME); |
| 31 | + if (module != null) |
| 32 | + { |
| 33 | + for (Container c : ContainerManager.getAllChildrenWithModule(ContainerManager.getRoot(), module)) |
| 34 | + { |
| 35 | + for (ExpProtocol protocol : ExperimentService.get().getExpProtocols(c)) |
| 36 | + { |
| 37 | + AssayProvider provider = AssayService.get().getProvider(protocol); |
| 38 | + if (provider != null && provider.getName().equalsIgnoreCase("Signal Data")) |
| 39 | + { |
| 40 | + Domain domain = provider.getResultsDomain(protocol, true); |
| 41 | + DomainProperty dataFile = domain.getPropertyByName("DataFile"); |
| 42 | + if (dataFile != null && dataFile.isRequired()) |
| 43 | + { |
| 44 | + LOG.info(String.format("Updating Signal Data assay in folder '%s'", c.getPath())); |
| 45 | + dataFile.setRequired(false); |
| 46 | + domain.save(User.getAdminServiceUser()); |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments