Result.mergeFrom handles dateOfAcceptance

This commit is contained in:
Claudio Atzori 2021-06-18 09:58:30 +02:00
parent f0e00d3abd
commit f5a3b451c9
2 changed files with 166 additions and 4 deletions

View File

@ -4,6 +4,7 @@ package eu.dnetlib.dhp.schema.oaf;
import java.io.Serializable;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import eu.dnetlib.dhp.schema.common.AccessRightComparator;
@ -256,6 +257,14 @@ public class Result extends OafEntity implements Serializable {
if (r.getLanguage() != null && compareTrust(this, r) < 0)
language = r.getLanguage();
if (Objects.nonNull(r.getDateofacceptance())) {
if (Objects.isNull(getDateofacceptance())) {
dateofacceptance = r.getDateofacceptance();
} else if (compareTrust(this, r) < 0) {
dateofacceptance = r.getDateofacceptance();
}
}
country = mergeLists(country, r.getCountry());
subject = mergeLists(subject, r.getSubject());

View File

@ -37,8 +37,8 @@ public class MergeTest {
@Test
public void mergePublicationCollectedFromTest() {
Publication a = new Publication();
Publication b = new Publication();
Publication a = publication();
Publication b = publication();
a.setCollectedfrom(Arrays.asList(setKV("a", "open"), setKV("b", "closed")));
b.setCollectedfrom(Arrays.asList(setKV("A", "open"), setKV("b", "Open")));
@ -49,11 +49,140 @@ public class MergeTest {
assertEquals(3, a.getCollectedfrom().size());
}
@Test
public void mergePublicationDateOfAcceptanceTest_bothPresent() {
Publication a = publication();
Publication b = publication();
a.setDateofacceptance(field("2021-06-18"));
b.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-18", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationDateOfAcceptanceTest_bothPresent_1() {
Publication a = publication("0.8");
Publication b = publication("0.9");
a.setDateofacceptance(field("2021-06-18"));
b.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationDateOfAcceptanceTest_bothPresent_2() {
Publication a = publication("0.9");
Publication b = publication("0.8");
a.setDateofacceptance(field("2021-06-18"));
b.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-18", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationDateOfAcceptanceTest_leftMissing() {
Publication a = publication();
Publication b = publication();
b.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationDateOfAcceptanceTest_leftMissing_1() {
Publication a = publication("0.9");
Publication b = publication("0.8");
b.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationDateOfAcceptanceTest_leftMissing_2() {
Publication a = publication("0.8");
Publication b = publication("0.9");
b.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationDateOfAcceptanceTest_rightMissing() {
Publication a = publication();
Publication b = publication();
a.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationDateOfAcceptanceTest_rightMissing_1() {
Publication a = publication("0.8");
Publication b = publication("0.9");
a.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationDateOfAcceptanceTest_rightMissing_2() {
Publication a = publication("0.9");
Publication b = publication("0.8");
a.setDateofacceptance(field("2021-06-19"));
a.mergeFrom(b);
assertNotNull(a.getDateofacceptance());
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
}
@Test
public void mergePublicationSubjectTest() {
Publication a = new Publication();
Publication b = new Publication();
Publication a = publication();
Publication b = publication();
a.setSubject(Arrays.asList(setSP("a", "open", "classe"), setSP("b", "open", "classe")));
b.setSubject(Arrays.asList(setSP("A", "open", "classe"), setSP("c", "open", "classe")));
@ -148,4 +277,28 @@ public class MergeTest {
s.setQualifier(q);
return s;
}
private <T> Field<T> field(T value) {
Field<T> f = new Field<T>();
f.setValue(value);
return f;
}
private Publication publication() {
Publication p = new Publication();
p.setDataInfo(df("0.9"));
return p;
}
private Publication publication(String trust) {
Publication p = new Publication();
p.setDataInfo(df(trust));
return p;
}
private DataInfo df(String trust) {
DataInfo d = new DataInfo();
d.setTrust(trust);
return d;
}
}