address review comments and add additional cleanup
This commit is contained in:
parent
530ad7d39c
commit
ce82c237a3
4 changed files with 65 additions and 69 deletions
|
@ -148,7 +148,7 @@ public class ConfigurationModelsSetup implements ServletContextListener {
|
|||
log.debug("Difference for " + modelIdString + " (old -> new), these triples should be removed: " + out);
|
||||
|
||||
// Check if the UI-changes Overlap with the changes made in the fristtime-files
|
||||
RDFFilesLoader.checkUiChangesOverlapWithFileChanges(baseModel, userModel, difOldNew);
|
||||
RDFFilesLoader.removeChangesThatConflictWithUIEdits(baseModel, userModel, difOldNew);
|
||||
|
||||
// before we remove the triples, we need to compare values in back up firsttime with user's triplestore
|
||||
// if the triples which should be removed are still in user´s triplestore, remove them
|
||||
|
@ -166,7 +166,7 @@ public class ConfigurationModelsSetup implements ServletContextListener {
|
|||
log.debug("Difference for " + modelIdString + " (new -> old), these triples should be added: " + out2);
|
||||
|
||||
// Check if the UI-changes Overlap with the changes made in the fristtime-files
|
||||
RDFFilesLoader.checkUiChangesOverlapWithFileChanges(baseModel, userModel, difNewOld);
|
||||
RDFFilesLoader.removeChangesThatConflictWithUIEdits(baseModel, userModel, difNewOld);
|
||||
|
||||
// before we add the triples, we need to compare values in back up firsttime with user's triplestore
|
||||
// if the triples which should be added are not already in user´s triplestore, add them
|
||||
|
|
|
@ -298,7 +298,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
|||
log.debug("Difference for " + modelIdString + " (old -> new), these triples should be removed: " + out);
|
||||
|
||||
// Check if the UI-changes Overlap with the changes made in the fristtime-files
|
||||
RDFFilesLoader.checkUiChangesOverlapWithFileChanges(baseModel, userModel, difOldNew);
|
||||
RDFFilesLoader.removeChangesThatConflictWithUIEdits(baseModel, userModel, difOldNew);
|
||||
|
||||
// before we remove the triples, we need to compare values in back up firsttime with user's triplestore
|
||||
// if the triples which should be removed are still in user´s triplestore, remove them
|
||||
|
@ -317,7 +317,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
|||
log.debug("Difference for " + modelIdString + " (new -> old), these triples should be added: " + out2);
|
||||
|
||||
// Check if the UI-changes Overlap with the changes made in the fristtime-files
|
||||
RDFFilesLoader.checkUiChangesOverlapWithFileChanges(baseModel, userModel, difNewOld);
|
||||
RDFFilesLoader.removeChangesThatConflictWithUIEdits(baseModel, userModel, difNewOld);
|
||||
|
||||
// before we add the triples, we need to compare values in back up firsttime with user's triplestore
|
||||
// if the triples which should be added are not already in user´s triplestore, add them
|
||||
|
|
|
@ -224,7 +224,7 @@ public class RDFFilesLoader {
|
|||
* @param userModel current state in the system (user/UI-model)
|
||||
* @param changesModel the changes between firsttime-files and firsttime-backup
|
||||
*/
|
||||
public static void checkUiChangesOverlapWithFileChanges(Model baseModel,
|
||||
public static void removeChangesThatConflictWithUIEdits(Model baseModel,
|
||||
Model userModel, Model changesModel) {
|
||||
log.debug("Check if subtractions from backup-firsttime model to"
|
||||
+ " current state of firsttime-files were changed in user-model"
|
||||
|
@ -245,7 +245,11 @@ public class RDFFilesLoader {
|
|||
log.debug("Diff of scoped user model against firsttime backup has "
|
||||
+ changesUserModel.size() + " triples");
|
||||
List<Statement> changedInUIandFileStatements = new ArrayList<Statement>();
|
||||
if(!changesUserModel.isEmpty()) {
|
||||
if(changesUserModel.isEmpty()) {
|
||||
log.debug("There were no changes in the user-model via UI"
|
||||
+ " compared to the backup-firsttime-model");
|
||||
return;
|
||||
}
|
||||
removeBlankTriples(changesUserModel);
|
||||
if(log.isDebugEnabled()) {
|
||||
StringWriter out3 = new StringWriter();
|
||||
|
@ -257,16 +261,16 @@ public class RDFFilesLoader {
|
|||
+ " triples will not be updated.");
|
||||
// Iterate over all statements and check if the ones which should be
|
||||
// removed were not changed via the UI
|
||||
StmtIterator iter = changesUserModel.listStatements();
|
||||
while (iter.hasNext()) {
|
||||
Statement stmt = iter.nextStatement();
|
||||
StmtIterator userChanges = changesUserModel.listStatements();
|
||||
while (userChanges.hasNext()) {
|
||||
Statement stmt = userChanges.nextStatement();
|
||||
Resource subject = stmt.getSubject();
|
||||
Property predicate = stmt.getPredicate();
|
||||
RDFNode object = stmt.getObject();
|
||||
StmtIterator iter2 = changesModel.listStatements(
|
||||
StmtIterator firsttimeChanges = changesModel.listStatements(
|
||||
subject, predicate, (RDFNode) null);
|
||||
while (iter2.hasNext()) {
|
||||
Statement stmt2 = iter2.nextStatement();
|
||||
while (firsttimeChanges.hasNext()) {
|
||||
Statement stmt2 = firsttimeChanges.nextStatement();
|
||||
RDFNode object2 = stmt2.getObject();
|
||||
// If subject and predicate are equal but the object differs
|
||||
// and the language tag is the same, do not update these triples.
|
||||
|
@ -295,24 +299,17 @@ public class RDFFilesLoader {
|
|||
}
|
||||
// remove triples which were changed in the user model (UI) from the list
|
||||
changesModel.remove(changedInUIandFileStatements);
|
||||
} else {
|
||||
log.debug("There were no changes in the user-model via UI"
|
||||
+ " compared to the backup-firsttime-model");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all triples where subject or object is blank (Anon)
|
||||
*/
|
||||
public static void removeBlankTriples(Model model) {
|
||||
StmtIterator iter = model.listStatements();
|
||||
List<Statement> removeStatement = new ArrayList<Statement>();
|
||||
while (iter.hasNext()) {
|
||||
Statement stmt = iter.nextStatement(); // get next statement
|
||||
Resource subject = stmt.getSubject(); // get the subject
|
||||
RDFNode object = stmt.getObject(); // get the object
|
||||
|
||||
if(subject.isAnon() || object.isAnon())
|
||||
StmtIterator stmts = model.listStatements();
|
||||
while (stmts.hasNext()) {
|
||||
Statement stmt = stmts.nextStatement();
|
||||
if(stmt.getSubject().isAnon() || stmt.getObject().isAnon())
|
||||
{
|
||||
removeStatement.add(stmt);
|
||||
}
|
||||
|
|
|
@ -61,8 +61,8 @@ public class RDFFilesLoaderTest extends AbstractTestClass {
|
|||
Model additionsModel = fileModel.difference(backupModel);
|
||||
Model retractionsModel = backupModel.difference(fileModel);
|
||||
|
||||
RDFFilesLoader.checkUiChangesOverlapWithFileChanges(backupModel, userModel, additionsModel);
|
||||
RDFFilesLoader.checkUiChangesOverlapWithFileChanges(backupModel, userModel, retractionsModel);
|
||||
RDFFilesLoader.removeChangesThatConflictWithUIEdits(backupModel, userModel, additionsModel);
|
||||
RDFFilesLoader.removeChangesThatConflictWithUIEdits(backupModel, userModel, retractionsModel);
|
||||
|
||||
userModel.remove(retractionsModel);
|
||||
userModel.add(additionsModel);
|
||||
|
@ -73,7 +73,6 @@ public class RDFFilesLoaderTest extends AbstractTestClass {
|
|||
// have the same language tag.
|
||||
assertTrue("expected: " + userModelExpected + " but was: " + userModel,
|
||||
userModelExpected.isIsomorphicWith(userModel));
|
||||
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
|
@ -118,8 +117,8 @@ public class RDFFilesLoaderTest extends AbstractTestClass {
|
|||
Model additionsModel = fileModel.difference(backupModel);
|
||||
Model retractionsModel = backupModel.difference(fileModel);
|
||||
|
||||
RDFFilesLoader.checkUiChangesOverlapWithFileChanges(backupModel, userModel, additionsModel);
|
||||
RDFFilesLoader.checkUiChangesOverlapWithFileChanges(backupModel, userModel, retractionsModel);
|
||||
RDFFilesLoader.removeChangesThatConflictWithUIEdits(backupModel, userModel, additionsModel);
|
||||
RDFFilesLoader.removeChangesThatConflictWithUIEdits(backupModel, userModel, retractionsModel);
|
||||
|
||||
userModel.remove(retractionsModel);
|
||||
userModel.add(additionsModel);
|
||||
|
|
Loading…
Add table
Reference in a new issue