2019-10-24 11:39:41 +02:00
package eu.dnetlib.dhp.schema.oaf ;
2019-12-10 14:57:16 +01:00
import org.apache.commons.lang3.StringUtils ;
2019-10-24 11:39:41 +02:00
import java.io.Serializable ;
import java.util.List ;
2019-12-10 14:57:16 +01:00
import java.util.Map ;
import java.util.Objects ;
2019-10-24 11:39:41 +02:00
2019-10-25 18:10:30 +02:00
public abstract class Result extends OafEntity implements Serializable {
2019-10-24 11:39:41 +02:00
private List < Author > author ;
// resulttype allows subclassing results into publications | datasets | software
private Qualifier resulttype ;
// common fields
private Qualifier language ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private List < Qualifier > country ;
private List < StructuredProperty > subject ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private List < StructuredProperty > title ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private List < StructuredProperty > relevantdate ;
private List < Field < String > > description ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private Field < String > dateofacceptance ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private Field < String > publisher ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private Field < String > embargoenddate ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private List < Field < String > > source ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private List < Field < String > > fulltext ; // remove candidate
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private List < Field < String > > format ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private List < Field < String > > contributor ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private Qualifier resourcetype ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private List < Field < String > > coverage ;
2019-12-10 14:57:16 +01:00
2019-10-24 11:39:41 +02:00
private Field < String > refereed ; //peer-review status
private List < Context > context ;
2019-11-14 15:42:52 +01:00
// ( article | book ) processing charges. Defined here to cope with possible wrongly typed results
private Field < String > processingchargeamount ;
// currency - alphabetic code describe in ISO-4217. Defined here to cope with possible wrongly typed results
private Field < String > processingchargecurrency ;
2019-10-24 11:39:41 +02:00
private List < ExternalReference > externalReference ;
private List < Instance > instance ;
public List < Author > getAuthor ( ) {
return author ;
}
2019-10-25 18:10:30 +02:00
public void setAuthor ( List < Author > author ) {
2019-10-24 11:39:41 +02:00
this . author = author ;
}
public Qualifier getResulttype ( ) {
return resulttype ;
}
2019-10-25 18:10:30 +02:00
public void setResulttype ( Qualifier resulttype ) {
2019-10-24 11:39:41 +02:00
this . resulttype = resulttype ;
}
public Qualifier getLanguage ( ) {
return language ;
}
2019-10-25 18:10:30 +02:00
public void setLanguage ( Qualifier language ) {
2019-10-24 11:39:41 +02:00
this . language = language ;
}
public List < Qualifier > getCountry ( ) {
return country ;
}
2019-10-25 18:10:30 +02:00
public void setCountry ( List < Qualifier > country ) {
2019-10-24 11:39:41 +02:00
this . country = country ;
}
public List < StructuredProperty > getSubject ( ) {
return subject ;
}
2019-10-25 18:10:30 +02:00
public void setSubject ( List < StructuredProperty > subject ) {
2019-10-24 11:39:41 +02:00
this . subject = subject ;
}
public List < StructuredProperty > getTitle ( ) {
return title ;
}
2019-10-25 18:10:30 +02:00
public void setTitle ( List < StructuredProperty > title ) {
2019-10-24 11:39:41 +02:00
this . title = title ;
}
public List < StructuredProperty > getRelevantdate ( ) {
return relevantdate ;
}
2019-10-25 18:10:30 +02:00
public void setRelevantdate ( List < StructuredProperty > relevantdate ) {
2019-10-24 11:39:41 +02:00
this . relevantdate = relevantdate ;
}
public List < Field < String > > getDescription ( ) {
return description ;
}
2019-10-25 18:10:30 +02:00
public void setDescription ( List < Field < String > > description ) {
2019-10-24 11:39:41 +02:00
this . description = description ;
}
public Field < String > getDateofacceptance ( ) {
return dateofacceptance ;
}
2019-10-25 18:10:30 +02:00
public void setDateofacceptance ( Field < String > dateofacceptance ) {
2019-10-24 11:39:41 +02:00
this . dateofacceptance = dateofacceptance ;
}
public Field < String > getPublisher ( ) {
return publisher ;
}
2019-10-25 18:10:30 +02:00
public void setPublisher ( Field < String > publisher ) {
2019-10-24 11:39:41 +02:00
this . publisher = publisher ;
}
public Field < String > getEmbargoenddate ( ) {
return embargoenddate ;
}
2019-10-25 18:10:30 +02:00
public void setEmbargoenddate ( Field < String > embargoenddate ) {
2019-10-24 11:39:41 +02:00
this . embargoenddate = embargoenddate ;
}
public List < Field < String > > getSource ( ) {
return source ;
}
2019-10-25 18:10:30 +02:00
public void setSource ( List < Field < String > > source ) {
2019-10-24 11:39:41 +02:00
this . source = source ;
}
public List < Field < String > > getFulltext ( ) {
return fulltext ;
}
2019-10-25 18:10:30 +02:00
public void setFulltext ( List < Field < String > > fulltext ) {
2019-10-24 11:39:41 +02:00
this . fulltext = fulltext ;
}
public List < Field < String > > getFormat ( ) {
return format ;
}
2019-10-25 18:10:30 +02:00
public void setFormat ( List < Field < String > > format ) {
2019-10-24 11:39:41 +02:00
this . format = format ;
}
public List < Field < String > > getContributor ( ) {
return contributor ;
}
2019-10-25 18:10:30 +02:00
public void setContributor ( List < Field < String > > contributor ) {
2019-10-24 11:39:41 +02:00
this . contributor = contributor ;
}
public Qualifier getResourcetype ( ) {
return resourcetype ;
}
2019-10-25 18:10:30 +02:00
public void setResourcetype ( Qualifier resourcetype ) {
2019-10-24 11:39:41 +02:00
this . resourcetype = resourcetype ;
}
public List < Field < String > > getCoverage ( ) {
return coverage ;
}
2019-10-25 18:10:30 +02:00
public void setCoverage ( List < Field < String > > coverage ) {
2019-10-24 11:39:41 +02:00
this . coverage = coverage ;
}
public Field < String > getRefereed ( ) {
return refereed ;
}
2019-10-25 18:10:30 +02:00
public void setRefereed ( Field < String > refereed ) {
2019-10-24 11:39:41 +02:00
this . refereed = refereed ;
}
public List < Context > getContext ( ) {
return context ;
}
2019-10-25 18:10:30 +02:00
public void setContext ( List < Context > context ) {
2019-10-24 11:39:41 +02:00
this . context = context ;
}
public List < ExternalReference > getExternalReference ( ) {
return externalReference ;
}
2019-10-25 18:10:30 +02:00
public void setExternalReference ( List < ExternalReference > externalReference ) {
2019-10-24 11:39:41 +02:00
this . externalReference = externalReference ;
}
public List < Instance > getInstance ( ) {
return instance ;
}
2019-10-25 18:10:30 +02:00
public void setInstance ( List < Instance > instance ) {
2019-10-24 11:39:41 +02:00
this . instance = instance ;
}
2019-11-14 15:42:52 +01:00
public Field < String > getProcessingchargeamount ( ) {
return processingchargeamount ;
}
public Result setProcessingchargeamount ( Field < String > processingchargeamount ) {
this . processingchargeamount = processingchargeamount ;
return this ;
}
public Field < String > getProcessingchargecurrency ( ) {
return processingchargecurrency ;
}
public Result setProcessingchargecurrency ( Field < String > processingchargecurrency ) {
this . processingchargecurrency = processingchargecurrency ;
return this ;
}
2019-12-10 14:57:16 +01:00
@Override
public void mergeFrom ( OafEntity e ) {
super . mergeFrom ( e ) ;
Result r = ( Result ) e ;
mergeAuthors ( r . getAuthor ( ) ) ;
//TODO mergeFrom is used only for create Dedup Records since the creation of these two fields requires more complex functions (maybe they will be filled in an external function)
// if (author == null)
// author = r.getAuthor(); //authors will be replaced because they could be too much
// dateofacceptance = r.getDateofacceptance();
// instance = mergeLists(instance, r.getInstance());
if ( r . getResulttype ( ) ! = null )
resulttype = r . getResulttype ( ) ;
if ( r . getLanguage ( ) ! = null )
language = r . getLanguage ( ) ;
country = mergeLists ( country , r . getCountry ( ) ) ;
subject = mergeLists ( subject , r . getSubject ( ) ) ;
title = mergeLists ( title , r . getTitle ( ) ) ;
relevantdate = mergeLists ( relevantdate , r . getRelevantdate ( ) ) ;
description = mergeLists ( description , r . getDescription ( ) ) ;
if ( r . getPublisher ( ) ! = null )
publisher = r . getPublisher ( ) ;
if ( r . getEmbargoenddate ( ) ! = null )
embargoenddate = r . getEmbargoenddate ( ) ;
source = mergeLists ( source , r . getSource ( ) ) ;
fulltext = mergeLists ( fulltext , r . getFulltext ( ) ) ;
format = mergeLists ( format , r . getFormat ( ) ) ;
contributor = mergeLists ( contributor , r . getContributor ( ) ) ;
if ( r . getResourcetype ( ) ! = null )
resourcetype = r . getResourcetype ( ) ;
coverage = mergeLists ( coverage , r . getCoverage ( ) ) ;
if ( r . getRefereed ( ) ! = null )
refereed = r . getRefereed ( ) ;
context = mergeLists ( context , r . getContext ( ) ) ;
if ( r . getProcessingchargeamount ( ) ! = null )
processingchargeamount = r . getProcessingchargeamount ( ) ;
if ( r . getProcessingchargecurrency ( ) ! = null )
processingchargecurrency = r . getProcessingchargecurrency ( ) ;
externalReference = mergeLists ( externalReference , r . getExternalReference ( ) ) ;
}
public void mergeAuthors ( List < Author > authors ) {
int c1 = countAuthorsPids ( author ) ;
int c2 = countAuthorsPids ( authors ) ;
int s1 = authorsSize ( author ) ;
int s2 = authorsSize ( authors ) ;
//if both have no authors with pids and authors is bigger than author
if ( c1 = = 0 & & c2 = = 0 & & author . size ( ) < authors . size ( ) ) {
author = authors ;
return ;
}
//author is null and authors have 0 or more authors with pids
if ( c1 < c2 & & c1 < 0 ) {
author = authors ;
return ;
}
//andiamo a mangiare
// if (author == null && authors == null)
// return;
//
// int c1 = countAuthorsPids(author);
// int c2 = countAuthorsPids(authors);
//
// if (c1<c2 && c1<1){
// author = authors;
// return;
// }
//
// if (c1<c2)
}
public int countAuthorsPids ( List < Author > authors ) {
if ( authors = = null )
return - 1 ;
return ( int ) authors . stream ( ) . map ( this : : extractAuthorPid ) . filter ( Objects : : nonNull ) . filter ( StringUtils : : isNotBlank ) . count ( ) ;
}
public int authorsSize ( List < Author > authors ) {
if ( authors = = null )
return 0 ;
return authors . size ( ) ;
}
public String extractAuthorPid ( Author a ) {
if ( a = = null | | a . getPid ( ) = = null | | a . getPid ( ) . size ( ) = = 0 )
return null ;
StringBuilder mainPid = new StringBuilder ( ) ;
a . getPid ( ) . forEach ( pid - > {
if ( pid . getQualifier ( ) . getClassid ( ) . equalsIgnoreCase ( " orcid " ) ) {
mainPid . setLength ( 0 ) ;
mainPid . append ( pid . getValue ( ) ) ;
}
else {
if ( mainPid . length ( ) = = 0 )
mainPid . append ( pid . getValue ( ) ) ;
}
} ) ;
return mainPid . toString ( ) ;
}
2019-10-24 11:39:41 +02:00
}