Fix duplicate creations, closes #2206

This commit is contained in:
Antonin Delpeuch 2019-11-04 21:17:18 +00:00
parent 11c7788239
commit ec5c9cd418
3 changed files with 26 additions and 4 deletions

View File

@ -89,6 +89,7 @@ public class ReconEntityRewriter extends DatamodelConverter {
}
public ItemUpdate rewrite(ItemUpdate update) {
ItemIdValue subject = copy(update.getItemId());
Set<MonolingualTextValue> labels = update.getLabels().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> labelsIfNew = update.getLabelsIfNew().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> descriptions = update.getDescriptions().stream().map(l -> copy(l))
@ -100,6 +101,6 @@ public class ReconEntityRewriter extends DatamodelConverter {
.collect(Collectors.toList());
Set<Statement> deletedStatements = update.getDeletedStatements().stream().map(l -> copy(l))
.collect(Collectors.toSet());
return new ItemUpdate(update.getItemId(), addedStatements, deletedStatements, labels, labelsIfNew, descriptions, descriptionsIfNew, aliases);
return new ItemUpdate(subject, addedStatements, deletedStatements, labels, labelsIfNew, descriptions, descriptionsIfNew, aliases);
}
}

View File

@ -407,13 +407,21 @@ public class ItemUpdate {
builder.append("<Update on ");
builder.append(qid);
if (!labels.isEmpty()) {
builder.append("\n Labels: ");
builder.append("\n Labels (override): ");
builder.append(labels);
}
if (!labelsIfNew.isEmpty()) {
builder.append("\n Labels (if new): ");
builder.append(labelsIfNew);
}
if (!descriptions.isEmpty()) {
builder.append("\n Descriptions: ");
builder.append("\n Descriptions (override): ");
builder.append(descriptions);
}
if (!descriptionsIfNew.isEmpty()) {
builder.append("\n Descriptions (if new): ");
builder.append(descriptionsIfNew);
}
if (!aliases.isEmpty()) {
builder.append("\n Aliases: ");
builder.append(aliases);

View File

@ -83,6 +83,19 @@ public class ReconEntityRewriterTest {
.addLabel(Datamodel.makeMonolingualTextValue("label", "de"), true)
.addDescription(Datamodel.makeMonolingualTextValue("beschreibung", "de"), false)
.addAlias(Datamodel.makeMonolingualTextValue("darstellung", "de")).build();
assertEquals(expected, rewritten);
assertEquals(rewritten, expected);
}
@Test
public void testRewriteCreation() {
library.setQid(4567L, "Q1234");
ItemUpdate update = new ItemUpdateBuilder(TestingData.newIdB)
.addDescription(Datamodel.makeMonolingualTextValue("beschreibung", "de"), false)
.addAlias(Datamodel.makeMonolingualTextValue("darstellung", "de")).build();
ItemUpdate rewritten = rewriter.rewrite(update);
ItemUpdate expected = new ItemUpdateBuilder(newlyCreated)
.addDescription(Datamodel.makeMonolingualTextValue("beschreibung", "de"), false)
.addAlias(Datamodel.makeMonolingualTextValue("darstellung", "de")).build();
assertEquals(rewritten, expected);
}
}