partial update

This commit is contained in:
Michele Artini 2020-01-21 12:32:10 +01:00
parent b35c59eb42
commit cd114f1c3b
4 changed files with 60 additions and 45 deletions

View File

@ -19,6 +19,9 @@ import org.apache.commons.logging.LogFactory;
import eu.dnetlib.dhp.application.ArgumentApplicationParser; import eu.dnetlib.dhp.application.ArgumentApplicationParser;
import eu.dnetlib.dhp.schema.oaf.DataInfo; import eu.dnetlib.dhp.schema.oaf.DataInfo;
import eu.dnetlib.dhp.schema.oaf.Datasource; import eu.dnetlib.dhp.schema.oaf.Datasource;
import eu.dnetlib.dhp.schema.oaf.Field;
import eu.dnetlib.dhp.schema.oaf.Journal;
import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.Organization; import eu.dnetlib.dhp.schema.oaf.Organization;
import eu.dnetlib.dhp.schema.oaf.Project; import eu.dnetlib.dhp.schema.oaf.Project;
import eu.dnetlib.dhp.schema.oaf.Qualifier; import eu.dnetlib.dhp.schema.oaf.Qualifier;
@ -84,10 +87,9 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
ds.setCollectedfrom(MigrationUtils.listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname"))); ds.setCollectedfrom(MigrationUtils.listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname")));
ds.setPid(null); // List<StructuredProperty> // TODO ds.setPid(null); // List<StructuredProperty> // TODO
ds.setDateofcollection(rs.getDate("dateofcollection").toString()); ds.setDateofcollection(rs.getDate("dateofcollection").toString());
ds.setDateoftransformation(null); // TODO ds.setDateoftransformation(null); // Value not returned by the SQL query
ds.setExtraInfo(null); // TODO ds.setExtraInfo(null); // TODO
ds.setOaiprovenance(null); // TODO ds.setOaiprovenance(null); // Values not present in the DB
ds.setDatasourcetype(prepareQualifierSplitting(rs.getString("datasourcetype"))); ds.setDatasourcetype(prepareQualifierSplitting(rs.getString("datasourcetype")));
ds.setOpenairecompatibility(prepareQualifierSplitting(rs.getString("openairecompatibility"))); ds.setOpenairecompatibility(prepareQualifierSplitting(rs.getString("openairecompatibility")));
ds.setOfficialname(MigrationUtils.field(rs.getString("officialname"), info)); ds.setOfficialname(MigrationUtils.field(rs.getString("officialname"), info));
@ -104,9 +106,9 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
ds.setOdnumberofitems(MigrationUtils.field(Double.toString(rs.getInt("odnumberofitems")), info)); ds.setOdnumberofitems(MigrationUtils.field(Double.toString(rs.getInt("odnumberofitems")), info));
ds.setOdnumberofitemsdate(MigrationUtils.field(rs.getDate("odnumberofitemsdate").toString(), info)); ds.setOdnumberofitemsdate(MigrationUtils.field(rs.getDate("odnumberofitemsdate").toString(), info));
ds.setOdpolicies(MigrationUtils.field(rs.getString("odpolicies"), info)); ds.setOdpolicies(MigrationUtils.field(rs.getString("odpolicies"), info));
ds.setOdlanguages(MigrationUtils.listFields(info, rs.getArray("odlanguages"))); ds.setOdlanguages(prepareListFields(rs.getArray("odlanguages"), info));
ds.setOdcontenttypes(MigrationUtils.listFields(info, rs.getArray("odcontenttypes"))); ds.setOdcontenttypes(prepareListFields(rs.getArray("odcontenttypes"), info));
ds.setAccessinfopackage(MigrationUtils.listFields(info, rs.getArray("accessinfopackage"))); ds.setAccessinfopackage(prepareListFields(rs.getArray("accessinfopackage"), info));
ds.setReleasestartdate(MigrationUtils.field(rs.getDate("releasestartdate").toString(), info)); ds.setReleasestartdate(MigrationUtils.field(rs.getDate("releasestartdate").toString(), info));
ds.setReleaseenddate(MigrationUtils.field(rs.getDate("releaseenddate").toString(), info)); ds.setReleaseenddate(MigrationUtils.field(rs.getDate("releaseenddate").toString(), info));
ds.setMissionstatementurl(MigrationUtils.field(rs.getString("missionstatementurl"), info)); ds.setMissionstatementurl(MigrationUtils.field(rs.getString("missionstatementurl"), info));
@ -121,14 +123,13 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
ds.setQualitymanagementkind(MigrationUtils.field(rs.getString("qualitymanagementkind"), info)); ds.setQualitymanagementkind(MigrationUtils.field(rs.getString("qualitymanagementkind"), info));
ds.setPidsystems(MigrationUtils.field(rs.getString("pidsystems"), info)); ds.setPidsystems(MigrationUtils.field(rs.getString("pidsystems"), info));
ds.setCertificates(MigrationUtils.field(rs.getString("certificates"), info)); ds.setCertificates(MigrationUtils.field(rs.getString("certificates"), info));
ds.setPolicies(null); // List<KeyValue> // TODO ds.setPolicies(new ArrayList<>()); // The sql query returns an empty array
ds.setJournal(null); // Journal // TODO ds.setJournal(prepareJournal(rs.getString("officialname"), rs.getString("journal"), info)); // Journal
ds.setDataInfo(info); ds.setDataInfo(info);
ds.setLastupdatetimestamp(lastUpdateTimestamp); ds.setLastupdatetimestamp(lastUpdateTimestamp);
// rs.getString("datasourceid"); // rs.getString("datasourceid");
rs.getArray("identities"); // rs.getArray("identities");
// rs.getString("officialname"); // rs.getString("officialname");
// rs.getString("englishname"); // rs.getString("englishname");
// rs.getString("contactemail"); // rs.getString("contactemail");
@ -166,14 +167,14 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
// rs.getString("qualitymanagementkind"); // rs.getString("qualitymanagementkind");
// rs.getString("pidsystems"); // rs.getString("pidsystems");
// rs.getString("certificates"); // rs.getString("certificates");
rs.getArray("policies"); // rs.getArray("policies");
// rs.getString("collectedfromid"); // rs.getString("collectedfromid");
// rs.getString("collectedfromname"); // rs.getString("collectedfromname");
// rs.getString("datasourcetype"); // COMPLEX XXX@@@@.... // rs.getString("datasourcetype"); // COMPLEX
// rs.getString("provenanceaction"); // // rs.getString("provenanceaction"); //
// 'sysimport:crosswalk:entityregistry@@@sysimport:crosswalk:entityregistry@@@dnet:provenance_actions@@@dnet:provenance_actions' // 'sysimport:crosswalk:entityregistry@@@sysimport:crosswalk:entityregistry@@@dnet:provenance_actions@@@dnet:provenance_actions'
// AS provenanceaction, // AS provenanceaction,
rs.getString("journal"); // CONCAT(d.issn, '@@@', d.eissn, '@@@', d.lissn) AS journal // rs.getString("journal"); // CONCAT(d.issn, '@@@', d.eissn, '@@@', d.lissn) AS journal
emitOaf(ds); emitOaf(ds);
} catch (final Exception e) { } catch (final Exception e) {
@ -192,12 +193,10 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
p.setOriginalId(Arrays.asList(rs.getString("projectid"))); p.setOriginalId(Arrays.asList(rs.getString("projectid")));
p.setCollectedfrom(MigrationUtils.listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname"))); p.setCollectedfrom(MigrationUtils.listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname")));
p.setPid(null); // List<StructuredProperty> // TODO p.setPid(null); // List<StructuredProperty> // TODO
p.setDateofcollection(rs.getDate("dateofcollection").toString()); p.setDateofcollection(rs.getDate("dateofcollection").toString());
p.setDateoftransformation(rs.getDate("dateoftransformation").toString()); p.setDateoftransformation(rs.getDate("dateoftransformation").toString());
p.setExtraInfo(null); // List<ExtraInfo> //TODO p.setExtraInfo(null); // List<ExtraInfo> //TODO
p.setOaiprovenance(null); // OAIProvenance /TODO p.setOaiprovenance(null); // Values not present in the DB
p.setWebsiteurl(MigrationUtils.field(rs.getString("websiteurl"), info)); p.setWebsiteurl(MigrationUtils.field(rs.getString("websiteurl"), info));
p.setCode(MigrationUtils.field(rs.getString("code"), info)); p.setCode(MigrationUtils.field(rs.getString("code"), info));
p.setAcronym(MigrationUtils.field(rs.getString("acronym"), info)); p.setAcronym(MigrationUtils.field(rs.getString("acronym"), info));
@ -211,7 +210,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
p.setOamandatepublications(MigrationUtils.field(Boolean.toString(rs.getBoolean("oamandatepublications")), info)); p.setOamandatepublications(MigrationUtils.field(Boolean.toString(rs.getBoolean("oamandatepublications")), info));
p.setEcarticle29_3(MigrationUtils.field(Boolean.toString(rs.getBoolean("ecarticle29_3")), info)); p.setEcarticle29_3(MigrationUtils.field(Boolean.toString(rs.getBoolean("ecarticle29_3")), info));
p.setSubjects(prepareListOfStructProps(rs.getArray("subjects"), info)); p.setSubjects(prepareListOfStructProps(rs.getArray("subjects"), info));
p.setFundingtree(null); // List<Field<String>> //TODO p.setFundingtree(prepareListFields(rs.getArray("fundingtree"), info));
p.setContracttype(prepareQualifierSplitting(rs.getString("contracttype"))); p.setContracttype(prepareQualifierSplitting(rs.getString("contracttype")));
p.setOptional1(MigrationUtils.field(rs.getString("optional1"), info)); p.setOptional1(MigrationUtils.field(rs.getString("optional1"), info));
p.setOptional2(MigrationUtils.field(rs.getString("optional2"), info)); p.setOptional2(MigrationUtils.field(rs.getString("optional2"), info));
@ -224,7 +223,6 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
p.setCurrency(MigrationUtils.field(rs.getString("currency"), info)); p.setCurrency(MigrationUtils.field(rs.getString("currency"), info));
p.setTotalcost(new Float(rs.getDouble("totalcost"))); p.setTotalcost(new Float(rs.getDouble("totalcost")));
p.setFundedamount(new Float(rs.getDouble("fundedamount"))); p.setFundedamount(new Float(rs.getDouble("fundedamount")));
p.setDataInfo(info); p.setDataInfo(info);
p.setLastupdatetimestamp(lastUpdateTimestamp); p.setLastupdatetimestamp(lastUpdateTimestamp);
@ -260,11 +258,11 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
// rs.getDouble("fundedamount"); // rs.getDouble("fundedamount");
// rs.getString("collectedfromid"); // rs.getString("collectedfromid");
// rs.getString("collectedfromname"); // rs.getString("collectedfromname");
rs.getString("contracttype"); // COMPLEX // rs.getString("contracttype"); // COMPLEX
rs.getString("provenanceaction"); // COMPLEX // rs.getString("provenanceaction"); // COMPLEX
rs.getArray("pid"); // rs.getArray("pid");
rs.getArray("subjects"); // rs.getArray("subjects");
rs.getArray("fundingtree"); // rs.getArray("fundingtree");
emitOaf(p); emitOaf(p);
@ -287,10 +285,10 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
o.setDateofcollection(rs.getDate("dateofcollection").toString()); o.setDateofcollection(rs.getDate("dateofcollection").toString());
o.setDateoftransformation(rs.getDate("dateoftransformation").toString()); o.setDateoftransformation(rs.getDate("dateoftransformation").toString());
o.setExtraInfo(null); // List<ExtraInfo> // TODO o.setExtraInfo(null); // List<ExtraInfo> // TODO
o.setOaiprovenance(null); // OAIProvenance // TODO o.setOaiprovenance(null); // Values not present in the DB
o.setLegalshortname(MigrationUtils.field("legalshortname", info)); o.setLegalshortname(MigrationUtils.field("legalshortname", info));
o.setLegalname(MigrationUtils.field("legalname", info)); o.setLegalname(MigrationUtils.field("legalname", info));
o.setAlternativeNames(new ArrayList<>()); o.setAlternativeNames(new ArrayList<>()); // Values not returned by the SQL query
o.setWebsiteurl(MigrationUtils.field("websiteurl", info)); o.setWebsiteurl(MigrationUtils.field("websiteurl", info));
o.setLogourl(MigrationUtils.field("logourl", info)); o.setLogourl(MigrationUtils.field("logourl", info));
o.setEclegalbody(MigrationUtils.field(Boolean.toString(rs.getBoolean("eclegalbody")), info)); o.setEclegalbody(MigrationUtils.field(Boolean.toString(rs.getBoolean("eclegalbody")), info));
@ -305,7 +303,6 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
o.setEcsmevalidated(MigrationUtils.field(Boolean.toString(rs.getBoolean("ecsmevalidated")), info)); o.setEcsmevalidated(MigrationUtils.field(Boolean.toString(rs.getBoolean("ecsmevalidated")), info));
o.setEcnutscode(MigrationUtils.field(Boolean.toString(rs.getBoolean("ecnutscode")), info)); o.setEcnutscode(MigrationUtils.field(Boolean.toString(rs.getBoolean("ecnutscode")), info));
o.setCountry(prepareQualifierSplitting(rs.getString("country"))); o.setCountry(prepareQualifierSplitting(rs.getString("country")));
o.setDataInfo(info); o.setDataInfo(info);
o.setLastupdatetimestamp(lastUpdateTimestamp); o.setLastupdatetimestamp(lastUpdateTimestamp);
@ -333,8 +330,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
// rs.getString("collectedfromid"); // rs.getString("collectedfromid");
// rs.getString("collectedfromname"); // rs.getString("collectedfromname");
// rs.getString("country"); // rs.getString("country");
rs.getString("provenanceaction"); // rs.getString("provenanceaction");
rs.getArray("pid"); // rs.getArray("pid");
emitOaf(o); emitOaf(o);
} catch (final Exception e) { } catch (final Exception e) {
@ -348,6 +345,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
final DataInfo info = prepareDataInfo(rs); final DataInfo info = prepareDataInfo(rs);
final String orgId = MigrationUtils.createOpenaireId("20", rs.getString("organization")); final String orgId = MigrationUtils.createOpenaireId("20", rs.getString("organization"));
final String dsId = MigrationUtils.createOpenaireId("10", rs.getString("datasource")); final String dsId = MigrationUtils.createOpenaireId("10", rs.getString("datasource"));
final List<KeyValue> collectedFrom = MigrationUtils.listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname"));
final Relation r1 = new Relation(); final Relation r1 = new Relation();
r1.setRelType("datasourceOrganization"); r1.setRelType("datasourceOrganization");
@ -355,7 +353,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
r1.setRelClass("isProvidedBy"); r1.setRelClass("isProvidedBy");
r1.setSource(dsId); r1.setSource(dsId);
r1.setTarget(orgId); r1.setTarget(orgId);
r1.setCollectedFrom(null);// TODO r1.setCollectedFrom(collectedFrom);
r1.setDataInfo(info); r1.setDataInfo(info);
r1.setLastupdatetimestamp(lastUpdateTimestamp); r1.setLastupdatetimestamp(lastUpdateTimestamp);
emitOaf(r1); emitOaf(r1);
@ -366,7 +364,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
r2.setRelClass("provides"); r2.setRelClass("provides");
r2.setSource(orgId); r2.setSource(orgId);
r2.setTarget(dsId); r2.setTarget(dsId);
r2.setCollectedFrom(null); // TODO r2.setCollectedFrom(collectedFrom);
r2.setDataInfo(info); r2.setDataInfo(info);
r1.setLastupdatetimestamp(lastUpdateTimestamp); r1.setLastupdatetimestamp(lastUpdateTimestamp);
emitOaf(r2); emitOaf(r2);
@ -395,6 +393,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
final DataInfo info = prepareDataInfo(rs); final DataInfo info = prepareDataInfo(rs);
final String orgId = MigrationUtils.createOpenaireId("20", rs.getString("resporganization")); final String orgId = MigrationUtils.createOpenaireId("20", rs.getString("resporganization"));
final String projectId = MigrationUtils.createOpenaireId("40", rs.getString("project")); final String projectId = MigrationUtils.createOpenaireId("40", rs.getString("project"));
final List<KeyValue> collectedFrom = MigrationUtils.listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname"));
final Relation r1 = new Relation(); final Relation r1 = new Relation();
r1.setRelType("projectOrganization"); r1.setRelType("projectOrganization");
@ -402,7 +401,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
r1.setRelClass("isParticipant"); r1.setRelClass("isParticipant");
r1.setSource(projectId); r1.setSource(projectId);
r1.setTarget(orgId); r1.setTarget(orgId);
r1.setCollectedFrom(null);// TODO r1.setCollectedFrom(collectedFrom);
r1.setDataInfo(info); r1.setDataInfo(info);
r1.setLastupdatetimestamp(lastUpdateTimestamp); r1.setLastupdatetimestamp(lastUpdateTimestamp);
emitOaf(r1); emitOaf(r1);
@ -413,7 +412,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
r2.setRelClass("hasParticipant"); r2.setRelClass("hasParticipant");
r2.setSource(orgId); r2.setSource(orgId);
r2.setTarget(projectId); r2.setTarget(projectId);
r2.setCollectedFrom(null); // TODO r2.setCollectedFrom(collectedFrom);
r2.setDataInfo(info); r2.setDataInfo(info);
r1.setLastupdatetimestamp(lastUpdateTimestamp); r1.setLastupdatetimestamp(lastUpdateTimestamp);
emitOaf(r2); emitOaf(r2);
@ -453,6 +452,14 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
return arr.length == 4 ? MigrationUtils.qualifier(arr[0], arr[1], arr[2], arr[3]) : null; return arr.length == 4 ? MigrationUtils.qualifier(arr[0], arr[1], arr[2], arr[3]) : null;
} }
public static List<Field<String>> prepareListFields(final Array array, final DataInfo info) {
try {
return MigrationUtils.listFields(info, (String[]) array.getArray());
} catch (final SQLException e) {
throw new RuntimeException("Invalid SQL array", e);
}
}
private StructuredProperty prepareStructProp(final String s, final DataInfo dataInfo) { private StructuredProperty prepareStructProp(final String s, final DataInfo dataInfo) {
if (StringUtils.isBlank(s)) { return null; } if (StringUtils.isBlank(s)) { return null; }
final String[] parts = s.split("###"); final String[] parts = s.split("###");
@ -478,6 +485,20 @@ public class MigrateDbEntitiesApplication extends AbstractMigrateApplication imp
return res; return res;
} }
private Journal prepareJournal(final String name, final String sj, final DataInfo info) {
if (StringUtils.isNotBlank(sj)) {
final String[] arr = sj.split("@@@");
if (arr.length == 3) {
final String issn = StringUtils.isNotBlank(arr[0]) ? arr[0] : null;
final String eissn = StringUtils.isNotBlank(arr[1]) ? arr[1] : null;;
final String lissn = StringUtils.isNotBlank(arr[2]) ? arr[2] : null;;
if (issn != null || eissn != null || lissn != null) { return MigrationUtils
.journal(name, issn, eissn, eissn, null, null, null, null, null, null, null, info); }
}
}
return null;
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
super.close(); super.close();

View File

@ -1,7 +1,5 @@
package eu.dnetlib.dhp.migration; package eu.dnetlib.dhp.migration;
import java.sql.Array;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -50,14 +48,6 @@ public class MigrationUtils {
return Arrays.stream(values).map(v -> field(v, info)).collect(Collectors.toList()); return Arrays.stream(values).map(v -> field(v, info)).collect(Collectors.toList());
} }
public static List<Field<String>> listFields(final DataInfo info, final Array array) {
try {
return listFields(info, (String[]) array.getArray());
} catch (final SQLException e) {
throw new RuntimeException("Invalid SQL array", e);
}
}
public static Qualifier qualifier(final String classid, final String classname, final String schemeid, final String schemename) { public static Qualifier qualifier(final String classid, final String classname, final String schemeid, final String schemename) {
final Qualifier q = new Qualifier(); final Qualifier q = new Qualifier();
q.setClassid(classid); q.setClassid(classid);

View File

@ -7,10 +7,11 @@ SELECT
false AS deletedbyinference, false AS deletedbyinference,
0.9 AS trust, 0.9 AS trust,
NULL AS inferenceprovenance, NULL AS inferenceprovenance,
dc.id AS collectedfromid,
dc.officialname AS collectedfromname,
'providedBy@@@provided by@@@dnet:datasources_organizations_typologies@@@dnet:datasources_organizations_typologies' AS semantics, 'providedBy@@@provided by@@@dnet:datasources_organizations_typologies@@@dnet:datasources_organizations_typologies' AS semantics,
d.provenanceaction || '@@@' || d.provenanceaction || '@@@dnet:provenanceActions@@@dnet:provenanceActions' AS provenanceaction d.provenanceaction || '@@@' || d.provenanceaction || '@@@dnet:provenanceActions@@@dnet:provenanceActions' AS provenanceaction
FROM dsm_datasource_organization dor FROM dsm_datasource_organization dor
LEFT OUTER JOIN dsm_datasources d ON (dor.datasource = d.id) LEFT OUTER JOIN dsm_datasources d ON (dor.datasource = d.id)
LEFT OUTER JOIN dsm_datasources dc ON (dc.id = d.collectedfrom)

View File

@ -9,8 +9,11 @@ SELECT
false AS deletedbyinference, false AS deletedbyinference,
po.trust AS trust, po.trust AS trust,
NULL AS inferenceprovenance, NULL AS inferenceprovenance,
dc.id AS collectedfromid,
dc.officialname AS collectedfromname,
po.semanticclass || '@@@' || po.semanticclass || '@@@dnet:project_organization_relations@@@dnet:project_organization_relations' AS semantics, po.semanticclass || '@@@' || po.semanticclass || '@@@dnet:project_organization_relations@@@dnet:project_organization_relations' AS semantics,
'sysimport:crosswalk:entityregistry@@@sysimport:crosswalk:entityregistry@@@dnet:provenance_actions@@@dnet:provenance_actions' AS provenanceaction 'sysimport:crosswalk:entityregistry@@@sysimport:crosswalk:entityregistry@@@dnet:provenance_actions@@@dnet:provenance_actions' AS provenanceaction
FROM project_organization po FROM project_organization po
LEFT OUTER JOIN projects p ON (p.id = po.project)
LEFT OUTER JOIN dsm_datasources dc ON (dc.id = p.collectedfrom)