From b8dc95d6629802297cfd42746fce5febf7768e46 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 16 Jan 2018 12:53:37 +0100
Subject: [PATCH] unnecessary method getByNames removed

---
 .../services/search/db/IDbSearchService.java  |  12 -
 .../search/db/chemical/ChemicalService.java   | 476 +++++++++---------
 .../services/search/db/drug/DrugService.java  |  30 +-
 .../search/db/mirna/MiRNAService.java         | 366 +++++++-------
 .../db/chemical/ChemicalServiceTest.java      |  32 --
 .../search/db/mirna/MiRNAServiceTest.java     |  87 ++--
 6 files changed, 428 insertions(+), 575 deletions(-)

diff --git a/service/src/main/java/lcsb/mapviewer/services/search/db/IDbSearchService.java b/service/src/main/java/lcsb/mapviewer/services/search/db/IDbSearchService.java
index bfacf6371b..b3630c46ab 100644
--- a/service/src/main/java/lcsb/mapviewer/services/search/db/IDbSearchService.java
+++ b/service/src/main/java/lcsb/mapviewer/services/search/db/IDbSearchService.java
@@ -18,18 +18,6 @@ import lcsb.mapviewer.model.map.species.Element;
  */
 public interface IDbSearchService<T> {
 
-	/**
-	 * Returns list of objects found by list of names.
-	 * 
-	 * @param names
-	 *          list of object names
-	 * @param searchCriteria
-	 *          set of {@link DbSearchCriteria} used for searching (like:
-	 *          {@link lcsb.mapviewer.model.map.model.Model Model})
-	 * @return list of objects for given list of names
-	 */
-	List<T> getByNames(List<String> names, DbSearchCriteria searchCriteria);
-
 	/**
 	 * Returns the drugs found by drug name.
 	 * 
diff --git a/service/src/main/java/lcsb/mapviewer/services/search/db/chemical/ChemicalService.java b/service/src/main/java/lcsb/mapviewer/services/search/db/chemical/ChemicalService.java
index 94eaaef9c4..6ff3510b5a 100644
--- a/service/src/main/java/lcsb/mapviewer/services/search/db/chemical/ChemicalService.java
+++ b/service/src/main/java/lcsb/mapviewer/services/search/db/chemical/ChemicalService.java
@@ -31,8 +31,6 @@ import lcsb.mapviewer.model.map.species.Element;
 import lcsb.mapviewer.model.map.species.Gene;
 import lcsb.mapviewer.model.map.species.Protein;
 import lcsb.mapviewer.model.map.species.Rna;
-import lcsb.mapviewer.model.map.statistics.SearchType;
-import lcsb.mapviewer.services.interfaces.ISearchHistoryService;
 import lcsb.mapviewer.services.search.db.DbSearchCriteria;
 import lcsb.mapviewer.services.search.db.DbSearchService;
 
@@ -45,272 +43,252 @@ import lcsb.mapviewer.services.search.db.DbSearchService;
 @Transactional(value = "txManager")
 public class ChemicalService extends DbSearchService implements IChemicalService {
 
-	/**
-	 * Default class logger.
-	 */
-	private Logger																	 logger		= Logger.getLogger(ChemicalService.class);
+  /**
+   * Default class logger.
+   */
+  private Logger logger = Logger.getLogger(ChemicalService.class);
 
-	/**
-	 * List of chemicals pairs of id and name.
-	 */
-	private Map<MiriamData, Map<MiriamData, String>> diseases	= new HashMap<>();
+  /**
+   * List of chemicals pairs of id and name.
+   */
+  private Map<MiriamData, Map<MiriamData, String>> diseases = new HashMap<>();
 
-	/**
-	 * Access point and parser for the online ctd database.
-	 */
-	@Autowired
-	private ChemicalParser													 chemicalParser;
+  /**
+   * Access point and parser for the online ctd database.
+   */
+  @Autowired
+  private ChemicalParser chemicalParser;
 
-	/**
-	 * Object used to perform operations on {@link MiriamType#HGNC} annotations.
-	 */
-	@Autowired
-	private HgncAnnotator														 hgncAnnotator;
+  /**
+   * Object used to perform operations on {@link MiriamType#HGNC} annotations.
+   */
+  @Autowired
+  private HgncAnnotator hgncAnnotator;
 
-	/**
-	 * Service that manages search history.
-	 */
-	@Autowired
-	private ISearchHistoryService										 searchHistoryService;
+  /**
+   * Default constructor.
+   */
+  public ChemicalService() {
+    super();
+  }
 
-	/**
-	 * Default constructor.
-	 */
-	public ChemicalService() {
-		super();
-	}
+  /**
+   * Returns list of {@link Chemical chemicals} for a given disease and list of
+   * names.
+   * 
+   * @param diseaseID
+   *          {@link MiriamData} identifying disease; it should be a
+   *          {@link MiriamType#MESH_2012} identifier
+   * @param names
+   *          list of drug names that we are looking for
+   * @return list of {@link Chemical chemicals} that were found
+   */
+  protected List<Chemical> getChemicalByName(MiriamData diseaseID, List<String> names) {
+    if (diseaseID == null || names == null) {
+      throw new InvalidArgumentException("diseaseID cannot be null");
+    }
+    names.removeAll(Collections.singleton(null));
 
-	@Override
-	public List<Chemical> getByNames(List<String> names, DbSearchCriteria criteria) {
-		if (names == null) {
-			return null;
-		}
+    // Create a map with the each search string and chemical id.
+    // Remove empty string and special characters.
+    Map<String, MiriamData> searchNamesMap = new LinkedHashMap<String, MiriamData>();
+    for (int i = 0; i < names.size(); i++) {
+      String name = names.get(i).trim().toLowerCase().replaceAll("[^\\w]", "");
+      if (!name.isEmpty()) {
+        searchNamesMap.put(name, null);
+      }
+    }
+    try {
 
-		if (criteria.getIpAddress() != null && criteria.getModel() != null) {
-			searchHistoryService.addQuery(names.toString(), SearchType.CHEMICAL, criteria.getIpAddress(), criteria.getModel().getProject().getProjectId());
-		}
+      // Search id, name Map for matching records
+      List<MiriamData> ids = new ArrayList<MiriamData>();
+      Iterator<Entry<MiriamData, String>> idNameEnteries = getChemicalsByDisease(diseaseID).entrySet().iterator();
+      int namesFound = 0;
+      while (idNameEnteries.hasNext() && namesFound < searchNamesMap.size()) {
+        Map.Entry<MiriamData, String> pair = idNameEnteries.next();
+        String chemicalName = pair.getValue();
+        if (chemicalName != null) {
+          chemicalName = chemicalName.toLowerCase().replaceAll("[^\\w]", "");
+          for (Map.Entry<String, MiriamData> nameEntry : searchNamesMap.entrySet()) {
+            if (nameEntry.getKey().equals(chemicalName)) {
+              nameEntry.setValue(pair.getKey());
+              namesFound++;
 
-		List<Chemical> chemicals = getChemicalByName(criteria.getDisease(), names);
+            }
+          }
 
-		return chemicals;
-	}
+        }
+      }
 
-	/**
-	 * Returns list of {@link Chemical chemicals} for a given disease and list of
-	 * names.
-	 * 
-	 * @param diseaseID
-	 *          {@link MiriamData} identifing disease; it should be a
-	 *          {@link MiriamType#MESH_2012} identifier
-	 * @param names
-	 *          list of drug names that we are looking for
-	 * @return list of {@link Chemical chemicals} that were found
-	 */
-	protected List<Chemical> getChemicalByName(MiriamData diseaseID, List<String> names) {
-		if (diseaseID == null || names == null) {
-			throw new InvalidArgumentException("diseaseID cannot be null");
-		}
-		names.removeAll(Collections.singleton(null));
+      // Get what all values include null where no matching record is found,
+      // remove null and look in the database.
+      ids.addAll(searchNamesMap.values());
+      ids.removeAll(Collections.singleton(null));
+      List<Chemical> sortedResult = new ArrayList<Chemical>();
+      if (!ids.isEmpty()) {
+        List<Chemical> result = chemicalParser.getChemicals(diseaseID, ids);
 
-		// Create a map with the each search string and chemical id.
-		// Remove empty string and special characters.
-		Map<String, MiriamData> searchNamesMap = new LinkedHashMap<String, MiriamData>();
-		for (int i = 0; i < names.size(); i++) {
-			String name = names.get(i).trim().toLowerCase().replaceAll("[^\\w]", "");
-			if (!name.isEmpty()) {
-				searchNamesMap.put(name, null);
-			}
-		}
-		try {
+        // If the result is not empty and we found chemicals, try to sort as
+        // by the initial list provided.
+        Map<MiriamData, Chemical> resultAsMap = new HashMap<MiriamData, Chemical>();
+        if (result != null && !result.isEmpty()) {
+          for (Chemical chemo : result) {
+            resultAsMap.put(chemo.getChemicalId(), chemo);
+          }
 
-			// Search id, name Map for matching records
-			List<MiriamData> ids = new ArrayList<MiriamData>();
-			Iterator<Entry<MiriamData, String>> idNameEnteries = getChemicalsByDisease(diseaseID).entrySet().iterator();
-			int namesFound = 0;
-			while (idNameEnteries.hasNext() && namesFound < searchNamesMap.size()) {
-				Map.Entry<MiriamData, String> pair = idNameEnteries.next();
-				String chemicalName = pair.getValue();
-				if (chemicalName != null) {
-					chemicalName = chemicalName.toLowerCase().replaceAll("[^\\w]", "");
-					for (Map.Entry<String, MiriamData> nameEntry : searchNamesMap.entrySet()) {
-						if (nameEntry.getKey().equals(chemicalName)) {
-							nameEntry.setValue(pair.getKey());
-							namesFound++;
+          for (Map.Entry<String, MiriamData> nameEntry : searchNamesMap.entrySet()) {
+            if (nameEntry.getValue() != null) {
+              sortedResult.add(resultAsMap.get(nameEntry.getValue()));
+            }
+          }
+        }
+      }
 
-						}
-					}
+      return sortedResult;
+    } catch (ChemicalSearchException e) {
+      logger.error("Problem with accessing database", e);
+      return new ArrayList<Chemical>();
+    }
+  }
 
-				}
-			}
+  @Override
+  public Chemical getByName(String name, DbSearchCriteria searchCriteria) {
+    if (searchCriteria.getDisease() == null) {
+      throw new InvalidArgumentException("diseaseID cannot be null");
+    }
+    if (name == null || name.isEmpty()) {
+      return null;
+    }
+    MiriamData id = null;
+    List<Chemical> result = new ArrayList<Chemical>();
+    name = name.toLowerCase().replaceAll("[^\\w]", "");
+    try {
+      Iterator<Entry<MiriamData, String>> mapValues = getChemicalsByDisease(searchCriteria.getDisease()).entrySet()
+          .iterator();
+      int shortestName = Integer.MAX_VALUE;
+      while (mapValues.hasNext()) {
+        Map.Entry<MiriamData, String> pair = mapValues.next();
+        String chemicalName = pair.getValue();
+        if (chemicalName != null) {
+          chemicalName = chemicalName.toLowerCase().replaceAll("[^\\w]", "");
+          if (chemicalName.contains(name) && name.length() < shortestName) {
+            id = pair.getKey();
+            shortestName = chemicalName.length();
+          }
+        }
+      }
+      if (id != null) {
+        List<MiriamData> chemicalId = new ArrayList<>();
+        chemicalId.add(id);
+        result = chemicalParser.getChemicals(searchCriteria.getDisease(), chemicalId);
+      }
+    } catch (ChemicalSearchException e) {
+      logger.error("Problem with accesing database", e);
+    }
+    if (result.size() == 0) {
+      return null;
+    } else {
+      // return chemicalViewFactory.create(result.get(0),
+      // searchCriteria.getModel(), searchCriteria.getColorSet());
+      return result.get(0);
+    }
 
-			// Get what all values include null where no matching record is found,
-			// remove null and look in the database.
-			ids.addAll(searchNamesMap.values());
-			ids.removeAll(Collections.singleton(null));
-			List<Chemical> sortedResult = new ArrayList<Chemical>();
-			if (!ids.isEmpty()) {
-				List<Chemical> result = chemicalParser.getChemicals(diseaseID, ids);
+  }
 
-				// If the result is not empty and we found chemicals, try to sort as
-				// by the initial list provided.
-				Map<MiriamData, Chemical> resultAsMap = new HashMap<MiriamData, Chemical>();
-				if (result != null && !result.isEmpty()) {
-					for (Chemical chemo : result) {
-						resultAsMap.put(chemo.getChemicalId(), chemo);
-					}
+  @Override
+  public List<Chemical> getForTargets(Collection<Element> targets, DbSearchCriteria searchCriteria) {
+    List<Chemical> chemicalList = new ArrayList<>();
+    Set<MiriamData> targetsMiriam = new HashSet<MiriamData>();
+    for (Element alias : targets) {
+      if (alias instanceof Protein || alias instanceof Gene || alias instanceof Rna) {
+        boolean hgncFound = false;
+        for (MiriamData md : alias.getMiriamData()) {
+          if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
+            targetsMiriam.add(md);
+            hgncFound = true;
+          } else if (MiriamType.ENTREZ.equals(md.getDataType())) {
+            // ad also entrez in case of mouse, rat, etc
+            targetsMiriam.add(md);
+          }
 
-					for (Map.Entry<String, MiriamData> nameEntry : searchNamesMap.entrySet()) {
-						if (nameEntry.getValue() != null) {
-							sortedResult.add(resultAsMap.get(nameEntry.getValue()));
-						}
-					}
-				}
-			}
+        }
+        if (!hgncFound) {
+          MiriamData md = new MiriamData(MiriamType.HGNC_SYMBOL, alias.getName());
+          try {
+            if (hgncAnnotator.isValidHgncMiriam(md)) {
+              targetsMiriam.add(md);
+            }
+          } catch (AnnotatorException e) {
+            logger.error("Problem with accessing HGNC database", e);
+          }
+        }
+      }
+    }
+    try {
+      chemicalList = chemicalParser.getChemicalListByTarget(targetsMiriam, searchCriteria.getDisease());
+    } catch (ChemicalSearchException e) {
+      logger.error("Problem with accessing chemical database", e);
+    }
 
-			return sortedResult;
-		} catch (ChemicalSearchException e) {
-			logger.error("Problem with accessing database", e);
-			return new ArrayList<Chemical>();
-		}
-	}
+    Collections.sort(chemicalList, new Chemical.NameComparator());
+    return chemicalList;
+  }
 
-	@Override
-	public Chemical getByName(String name, DbSearchCriteria searchCriteria) {
-		if (searchCriteria.getDisease() == null) {
-			throw new InvalidArgumentException("diseaseID cannot be null");
-		}
-		if (name == null || name.isEmpty()) {
-			return null;
-		}
-		MiriamData id = null;
-		List<Chemical> result = new ArrayList<Chemical>();
-		name = name.toLowerCase().replaceAll("[^\\w]", "");
-		try {
-			Iterator<Entry<MiriamData, String>> mapValues = getChemicalsByDisease(searchCriteria.getDisease()).entrySet().iterator();
-			int shortestName = Integer.MAX_VALUE;
-			while (mapValues.hasNext()) {
-				Map.Entry<MiriamData, String> pair = mapValues.next();
-				String chemicalName = pair.getValue();
-				if (chemicalName != null) {
-					chemicalName = chemicalName.toLowerCase().replaceAll("[^\\w]", "");
-					if (chemicalName.contains(name) && name.length() < shortestName) {
-						id = pair.getKey();
-						shortestName = chemicalName.length();
-					}
-				}
-			}
-			if (id != null) {
-				List<MiriamData> chemicalId = new ArrayList<>();
-				chemicalId.add(id);
-				result = chemicalParser.getChemicals(searchCriteria.getDisease(), chemicalId);
-			}
-		} catch (ChemicalSearchException e) {
-			logger.error("Problem with accesing database", e);
-		}
-		if (result.size() == 0) {
-			return null;
-		} else {
-			// return chemicalViewFactory.create(result.get(0),
-			// searchCriteria.getModel(), searchCriteria.getColorSet());
-			return result.get(0);
-		}
+  /**
+   * @param disease
+   *          {@link MiriamType#MESH_2012 mesh term} describing disease
+   * 
+   * @return chemicals related to the disease
+   * @see #diseases
+   * @throws ChemicalSearchException
+   *           thrown when there is problem with accessing ctd database
+   */
+  private Map<MiriamData, String> getChemicalsByDisease(MiriamData disease) throws ChemicalSearchException {
+    if (diseases.get(disease) == null) {
+      diseases.put(disease, chemicalParser.getChemicalsForDisease(disease));
+    }
+    return diseases.get(disease);
+  }
 
-	}
-
-	@Override
-	public List<Chemical> getForTargets(Collection<Element> targets, DbSearchCriteria searchCriteria) {
-		List<Chemical> chemicalList = new ArrayList<>();
-		Set<MiriamData> targetsMiriam = new HashSet<MiriamData>();
-		for (Element alias : targets) {
-			if (alias instanceof Protein || alias instanceof Gene || alias instanceof Rna) {
-				boolean hgncFound = false;
-				for (MiriamData md : alias.getMiriamData()) {
-					if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
-						targetsMiriam.add(md);
-						hgncFound = true;
-					} else if (MiriamType.ENTREZ.equals(md.getDataType())) {
-						// ad also entrez in case of mouse, rat, etc
-						targetsMiriam.add(md);
-					}
-
-				}
-				if (!hgncFound) {
-					MiriamData md = new MiriamData(MiriamType.HGNC_SYMBOL, alias.getName());
-					try {
-						if (hgncAnnotator.isValidHgncMiriam(md)) {
-							targetsMiriam.add(md);
-						}
-					} catch (AnnotatorException e) {
-						logger.error("Problem with accessing HGNC database", e);
-					}
-				}
-			}
-		}
-		try {
-			chemicalList = chemicalParser.getChemicalListByTarget(targetsMiriam, searchCriteria.getDisease());
-		} catch (ChemicalSearchException e) {
-			logger.error("Problem with accessing chemical database", e);
-		}
-
-		Collections.sort(chemicalList, new Chemical.NameComparator());
-		return chemicalList;
-	}
-
-	/**
-	 * @param disease
-	 *          {@link MiriamType#MESH_2012 mesh term} describing disease
-	 * 
-	 * @return chemicals related to the disease
-	 * @see #diseases
-	 * @throws ChemicalSearchException
-	 *           thrown when there is problem with accessing ctd database
-	 */
-	private Map<MiriamData, String> getChemicalsByDisease(MiriamData disease) throws ChemicalSearchException {
-		if (diseases.get(disease) == null) {
-			diseases.put(disease, chemicalParser.getChemicalsForDisease(disease));
-		}
-		return diseases.get(disease);
-	}
-
-	@Override
-	public void cacheDataForModel(Model originalModel, IProgressUpdater iProgressUpdater) {
-		double progress = 0.0;
-		iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
-		MiriamData disease = originalModel.getProject().getDisease();
-		if (disease != null) {
-			logger.debug("Caching chemical queries...");
-			Set<MiriamData> targetMiriams = new HashSet<>();
-			List<Model> models = new ArrayList<>();
-			models.add(originalModel);
-			models.addAll(originalModel.getSubmodels());
-			for (Model model : models) {
-				for (BioEntity element : model.getBioEntities()) {
-					for (MiriamData md : element.getMiriamData()) {
-						if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
-							targetMiriams.add(md);
-						} else if (MiriamType.ENTREZ.equals(md.getDataType())) {
-							targetMiriams.add(md);
-						}
-					}
-				}
-			}
-			double counter = 0.0;
-			for (MiriamData md : targetMiriams) {
-				try {
-					List<Chemical> chemicalList = chemicalParser.getChemicalListByTarget(md, disease);
-					for (Chemical chemical : chemicalList) {
-						cacheMiriamData(chemical);
-					}
-				} catch (ChemicalSearchException | AnnotatorException e) {
-					logger.error("Problem with accessing info about chemical for target: " + md, e);
-				}
-				counter += 1;
-				progress = counter / (double) targetMiriams.size();
-				iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
-			}
-		} else {
-			logger.debug("Caching chemical queries not possible...");
-		}
-	}
+  @Override
+  public void cacheDataForModel(Model originalModel, IProgressUpdater iProgressUpdater) {
+    double progress = 0.0;
+    iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
+    MiriamData disease = originalModel.getProject().getDisease();
+    if (disease != null) {
+      logger.debug("Caching chemical queries...");
+      Set<MiriamData> targetMiriams = new HashSet<>();
+      List<Model> models = new ArrayList<>();
+      models.add(originalModel);
+      models.addAll(originalModel.getSubmodels());
+      for (Model model : models) {
+        for (BioEntity element : model.getBioEntities()) {
+          for (MiriamData md : element.getMiriamData()) {
+            if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
+              targetMiriams.add(md);
+            } else if (MiriamType.ENTREZ.equals(md.getDataType())) {
+              targetMiriams.add(md);
+            }
+          }
+        }
+      }
+      double counter = 0.0;
+      for (MiriamData md : targetMiriams) {
+        try {
+          List<Chemical> chemicalList = chemicalParser.getChemicalListByTarget(md, disease);
+          for (Chemical chemical : chemicalList) {
+            cacheMiriamData(chemical);
+          }
+        } catch (ChemicalSearchException | AnnotatorException e) {
+          logger.error("Problem with accessing info about chemical for target: " + md, e);
+        }
+        counter += 1;
+        progress = counter / (double) targetMiriams.size();
+        iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
+      }
+    } else {
+      logger.debug("Caching chemical queries not possible...");
+    }
+  }
 
 }
diff --git a/service/src/main/java/lcsb/mapviewer/services/search/db/drug/DrugService.java b/service/src/main/java/lcsb/mapviewer/services/search/db/drug/DrugService.java
index 275dd76631..c3217f0a99 100644
--- a/service/src/main/java/lcsb/mapviewer/services/search/db/drug/DrugService.java
+++ b/service/src/main/java/lcsb/mapviewer/services/search/db/drug/DrugService.java
@@ -72,36 +72,8 @@ public class DrugService extends DbSearchService implements IDrugService {
   @Autowired
   private ISearchHistoryService searchHistoryService;
 
-  @Override
-  public List<Drug> getByNames(List<String> names, DbSearchCriteria searchCriteria) {
-    List<Drug> result = new ArrayList<>();
-
-    Set<MiriamData> processedDrugIds = new HashSet<>();
-
-    int oldSet = searchCriteria.getColorSet();
-    for (String string : names) {
-      searchCriteria.colorSet(searchCriteria.getColorSet() + 1);
-      Drug drug = getByName(string, searchCriteria);
-      if (drug != null) {
-        boolean isNewDrug = false;
-        for (MiriamData id : drug.getSources()) {
-          if (!processedDrugIds.contains(id)) {
-            isNewDrug = true;
-          }
-          processedDrugIds.add(id);
-        }
-        if (isNewDrug) {
-          result.add(drug);
-        }
-      }
-    }
-    searchCriteria.colorSet(oldSet);
-
-    return result;
-  }
-
   /**
-   * Removes targets for unknown orginisms from the drug.
+   * Removes targets for unknown organisms from the drug.
    * 
    * @param drug
    *          drug from which we want to remove targets
diff --git a/service/src/main/java/lcsb/mapviewer/services/search/db/mirna/MiRNAService.java b/service/src/main/java/lcsb/mapviewer/services/search/db/mirna/MiRNAService.java
index a859f321b0..526459bdab 100644
--- a/service/src/main/java/lcsb/mapviewer/services/search/db/mirna/MiRNAService.java
+++ b/service/src/main/java/lcsb/mapviewer/services/search/db/mirna/MiRNAService.java
@@ -28,13 +28,11 @@ import lcsb.mapviewer.model.map.species.Element;
 import lcsb.mapviewer.model.map.species.Gene;
 import lcsb.mapviewer.model.map.species.Protein;
 import lcsb.mapviewer.model.map.species.Rna;
-import lcsb.mapviewer.model.map.statistics.SearchType;
-import lcsb.mapviewer.services.interfaces.ISearchHistoryService;
 import lcsb.mapviewer.services.search.db.DbSearchCriteria;
 import lcsb.mapviewer.services.search.db.DbSearchService;
 
 /**
- * Implementation of the service that allows access information about che.
+ * Implementation of the service that allows access information about miRNAs.
  * 
  * @author Ayan Rota
  * 
@@ -42,199 +40,173 @@ import lcsb.mapviewer.services.search.db.DbSearchService;
 @Transactional(value = "txManager")
 public class MiRNAService extends DbSearchService implements IMiRNAService {
 
-	/**
-	 * Default class logger.
-	 */
-	private Logger								logger = Logger.getLogger(MiRNAService.class);
-
-	/**
-	 * Access point and parser for the online ctd database.
-	 */
-	@Autowired
-	private MiRNAParser						miRNAParser;
-
-	/**
-	 * Object used to get information about {@link MiriamType#HGNC} annotations
-	 * and transformations.
-	 */
-	@Autowired
-	private HgncAnnotator					hgncAnnotator;
-
-	/**
-	 * Service that manages search history.
-	 */
-	@Autowired
-	private ISearchHistoryService	searchHistoryService;
-
-	/**
-	 * Default constructor.
-	 */
-	public MiRNAService() {
-		super();
-	}
-
-	/**
-	 * Init method called after intialization of spring bean.
-	 */
-	@PostConstruct
-	public void init() {
-	}
-
-	@Override
-	public List<MiRNA> getByNames(List<String> names, DbSearchCriteria criteria) {
-		if (names == null) {
-			return null;
-		}
-		if (criteria.getIpAddress() != null && criteria.getModel() != null) {
-			searchHistoryService.addQuery(names.toString(), SearchType.MI_RNA, criteria.getIpAddress(), criteria.getModel().getProject().getProjectId());
-		}
-		List<MiRNA> views = new ArrayList<>();
-		try {
-			List<MiRNA> miRNAs = miRNAParser.getMiRnasByNames(names);
-			for (MiRNA miRNA : miRNAs) {
-				views.add(miRNA);
-			}
-		} catch (MiRNASearchException e) {
-			logger.error("Problem with accessing mirna database", e);
-		}
-
-		return views;
-	}
-
-	@Override
-	public MiRNA getByName(String name, DbSearchCriteria searchCriteria) {
-		if ("".equals(name)) {
-			return null;
-		}
-		try {
-			List<String> names = new ArrayList<>();
-			names.add(name);
-			List<MiRNA> miRNAs = miRNAParser.getMiRnasByNames(names);
-                        if (miRNAs.size() > 0) {
-                            return miRNAs.get(0);
-                        }
-			return null;
-			// return miRNAViewFactory.create(miRNAs.get(0),
-			// searchCriteria.getModel(), searchCriteria.getColorSet());
-		} catch (MiRNASearchException e) {
-			logger.error("Problem with accessing mirna database", e);
-			return null;
-		}
-	}
-
-	@Override
-	public List<MiRNA> getForTargets(Collection<Element> targets, DbSearchCriteria searchCriteria) {
-		List<MiRNA> mirnaList = new ArrayList<MiRNA>();
-		Set<MiriamData> targetsMiriam = new HashSet<MiriamData>();
-		for (Element element : targets) {
-			if (element instanceof Protein || element instanceof Gene || element instanceof Rna) {
-				boolean hgncFound = false;
-				for (MiriamData md : element.getMiriamData()) {
-					if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
-						targetsMiriam.add(md);
-						hgncFound = true;
-					} else if (MiriamType.ENTREZ.equals(md.getDataType())) {
-						// ad also entrez in case of mouse, rat, etc
-						targetsMiriam.add(md);
-					}
-
-				}
-				if (!hgncFound) {
-					MiriamData md = new MiriamData(MiriamType.HGNC_SYMBOL, element.getName());
-					try {
-						if (hgncAnnotator.isValidHgncMiriam(md)) {
-							targetsMiriam.add(md);
-						}
-					} catch (AnnotatorException e) {
-						logger.error("Problem with accessing HGNC database", e);
-					}
-				}
-			}
-		}
-		try {
-			mirnaList = miRNAParser.getMiRnaListByTargets(targetsMiriam);
-		} catch (MiRNASearchException e) {
-			logger.error("Problem with accessing mirna database", e);
-		}
-
-		for (MiRNA drug : mirnaList) {
-			removeUnknownOrganisms(drug, searchCriteria.getOrganisms());
-		}
-
-		Collections.sort(mirnaList, new MiRNA.NameComparator());
-		return mirnaList;
-	}
-
-	/**
-	 * Removes targets for unknown organisms from the mirna.
-	 * 
-	 * @param drug
-	 *          drug from which we want to remove targets
-	 * @param organisms
-	 *          organisms that should be kept
-	 */
-	private void removeUnknownOrganisms(MiRNA drug, List<MiriamData> organisms) {
-		if (organisms.size() > 0) {
-			List<Target> toRemove = new ArrayList<Target>();
-			for (Target target : drug.getTargets()) {
-				boolean remove = true;
-				for (MiriamData organism : organisms) {
-					if (target.getOrganism() == null) {
-						remove = false;
-					} else if (target.getOrganism().equals(organism)) {
-						remove = false;
-					}
-				}
-				if (remove) {
-					logger.debug("Target " + target.getName() + " removed from list because results are limited to organisms: " + organisms);
-					toRemove.add(target);
-				}
-			}
-			drug.getTargets().removeAll(toRemove);
-		}
-	}
-
-	@Override
-	public void cacheDataForModel(Model originalModel, IProgressUpdater iProgressUpdater) {
-		logger.debug("Caching mirna queries...");
-		double progress = 0.0;
-		iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
-		Set<MiriamData> targetMiriams = new HashSet<>();
-		List<Model> models = new ArrayList<>();
-		models.add(originalModel);
-		models.addAll(originalModel.getSubmodels());
-		for (Model model : models) {
-			for (BioEntity element : model.getBioEntities()) {
-				for (MiriamData md : element.getMiriamData()) {
-					if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
-						targetMiriams.add(md);
-					} else if (MiriamType.ENTREZ.equals(md.getDataType())) {
-						targetMiriams.add(md);
-					}
-				}
-			}
-		}
-		double counter = 0.0;
-		int step = Math.max(targetMiriams.size() / 100, 1);
-		List<MiriamData> currentList = new ArrayList<>();
-		for (MiriamData md : targetMiriams) {
-			counter += 1;
-			currentList.add(md);
-			if (currentList.size() >= step) {
-				logger.debug("check mirna target: " + currentList);
-				try {
-					List<MiRNA> chemicalList = miRNAParser.getMiRnaListByTargets(currentList);
-					for (MiRNA chemical : chemicalList) {
-						cacheMiriamData(chemical);
-					}
-				} catch (MiRNASearchException | AnnotatorException e) {
-					logger.error("Problem with accessing info about mirna for target: " + md, e);
-				}
-				progress = counter / (double) targetMiriams.size();
-				iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
-				currentList.clear();
-			}
-		}
-	}
+  /**
+   * Default class logger.
+   */
+  private Logger logger = Logger.getLogger(MiRNAService.class);
+
+  /**
+   * Access point and parser for the online ctd database.
+   */
+  @Autowired
+  private MiRNAParser miRNAParser;
+
+  /**
+   * Object used to get information about {@link MiriamType#HGNC} annotations and
+   * transformations.
+   */
+  @Autowired
+  private HgncAnnotator hgncAnnotator;
+
+  /**
+   * Default constructor.
+   */
+  public MiRNAService() {
+    super();
+  }
+
+  /**
+   * Init method called after initialization of spring bean.
+   */
+  @PostConstruct
+  public void init() {
+  }
+
+  @Override
+  public MiRNA getByName(String name, DbSearchCriteria searchCriteria) {
+    if ("".equals(name)) {
+      return null;
+    }
+    try {
+      List<String> names = new ArrayList<>();
+      names.add(name);
+      List<MiRNA> miRNAs = miRNAParser.getMiRnasByNames(names);
+      if (miRNAs.size() > 0) {
+        return miRNAs.get(0);
+      }
+      return null;
+      // return miRNAViewFactory.create(miRNAs.get(0),
+      // searchCriteria.getModel(), searchCriteria.getColorSet());
+    } catch (MiRNASearchException e) {
+      logger.error("Problem with accessing mirna database", e);
+      return null;
+    }
+  }
+
+  @Override
+  public List<MiRNA> getForTargets(Collection<Element> targets, DbSearchCriteria searchCriteria) {
+    List<MiRNA> mirnaList = new ArrayList<MiRNA>();
+    Set<MiriamData> targetsMiriam = new HashSet<MiriamData>();
+    for (Element element : targets) {
+      if (element instanceof Protein || element instanceof Gene || element instanceof Rna) {
+        boolean hgncFound = false;
+        for (MiriamData md : element.getMiriamData()) {
+          if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
+            targetsMiriam.add(md);
+            hgncFound = true;
+          } else if (MiriamType.ENTREZ.equals(md.getDataType())) {
+            // ad also entrez in case of mouse, rat, etc
+            targetsMiriam.add(md);
+          }
+
+        }
+        if (!hgncFound) {
+          MiriamData md = new MiriamData(MiriamType.HGNC_SYMBOL, element.getName());
+          try {
+            if (hgncAnnotator.isValidHgncMiriam(md)) {
+              targetsMiriam.add(md);
+            }
+          } catch (AnnotatorException e) {
+            logger.error("Problem with accessing HGNC database", e);
+          }
+        }
+      }
+    }
+    try {
+      mirnaList = miRNAParser.getMiRnaListByTargets(targetsMiriam);
+    } catch (MiRNASearchException e) {
+      logger.error("Problem with accessing mirna database", e);
+    }
+
+    for (MiRNA drug : mirnaList) {
+      removeUnknownOrganisms(drug, searchCriteria.getOrganisms());
+    }
+
+    Collections.sort(mirnaList, new MiRNA.NameComparator());
+    return mirnaList;
+  }
+
+  /**
+   * Removes targets for unknown organisms from the mirna.
+   * 
+   * @param drug
+   *          drug from which we want to remove targets
+   * @param organisms
+   *          organisms that should be kept
+   */
+  private void removeUnknownOrganisms(MiRNA drug, List<MiriamData> organisms) {
+    if (organisms.size() > 0) {
+      List<Target> toRemove = new ArrayList<Target>();
+      for (Target target : drug.getTargets()) {
+        boolean remove = true;
+        for (MiriamData organism : organisms) {
+          if (target.getOrganism() == null) {
+            remove = false;
+          } else if (target.getOrganism().equals(organism)) {
+            remove = false;
+          }
+        }
+        if (remove) {
+          logger.debug("Target " + target.getName() + " removed from list because results are limited to organisms: "
+              + organisms);
+          toRemove.add(target);
+        }
+      }
+      drug.getTargets().removeAll(toRemove);
+    }
+  }
+
+  @Override
+  public void cacheDataForModel(Model originalModel, IProgressUpdater iProgressUpdater) {
+    logger.debug("Caching mirna queries...");
+    double progress = 0.0;
+    iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
+    Set<MiriamData> targetMiriams = new HashSet<>();
+    List<Model> models = new ArrayList<>();
+    models.add(originalModel);
+    models.addAll(originalModel.getSubmodels());
+    for (Model model : models) {
+      for (BioEntity element : model.getBioEntities()) {
+        for (MiriamData md : element.getMiriamData()) {
+          if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) {
+            targetMiriams.add(md);
+          } else if (MiriamType.ENTREZ.equals(md.getDataType())) {
+            targetMiriams.add(md);
+          }
+        }
+      }
+    }
+    double counter = 0.0;
+    int step = Math.max(targetMiriams.size() / 100, 1);
+    List<MiriamData> currentList = new ArrayList<>();
+    for (MiriamData md : targetMiriams) {
+      counter += 1;
+      currentList.add(md);
+      if (currentList.size() >= step) {
+        logger.debug("check mirna target: " + currentList);
+        try {
+          List<MiRNA> chemicalList = miRNAParser.getMiRnaListByTargets(currentList);
+          for (MiRNA chemical : chemicalList) {
+            cacheMiriamData(chemical);
+          }
+        } catch (MiRNASearchException | AnnotatorException e) {
+          logger.error("Problem with accessing info about mirna for target: " + md, e);
+        }
+        progress = counter / (double) targetMiriams.size();
+        iProgressUpdater.setProgress(progress * IProgressUpdater.MAX_PROGRESS);
+        currentList.clear();
+      }
+    }
+  }
 
 }
diff --git a/service/src/test/java/lcsb/mapviewer/services/search/db/chemical/ChemicalServiceTest.java b/service/src/test/java/lcsb/mapviewer/services/search/db/chemical/ChemicalServiceTest.java
index b0eb8bd661..daecc44c3e 100644
--- a/service/src/test/java/lcsb/mapviewer/services/search/db/chemical/ChemicalServiceTest.java
+++ b/service/src/test/java/lcsb/mapviewer/services/search/db/chemical/ChemicalServiceTest.java
@@ -31,38 +31,6 @@ public class ChemicalServiceTest extends ServiceTestFunctions {
 	public void tearDown() throws Exception {
 	}
 
-	/**
-	 * @throws Exception
-	 */
-	@Test
-	public void testgetPDChemicalByName() throws Exception {
-		try {
-			List<Chemical> result = null;
-			MiriamData pdDiseaseID = new MiriamData(MiriamType.MESH_2012, "D010300");
-
-			List<String> names = new ArrayList<String>();
-			names.add("Dopamine");
-			names.add("2-(2-furanyl)-7-(2-(4-(4-(2-methoxyethoxy)phenyl)-1-piperazinyl)ethyl)-7H-pyrazolo(4,3-e)(1,2,4)triazolo(1,5-c)pyrimidine-5-amine");
-			names.add("Anti-Inflammatory Agents, Non-Steroidal");
-			names.add("2-furanyl");
-			names.add(null);
-			result = chemicalService.getByNames(names, new DbSearchCriteria().disease(pdDiseaseID));
-			assertNotNull(result);
-			assertTrue(!result.isEmpty());
-			assertTrue(result.size() == 3);
-			names.clear();
-			names.add("2-furanyl");
-			result = chemicalService.getByNames(names, new DbSearchCriteria().disease(pdDiseaseID));
-			assertNotNull(result);
-			assertTrue(result.isEmpty());
-
-			assertEquals("No warnings expected.", 0, getWarnings().size());
-		} catch (Exception e) {
-			e.printStackTrace();
-			throw e;
-		}
-	}
-
 	@Test
 	public void testgetPDChemicalByName2() throws Exception {
 		try {
diff --git a/service/src/test/java/lcsb/mapviewer/services/search/db/mirna/MiRNAServiceTest.java b/service/src/test/java/lcsb/mapviewer/services/search/db/mirna/MiRNAServiceTest.java
index c4bd306e27..f623d5349f 100644
--- a/service/src/test/java/lcsb/mapviewer/services/search/db/mirna/MiRNAServiceTest.java
+++ b/service/src/test/java/lcsb/mapviewer/services/search/db/mirna/MiRNAServiceTest.java
@@ -1,72 +1,47 @@
 package lcsb.mapviewer.services.search.db.mirna;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.log4j.Logger;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import lcsb.mapviewer.annotation.data.MiRNA;
 import lcsb.mapviewer.common.IProgressUpdater;
 import lcsb.mapviewer.model.map.model.Model;
 import lcsb.mapviewer.model.map.model.ModelFullIndexed;
 import lcsb.mapviewer.services.ServiceTestFunctions;
-import lcsb.mapviewer.services.search.db.DbSearchCriteria;
 
 public class MiRNAServiceTest extends ServiceTestFunctions {
-	Logger									logger = Logger.getLogger(MiRNAServiceTest.class);
-
-	@Autowired
-	protected IMiRNAService	miRNAService;
-
-	@Before
-	public void setUp() throws Exception {
-	}
-
-	@After
-	public void tearDown() throws Exception {
-	}
-
-	@Test
-	public void testgetMiRNAByID() throws Exception {
-		try {
-			List<MiRNA> result = null;
-			List<String> idStrings = new ArrayList<String>();
-			idStrings.add("hsa-miR-122-5p");
-			idStrings.add("hsa-miR-32-5p");
-			result = miRNAService.getByNames(idStrings, new DbSearchCriteria());
-			assertNotNull(result);
-			assertTrue(!result.isEmpty());
-			assertTrue(result.size() == 2);
-		} catch (Exception e) {
-			e.printStackTrace();
-			throw e;
-		}
-	}
-
-	@Test
-	public void testCacheStub() throws Exception {
-		try {
-			// CellDesignerXmlParser parser = new CellDesignerXmlParser();
-			// Model model = parser.createModel(new
-			// ConverterParams().filename("testFiles/pd_full/PD_130909.xml"));
-			Model model = new ModelFullIndexed(null);
-			miRNAService.cacheDataForModel(model, new IProgressUpdater() {
-				@Override
-				public void setProgress(double progress) {
-					logger.debug("Progress: " + progress);
-				}
-			});
-		} catch (Exception e) {
-			e.printStackTrace();
-			throw e;
-		}
-	}
+  Logger logger = Logger.getLogger(MiRNAServiceTest.class);
+
+  @Autowired
+  protected IMiRNAService miRNAService;
+
+  @Before
+  public void setUp() throws Exception {
+  }
+
+  @After
+  public void tearDown() throws Exception {
+  }
+
+  @Test
+  public void testCacheStub() throws Exception {
+    try {
+      // CellDesignerXmlParser parser = new CellDesignerXmlParser();
+      // Model model = parser.createModel(new
+      // ConverterParams().filename("testFiles/pd_full/PD_130909.xml"));
+      Model model = new ModelFullIndexed(null);
+      miRNAService.cacheDataForModel(model, new IProgressUpdater() {
+        @Override
+        public void setProgress(double progress) {
+          logger.debug("Progress: " + progress);
+        }
+      });
+    } catch (Exception e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
 
 }
-- 
GitLab