Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to allow external server to trigger re-import of genetics data #782

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions GeneticsCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {

dependencies {
BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: ":server:modules:LabDevKitModules:LDK", depProjectConfig: "apiJarFile")
BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: ":server:modules:ehrModules:ehr", depProjectConfig: "apiJarFile")

BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:ehrModules:ehr", depProjectConfig: 'published', depExtension: 'module')
BuildUtils.addLabKeyDependency(project: project, config: "modules", depProjectPath: ":server:modules:LabDevKitModules:LDK", depProjectConfig: 'published', depExtension: 'module')
BuildUtils.addLabKeyDependency(project: project, config: "implementation", depProjectPath: ":server:modules:dataintegration", depProjectConfig: "apiJarFile")
Expand Down
14 changes: 14 additions & 0 deletions GeneticsCore/resources/etls/KinshipDataImport.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<etl xmlns="http://labkey.org/etl/xml">
<name>KinshipDataImport</name>
<description>Import PRIMe-seq Kinship Data</description>
<transforms>
<transform id="kinship" type="TaskRefTransformStep">
<taskref ref="org.labkey.GeneticsCore.etl.ImportGeneticsCalculationsStep">
<settings>

</settings>
</taskref>
</transform>
</transforms>
</etl>
7 changes: 7 additions & 0 deletions GeneticsCore/resources/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
</editPermissions>
<description>This is the containerPath to the folder holding the primary data for Parentage. Use of slashes is very important - it should be in the format '/myProject/folder'</description>
</propertyDescriptor>
<propertyDescriptor name="KinshipDataPath">
<canSetPerContainer>true</canSetPerContainer>
<editPermissions>
<permission>ADMIN</permission>
</editPermissions>
<description>This is the filepath of a folder where externally kinship/inbreeding TSVs calculated externally will be deposited. It is used by the KinshipData ETL to initiate import.</description>
</propertyDescriptor>
</properties>
<clientDependencies>
<dependency path="clientapi/ext4.lib.xml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.labkey.GeneticsCore.mhc.MhcTaskRef;
import org.labkey.api.action.ApiResponse;
import org.labkey.api.action.ApiSimpleResponse;
import org.labkey.api.action.ConfirmAction;
import org.labkey.api.action.MutatingApiAction;
import org.labkey.api.action.SpringActionController;
import org.labkey.api.di.DataIntegrationService;
import org.labkey.api.security.RequiresPermission;
import org.labkey.api.security.permissions.AdminPermission;
import org.labkey.api.security.permissions.UpdatePermission;
import org.labkey.api.util.HtmlString;
import org.labkey.api.util.URLHelper;
import org.labkey.api.view.HtmlView;
Expand Down Expand Up @@ -62,4 +67,26 @@ public URLHelper getSuccessURL(Object o)
return getContainer().getStartURL(getUser());
}
}


@RequiresPermission(UpdatePermission.class)
public static class ImportGeneticsDataAction extends MutatingApiAction<Object>
{
@Override
public ApiResponse execute(Object form, BindException errors)
{
try
{
DataIntegrationService.get().runTransformNow(getContainer(), getUser(), "{GeneticsCore}/KinshipDataImport");

return new ApiSimpleResponse("success", true);
}
catch (Exception e)
{
_log.error("Unable to initiate genetics data import", e);
errors.reject(ERROR_MSG, "Unable to initiate genetics data import");
return null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.labkey.GeneticsCore.etl;

import org.apache.commons.lang3.StringUtils;
import org.apache.xmlbeans.XmlException;
import org.jetbrains.annotations.NotNull;
import org.labkey.GeneticsCore.GeneticsCoreModule;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerManager;
import org.labkey.api.di.TaskRefTask;
import org.labkey.api.ehr.EHRService;
import org.labkey.api.module.Module;
import org.labkey.api.module.ModuleLoader;
import org.labkey.api.module.ModuleProperty;
import org.labkey.api.pipeline.PipelineJob;
import org.labkey.api.pipeline.PipelineJobException;
import org.labkey.api.pipeline.RecordedActionSet;
import org.labkey.api.security.permissions.UpdatePermission;
import org.labkey.api.view.UnauthorizedException;
import org.labkey.api.writer.ContainerUser;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ImportGeneticsCalculationsStep implements TaskRefTask
{
protected ContainerUser _containerUser;

@Override
public RecordedActionSet run(@NotNull PipelineJob job) throws PipelineJobException
{
Module ehr = ModuleLoader.getInstance().getModule("ehr");
Module geneticsCore = ModuleLoader.getInstance().getModule(GeneticsCoreModule.class);

ModuleProperty mp = ehr.getModuleProperties().get("EHRStudyContainer");
String ehrContainerPath = StringUtils.trimToNull(mp.getEffectiveValue(_containerUser.getContainer()));
if (ehrContainerPath == null)
{
throw new PipelineJobException("EHRStudyContainer has not been set");
}

Container ehrContainer = ContainerManager.getForPath(ehrContainerPath);
if (ehrContainer == null)
{
throw new PipelineJobException("Invalid container: " + ehrContainerPath);
}

if (!_containerUser.getContainer().equals(ehrContainer))
{
throw new PipelineJobException("This ETL can only be run from the EHRStudyContainer");
}

// Downstream import events will get additional permissions checks
if (!ehrContainer.hasPermission(_containerUser.getUser(), UpdatePermission.class))
{
throw new UnauthorizedException();
}

ModuleProperty mp2 = geneticsCore.getModuleProperties().get("KinshipDataPath");
String pipeDirPath = StringUtils.trimToNull(mp2.getEffectiveValue(ehrContainer));
if (pipeDirPath == null)
{
throw new PipelineJobException("Must provide the filepath to import data using the KinshipDataPath module property");
}

File pipeDir = new File(pipeDirPath);
if (!pipeDir.exists())
{
throw new PipelineJobException("Path does not exist: " + pipeDir.getPath());
}

File kinship = new File(pipeDir, "kinship.txt");
if (!kinship.exists())
{
throw new PipelineJobException("File does not exist: " + kinship.getPath());
}

File inbreeding = new File(pipeDir, "inbreeding.txt");
if (!inbreeding.exists())
{
throw new PipelineJobException("File does not exist: " + inbreeding.getPath());
}

EHRService.get().standaloneProcessKinshipAndInbreeding(ehrContainer, _containerUser.getUser(), pipeDir, job.getLogger());

return new RecordedActionSet();
}

@Override
public List<String> getRequiredSettings()
{
return Collections.emptyList();
}

@Override
public void setSettings(Map<String, String> settings) throws XmlException
{

}

@Override
public void setContainerUser(ContainerUser containerUser)
{
_containerUser = containerUser;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,9 @@ private void updateTotalVolume(Integer quantity)

private void addProjectToTheRow(Ext4GridRef gridRef, int index, String project)
{
gridRef.clickDownArrowOnGrid(index, "project");
gridRef.startEditing(index, "project");
Ext4FieldRef fieldRef = gridRef.getActiveEditor(index, "project");
fieldRef.eval("expand()");
waitAndClick(Locator.tag("li").append(Locator.tagContainingText("span", "Other")));
waitForElement(Ext4Helper.Locators.window("Choose Project"));
_ext4Helper.queryOne("window[title=Choose Project] [fieldLabel='Project']", Ext4ComboRef.class).setComboByDisplayValue(project);
Expand Down