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 @@ -16,6 +16,7 @@

package org.labkey.genotypeassays;

import org.apache.commons.text.StringEscapeUtils;
import org.json.JSONArray;
import org.labkey.api.action.ApiResponse;
import org.labkey.api.action.ApiSimpleResponse;
Expand All @@ -37,6 +38,7 @@
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -130,7 +132,8 @@ public ApiResponse execute(CacheAnalysesForm form, BindException errors)
return null;
}

Pair<List<Integer>, List<Integer>> ret = GenotypeAssaysManager.get().cacheAnalyses(getViewContext(), protocol, form.getAlleleNames());
String[] alleleNames = Arrays.stream(form.getAlleleNames()).map(StringEscapeUtils::unescapeHtml4).toArray(String[]::new);
Pair<List<Integer>, List<Integer>> ret = GenotypeAssaysManager.get().cacheAnalyses(getViewContext(), protocol, alleleNames);
resultProperties.put("runsCreated", ret.first);
resultProperties.put("runsDeleted", ret.second);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

public class GenotypeAssaysManager
{
Expand Down Expand Up @@ -121,13 +122,15 @@ public Pair<List<Integer>, List<Integer>> cacheAnalyses(final ViewContext ctx, f
final Map<Integer, List<Map<String, Object>>> rowHash = new HashMap<>();
final Map<Integer, Set<Integer>> toDeleteByAnalysis = new HashMap<>();

AtomicInteger records = new AtomicInteger();
TableSelector tsAlignments = new TableSelector(tableAlignments, cols.values(), new SimpleFilter(FieldKey.fromString("key"), Arrays.asList(pks), CompareType.IN), null);
tsAlignments.forEach(new Selector.ForEachBlock<ResultSet>()
{
@Override
public void exec(ResultSet object) throws SQLException
{
Results rs = new ResultsImpl(object, cols);
records.getAndIncrement();

int analysisId = rs.getInt(FieldKey.fromString("analysis_id"));
String lineages = rs.getString(FieldKey.fromString("lineages"));
Expand Down Expand Up @@ -167,6 +170,11 @@ public void exec(ResultSet object) throws SQLException
}
});

if (records.get() != pks.length)
{
throw new IllegalStateException("The number of records found did not match the number supplied. This indicates a problem with the import.");
}

if (!rowHash.isEmpty())
{
processSet(SBT_LINEAGE_ASSAY_TYPE, rowHash, assayDataTable, u, ctx, toDeleteByAnalysis, ap, protocol, runsCreated);
Expand Down