Merge pull request 'APClevelresult' (#13) from APClevelresult into master

Reviewed-on: #13
This commit is contained in:
Alessia Bardi 2022-02-04 14:11:52 +01:00
commit 30697da8dd
4 changed files with 113 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@ -17,6 +18,18 @@ import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions;
*/
public class Result extends OafEntity implements Serializable {
/**
* ( article | book ) processing charges.
*/
private Field<String> processingchargeamount;
/**
* currency - alphabetic code describe in ISO-4217.
*/
private Field<String> processingchargecurrency;
/**
* The Measures.
*/
@ -147,6 +160,22 @@ public class Result extends OafEntity implements Serializable {
this.measures = measures;
}
public Field<String> getProcessingchargeamount() {
return processingchargeamount;
}
public void setProcessingchargeamount(Field<String> processingchargeamount) {
this.processingchargeamount = processingchargeamount;
}
public Field<String> getProcessingchargecurrency() {
return processingchargecurrency;
}
public void setProcessingchargecurrency(Field<String> processingchargecurrency) {
this.processingchargecurrency = processingchargecurrency;
}
/**
* Gets author.
*
@ -713,6 +742,11 @@ public class Result extends OafEntity implements Serializable {
Result r = (Result) e;
if(processingchargeamount == null || StringUtils.isBlank(processingchargeamount.getValue() )){
processingchargeamount = r.getProcessingchargeamount();
processingchargecurrency = r.getProcessingchargecurrency();
}
measures = mergeLists(measures, r.getMeasures());
if( !isAnEnrichment(this) && !isAnEnrichment(e))

View File

@ -12,6 +12,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -130,7 +131,81 @@ class MergeTest {
}
/**
* Test the merge of the APC at the level of the result and the instance.
*
* @throws Exception the exception
*/
@Test
void testAPCMerge() throws Exception {
List<Result> publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publication_apc.json", Publication.class);
System.out.println(publications.size());
publications.forEach(p -> assertEquals(1, p.getInstance().size()));
publications.forEach(p -> assertTrue(p.getProcessingchargeamount() != null ));
publications.forEach(p -> assertTrue(p.getProcessingchargecurrency() != null ));
publications.forEach(p -> assertTrue(StringUtils.isNotBlank(p.getProcessingchargeamount().getValue() )));
publications.forEach(p -> assertTrue(StringUtils.isNotBlank(p.getProcessingchargecurrency().getValue() )));
publications.forEach(p -> p.getInstance().stream()
.forEach(i -> assertTrue(i.getProcessingchargeamount() != null)));
publications.forEach(p -> p.getInstance().stream()
.forEach(i -> assertTrue(i.getProcessingchargecurrency() != null)));
publications.forEach(p -> p.getInstance().stream()
.forEach(i -> assertTrue(StringUtils.isNotBlank(i.getProcessingchargeamount().getValue()))));
publications.forEach(p -> p.getInstance().stream()
.forEach(i -> assertTrue(StringUtils.isNotBlank(i.getProcessingchargecurrency().getValue()))));
Result p1 = publications.get(0);
Result p2 = publications.get(1);
p1.mergeFrom(p2);
assertEquals("1721.47", p1.getProcessingchargeamount().getValue());
assertEquals("EUR", p1.getProcessingchargecurrency().getValue());
assertEquals(2 , p1.getInstance().size());
p1.getInstance().stream().forEach(i -> assertTrue(i.getProcessingchargeamount() != null));
p1.getInstance().stream().forEach(i -> assertTrue(i.getProcessingchargecurrency() != null));
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount().getValue().equals("2000.47"));
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount().getValue().equals("1721.47"));
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency().getValue().equals("EUR"));
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency().getValue().equals("USD"));
System.out.println(new ObjectMapper().writeValueAsString(p1));
}
@Test
void testAPCMerge2() throws Exception {
List<Result> publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publication_apc2.json", Publication.class);
System.out.println(publications.size());
publications.forEach(p -> assertEquals(1, p.getInstance().size()));
assertTrue(publications.get(0).getProcessingchargeamount() != null );
assertTrue(publications.get(0).getProcessingchargecurrency() != null );
assertTrue(publications.get(1).getProcessingchargeamount() == null );
Result p1 = publications.get(1);
Result p2 = publications.get(0);
p1.mergeFrom(p2);
assertEquals("1721.47", p1.getProcessingchargeamount().getValue());
assertEquals("EUR", p1.getProcessingchargecurrency().getValue());
assertEquals(2 , p1.getInstance().size());
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount() != null);
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency() != null);
assertEquals("1721.47", p1.getInstance().stream().filter(i -> i.getProcessingchargeamount() != null)
.collect(Collectors.toList()).get(0).getProcessingchargeamount().getValue());
assertEquals("EUR", p1.getInstance().stream().filter(i -> i.getProcessingchargeamount() != null)
.collect(Collectors.toList()).get(0).getProcessingchargecurrency().getValue());
System.out.println(new ObjectMapper().writeValueAsString(p1));
}
/**
* Test enrichment function.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long