From a970039ff3d373139bb7351aa0035f6697f635af Mon Sep 17 00:00:00 2001 From: ryounes Date: Mon, 11 Jul 2011 18:26:29 +0000 Subject: [PATCH] NIHVIVO-707 Set hidden rank field value based on existing webpage ranks --- productMods/edit/forms/addEditWebpageForm.jsp | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/productMods/edit/forms/addEditWebpageForm.jsp b/productMods/edit/forms/addEditWebpageForm.jsp index 3fd6fb7d..c84aba0e 100644 --- a/productMods/edit/forms/addEditWebpageForm.jsp +++ b/productMods/edit/forms/addEditWebpageForm.jsp @@ -46,14 +46,16 @@ core:rank <%! public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.addEditWebpageForm.jsp"); - public static String RANK_QUERY = - "PREFIX core: \n" + - "SELECT DISTINCT ?rank WHERE { \n" + - " ?subject core:webpage ?link . \n" + - " ?link core:rank ?rank .\n" + - "} ORDER BY DESC(?rank) \n" + - "LIMIT 1"; - + /* Note on ordering by rank in sparql: if there is a non-integer value on a link, that will be returned. + * Preventing that would require getting all the ranks and ordering in Java, throwing out non-int values. + */ + public static String RANK_QUERY = "" + + "PREFIX core: \n" + + "SELECT DISTINCT ?rank WHERE { \n" + + " ?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 uriDatatypeUriJson = MiscWebUtils.escape(XSD.anyURI.toString()); + String intDatatypeUriJson = MiscWebUtils.escape(XSD.xint.toString()); %> + @@ -188,7 +192,7 @@ core:rank "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", - "rangeDatatypeUri" : "${stringDatatypeUriJson}", + "rangeDatatypeUri" : "${intDatatypeUriJson}", "rangeLang" : "", "assertions" : [ "${rankAssertion}" ] } @@ -218,32 +222,33 @@ core:rank 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 if (objectUri == null) { // adding new webpage - log.debug("getting max existing rank for subject"); String queryStr = QueryUtils.subUriForQueryVar(RANK_QUERY, "subject", subjectUri); log.debug("Query string is: " + queryStr); try { ResultSet results = QueryUtils.getQueryResults(queryStr, vreq); if (results != null && results.hasNext()) { // there is at most one result - log.debug("found a rank"); QuerySolution soln = results.next(); RDFNode node = soln.get("rank"); if (node != null && node.isLiteral()) { - log.debug("node value =" + node.asLiteral().getLexicalForm()); - int rank = node.asLiteral().getInt(); // what if it's not an int? - what gets returned? + // node.asLiteral().getInt() won't return an xsd:string that + // can be parsed as an int. + int rank = Integer.parseInt(node.asLiteral().getLexicalForm()); if (rank > maxRank) { log.debug("setting maxRank to " + rank); maxRank = rank; } } } + } catch (NumberFormatException e) { + log.error("Invalid rank returned from query: not an integer value."); } catch (Exception e) { log.error(e, e); } } - maxRank++; + %> @@ -272,9 +277,11 @@ core:rank

If left blank, the URL will be used when displaying a link to this webpage.

- +

+ +