fixed bug on ranking, after use case: check all/ unceck all

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/speciesdiscovery@77520 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2013-07-03 13:47:39 +00:00
parent d4b70cdff1
commit 88ecdfdfc1
9 changed files with 111 additions and 27 deletions

36
pom.xml
View File

@ -19,7 +19,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>species-discovery</artifactId> <artifactId>species-discovery</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>3.2.0-SNAPSHOT</version> <version>3.3.0-SNAPSHOT</version>
<name>gCube Species Discovery</name> <name>gCube Species Discovery</name>
<description> <description>
gCube Species Discovery Portlet lets the users discovery species information from the Species Service. gCube Species Discovery Portlet lets the users discovery species information from the Species Service.
@ -52,12 +52,12 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- <dependency> --> <!-- <dependency> -->
<!-- <groupId>org.gcube.core</groupId> --> <!-- <groupId>org.gcube.core</groupId> -->
<!-- <artifactId>common-fw-clients</artifactId> --> <!-- <artifactId>common-fw-clients</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> --> <!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<!-- <scope>runtime</scope> --> <!-- <scope>runtime</scope> -->
<!-- </dependency> --> <!-- </dependency> -->
<dependency> <dependency>
<groupId>org.gcube.data.spd</groupId> <groupId>org.gcube.data.spd</groupId>
@ -77,8 +77,8 @@
<groupId>org.gcube.data.spd</groupId> <groupId>org.gcube.data.spd</groupId>
<artifactId>spd-model</artifactId> <artifactId>spd-model</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> --> <!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<!-- <scope>provided</scope> --> <!-- <scope>provided</scope> -->
</dependency> </dependency>
<dependency> <dependency>
@ -105,7 +105,7 @@
<dependency> <dependency>
<groupId>org.gcube.contentmanagement</groupId> <groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId> <artifactId>storage-manager-wrapper</artifactId>
<!-- <version>[1.0.1-SNAPSHOT, 1.1.0-SNAPSHOT)</version> --> <!-- <version>[1.0.1-SNAPSHOT, 1.1.0-SNAPSHOT)</version> -->
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -113,11 +113,11 @@
<dependency> <dependency>
<groupId>org.gcube.contentmanagement</groupId> <groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId> <artifactId>storage-manager-core</artifactId>
<!-- <version>[1.0.1-SNAPSHOT, 1.11.0-SNAPSHOT)</version> --> <!-- <version>[1.0.1-SNAPSHOT, 1.11.0-SNAPSHOT)</version> -->
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.contentmanagement</groupId> <groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-resource-link-plugin</artifactId> <artifactId>storage-resource-link-plugin</artifactId>
@ -228,7 +228,7 @@
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>home-library</artifactId> <artifactId>home-library</artifactId>
@ -259,6 +259,15 @@
<version>2.0</version> <version>2.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- LOGGER -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
@ -271,6 +280,7 @@
<version>1.6.4</version> <version>1.6.4</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -355,7 +355,7 @@ public class TaxonomySearchServiceImpl extends RemoteServiceServlet implements T
resultRow.setProperties(null); resultRow.setProperties(null);
} }
// System.out.println("resultRow "+resultRow); System.out.println("################### ResultRow parents: "+resultRow.getParents());
chunk.add(resultRow); chunk.add(resultRow);

View File

@ -105,8 +105,8 @@ public class SessionUtil {
// user = "pasquale.pagano"; // user = "pasquale.pagano";
// user = "lucio.lelii"; // user = "lucio.lelii";
// String scope = "/gcube/devsec"; //Development String scope = "/gcube/devsec"; //Development
String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityResearchEnvironment"; //Production // String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityResearchEnvironment"; //Production
httpSession.setAttribute(USERNAME_ATTRIBUTE, user); httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user); ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);

View File

@ -152,6 +152,10 @@ public class ResultItemConverter implements Converter<ResultItem, ResultRow> {
} }
} }
//DEBUG
// System.out.println("Insert row id: "+row.getId());
row.setMatchingTaxon(convertTaxon(input)); row.setMatchingTaxon(convertTaxon(input));
row.setBaseTaxonValue(NormalizeString.lowerCaseUpFirstChar(getBaseTaxonValue(TaxonomySearchServiceImpl.BASETAXONOMY,input))); row.setBaseTaxonValue(NormalizeString.lowerCaseUpFirstChar(getBaseTaxonValue(TaxonomySearchServiceImpl.BASETAXONOMY,input)));
@ -186,6 +190,8 @@ public class ResultItemConverter implements Converter<ResultItem, ResultRow> {
Taxon tax = new Taxon(count++, taxon.getScientificName(), taxon.getCitation(), NormalizeString.lowerCaseUpFirstChar(taxon.getRank())); Taxon tax = new Taxon(count++, taxon.getScientificName(), taxon.getCitation(), NormalizeString.lowerCaseUpFirstChar(taxon.getRank()));
listTaxon.add(tax); listTaxon.add(tax);
taxon = taxon.getParent(); taxon = taxon.getParent();
// System.out.println("Insert tax parent id: "+tax.getId());
} }
return listTaxon; return listTaxon;
} }

View File

@ -39,6 +39,9 @@ public class TaxonomyItemConverter implements Converter<TaxonomyItem, TaxonomyRo
TaxonomyRow taxonomy = createTaxonomyRow(input); TaxonomyRow taxonomy = createTaxonomyRow(input);
//SET PARENTS //SET PARENTS
// System.out.println("Convert Taxonomy parent for: "+taxonomy.getId());
taxonomy.setParent(convertParentsTaxonomy(input)); taxonomy.setParent(convertParentsTaxonomy(input));
//SET BASE TAXON //SET BASE TAXON
@ -180,9 +183,15 @@ public class TaxonomyItemConverter implements Converter<TaxonomyItem, TaxonomyRo
List<TaxonomyRow> listTaxonomy = new ArrayList<TaxonomyRow>(); List<TaxonomyRow> listTaxonomy = new ArrayList<TaxonomyRow>();
TaxonomyItem parent = taxon.getParent(); TaxonomyItem parent = taxon.getParent();
int i=0;
while(parent!=null){ while(parent!=null){
TaxonomyRow row = createTaxonomyRow(parent); TaxonomyRow row = createTaxonomyRow(parent);
row.setParent(true); row.setParent(true);
row.setParentIndex(i++);
// System.out.println("Insert Taxonomy parent id: "+row.getId() + ", row.getParentIndex: "+row.getParentIndex());
listTaxonomy.add(row); listTaxonomy.add(row);
parent = parent.getParent(); parent = parent.getParent();
} }

View File

@ -5,6 +5,7 @@ package org.gcube.portlets.user.speciesdiscovery.shared;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -62,6 +63,7 @@ public class ResultRow implements FetchingElement, SelectableElement, Serializab
public final static String PROPERTIES = "properties"; //USED public final static String PROPERTIES = "properties"; //USED
public static final String EXISTS_PROPERTIES = "existsProperties"; //USED public static final String EXISTS_PROPERTIES = "existsProperties"; //USED
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
protected int id; protected int id;
@ -528,6 +530,11 @@ public class ResultRow implements FetchingElement, SelectableElement, Serializab
public List<Taxon> getParents() { public List<Taxon> getParents() {
Collections.sort(matchingTaxon);
// for (Taxon t : matchingTaxon) {
// System.out.println("+++ Parent :" +t.getId() + ", name: "+t.getName() +", rank: "+t.getRank());
// }
return matchingTaxon; return matchingTaxon;
} }
@ -560,8 +567,7 @@ public class ResultRow implements FetchingElement, SelectableElement, Serializab
public void setProperties(List<ItemParameter> properties) { public void setProperties(List<ItemParameter> properties) {
this.properties = properties; this.properties = properties;
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -638,5 +644,7 @@ public class ResultRow implements FetchingElement, SelectableElement, Serializab
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -13,7 +13,7 @@ import javax.persistence.Id;
* *
*/ */
@Entity @Entity
public class Taxon implements Serializable, FetchingElement, TaxonomyInterface { public class Taxon implements Serializable, FetchingElement, TaxonomyInterface, Comparable<Taxon>{
private static final long serialVersionUID = -3579358036639552802L; private static final long serialVersionUID = -3579358036639552802L;
@ -25,6 +25,8 @@ public class Taxon implements Serializable, FetchingElement, TaxonomyInterface {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
protected int internalId;
protected int id; protected int id;
protected String name; protected String name;
@ -106,10 +108,23 @@ public class Taxon implements Serializable, FetchingElement, TaxonomyInterface {
this.id = id; this.id = id;
} }
/*
*
* Comparable on insertion order
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Taxon o) {
return id-o.getId();
}
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("Taxon [id="); builder.append("Taxon [internalId=");
builder.append(internalId);
builder.append(", id=");
builder.append(id); builder.append(id);
builder.append(", name="); builder.append(", name=");
builder.append(name); builder.append(name);
@ -120,6 +135,4 @@ public class Taxon implements Serializable, FetchingElement, TaxonomyInterface {
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View File

@ -5,6 +5,7 @@ package org.gcube.portlets.user.speciesdiscovery.shared;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -22,7 +23,7 @@ import javax.persistence.OneToMany;
*/ */
@Entity @Entity
//@Customizer(org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.TaxonomyCustomizer.class) //@Customizer(org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.TaxonomyCustomizer.class)
public class TaxonomyRow implements FetchingElement, Serializable, TaxonomyInterface, TaxonomyProvider, SelectableElement { public class TaxonomyRow implements FetchingElement, Serializable, TaxonomyInterface, TaxonomyProvider, SelectableElement, Comparable<TaxonomyRow> {
private static final long serialVersionUID = 1028839024130840026L; private static final long serialVersionUID = 1028839024130840026L;
@ -101,7 +102,9 @@ public class TaxonomyRow implements FetchingElement, Serializable, TaxonomyInter
@OneToMany(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER) @OneToMany(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER)
protected List<TaxonomyRow> parents; protected List<TaxonomyRow> parents;
//USED FOR PARENT
protected String parentID; protected String parentID;
protected int parentIndex = -1;
protected TaxonomyRow() { protected TaxonomyRow() {
@ -246,6 +249,7 @@ public class TaxonomyRow implements FetchingElement, Serializable, TaxonomyInter
@Override @Override
public List<TaxonomyRow> getParents() { public List<TaxonomyRow> getParents() {
Collections.sort(parents);
return parents; return parents;
} }
@ -422,6 +426,14 @@ public class TaxonomyRow implements FetchingElement, Serializable, TaxonomyInter
this.isParent = isParent; this.isParent = isParent;
} }
public int getParentIndex() {
return parentIndex;
}
public void setParentIndex(int parentIndex) {
this.parentIndex = parentIndex;
}
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -487,8 +499,18 @@ public class TaxonomyRow implements FetchingElement, Serializable, TaxonomyInter
builder.append(parents); builder.append(parents);
builder.append(", parentID="); builder.append(", parentID=");
builder.append(parentID); builder.append(parentID);
builder.append(", parentIndex=");
builder.append(parentIndex);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
/* (non-Javadoc)
* Comparable on insertion order
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(TaxonomyRow o) {
return parentIndex - o.getParentIndex();
}
} }

View File

@ -28,14 +28,30 @@ public class ServiceQuery {
*/ */
public static void main(String[] args) throws InvalidQueryException, UnsupportedPluginException { public static void main(String[] args) throws InvalidQueryException, UnsupportedPluginException {
String scope = "/gcube/devsec"; String scope = "/gcube/devsec";
// String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityResearchEnvironment"; //Production
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
Manager call = manager().at(URI.create("http://node24.d.d4science.research-infrastructures.eu:9000")).withTimeout(3, TimeUnit.MINUTES).build();
Manager call = manager().withTimeout(3, TimeUnit.MINUTES).build();
// Manager call = manager().at(URI.create("http://node24.d.d4science.research-infrastructures.eu:9000")).withTimeout(3, TimeUnit.MINUTES).build();
//Stream<ResultElement> results = call.search("SEARCH BY CN 'shark' RESOLVE WITH OBIS EXPAND WITH ITIS RETURN Product"); //Stream<ResultElement> results = call.search("SEARCH BY CN 'shark' RESOLVE WITH OBIS EXPAND WITH ITIS RETURN Product");
Stream<ResultElement> results = call.search("SEARCH BY CN 'shark' RESOLVE WITH OBIS EXPAND WITH ITIS WHERE coordinate <= 15.12, 16.12 RETURN Product"); // Stream<ResultElement> results = call.search("SEARCH BY CN 'shark' RESOLVE WITH OBIS EXPAND WITH ITIS WHERE coordinate <= 15.12, 16.12 RETURN Product");
if (results.hasNext()) results.next();
// Stream<ResultElement> results = call.search("SEARCH BY SN 'sarda sarda' RESOLVE WITH OBIS EXPAND WITH ITIS WHERE coordinate <= 15.12, 16.12 RETURN Product");
System.out.println("start query...");
Stream<ResultElement> results = call.search("SEARCH BY SN 'sarda sarda' RETURN Product");
int i=0;
if (results.hasNext()) {
ResultElement elem = results.next();
System.out.println(++i +") el: "+elem.getId());
}
results.close(); results.close();
System.out.println("DONE"); System.out.println("DONE");