SPARQL Query Builder with one property button.
This commit is contained in:
parent
2e137e316b
commit
62aae75893
3 changed files with 222 additions and 115 deletions
|
@ -1329,6 +1329,15 @@
|
||||||
<servlet-name>GetClazzDataProperties</servlet-name>
|
<servlet-name>GetClazzDataProperties</servlet-name>
|
||||||
<url-pattern>/admin/getClazzDataProperties</url-pattern>
|
<url-pattern>/admin/getClazzDataProperties</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>GetClazzAllProperties</servlet-name>
|
||||||
|
<servlet-class>edu.cornell.mannlib.vitro.webapp.sparql.GetClazzAllProperties</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>GetClazzAllProperties</servlet-name>
|
||||||
|
<url-pattern>/admin/getClazzAllProperties</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>GetClazzObjectProperties</servlet-name>
|
<servlet-name>GetClazzObjectProperties</servlet-name>
|
||||||
|
|
|
@ -0,0 +1,177 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.sparql;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||||
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.edit.SiteAdminController;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This servlet gets all the properties for a given subject.
|
||||||
|
*
|
||||||
|
* @param vClassURI
|
||||||
|
* @author yuysun
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GetClazzAllProperties extends BaseEditController {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(SiteAdminController.class
|
||||||
|
.getName());
|
||||||
|
|
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
super.doGet(request, response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (!checkLoginStatus(request, response))
|
||||||
|
return;
|
||||||
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
|
|
||||||
|
String vClassURI = vreq.getParameter("vClassURI");
|
||||||
|
if (vClassURI == null || vClassURI.trim().equals("")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
||||||
|
respo += "<options>";
|
||||||
|
|
||||||
|
// Get Data Properties
|
||||||
|
// Add rdfs:label to the list
|
||||||
|
respo += "<option>"
|
||||||
|
+ "<key>" + "label" + "</key>"
|
||||||
|
+ "<value>" + "http://www.w3.org/2000/01/rdf-schema#label" + "</value>"
|
||||||
|
+ "<type>0</type>"
|
||||||
|
+ "</option>";
|
||||||
|
|
||||||
|
DataPropertyDao ddao = vreq.getFullWebappDaoFactory()
|
||||||
|
.getDataPropertyDao();
|
||||||
|
|
||||||
|
Collection<DataProperty> dataProps = ddao
|
||||||
|
.getDataPropertiesForVClass(vClassURI);
|
||||||
|
Iterator<DataProperty> dataPropIt = dataProps.iterator();
|
||||||
|
HashSet<String> dpropURIs = new HashSet<String>();
|
||||||
|
while (dataPropIt.hasNext()) {
|
||||||
|
DataProperty dp = dataPropIt.next();
|
||||||
|
if (!(dpropURIs.contains(dp.getURI()))) {
|
||||||
|
dpropURIs.add(dp.getURI());
|
||||||
|
DataProperty dprop = (DataProperty) ddao
|
||||||
|
.getDataPropertyByURI(dp.getURI());
|
||||||
|
if (dprop != null) {
|
||||||
|
respo += "<option>"
|
||||||
|
+ "<key>" + dprop.getLocalName() + "</key>"
|
||||||
|
+ "<value>" + dprop.getURI() + "</value>"
|
||||||
|
+ "<type>0</type>"
|
||||||
|
+ "</option>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Object Properties
|
||||||
|
|
||||||
|
ObjectPropertyDao odao = vreq.getFullWebappDaoFactory()
|
||||||
|
.getObjectPropertyDao();
|
||||||
|
PropertyInstanceDao piDao = vreq.getFullWebappDaoFactory()
|
||||||
|
.getPropertyInstanceDao();
|
||||||
|
VClassDao vcDao = vreq.getFullWebappDaoFactory().getVClassDao();
|
||||||
|
|
||||||
|
// incomplete list of classes to check, but better than before
|
||||||
|
List<String> superclassURIs = vcDao.getAllSuperClassURIs(vClassURI);
|
||||||
|
superclassURIs.add(vClassURI);
|
||||||
|
superclassURIs.addAll(vcDao.getEquivalentClassURIs(vClassURI));
|
||||||
|
|
||||||
|
Map<String, PropertyInstance> propInstMap = new HashMap<String, PropertyInstance>();
|
||||||
|
for (String classURI : superclassURIs) {
|
||||||
|
Collection<PropertyInstance> propInsts = piDao
|
||||||
|
.getAllPropInstByVClass(classURI);
|
||||||
|
try {
|
||||||
|
for (PropertyInstance propInst : propInsts) {
|
||||||
|
propInstMap.put(propInst.getPropertyURI(), propInst);
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<PropertyInstance> propInsts = new ArrayList<PropertyInstance>();
|
||||||
|
propInsts.addAll(propInstMap.values());
|
||||||
|
Collections.sort(propInsts);
|
||||||
|
|
||||||
|
Iterator propInstIt = propInsts.iterator();
|
||||||
|
HashSet opropURIs = new HashSet();
|
||||||
|
while (propInstIt.hasNext()) {
|
||||||
|
PropertyInstance pi = (PropertyInstance) propInstIt.next();
|
||||||
|
if (!(opropURIs.contains(pi.getPropertyURI()))) {
|
||||||
|
opropURIs.add(pi.getPropertyURI());
|
||||||
|
ObjectProperty oprop = (ObjectProperty) odao
|
||||||
|
.getObjectPropertyByURI(pi.getPropertyURI());
|
||||||
|
if (oprop != null) {
|
||||||
|
respo += "<option>"
|
||||||
|
+ "<key>" + oprop.getLocalName() + "</key>"
|
||||||
|
+ "<value>" + oprop.getURI() + "</value>"
|
||||||
|
+ "<type>1</type>"
|
||||||
|
+ "</option>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
respo += "</options>";
|
||||||
|
response.setContentType("text/xml");
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
PrintWriter out = response.getWriter();
|
||||||
|
|
||||||
|
out.println(respo);
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The doPost method of the servlet. <br>
|
||||||
|
*
|
||||||
|
* This method is called when a form has its tag value method equals to
|
||||||
|
* post.
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the request send by the client to the server
|
||||||
|
* @param response
|
||||||
|
* the response send by the server to the client
|
||||||
|
* @throws ServletException
|
||||||
|
* if an error occurred
|
||||||
|
* @throws IOException
|
||||||
|
* if an error occurred
|
||||||
|
*/
|
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
|
||||||
|
doGet(request, response);
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,22 +32,14 @@
|
||||||
subdiv.appendChild(document.createElement("br"));
|
subdiv.appendChild(document.createElement("br"));
|
||||||
|
|
||||||
|
|
||||||
var adddprop = document.createElement("input");
|
var addprop = document.createElement("input");
|
||||||
adddprop.type = "button";
|
addprop.type = "button";
|
||||||
adddprop.value = "Add Data Property";
|
addprop.value = "Add Property";
|
||||||
adddprop.level = 0;
|
addprop.level = 0;
|
||||||
adddprop.onclick = function() {
|
addprop.onclick = function() {
|
||||||
return getDataProperty(this);
|
return getProperty(this);
|
||||||
}
|
}
|
||||||
subdiv.appendChild(adddprop);
|
subdiv.appendChild(addprop);
|
||||||
var addoprop = document.createElement("input");
|
|
||||||
addoprop.type = "button";
|
|
||||||
addoprop.value = "Add Object Property";
|
|
||||||
addoprop.level = 0;
|
|
||||||
addoprop.onclick = function() {
|
|
||||||
return getObjectProperty(this);
|
|
||||||
}
|
|
||||||
subdiv.appendChild(addoprop);
|
|
||||||
level ++;
|
level ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,9 +60,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getDataProperty(addprop){
|
function getProperty(addprop){
|
||||||
|
|
||||||
var url = "getClazzDataProperties";
|
var url = "getClazzAllProperties";
|
||||||
var base = document.getElementById("subject(" + addprop.level + ",0)");
|
var base = document.getElementById("subject(" + addprop.level + ",0)");
|
||||||
var subject = base.value;
|
var subject = base.value;
|
||||||
if (subject == ""){
|
if (subject == ""){
|
||||||
|
@ -89,89 +81,8 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(i=0; i<options.length; i++){
|
for(i=0; i<options.length; i++){
|
||||||
property[property.length] = new Option(options[i].childNodes[0].firstChild.data, options[i].childNodes[1].firstChild.data);
|
property[property.length] = new Option(options[i].childNodes[0].firstChild.data, options[i].childNodes[1].firstChild.data + options[i].childNodes[2].firstChild.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
property.level = base.level;
|
|
||||||
property.count = base.count;
|
|
||||||
|
|
||||||
property.onchange = function() {
|
|
||||||
return getData(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
var prediv = document.getElementById("predicate(" + base.level + ")");
|
|
||||||
|
|
||||||
if (prediv.innerHTML.trim() != "") {
|
|
||||||
var lastNode = prediv.lastChild.previousSibling;
|
|
||||||
if (lastNode.selectedIndex == 0){
|
|
||||||
alert("You have a undefined property, please make sure it has been initialized.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
prediv.appendChild(property);
|
|
||||||
|
|
||||||
base.count += 1
|
|
||||||
prediv.appendChild(document.createElement("br"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getData(property){
|
|
||||||
var base = document.getElementById("subject(" + property.level + ",0)")
|
|
||||||
var subject = base.value;
|
|
||||||
|
|
||||||
//Disable the selection
|
|
||||||
property.disabled = true;
|
|
||||||
|
|
||||||
//DEL PROPERTY
|
|
||||||
var delprop = document.createElement("input");
|
|
||||||
delprop.type = "button";
|
|
||||||
delprop.value = "Delete";
|
|
||||||
delprop.count = base.count - 1;
|
|
||||||
delprop.level = base.level;
|
|
||||||
delprop.onclick = function() {
|
|
||||||
return delProperty(this);
|
|
||||||
}
|
|
||||||
var prediv = document.getElementById("predicate(" + base.level + ")");
|
|
||||||
prediv.insertBefore(delprop, property.nextSibling);
|
|
||||||
var objdiv = document.getElementById("object(" + base.level + ")");
|
|
||||||
var dataprop = document.createElement("input");
|
|
||||||
dataprop.type = "text";
|
|
||||||
dataprop.size = 50;
|
|
||||||
dataprop.count = base.count - 1;
|
|
||||||
dataprop.level = base.level;
|
|
||||||
dataprop.id = "object(" + base.level + "," + (base.count - 1) + ")";
|
|
||||||
objdiv.appendChild(dataprop);
|
|
||||||
objdiv.appendChild(document.createElement("br"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getObjectProperty(addprop){
|
|
||||||
|
|
||||||
var url = "getClazzObjectProperties";
|
|
||||||
var base = document.getElementById("subject(" + addprop.level + ",0)");
|
|
||||||
var subject = base.value;
|
|
||||||
if (subject == ""){
|
|
||||||
alert("Please select a class.");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
var params = "vClassURI=" + subject.replace('#', '%23');
|
|
||||||
var myAjax = new Ajax.Request( url, {method: "get", parameters: params, onComplete: function(originalRequest){
|
|
||||||
var response = originalRequest.responseXML;
|
|
||||||
var property = document.createElement("select");
|
|
||||||
property.id = "predicate(" + base.level + "," + base.count + ")";
|
|
||||||
property[property.length] = new Option("Properties", "");
|
|
||||||
var options = response.getElementsByTagName('option');
|
|
||||||
if (options == null || options.length == 0){
|
|
||||||
alert("Error: Cannot get object properties for " + subject + ".");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for(i=0; i<options.length; i++){
|
|
||||||
property[property.length] = new Option(options[i].childNodes[0].firstChild.data, options[i].childNodes[1].firstChild.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
property.level = base.level;
|
property.level = base.level;
|
||||||
property.count = base.count;
|
property.count = base.count;
|
||||||
|
|
||||||
|
@ -180,6 +91,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var prediv = document.getElementById("predicate(" + base.level + ")");
|
var prediv = document.getElementById("predicate(" + base.level + ")");
|
||||||
|
|
||||||
if (prediv.innerHTML.trim() != "") {
|
if (prediv.innerHTML.trim() != "") {
|
||||||
var lastNode = prediv.lastChild.previousSibling;
|
var lastNode = prediv.lastChild.previousSibling;
|
||||||
if (lastNode.selectedIndex == 0){
|
if (lastNode.selectedIndex == 0){
|
||||||
|
@ -198,6 +110,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getObject(property){
|
function getObject(property){
|
||||||
var url = "getObjectClasses";
|
var url = "getObjectClasses";
|
||||||
|
|
||||||
|
@ -221,7 +134,20 @@
|
||||||
|
|
||||||
|
|
||||||
var predicate = property.value;
|
var predicate = property.value;
|
||||||
|
var type = predicate.charAt(predicate.length-1);
|
||||||
|
predicate = predicate.substring(0, predicate.length-1);
|
||||||
|
if (type == '0') {
|
||||||
|
var objdiv = document.getElementById("object(" + base.level + ")");
|
||||||
|
var dataprop = document.createElement("input");
|
||||||
|
dataprop.type = "text";
|
||||||
|
dataprop.size = 50;
|
||||||
|
dataprop.count = base.count - 1;
|
||||||
|
dataprop.level = base.level;
|
||||||
|
dataprop.id = "object(" + base.level + "," + (base.count - 1) + ")";
|
||||||
|
objdiv.appendChild(dataprop);
|
||||||
|
objdiv.appendChild(document.createElement("br"));
|
||||||
|
}
|
||||||
|
else{
|
||||||
var params = "predicate=" + predicate.replace('#', '%23');
|
var params = "predicate=" + predicate.replace('#', '%23');
|
||||||
|
|
||||||
var myAjax = new Ajax.Request( url, {method: "get", parameters: params, onComplete: function(originalRequest){
|
var myAjax = new Ajax.Request( url, {method: "get", parameters: params, onComplete: function(originalRequest){
|
||||||
|
@ -283,6 +209,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addClass(obj){
|
function addClass(obj){
|
||||||
|
@ -313,22 +241,14 @@
|
||||||
}
|
}
|
||||||
subdiv.appendChild(delclazz);
|
subdiv.appendChild(delclazz);
|
||||||
subdiv.appendChild(document.createElement("br"));
|
subdiv.appendChild(document.createElement("br"));
|
||||||
var adddprop = document.createElement("input");
|
var addprop = document.createElement("input");
|
||||||
adddprop.type = "button";
|
addprop.type = "button";
|
||||||
adddprop.value = "Add Data Property";
|
addprop.value = "Add Property";
|
||||||
adddprop.level = subject.level;
|
addprop.level = subject.level;
|
||||||
adddprop.onclick = function() {
|
addprop.onclick = function() {
|
||||||
return getDataProperty(this);
|
return getProperty(this);
|
||||||
}
|
}
|
||||||
subdiv.appendChild(adddprop);
|
subdiv.appendChild(addprop);
|
||||||
var addoprop = document.createElement("input");
|
|
||||||
addoprop.type = "button";
|
|
||||||
addoprop.value = "Add Object Property";
|
|
||||||
addoprop.level = subject.level;
|
|
||||||
addoprop.onclick = function() {
|
|
||||||
return getObjectProperty(this);
|
|
||||||
}
|
|
||||||
subdiv.appendChild(addoprop);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,6 +336,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pre = pre.value;
|
pre = pre.value;
|
||||||
|
pre = pre.substring(0, pre.length-1);
|
||||||
pre = getNameWithPrefix(pre);
|
pre = getNameWithPrefix(pre);
|
||||||
if (obj.tagName == "INPUT"){
|
if (obj.tagName == "INPUT"){
|
||||||
var objname = subname + "_" + pre.substring(pre.indexOf(":") + 1);
|
var objname = subname + "_" + pre.substring(pre.indexOf(":") + 1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue