NIHVIVO-707 Set hidden rank field value based on existing webpage ranks
This commit is contained in:
parent
749e6f4572
commit
a970039ff3
1 changed files with 23 additions and 16 deletions
|
@ -46,13 +46,15 @@ core:rank
|
||||||
<%!
|
<%!
|
||||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.addEditWebpageForm.jsp");
|
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.addEditWebpageForm.jsp");
|
||||||
|
|
||||||
public static String RANK_QUERY =
|
/* Note on ordering by rank in sparql: if there is a non-integer value on a link, that will be returned.
|
||||||
"PREFIX core: <http://vivoweb.org/ontology/core#> \n" +
|
* Preventing that would require getting all the ranks and ordering in Java, throwing out non-int values.
|
||||||
"SELECT DISTINCT ?rank WHERE { \n" +
|
*/
|
||||||
" ?subject core:webpage ?link . \n" +
|
public static String RANK_QUERY = ""
|
||||||
" ?link core:rank ?rank .\n" +
|
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
|
||||||
"} ORDER BY DESC(?rank) \n" +
|
+ "SELECT DISTINCT ?rank WHERE { \n"
|
||||||
"LIMIT 1";
|
+ " ?subject core:webpage ?link . \n"
|
||||||
|
+ " ?link core:rank ?rank .\n"
|
||||||
|
+ "} ORDER BY DESC(?rank) LIMIT 1";
|
||||||
|
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
@ -67,10 +69,12 @@ core:rank
|
||||||
|
|
||||||
String stringDatatypeUriJson = MiscWebUtils.escape(XSD.xstring.toString());
|
String stringDatatypeUriJson = MiscWebUtils.escape(XSD.xstring.toString());
|
||||||
String uriDatatypeUriJson = MiscWebUtils.escape(XSD.anyURI.toString());
|
String uriDatatypeUriJson = MiscWebUtils.escape(XSD.anyURI.toString());
|
||||||
|
String intDatatypeUriJson = MiscWebUtils.escape(XSD.xint.toString());
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<c:set var="stringDatatypeUriJson" value="<%= stringDatatypeUriJson %>" />
|
<c:set var="stringDatatypeUriJson" value="<%= stringDatatypeUriJson %>" />
|
||||||
<c:set var="uriDatatypeUriJson" value="<%= uriDatatypeUriJson %>" />
|
<c:set var="uriDatatypeUriJson" value="<%= uriDatatypeUriJson %>" />
|
||||||
|
<c:set var="intDatatypeUriJson" value="<%= intDatatypeUriJson %>" />
|
||||||
|
|
||||||
<c:set var="core" value="http://vivoweb.org/ontology/core#" />
|
<c:set var="core" value="http://vivoweb.org/ontology/core#" />
|
||||||
<c:set var="linkClass" value="${core}URLLink" />
|
<c:set var="linkClass" value="${core}URLLink" />
|
||||||
|
@ -188,7 +192,7 @@ core:rank
|
||||||
"literalOptions" : [ ],
|
"literalOptions" : [ ],
|
||||||
"predicateUri" : "",
|
"predicateUri" : "",
|
||||||
"objectClassUri" : "",
|
"objectClassUri" : "",
|
||||||
"rangeDatatypeUri" : "${stringDatatypeUriJson}",
|
"rangeDatatypeUri" : "${intDatatypeUriJson}",
|
||||||
"rangeLang" : "",
|
"rangeLang" : "",
|
||||||
"assertions" : [ "${rankAssertion}" ]
|
"assertions" : [ "${rankAssertion}" ]
|
||||||
}
|
}
|
||||||
|
@ -218,32 +222,33 @@ core:rank
|
||||||
|
|
||||||
String subjectName = ((Individual)request.getAttribute("subject")).getName();
|
String subjectName = ((Individual)request.getAttribute("subject")).getName();
|
||||||
|
|
||||||
// Get largest existing rank value, increment by 1, for hidden rank field value
|
// Get largest existing rank value
|
||||||
int maxRank = 0; // default value
|
int maxRank = 0; // default value
|
||||||
if (objectUri == null) { // adding new webpage
|
if (objectUri == null) { // adding new webpage
|
||||||
log.debug("getting max existing rank for subject");
|
|
||||||
String queryStr = QueryUtils.subUriForQueryVar(RANK_QUERY, "subject", subjectUri);
|
String queryStr = QueryUtils.subUriForQueryVar(RANK_QUERY, "subject", subjectUri);
|
||||||
log.debug("Query string is: " + queryStr);
|
log.debug("Query string is: " + queryStr);
|
||||||
try {
|
try {
|
||||||
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||||
if (results != null && results.hasNext()) { // there is at most one result
|
if (results != null && results.hasNext()) { // there is at most one result
|
||||||
log.debug("found a rank");
|
|
||||||
QuerySolution soln = results.next();
|
QuerySolution soln = results.next();
|
||||||
RDFNode node = soln.get("rank");
|
RDFNode node = soln.get("rank");
|
||||||
if (node != null && node.isLiteral()) {
|
if (node != null && node.isLiteral()) {
|
||||||
log.debug("node value =" + node.asLiteral().getLexicalForm());
|
// node.asLiteral().getInt() won't return an xsd:string that
|
||||||
int rank = node.asLiteral().getInt(); // what if it's not an int? - what gets returned?
|
// can be parsed as an int.
|
||||||
|
int rank = Integer.parseInt(node.asLiteral().getLexicalForm());
|
||||||
if (rank > maxRank) {
|
if (rank > maxRank) {
|
||||||
log.debug("setting maxRank to " + rank);
|
log.debug("setting maxRank to " + rank);
|
||||||
maxRank = rank;
|
maxRank = rank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
log.error("Invalid rank returned from query: not an integer value.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maxRank++;
|
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<c:choose>
|
<c:choose>
|
||||||
|
@ -272,9 +277,11 @@ core:rank
|
||||||
<v:input type="text" label="Webpage Name" id="anchor" size="70"/>
|
<v:input type="text" label="Webpage Name" id="anchor" size="70"/>
|
||||||
<p><em>If left blank, the URL will be used when displaying a link to this webpage.</em></p>
|
<p><em>If left blank, the URL will be used when displaying a link to this webpage.</em></p>
|
||||||
<c:if test="${editMode == 'add'}">
|
<c:if test="${editMode == 'add'}">
|
||||||
<input type="hidden" name="rank" value="<%= maxRank %>" />
|
<input type="hidden" name="rank" value="<%= maxRank + 1 %>" />
|
||||||
</c:if>
|
</c:if>
|
||||||
<p class="submit"><v:input type="submit" id="submit" value="${submitButtonText}" cancel="true"/></p>
|
<p class="submit"><v:input type="submit" id="submit" value="${submitButtonText}" cancel="true"/></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<jsp:include page="${postForm}"/>
|
<jsp:include page="${postForm}"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue