Skip to content

Commit

Permalink
Merge pull request #448 from mcneilco/release/2023.3.x
Browse files Browse the repository at this point in the history
⬆️ Upmerge release/2023.3.x to release/2023.4.x
  • Loading branch information
brianbolt authored Aug 17, 2023
2 parents ced5d7b + fbc74c1 commit 4bfe150
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.labsynch.labseer.dto.TsvLoaderResponseDTO;
import com.labsynch.labseer.exceptions.ErrorMessage;
import com.labsynch.labseer.exceptions.NotFoundException;
import com.labsynch.labseer.exceptions.TooManyResultsException;
import com.labsynch.labseer.exceptions.UniqueNameException;
import com.labsynch.labseer.service.AnalysisGroupService;
import com.labsynch.labseer.service.AnalysisGroupValueService;
Expand Down Expand Up @@ -1634,20 +1635,19 @@ public ResponseEntity<java.lang.String> jsonFindExperimentByNameGet(@RequestPara
@RequestMapping(value = "/protocol/{codeName}", method = RequestMethod.GET, headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<java.lang.String> jsonFindExperimentsByProtocolCodeName(
@PathVariable("codeName") String codeName, @RequestParam(value = "with", required = false) String with) {
@PathVariable("codeName") String codeName, @RequestParam(value = "projects", required = false) List<String> projects, @RequestParam(value = "with", required = false) String with) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
List<Protocol> protocols = Protocol.findProtocolsByCodeNameEqualsAndIgnoredNot(codeName, true).getResultList();
if (protocols.size() == 1) {
try {
Collection<Experiment> experiments = experimentService.findExperimentsByProtocolCodeName(codeName, projects);
return new ResponseEntity<String>(
Experiment.toJsonArrayStub(Experiment.findExperimentsByProtocol(protocols.get(0)).getResultList()),
Experiment.toJsonArrayStub(experiments),
headers, HttpStatus.OK);
} else if (protocols.size() > 1) {
logger.error("ERROR: multiple protocols found with the same code name");
return new ResponseEntity<String>("[ ]", headers, HttpStatus.CONFLICT);
} else {
logger.warn("WARN: no protocols found with the query code name");
} catch (NoResultException e) {
return new ResponseEntity<String>("[ ]", headers, HttpStatus.NOT_FOUND);

} catch (TooManyResultsException e) {
return new ResponseEntity<String>("[ ]", headers, HttpStatus.CONFLICT);
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/labsynch/labseer/domain/SaltForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Order;
import javax.validation.constraints.Size;

import com.labsynch.labseer.dto.SearchFormDTO;
Expand Down Expand Up @@ -239,6 +241,7 @@ public static TypedQuery<SaltForm> findSaltFormsByMeta(SearchFormDTO searchParam

Predicate[] predicates = new Predicate[0];
List<Predicate> predicateList = new ArrayList<Predicate>();
List<Order> orderList = new ArrayList<Order>();

if (searchParams.getChemist() != null && !searchParams.getChemist().equals("anyone")) {
logger.debug("incoming chemist :" + searchParams.getChemist().toString());
Expand Down Expand Up @@ -282,12 +285,34 @@ public static TypedQuery<SaltForm> findSaltFormsByMeta(SearchFormDTO searchParam
List<String> corpNames = searchParams.getFormattedCorpNameList();
logger.debug("incoming corpNameList :" + corpNames.toString());
ArrayList<Predicate> corpNameLikePredicates = new ArrayList<Predicate>();
Expression<Double> maxSimilarity = null;
for (String corpName : corpNames) {
Predicate predicate = criteriaBuilder.like(saltFormParent.get("corpName"), '%' + corpName);
corpNameLikePredicates.add(predicate);
// Using pg_trgm.similarity to order results based on how similar the value is to
// the formatted corporate names.
Expression<Double> similarity = criteriaBuilder.function(
"similarity",
Double.class,
saltFormParent.get("corpName"),
criteriaBuilder.literal(corpName)
);
if (maxSimilarity == null) {
maxSimilarity = similarity;
}
else {
maxSimilarity = criteriaBuilder.selectCase()
.when(criteriaBuilder.greaterThan(similarity, maxSimilarity), similarity)
.otherwise(maxSimilarity)
.as(Double.class);
}
}
Predicate predicate = criteriaBuilder.or(corpNameLikePredicates.toArray(new Predicate[0]));
predicateList.add(predicate);
if (maxSimilarity != null) {
// Rows with a higher similarity will be ordered first.
orderList.add(criteriaBuilder.desc(maxSimilarity));
}
}
if (searchParams.getAlias() != null && !searchParams.getAlias().equals("")) {
Predicate predicate = null;
Expand Down Expand Up @@ -335,6 +360,7 @@ public static TypedQuery<SaltForm> findSaltFormsByMeta(SearchFormDTO searchParam

predicates = predicateList.toArray(predicates);
criteria.where(criteriaBuilder.and(predicates));
criteria.orderBy(orderList);
TypedQuery<SaltForm> q = em.createQuery(criteria);

if (searchParams.getMaxSynthDate() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class SearchFormReturnDTO {

private Collection<SearchCompoundReturnDTO> foundCompounds = new HashSet<SearchCompoundReturnDTO>();
private Collection<SearchCompoundReturnDTO> foundCompounds = new ArrayList<SearchCompoundReturnDTO>();

private boolean lotsWithheld;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public Collection<JSTreeNodeDTO> getExperimentNodesByProtocolTree(
public Collection<Experiment> findExperimentsByMetadataJson(
List<StringCollectionDTO> metaDataList);


public Collection<Experiment> findExperimentsByProtocolCodeName(String query, List<String> projects)
throws TooManyResultsException;

public Collection<Experiment> findExperimentsByGenericMetaDataSearch(String query, String userName, Boolean includeDeleted)
throws TooManyResultsException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,45 @@ public Collection<Experiment> findExperimentsByGenericMetaDataSearch(String quer

}

public Collection<Experiment> findExperimentsByProtocolCodeName(String codeName, List<String> projects)
throws TooManyResultsException, NoResultException {
List<Protocol> protocols = Protocol.findProtocolsByCodeNameEqualsAndIgnoredNot(codeName, true).getResultList();

if (protocols.size() > 1) {
logger.error("ERROR: multiple protocols found with the same code name");
throw new TooManyResultsException("ERROR: multiple protocols found with the same code name");
} else if (protocols.size() < 1) {
logger.warn("WARN: no protocols found with the query code name");
throw new NoResultException("WARN: no protocols found with the query code name");
}

Collection<Experiment> rawResults = Experiment.findExperimentsByProtocol(protocols.get(0)).getResultList();
if (propertiesUtilService.getRestrictExperiments()) {
projects.add("unassigned");
Collection<Experiment> results = new HashSet<Experiment>();
for (Experiment rawResult : rawResults) {
String experimentProject = null;
for (ExperimentState state : rawResult.getLsStates()) {
if (!state.isIgnored() && !state.isDeleted()) {
for (ExperimentValue value : state.getLsValues()) {
if (value.getLsKind().equals("project") && !value.getDeleted() && !value.getIgnored()) {
experimentProject = value.getCodeValue();
break;
}
}
}
}
if (projects.contains(experimentProject)) {
results.add(rawResult);
}
}
return results;
} else {
return rawResults;
}

}

@Override
public Collection<Experiment> findExperimentsByGenericMetaDataSearch(String queryString, List<String> projects, Boolean includeDeleted)
throws TooManyResultsException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ public SearchFormReturnDTO findQuerySaltForms(SearchFormDTO searchParams) throws

private SearchFormReturnDTO filterSearchResultsByProject(SearchFormReturnDTO searchResults, List<String> projects) {
if (!searchResults.getFoundCompounds().isEmpty()) {
Collection<SearchCompoundReturnDTO> filteredFoundCompounds = new HashSet<SearchCompoundReturnDTO>();
Collection<SearchCompoundReturnDTO> filteredFoundCompounds = new ArrayList<SearchCompoundReturnDTO>();
for (SearchCompoundReturnDTO foundCompound : searchResults.getFoundCompounds()) {
List<SearchLotDTO> filteredFoundLots = new ArrayList<SearchLotDTO>();
for (SearchLotDTO foundLot : foundCompound.getLotIDs()) {
Expand Down

0 comments on commit 4bfe150

Please sign in to comment.