[VIVO-1075] Get Literal and Integer from count RDFNode rather than a toString/parseInt which fails if there is a type present.

This commit is contained in:
grahamtriggs 2015-10-14 07:54:48 +01:00
parent 2f6489610c
commit 83404c2c80

View file

@ -7,6 +7,7 @@ import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.hp.hpl.jena.rdf.model.RDFNode;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
@ -290,8 +291,10 @@ class IndividualResponseBuilder {
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq); ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
if (results.hasNext()) { if (results.hasNext()) {
QuerySolution soln = results.nextSolution(); QuerySolution soln = results.nextSolution();
String countStr = soln.get("labelCount").toString(); RDFNode labelCount = soln.get("labelCount");
theCount = Integer.parseInt(countStr); if (labelCount != null && labelCount.isLiteral()) {
theCount = labelCount.asLiteral().getInt();
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);
@ -309,8 +312,10 @@ class IndividualResponseBuilder {
ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq); ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq);
if (results.hasNext()) { if (results.hasNext()) {
QuerySolution soln = results.nextSolution(); QuerySolution soln = results.nextSolution();
String countStr = soln.get("languageCount").toString(); RDFNode languageCount = soln.get("languageCount");
theCount = Integer.parseInt(countStr); if (languageCount != null && languageCount.isLiteral()) {
theCount = languageCount.asLiteral().getInt();
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);