NIHVIVO-3510 fixed bugs introduced in updating sparql query builder to generate prefixes

This commit is contained in:
brianjlowe 2011-12-15 17:36:37 +00:00
parent abf72d6924
commit 5966c5e945
2 changed files with 18 additions and 14 deletions

View file

@ -3,9 +3,10 @@ package edu.cornell.mannlib.vitro.webapp.sparql;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -69,8 +70,11 @@ public class GetAllPrefix extends BaseEditController {
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
respo += "<options>"; respo += "<options>";
for (String namespace : prefixMap.keySet()) { List<String> prefixList = new ArrayList<String>();
respo += makeOption(prefixMap.get(namespace), namespace); prefixList.addAll(prefixMap.keySet());
Collections.sort(prefixList, Collator.getInstance());
for (String prefix : prefixList) {
respo += makeOption(prefix, prefixMap.get(prefix));
} }
respo += "</options>"; respo += "</options>";
out.println(respo); out.println(respo);
@ -79,11 +83,11 @@ public class GetAllPrefix extends BaseEditController {
} }
/** /**
* Returns a map to prefixes for use in building queries. Will manufacture a * Returns a map of prefixes for use in building queries. Will manufacture a
* prefix for any namespace that doesn't have an associated owl:Ontology resource * prefix for any namespace that doesn't have an associated owl:Ontology resource
* with a prefix annotation * with a prefix annotation
* @param wadf * @param wadf
* @return map of namespace URIs to prefix strings * @return map of prefix strings to namespace URIs
*/ */
private Map<String, String> getPrefixMap(WebappDaoFactory wadf) { private Map<String, String> getPrefixMap(WebappDaoFactory wadf) {
Map<String, String> prefixMap = new HashMap<String, String>(); Map<String, String> prefixMap = new HashMap<String, String>();
@ -113,10 +117,10 @@ public class GetAllPrefix extends BaseEditController {
ontEntityList.addAll(wadf.getDataPropertyDao().getAllDataProperties()); ontEntityList.addAll(wadf.getDataPropertyDao().getAllDataProperties());
for (BaseResourceBean ontEntity : ontEntityList) { for (BaseResourceBean ontEntity : ontEntityList) {
if (!ontEntity.isAnonymous() if (!ontEntity.isAnonymous()
&& !prefixMap.containsKey(ontEntity.getNamespace())) { && !prefixMap.containsValue(ontEntity.getNamespace())) {
newPrefixCount++; newPrefixCount++;
prefixMap.put(ontEntity.getNamespace(), "p." + Integer.toString( prefixMap.put("p." + Integer.toString(
newPrefixCount)); newPrefixCount), ontEntity.getNamespace());
} }
} }
@ -125,8 +129,8 @@ public class GetAllPrefix extends BaseEditController {
private void addPrefixIfNecessary(String prefix, String namespace, private void addPrefixIfNecessary(String prefix, String namespace,
Map<String, String> prefixMap) { Map<String, String> prefixMap) {
if (!prefixMap.containsKey(namespace)) { if (!prefixMap.containsValue(namespace)) {
prefixMap.put(namespace, prefix); prefixMap.put(prefix, namespace);
} }
} }

View file

@ -22,10 +22,10 @@
var myAjax = new Ajax.Request( url, {method: "get", parameters: "", onComplete: function(originalRequest){ var myAjax = new Ajax.Request( url, {method: "get", parameters: "", onComplete: function(originalRequest){
var response = originalRequest.responseXML; var response = originalRequest.responseXML;
var options = response.getElementsByTagName("option"); var options = response.getElementsByTagName("option");
if (options == null || options.length == 0){ // if (options == null || options.length == 0){
alert("Error: Cannot get all the classes."); // alert("Error: Cannot get all the classes.");
return; // return;
} // }
for(i=0; i<options.length; i++){ for(i=0; i<options.length; i++){
base[base.length] = new Option(options[i].childNodes[0].firstChild.data, options[i].childNodes[1].firstChild.data); base[base.length] = new Option(options[i].childNodes[0].firstChild.data, options[i].childNodes[1].firstChild.data);
} }