Commit b4d52b1d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fix on issue #38

search for multiple drugs returned from time to time more results than
queried
parent 163f6789
......@@ -6,3 +6,4 @@ map_images/
*/target/
web/src/main/webapp/svnversion.txt
*.war
/target/
......@@ -30,6 +30,7 @@ import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.statistics.SearchType;
import lcsb.mapviewer.services.interfaces.ISearchHistoryService;
import lcsb.mapviewer.services.search.db.DbSearchCriteria;
import lcsb.mapviewer.services.view.AnnotationView;
/**
* Implementation of the service that allows access information about drugs.
......@@ -85,14 +86,25 @@ public class DrugService implements IDrugService {
@Override
public List<DrugView> getByNames(List<String> names, DbSearchCriteria searchCriteria) {
List<DrugView> result = new ArrayList<DrugView>();
List<DrugView> result = new ArrayList<>();
Set<String> processedDrugIds = new HashSet<>();
int oldSet = searchCriteria.getColorSet();
for (String string : names) {
searchCriteria.colorSet(searchCriteria.getColorSet() + 1);
DrugView drug = getByName(string, searchCriteria);
if (drug != null) {
result.add(drug);
boolean isNewDrug = false;
for (AnnotationView id : drug.getDrugLinks()) {
if (!processedDrugIds.contains(id.toString())) {
isNewDrug = true;
}
processedDrugIds.add(id.toString());
}
if (isNewDrug) {
result.add(drug);
}
}
}
searchCriteria.colorSet(oldSet);
......
......@@ -66,27 +66,31 @@ public class DrugView extends AbstractView<Drug> implements Serializable, ISearc
* List of links to extenral databases.
*/
private List<AnnotationView> drugLinks = new ArrayList<>();
/**
* List of targets for the drug.
*/
private List<TargetView> targetRows = new ArrayList<>();
private List<TargetView> targetRows = new ArrayList<>();
/**
* Description of the drug.
*/
private String description;
/**
* Status of blood brain barries for the drug.
*/
private String bloodBrainBarrier = "N/A";
/**
* Known brand names.
*/
private List<String> brandNames = new ArrayList<String>();
private List<String> brandNames = new ArrayList<>();
/**
* Known synonyms.
*/
private List<String> synonyms = new ArrayList<String>();
private List<String> synonyms = new ArrayList<>();
/**
* Constructor that initialize the data with information from the parameter
......
......@@ -184,13 +184,9 @@ public class DrugBean extends AbstractMarkerManagerBean<DrugView> implements Ser
// drugs are comma separated
List<String> names = splitQuery(query, true);
int set = 0;
for (String string : names) {
DrugView drug = drugService.getByName(string, new DbSearchCriteria().ipAddress(ipAddress).model(model).organisms(mapBean.getOrganism()).colorSet(set++));
if (drug != null) {
addResult(drug);
}
}
List<DrugView> drugs = drugService
.getByNames(names, new DbSearchCriteria().ipAddress(ipAddress).model(model).organisms(mapBean.getOrganism()).colorSet(0));
addResults(drugs);
// format results
if (getResults().size() == 0) { // if there are no results, add empty drug
......
package lcsb.mapviewer.bean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.Serializable;
......@@ -96,4 +97,15 @@ public class DrugBeanTest extends WebTestFunctions {
}
}
@Test
public void testFindDrug() throws Exception {
try {
drugBean.findDrug("levadopa; carbidopa");
assertEquals(2, drugBean.getResults().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment