Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.labkey.vfs.FileLike;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.LineNumberReader;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -152,8 +151,8 @@ public RecordedActionSet run() throws PipelineJobException
PipelineJob job = getJob();
FileAnalysisJobSupport support = (FileAnalysisJobSupport) job;

processInbreeding(job.getContainer(), job.getUser(), support.getAnalysisDirectoryFileLike(), job.getLogger());
processKinship(job.getContainer(), job.getUser(), support.getAnalysisDirectoryFileLike(), job.getLogger(), job);
processInbreeding(job.getContainer(), job.getUser(), support.getAnalysisDirectory(), job.getLogger());
processKinship(job.getContainer(), job.getUser(), support.getAnalysisDirectory(), job.getLogger(), job);

if (GeneticCalculationsJob.isKinshipValidation())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.labkey.api.util.FileType;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.writer.PrintWriters;
import org.labkey.vfs.FileLike;
import org.springframework.jdbc.BadSqlGrammarException;

import java.io.File;
Expand Down Expand Up @@ -135,9 +136,9 @@ public RecordedActionSet run() throws PipelineJobException
}
TableSelector ts = new TableSelector(pedTable, PageFlowUtil.set("Id", "Dam", "Sire", "Gender", "Species"), null, new Sort("Species, Id"));

File outputFile = new File(support.getAnalysisDirectory(), GeneticCalculationsImportTask.PEDIGREE_FILE);
FileLike outputFile = support.getAnalysisDirectory().resolveChild(GeneticCalculationsImportTask.PEDIGREE_FILE);

try (CSVWriter writer = new CSVWriter(PrintWriters.getPrintWriter(outputFile), '\t', CSVWriter.DEFAULT_QUOTE_CHARACTER))
try (CSVWriter writer = new CSVWriter(PrintWriters.getPrintWriter(outputFile.openOutputStream()), '\t', CSVWriter.DEFAULT_QUOTE_CHARACTER))
{
long count = ts.getRowCount();
if (count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.labkey.api.resource.Resource;
import org.labkey.api.util.FileType;
import org.labkey.ehr.EHRModule;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -120,7 +121,7 @@ public RecordedAction runScript(String scriptName, String outputFileName, String
String exePath = getRPath();

String scriptPath = getScriptPath(scriptName);
File tsvFile = new File(support.getAnalysisDirectory(), GeneticCalculationsImportTask.PEDIGREE_FILE);
FileLike tsvFile = support.getAnalysisDirectory().resolveChild(GeneticCalculationsImportTask.PEDIGREE_FILE);
if (!tsvFile.exists())
throw new PipelineJobException("Unable to find TSV file at location: " + tsvFile.getPath());

Expand All @@ -132,13 +133,13 @@ public RecordedAction runScript(String scriptName, String outputFileName, String
args.add("--no-restore"); // don't restore saved objects
args.add(scriptPath);
args.add("-f");
args.add(tsvFile.getPath());
args.add(tsvFile.toNioPathForRead().toFile().getPath());

getJob().getLogger().info("Using working directory of: " + support.getAnalysisDirectory().getPath());
ProcessBuilder pb = new ProcessBuilder(args);
job.runSubProcess(pb, support.getAnalysisDirectory());

File output = new File(support.getAnalysisDirectory(), outputFileName);
FileLike output = support.getAnalysisDirectory().resolveChild(outputFileName);
if (!output.exists())
throw new PipelineJobException("Unable to find file: " + output.getPath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public interface BillingPipelineJobSupport

String getName();

File getAnalysisDir();

/*
* Returns Pair of previous matching billing run's objectId and rowId
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.labkey.api.security.permissions.ReadPermission;
import org.labkey.api.security.permissions.UpdatePermission;
import org.labkey.api.util.GUID;
import org.labkey.api.util.HtmlString;
import org.labkey.api.util.HtmlStringBuilder;
import org.labkey.api.util.Pair;
import org.labkey.api.util.URLHelper;
import org.labkey.api.view.ActionURL;
Expand All @@ -57,11 +59,12 @@
import org.labkey.api.view.WebPartView;
import org.labkey.ehr_billing.pipeline.BillingPipelineForm;
import org.labkey.ehr_billing.pipeline.BillingPipelineJob;
import org.labkey.vfs.FileLike;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -113,12 +116,12 @@ public ApiResponse execute(BillingPipelineForm form, BindException errors)
}

PipeRoot pipelineRoot = PipelineService.get().findPipelineRoot(getContainer());
File analysisDir = BillingPipelineJob.createAnalysisDir(pipelineRoot, form.getProtocolName());
FileLike analysisDir = BillingPipelineJob.createAnalysisDir(pipelineRoot, form.getProtocolName());
PipelineService.get().queueJob(new BillingPipelineJob(getContainer(), getUser(), getViewContext().getActionURL(), pipelineRoot, analysisDir, form));

resultProperties.put("success", true);
}
catch (PipelineValidationException | PipelineJobException e)
catch (PipelineValidationException | PipelineJobException | IOException e)
{
errors.reject(ERROR_MSG, e.getMessage());
return null;
Expand Down Expand Up @@ -146,15 +149,16 @@ public ModelAndView getConfirmView(QueryForm form, BindException errors) throws
{
Set<String> ids = DataRegionSelection.getSelected(form.getViewContext(), true);

StringBuilder msg = new StringBuilder("You have selected " + ids.size() + " billing runs to delete. This will also delete: <p>");
for (String m : EHR_BillingManager.get().deleteBillingRuns(getUser(),getContainer(), ids, true))
HtmlStringBuilder msg = HtmlStringBuilder.of("You have selected ").append(ids.size()).append(" billing runs to delete. This will also delete: ");
msg.startTag("p");
for (HtmlString m : EHR_BillingManager.get().deleteBillingRuns(getUser(),getContainer(), ids, true))
{
msg.append(m).append("<br>");
msg.append(m).append(msg.startTag("br"));
}

msg.append("<p>Are you sure you want to do this?");
msg.startTag("p").append("Are you sure you want to do this?");

return new HtmlView(msg.toString());
return new HtmlView(msg.getHtmlString());
}

@Override
Expand Down
11 changes: 6 additions & 5 deletions ehr_billing/src/org/labkey/ehr_billing/EHR_BillingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.labkey.api.query.QueryUpdateServiceException;
import org.labkey.api.security.User;
import org.labkey.api.data.RuntimeSQLException;
import org.labkey.api.util.HtmlString;

import java.sql.SQLException;
import java.util.ArrayList;
Expand All @@ -60,7 +61,7 @@ public static EHR_BillingManager get()
return _instance;
}

public List<String> deleteBillingRuns(User user, Container container, Collection<String> pks, boolean testOnly) throws QueryUpdateServiceException, BatchValidationException, InvalidKeyException
public List<HtmlString> deleteBillingRuns(User user, Container container, Collection<String> pks, boolean testOnly) throws QueryUpdateServiceException, BatchValidationException, InvalidKeyException
{
TableInfo invoice = EHR_BillingSchema.getInstance().getSchema().getTable(EHR_BillingSchema.TABLE_INVOICE);
TableInfo invoiceRuns = QueryService.get().getUserSchema(user, container,EHR_BillingSchema.NAME).getTable(EHR_BillingSchema.TABLE_INVOICE_RUNS);
Expand All @@ -75,17 +76,17 @@ public List<String> deleteBillingRuns(User user, Container container, Collection
SimpleFilter miscChargesFilter = new SimpleFilter(FieldKey.fromString("invoiceId"), pks, CompareType.IN);

//perform the work
List<String> ret = new ArrayList<>();
List<HtmlString> ret = new ArrayList<>();
if (testOnly)
{
TableSelector tsInvItems = new TableSelector(invoicedItems, invoiceIdFilter, null);
ret.add(tsInvItems.getRowCount() + " records from invoiced items");
ret.add(HtmlString.of(tsInvItems.getRowCount() + " records from invoiced items"));

TableSelector tsInvoice = new TableSelector(invoice, invoiceRunIdFilter, null);
ret.add(tsInvoice.getRowCount() + " records from invoice");
ret.add(HtmlString.of(tsInvoice.getRowCount() + " records from invoice"));

TableSelector tsMiscCharges2 = new TableSelector(miscCharges, miscChargesFilter, null);
ret.add(tsMiscCharges2.getRowCount() + " invoice records from misc charges will be removed from the deleted invoice, which means they will be picked up by the next billing period. They are not deleted.");
ret.add(HtmlString.of(tsMiscCharges2.getRowCount() + " invoice records from misc charges will be removed from the deleted invoice, which means they will be picked up by the next billing period. They are not deleted."));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.labkey.api.util.Pair;
import org.labkey.api.view.ActionURL;
import org.labkey.api.view.ViewBackgroundInfo;
import org.labkey.vfs.FileLike;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;

Expand All @@ -41,31 +43,29 @@
*/
public class BillingPipelineJob extends PipelineJob implements BillingPipelineJobSupport
{
private File _analysisDir;
private BillingPipelineForm _form;

// For serialization
protected BillingPipelineJob() {}

public BillingPipelineJob(Container c, User user, ActionURL url, PipeRoot pipeRoot, File analysisDir, BillingPipelineForm form)
public BillingPipelineJob(Container c, User user, ActionURL url, PipeRoot pipeRoot, FileLike analysisDir, BillingPipelineForm form)
{
super(null, new ViewBackgroundInfo(c, user, url), pipeRoot);

_analysisDir = analysisDir;
setLogFile(new File(analysisDir, FileUtil.makeFileNameWithTimestamp("billingPipeline", "log")));
setLogFile(analysisDir.resolveChild(FileUtil.makeFileNameWithTimestamp("billingPipeline", "log")));
_form = form;
}

public static File createAnalysisDir(PipeRoot pipeRoot, String name)
public static FileLike createAnalysisDir(PipeRoot pipeRoot, String name) throws IOException
{
String trialName = FileUtil.makeLegalName(name);
File analysisDir = new File(pipeRoot.getRootPath(), trialName);
FileLike analysisDir = pipeRoot.getRootFileLike().resolveChild(trialName);
int suffix = 0;
while (analysisDir.exists())
{
suffix++;
trialName = FileUtil.makeLegalName(name) + "." + suffix;
analysisDir = new File(pipeRoot.getRootPath(), trialName);
analysisDir = pipeRoot.getRootFileLike().resolveChild(trialName);
}

analysisDir.mkdirs();
Expand All @@ -86,7 +86,7 @@ public ActionURL getStatusHref()
}

@Override
public TaskPipeline getTaskPipeline()
public TaskPipeline<?> getTaskPipeline()
{
return PipelineJobService.get().getTaskPipeline(new TaskId(BillingPipelineJob.class));
}
Expand Down Expand Up @@ -115,12 +115,6 @@ public String getName()
return _form.getProtocolName();
}

@Override
public File getAnalysisDir()
{
return _analysisDir;
}

@Override
public Pair<String,String> getPreviousInvoice()
{
Expand Down