From 03dcdf996b269c3a0d39a41db2078ddf175b8d5c Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Wed, 18 Oct 2017 12:40:22 +0200
Subject: [PATCH] small fixes for pdb annotator - class types modified

---
 .../annotation/services/annotators/PdbAnnotator.java     | 9 +++++----
 .../mapviewer/model/map/species/field/UniprotRecord.java | 5 +++++
 persist/src/db/{11.0.1 => 11.1.0}/fix_db_20170713.sql    | 4 ++--
 3 files changed, 12 insertions(+), 6 deletions(-)
 rename persist/src/db/{11.0.1 => 11.1.0}/fix_db_20170713.sql (57%)

diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/PdbAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/PdbAnnotator.java
index 4d69f2e648..f2dca91d0d 100644
--- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/PdbAnnotator.java
+++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/PdbAnnotator.java
@@ -1,6 +1,7 @@
 package lcsb.mapviewer.annotation.services.annotators;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
@@ -136,7 +137,7 @@ public class PdbAnnotator extends ElementAnnotator implements IExternalService {
 			
 			for (MiriamData md : mds) {
 				try {				
-					Set<Structure> structures = (Set<Structure>)uniProtToPdb(md);				
+					Collection<Structure> structures = uniProtToPdb(md);				
 					if (structures.size() == 0) {
 						logger.warn(elementUtils.getElementTag(bioEntity) + " No PDB mapping for UniProt ID: " + md.getResource());
 					} else {
@@ -159,7 +160,7 @@ public class PdbAnnotator extends ElementAnnotator implements IExternalService {
 						for (Structure s : structures) {
 							s.setUniprot(ur);							
 						}
-						ur.setStructures(structures);
+						ur.addStructures(structures);
 						((Species)bioEntity).getUniprots().add(ur);
 					}
 				} catch (WrongResponseCodeIOException exception) {
@@ -259,7 +260,7 @@ public class PdbAnnotator extends ElementAnnotator implements IExternalService {
 	 */
 	public Collection<Structure> uniProtToPdb(MiriamData uniprot) throws IOException {
 		if (uniprot == null) {
-			return null;
+			return new ArrayList<>();
 		}
 
 		if (!MiriamType.UNIPROT.equals(uniprot.getDataType())) {
@@ -269,7 +270,7 @@ public class PdbAnnotator extends ElementAnnotator implements IExternalService {
 		String accessUrl = getPdbMappingUrl(uniprot.getResource());
 		String json = getWebPageContent(accessUrl);
 		
-		return isJson(json) ? processMappingData(json) : null;
+		return isJson(json) ? processMappingData(json) : new ArrayList<>();
 	}
 
 	@Override
diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/UniprotRecord.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/UniprotRecord.java
index 92346cb4f2..ceba7173db 100644
--- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/UniprotRecord.java
+++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/UniprotRecord.java
@@ -1,6 +1,7 @@
 package lcsb.mapviewer.model.map.species.field;
 
 import java.io.Serializable;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -178,4 +179,8 @@ public class UniprotRecord implements Serializable {
 	public Set<Structure> getStructures() {
 		return structures;
 	}
+
+  public void addStructures(Collection<Structure> structures) {
+    this.structures.addAll(structures);
+  }
 }
diff --git a/persist/src/db/11.0.1/fix_db_20170713.sql b/persist/src/db/11.1.0/fix_db_20170713.sql
similarity index 57%
rename from persist/src/db/11.0.1/fix_db_20170713.sql
rename to persist/src/db/11.1.0/fix_db_20170713.sql
index c0f3e49c8e..9bac775133 100644
--- a/persist/src/db/11.0.1/fix_db_20170713.sql
+++ b/persist/src/db/11.1.0/fix_db_20170713.sql
@@ -1,2 +1,2 @@
-DELETE FROM cache_type WHERE classname = 'lcsb.mapviewer.annotation.services.annotators.PdbAnnotator'
-INSERT INTO cache_type(validity, classname) VALUES (365, 'lcsb.mapviewer.annotation.services.annotators.PdbAnnotator')
\ No newline at end of file
+DELETE FROM cache_type WHERE classname = 'lcsb.mapviewer.annotation.services.annotators.PdbAnnotator';
+INSERT INTO cache_type(validity, classname) VALUES (365, 'lcsb.mapviewer.annotation.services.annotators.PdbAnnotator');
\ No newline at end of file
-- 
GitLab