Skip to content

Commit

Permalink
Fixes for N3Optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg committed Nov 5, 2024
1 parent 4d4d424 commit daff484
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class EditConfigurationVTwo {
List<String> n3Optional = new ArrayList<String>();
//String representing optional N3 for RDF retracts
List<String> n3OptionalRetracts = new ArrayList<String>();
//String representing optional N3 for RDF retracts
List<String> n3OptionalAssertions = new ArrayList<String>();
//Names of variables of 'objects' i.e. URIs on form
List<String> urisOnform = new ArrayList<String>();
//Names of variables corresponding to data values i.e. literals on form
Expand Down Expand Up @@ -493,25 +495,20 @@ public void addN3Optional(String ... n3Strs){
this.n3Optional.addAll(Arrays.asList( n3Strs ));
}

public List<String> getN3OptionalRetracts() {
return EditConfigurationUtils.copy(n3OptionalRetracts);
}

public void setN3OptionalRetracts(List<String> n3OptionalRetracts) {
this.n3OptionalRetracts = n3OptionalRetracts;
}

public void setN3OptionalRetracts(String... n3Strs) {
this.n3OptionalRetracts = new ArrayList<String>(Arrays.asList(n3Strs));
}
public List<String> getN3OptionalAssertions() {
return EditConfigurationUtils.copy(n3OptionalAssertions);
}

public void addN3OptionalRetracts(List<String> n3OptionalRetracts) {
this.n3OptionalRetracts.addAll(n3OptionalRetracts);
}
public void addN3OptionalAssertions(List<String> assertions) {
this.n3OptionalAssertions.addAll(assertions);
}
public List<String> getN3OptionalRetractions() {
return EditConfigurationUtils.copy(n3OptionalRetracts);
}

public void addN3OptionalRetracts(String... n3Strs) {
this.n3OptionalRetracts.addAll(Arrays.asList(n3Strs));
}
public void addN3OptionalRetracts(List<String> n3OptionalRetracts) {
this.n3OptionalRetracts.addAll(n3OptionalRetracts);
}

public Map<String,String> getNewResources() {
return newResources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ private AdditionsAndRetractions createNewStatements(
List<String> requiredN3 = configuration.getN3Required();
List<String> optionalN3 = configuration.getN3Optional();

if (isCustomizedOptional(configuration)) {
optionalN3 = configuration.getN3OptionalAssertions();
}

/* substitute in the form values and existing values */
subInValuesToN3( configuration, submission, requiredN3, optionalN3, null , null, vreq);

Expand Down Expand Up @@ -172,8 +176,12 @@ protected AdditionsAndRetractions editExistingStatements(
List<String> N3RequiredAssert = editConfig.getN3Required();
List<String> N3OptionalAssert = editConfig.getN3Optional();
List<String> N3RequiredRetract = editConfig.getN3Required();
List<String> N3OptionalRetract = editConfig.getN3OptionalRetracts();

List<String> N3OptionalRetract = editConfig.getN3Optional();

if (isCustomizedOptional(editConfig)) {
N3OptionalAssert = editConfig.getN3OptionalAssertions();
N3OptionalRetract = editConfig.getN3OptionalRetractions();
}
subInValuesToN3(editConfig, submission,
N3RequiredAssert, N3OptionalAssert,
N3RequiredRetract, N3OptionalRetract, vreq);
Expand All @@ -183,6 +191,13 @@ protected AdditionsAndRetractions editExistingStatements(
N3RequiredRetract, N3OptionalRetract, vreq, editConfig);
}

private boolean isCustomizedOptional(EditConfigurationVTwo editConfig){
return
editConfig.getN3Optional().isEmpty() && (
!editConfig.getN3OptionalAssertions().isEmpty() ||
!editConfig.getN3OptionalRetractions().isEmpty() );
}

@SuppressWarnings("unchecked")
protected void subInValuesToN3(
EditConfigurationVTwo editConfig, MultiValueEditSubmission submission,
Expand All @@ -199,11 +214,16 @@ protected void subInValuesToN3(

//At this point deprecated optional retracts n3 are the same as optional asserts n3
List<String> deprecatedRetracts = new ArrayList<String>();
if (optionalAsserts != null && optionalRetracts != null) {
deprecatedRetracts.addAll(optionalAsserts);
}
/* ********** Form submission URIs ********* */
substituteInMultiURIs(submission.getUrisFromForm(), requiredAsserts, optionalAsserts, optionalRetracts, URLToReturnTo);
if (isCustomizedOptional(editConfig)) {
if (optionalAsserts != null) {
deprecatedRetracts.addAll(optionalAsserts);
}
substituteInMultiURIs(submission.getUrisFromForm(), requiredAsserts, optionalAsserts, optionalRetracts, URLToReturnTo);
} else {
substituteInMultiURIs(submission.getUrisFromForm(), requiredAsserts, optionalAsserts, URLToReturnTo);
}

logSubstitue( "Added form URIs", requiredAsserts, optionalAsserts, requiredRetracts, optionalRetracts);
//Retractions does NOT get values from form.

Expand Down Expand Up @@ -242,12 +262,16 @@ else if ( RDF.dtLangString.getURI().equals(aLiteratDT)) {
literalsFromForm.replace(aKey, newLiteralFromForm);
}

substituteInMultiLiterals( literalsFromForm, requiredAsserts, optionalAsserts, optionalRetracts, URLToReturnTo);
logSubstitue( "Added form Literals", requiredAsserts, optionalAsserts, requiredRetracts, optionalRetracts);
//Retractions does NOT get values from form.
if (optionalAsserts != null && optionalRetracts != null) {
optionalRetracts.addAll(deprecatedRetracts);
if (isCustomizedOptional(editConfig)) {
substituteInMultiLiterals( literalsFromForm, requiredAsserts, optionalAsserts, optionalRetracts, URLToReturnTo);
//Retractions does NOT get values from form.
if (optionalRetracts != null) {
optionalRetracts.addAll(deprecatedRetracts);
}
} else {
substituteInMultiLiterals( literalsFromForm, requiredAsserts, optionalAsserts, URLToReturnTo);
}
logSubstitue( "Added form Literals", requiredAsserts, optionalAsserts, requiredRetracts, optionalRetracts);

/* *********** Add subject, object and predicate ******** */
substituteInSubPredObjURIs(editConfig, requiredAsserts, optionalAsserts, requiredRetracts, optionalRetracts, URLToReturnTo);
Expand Down

0 comments on commit daff484

Please sign in to comment.