VIVO-922: updates for new faux listing functionality. New controller, template and js file, updated web.xml and site admin page, and updates to the all.properties

This commit is contained in:
Tim Worrall 2014-12-05 16:57:09 -05:00
parent 4da345d843
commit b8cb95d252
8 changed files with 400 additions and 2 deletions

View file

@ -874,4 +874,10 @@ view_labels_for = Ver Etiquetas de
select_an_existing_document = Seleccione un documento existente
datetime_year_required = Intervalos de fecha / hora deben empezar por un año. Ingrese una Fecha de inicio, un fin de año o los dos.
select_a_language = Seleccione un idioma
select_a_language = Seleccione un idioma
base_property_capitalized = Base propiedad
faux_property_capitalized = Faux propiedad
faux_property_listing = Lista de faux propiedades
faux_property_by_base = Faux propiedades por base propriedad
faux_property_alpha = Faux propiedades en orden alfabético

View file

@ -187,6 +187,7 @@ public class BaseSiteAdminController extends FreemarkerHttpServlet {
urls.put("classHierarchy", UrlBuilder.getUrl("/showClassHierarchy"));
urls.put("classGroups", UrlBuilder.getUrl("/listGroups"));
urls.put("dataPropertyHierarchy", UrlBuilder.getUrl("/showDataPropertyHierarchy"));
urls.put("fauxPropertyList", UrlBuilder.getUrl("/listFauxProperties"));
urls.put("propertyGroups", UrlBuilder.getUrl("/listPropertyGroups"));
urls.put("objectPropertyHierarchy", UrlBuilder.getUrl("/showObjectPropertyHierarchy", new ParamMap("iffRoot", "true")));
map.put("urls", urls);

View file

@ -0,0 +1,233 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import net.sf.json.util.JSONUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
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.dao.FauxPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
public class ListFauxPropertiesController extends FreemarkerHttpServlet {
private static final Log log = LogFactory.getLog(ListFauxPropertiesController.class.getName());
private static final String TEMPLATE_NAME = "siteAdmin-fauxPropertiesList.ftl";
private ObjectPropertyDao opDao = null;
private PropertyGroupDao pgDao = null;
private FauxPropertyDao fpDao = null;
private String notFoundMessage = "";
@Override
protected AuthorizationRequest requiredActions(VitroRequest vreq) {
return SimplePermission.EDIT_ONTOLOGY.ACTION;
}
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
Map<String, Object> body = new HashMap<String, Object>();
try {
String displayOption = "";
if ( vreq.getParameter("displayOption") != null ) {
displayOption = vreq.getParameter("displayOption");
}
else {
displayOption = "listing";
}
body.put("displayOption", displayOption);
if ( displayOption.equals("listing") ) {
body.put("pageTitle", "Faux Property Listing");
}
else {
body.put("pageTitle", "Faux Properties by Base Property");
}
opDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getObjectPropertyDao();
fpDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getFauxPropertyDao();
pgDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getPropertyGroupDao();
List<ObjectProperty> objectProps = null;
objectProps = opDao.getRootObjectProperties();
Map<String, Object> allFauxProps = new TreeMap<String, Object>();
// get the faux depending on the display option
if ( displayOption.equals("listing") ) {
allFauxProps = getFauxPropertyList(objectProps);
}
else {
allFauxProps = getFauxByBaseList(objectProps);
}
log.debug(allFauxProps.toString());
if ( notFoundMessage.length() == 0 ) {
body.put("message", notFoundMessage);
}
else {
body.put("fauxProps", allFauxProps);
}
} catch (Throwable t) {
t.printStackTrace();
}
return new TemplateResponseValues(TEMPLATE_NAME, body);
}
private TreeMap<String, Object> getFauxPropertyList(List<ObjectProperty> objectProps) {
List<FauxProperty> fauxProps = null;
TreeMap<String, Object> theFauxProps = new TreeMap<String, Object>();
if ( objectProps != null ) {
Iterator<ObjectProperty> opIt = objectProps.iterator();
if ( !opIt.hasNext()) {
notFoundMessage = "No object properties found.";
}
else {
while (opIt.hasNext()) {
ObjectProperty op = opIt.next();
String baseURI = op.getURI();
fauxProps = fpDao.getFauxPropertiesForBaseUri(baseURI);
if ( fauxProps != null ) {
Iterator<FauxProperty> fpIt = fauxProps.iterator();
if ( !fpIt.hasNext()) {
notFoundMessage = "No faux properties found.";
}
else {
while (fpIt.hasNext()) {
// No point in getting these unless we have a faux property
String baseLabel = getDisplayLabel(op) == null ? "(no name)" : getDisplayLabel(op);
String baseLocalName = op.getLocalNameWithPrefix();
baseLabel = baseLabel.substring(0,baseLabel.indexOf("("));
baseLabel += "(" + baseLocalName + ")";
// get the info we need from the faux property
FauxProperty fp = fpIt.next();
String fauxLabel = fp.getDisplayName();
String rangeLabel = fp.getRangeLabel();
String rangeURI = fp.getRangeURI();
String domainLabel = fp.getDomainLabel();
String domainURI = fp.getDomainURI();
String groupURI = fp.getGroupURI();
// FauxProperty only gets groupURI but we want the label
PropertyGroup pGroup = pgDao.getGroupByURI(groupURI);
String groupLabel = ( pGroup == null ) ? "unspecified" : pGroup.getName();
// store all the strings in a hash with the faux property label as the key
Map<String, Object> tmpHash = new HashMap<String, Object>();
tmpHash.put("base", baseLabel);
tmpHash.put("baseURI", baseURI);
tmpHash.put("group", groupLabel);
tmpHash.put("range", rangeLabel);
tmpHash.put("rangeURI", rangeURI);
tmpHash.put("domain", domainLabel);
tmpHash.put("domainURI", domainURI);
// add the faux and its details to the treemap
theFauxProps.put(fauxLabel, tmpHash);
}
}
}
}
}
}
return theFauxProps;
}
private TreeMap<String, Object> getFauxByBaseList(List<ObjectProperty> objectProps) {
List<FauxProperty> fauxProps = null;
TreeMap<String, Object> fauxByBaseProps = new TreeMap<String, Object>();
if ( objectProps != null ) {
Iterator<ObjectProperty> opIt = objectProps.iterator();
if ( !opIt.hasNext()) {
notFoundMessage = "No object properties found.";
}
else {
while (opIt.hasNext()) {
TreeMap<String, Object> fauxForGivenBase = new TreeMap<String, Object>();
ObjectProperty op = opIt.next();
String baseURI = op.getURI();
fauxProps = fpDao.getFauxPropertiesForBaseUri(baseURI);
if ( fauxProps != null ) {
Iterator<FauxProperty> fpIt = fauxProps.iterator();
if ( !fpIt.hasNext()) {
notFoundMessage = "No faux properties found.";
}
else {
String baseLabel = getDisplayLabel(op) == null ? "(no name)" : getDisplayLabel(op);
String baseLocalName = op.getLocalNameWithPrefix();
baseLabel = baseLabel.substring(0,baseLabel.indexOf("("));
baseLabel += "(" + baseLocalName + ")" + "|" + baseURI;
while (fpIt.hasNext()) {
// get the info we need from the faux property
FauxProperty fp = fpIt.next();
String fauxLabel = fp.getDisplayName();
String rangeLabel = fp.getRangeLabel();
String rangeURI = fp.getRangeURI();
String domainLabel = fp.getDomainLabel();
String domainURI = fp.getDomainURI();
String groupURI = fp.getGroupURI();
// FauxProperty only gets groupURI but we want the label
PropertyGroup pGroup = pgDao.getGroupByURI(groupURI);
String groupLabel = ( pGroup == null ) ? "unspecified" : pGroup.getName();
// store all the strings in a hash with the faux property label as the key
Map<String, Object> tmpHash = new HashMap<String, Object>();
tmpHash.put("baseURI", baseURI);
tmpHash.put("group", groupLabel);
tmpHash.put("range", rangeLabel);
tmpHash.put("rangeURI", rangeURI);
tmpHash.put("domain", domainLabel);
tmpHash.put("domainURI", domainURI);
// add the faux and its details to the treemap
fauxForGivenBase.put(fauxLabel, tmpHash);
}
fauxByBaseProps.put(baseLabel, fauxForGivenBase);
}
}
}
}
}
return fauxByBaseProps;
}
/*
* should never be null
*/
public static String getDisplayLabel(ObjectProperty op) {
String displayLabel = op.getPickListName();
displayLabel = (displayLabel != null && displayLabel.length() > 0)
? displayLabel
: op.getLocalName();
return (displayLabel != null) ? displayLabel : "[object property]" ;
}
}

View file

@ -762,6 +762,15 @@
<url-pattern>/showDataPropertyHierarchy</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ListFauxPropertiesController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListFauxPropertiesController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ListFauxPropertiesController</servlet-name>
<url-pattern>/listFauxProperties</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ListPropertyWebappsController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListPropertyWebappsController</servlet-class>

View file

@ -887,4 +887,10 @@ view_labels_for = View Labels for
select_an_existing_document = Select an existing document
datetime_year_required = Date/time intervals must begin with a year. Enter either a Start Year, an End Year or both.
select_a_language = Select a language
select_a_language = Select a language
base_property_capitalized = Base Property
faux_property_capitalized = Faux Property
faux_property_listing = Faux Property Listing
faux_property_by_base = faux properties by base property
faux_property_alpha = faux properties alphabetically

View file

@ -0,0 +1,19 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
var fauxPropertiesListingUtils = {
onLoad: function() {
this.initObjects();
this.bindEventListeners();
},
initObjects: function() {
this.select = $('select#displayOption');
this.theForm = $('form#fauxListing');
},
bindEventListeners: function() {
this.select.change(function() {
fauxPropertiesListingUtils.theForm.submit();
});
}
}

View file

@ -0,0 +1,123 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#--
Used to display both the object and data property hierarchies, though there are
separate controllers for those. Also used to display lists of "all" object and
data properties, though there are separate controllers for those, too.
-->
<#if propertyType??>
<#assign propType = propertyType>
<#else>
<#assign propType = "group">
</#if>
<section role="region">
<h2>${pageTitle!}</h2>
<#if message?has_content>
<p>${message}</p>
<#else>
<#if !displayOption?has_content>
<#assign displayOption = "listing">
</#if>
<form name="fauxListingForm" id="fauxListing" action="listFauxProperties" method="post" role="classHierarchy">
<label id="displayOptionLabel" class="inline">${i18n().display_options}</label>
<select id="displayOption" name="displayOption">
<option value="listing" <#if displayOption == "listing">selected</#if> >faux properties alphabetically</option>
<option value="byBase" <#if displayOption == "byBase">selected</#if> >faux properties by base property</option>
</select>
</form>
<section id="container" style="margin-top:10px">
<#if displayOption == "listing" >
<#assign keys = fauxProps?keys/>
<#list keys as key>
<#assign ks = fauxProps[key] />
<section id="classContainer1">
<div>
<a href='editForm?controller=FauxProperty&baseUri=${ks["baseURI"]?url!}&<#if ks["domainURI"]?has_content>domainUri=${ks["domainURI"]?url}&</#if>rangeUri=${ks["rangeURI"]?url!}'>${key}</a>
</div>
<table id="classHierarchy1" class="classHierarchy">
<tbody>
<tr>
<td class="classDetail">${i18n().base_property_capitalized}:</td>
<td><a href='propertyEdit?uri=${ks["baseURI"]?url!}'>${ks["base"]!}</a></td>
</tr>
<tr>
<td class="classDetail">${i18n().group_capitalized}:</td>
<td>${ks["group"]?capitalize}</td>
</tr>
<tr>
<td class="classDetail">${i18n().domain_class}:</td>
<td>
${ks["domain"]!}
<span class="rangeClass">${i18n().range_class}:</span>
${ks["range"]!}
</td>
</tr>
</tbody>
</table>
</section>
</#list>
<#else>
<#assign keys = fauxProps?keys />
<#list keys as key>
<#assign fauxList = fauxProps[key] />
<section id="classContainer1">
<#assign baseLabel = key?substring(0,key?index_of("|")) />
<#assign baseUri = key?substring(key?index_of("|")+1) />
<div>
<a href='propertyEdit?uri=${baseUri?url}'>${baseLabel}</a>
</div>
<#assign keysTwo = fauxList?keys />
<#assign firstLoop = true />
<#list keysTwo as k2>
<#assign faux = fauxList[k2] />
<table id="classHierarchy1" class="classHierarchy" <#if !firstLoop >style="margin-top:-16px"</#if>>
<tbody>
<tr>
<td class="classDetail">${i18n().faux_property_capitalized}:</td>
<td><a href='editForm?controller=FauxProperty&baseUri=${faux["baseURI"]?url!}&<#if faux["domainURI"]?has_content>domainUri=${faux["domainURI"]?url}&</#if>rangeUri=${faux["rangeURI"]?url!}'>${k2}</a></td>
</tr>
<tr>
<td class="classDetail">${i18n().group_capitalized}:</td>
<td>${faux["group"]?capitalize}
</td>
</tr>
<tr>
<td class="classDetail">${i18n().domain_class}:</td>
<td>
${faux["domain"]!}
<span class="rangeClass">${i18n().range_class}:</span>
${faux["range"]!}
</td>
</tr>
</tbody>
</table>
<#assign firstLoop = false />
</#list>
</section>
</#list>
</#if>
</section>
</#if>
</section>
<script language="javascript" type="text/javascript" >
var i18nStrings = {
'',
};
</script>
<script language="javascript" type="text/javascript" >
$(document).ready(function() {
fauxPropertiesListingUtils.onLoad();
});
</script>
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/classHierarchy.css" />')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/jquery-ui-1.8.9.custom.min.js"></script>',
'<script type="text/javascript" src="${urls.base}/js/siteAdmin/fauxPropertiesListingUtils.js"></script>')}

View file

@ -33,6 +33,7 @@
<ul role="navigation">
<li role="listitem"><a href="${ontologyEditor.urls.objectPropertyHierarchy}" title="${i18n().object_property_hierarchy}">${i18n().object_property_hierarchy}</a></li>
<li role="listitem"><a href="${ontologyEditor.urls.dataPropertyHierarchy}" title="${i18n().data_property_hierarchy}">${i18n().data_property_hierarchy}</a></li>
<li role="listitem"><a href="${ontologyEditor.urls.fauxPropertyList}" title="${i18n().data_property_hierarchy}">${i18n().faux_property_listing}</a></li>
<li role="listitem"><a href="${ontologyEditor.urls.propertyGroups}" title="${i18n().property_groups}">${i18n().property_groups}</a></li>
</ul>