From c8ec6c906790e38a356e94624e1508dd8a582a32 Mon Sep 17 00:00:00 2001 From: bjl23 Date: Wed, 2 Feb 2011 20:55:08 +0000 Subject: [PATCH] NIHVIVO-1989 ; fixes lack of labels for individuals returned from getIndividualsByVClass() in SDB --- .../webapp/dao/jena/IndividualDaoSDB.java | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java index 24aeeb9d1..bd5ef04e8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java @@ -125,26 +125,34 @@ public class IndividualDaoSDB extends IndividualDaoJena { ResultSet rs =QueryExecutionFactory.create( QueryFactory.create(query), dataset) .execSelect(); - Resource res = null; + String uri = null; + String label = null; + String moniker = null; while (rs.hasNext()) { QuerySolution sol = rs.nextSolution(); Resource currRes = sol.getResource("ind"); - if ((res == null || !res.equals(currRes)) - && !currRes.isAnon()) { - res = currRes; - Individual ent = new IndividualSDB(currRes.getURI(), - this.dwf, datasetMode, getWebappDaoFactory(), - SKIP_INITIALIZATION); - Literal label = sol.getLiteral("label"); - if (label != null) { - ent.setName(label.getLexicalForm()); - } - Literal moniker = sol.getLiteral("moniker"); - if (moniker != null) { - ent.setMoniker(moniker.getLexicalForm()); - } - ents.add(ent); + if (currRes.isAnon()) { + continue; } + if (uri != null && !uri.equals(currRes.getURI())) { + ents.add(makeIndividual(uri, label, moniker)); + uri = currRes.getURI(); + label = null; + moniker = null; + } else if (uri == null) { + uri = currRes.getURI(); + } + Literal labelLit = sol.getLiteral("label"); + if (labelLit != null) { + label = labelLit.getLexicalForm(); + } + Literal monikerLit = sol.getLiteral("moniker"); + if (monikerLit != null) { + moniker = monikerLit.getLexicalForm(); + } + if (!rs.hasNext()) { + ents.add(makeIndividual(uri, label, moniker)); + } } } finally { dataset.getLock().leaveCriticalSection(); @@ -165,6 +173,15 @@ public class IndividualDaoSDB extends IndividualDaoJena { return ents; } + + private Individual makeIndividual(String uri, String label, String moniker) { + Individual ent = new IndividualSDB(uri, + this.dwf, datasetMode, getWebappDaoFactory(), + SKIP_INITIALIZATION); + ent.setName(label); + ent.setMoniker(moniker); + return ent; + } @Override public Individual getIndividualByURI(String entityURI) {