more proto 2 graph model mappings

This commit is contained in:
Claudio Atzori 2019-10-25 09:25:36 +02:00
parent d46371ceab
commit c929c1dfac
6 changed files with 231 additions and 106 deletions

View File

@ -65,7 +65,7 @@ public class Datasource extends OafEntity implements Serializable {
private Field<String> databaseaccessrestriction;
// {feeRequired, registration, other}
private Field<String> datauploadrestriction9;
private Field<String> datauploadrestriction;
private Field<Boolean> versioning;
@ -86,279 +86,314 @@ public class Datasource extends OafEntity implements Serializable {
return datasourcetype;
}
public void setDatasourcetype(Qualifier datasourcetype) {
public Datasource setDatasourcetype(Qualifier datasourcetype) {
this.datasourcetype = datasourcetype;
return this;
}
public Qualifier getOpenairecompatibility() {
return openairecompatibility;
}
public void setOpenairecompatibility(Qualifier openairecompatibility) {
public Datasource setOpenairecompatibility(Qualifier openairecompatibility) {
this.openairecompatibility = openairecompatibility;
return this;
}
public Field<String> getOfficialname() {
return officialname;
}
public void setOfficialname(Field<String> officialname) {
public Datasource setOfficialname(Field<String> officialname) {
this.officialname = officialname;
return this;
}
public Field<String> getEnglishname() {
return englishname;
}
public void setEnglishname(Field<String> englishname) {
public Datasource setEnglishname(Field<String> englishname) {
this.englishname = englishname;
return this;
}
public Field<String> getWebsiteurl() {
return websiteurl;
}
public void setWebsiteurl(Field<String> websiteurl) {
public Datasource setWebsiteurl(Field<String> websiteurl) {
this.websiteurl = websiteurl;
return this;
}
public Field<String> getLogourl() {
return logourl;
}
public void setLogourl(Field<String> logourl) {
public Datasource setLogourl(Field<String> logourl) {
this.logourl = logourl;
return this;
}
public Field<String> getContactemail() {
return contactemail;
}
public void setContactemail(Field<String> contactemail) {
public Datasource setContactemail(Field<String> contactemail) {
this.contactemail = contactemail;
return this;
}
public Field<String> getNamespaceprefix() {
return namespaceprefix;
}
public void setNamespaceprefix(Field<String> namespaceprefix) {
public Datasource setNamespaceprefix(Field<String> namespaceprefix) {
this.namespaceprefix = namespaceprefix;
return this;
}
public Field<String> getLatitude() {
return latitude;
}
public void setLatitude(Field<String> latitude) {
public Datasource setLatitude(Field<String> latitude) {
this.latitude = latitude;
return this;
}
public Field<String> getLongitude() {
return longitude;
}
public void setLongitude(Field<String> longitude) {
public Datasource setLongitude(Field<String> longitude) {
this.longitude = longitude;
return this;
}
public Field<String> getDateofvalidation() {
return dateofvalidation;
}
public void setDateofvalidation(Field<String> dateofvalidation) {
public Datasource setDateofvalidation(Field<String> dateofvalidation) {
this.dateofvalidation = dateofvalidation;
return this;
}
public Field<String> getDescription() {
return description;
}
public void setDescription(Field<String> description) {
public Datasource setDescription(Field<String> description) {
this.description = description;
return this;
}
public List<StructuredProperty> getSubjects() {
return subjects;
}
public void setSubjects(List<StructuredProperty> subjects) {
public Datasource setSubjects(List<StructuredProperty> subjects) {
this.subjects = subjects;
return this;
}
public Field<String> getOdnumberofitems() {
return odnumberofitems;
}
public void setOdnumberofitems(Field<String> odnumberofitems) {
public Datasource setOdnumberofitems(Field<String> odnumberofitems) {
this.odnumberofitems = odnumberofitems;
return this;
}
public Field<String> getOdnumberofitemsdate() {
return odnumberofitemsdate;
}
public void setOdnumberofitemsdate(Field<String> odnumberofitemsdate) {
public Datasource setOdnumberofitemsdate(Field<String> odnumberofitemsdate) {
this.odnumberofitemsdate = odnumberofitemsdate;
return this;
}
public Field<String> getOdpolicies() {
return odpolicies;
}
public void setOdpolicies(Field<String> odpolicies) {
public Datasource setOdpolicies(Field<String> odpolicies) {
this.odpolicies = odpolicies;
return this;
}
public List<Field<String>> getOdlanguages() {
return odlanguages;
}
public void setOdlanguages(List<Field<String>> odlanguages) {
public Datasource setOdlanguages(List<Field<String>> odlanguages) {
this.odlanguages = odlanguages;
return this;
}
public List<Field<String>> getOdcontenttypes() {
return odcontenttypes;
}
public void setOdcontenttypes(List<Field<String>> odcontenttypes) {
public Datasource setOdcontenttypes(List<Field<String>> odcontenttypes) {
this.odcontenttypes = odcontenttypes;
return this;
}
public List<Field<String>> getAccessinfopackage() {
return accessinfopackage;
}
public void setAccessinfopackage(List<Field<String>> accessinfopackage) {
public Datasource setAccessinfopackage(List<Field<String>> accessinfopackage) {
this.accessinfopackage = accessinfopackage;
return this;
}
public Field<String> getReleasestartdate() {
return releasestartdate;
}
public void setReleasestartdate(Field<String> releasestartdate) {
public Datasource setReleasestartdate(Field<String> releasestartdate) {
this.releasestartdate = releasestartdate;
return this;
}
public Field<String> getReleaseenddate() {
return releaseenddate;
}
public void setReleaseenddate(Field<String> releaseenddate) {
public Datasource setReleaseenddate(Field<String> releaseenddate) {
this.releaseenddate = releaseenddate;
return this;
}
public Field<String> getMissionstatementurl() {
return missionstatementurl;
}
public void setMissionstatementurl(Field<String> missionstatementurl) {
public Datasource setMissionstatementurl(Field<String> missionstatementurl) {
this.missionstatementurl = missionstatementurl;
return this;
}
public Field<Boolean> getDataprovider() {
return dataprovider;
}
public void setDataprovider(Field<Boolean> dataprovider) {
public Datasource setDataprovider(Field<Boolean> dataprovider) {
this.dataprovider = dataprovider;
return this;
}
public Field<Boolean> getServiceprovider() {
return serviceprovider;
}
public void setServiceprovider(Field<Boolean> serviceprovider) {
public Datasource setServiceprovider(Field<Boolean> serviceprovider) {
this.serviceprovider = serviceprovider;
return this;
}
public Field<String> getDatabaseaccesstype() {
return databaseaccesstype;
}
public void setDatabaseaccesstype(Field<String> databaseaccesstype) {
public Datasource setDatabaseaccesstype(Field<String> databaseaccesstype) {
this.databaseaccesstype = databaseaccesstype;
return this;
}
public Field<String> getDatauploadtype() {
return datauploadtype;
}
public void setDatauploadtype(Field<String> datauploadtype) {
public Datasource setDatauploadtype(Field<String> datauploadtype) {
this.datauploadtype = datauploadtype;
return this;
}
public Field<String> getDatabaseaccessrestriction() {
return databaseaccessrestriction;
}
public void setDatabaseaccessrestriction(Field<String> databaseaccessrestriction) {
public Datasource setDatabaseaccessrestriction(Field<String> databaseaccessrestriction) {
this.databaseaccessrestriction = databaseaccessrestriction;
return this;
}
public Field<String> getDatauploadrestriction9() {
return datauploadrestriction9;
public Field<String> getDatauploadrestriction() {
return datauploadrestriction;
}
public void setDatauploadrestriction9(Field<String> datauploadrestriction9) {
this.datauploadrestriction9 = datauploadrestriction9;
public Datasource setDatauploadrestriction(Field<String> datauploadrestriction) {
this.datauploadrestriction = datauploadrestriction;
return this;
}
public Field<Boolean> getVersioning() {
return versioning;
}
public void setVersioning(Field<Boolean> versioning) {
public Datasource setVersioning(Field<Boolean> versioning) {
this.versioning = versioning;
return this;
}
public Field<String> getCitationguidelineurl() {
return citationguidelineurl;
}
public void setCitationguidelineurl(Field<String> citationguidelineurl) {
public Datasource setCitationguidelineurl(Field<String> citationguidelineurl) {
this.citationguidelineurl = citationguidelineurl;
return this;
}
public Field<String> getQualitymanagementkind() {
return qualitymanagementkind;
}
public void setQualitymanagementkind(Field<String> qualitymanagementkind) {
public Datasource setQualitymanagementkind(Field<String> qualitymanagementkind) {
this.qualitymanagementkind = qualitymanagementkind;
return this;
}
public Field<String> getPidsystems() {
return pidsystems;
}
public void setPidsystems(Field<String> pidsystems) {
public Datasource setPidsystems(Field<String> pidsystems) {
this.pidsystems = pidsystems;
return this;
}
public Field<String> getCertificates() {
return certificates;
}
public void setCertificates(Field<String> certificates) {
public Datasource setCertificates(Field<String> certificates) {
this.certificates = certificates;
return this;
}
public List<KeyValue> getPolicies() {
return policies;
}
public void setPolicies(List<KeyValue> policies) {
public Datasource setPolicies(List<KeyValue> policies) {
this.policies = policies;
return this;
}
public Journal getJournal() {
return journal;
}
public void setJournal(Journal journal) {
public Datasource setJournal(Journal journal) {
this.journal = journal;
return this;
}
}

View File

@ -32,95 +32,107 @@ public class Journal implements Serializable {
return name;
}
public void setName(String name) {
public Journal setName(String name) {
this.name = name;
return this;
}
public String getIssnPrinted() {
return issnPrinted;
}
public void setIssnPrinted(String issnPrinted) {
public Journal setIssnPrinted(String issnPrinted) {
this.issnPrinted = issnPrinted;
return this;
}
public String getIssnOnline() {
return issnOnline;
}
public void setIssnOnline(String issnOnline) {
public Journal setIssnOnline(String issnOnline) {
this.issnOnline = issnOnline;
return this;
}
public String getIssnLinking() {
return issnLinking;
}
public void setIssnLinking(String issnLinking) {
public Journal setIssnLinking(String issnLinking) {
this.issnLinking = issnLinking;
return this;
}
public String getEp() {
return ep;
}
public void setEp(String ep) {
public Journal setEp(String ep) {
this.ep = ep;
return this;
}
public String getIss() {
return iss;
}
public void setIss(String iss) {
public Journal setIss(String iss) {
this.iss = iss;
return this;
}
public String getSp() {
return sp;
}
public void setSp(String sp) {
public Journal setSp(String sp) {
this.sp = sp;
return this;
}
public String getVol() {
return vol;
}
public void setVol(String vol) {
public Journal setVol(String vol) {
this.vol = vol;
return this;
}
public String getEdition() {
return edition;
}
public void setEdition(String edition) {
public Journal setEdition(String edition) {
this.edition = edition;
return this;
}
public String getConferenceplace() {
return conferenceplace;
}
public void setConferenceplace(String conferenceplace) {
public Journal setConferenceplace(String conferenceplace) {
this.conferenceplace = conferenceplace;
return this;
}
public String getConferencedate() {
return conferencedate;
}
public void setConferencedate(String conferencedate) {
public Journal setConferencedate(String conferencedate) {
this.conferencedate = conferencedate;
return this;
}
public DataInfo getDataInfo() {
return dataInfo;
}
public void setDataInfo(DataInfo dataInfo) {
public Journal setDataInfo(DataInfo dataInfo) {
this.dataInfo = dataInfo;
return this;
}
}

View File

@ -12,15 +12,17 @@ public abstract class Oaf implements Serializable {
return dataInfo;
}
public void setDataInfo(DataInfo dataInfo) {
public Oaf setDataInfo(DataInfo dataInfo) {
this.dataInfo = dataInfo;
return this;
}
public Long getLastupdatetimestamp() {
return lastupdatetimestamp;
}
public void setLastupdatetimestamp(Long lastupdatetimestamp) {
public Oaf setLastupdatetimestamp(Long lastupdatetimestamp) {
this.lastupdatetimestamp = lastupdatetimestamp;
return this;
}
}

View File

@ -29,71 +29,80 @@ public abstract class OafEntity extends Oaf implements Serializable {
return id;
}
public void setId(String id) {
public OafEntity setId(String id) {
this.id = id;
return this;
}
public List<String> getOriginalId() {
return originalId;
}
public void setOriginalId(List<String> originalId) {
public OafEntity setOriginalId(List<String> originalId) {
this.originalId = originalId;
return this;
}
public List<KeyValue> getCollectedfrom() {
return collectedfrom;
}
public void setCollectedfrom(List<KeyValue> collectedfrom) {
public OafEntity setCollectedfrom(List<KeyValue> collectedfrom) {
this.collectedfrom = collectedfrom;
return this;
}
public List<StructuredProperty> getPid() {
return pid;
}
public void setPid(List<StructuredProperty> pid) {
public OafEntity setPid(List<StructuredProperty> pid) {
this.pid = pid;
return this;
}
public String getDateofcollection() {
return dateofcollection;
}
public void setDateofcollection(String dateofcollection) {
public OafEntity setDateofcollection(String dateofcollection) {
this.dateofcollection = dateofcollection;
return this;
}
public String getDateoftransformation() {
return dateoftransformation;
}
public void setDateoftransformation(String dateoftransformation) {
public OafEntity setDateoftransformation(String dateoftransformation) {
this.dateoftransformation = dateoftransformation;
return this;
}
public List<OafEntity> getChildren() {
return children;
}
public void setChildren(List<OafEntity> children) {
public OafEntity setChildren(List<OafEntity> children) {
this.children = children;
return this;
}
public List<ExtraInfo> getExtraInfo() {
return extraInfo;
}
public void setExtraInfo(List<ExtraInfo> extraInfo) {
public OafEntity setExtraInfo(List<ExtraInfo> extraInfo) {
this.extraInfo = extraInfo;
return this;
}
public OAIProvenance getOaiprovenance() {
return oaiprovenance;
}
public void setOaiprovenance(OAIProvenance oaiprovenance) {
public OafEntity setOaiprovenance(OAIProvenance oaiprovenance) {
this.oaiprovenance = oaiprovenance;
return this;
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.dhp.graph;
import eu.dnetlib.data.proto.DatasourceProtos;
import eu.dnetlib.data.proto.KindProtos;
import eu.dnetlib.data.proto.OafProtos;
import eu.dnetlib.data.proto.ProjectProtos;
@ -60,54 +61,78 @@ public class ProtoConverter implements Serializable {
}
private static Organization convertOrganization(OafProtos.Oaf oaf) {
return new Organization();
final DatasourceProtos.Datasource.Metadata m = oaf.getEntity().getDatasource().getMetadata();
final Organization org = setOaf(new Organization(), oaf);
return setEntity(org, oaf);
//TODO set org fields
}
private static Datasource convertDataSource(OafProtos.Oaf oaf) {
final Datasource result = new Datasource();
//Set Oaf Fields
result.setDataInfo(ProtoUtils.mapDataInfo(oaf.getDataInfo()));
result.setLastupdatetimestamp(oaf.getLastupdatetimestamp());
//setting Entity fields
final OafProtos.OafEntity entity = oaf.getEntity();
result.setId(entity.getId());
result.setOriginalId(entity.getOriginalIdList());
result.setCollectedfrom(entity.getCollectedfromList()
.stream()
.map(ProtoUtils::mapKV)
.collect(Collectors.toList()));
result.setPid(entity.getPidList()
.stream()
.map(ProtoUtils::mapStructuredProperty)
.collect(Collectors.toList()));
result.setDateofcollection(entity.getDateofcollection());
result.setDateoftransformation(entity.getDateoftransformation());
result.setExtraInfo(entity.getExtraInfoList()
.stream()
.map(ProtoUtils::mapExtraInfo)
.collect(Collectors.toList()));
return result;
final DatasourceProtos.Datasource.Metadata m = oaf.getEntity().getDatasource().getMetadata();
final Datasource datasource = setOaf(new Datasource(), oaf);
return setEntity(datasource, oaf)
.setAccessinfopackage(m.getAccessinfopackageCount() > 0 ?
m.getAccessinfopackageList()
.stream()
.map(ProtoUtils::mapStringField)
.collect(Collectors.toList()) : null)
.setCertificates(mapStringField(m.getCertificates()))
.setCitationguidelineurl(mapStringField(m.getCitationguidelineurl()))
.setContactemail(mapStringField(m.getContactemail()))
.setDatabaseaccessrestriction(mapStringField(m.getDatabaseaccessrestriction()))
.setDatabaseaccesstype(mapStringField(m.getDatabaseaccesstype()))
.setDataprovider(mapBoolField(m.getDataprovider()))
.setDatasourcetype(mapQualifier(m.getDatasourcetype()))
.setDatauploadrestriction(mapStringField(m.getDatauploadrestriction()))
.setCitationguidelineurl(mapStringField(m.getCitationguidelineurl()))
.setDatauploadtype(mapStringField(m.getDatauploadtype()))
.setDateofvalidation(mapStringField(m.getDateofvalidation()))
.setDescription(mapStringField(m.getDescription()))
.setEnglishname(mapStringField(m.getEnglishname()))
.setLatitude(mapStringField(m.getLatitude()))
.setLongitude(mapStringField(m.getLongitude()))
.setLogourl(mapStringField(m.getLogourl()))
.setMissionstatementurl(mapStringField(m.getMissionstatementurl()))
.setNamespaceprefix(mapStringField(m.getNamespaceprefix()))
.setOdcontenttypes(m.getOdcontenttypesCount() > 0 ?
m.getOdcontenttypesList()
.stream()
.map(ProtoUtils::mapStringField)
.collect(Collectors.toList()) : null)
.setOdlanguages(m.getOdlanguagesCount() > 0 ?
m.getOdlanguagesList()
.stream()
.map(ProtoUtils::mapStringField)
.collect(Collectors.toList()) : null)
.setOdnumberofitems(mapStringField(m.getOdnumberofitems()))
.setOdnumberofitemsdate(mapStringField(m.getOdnumberofitemsdate()))
.setOdpolicies(mapStringField(m.getOdpolicies()))
.setOfficialname(mapStringField(m.getOfficialname()))
.setOpenairecompatibility(mapQualifier(m.getOpenairecompatibility()))
.setPidsystems(mapStringField(m.getPidsystems()))
.setPolicies(m.getPoliciesCount() > 0 ?
m.getPoliciesList()
.stream()
.map(ProtoUtils::mapKV)
.collect(Collectors.toList()) : null)
.setQualitymanagementkind(mapStringField(m.getQualitymanagementkind()))
.setReleaseenddate(mapStringField(m.getReleaseenddate()))
.setServiceprovider(mapBoolField(m.getServiceprovider()))
.setReleasestartdate(mapStringField(m.getReleasestartdate()))
.setSubjects(m.getSubjectsCount() > 0 ?
m.getSubjectsList()
.stream()
.map(ProtoUtils::mapStructuredProperty)
.collect(Collectors.toList()) : null)
.setVersioning(mapBoolField(m.getVersioning()))
.setWebsiteurl(mapStringField(m.getWebsiteurl()))
.setJournal(mapJournal(m.getJournal()));
}
private static Project convertProject(OafProtos.Oaf oaf) {
final ProjectProtos.Project.Metadata m = oaf.getEntity().getProject().getMetadata();
final Project project = new Project();
project.setDataInfo(mapDataInfo(oaf.getDataInfo()));
project.setLastupdatetimestamp(oaf.getLastupdatetimestamp());
return project
final Project project = setOaf(new Project(), oaf);
return setEntity(project, oaf)
.setAcronym(mapStringField(m.getAcronym()))
.setCallidentifier(mapStringField(m.getCallidentifier()))
.setCode(mapStringField(m.getCode()))

View File

@ -5,6 +5,8 @@ import eu.dnetlib.data.proto.FieldTypeProtos;
import eu.dnetlib.data.proto.OafProtos;
import eu.dnetlib.dhp.schema.oaf.*;
import java.util.stream.Collectors;
public class ProtoUtils {
public static OafProtos.Oaf parse(String json) throws JsonFormat.ParseException {
@ -13,6 +15,33 @@ public class ProtoUtils {
return builder.build();
}
public static <T extends Oaf> T setOaf(T oaf, OafProtos.Oaf o) {
oaf.setDataInfo(mapDataInfo(o.getDataInfo())).setLastupdatetimestamp(o.getLastupdatetimestamp());
return oaf;
}
public static <T extends OafEntity> T setEntity(T entity, OafProtos.Oaf oaf) {
//setting Entity fields
final OafProtos.OafEntity e = oaf.getEntity();
entity
.setId(e.getId())
.setOriginalId(e.getOriginalIdList())
.setCollectedfrom(e.getCollectedfromList()
.stream()
.map(ProtoUtils::mapKV)
.collect(Collectors.toList()))
.setPid(e.getPidList().stream()
.map(ProtoUtils::mapStructuredProperty)
.collect(Collectors.toList()))
.setDateofcollection(entity.getDateofcollection())
.setDateoftransformation(entity.getDateoftransformation())
.setExtraInfo(e.getExtraInfoList()
.stream()
.map(ProtoUtils::mapExtraInfo)
.collect(Collectors.toList()));
return entity;
}
public static KeyValue mapKV(FieldTypeProtos.KeyValue kv) {
return new KeyValue()
.setKey(kv.getKey())
@ -54,12 +83,10 @@ public class ProtoUtils {
.setValue(extraInfo.getValue());
}
public static OAIProvenance mapOAIProvenance(FieldTypeProtos.OAIProvenance oaiProvenance) {
return new OAIProvenance().setOriginDescription(mapOriginalDescription(oaiProvenance.getOriginDescription()));
}
public static OriginDescription mapOriginalDescription(FieldTypeProtos.OAIProvenance.OriginDescription originDescription) {
final OriginDescription originDescriptionResult = new OriginDescription()
.setHarvestDate(originDescription.getHarvestDate())
@ -71,7 +98,6 @@ public class ProtoUtils {
if (originDescription.hasOriginDescription())
originDescriptionResult.setOriginDescription(mapOriginalDescription(originDescription.getOriginDescription()));
return originDescriptionResult;
}
public static Field<String> mapStringField(FieldTypeProtos.StringField s) {
@ -92,4 +118,20 @@ public class ProtoUtils {
.setDataInfo(b.hasDataInfo() ? mapDataInfo(b.getDataInfo()) : null);
}
public static Journal mapJournal(FieldTypeProtos.Journal j) {
return new Journal()
.setConferencedate(j.getConferencedate())
.setConferenceplace(j.getConferenceplace())
.setEdition(j.getEdition())
.setEp(j.getEp())
.setIss(j.getIss())
.setIssnLinking(j.getIssnLinking())
.setIssnOnline(j.getIssnOnline())
.setIssnPrinted(j.getIssnPrinted())
.setName(j.getName())
.setSp(j.getSp())
.setVol(j.getVol())
.setDataInfo(mapDataInfo(j.getDataInfo()));
}
}