Fixed bug on taxon.getName()==null

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/speciesdiscovery@117452 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-24 10:27:24 +00:00
parent 7822e080af
commit 7f15382661
5 changed files with 25 additions and 11 deletions

View File

@ -3,9 +3,6 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<dependent-module archiveName="gis-viewer-3.7.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gis-viewer-TRUNK/gis-viewer-TRUNK">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/> <property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="species-discovery"/> <property name="context-root" value="species-discovery"/>
</wb-module> </wb-module>

View File

@ -21,7 +21,7 @@ import org.gcube.portlets.user.speciesdiscovery.shared.FetchingElement;
public class Fetcher<T extends FetchingElement> implements Runnable, Closeable { public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
protected Logger logger = Logger.getLogger(Fetcher.class); protected Logger logger = Logger.getLogger(Fetcher.class);
protected final int MAX_CONSECUTIVE_ATTEMPTS_ON_NULL = 5; protected final int MAX_CONSECUTIVE_ATTEMPTS_ON_NULL = 2;
protected FetchingBuffer<T> buffer; protected FetchingBuffer<T> buffer;
protected CloseableIterator<T> source; protected CloseableIterator<T> source;
protected boolean complete = false; protected boolean complete = false;
@ -75,6 +75,7 @@ public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
if(next!=null){ if(next!=null){
logger.info("item "+count++ +" fetch new row: "+next.getId()); logger.info("item "+count++ +" fetch new row: "+next.getId());
buffer.add(next); buffer.add(next);
countNullItems = 0;
} }
else{ else{
countNullItems++; countNullItems++;
@ -120,6 +121,7 @@ public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
*/ */
public void close() throws IOException public void close() throws IOException
{ {
logger.info("Fetcher closing iterator!!");
complete = true; complete = true;
source.close(); source.close();
} }

View File

@ -7,6 +7,8 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger;
/** /**
* @author "Federico De Faveri defaveri@isti.cnr.it" * @author "Federico De Faveri defaveri@isti.cnr.it"
* *
@ -15,6 +17,7 @@ public class AggregatorIterator<I> implements CloseableIterator<I> {
protected CloseableIterator<I> source; protected CloseableIterator<I> source;
protected Map<String, Aggregator<I, ?>> aggregators; protected Map<String, Aggregator<I, ?>> aggregators;
protected Logger logger = Logger.getLogger(AggregatorIterator.class);
/** /**
* @param source * @param source
@ -42,6 +45,12 @@ public class AggregatorIterator<I> implements CloseableIterator<I> {
@Override @Override
public I next() { public I next() {
I input = source.next(); I input = source.next();
//Another check
if(input==null){
logger.warn("Skipping conversion source.next() is Null!!");
return null;
}
for (Aggregator<I, ?> aggregator:aggregators.values()) aggregator.aggregate(input); for (Aggregator<I, ?> aggregator:aggregators.values()) aggregator.aggregate(input);
return input; return input;
} }

View File

@ -41,6 +41,13 @@ public class ConversionIterator<I,O> implements CloseableIterator<O> {
assert hasNext(); assert hasNext();
try { try {
I input = source.next(); I input = source.next();
////Another check
if(input==null){
logger.warn("Skipping conversion source.next() is Null!!");
return null;
}
O output = converter.convert(input); O output = converter.convert(input);
return output; return output;
} catch (Exception e) { } catch (Exception e) {

View File

@ -48,19 +48,17 @@ public class TaxonomyClassificationAggregator<T extends TaxonomyProvider> implem
@Override @Override
public void aggregate(TaxonomyProvider row) { public void aggregate(TaxonomyProvider row) {
// System.out.println("TaxonomyProvider " + row); // System.out.println("TaxonomyProvider " + row);
List<? extends TaxonomyInterface> matchingTaxon = row.getParents(); List<? extends TaxonomyInterface> matchingTaxon = row.getParents();
if(matchingTaxon == null || matchingTaxon.size()==0) return; if(matchingTaxon == null || matchingTaxon.size()==0) return;
EnumMap<MainTaxonomicRankEnum, TaxonomyInterface> groupedTaxon = groupTaxonByRank(matchingTaxon); EnumMap<MainTaxonomicRankEnum, TaxonomyInterface> groupedTaxon = groupTaxonByRank(matchingTaxon);
// System.out.println("GroupedTaxon Key Set: " + groupedTaxon.keySet());
for (MainTaxonomicRankEnum aggregationRank: MainTaxonomicRankEnum.values()){ for (MainTaxonomicRankEnum aggregationRank: MainTaxonomicRankEnum.values()){
TaxonomyInterface taxon = groupedTaxon.get(aggregationRank); TaxonomyInterface taxon = groupedTaxon.get(aggregationRank);
String taxonId; String taxonId;
//IF RANK CLASS EXISTS INSERT INTO HASHMAP GROUP BY RANK //IF RANK CLASS EXISTS INSERT INTO HASHMAP GROUP BY RANK
@ -71,9 +69,10 @@ public class TaxonomyClassificationAggregator<T extends TaxonomyProvider> implem
String unknownRank = matchingTaxon.get(0).getRank()!=null?matchingTaxon.get(0).getRank():TAXONOMYUNKNOWN; // GET THE FIRST RANK CLASS String unknownRank = matchingTaxon.get(0).getRank()!=null?matchingTaxon.get(0).getRank():TAXONOMYUNKNOWN; // GET THE FIRST RANK CLASS
taxon = row.getParents().get(0);
//IF BASETAXONOMY CLASS IS NOT UNKNOWN - INSERT INTO HASHMAP GROUP BY FIRST RANK //IF BASETAXONOMY CLASS IS NOT UNKNOWN - INSERT INTO HASHMAP GROUP BY FIRST RANK
if(!row.getBaseTaxonValue().equalsIgnoreCase(TAXONOMYUNKNOWN)) { if(!row.getBaseTaxonValue().equalsIgnoreCase(TAXONOMYUNKNOWN) && (taxon!=null)) {
taxonId = addTaxonToAggregation(aggregationRank, row.getParents().get(0), row.getBaseTaxonValue(), row.getBaseTaxonValue(), unknownRank); taxonId = addTaxonToAggregation(aggregationRank, taxon, row.getBaseTaxonValue(), row.getBaseTaxonValue(), unknownRank);
setClassification(row, aggregationRank, taxonId); setClassification(row, aggregationRank, taxonId);
} else { } else {
//BASETAXONOMY UNKNOWN - INSERT INTO HASHMAP GROUP BY haskKey UNKNOWN RANK //BASETAXONOMY UNKNOWN - INSERT INTO HASHMAP GROUP BY haskKey UNKNOWN RANK
@ -119,7 +118,7 @@ public class TaxonomyClassificationAggregator<T extends TaxonomyProvider> implem
protected String addTaxonToAggregation(MainTaxonomicRankEnum aggregationRank, TaxonomyInterface taxon, String baseTaxonId, String baseTaxonValue, String classificationRank) protected String addTaxonToAggregation(MainTaxonomicRankEnum aggregationRank, TaxonomyInterface taxon, String baseTaxonId, String baseTaxonValue, String classificationRank)
{ {
String taxonName = taxon.getName().toLowerCase(); String taxonName =taxon.getName()!=null?taxon.getName().toLowerCase():"No name";
return addTaxonToAggregation(aggregationRank, taxonName, taxonName, baseTaxonId, baseTaxonValue, classificationRank); return addTaxonToAggregation(aggregationRank, taxonName, taxonName, baseTaxonId, baseTaxonValue, classificationRank);
} }