VIVO-112 and VIVO-298
This commit is contained in:
parent
c5d0bc21e8
commit
3d527acce9
5 changed files with 139 additions and 81 deletions
|
@ -8,12 +8,16 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
@ -22,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.PublicationHasAuthorValidator;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
|
@ -334,99 +339,117 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
//Get the existing authorships
|
||||
formSpecificData.put("existingAuthorInfo", getExistingAuthorships(vreq));
|
||||
formSpecificData.put("newRank", getMaxRank(vreq) + 1);
|
||||
formSpecificData.put("rankPredicate", authorRankPredicate);
|
||||
formSpecificData.put("existingAuthorInfo", getExistingAuthorships(editConfiguration.getSubjectUri(), vreq));
|
||||
formSpecificData.put("newRank", getMaxRank(editConfiguration.getSubjectUri(), vreq) + 1);
|
||||
formSpecificData.put("rankPredicate", "http://vivoweb.org/ontology/core#rank");
|
||||
editConfiguration.setFormSpecificData(formSpecificData);
|
||||
}
|
||||
|
||||
private List<AuthorshipInfo> getExistingAuthorships(VitroRequest vreq) {
|
||||
Individual infoResource = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||
List<Individual> authorships = infoResource.getRelatedIndividuals(
|
||||
EditConfigurationUtils.getPredicateUri(vreq));
|
||||
//TODO: Check if sorted correctly
|
||||
|
||||
log.debug("authorships = " + authorships);
|
||||
|
||||
sortAuthorshipIndividuals(authorships);
|
||||
|
||||
return getAuthorshipInfo(authorships);
|
||||
}
|
||||
/*
|
||||
|
||||
private static String AUTHORSHIPS_QUERY = ""
|
||||
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
|
||||
+ "PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#> \n"
|
||||
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
|
||||
+ "SELECT ?authorshipURI (afn:localname(?authorshipURI) AS ?authorshipName) ?authorURI ?authorName \n"
|
||||
+ "SELECT ?authorshipURI (afn:localname(?authorshipURI) AS ?authorshipName) ?authorURI ?authorName ?rank \n"
|
||||
+ "WHERE { \n"
|
||||
+ "?subject core:relatedBy ?authorshipURI . \n"
|
||||
+ "?authorshipURI a core:Authorship . \n"
|
||||
+ "?authorshipURI core:relates ?authorURI . \n"
|
||||
+ "?authorURI a foaf:Person . \n"
|
||||
+ "?authorURI rdfs:label ?authorName \n"
|
||||
+ "}";
|
||||
+ "OPTIONAL { ?authorURI rdfs:label ?authorName } \n"
|
||||
+ "OPTIONAL { ?authorshipURI core:rank ?rank } \n"
|
||||
+ "} ORDER BY ?rank";
|
||||
|
||||
|
||||
private List<Map<String, String>> getExistingAuthorships(String subjectUri, VitroRequest vreq) {
|
||||
private List<AuthorshipInfo> getExistingAuthorships(String subjectUri, VitroRequest vreq) {
|
||||
|
||||
String queryStr = QueryUtils.subUriForQueryVar(this.getAuthorshipsQuery(), "subject", subjectUri);
|
||||
log.debug("Query string is: " + queryStr);
|
||||
List<Map<String, String>> authorshipss = new ArrayList<Map<String, String>>();
|
||||
List<Map<String, String>> authorships = new ArrayList<Map<String, String>>();
|
||||
try {
|
||||
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||
while (results.hasNext()) {
|
||||
QuerySolution soln = results.nextSolution();
|
||||
RDFNode node = soln.get("link");
|
||||
RDFNode node = soln.get("authorshipURI");
|
||||
if (node.isURIResource()) {
|
||||
webpages.add(QueryUtils.querySolutionToStringValueMap(soln));
|
||||
authorships.add(QueryUtils.querySolutionToStringValueMap(soln));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
log.debug("webpages = " + webpages);
|
||||
return webpages;
|
||||
log.debug("authorships = " + authorships);
|
||||
return getAuthorshipInfo(authorships);
|
||||
}
|
||||
*/
|
||||
|
||||
private static String MAX_RANK_QUERY = ""
|
||||
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
|
||||
+ "SELECT DISTINCT ?rank WHERE { \n"
|
||||
+ " ?subject core:relatedBy ?authorship . \n"
|
||||
+ " ?authorship a core:Authorship . \n"
|
||||
+ " ?authorship core:rank ?rank .\n"
|
||||
+ "} ORDER BY DESC(?rank) LIMIT 1";
|
||||
|
||||
private int getMaxRank(String subjectUri, VitroRequest vreq) {
|
||||
|
||||
int maxRank = 0; // default value
|
||||
String queryStr = QueryUtils.subUriForQueryVar(this.getMaxRankQueryStr(), "subject", subjectUri);
|
||||
log.debug("maxRank query string is: " + queryStr);
|
||||
try {
|
||||
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||
if (results != null && results.hasNext()) { // there is at most one result
|
||||
QuerySolution soln = results.next();
|
||||
RDFNode node = soln.get("rank");
|
||||
if (node != null && node.isLiteral()) {
|
||||
// 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);
|
||||
}
|
||||
log.debug("maxRank is: " + maxRank);
|
||||
return maxRank;
|
||||
}
|
||||
|
||||
private List<AuthorshipInfo> getAuthorshipInfo(
|
||||
List<Individual> authorships) {
|
||||
List<Map<String, String>> authorships) {
|
||||
List<AuthorshipInfo> info = new ArrayList<AuthorshipInfo>();
|
||||
for ( Individual authorship : authorships ) {
|
||||
String authorshipUri = authorship.getURI();
|
||||
String authorshipName = authorship.getName();
|
||||
String authorUri = "";
|
||||
String authorName = "";
|
||||
Individual author = authorship.getRelatedIndividual(linkedAuthorPredicate);
|
||||
if(author != null) {
|
||||
authorUri = author.getURI();
|
||||
authorName = author.getName();
|
||||
}
|
||||
AuthorshipInfo aaInfo = new AuthorshipInfo(authorshipUri, authorshipName, authorUri, authorName);
|
||||
info.add(aaInfo);
|
||||
String authorshipUri = "";
|
||||
String authorshipName = "";
|
||||
String authorUri = "";
|
||||
String authorName = "";
|
||||
|
||||
for ( Map<String, String> authorship : authorships ) {
|
||||
for (Entry<String, String> entry : authorship.entrySet() ) {
|
||||
if ( entry.getKey().equals("authorshipURI") ) {
|
||||
authorshipUri = entry.getValue();
|
||||
}
|
||||
else if ( entry.getKey().equals("authorshipName") ) {
|
||||
authorshipName = entry.getValue();
|
||||
}
|
||||
else if ( entry.getKey().equals("authorURI") ) {
|
||||
authorUri = entry.getValue();
|
||||
}
|
||||
else if ( entry.getKey().equals("authorName") ) {
|
||||
authorName = entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
AuthorshipInfo aaInfo = new AuthorshipInfo(authorshipUri, authorshipName, authorUri, authorName);
|
||||
info.add(aaInfo);
|
||||
}
|
||||
log.debug("info = " + info);
|
||||
return info;
|
||||
}
|
||||
|
||||
private int getMaxRank(VitroRequest vreq) {
|
||||
Individual infoResource = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||
List<Individual> authorships = infoResource.getRelatedIndividuals(
|
||||
EditConfigurationUtils.getPredicateUri(vreq));
|
||||
sortAuthorshipIndividuals(authorships);
|
||||
int maxRank = 0;
|
||||
for(Individual authorship: authorships) {
|
||||
DataPropertyStatement rankStmt = authorship.getDataPropertyStatement(authorRankPredicate);
|
||||
if (rankStmt != null) {
|
||||
maxRank = Integer.parseInt(rankStmt.getData());
|
||||
}
|
||||
}
|
||||
return maxRank;
|
||||
}
|
||||
|
||||
private void sortAuthorshipIndividuals(List<Individual> authorships) {
|
||||
DataPropertyComparator comp = new DataPropertyComparator(authorRankPredicate);
|
||||
Collections.sort(authorships, comp);
|
||||
}
|
||||
|
||||
//This is the information about authors the form will require
|
||||
public class AuthorshipInfo {
|
||||
//This is the authorship node information
|
||||
|
@ -467,8 +490,12 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
|
||||
static final String DEFAULT_NS_TOKEN=null; //null forces the default NS
|
||||
|
||||
// protected String getAuthorshipsQuery() {
|
||||
// return AUTHORSHIPS_QUERY;
|
||||
// }
|
||||
protected String getMaxRankQueryStr() {
|
||||
return MAX_RANK_QUERY;
|
||||
}
|
||||
|
||||
protected String getAuthorshipsQuery() {
|
||||
return AUTHORSHIPS_QUERY;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -308,15 +308,24 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
|
|||
|
||||
private String getN3ForNewBookNewEditor() {
|
||||
return "@prefix vivo: <" + vivoCore + "> . \n" +
|
||||
"?newBook vivo:editor ?newEditor . \n " +
|
||||
"?newEditor vivo:editorOf ?newBook . \n" +
|
||||
"?newBook vivo:relatedBy ?editorship . \n" +
|
||||
"?editorship vivo:relates ?newBook . \n" +
|
||||
"?newBook <" + label + "> ?book . \n " +
|
||||
"?editorship a vivo:Editorship . \n" +
|
||||
"?editorship vivo:relates ?newEditor . \n" +
|
||||
"?newEditor a <" + editorClass + "> . \n" +
|
||||
"?newEditor vivo:relatedBy ?editorship . \n" +
|
||||
"?newEditor <" + label + "> ?editor .";
|
||||
}
|
||||
|
||||
private String getN3ForNewBookEditor() {
|
||||
return "@prefix vivo: <" + vivoCore + "> . \n" +
|
||||
"?newBook vivo:editor ?editorUri . \n" +
|
||||
"?editorUri vivo:editorOf ?newBook . " ;
|
||||
"?newBook vivo:relatedBy ?editorship . \n" +
|
||||
"?editorship vivo:relates ?newBook . \n" +
|
||||
"?newBook <" + label + "> ?book . \n " +
|
||||
"?editorship a vivo:Editorship . \n" +
|
||||
"?editorship vivo:relates ?editorUri . \n" +
|
||||
"?editorUri vivo:relatedBy ?editorship . ";
|
||||
}
|
||||
|
||||
private String getN3ForNewBookNewPublisher() {
|
||||
|
@ -396,30 +405,44 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
|
|||
|
||||
private String getN3ForNewEditor() {
|
||||
return "@prefix vivo: <" + vivoCore + "> . \n" +
|
||||
"?pubUri vivo:editor ?newEditor . \n" +
|
||||
"?pubUri vivo:relatedBy ?editorship . \n" +
|
||||
"?editorship vivo:relates ?pubUri . \n" +
|
||||
"?editorship a vivo:Editorship . \n" +
|
||||
"?editorship vivo:relates ?newEditor . \n" +
|
||||
"?newEditor a <" + editorClass + "> . \n" +
|
||||
"?newEditor vivo:editorOf ?pubUri . \n" +
|
||||
"?newEditor vivo:relatedBy ?editorship . \n" +
|
||||
"?newEditor <" + label + "> ?editor .";
|
||||
}
|
||||
|
||||
private String getN3ForEditor() {
|
||||
return "@prefix vivo: <" + vivoCore + "> . \n" +
|
||||
"?pubUri vivo:editor ?editorUri . \n" +
|
||||
"?editorUri vivo:editorOf ?pubUri . ";
|
||||
"?pubUri vivo:relatedBy ?editorship . \n" +
|
||||
"?editorship vivo:relates ?pubUri . \n" +
|
||||
"?editorship a vivo:Editorship . \n" +
|
||||
"?editorship vivo:relates ?editorUri . \n" +
|
||||
"?editorUri vivo:relatedBy ?editorship . ";
|
||||
}
|
||||
|
||||
private String getN3ForNewEditorNewPub() {
|
||||
return "@prefix vivo: <" + vivoCore + "> . \n" +
|
||||
"?newPublication vivo:editor ?newEditor . \n" +
|
||||
"?newPublication vivo:relatedBy ?editorship . \n" +
|
||||
"?editorship vivo:relates ?newPublication . \n" +
|
||||
"?newPublication <" + label + "> ?title ." +
|
||||
"?editorship a vivo:Editorship . \n" +
|
||||
"?editorship vivo:relates ?newEditor . \n" +
|
||||
"?newEditor a <" + editorClass + "> . \n" +
|
||||
"?newEditor vivo:editorOf ?newPublication . \n" +
|
||||
"?newEditor vivo:relatedBy ?editorship . \n" +
|
||||
"?newEditor <" + label + "> ?editor .";
|
||||
}
|
||||
|
||||
private String getN3ForEditorNewPub() {
|
||||
return "@prefix vivo: <" + vivoCore + "> . \n" +
|
||||
"?newPublication vivo:editor ?editorUri . \n" +
|
||||
"?editorUri vivo:editorOf ?newPublication . ";
|
||||
"?newPublication vivo:relatedBy ?editorship . \n" +
|
||||
"?editorship vivo:relates ?newPublication . \n" +
|
||||
"?newPublication <" + label + "> ?title ." +
|
||||
"?editorship vivo:relates ?editorUri . \n" +
|
||||
"?editorship a vivo:Editorship . \n" +
|
||||
"?editorUri vivo:relatedBy ?editorship . ";
|
||||
}
|
||||
|
||||
private String getN3ForNewPublisher() {
|
||||
|
@ -525,6 +548,7 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
|
|||
newResources.put("newConference", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newEvent", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newEditor", DEFAULT_NS_TOKEN);
|
||||
newResources.put("editorship", DEFAULT_NS_TOKEN);
|
||||
newResources.put("vcardEditor", DEFAULT_NS_TOKEN);
|
||||
newResources.put("vcardName", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newPublisher", DEFAULT_NS_TOKEN);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue