Merge branch 'maint-rel-1.6' of https://github.com/vivo-project/Vitro into maint-rel-1.6
Conflicts: webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java
This commit is contained in:
commit
754c8004ae
64 changed files with 1174 additions and 925 deletions
|
@ -11,7 +11,6 @@ import com.hp.hpl.jena.ontology.OntModel;
|
|||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
|
@ -20,7 +19,6 @@ import com.hp.hpl.jena.rdf.model.StmtIterator;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ActiveIdentifierBundleFactories;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
|
@ -136,7 +134,8 @@ public class PolicyHelper {
|
|||
.asResource().getURI());
|
||||
} else {
|
||||
action = new AddDataPropertyStatement(modelToBeModified,
|
||||
subject.getURI(), predicate.getURI());
|
||||
subject.getURI(), predicate.getURI(), objectNode
|
||||
.asLiteral().getString());
|
||||
}
|
||||
return isAuthorizedForActions(req, action);
|
||||
}
|
||||
|
@ -169,7 +168,8 @@ public class PolicyHelper {
|
|||
.asResource().getURI());
|
||||
} else {
|
||||
action = new DropDataPropertyStatement(modelToBeModified,
|
||||
subject.getURI(), predicate.getURI());
|
||||
subject.getURI(), predicate.getURI(), objectNode
|
||||
.asLiteral().getString());
|
||||
}
|
||||
return isAuthorizedForActions(req, action);
|
||||
}
|
||||
|
|
|
@ -16,15 +16,17 @@ public abstract class AbstractDataPropertyStatementAction extends
|
|||
private final String subjectUri;
|
||||
private final String predicateUri;
|
||||
private final Property predicate;
|
||||
private final String dataValue;
|
||||
|
||||
public AbstractDataPropertyStatementAction(OntModel ontModel,
|
||||
String subjectUri, String predicateUri) {
|
||||
String subjectUri, String predicateUri, String dataValue) {
|
||||
super(ontModel);
|
||||
this.subjectUri = subjectUri;
|
||||
this.predicateUri = predicateUri;
|
||||
Property dataProperty = new Property();
|
||||
dataProperty.setURI(predicateUri);
|
||||
this.predicate = dataProperty;
|
||||
this.dataValue = dataValue;
|
||||
}
|
||||
|
||||
public AbstractDataPropertyStatementAction(OntModel ontModel,
|
||||
|
@ -36,12 +38,14 @@ public abstract class AbstractDataPropertyStatementAction extends
|
|||
Property dataProperty = new Property();
|
||||
dataProperty.setURI(predicateUri);
|
||||
this.predicate = dataProperty;
|
||||
this.dataValue = dps.getData();
|
||||
}
|
||||
|
||||
public String getSubjectUri() {
|
||||
return subjectUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getPredicate() {
|
||||
return predicate;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ public class AddDataPropertyStatement extends
|
|||
AbstractDataPropertyStatementAction {
|
||||
|
||||
public AddDataPropertyStatement(OntModel ontModel, String subjectUri,
|
||||
String predicateUri) {
|
||||
super(ontModel, subjectUri, predicateUri);
|
||||
String predicateUri, String dataValue) {
|
||||
super(ontModel, subjectUri, predicateUri, dataValue);
|
||||
}
|
||||
|
||||
public AddDataPropertyStatement(OntModel ontModel, DataPropertyStatement dps) {
|
||||
|
|
|
@ -14,8 +14,8 @@ public class DropDataPropertyStatement extends
|
|||
AbstractDataPropertyStatementAction {
|
||||
|
||||
public DropDataPropertyStatement(OntModel ontModel, String subjectUri,
|
||||
String predicateUri) {
|
||||
super(ontModel, subjectUri, predicateUri);
|
||||
String predicateUri, String dataValue) {
|
||||
super(ontModel, subjectUri, predicateUri, dataValue);
|
||||
}
|
||||
|
||||
public DropDataPropertyStatement(OntModel ontModel,
|
||||
|
|
|
@ -12,8 +12,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|||
public class EditDataPropertyStatement extends
|
||||
AbstractDataPropertyStatementAction {
|
||||
public EditDataPropertyStatement(OntModel ontModel, String subjectUri,
|
||||
String predicateUri) {
|
||||
super(ontModel, subjectUri, predicateUri);
|
||||
String predicateUri, String dataValue) {
|
||||
super(ontModel, subjectUri, predicateUri, dataValue);
|
||||
}
|
||||
|
||||
public EditDataPropertyStatement(OntModel ontModel,
|
||||
|
|
|
@ -13,10 +13,7 @@ import javax.servlet.ServletContext;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
|
@ -25,9 +22,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
|
||||
|
||||
|
@ -94,16 +90,15 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
|
||||
String alpha = getAlphaParameter(vreq);
|
||||
int page = getPageParameter(vreq);
|
||||
Map<String,Object> map = getResultsForVClass(
|
||||
IndividualListResults vcResults = getResultsForVClass(
|
||||
vclass.getURI(),
|
||||
page,
|
||||
alpha,
|
||||
vreq.getWebappDaoFactory().getIndividualDao(),
|
||||
getServletContext());
|
||||
body.putAll(map);
|
||||
body.putAll(vcResults.asFreemarkerMap());
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Individual> inds = (List<Individual>)map.get("entities");
|
||||
List<Individual> inds = vcResults.getEntities();
|
||||
List<ListedIndividual> indsTm = new ArrayList<ListedIndividual>();
|
||||
if (inds != null) {
|
||||
for ( Individual ind : inds ) {
|
||||
|
@ -154,13 +149,12 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
return SolrQueryUtils.getPageParameter(request);
|
||||
}
|
||||
|
||||
public static Map<String,Object> getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao, ServletContext context)
|
||||
public static IndividualListResults getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao, ServletContext context)
|
||||
throws SearchException{
|
||||
Map<String,Object> rvMap = new HashMap<String,Object>();
|
||||
try{
|
||||
List<String> classUris = Collections.singletonList(vclassURI);
|
||||
IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE, context, indDao);
|
||||
rvMap = getResultsForVClassQuery(results, page, INDIVIDUALS_PER_PAGE, alpha);
|
||||
return getResultsForVClassQuery(results, page, INDIVIDUALS_PER_PAGE, alpha);
|
||||
} catch (SolrServerException e) {
|
||||
String msg = "An error occurred retrieving results for vclass query";
|
||||
log.error(msg, e);
|
||||
|
@ -168,31 +162,29 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
throw new SearchException(msg);
|
||||
} catch(Throwable th) {
|
||||
log.error("An error occurred retrieving results for vclass query", th);
|
||||
return IndividualListResults.EMPTY;
|
||||
}
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
public static Map<String,Object> getResultsForVClassIntersections(List<String> vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao, ServletContext context) {
|
||||
Map<String,Object> rvMap = new HashMap<String,Object>();
|
||||
public static IndividualListResults getResultsForVClassIntersections(List<String> vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao, ServletContext context) {
|
||||
try{
|
||||
IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(vclassURIs, alpha, page, pageSize, context, indDao);
|
||||
rvMap = getResultsForVClassQuery(results, page, pageSize, alpha);
|
||||
return getResultsForVClassQuery(results, page, pageSize, alpha);
|
||||
} catch(Throwable th) {
|
||||
log.error("Error retrieving individuals corresponding to intersection multiple classes." + vclassURIs.toString(), th);
|
||||
return IndividualListResults.EMPTY;
|
||||
}
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
public static Map<String,Object> getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao, ServletContext context) {
|
||||
Map<String,Object> rvMap = new HashMap<String,Object>();
|
||||
public static IndividualListResults getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao, ServletContext context) {
|
||||
try{
|
||||
List<String> classUris = Collections.singletonList(vclassURI);
|
||||
IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, context, indDao);
|
||||
rvMap = getResultsForVClassQuery(results, page, pageSize, "");
|
||||
return getResultsForVClassQuery(results, page, pageSize, "");
|
||||
} catch(Throwable th) {
|
||||
log.error("An error occurred retrieving random results for vclass query", th);
|
||||
return IndividualListResults.EMPTY;
|
||||
}
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
//TODO: Get rid of this method and utilize SolrQueryUtils - currently appears to be referenced
|
||||
|
@ -201,24 +193,13 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
return SolrQueryUtils.getIndividualCount(vclassUris, indDao, context);
|
||||
}
|
||||
|
||||
private static Map<String,Object> getResultsForVClassQuery(IndividualListQueryResults results, int page, int pageSize, String alpha) {
|
||||
Map<String,Object> rvMap = new HashMap<String,Object>();
|
||||
|
||||
private static IndividualListResults getResultsForVClassQuery(IndividualListQueryResults results, int page, int pageSize, String alpha) {
|
||||
long hitCount = results.getHitCount();
|
||||
if ( hitCount > pageSize ){
|
||||
rvMap.put("showPages", Boolean.TRUE);
|
||||
List<PageRecord> pageRecords = makePagesList(hitCount, pageSize, page);
|
||||
rvMap.put("pages", pageRecords);
|
||||
return new IndividualListResults(hitCount, results.getIndividuals(), alpha, true, makePagesList(hitCount, pageSize, page));
|
||||
}else{
|
||||
rvMap.put("showPages", Boolean.FALSE);
|
||||
rvMap.put("pages", Collections.emptyList());
|
||||
return new IndividualListResults(hitCount, results.getIndividuals(), alpha, false, Collections.<PageRecord>emptyList());
|
||||
}
|
||||
|
||||
rvMap.put("alpha",alpha);
|
||||
rvMap.put("totalCount", hitCount);
|
||||
rvMap.put("entities", results.getIndividuals());
|
||||
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,11 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.individual;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
@ -22,18 +17,13 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
|
|||
*/
|
||||
public class IndividualRequestAnalysisContextImpl implements
|
||||
IndividualRequestAnalysisContext {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(IndividualRequestAnalysisContextImpl.class);
|
||||
|
||||
|
||||
private final VitroRequest vreq;
|
||||
private final ServletContext ctx;
|
||||
|
||||
private final VitroRequest vreq;
|
||||
private final WebappDaoFactory wadf;
|
||||
private final IndividualDao iDao;
|
||||
|
||||
public IndividualRequestAnalysisContextImpl(VitroRequest vreq) {
|
||||
this.vreq = vreq;
|
||||
this.ctx = vreq.getSession().getServletContext();
|
||||
this.vreq = vreq;
|
||||
this.wadf = vreq.getWebappDaoFactory();
|
||||
this.iDao = wadf.getIndividualDao();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.individuallist;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
/**
|
||||
* Wrap an Individual in a JSON object for display by the script.
|
||||
*
|
||||
* This will be overridden in VIVO so we can have more info in the display.
|
||||
*/
|
||||
public class IndividualJsonWrapper {
|
||||
static JSONObject packageIndividualAsJson(VitroRequest vreq, Individual ind)
|
||||
throws JSONException {
|
||||
// need an unfiltered dao to get firstnames and lastnames
|
||||
WebappDaoFactory fullWdf = vreq.getUnfilteredWebappDaoFactory();
|
||||
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("URI", ind.getURI());
|
||||
jo.put("label", ind.getRdfsLabel());
|
||||
jo.put("name", ind.getName());
|
||||
jo.put("thumbUrl", ind.getThumbUrl());
|
||||
jo.put("imageUrl", ind.getImageUrl());
|
||||
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
|
||||
jo.put("mostSpecificTypes", getMostSpecificTypes(ind, fullWdf));
|
||||
return jo;
|
||||
}
|
||||
|
||||
public static Collection<String> getMostSpecificTypes(
|
||||
Individual individual, WebappDaoFactory wdf) {
|
||||
ObjectPropertyStatementDao opsDao = wdf.getObjectPropertyStatementDao();
|
||||
Map<String, String> mostSpecificTypes = opsDao
|
||||
.getMostSpecificTypesInClassgroupsForIndividual(individual
|
||||
.getURI());
|
||||
return mostSpecificTypes.values();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.individuallist;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
|
||||
|
||||
/**
|
||||
* These are the paged results of a query for Individuals.
|
||||
*
|
||||
* The criteria for the search are the index of the desired page, the number of
|
||||
* results displayed on each page, and an optional initial letter to search
|
||||
* against.
|
||||
*
|
||||
* By the time this is built, the results have already been partially processed.
|
||||
* A list of PageRecord object is included, with values that the GUI can use to
|
||||
* create Alphabetical links. Maybe this processing should have been done later.
|
||||
* Maybe it should have been left to the GUI.
|
||||
*/
|
||||
public class IndividualListResults {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(IndividualListResults.class);
|
||||
|
||||
public static final IndividualListResults EMPTY = new IndividualListResults();
|
||||
|
||||
private final long totalCount;
|
||||
private final List<Individual> entities;
|
||||
private final String alpha;
|
||||
private final boolean showPages;
|
||||
private final List<PageRecord> pages;
|
||||
|
||||
public IndividualListResults(long totalCount, List<Individual> entities,
|
||||
String alpha, boolean showPages, List<PageRecord> pages) {
|
||||
this.totalCount = totalCount;
|
||||
this.entities = entities;
|
||||
this.alpha = alpha;
|
||||
this.showPages = showPages;
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
private IndividualListResults() {
|
||||
this(0L, Collections.<Individual> emptyList(), "", false, Collections
|
||||
.<PageRecord> emptyList());
|
||||
}
|
||||
|
||||
public long getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public String getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public List<Individual> getEntities() {
|
||||
return entities;
|
||||
}
|
||||
|
||||
public List<PageRecord> getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
public boolean isShowPages() {
|
||||
return showPages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some controllers put this data directly into the Freemarker body map.
|
||||
* Others wrap it in JSON.
|
||||
*/
|
||||
public Map<String, Object> asFreemarkerMap() {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
m.put("showPages", showPages);
|
||||
m.put("pages", pages);
|
||||
m.put("alpha", alpha);
|
||||
m.put("totalCount", totalCount);
|
||||
m.put("entities", entities);
|
||||
return m;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.individuallist;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
|
||||
|
||||
/**
|
||||
* Utility methods for procesing the paged results of a query for a list of Individuals.
|
||||
*
|
||||
* Right now, there is only a method to wrap the results in Json.
|
||||
*/
|
||||
public class IndividualListResultsUtils {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(IndividualListResultsUtils.class);
|
||||
|
||||
/**
|
||||
* Process results related to VClass or vclasses. Handles both single and
|
||||
* multiple vclasses being sent.
|
||||
*/
|
||||
public static JSONObject wrapIndividualListResultsInJson(IndividualListResults results, VitroRequest vreq,
|
||||
boolean multipleVclasses) {
|
||||
JSONObject rObj = new JSONObject();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
dumpParametersFromRequest(vreq);
|
||||
}
|
||||
|
||||
try {
|
||||
List<VClass> vclasses = buildListOfRequestedVClasses(vreq);
|
||||
|
||||
VClass vclass = null;
|
||||
// if single vclass expected, then include vclass.
|
||||
// This relates to what the expected behavior is, not size of list
|
||||
if (!multipleVclasses) {
|
||||
vclass = vclasses.get(0);
|
||||
// currently used for ClassGroupPage
|
||||
} else {
|
||||
// For now, utilize very last VClass (assume that that is the one to be employed)
|
||||
// TODO: Find more general way of dealing with this: put multiple ones in?
|
||||
vclass = vclasses.get(vclasses.size() - 1);
|
||||
// rObj.put("vclasses", new JSONObject().put("URIs",vitroClassIdStr).put("name",vclass.getName()));
|
||||
}
|
||||
|
||||
rObj.put("vclass", packageVClassAsJson(vclass));
|
||||
rObj.put("totalCount", results.getTotalCount());
|
||||
rObj.put("alpha", results.getAlpha());
|
||||
rObj.put("individuals", packageIndividualsAsJson(vreq, results.getEntities()));
|
||||
rObj.put("pages", packagePageRecordsAsJson(results.getPages()));
|
||||
rObj.put("letters", packageLettersAsJson());
|
||||
} catch (Exception ex) {
|
||||
log.error("Error occurred in processing JSON object", ex);
|
||||
}
|
||||
return rObj;
|
||||
}
|
||||
|
||||
private static List<VClass> buildListOfRequestedVClasses(VitroRequest vreq)
|
||||
throws Exception {
|
||||
String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
|
||||
if (ArrayUtils.isEmpty(vitroClassIdStr)) {
|
||||
log.error("parameter vclassId URI parameter expected ");
|
||||
throw new Exception("parameter vclassId URI parameter expected ");
|
||||
}
|
||||
|
||||
List<VClass> list = new ArrayList<>();
|
||||
for (String vclassId : vitroClassIdStr) {
|
||||
VClass vclass = vreq.getWebappDaoFactory().getVClassDao()
|
||||
.getVClassByURI(vclassId);
|
||||
if (vclass == null) {
|
||||
log.error("Couldn't retrieve vclass ");
|
||||
throw new Exception("Class " + vclassId + " not found");
|
||||
}
|
||||
list.add(vclass);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static JSONObject packageVClassAsJson(VClass vclass)
|
||||
throws JSONException {
|
||||
JSONObject jvclass = new JSONObject();
|
||||
jvclass.put("URI", vclass.getURI());
|
||||
jvclass.put("name", vclass.getName());
|
||||
return jvclass;
|
||||
}
|
||||
|
||||
private static JSONArray packageLettersAsJson() throws JSONException,
|
||||
UnsupportedEncodingException {
|
||||
List<String> letters = Controllers.getLetters();
|
||||
JSONArray jletters = new JSONArray();
|
||||
for (String s : letters) {
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("text", s);
|
||||
jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
|
||||
jletters.put(jo);
|
||||
}
|
||||
return jletters;
|
||||
}
|
||||
|
||||
private static JSONArray packagePageRecordsAsJson(List<PageRecord> pages)
|
||||
throws JSONException {
|
||||
JSONArray wpages = new JSONArray();
|
||||
for (PageRecord pr : pages) {
|
||||
JSONObject p = new JSONObject();
|
||||
p.put("text", pr.text);
|
||||
p.put("param", pr.param);
|
||||
p.put("index", pr.index);
|
||||
wpages.put(p);
|
||||
}
|
||||
return wpages;
|
||||
}
|
||||
|
||||
private static JSONArray packageIndividualsAsJson(VitroRequest vreq,
|
||||
List<Individual> inds) throws JSONException {
|
||||
log.debug("Number of individuals returned from request: " + inds.size());
|
||||
|
||||
JSONArray jInds = new JSONArray();
|
||||
for (Individual ind : inds) {
|
||||
jInds.put(IndividualJsonWrapper.packageIndividualAsJson(vreq, ind));
|
||||
}
|
||||
return jInds;
|
||||
}
|
||||
|
||||
private static void dumpParametersFromRequest(VitroRequest vreq) {
|
||||
Map<String, String[]> pMap = vreq.getParameterMap();
|
||||
for (String name : pMap.keySet()) {
|
||||
for (String value : pMap.get(name)) {
|
||||
log.debug("value for " + name + ": '" + value + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,11 +3,8 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.controller.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -18,18 +15,15 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResultsUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils;
|
||||
|
@ -94,29 +88,28 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
List<String> vclassURIs = Collections.singletonList(vclassURI);
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
|
||||
Map<String, Object> map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
|
||||
IndividualListResults vcResults = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
|
||||
//last parameter indicates single vclass instead of multiple vclasses
|
||||
return processVclassResultsJSON(map, vreq, false);
|
||||
return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, false);
|
||||
}
|
||||
|
||||
public static JSONObject getSolrIndividualsByVClasses(List<String> vclassURIs, HttpServletRequest req, ServletContext context) throws Exception {
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
log.debug("Retrieve solr results for vclasses" + vclassURIs.toString());
|
||||
Map<String, Object> map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
|
||||
log.debug("Results returned from Solr for " + vclassURIs.toString() + " are of size " + map.size());
|
||||
IndividualListResults vcResults = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
|
||||
log.debug("Results returned from Solr for " + vclassURIs.toString() + " are of size " + vcResults.getTotalCount());
|
||||
|
||||
return processVclassResultsJSON(map, vreq, true);
|
||||
return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, true);
|
||||
}
|
||||
|
||||
//Including version for Solr query for Vclass Intersections
|
||||
private static Map<String,Object> getSolrVClassIntersectionResults(List<String> vclassURIs, VitroRequest vreq, ServletContext context){
|
||||
private static IndividualListResults getSolrVClassIntersectionResults(List<String> vclassURIs, VitroRequest vreq, ServletContext context){
|
||||
log.debug("Retrieving Solr intersection results for " + vclassURIs.toString());
|
||||
String alpha = IndividualListController.getAlphaParameter(vreq);
|
||||
int page = IndividualListController.getPageParameter(vreq);
|
||||
log.debug("Alpha and page parameters are " + alpha + " and " + page);
|
||||
Map<String,Object> map = null;
|
||||
try {
|
||||
map = IndividualListController.getResultsForVClassIntersections(
|
||||
return IndividualListController.getResultsForVClassIntersections(
|
||||
vclassURIs,
|
||||
page, INDIVIDUALS_PER_PAGE,
|
||||
alpha,
|
||||
|
@ -124,23 +117,10 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
context);
|
||||
} catch(Exception ex) {
|
||||
log.error("Error in retrieval of search results for VClass " + vclassURIs.toString(), ex);
|
||||
return IndividualListResults.EMPTY;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
// Map given to process method includes the actual individuals returned from the search
|
||||
// public static JSONObject processVClassResults(Map<String, Object> map, VitroRequest vreq, ServletContext context, boolean multipleVclasses) throws Exception{
|
||||
// JSONObject rObj = processVclassResultsJSON(map, vreq, multipleVclasses);
|
||||
// return rObj;
|
||||
// }
|
||||
|
||||
public static Collection<String> getMostSpecificTypes(Individual individual, WebappDaoFactory wdf) {
|
||||
ObjectPropertyStatementDao opsDao = wdf.getObjectPropertyStatementDao();
|
||||
Map<String, String> mostSpecificTypes = opsDao.getMostSpecificTypesInClassgroupsForIndividual(individual.getURI());
|
||||
return mostSpecificTypes.values();
|
||||
}
|
||||
|
||||
public static String getDataPropertyValue(Individual ind, DataProperty dp, WebappDaoFactory wdf){
|
||||
String value = ind.getDataValue(dp.getURI());
|
||||
if( value == null || value.isEmpty() )
|
||||
|
@ -152,21 +132,20 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
public static JSONObject getRandomSolrIndividualsByVClass(String vclassURI, HttpServletRequest req, ServletContext context) throws Exception {
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
|
||||
Map<String, Object> map = getRandomSolrVClassResults(vclassURI, vreq, context);
|
||||
IndividualListResults vcResults = getRandomSolrVClassResults(vclassURI, vreq, context);
|
||||
//last parameter indicates single vclass instead of multiple vclasses
|
||||
return processVclassResultsJSON(map, vreq, false);
|
||||
return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, false);
|
||||
}
|
||||
|
||||
//Including version for Random Solr query for Vclass Intersections
|
||||
private static Map<String,Object> getRandomSolrVClassResults(String vclassURI, VitroRequest vreq, ServletContext context){
|
||||
private static IndividualListResults getRandomSolrVClassResults(String vclassURI, VitroRequest vreq, ServletContext context){
|
||||
log.debug("Retrieving random Solr intersection results for " + vclassURI);
|
||||
|
||||
int page = IndividualListController.getPageParameter(vreq);
|
||||
int pageSize = Integer.parseInt(vreq.getParameter("pageSize"));
|
||||
log.debug("page and pageSize parameters = " + page + " and " + pageSize);
|
||||
Map<String,Object> map = null;
|
||||
try {
|
||||
map = IndividualListController.getRandomResultsForVClass(
|
||||
return IndividualListController.getRandomResultsForVClass(
|
||||
vclassURI,
|
||||
page,
|
||||
pageSize,
|
||||
|
@ -174,126 +153,8 @@ public class JsonServlet extends VitroHttpServlet {
|
|||
context);
|
||||
} catch(Exception ex) {
|
||||
log.error("Error in retrieval of search results for VClass " + vclassURI, ex);
|
||||
return IndividualListResults.EMPTY;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process results related to VClass or vclasses. Handles both single and multiple vclasses being sent.
|
||||
*/
|
||||
public static JSONObject processVclassResultsJSON(Map<String, Object> map, VitroRequest vreq, boolean multipleVclasses) {
|
||||
JSONObject rObj = new JSONObject();
|
||||
VClass vclass=null;
|
||||
|
||||
try {
|
||||
|
||||
// Properties from ontologies used by VIVO - should not be in vitro
|
||||
DataProperty fNameDp = (new DataProperty());
|
||||
fNameDp.setURI("http://xmlns.com/foaf/0.1/firstName");
|
||||
DataProperty lNameDp = (new DataProperty());
|
||||
lNameDp.setURI("http://xmlns.com/foaf/0.1/lastName");
|
||||
DataProperty preferredTitleDp = (new DataProperty());
|
||||
preferredTitleDp.setURI("http://vivoweb.org/ontology/core#preferredTitle");
|
||||
|
||||
if( log.isDebugEnabled() ){
|
||||
@SuppressWarnings("unchecked")
|
||||
Enumeration<String> e = vreq.getParameterNames();
|
||||
while(e.hasMoreElements()){
|
||||
String name = e.nextElement();
|
||||
log.debug("parameter: " + name);
|
||||
for( String value : vreq.getParameterValues(name) ){
|
||||
log.debug("value for " + name + ": '" + value + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//need an unfiltered dao to get firstnames and lastnames
|
||||
WebappDaoFactory fullWdf = vreq.getUnfilteredWebappDaoFactory();
|
||||
|
||||
String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
|
||||
if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){
|
||||
for(String vclassId: vitroClassIdStr) {
|
||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassId);
|
||||
if (vclass == null) {
|
||||
log.error("Couldn't retrieve vclass ");
|
||||
throw new Exception ("Class " + vclassId + " not found");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
log.error("parameter vclassId URI parameter expected ");
|
||||
throw new Exception("parameter vclassId URI parameter expected ");
|
||||
}
|
||||
List<String> vclassIds = Arrays.asList(vitroClassIdStr);
|
||||
//if single vclass expected, then include vclass. This relates to what the expected behavior is, not size of list
|
||||
if(!multipleVclasses) {
|
||||
//currently used for ClassGroupPage
|
||||
rObj.put("vclass",
|
||||
new JSONObject().put("URI",vclass.getURI())
|
||||
.put("name",vclass.getName()));
|
||||
} else {
|
||||
//For now, utilize very last VClass (assume that that is the one to be employed)
|
||||
//TODO: Find more general way of dealing with this
|
||||
//put multiple ones in?
|
||||
if(vclassIds.size() > 0) {
|
||||
int numberVClasses = vclassIds.size();
|
||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassIds.get(numberVClasses - 1));
|
||||
rObj.put("vclass", new JSONObject().put("URI",vclass.getURI())
|
||||
.put("name",vclass.getName()));
|
||||
}
|
||||
// rObj.put("vclasses", new JSONObject().put("URIs",vitroClassIdStr)
|
||||
// .put("name",vclass.getName()));
|
||||
}
|
||||
if (vclass != null) {
|
||||
|
||||
rObj.put("totalCount", map.get("totalCount"));
|
||||
rObj.put("alpha", map.get("alpha"));
|
||||
|
||||
List<Individual> inds = (List<Individual>)map.get("entities");
|
||||
log.debug("Number of individuals returned from request: " + inds.size());
|
||||
JSONArray jInds = new JSONArray();
|
||||
for(Individual ind : inds ){
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("URI", ind.getURI());
|
||||
jo.put("label",ind.getRdfsLabel());
|
||||
jo.put("name",ind.getName());
|
||||
jo.put("thumbUrl", ind.getThumbUrl());
|
||||
jo.put("imageUrl", ind.getImageUrl());
|
||||
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
|
||||
|
||||
jo.put("mostSpecificTypes", JsonServlet.getMostSpecificTypes(ind,fullWdf));
|
||||
jo.put("preferredTitle", JsonServlet.getDataPropertyValue(ind, preferredTitleDp, fullWdf));
|
||||
|
||||
jInds.put(jo);
|
||||
}
|
||||
rObj.put("individuals", jInds);
|
||||
|
||||
JSONArray wpages = new JSONArray();
|
||||
//Made sure that PageRecord here is SolrIndividualListController not IndividualListController
|
||||
List<PageRecord> pages = (List<PageRecord>)map.get("pages");
|
||||
for( PageRecord pr: pages ){
|
||||
JSONObject p = new JSONObject();
|
||||
p.put("text", pr.text);
|
||||
p.put("param", pr.param);
|
||||
p.put("index", pr.index);
|
||||
wpages.put( p );
|
||||
}
|
||||
rObj.put("pages",wpages);
|
||||
|
||||
JSONArray jletters = new JSONArray();
|
||||
List<String> letters = Controllers.getLetters();
|
||||
for( String s : letters){
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("text", s);
|
||||
jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
|
||||
jletters.put( jo );
|
||||
}
|
||||
rObj.put("letters", jletters);
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
log.error("Error occurred in processing JSON object", ex);
|
||||
}
|
||||
return rObj;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
|
||||
initBasics(conf, vreq);
|
||||
initPropertyParameters(vreq, session, conf);
|
||||
initObjectPropForm(conf, vreq);
|
||||
initObjectPropForm(conf, vreq);
|
||||
|
||||
conf.setTemplate(this.getTemplate());
|
||||
|
||||
|
@ -126,6 +126,7 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
formSpecificData.put("editMode", getEditMode(vreq).name().toLowerCase());
|
||||
formSpecificData.put("domainUri", getDomainUri(vreq));
|
||||
editConfiguration.setFormSpecificData(formSpecificData);
|
||||
}
|
||||
|
||||
|
@ -140,4 +141,10 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
}
|
||||
return editMode;
|
||||
}
|
||||
|
||||
private String getDomainUri(VitroRequest vreq) {
|
||||
String domainUri = vreq.getParameter("domainUri");
|
||||
|
||||
return domainUri;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_PREDICATE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_URI;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -24,14 +28,12 @@ import com.hp.hpl.jena.vocabulary.RDFS;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
|
@ -271,11 +273,10 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
|||
Individual individual = EditConfigurationUtils.getIndividual(vreq, config.getSubjectUri());
|
||||
AddDataPropertyStatement adps = new AddDataPropertyStatement(
|
||||
vreq.getJenaOntModel(), individual.getURI(),
|
||||
RequestActionConstants.SOME_URI);
|
||||
SOME_URI, SOME_LITERAL);
|
||||
AddObjectPropertyStatement aops = new AddObjectPropertyStatement(
|
||||
vreq.getJenaOntModel(), individual.getURI(),
|
||||
RequestActionConstants.SOME_PREDICATE,
|
||||
RequestActionConstants.SOME_URI);
|
||||
SOME_PREDICATE, SOME_URI);
|
||||
return PolicyHelper.isAuthorizedForActions(vreq, new Actions(adps).or(aops));
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,15 @@ public class PostEditCleanupController extends FreemarkerHttpServlet{
|
|||
return new RedirectResponseValues( UrlBuilder.getHomeUrl() );
|
||||
}
|
||||
|
||||
//In some cases, a generator/form may have a regular URL to return to but the same generator
|
||||
//may be used from different pages, so a parameter allowing the form to return to a specific page
|
||||
//would be useful
|
||||
|
||||
String returnURLParameter = vreq.getParameter("returnURL");
|
||||
if(returnURLParameter != null) {
|
||||
return new DirectRedirectResponseValues( returnURLParameter );
|
||||
}
|
||||
|
||||
// If there is a urlToReturnTo that takes precedence
|
||||
if( editConfig.getUrlToReturnTo() != null && ! editConfig.getUrlToReturnTo().trim().isEmpty()){
|
||||
//this does not get value substitution or the predicate anchor
|
||||
|
|
|
@ -439,9 +439,13 @@ public class FakeApplicationOntologyService {
|
|||
* "display model". The query finds a preferred title for the individual.
|
||||
*/
|
||||
private static class FakeVivoPeopleDataGetter extends SparqlQueryDataGetter {
|
||||
private static final String QUERY_STRING = "SELECT ?uri ?pt WHERE {\n"
|
||||
+ " ?uri <http://vivoweb.org/ontology/core#preferredTitle> ?pt\n"
|
||||
+ "} LIMIT 1";
|
||||
private static String QUERY_STRING = ""
|
||||
+ "PREFIX obo: <http://purl.obolibrary.org/obo/> \n"
|
||||
+ "PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> \n"
|
||||
+ "SELECT ?uri ?pt \n" + "WHERE { \n"
|
||||
+ " ?uri obo:ARG_2000028 ?vIndividual . \n"
|
||||
+ " ?vIndividual vcard:hasTitle ?vTitle . \n"
|
||||
+ " ?vTitle vcard:title ?pt . \n" + "} LIMIT 1";
|
||||
|
||||
private static final String FAKE_VIVO_PEOPLE_DATA_GETTER_URI = "http://FakeVivoPeopleDataGetter";
|
||||
|
||||
|
|
|
@ -188,6 +188,7 @@ public class FileGraphSetup implements ServletContextListener {
|
|||
baseModel.add(model);
|
||||
}
|
||||
log.info("Attached file graph as " + type + " submodel " + p.getFileName());
|
||||
|
||||
}
|
||||
|
||||
modelChanged = modelChanged | updateGraphInDB(dataset, model, type, p);
|
||||
|
|
|
@ -87,14 +87,23 @@ public class RDFFilesLoader {
|
|||
OntModel model) {
|
||||
OntModel everytimeModel = ModelFactory
|
||||
.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Set<Path> paths = getPaths(locateHomeDirectory(ctx), RDF, modelPath,
|
||||
EVERY_TIME);
|
||||
String home = locateHomeDirectory(ctx);
|
||||
Set<Path> paths = getPaths(home, RDF, modelPath, EVERY_TIME);
|
||||
for (Path p : paths) {
|
||||
log.info("Loading " + relativePath(p, home));
|
||||
readOntologyFileIntoModel(p, everytimeModel);
|
||||
}
|
||||
model.addSubModel(everytimeModel);
|
||||
}
|
||||
|
||||
private static Path relativePath(Path p, String home) {
|
||||
try {
|
||||
return Paths.get(home).relativize(p);
|
||||
} catch (Exception e) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a model from all the RDF files in the specified directory.
|
||||
*/
|
||||
|
@ -148,7 +157,7 @@ public class RDFFilesLoader {
|
|||
|
||||
private static void readOntologyFileIntoModel(Path p, Model model) {
|
||||
String format = getRdfFormat(p);
|
||||
log.info("Loading "+ p);
|
||||
log.debug("Loading "+ p);
|
||||
try (InputStream stream = new FileInputStream(p.toFile())) {
|
||||
model.read(stream, null, format);
|
||||
log.debug("...successful");
|
||||
|
|
|
@ -3,10 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
|
|||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -17,7 +14,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
|
@ -35,20 +31,13 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
|||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.json.JsonServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||
|
||||
|
||||
|
@ -324,123 +313,6 @@ public class DataGetterUtils {
|
|||
return classGroupUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process results related to VClass or vclasses. Handles both single and multiple vclasses being sent.
|
||||
*/
|
||||
public static JSONObject processVclassResultsJSON(Map<String, Object> map, VitroRequest vreq, boolean multipleVclasses) {
|
||||
JSONObject rObj = new JSONObject();
|
||||
VClass vclass=null;
|
||||
|
||||
try {
|
||||
|
||||
// Properties from ontologies used by VIVO - should not be in vitro
|
||||
DataProperty fNameDp = (new DataProperty());
|
||||
fNameDp.setURI("http://xmlns.com/foaf/0.1/firstName");
|
||||
DataProperty lNameDp = (new DataProperty());
|
||||
lNameDp.setURI("http://xmlns.com/foaf/0.1/lastName");
|
||||
DataProperty preferredTitleDp = (new DataProperty());
|
||||
preferredTitleDp.setURI("http://vivoweb.org/ontology/core#preferredTitle");
|
||||
|
||||
if( log.isDebugEnabled() ){
|
||||
@SuppressWarnings("unchecked")
|
||||
Enumeration<String> e = vreq.getParameterNames();
|
||||
while(e.hasMoreElements()){
|
||||
String name = e.nextElement();
|
||||
log.debug("parameter: " + name);
|
||||
for( String value : vreq.getParameterValues(name) ){
|
||||
log.debug("value for " + name + ": '" + value + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//need an unfiltered dao to get firstnames and lastnames
|
||||
WebappDaoFactory fullWdf = vreq.getUnfilteredWebappDaoFactory();
|
||||
|
||||
String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
|
||||
if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){
|
||||
for(String vclassId: vitroClassIdStr) {
|
||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassId);
|
||||
if (vclass == null) {
|
||||
log.error("Couldn't retrieve vclass ");
|
||||
throw new Exception ("Class " + vclassId + " not found");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
log.error("parameter vclassId URI parameter expected ");
|
||||
throw new Exception("parameter vclassId URI parameter expected ");
|
||||
}
|
||||
List<String> vclassIds = Arrays.asList(vitroClassIdStr);
|
||||
//if single vclass expected, then include vclass. This relates to what the expected behavior is, not size of list
|
||||
if(!multipleVclasses) {
|
||||
//currently used for ClassGroupPage
|
||||
rObj.put("vclass",
|
||||
new JSONObject().put("URI",vclass.getURI())
|
||||
.put("name",vclass.getName()));
|
||||
} else {
|
||||
//For now, utilize very last VClass (assume that that is the one to be employed)
|
||||
//TODO: Find more general way of dealing with this
|
||||
//put multiple ones in?
|
||||
if(vclassIds.size() > 0) {
|
||||
int numberVClasses = vclassIds.size();
|
||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassIds.get(numberVClasses - 1));
|
||||
rObj.put("vclass", new JSONObject().put("URI",vclass.getURI())
|
||||
.put("name",vclass.getName()));
|
||||
}
|
||||
// rObj.put("vclasses", new JSONObject().put("URIs",vitroClassIdStr)
|
||||
// .put("name",vclass.getName()));
|
||||
}
|
||||
if (vclass != null) {
|
||||
|
||||
rObj.put("totalCount", map.get("totalCount"));
|
||||
rObj.put("alpha", map.get("alpha"));
|
||||
|
||||
List<Individual> inds = (List<Individual>)map.get("entities");
|
||||
log.debug("Number of individuals returned from request: " + inds.size());
|
||||
JSONArray jInds = new JSONArray();
|
||||
for(Individual ind : inds ){
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("URI", ind.getURI());
|
||||
jo.put("label",ind.getRdfsLabel());
|
||||
jo.put("name",ind.getName());
|
||||
jo.put("thumbUrl", ind.getThumbUrl());
|
||||
jo.put("imageUrl", ind.getImageUrl());
|
||||
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
|
||||
|
||||
jo.put("mostSpecificTypes", JsonServlet.getMostSpecificTypes(ind,fullWdf));
|
||||
jo.put("preferredTitle", JsonServlet.getDataPropertyValue(ind, preferredTitleDp, fullWdf));
|
||||
|
||||
jInds.put(jo);
|
||||
}
|
||||
rObj.put("individuals", jInds);
|
||||
|
||||
JSONArray wpages = new JSONArray();
|
||||
//Made sure that PageRecord here is SolrIndividualListController not IndividualListController
|
||||
List<PageRecord> pages = (List<PageRecord>)map.get("pages");
|
||||
for( PageRecord pr: pages ){
|
||||
JSONObject p = new JSONObject();
|
||||
p.put("text", pr.text);
|
||||
p.put("param", pr.param);
|
||||
p.put("index", pr.index);
|
||||
wpages.put( p );
|
||||
}
|
||||
rObj.put("pages",wpages);
|
||||
|
||||
JSONArray jletters = new JSONArray();
|
||||
List<String> letters = Controllers.getLetters();
|
||||
for( String s : letters){
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("text", s);
|
||||
jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
|
||||
jletters.put( jo );
|
||||
}
|
||||
rObj.put("letters", jletters);
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
log.error("Error occurred in processing JSON object", ex);
|
||||
}
|
||||
return rObj;
|
||||
}
|
||||
|
||||
private static final String forClassGroupURI = "<" + DisplayVocabulary.FOR_CLASSGROUP + ">";
|
||||
|
||||
private static final String classGroupForDataGetterQuery =
|
||||
|
|
|
@ -353,14 +353,15 @@ public class IndividualsForClassesDataGetter extends DataGetterBase implements D
|
|||
public String getDataServiceUrl() {
|
||||
return UrlBuilder.getUrl("/dataservice?getRenderedSolrIndividualsByVClass=1&vclassId=");
|
||||
}
|
||||
|
||||
/**
|
||||
* For processig of JSONObject
|
||||
*/
|
||||
public JSONObject convertToJSON(Map<String, Object> map, VitroRequest vreq) {
|
||||
JSONObject rObj = DataGetterUtils.processVclassResultsJSON(map, vreq, true);
|
||||
public JSONObject convertToJSON(Map<String, Object> dataMap, VitroRequest vreq) {
|
||||
JSONObject rObj = null;
|
||||
return rObj;
|
||||
}
|
||||
|
||||
|
||||
protected static void setAllClassCountsToZero(VClassGroup vcg){
|
||||
for(VClass vc : vcg){
|
||||
vc.setEntityCount(0);
|
||||
|
|
|
@ -3,9 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -23,7 +21,6 @@ import com.hp.hpl.jena.query.QuerySolutionMap;
|
|||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
|
@ -33,8 +30,9 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.SearchException;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
|
||||
|
@ -174,16 +172,15 @@ public class SolrIndividualsDataGetter extends DataGetterBase implements DataGet
|
|||
try {
|
||||
String alpha = SolrQueryUtils.getAlphaParameter(vreq);
|
||||
int page = SolrQueryUtils.getPageParameter(vreq);
|
||||
Map<String,Object> map = IndividualListController.getResultsForVClass(
|
||||
IndividualListResults vcResults = IndividualListController.getResultsForVClass(
|
||||
vclass.getURI(),
|
||||
page,
|
||||
alpha,
|
||||
vreq.getWebappDaoFactory().getIndividualDao(),
|
||||
vreq.getSession().getServletContext());
|
||||
body.putAll(map);
|
||||
body.putAll(vcResults.asFreemarkerMap());
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Individual> inds = (List<Individual>)map.get("entities");
|
||||
List<Individual> inds = vcResults.getEntities();
|
||||
List<ListedIndividual> indsTm = new ArrayList<ListedIndividual>();
|
||||
if (inds != null) {
|
||||
for ( Individual ind : inds ) {
|
||||
|
|
|
@ -4,8 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.utils.solr;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -20,9 +18,7 @@ import org.apache.solr.client.solrj.SolrServerException;
|
|||
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListQueryResults;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.SearchException;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
|
||||
|
|
|
@ -666,7 +666,13 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
|||
//this url is for canceling
|
||||
public String getCancelUrl() {
|
||||
String editKey = editConfig.getEditKey();
|
||||
return EditConfigurationUtils.getCancelUrlBase(vreq) + "?editKey=" + editKey + "&cancel=true";
|
||||
String cancelURL = EditConfigurationUtils.getCancelUrlBase(vreq) + "?editKey=" + editKey + "&cancel=true";
|
||||
//Check for special return url parameter
|
||||
String returnURLParameter = vreq.getParameter("returnURL");
|
||||
if(returnURLParameter != null && !returnURLParameter.isEmpty() ) {
|
||||
cancelURL += "&returnURL=" + returnURLParameter;
|
||||
}
|
||||
return cancelURL;
|
||||
}
|
||||
|
||||
//Get confirm deletion url
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_PREDICATE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_URI;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -16,7 +20,6 @@ import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
|
@ -116,11 +119,10 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
|||
public boolean isEditable() {
|
||||
AddDataPropertyStatement adps = new AddDataPropertyStatement(
|
||||
vreq.getJenaOntModel(), individual.getURI(),
|
||||
RequestActionConstants.SOME_URI);
|
||||
SOME_URI, SOME_LITERAL);
|
||||
AddObjectPropertyStatement aops = new AddObjectPropertyStatement(
|
||||
vreq.getJenaOntModel(), individual.getURI(),
|
||||
RequestActionConstants.SOME_PREDICATE,
|
||||
RequestActionConstants.SOME_URI);
|
||||
SOME_PREDICATE, SOME_URI);
|
||||
return PolicyHelper.isAuthorizedForActions(vreq, new Actions(adps).or(aops));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -118,7 +120,7 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
|||
|
||||
// Determine whether a new statement can be added
|
||||
RequestedAction action = new AddDataPropertyStatement(
|
||||
vreq.getJenaOntModel(), subjectUri, propertyUri);
|
||||
vreq.getJenaOntModel(), subjectUri, propertyUri, SOME_LITERAL);
|
||||
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue