1
0
Fork 0

[dhp-schemas] added safeguard against casting exception in mergeFrom methods and null-safe handling of collectedfrom collection for relation

This commit is contained in:
Przemysław Jacewicz 2020-04-01 18:28:23 +02:00 committed by przemek
parent 9d1d18d4b9
commit 51ff3b4e81
9 changed files with 43 additions and 6 deletions

View File

@ -79,6 +79,11 @@ public class Dataset extends Result implements Serializable {
@Override @Override
public void mergeFrom(OafEntity e) { public void mergeFrom(OafEntity e) {
super.mergeFrom(e); super.mergeFrom(e);
if (!Dataset.class.isAssignableFrom(e.getClass())){
return;
}
final Dataset d = (Dataset) e; final Dataset d = (Dataset) e;
storagedate = d.getStoragedate() != null && compareTrust(this, e)<0? d.getStoragedate() : storagedate; storagedate = d.getStoragedate() != null && compareTrust(this, e)<0? d.getStoragedate() : storagedate;

View File

@ -367,6 +367,10 @@ public class Datasource extends OafEntity implements Serializable {
public void mergeFrom(OafEntity e) { public void mergeFrom(OafEntity e) {
super.mergeFrom(e); super.mergeFrom(e);
if (!Datasource.class.isAssignableFrom(e.getClass())){
return;
}
Datasource d = (Datasource)e; Datasource d = (Datasource)e;
datasourcetype = d.getDatasourcetype() != null && compareTrust(this, e)<0? d.getDatasourcetype() : datasourcetype; datasourcetype = d.getDatasourcetype() != null && compareTrust(this, e)<0? d.getDatasourcetype() : datasourcetype;

View File

@ -170,6 +170,11 @@ public class Organization extends OafEntity implements Serializable {
@Override @Override
public void mergeFrom(OafEntity e) { public void mergeFrom(OafEntity e) {
super.mergeFrom(e); super.mergeFrom(e);
if (!Organization.class.isAssignableFrom(e.getClass())){
return;
}
final Organization o = (Organization) e; final Organization o = (Organization) e;
legalshortname = o.getLegalshortname() != null && compareTrust(this, e)<0? o.getLegalshortname() : legalshortname; legalshortname = o.getLegalshortname() != null && compareTrust(this, e)<0? o.getLegalshortname() : legalshortname;
legalname = o.getLegalname() != null && compareTrust(this, e)<0 ? o.getLegalname() : legalname; legalname = o.getLegalname() != null && compareTrust(this, e)<0 ? o.getLegalname() : legalname;

View File

@ -40,6 +40,10 @@ public class OtherResearchProduct extends Result implements Serializable {
public void mergeFrom(OafEntity e) { public void mergeFrom(OafEntity e) {
super.mergeFrom(e); super.mergeFrom(e);
if (!OtherResearchProduct.class.isAssignableFrom(e.getClass())){
return;
}
OtherResearchProduct o = (OtherResearchProduct)e; OtherResearchProduct o = (OtherResearchProduct)e;
contactperson = mergeLists(contactperson, o.getContactperson()); contactperson = mergeLists(contactperson, o.getContactperson());

View File

@ -270,6 +270,11 @@ public class Project extends OafEntity implements Serializable {
@Override @Override
public void mergeFrom(OafEntity e) { public void mergeFrom(OafEntity e) {
super.mergeFrom(e); super.mergeFrom(e);
if (!Project.class.isAssignableFrom(e.getClass())){
return;
}
Project p = (Project)e; Project p = (Project)e;
websiteurl= p.getWebsiteurl()!= null && compareTrust(this,e)<0?p.getWebsiteurl():websiteurl; websiteurl= p.getWebsiteurl()!= null && compareTrust(this,e)<0?p.getWebsiteurl():websiteurl;

View File

@ -20,6 +20,10 @@ public class Publication extends Result implements Serializable {
public void mergeFrom(OafEntity e) { public void mergeFrom(OafEntity e) {
super.mergeFrom(e); super.mergeFrom(e);
if (!Publication.class.isAssignableFrom(e.getClass())){
return;
}
Publication p = (Publication) e; Publication p = (Publication) e;
if (p.getJournal() != null && compareTrust(this, e)<0) if (p.getJournal() != null && compareTrust(this, e)<0)

View File

@ -1,8 +1,6 @@
package eu.dnetlib.dhp.schema.oaf; package eu.dnetlib.dhp.schema.oaf;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -78,9 +76,12 @@ public class Relation extends Oaf {
checkArgument(Objects.equals(getSubRelType(), r.getSubRelType()),"subRelType(s) must be equal"); checkArgument(Objects.equals(getSubRelType(), r.getSubRelType()),"subRelType(s) must be equal");
checkArgument(Objects.equals(getRelClass(), r.getRelClass()),"relClass(es) must be equal"); checkArgument(Objects.equals(getRelClass(), r.getRelClass()),"relClass(es) must be equal");
setCollectedFrom(Stream.concat(getCollectedFrom().stream(), r.getCollectedFrom().stream()) setCollectedFrom(
.distinct() // relies on KeyValue.equals Stream
.collect(Collectors.toList())); .concat(Optional.ofNullable(getCollectedFrom()).map(Collection::stream).orElse(Stream.empty()),
Optional.ofNullable(r.getCollectedFrom()).map(Collection::stream).orElse(Stream.empty()))
.distinct() // relies on KeyValue.equals
.collect(Collectors.toList()));
} }
@Override @Override

View File

@ -223,6 +223,10 @@ public class Result extends OafEntity implements Serializable {
public void mergeFrom(OafEntity e) { public void mergeFrom(OafEntity e) {
super.mergeFrom(e); super.mergeFrom(e);
if (!Result.class.isAssignableFrom(e.getClass())){
return;
}
Result r = (Result) e; Result r = (Result) e;
instance = mergeLists(instance, r.getInstance()); instance = mergeLists(instance, r.getInstance());

View File

@ -49,6 +49,11 @@ public class Software extends Result implements Serializable {
@Override @Override
public void mergeFrom(OafEntity e) { public void mergeFrom(OafEntity e) {
super.mergeFrom(e); super.mergeFrom(e);
if (!Software.class.isAssignableFrom(e.getClass())){
return;
}
final Software s = (Software) e; final Software s = (Software) e;
documentationUrl = mergeLists(documentationUrl, s.getDocumentationUrl()); documentationUrl = mergeLists(documentationUrl, s.getDocumentationUrl());