2020-02-26 10:51:35 +01:00
|
|
|
package eu.dnetlib.dhp.provision.scholix;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import eu.dnetlib.dhp.provision.scholix.summary.ScholixSummary;
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.Relation;
|
2020-02-26 12:09:06 +01:00
|
|
|
import eu.dnetlib.dhp.utils.DHPUtils;
|
2020-02-26 10:51:35 +01:00
|
|
|
import java.io.Serializable;
|
2020-03-19 11:11:07 +01:00
|
|
|
import java.util.*;
|
2020-02-26 10:51:35 +01:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
public class Scholix implements Serializable {
|
|
|
|
private String publicationDate;
|
|
|
|
|
|
|
|
private List<ScholixEntityId> publisher;
|
|
|
|
|
|
|
|
private List<ScholixEntityId> linkprovider;
|
|
|
|
|
|
|
|
private ScholixRelationship relationship;
|
|
|
|
|
|
|
|
private ScholixResource source;
|
|
|
|
|
|
|
|
private ScholixResource target;
|
|
|
|
|
|
|
|
private String identifier;
|
|
|
|
|
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public Scholix clone(final ScholixResource t) {
|
|
|
|
final Scholix clone = new Scholix();
|
|
|
|
clone.setPublicationDate(publicationDate);
|
|
|
|
clone.setPublisher(publisher);
|
|
|
|
clone.setLinkprovider(linkprovider);
|
|
|
|
clone.setRelationship(relationship);
|
|
|
|
clone.setSource(source);
|
|
|
|
clone.setTarget(t);
|
|
|
|
clone.generatelinkPublisher();
|
|
|
|
clone.generateIdentifier();
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-26 10:51:35 +01:00
|
|
|
public static Scholix generateScholixWithSource(final String sourceSummaryJson, final String relation) {
|
|
|
|
final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
|
|
try {
|
|
|
|
ScholixSummary scholixSummary = mapper.readValue(sourceSummaryJson, ScholixSummary.class);
|
2020-02-26 12:09:06 +01:00
|
|
|
Relation rel = mapper.readValue(relation, Relation.class);
|
2020-02-26 10:51:35 +01:00
|
|
|
final Scholix s = new Scholix();
|
2020-02-26 15:42:20 +01:00
|
|
|
if (scholixSummary.getDate() != null && scholixSummary.getDate().size()>0)
|
|
|
|
s.setPublicationDate(scholixSummary.getDate().get(0));
|
2020-02-26 10:51:35 +01:00
|
|
|
s.setLinkprovider(rel.getCollectedFrom().stream().map(cf ->
|
|
|
|
new ScholixEntityId(cf.getValue(), Collections.singletonList(
|
|
|
|
new ScholixIdentifier(cf.getKey(), "dnet_identifier")
|
|
|
|
))).collect(Collectors.toList()));
|
2020-02-26 12:09:06 +01:00
|
|
|
s.setRelationship(new ScholixRelationship(rel.getRelType(),rel.getRelClass(),null ));
|
|
|
|
s.setSource(ScholixResource.fromSummary(scholixSummary));
|
|
|
|
return s;
|
2020-02-26 10:51:35 +01:00
|
|
|
} catch (Throwable e) {
|
2020-02-26 15:25:03 +01:00
|
|
|
throw new RuntimeException(String.format("Summary: %s \n relation:%s",sourceSummaryJson, relation), e);
|
2020-02-26 10:51:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public static Scholix generateScholixWithSource(final ScholixSummary scholixSummary, final Relation rel) {
|
|
|
|
final Scholix s = new Scholix();
|
|
|
|
if (scholixSummary.getDate() != null && scholixSummary.getDate().size()>0)
|
|
|
|
s.setPublicationDate(scholixSummary.getDate().get(0));
|
|
|
|
s.setLinkprovider(rel.getCollectedFrom().stream().map(cf ->
|
|
|
|
new ScholixEntityId(cf.getValue(), Collections.singletonList(
|
|
|
|
new ScholixIdentifier(cf.getKey(), "dnet_identifier")
|
|
|
|
))).collect(Collectors.toList()));
|
|
|
|
s.setRelationship(new ScholixRelationship(rel.getRelType(),rel.getRelClass(),null ));
|
|
|
|
s.setSource(ScholixResource.fromSummary(scholixSummary));
|
|
|
|
|
|
|
|
s.setIdentifier(rel.getTarget());
|
|
|
|
// ScholixResource mockTarget = new ScholixResource();
|
|
|
|
// mockTarget.setDnetIdentifier(rel.getTarget());
|
|
|
|
// s.setTarget(mockTarget);
|
|
|
|
// s.generateIdentifier();
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void generatelinkPublisher() {
|
|
|
|
Set<String> publisher = new HashSet<>();
|
|
|
|
if (source.getPublisher() != null)
|
|
|
|
publisher.addAll(source.getPublisher().stream().map(ScholixEntityId::getName).collect(Collectors.toList()));
|
|
|
|
if (target.getPublisher() != null)
|
|
|
|
publisher.addAll(target.getPublisher().stream().map(ScholixEntityId::getName).collect(Collectors.toList()));
|
|
|
|
this.publisher = publisher.stream().map(k -> new ScholixEntityId(k ,null)).collect(Collectors.toList());
|
|
|
|
}
|
2020-02-26 12:09:06 +01:00
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public void generateIdentifier( ) {
|
2020-02-26 12:09:06 +01:00
|
|
|
setIdentifier(DHPUtils.md5(String.format("%s::%s::%s",source.getDnetIdentifier(),relationship.getName(), target.getDnetIdentifier())));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-26 10:51:35 +01:00
|
|
|
public Scholix addTarget(final String targetSummaryJson) {
|
2020-02-26 12:09:06 +01:00
|
|
|
final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
|
|
try {
|
|
|
|
ScholixSummary targetSummary = mapper.readValue(targetSummaryJson, ScholixSummary.class);
|
|
|
|
setTarget(ScholixResource.fromSummary(targetSummary));
|
|
|
|
generateIdentifier();
|
|
|
|
return this;
|
|
|
|
} catch (Throwable e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2020-02-26 10:51:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getPublicationDate() {
|
|
|
|
return publicationDate;
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public void setPublicationDate(String publicationDate) {
|
2020-02-26 10:51:35 +01:00
|
|
|
this.publicationDate = publicationDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<ScholixEntityId> getPublisher() {
|
|
|
|
return publisher;
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public void setPublisher(List<ScholixEntityId> publisher) {
|
2020-02-26 10:51:35 +01:00
|
|
|
this.publisher = publisher;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<ScholixEntityId> getLinkprovider() {
|
|
|
|
return linkprovider;
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public void setLinkprovider(List<ScholixEntityId> linkprovider) {
|
2020-02-26 10:51:35 +01:00
|
|
|
this.linkprovider = linkprovider;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ScholixRelationship getRelationship() {
|
|
|
|
return relationship;
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public void setRelationship(ScholixRelationship relationship) {
|
2020-02-26 10:51:35 +01:00
|
|
|
this.relationship = relationship;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ScholixResource getSource() {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public void setSource(ScholixResource source) {
|
2020-02-26 10:51:35 +01:00
|
|
|
this.source = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ScholixResource getTarget() {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:11:07 +01:00
|
|
|
public void setTarget(ScholixResource target) {
|
2020-02-26 10:51:35 +01:00
|
|
|
this.target = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getIdentifier() {
|
|
|
|
return identifier;
|
|
|
|
}
|
2020-03-19 11:11:07 +01:00
|
|
|
public void setIdentifier(String identifier) {
|
2020-02-26 10:51:35 +01:00
|
|
|
this.identifier = identifier;
|
|
|
|
}
|
|
|
|
}
|