AddAuthorsToInformationResourceGenerator will now always do an add and never an update. NIHVIVO-3400

This commit is contained in:
briancaruso 2011-12-02 18:11:09 +00:00
parent bf76ed8322
commit 8d21841293

View file

@ -25,6 +25,12 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUti
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
/**
* This is a slightly unusual generator that is used by Manage Authors on
* information resources.
*
* It is intended to always be an add, and never an update.
*/
public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator implements EditConfigurationGenerator { public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator implements EditConfigurationGenerator {
@Override @Override
@ -33,19 +39,23 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo(); EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
initBasics(editConfiguration, vreq); initBasics(editConfiguration, vreq);
initPropertyParameters(vreq, session, editConfiguration); initPropertyParameters(vreq, session, editConfiguration);
initObjectPropForm(editConfiguration, vreq);
//Overriding url to return to
setUrlToReturnTo(editConfiguration, vreq);
setVarNames(editConfiguration);
//Overriding URL to return to
setUrlToReturnTo(editConfiguration, vreq);
//set variable names
editConfiguration.setVarNameForSubject("infoResource");
editConfiguration.setVarNameForPredicate("predicate");
editConfiguration.setVarNameForObject("authorshipUri");
// Required N3 // Required N3
editConfiguration.setN3Required(generateN3Required()); editConfiguration.setN3Required( list( getN3NewAuthorship() ) );
// Optional N3 // Optional N3
editConfiguration.setN3Optional( generateN3Optional()); editConfiguration.setN3Optional( generateN3Optional());
editConfiguration.setNewResources( generateNewResources(vreq) ); editConfiguration.addNewResource("authorshipUri", DEFAULT_NS_TOKEN);
editConfiguration.addNewResource("newPerson", DEFAULT_NS_TOKEN);
//In scope //In scope
setUrisAndLiteralsInScope(editConfiguration, vreq); setUrisAndLiteralsInScope(editConfiguration, vreq);
@ -66,48 +76,29 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
//Adding additional data, specifically edit mode //Adding additional data, specifically edit mode
addFormSpecificData(editConfiguration, vreq); addFormSpecificData(editConfiguration, vreq);
prepare(vreq, editConfiguration);
//NOITCE this generator does not run prepare() since it
//is never an update and has no SPARQL for existing
return editConfiguration; return editConfiguration;
} }
private void setVarNames(EditConfigurationVTwo editConfiguration) {
editConfiguration.setVarNameForSubject("infoResource");
editConfiguration.setVarNameForPredicate("predicate");
editConfiguration.setVarNameForObject("authorshipUri");
}
private void setUrlToReturnTo(EditConfigurationVTwo editConfiguration, VitroRequest vreq) { private void setUrlToReturnTo(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq)); editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq));
} }
/***N3 strings both required and optional***/ /***N3 strings both required and optional***/
public String getN3PrefixString() { public String getN3PrefixString() {
return "@prefix core: <" + vivoCore + "> ." + return "@prefix core: <" + vivoCore + "> .\n" +
"@prefix foaf: <" + foaf + "> . " ; "@prefix foaf: <" + foaf + "> . \n" ;
}
//n3 for new authorship, authorship rank assertion
private List<String> generateN3Required() {
return list(getN3NewAuthorship(),
getN3AuthorshipRank());
} }
private String getN3NewAuthorship() { private String getN3NewAuthorship() {
return getN3PrefixString() + return getN3PrefixString() +
"?authorshipUri a core:Authorship ;" + "?authorshipUri a core:Authorship ;\n" +
" core:linkedInformationResource ?infoResource ;" + " core:linkedInformationResource ?infoResource .\n" +
" core:authorRank ?rank . " + "?infoResource core:informationResourceInAuthorship ?authorshipUri .";
"?infoResource core:informationResourceInAuthorship ?authorshipUri . ";
} }
private String getN3AuthorshipRank() { private String getN3AuthorshipRank() {
@ -118,10 +109,12 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
//first name, middle name, last name, and new perseon for new author being created, and n3 for existing person //first name, middle name, last name, and new perseon for new author being created, and n3 for existing person
//if existing person selected as author //if existing person selected as author
private List<String> generateN3Optional() { private List<String> generateN3Optional() {
return list(getN3NewPersonFirstName() , return list(
getN3NewPersonFirstName() ,
getN3NewPersonMiddleName(), getN3NewPersonMiddleName(),
getN3NewPersonLastName(), getN3NewPersonLastName(),
getN3NewPerson(), getN3NewPerson(),
getN3AuthorshipRank(),
getN3ForExistingPerson()); getN3ForExistingPerson());
} }
@ -144,15 +137,15 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
private String getN3NewPerson() { private String getN3NewPerson() {
return getN3PrefixString() + return getN3PrefixString() +
"?newPerson a foaf:Person ;" + "?newPerson a foaf:Person ;\n" +
"<" + RDFS.label.getURI() + "> ?label ." + "<" + RDFS.label.getURI() + "> ?label .\n" +
"?authorshipUri core:linkedAuthor ?newPerson ." + "?authorshipUri core:linkedAuthor ?newPerson .\n" +
"?newPerson core:authorInAuthorship ?authorshipUri . "; "?newPerson core:authorInAuthorship ?authorshipUri . ";
} }
private String getN3ForExistingPerson() { private String getN3ForExistingPerson() {
return getN3PrefixString() + return getN3PrefixString() +
"?authorshipUri core:linkedAuthor ?personUri ." + "?authorshipUri core:linkedAuthor ?personUri .\n" +
"?personUri core:authorInAuthorship ?authorshipUri ."; "?personUri core:authorInAuthorship ?authorshipUri .";
} }
@ -160,7 +153,7 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
//A new authorship uri will always be created when an author is added //A new authorship uri will always be created when an author is added
//A new person may be added if a person not in the system will be added as author //A new person may be added if a person not in the system will be added as author
private Map<String, String> generateNewResources(VitroRequest vreq) { private Map<String, String> generateNewResources(VitroRequest vreq) {
String DEFAULT_NS_TOKEN=null; //null forces the default NS
HashMap<String, String> newResources = new HashMap<String, String>(); HashMap<String, String> newResources = new HashMap<String, String>();
newResources.put("authorshipUri", DEFAULT_NS_TOKEN); newResources.put("authorshipUri", DEFAULT_NS_TOKEN);
@ -178,9 +171,6 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
Arrays.asList(new String[]{editConfiguration.getPredicateUri()})); Arrays.asList(new String[]{editConfiguration.getPredicateUri()}));
editConfiguration.setUrisInScope(urisInScope); editConfiguration.setUrisInScope(urisInScope);
//no literals in scope //no literals in scope
HashMap<String, List<Literal>> literalsInScope = new HashMap<String, List<Literal>>();
editConfiguration.setLiteralsInScope(literalsInScope);
} }
private void setUrisAndLiteralsOnForm(EditConfigurationVTwo editConfiguration, VitroRequest vreq) { private void setUrisAndLiteralsOnForm(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
@ -385,5 +375,6 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
} }
} }
static final String DEFAULT_NS_TOKEN=null; //null forces the default NS
} }