diff --git a/.github/workflows/.trivyignore b/.github/workflows/.trivyignore index e74d4f0..e69de29 100644 --- a/.github/workflows/.trivyignore +++ b/.github/workflows/.trivyignore @@ -1,4 +0,0 @@ -# Date: Feb 12, 2024 -# Notes: Issue with libexpat, parsing large tokens can trigger a denial of service -# Needs to be fixed in Docker Image. -CVE-2023-52425 \ No newline at end of file diff --git a/pom.xml b/pom.xml index ffea6a6..43a49b9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.3 + 3.2.4 eu.dissco.core diff --git a/src/main/java/eu/dissco/core/translator/ProjectRunner.java b/src/main/java/eu/dissco/core/translator/ProjectRunner.java index 643f999..e06319a 100644 --- a/src/main/java/eu/dissco/core/translator/ProjectRunner.java +++ b/src/main/java/eu/dissco/core/translator/ProjectRunner.java @@ -1,5 +1,6 @@ package eu.dissco.core.translator; +import eu.dissco.core.translator.service.TranslatorJobRecordService; import eu.dissco.core.translator.service.WebClientService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,10 +15,13 @@ public class ProjectRunner implements CommandLineRunner { private final WebClientService webService; private final ConfigurableApplicationContext context; + private final TranslatorJobRecordService tjrService; @Override public void run(String... args) { - webService.retrieveData(); + var jobId = tjrService.createNewJobRecord(); + var processingResult = webService.retrieveData(); + tjrService.updateJobState(jobId, processingResult); context.close(); } } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/DefaultCatalog.java b/src/main/java/eu/dissco/core/translator/database/jooq/DefaultCatalog.java index cc26e9e..27f8100 100644 --- a/src/main/java/eu/dissco/core/translator/database/jooq/DefaultCatalog.java +++ b/src/main/java/eu/dissco/core/translator/database/jooq/DefaultCatalog.java @@ -6,6 +6,7 @@ import java.util.Arrays; import java.util.List; + import org.jooq.Constants; import org.jooq.Schema; import org.jooq.impl.CatalogImpl; @@ -14,37 +15,40 @@ /** * This class is generated by jOOQ. */ -@SuppressWarnings({"all", "unchecked", "rawtypes"}) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class DefaultCatalog extends CatalogImpl { - /** - * The reference instance of DEFAULT_CATALOG - */ - public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog(); - private static final long serialVersionUID = 1L; - /** - * A reference to the 3.18 minor release of the code generator. If this doesn't compile, it's - * because the runtime library uses an older minor release, namely: 3.18. You can turn off the - * generation of this reference by specifying - * /configuration/generator/generate/jooqVersionReference - */ - private static final String REQUIRE_RUNTIME_JOOQ_VERSION = Constants.VERSION_3_18; - /** - * The schema public. - */ - public final Public PUBLIC = Public.PUBLIC; - - /** - * No further instances allowed - */ - private DefaultCatalog() { - super(""); - } - - @Override - public final List getSchemas() { - return Arrays.asList( - Public.PUBLIC - ); - } + private static final long serialVersionUID = 1L; + + /** + * The reference instance of DEFAULT_CATALOG + */ + public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog(); + + /** + * The schema public. + */ + public final Public PUBLIC = Public.PUBLIC; + + /** + * No further instances allowed + */ + private DefaultCatalog() { + super(""); + } + + @Override + public final List getSchemas() { + return Arrays.asList( + Public.PUBLIC + ); + } + + /** + * A reference to the 3.18 minor release of the code generator. If this + * doesn't compile, it's because the runtime library uses an older minor + * release, namely: 3.18. You can turn off the generation of this reference + * by specifying /configuration/generator/generate/jooqVersionReference + */ + private static final String REQUIRE_RUNTIME_JOOQ_VERSION = Constants.VERSION_3_18; } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/Keys.java b/src/main/java/eu/dissco/core/translator/database/jooq/Keys.java index c94a65a..37a2e57 100644 --- a/src/main/java/eu/dissco/core/translator/database/jooq/Keys.java +++ b/src/main/java/eu/dissco/core/translator/database/jooq/Keys.java @@ -6,8 +6,12 @@ import eu.dissco.core.translator.database.jooq.tables.Mapping; import eu.dissco.core.translator.database.jooq.tables.SourceSystem; +import eu.dissco.core.translator.database.jooq.tables.TranslatorJobRecord; import eu.dissco.core.translator.database.jooq.tables.records.MappingRecord; import eu.dissco.core.translator.database.jooq.tables.records.SourceSystemRecord; +import eu.dissco.core.translator.database.jooq.tables.records.TranslatorJobRecordRecord; + +import org.jooq.ForeignKey; import org.jooq.TableField; import org.jooq.UniqueKey; import org.jooq.impl.DSL; @@ -15,19 +19,23 @@ /** - * A class modelling foreign key relationships and constraints of tables in public. + * A class modelling foreign key relationships and constraints of tables in + * public. */ -@SuppressWarnings({"all", "unchecked", "rawtypes"}) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Keys { - // ------------------------------------------------------------------------- - // UNIQUE and PRIMARY KEY definitions - // ------------------------------------------------------------------------- + // ------------------------------------------------------------------------- + // UNIQUE and PRIMARY KEY definitions + // ------------------------------------------------------------------------- + + public static final UniqueKey NEW_MAPPING_PK = Internal.createUniqueKey(Mapping.MAPPING, DSL.name("new_mapping_pk"), new TableField[] { Mapping.MAPPING.ID, Mapping.MAPPING.VERSION }, true); + public static final UniqueKey NEW_SOURCE_SYSTEM_PKEY = Internal.createUniqueKey(SourceSystem.SOURCE_SYSTEM, DSL.name("new_source_system_pkey"), new TableField[] { SourceSystem.SOURCE_SYSTEM.ID }, true); + public static final UniqueKey TRANSLATOR_JOB_RECORD_PKEY = Internal.createUniqueKey(TranslatorJobRecord.TRANSLATOR_JOB_RECORD, DSL.name("translator_job_record_pkey"), new TableField[] { TranslatorJobRecord.TRANSLATOR_JOB_RECORD.JOB_ID, TranslatorJobRecord.TRANSLATOR_JOB_RECORD.SOURCE_SYSTEM_ID }, true); + + // ------------------------------------------------------------------------- + // FOREIGN KEY definitions + // ------------------------------------------------------------------------- - public static final UniqueKey NEW_MAPPING_PK = Internal.createUniqueKey( - Mapping.MAPPING, DSL.name("new_mapping_pk"), - new TableField[]{Mapping.MAPPING.ID, Mapping.MAPPING.VERSION}, true); - public static final UniqueKey NEW_SOURCE_SYSTEM_PKEY = Internal.createUniqueKey( - SourceSystem.SOURCE_SYSTEM, DSL.name("new_source_system_pkey"), - new TableField[]{SourceSystem.SOURCE_SYSTEM.ID}, true); + public static final ForeignKey TRANSLATOR_JOB_RECORD__TRANSLATOR_JOB_RECORD_SOURCE_SYSTEM_ID_FKEY = Internal.createForeignKey(TranslatorJobRecord.TRANSLATOR_JOB_RECORD, DSL.name("translator_job_record_source_system_id_fkey"), new TableField[] { TranslatorJobRecord.TRANSLATOR_JOB_RECORD.SOURCE_SYSTEM_ID }, Keys.NEW_SOURCE_SYSTEM_PKEY, new TableField[] { SourceSystem.SOURCE_SYSTEM.ID }, true); } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/Public.java b/src/main/java/eu/dissco/core/translator/database/jooq/Public.java index 662c659..3afc5fd 100644 --- a/src/main/java/eu/dissco/core/translator/database/jooq/Public.java +++ b/src/main/java/eu/dissco/core/translator/database/jooq/Public.java @@ -6,6 +6,8 @@ import eu.dissco.core.translator.database.jooq.tables.Mapping; import eu.dissco.core.translator.database.jooq.tables.SourceSystem; +import eu.dissco.core.translator.database.jooq.tables.TranslatorJobRecord; + import java.util.Arrays; import java.util.List; @@ -17,42 +19,50 @@ /** * This class is generated by jOOQ. */ -@SuppressWarnings({"all", "unchecked", "rawtypes"}) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Public extends SchemaImpl { - /** - * The reference instance of public - */ - public static final Public PUBLIC = new Public(); - private static final long serialVersionUID = 1L; - /** - * The table public.mapping. - */ - public final Mapping MAPPING = Mapping.MAPPING; - - /** - * The table public.source_system. - */ - public final SourceSystem SOURCE_SYSTEM = SourceSystem.SOURCE_SYSTEM; - - /** - * No further instances allowed - */ - private Public() { - super("public", null); - } - - - @Override - public Catalog getCatalog() { - return DefaultCatalog.DEFAULT_CATALOG; - } - - @Override - public final List> getTables() { - return Arrays.asList( - Mapping.MAPPING, - SourceSystem.SOURCE_SYSTEM - ); - } + private static final long serialVersionUID = 1L; + + /** + * The reference instance of public + */ + public static final Public PUBLIC = new Public(); + + /** + * The table public.mapping. + */ + public final Mapping MAPPING = Mapping.MAPPING; + + /** + * The table public.source_system. + */ + public final SourceSystem SOURCE_SYSTEM = SourceSystem.SOURCE_SYSTEM; + + /** + * The table public.translator_job_record. + */ + public final TranslatorJobRecord TRANSLATOR_JOB_RECORD = TranslatorJobRecord.TRANSLATOR_JOB_RECORD; + + /** + * No further instances allowed + */ + private Public() { + super("public", null); + } + + + @Override + public Catalog getCatalog() { + return DefaultCatalog.DEFAULT_CATALOG; + } + + @Override + public final List> getTables() { + return Arrays.asList( + Mapping.MAPPING, + SourceSystem.SOURCE_SYSTEM, + TranslatorJobRecord.TRANSLATOR_JOB_RECORD + ); + } } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/Tables.java b/src/main/java/eu/dissco/core/translator/database/jooq/Tables.java index 9e8654d..768314b 100644 --- a/src/main/java/eu/dissco/core/translator/database/jooq/Tables.java +++ b/src/main/java/eu/dissco/core/translator/database/jooq/Tables.java @@ -6,21 +6,27 @@ import eu.dissco.core.translator.database.jooq.tables.Mapping; import eu.dissco.core.translator.database.jooq.tables.SourceSystem; +import eu.dissco.core.translator.database.jooq.tables.TranslatorJobRecord; /** * Convenience access to all tables in public. */ -@SuppressWarnings({"all", "unchecked", "rawtypes"}) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Tables { - /** - * The table public.mapping. - */ - public static final Mapping MAPPING = Mapping.MAPPING; + /** + * The table public.mapping. + */ + public static final Mapping MAPPING = Mapping.MAPPING; - /** - * The table public.source_system. - */ - public static final SourceSystem SOURCE_SYSTEM = SourceSystem.SOURCE_SYSTEM; + /** + * The table public.source_system. + */ + public static final SourceSystem SOURCE_SYSTEM = SourceSystem.SOURCE_SYSTEM; + + /** + * The table public.translator_job_record. + */ + public static final TranslatorJobRecord TRANSLATOR_JOB_RECORD = TranslatorJobRecord.TRANSLATOR_JOB_RECORD; } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/enums/ErrorCode.java b/src/main/java/eu/dissco/core/translator/database/jooq/enums/ErrorCode.java new file mode 100644 index 0000000..14ed1fe --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/database/jooq/enums/ErrorCode.java @@ -0,0 +1,56 @@ +/* + * This file is generated by jOOQ. + */ +package eu.dissco.core.translator.database.jooq.enums; + + +import eu.dissco.core.translator.database.jooq.Public; + +import org.jooq.Catalog; +import org.jooq.EnumType; +import org.jooq.Schema; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public enum ErrorCode implements EnumType { + + TIMEOUT("TIMEOUT"), + + DISSCO_EXCEPTION("DISSCO_EXCEPTION"); + + private final String literal; + + private ErrorCode(String literal) { + this.literal = literal; + } + + @Override + public Catalog getCatalog() { + return getSchema().getCatalog(); + } + + @Override + public Schema getSchema() { + return Public.PUBLIC; + } + + @Override + public String getName() { + return "error_code"; + } + + @Override + public String getLiteral() { + return literal; + } + + /** + * Lookup a value of this EnumType by its literal + */ + public static ErrorCode lookupLiteral(String literal) { + return EnumType.lookupLiteral(ErrorCode.class, literal); + } +} diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/enums/JobState.java b/src/main/java/eu/dissco/core/translator/database/jooq/enums/JobState.java new file mode 100644 index 0000000..0199881 --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/database/jooq/enums/JobState.java @@ -0,0 +1,60 @@ +/* + * This file is generated by jOOQ. + */ +package eu.dissco.core.translator.database.jooq.enums; + + +import eu.dissco.core.translator.database.jooq.Public; + +import org.jooq.Catalog; +import org.jooq.EnumType; +import org.jooq.Schema; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public enum JobState implements EnumType { + + SCHEDULED("SCHEDULED"), + + RUNNING("RUNNING"), + + FAILED("FAILED"), + + COMPLETED("COMPLETED"); + + private final String literal; + + private JobState(String literal) { + this.literal = literal; + } + + @Override + public Catalog getCatalog() { + return getSchema().getCatalog(); + } + + @Override + public Schema getSchema() { + return Public.PUBLIC; + } + + @Override + public String getName() { + return "job_state"; + } + + @Override + public String getLiteral() { + return literal; + } + + /** + * Lookup a value of this EnumType by its literal + */ + public static JobState lookupLiteral(String literal) { + return EnumType.lookupLiteral(JobState.class, literal); + } +} diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/tables/Mapping.java b/src/main/java/eu/dissco/core/translator/database/jooq/tables/Mapping.java index eca9599..f42d163 100644 --- a/src/main/java/eu/dissco/core/translator/database/jooq/tables/Mapping.java +++ b/src/main/java/eu/dissco/core/translator/database/jooq/tables/Mapping.java @@ -7,8 +7,10 @@ import eu.dissco.core.translator.database.jooq.Keys; import eu.dissco.core.translator.database.jooq.Public; import eu.dissco.core.translator.database.jooq.tables.records.MappingRecord; + import java.time.Instant; import java.util.function.Function; + import org.jooq.Field; import org.jooq.ForeignKey; import org.jooq.Function9; @@ -31,172 +33,172 @@ /** * This class is generated by jOOQ. */ -@SuppressWarnings({"all", "unchecked", "rawtypes"}) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Mapping extends TableImpl { - /** - * The reference instance of public.mapping - */ - public static final Mapping MAPPING = new Mapping(); - private static final long serialVersionUID = 1L; - /** - * The column public.mapping.id. - */ - public final TableField ID = createField(DSL.name("id"), - SQLDataType.CLOB.nullable(false), this, ""); - /** - * The column public.mapping.version. - */ - public final TableField VERSION = createField(DSL.name("version"), - SQLDataType.INTEGER.nullable(false), this, ""); - /** - * The column public.mapping.name. - */ - public final TableField NAME = createField(DSL.name("name"), - SQLDataType.CLOB.nullable(false), this, ""); - /** - * The column public.mapping.description. - */ - public final TableField DESCRIPTION = createField(DSL.name("description"), - SQLDataType.CLOB, this, ""); - /** - * The column public.mapping.mapping. - */ - public final TableField MAPPING_ = createField(DSL.name("mapping"), - SQLDataType.JSONB.nullable(false), this, ""); - /** - * The column public.mapping.created. - */ - public final TableField CREATED = createField(DSL.name("created"), - SQLDataType.INSTANT.nullable(false), this, ""); - /** - * The column public.mapping.creator. - */ - public final TableField CREATOR = createField(DSL.name("creator"), - SQLDataType.CLOB.nullable(false), this, ""); - /** - * The column public.mapping.deleted. - */ - public final TableField DELETED = createField(DSL.name("deleted"), - SQLDataType.INSTANT, this, ""); - /** - * The column public.mapping.sourcedatastandard. - */ - public final TableField SOURCEDATASTANDARD = createField( - DSL.name("sourcedatastandard"), SQLDataType.VARCHAR.nullable(false), this, ""); - - private Mapping(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private Mapping(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); - } - - /** - * Create an aliased public.mapping table reference - */ - public Mapping(String alias) { - this(DSL.name(alias), MAPPING); - } - - /** - * Create an aliased public.mapping table reference - */ - public Mapping(Name alias) { - this(alias, MAPPING); - } - - /** - * Create a public.mapping table reference - */ - public Mapping() { - this(DSL.name("mapping"), null); - } - - public Mapping(Table child, ForeignKey key) { - super(child, key, MAPPING); - } - - /** - * The class holding records for this type - */ - @Override - public Class getRecordType() { - return MappingRecord.class; - } - - @Override - public Schema getSchema() { - return aliased() ? null : Public.PUBLIC; - } - - @Override - public UniqueKey getPrimaryKey() { - return Keys.NEW_MAPPING_PK; - } - - @Override - public Mapping as(String alias) { - return new Mapping(DSL.name(alias), this); - } - - @Override - public Mapping as(Name alias) { - return new Mapping(alias, this); - } - - @Override - public Mapping as(Table alias) { - return new Mapping(alias.getQualifiedName(), this); - } - - /** - * Rename this table - */ - @Override - public Mapping rename(String name) { - return new Mapping(DSL.name(name), null); - } - - /** - * Rename this table - */ - @Override - public Mapping rename(Name name) { - return new Mapping(name, null); - } - - /** - * Rename this table - */ - @Override - public Mapping rename(Table name) { - return new Mapping(name.getQualifiedName(), null); - } - - // ------------------------------------------------------------------------- - // Row9 type methods - // ------------------------------------------------------------------------- - - @Override - public Row9 fieldsRow() { - return (Row9) super.fieldsRow(); - } - - /** - * Convenience mapping calling {@link SelectField#convertFrom(Function)}. - */ - public SelectField mapping( - Function9 from) { - return convertFrom(Records.mapping(from)); - } - - /** - * Convenience mapping calling {@link SelectField#convertFrom(Class, Function)}. - */ - public SelectField mapping(Class toType, - Function9 from) { - return convertFrom(toType, Records.mapping(from)); - } + private static final long serialVersionUID = 1L; + + /** + * The reference instance of public.mapping + */ + public static final Mapping MAPPING = new Mapping(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return MappingRecord.class; + } + + /** + * The column public.mapping.id. + */ + public final TableField ID = createField(DSL.name("id"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column public.mapping.version. + */ + public final TableField VERSION = createField(DSL.name("version"), SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * The column public.mapping.name. + */ + public final TableField NAME = createField(DSL.name("name"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column public.mapping.description. + */ + public final TableField DESCRIPTION = createField(DSL.name("description"), SQLDataType.CLOB, this, ""); + + /** + * The column public.mapping.mapping. + */ + public final TableField MAPPING_ = createField(DSL.name("mapping"), SQLDataType.JSONB.nullable(false), this, ""); + + /** + * The column public.mapping.created. + */ + public final TableField CREATED = createField(DSL.name("created"), SQLDataType.INSTANT.nullable(false), this, ""); + + /** + * The column public.mapping.creator. + */ + public final TableField CREATOR = createField(DSL.name("creator"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column public.mapping.deleted. + */ + public final TableField DELETED = createField(DSL.name("deleted"), SQLDataType.INSTANT, this, ""); + + /** + * The column public.mapping.sourcedatastandard. + */ + public final TableField SOURCEDATASTANDARD = createField(DSL.name("sourcedatastandard"), SQLDataType.VARCHAR.nullable(false), this, ""); + + private Mapping(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private Mapping(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + } + + /** + * Create an aliased public.mapping table reference + */ + public Mapping(String alias) { + this(DSL.name(alias), MAPPING); + } + + /** + * Create an aliased public.mapping table reference + */ + public Mapping(Name alias) { + this(alias, MAPPING); + } + + /** + * Create a public.mapping table reference + */ + public Mapping() { + this(DSL.name("mapping"), null); + } + + public Mapping(Table child, ForeignKey key) { + super(child, key, MAPPING); + } + + @Override + public Schema getSchema() { + return aliased() ? null : Public.PUBLIC; + } + + @Override + public UniqueKey getPrimaryKey() { + return Keys.NEW_MAPPING_PK; + } + + @Override + public Mapping as(String alias) { + return new Mapping(DSL.name(alias), this); + } + + @Override + public Mapping as(Name alias) { + return new Mapping(alias, this); + } + + @Override + public Mapping as(Table alias) { + return new Mapping(alias.getQualifiedName(), this); + } + + /** + * Rename this table + */ + @Override + public Mapping rename(String name) { + return new Mapping(DSL.name(name), null); + } + + /** + * Rename this table + */ + @Override + public Mapping rename(Name name) { + return new Mapping(name, null); + } + + /** + * Rename this table + */ + @Override + public Mapping rename(Table name) { + return new Mapping(name.getQualifiedName(), null); + } + + // ------------------------------------------------------------------------- + // Row9 type methods + // ------------------------------------------------------------------------- + + @Override + public Row9 fieldsRow() { + return (Row9) super.fieldsRow(); + } + + /** + * Convenience mapping calling {@link SelectField#convertFrom(Function)}. + */ + public SelectField mapping(Function9 from) { + return convertFrom(Records.mapping(from)); + } + + /** + * Convenience mapping calling {@link SelectField#convertFrom(Class, + * Function)}. + */ + public SelectField mapping(Class toType, Function9 from) { + return convertFrom(toType, Records.mapping(from)); + } } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/tables/SourceSystem.java b/src/main/java/eu/dissco/core/translator/database/jooq/tables/SourceSystem.java index d45d64c..a7b497f 100644 --- a/src/main/java/eu/dissco/core/translator/database/jooq/tables/SourceSystem.java +++ b/src/main/java/eu/dissco/core/translator/database/jooq/tables/SourceSystem.java @@ -7,15 +7,17 @@ import eu.dissco.core.translator.database.jooq.Keys; import eu.dissco.core.translator.database.jooq.Public; import eu.dissco.core.translator.database.jooq.tables.records.SourceSystemRecord; + import java.time.Instant; import java.util.function.Function; + import org.jooq.Field; import org.jooq.ForeignKey; -import org.jooq.Function9; +import org.jooq.Function10; import org.jooq.Name; import org.jooq.Record; import org.jooq.Records; -import org.jooq.Row9; +import org.jooq.Row10; import org.jooq.Schema; import org.jooq.SelectField; import org.jooq.Table; @@ -30,175 +32,177 @@ /** * This class is generated by jOOQ. */ -@SuppressWarnings({"all", "unchecked", "rawtypes"}) +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class SourceSystem extends TableImpl { - /** - * The reference instance of public.source_system - */ - public static final SourceSystem SOURCE_SYSTEM = new SourceSystem(); - private static final long serialVersionUID = 1L; - /** - * The column public.source_system.id. - */ - public final TableField ID = createField(DSL.name("id"), - SQLDataType.CLOB.nullable(false), this, ""); - /** - * The column public.source_system.name. - */ - public final TableField NAME = createField(DSL.name("name"), - SQLDataType.CLOB.nullable(false), this, ""); - /** - * The column public.source_system.endpoint. - */ - public final TableField ENDPOINT = createField(DSL.name("endpoint"), - SQLDataType.CLOB.nullable(false), this, ""); - /** - * The column public.source_system.description. - */ - public final TableField DESCRIPTION = createField( - DSL.name("description"), SQLDataType.CLOB, this, ""); - /** - * The column public.source_system.created. - */ - public final TableField CREATED = createField(DSL.name("created"), - SQLDataType.INSTANT.nullable(false), this, ""); - /** - * The column public.source_system.deleted. - */ - public final TableField DELETED = createField(DSL.name("deleted"), - SQLDataType.INSTANT, this, ""); - /** - * The column public.source_system.mapping_id. - */ - public final TableField MAPPING_ID = createField( - DSL.name("mapping_id"), SQLDataType.CLOB.nullable(false), this, ""); - /** - * The column public.source_system.version. - */ - public final TableField VERSION = createField(DSL.name("version"), - SQLDataType.INTEGER.nullable(false) - .defaultValue(DSL.field(DSL.raw("1"), SQLDataType.INTEGER)), this, ""); - /** - * The column public.source_system.creator. - */ - public final TableField CREATOR = createField(DSL.name("creator"), - SQLDataType.CLOB.nullable(false) - .defaultValue(DSL.field(DSL.raw("'0000-0002-5669-2769'::text"), SQLDataType.CLOB)), this, - ""); - - private SourceSystem(Name alias, Table aliased) { - this(alias, aliased, null); - } - - private SourceSystem(Name alias, Table aliased, Field[] parameters) { - super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); - } - - /** - * Create an aliased public.source_system table reference - */ - public SourceSystem(String alias) { - this(DSL.name(alias), SOURCE_SYSTEM); - } - - /** - * Create an aliased public.source_system table reference - */ - public SourceSystem(Name alias) { - this(alias, SOURCE_SYSTEM); - } - - /** - * Create a public.source_system table reference - */ - public SourceSystem() { - this(DSL.name("source_system"), null); - } - - public SourceSystem(Table child, ForeignKey key) { - super(child, key, SOURCE_SYSTEM); - } - - /** - * The class holding records for this type - */ - @Override - public Class getRecordType() { - return SourceSystemRecord.class; - } - - @Override - public Schema getSchema() { - return aliased() ? null : Public.PUBLIC; - } - - @Override - public UniqueKey getPrimaryKey() { - return Keys.NEW_SOURCE_SYSTEM_PKEY; - } - - @Override - public SourceSystem as(String alias) { - return new SourceSystem(DSL.name(alias), this); - } - - @Override - public SourceSystem as(Name alias) { - return new SourceSystem(alias, this); - } - - @Override - public SourceSystem as(Table alias) { - return new SourceSystem(alias.getQualifiedName(), this); - } - - /** - * Rename this table - */ - @Override - public SourceSystem rename(String name) { - return new SourceSystem(DSL.name(name), null); - } - - /** - * Rename this table - */ - @Override - public SourceSystem rename(Name name) { - return new SourceSystem(name, null); - } - - /** - * Rename this table - */ - @Override - public SourceSystem rename(Table name) { - return new SourceSystem(name.getQualifiedName(), null); - } - - // ------------------------------------------------------------------------- - // Row9 type methods - // ------------------------------------------------------------------------- - - @Override - public Row9 fieldsRow() { - return (Row9) super.fieldsRow(); - } - - /** - * Convenience mapping calling {@link SelectField#convertFrom(Function)}. - */ - public SelectField mapping( - Function9 from) { - return convertFrom(Records.mapping(from)); - } - - /** - * Convenience mapping calling {@link SelectField#convertFrom(Class, Function)}. - */ - public SelectField mapping(Class toType, - Function9 from) { - return convertFrom(toType, Records.mapping(from)); - } + private static final long serialVersionUID = 1L; + + /** + * The reference instance of public.source_system + */ + public static final SourceSystem SOURCE_SYSTEM = new SourceSystem(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return SourceSystemRecord.class; + } + + /** + * The column public.source_system.id. + */ + public final TableField ID = createField(DSL.name("id"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column public.source_system.name. + */ + public final TableField NAME = createField(DSL.name("name"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column public.source_system.endpoint. + */ + public final TableField ENDPOINT = createField(DSL.name("endpoint"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column public.source_system.description. + */ + public final TableField DESCRIPTION = createField(DSL.name("description"), SQLDataType.CLOB, this, ""); + + /** + * The column public.source_system.created. + */ + public final TableField CREATED = createField(DSL.name("created"), SQLDataType.INSTANT.nullable(false), this, ""); + + /** + * The column public.source_system.deleted. + */ + public final TableField DELETED = createField(DSL.name("deleted"), SQLDataType.INSTANT, this, ""); + + /** + * The column public.source_system.mapping_id. + */ + public final TableField MAPPING_ID = createField(DSL.name("mapping_id"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column public.source_system.version. + */ + public final TableField VERSION = createField(DSL.name("version"), SQLDataType.INTEGER.nullable(false).defaultValue(DSL.field(DSL.raw("1"), SQLDataType.INTEGER)), this, ""); + + /** + * The column public.source_system.creator. + */ + public final TableField CREATOR = createField(DSL.name("creator"), SQLDataType.CLOB.nullable(false).defaultValue(DSL.field(DSL.raw("'0000-0002-5669-2769'::text"), SQLDataType.CLOB)), this, ""); + + /** + * The column public.source_system.translator_type. + */ + public final TableField TRANSLATOR_TYPE = createField(DSL.name("translator_type"), org.jooq.impl.DefaultDataType.getDefaultDataType("\"public\".\"translator_type\""), this, ""); + + private SourceSystem(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private SourceSystem(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + } + + /** + * Create an aliased public.source_system table reference + */ + public SourceSystem(String alias) { + this(DSL.name(alias), SOURCE_SYSTEM); + } + + /** + * Create an aliased public.source_system table reference + */ + public SourceSystem(Name alias) { + this(alias, SOURCE_SYSTEM); + } + + /** + * Create a public.source_system table reference + */ + public SourceSystem() { + this(DSL.name("source_system"), null); + } + + public SourceSystem(Table child, ForeignKey key) { + super(child, key, SOURCE_SYSTEM); + } + + @Override + public Schema getSchema() { + return aliased() ? null : Public.PUBLIC; + } + + @Override + public UniqueKey getPrimaryKey() { + return Keys.NEW_SOURCE_SYSTEM_PKEY; + } + + @Override + public SourceSystem as(String alias) { + return new SourceSystem(DSL.name(alias), this); + } + + @Override + public SourceSystem as(Name alias) { + return new SourceSystem(alias, this); + } + + @Override + public SourceSystem as(Table alias) { + return new SourceSystem(alias.getQualifiedName(), this); + } + + /** + * Rename this table + */ + @Override + public SourceSystem rename(String name) { + return new SourceSystem(DSL.name(name), null); + } + + /** + * Rename this table + */ + @Override + public SourceSystem rename(Name name) { + return new SourceSystem(name, null); + } + + /** + * Rename this table + */ + @Override + public SourceSystem rename(Table name) { + return new SourceSystem(name.getQualifiedName(), null); + } + + // ------------------------------------------------------------------------- + // Row10 type methods + // ------------------------------------------------------------------------- + + @Override + public Row10 fieldsRow() { + return (Row10) super.fieldsRow(); + } + + /** + * Convenience mapping calling {@link SelectField#convertFrom(Function)}. + */ + public SelectField mapping(Function10 from) { + return convertFrom(Records.mapping(from)); + } + + /** + * Convenience mapping calling {@link SelectField#convertFrom(Class, + * Function)}. + */ + public SelectField mapping(Class toType, Function10 from) { + return convertFrom(toType, Records.mapping(from)); + } } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/tables/TranslatorJobRecord.java b/src/main/java/eu/dissco/core/translator/database/jooq/tables/TranslatorJobRecord.java new file mode 100644 index 0000000..f49c969 --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/database/jooq/tables/TranslatorJobRecord.java @@ -0,0 +1,218 @@ +/* + * This file is generated by jOOQ. + */ +package eu.dissco.core.translator.database.jooq.tables; + + +import eu.dissco.core.translator.database.jooq.Keys; +import eu.dissco.core.translator.database.jooq.Public; +import eu.dissco.core.translator.database.jooq.enums.ErrorCode; +import eu.dissco.core.translator.database.jooq.enums.JobState; +import eu.dissco.core.translator.database.jooq.tables.records.TranslatorJobRecordRecord; + +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.function.Function; + +import org.jooq.Field; +import org.jooq.ForeignKey; +import org.jooq.Function7; +import org.jooq.Name; +import org.jooq.Record; +import org.jooq.Records; +import org.jooq.Row7; +import org.jooq.Schema; +import org.jooq.SelectField; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.TableOptions; +import org.jooq.UniqueKey; +import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; +import org.jooq.impl.TableImpl; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class TranslatorJobRecord extends TableImpl { + + private static final long serialVersionUID = 1L; + + /** + * The reference instance of public.translator_job_record + */ + public static final TranslatorJobRecord TRANSLATOR_JOB_RECORD = new TranslatorJobRecord(); + + /** + * The class holding records for this type + */ + @Override + public Class getRecordType() { + return TranslatorJobRecordRecord.class; + } + + /** + * The column public.translator_job_record.job_id. + */ + public final TableField JOB_ID = createField(DSL.name("job_id"), SQLDataType.UUID.nullable(false), this, ""); + + /** + * The column public.translator_job_record.job_state. + */ + public final TableField JOB_STATE = createField(DSL.name("job_state"), SQLDataType.VARCHAR.nullable(false).asEnumDataType(eu.dissco.core.translator.database.jooq.enums.JobState.class), this, ""); + + /** + * The column public.translator_job_record.source_system_id. + */ + public final TableField SOURCE_SYSTEM_ID = createField(DSL.name("source_system_id"), SQLDataType.CLOB.nullable(false), this, ""); + + /** + * The column public.translator_job_record.time_started. + */ + public final TableField TIME_STARTED = createField(DSL.name("time_started"), SQLDataType.INSTANT.nullable(false), this, ""); + + /** + * The column public.translator_job_record.time_completed. + */ + public final TableField TIME_COMPLETED = createField(DSL.name("time_completed"), SQLDataType.INSTANT, this, ""); + + /** + * The column public.translator_job_record.processed_records. + */ + public final TableField PROCESSED_RECORDS = createField(DSL.name("processed_records"), SQLDataType.INTEGER, this, ""); + + /** + * The column public.translator_job_record.error. + */ + public final TableField ERROR = createField(DSL.name("error"), SQLDataType.VARCHAR.asEnumDataType(eu.dissco.core.translator.database.jooq.enums.ErrorCode.class), this, ""); + + private TranslatorJobRecord(Name alias, Table aliased) { + this(alias, aliased, null); + } + + private TranslatorJobRecord(Name alias, Table aliased, Field[] parameters) { + super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table()); + } + + /** + * Create an aliased public.translator_job_record table + * reference + */ + public TranslatorJobRecord(String alias) { + this(DSL.name(alias), TRANSLATOR_JOB_RECORD); + } + + /** + * Create an aliased public.translator_job_record table + * reference + */ + public TranslatorJobRecord(Name alias) { + this(alias, TRANSLATOR_JOB_RECORD); + } + + /** + * Create a public.translator_job_record table reference + */ + public TranslatorJobRecord() { + this(DSL.name("translator_job_record"), null); + } + + public TranslatorJobRecord(Table child, ForeignKey key) { + super(child, key, TRANSLATOR_JOB_RECORD); + } + + @Override + public Schema getSchema() { + return aliased() ? null : Public.PUBLIC; + } + + @Override + public UniqueKey getPrimaryKey() { + return Keys.TRANSLATOR_JOB_RECORD_PKEY; + } + + @Override + public List> getReferences() { + return Arrays.asList(Keys.TRANSLATOR_JOB_RECORD__TRANSLATOR_JOB_RECORD_SOURCE_SYSTEM_ID_FKEY); + } + + private transient SourceSystem _sourceSystem; + + /** + * Get the implicit join path to the public.source_system + * table. + */ + public SourceSystem sourceSystem() { + if (_sourceSystem == null) + _sourceSystem = new SourceSystem(this, Keys.TRANSLATOR_JOB_RECORD__TRANSLATOR_JOB_RECORD_SOURCE_SYSTEM_ID_FKEY); + + return _sourceSystem; + } + + @Override + public TranslatorJobRecord as(String alias) { + return new TranslatorJobRecord(DSL.name(alias), this); + } + + @Override + public TranslatorJobRecord as(Name alias) { + return new TranslatorJobRecord(alias, this); + } + + @Override + public TranslatorJobRecord as(Table alias) { + return new TranslatorJobRecord(alias.getQualifiedName(), this); + } + + /** + * Rename this table + */ + @Override + public TranslatorJobRecord rename(String name) { + return new TranslatorJobRecord(DSL.name(name), null); + } + + /** + * Rename this table + */ + @Override + public TranslatorJobRecord rename(Name name) { + return new TranslatorJobRecord(name, null); + } + + /** + * Rename this table + */ + @Override + public TranslatorJobRecord rename(Table name) { + return new TranslatorJobRecord(name.getQualifiedName(), null); + } + + // ------------------------------------------------------------------------- + // Row7 type methods + // ------------------------------------------------------------------------- + + @Override + public Row7 fieldsRow() { + return (Row7) super.fieldsRow(); + } + + /** + * Convenience mapping calling {@link SelectField#convertFrom(Function)}. + */ + public SelectField mapping(Function7 from) { + return convertFrom(Records.mapping(from)); + } + + /** + * Convenience mapping calling {@link SelectField#convertFrom(Class, + * Function)}. + */ + public SelectField mapping(Class toType, Function7 from) { + return convertFrom(toType, Records.mapping(from)); + } +} diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/MappingRecord.java b/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/MappingRecord.java index 7ab0435..574b600 100644 --- a/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/MappingRecord.java +++ b/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/MappingRecord.java @@ -5,7 +5,9 @@ import eu.dissco.core.translator.database.jooq.tables.Mapping; + import java.time.Instant; + import org.jooq.Field; import org.jooq.JSONB; import org.jooq.Record2; @@ -17,392 +19,389 @@ /** * This class is generated by jOOQ. */ -@SuppressWarnings({"all", "unchecked", "rawtypes"}) -public class MappingRecord extends UpdatableRecordImpl implements - Record9 { - - private static final long serialVersionUID = 1L; - - /** - * Create a detached MappingRecord - */ - public MappingRecord() { - super(Mapping.MAPPING); - } - - /** - * Create a detached, initialised MappingRecord - */ - public MappingRecord(String id, Integer version, String name, String description, JSONB mapping, - Instant created, String creator, Instant deleted, String sourcedatastandard) { - super(Mapping.MAPPING); - - setId(id); - setVersion(version); - setName(name); - setDescription(description); - setMapping(mapping); - setCreated(created); - setCreator(creator); - setDeleted(deleted); - setSourcedatastandard(sourcedatastandard); - resetChangedOnNotNull(); - } - - /** - * Getter for public.mapping.id. - */ - public String getId() { - return (String) get(0); - } - - /** - * Setter for public.mapping.id. - */ - public void setId(String value) { - set(0, value); - } - - /** - * Getter for public.mapping.version. - */ - public Integer getVersion() { - return (Integer) get(1); - } - - /** - * Setter for public.mapping.version. - */ - public void setVersion(Integer value) { - set(1, value); - } - - /** - * Getter for public.mapping.name. - */ - public String getName() { - return (String) get(2); - } - - /** - * Setter for public.mapping.name. - */ - public void setName(String value) { - set(2, value); - } - - /** - * Getter for public.mapping.description. - */ - public String getDescription() { - return (String) get(3); - } - - /** - * Setter for public.mapping.description. - */ - public void setDescription(String value) { - set(3, value); - } - - /** - * Getter for public.mapping.mapping. - */ - public JSONB getMapping() { - return (JSONB) get(4); - } - - /** - * Setter for public.mapping.mapping. - */ - public void setMapping(JSONB value) { - set(4, value); - } - - /** - * Getter for public.mapping.created. - */ - public Instant getCreated() { - return (Instant) get(5); - } - - /** - * Setter for public.mapping.created. - */ - public void setCreated(Instant value) { - set(5, value); - } - - /** - * Getter for public.mapping.creator. - */ - public String getCreator() { - return (String) get(6); - } - - /** - * Setter for public.mapping.creator. - */ - public void setCreator(String value) { - set(6, value); - } - - /** - * Getter for public.mapping.deleted. - */ - public Instant getDeleted() { - return (Instant) get(7); - } - - /** - * Setter for public.mapping.deleted. - */ - public void setDeleted(Instant value) { - set(7, value); - } - - // ------------------------------------------------------------------------- - // Primary key information - // ------------------------------------------------------------------------- - - /** - * Getter for public.mapping.sourcedatastandard. - */ - public String getSourcedatastandard() { - return (String) get(8); - } - - // ------------------------------------------------------------------------- - // Record9 type implementation - // ------------------------------------------------------------------------- - - /** - * Setter for public.mapping.sourcedatastandard. - */ - public void setSourcedatastandard(String value) { - set(8, value); - } - - @Override - public Record2 key() { - return (Record2) super.key(); - } - - @Override - public Row9 fieldsRow() { - return (Row9) super.fieldsRow(); - } - - @Override - public Row9 valuesRow() { - return (Row9) super.valuesRow(); - } - - @Override - public Field field1() { - return Mapping.MAPPING.ID; - } - - @Override - public Field field2() { - return Mapping.MAPPING.VERSION; - } - - @Override - public Field field3() { - return Mapping.MAPPING.NAME; - } - - @Override - public Field field4() { - return Mapping.MAPPING.DESCRIPTION; - } - - @Override - public Field field5() { - return Mapping.MAPPING.MAPPING_; - } - - @Override - public Field field6() { - return Mapping.MAPPING.CREATED; - } - - @Override - public Field field7() { - return Mapping.MAPPING.CREATOR; - } - - @Override - public Field field8() { - return Mapping.MAPPING.DELETED; - } - - @Override - public Field field9() { - return Mapping.MAPPING.SOURCEDATASTANDARD; - } - - @Override - public String component1() { - return getId(); - } - - @Override - public Integer component2() { - return getVersion(); - } - - @Override - public String component3() { - return getName(); - } - - @Override - public String component4() { - return getDescription(); - } - - @Override - public JSONB component5() { - return getMapping(); - } - - @Override - public Instant component6() { - return getCreated(); - } - - @Override - public String component7() { - return getCreator(); - } - - @Override - public Instant component8() { - return getDeleted(); - } - - @Override - public String component9() { - return getSourcedatastandard(); - } - - @Override - public String value1() { - return getId(); - } - - @Override - public Integer value2() { - return getVersion(); - } - - @Override - public String value3() { - return getName(); - } - - @Override - public String value4() { - return getDescription(); - } - - @Override - public JSONB value5() { - return getMapping(); - } - - @Override - public Instant value6() { - return getCreated(); - } - - @Override - public String value7() { - return getCreator(); - } - - @Override - public Instant value8() { - return getDeleted(); - } - - @Override - public String value9() { - return getSourcedatastandard(); - } - - @Override - public MappingRecord value1(String value) { - setId(value); - return this; - } - - @Override - public MappingRecord value2(Integer value) { - setVersion(value); - return this; - } - - @Override - public MappingRecord value3(String value) { - setName(value); - return this; - } - - @Override - public MappingRecord value4(String value) { - setDescription(value); - return this; - } - - @Override - public MappingRecord value5(JSONB value) { - setMapping(value); - return this; - } - - @Override - public MappingRecord value6(Instant value) { - setCreated(value); - return this; - } - - @Override - public MappingRecord value7(String value) { - setCreator(value); - return this; - } - - @Override - public MappingRecord value8(Instant value) { - setDeleted(value); - return this; - } - - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- - - @Override - public MappingRecord value9(String value) { - setSourcedatastandard(value); - return this; - } - - @Override - public MappingRecord values(String value1, Integer value2, String value3, String value4, - JSONB value5, Instant value6, String value7, Instant value8, String value9) { - value1(value1); - value2(value2); - value3(value3); - value4(value4); - value5(value5); - value6(value6); - value7(value7); - value8(value8); - value9(value9); - return this; - } +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class MappingRecord extends UpdatableRecordImpl implements Record9 { + + private static final long serialVersionUID = 1L; + + /** + * Setter for public.mapping.id. + */ + public void setId(String value) { + set(0, value); + } + + /** + * Getter for public.mapping.id. + */ + public String getId() { + return (String) get(0); + } + + /** + * Setter for public.mapping.version. + */ + public void setVersion(Integer value) { + set(1, value); + } + + /** + * Getter for public.mapping.version. + */ + public Integer getVersion() { + return (Integer) get(1); + } + + /** + * Setter for public.mapping.name. + */ + public void setName(String value) { + set(2, value); + } + + /** + * Getter for public.mapping.name. + */ + public String getName() { + return (String) get(2); + } + + /** + * Setter for public.mapping.description. + */ + public void setDescription(String value) { + set(3, value); + } + + /** + * Getter for public.mapping.description. + */ + public String getDescription() { + return (String) get(3); + } + + /** + * Setter for public.mapping.mapping. + */ + public void setMapping(JSONB value) { + set(4, value); + } + + /** + * Getter for public.mapping.mapping. + */ + public JSONB getMapping() { + return (JSONB) get(4); + } + + /** + * Setter for public.mapping.created. + */ + public void setCreated(Instant value) { + set(5, value); + } + + /** + * Getter for public.mapping.created. + */ + public Instant getCreated() { + return (Instant) get(5); + } + + /** + * Setter for public.mapping.creator. + */ + public void setCreator(String value) { + set(6, value); + } + + /** + * Getter for public.mapping.creator. + */ + public String getCreator() { + return (String) get(6); + } + + /** + * Setter for public.mapping.deleted. + */ + public void setDeleted(Instant value) { + set(7, value); + } + + /** + * Getter for public.mapping.deleted. + */ + public Instant getDeleted() { + return (Instant) get(7); + } + + /** + * Setter for public.mapping.sourcedatastandard. + */ + public void setSourcedatastandard(String value) { + set(8, value); + } + + /** + * Getter for public.mapping.sourcedatastandard. + */ + public String getSourcedatastandard() { + return (String) get(8); + } + + // ------------------------------------------------------------------------- + // Primary key information + // ------------------------------------------------------------------------- + + @Override + public Record2 key() { + return (Record2) super.key(); + } + + // ------------------------------------------------------------------------- + // Record9 type implementation + // ------------------------------------------------------------------------- + + @Override + public Row9 fieldsRow() { + return (Row9) super.fieldsRow(); + } + + @Override + public Row9 valuesRow() { + return (Row9) super.valuesRow(); + } + + @Override + public Field field1() { + return Mapping.MAPPING.ID; + } + + @Override + public Field field2() { + return Mapping.MAPPING.VERSION; + } + + @Override + public Field field3() { + return Mapping.MAPPING.NAME; + } + + @Override + public Field field4() { + return Mapping.MAPPING.DESCRIPTION; + } + + @Override + public Field field5() { + return Mapping.MAPPING.MAPPING_; + } + + @Override + public Field field6() { + return Mapping.MAPPING.CREATED; + } + + @Override + public Field field7() { + return Mapping.MAPPING.CREATOR; + } + + @Override + public Field field8() { + return Mapping.MAPPING.DELETED; + } + + @Override + public Field field9() { + return Mapping.MAPPING.SOURCEDATASTANDARD; + } + + @Override + public String component1() { + return getId(); + } + + @Override + public Integer component2() { + return getVersion(); + } + + @Override + public String component3() { + return getName(); + } + + @Override + public String component4() { + return getDescription(); + } + + @Override + public JSONB component5() { + return getMapping(); + } + + @Override + public Instant component6() { + return getCreated(); + } + + @Override + public String component7() { + return getCreator(); + } + + @Override + public Instant component8() { + return getDeleted(); + } + + @Override + public String component9() { + return getSourcedatastandard(); + } + + @Override + public String value1() { + return getId(); + } + + @Override + public Integer value2() { + return getVersion(); + } + + @Override + public String value3() { + return getName(); + } + + @Override + public String value4() { + return getDescription(); + } + + @Override + public JSONB value5() { + return getMapping(); + } + + @Override + public Instant value6() { + return getCreated(); + } + + @Override + public String value7() { + return getCreator(); + } + + @Override + public Instant value8() { + return getDeleted(); + } + + @Override + public String value9() { + return getSourcedatastandard(); + } + + @Override + public MappingRecord value1(String value) { + setId(value); + return this; + } + + @Override + public MappingRecord value2(Integer value) { + setVersion(value); + return this; + } + + @Override + public MappingRecord value3(String value) { + setName(value); + return this; + } + + @Override + public MappingRecord value4(String value) { + setDescription(value); + return this; + } + + @Override + public MappingRecord value5(JSONB value) { + setMapping(value); + return this; + } + + @Override + public MappingRecord value6(Instant value) { + setCreated(value); + return this; + } + + @Override + public MappingRecord value7(String value) { + setCreator(value); + return this; + } + + @Override + public MappingRecord value8(Instant value) { + setDeleted(value); + return this; + } + + @Override + public MappingRecord value9(String value) { + setSourcedatastandard(value); + return this; + } + + @Override + public MappingRecord values(String value1, Integer value2, String value3, String value4, JSONB value5, Instant value6, String value7, Instant value8, String value9) { + value1(value1); + value2(value2); + value3(value3); + value4(value4); + value5(value5); + value6(value6); + value7(value7); + value8(value8); + value9(value9); + return this; + } + + // ------------------------------------------------------------------------- + // Constructors + // ------------------------------------------------------------------------- + + /** + * Create a detached MappingRecord + */ + public MappingRecord() { + super(Mapping.MAPPING); + } + + /** + * Create a detached, initialised MappingRecord + */ + public MappingRecord(String id, Integer version, String name, String description, JSONB mapping, Instant created, String creator, Instant deleted, String sourcedatastandard) { + super(Mapping.MAPPING); + + setId(id); + setVersion(version); + setName(name); + setDescription(description); + setMapping(mapping); + setCreated(created); + setCreator(creator); + setDeleted(deleted); + setSourcedatastandard(sourcedatastandard); + resetChangedOnNotNull(); + } } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/SourceSystemRecord.java b/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/SourceSystemRecord.java index e8e2816..a6c6bf3 100644 --- a/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/SourceSystemRecord.java +++ b/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/SourceSystemRecord.java @@ -5,403 +5,439 @@ import eu.dissco.core.translator.database.jooq.tables.SourceSystem; + import java.time.Instant; + import org.jooq.Field; import org.jooq.Record1; -import org.jooq.Record9; -import org.jooq.Row9; +import org.jooq.Record10; +import org.jooq.Row10; import org.jooq.impl.UpdatableRecordImpl; /** * This class is generated by jOOQ. */ -@SuppressWarnings({"all", "unchecked", "rawtypes"}) -public class SourceSystemRecord extends UpdatableRecordImpl implements - Record9 { - - private static final long serialVersionUID = 1L; - - /** - * Create a detached SourceSystemRecord - */ - public SourceSystemRecord() { - super(SourceSystem.SOURCE_SYSTEM); - } - - /** - * Create a detached, initialised SourceSystemRecord - */ - public SourceSystemRecord(String id, String name, String endpoint, String description, - Instant created, Instant deleted, String mappingId, Integer version, String creator) { - super(SourceSystem.SOURCE_SYSTEM); - - setId(id); - setName(name); - setEndpoint(endpoint); - setDescription(description); - setCreated(created); - setDeleted(deleted); - setMappingId(mappingId); - setVersion(version); - setCreator(creator); - resetChangedOnNotNull(); - } - - /** - * Getter for public.source_system.id. - */ - public String getId() { - return (String) get(0); - } - - /** - * Setter for public.source_system.id. - */ - public void setId(String value) { - set(0, value); - } - - /** - * Getter for public.source_system.name. - */ - public String getName() { - return (String) get(1); - } - - /** - * Setter for public.source_system.name. - */ - public void setName(String value) { - set(1, value); - } - - /** - * Getter for public.source_system.endpoint. - */ - public String getEndpoint() { - return (String) get(2); - } - - /** - * Setter for public.source_system.endpoint. - */ - public void setEndpoint(String value) { - set(2, value); - } - - /** - * Getter for public.source_system.description. - */ - public String getDescription() { - return (String) get(3); - } - - /** - * Setter for public.source_system.description. - */ - public void setDescription(String value) { - set(3, value); - } - - /** - * Getter for public.source_system.created. - */ - public Instant getCreated() { - return (Instant) get(4); - } - - /** - * Setter for public.source_system.created. - */ - public void setCreated(Instant value) { - set(4, value); - } - - /** - * Getter for public.source_system.deleted. - */ - public Instant getDeleted() { - return (Instant) get(5); - } - - /** - * Setter for public.source_system.deleted. - */ - public void setDeleted(Instant value) { - set(5, value); - } - - /** - * Getter for public.source_system.mapping_id. - */ - public String getMappingId() { - return (String) get(6); - } - - /** - * Setter for public.source_system.mapping_id. - */ - public void setMappingId(String value) { - set(6, value); - } - - /** - * Getter for public.source_system.version. - */ - public Integer getVersion() { - return (Integer) get(7); - } - - /** - * Setter for public.source_system.version. - */ - public void setVersion(Integer value) { - set(7, value); - } - - // ------------------------------------------------------------------------- - // Primary key information - // ------------------------------------------------------------------------- - - /** - * Getter for public.source_system.creator. - */ - public String getCreator() { - return (String) get(8); - } - - // ------------------------------------------------------------------------- - // Record9 type implementation - // ------------------------------------------------------------------------- - - /** - * Setter for public.source_system.creator. - */ - public void setCreator(String value) { - set(8, value); - } - - @Override - public Record1 key() { - return (Record1) super.key(); - } - - @Override - public Row9 fieldsRow() { - return (Row9) super.fieldsRow(); - } - - @Override - public Row9 valuesRow() { - return (Row9) super.valuesRow(); - } - - @Override - public Field field1() { - return SourceSystem.SOURCE_SYSTEM.ID; - } - - @Override - public Field field2() { - return SourceSystem.SOURCE_SYSTEM.NAME; - } - - @Override - public Field field3() { - return SourceSystem.SOURCE_SYSTEM.ENDPOINT; - } - - @Override - public Field field4() { - return SourceSystem.SOURCE_SYSTEM.DESCRIPTION; - } - - @Override - public Field field5() { - return SourceSystem.SOURCE_SYSTEM.CREATED; - } - - @Override - public Field field6() { - return SourceSystem.SOURCE_SYSTEM.DELETED; - } - - @Override - public Field field7() { - return SourceSystem.SOURCE_SYSTEM.MAPPING_ID; - } - - @Override - public Field field8() { - return SourceSystem.SOURCE_SYSTEM.VERSION; - } - - @Override - public Field field9() { - return SourceSystem.SOURCE_SYSTEM.CREATOR; - } - - @Override - public String component1() { - return getId(); - } - - @Override - public String component2() { - return getName(); - } - - @Override - public String component3() { - return getEndpoint(); - } - - @Override - public String component4() { - return getDescription(); - } - - @Override - public Instant component5() { - return getCreated(); - } - - @Override - public Instant component6() { - return getDeleted(); - } - - @Override - public String component7() { - return getMappingId(); - } - - @Override - public Integer component8() { - return getVersion(); - } - - @Override - public String component9() { - return getCreator(); - } - - @Override - public String value1() { - return getId(); - } - - @Override - public String value2() { - return getName(); - } - - @Override - public String value3() { - return getEndpoint(); - } - - @Override - public String value4() { - return getDescription(); - } - - @Override - public Instant value5() { - return getCreated(); - } - - @Override - public Instant value6() { - return getDeleted(); - } - - @Override - public String value7() { - return getMappingId(); - } - - @Override - public Integer value8() { - return getVersion(); - } - - @Override - public String value9() { - return getCreator(); - } - - @Override - public SourceSystemRecord value1(String value) { - setId(value); - return this; - } - - @Override - public SourceSystemRecord value2(String value) { - setName(value); - return this; - } - - @Override - public SourceSystemRecord value3(String value) { - setEndpoint(value); - return this; - } - - @Override - public SourceSystemRecord value4(String value) { - setDescription(value); - return this; - } - - @Override - public SourceSystemRecord value5(Instant value) { - setCreated(value); - return this; - } - - @Override - public SourceSystemRecord value6(Instant value) { - setDeleted(value); - return this; - } - - @Override - public SourceSystemRecord value7(String value) { - setMappingId(value); - return this; - } - - @Override - public SourceSystemRecord value8(Integer value) { - setVersion(value); - return this; - } - - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- - - @Override - public SourceSystemRecord value9(String value) { - setCreator(value); - return this; - } - - @Override - public SourceSystemRecord values(String value1, String value2, String value3, String value4, - Instant value5, Instant value6, String value7, Integer value8, String value9) { - value1(value1); - value2(value2); - value3(value3); - value4(value4); - value5(value5); - value6(value6); - value7(value7); - value8(value8); - value9(value9); - return this; - } +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class SourceSystemRecord extends UpdatableRecordImpl implements Record10 { + + private static final long serialVersionUID = 1L; + + /** + * Setter for public.source_system.id. + */ + public void setId(String value) { + set(0, value); + } + + /** + * Getter for public.source_system.id. + */ + public String getId() { + return (String) get(0); + } + + /** + * Setter for public.source_system.name. + */ + public void setName(String value) { + set(1, value); + } + + /** + * Getter for public.source_system.name. + */ + public String getName() { + return (String) get(1); + } + + /** + * Setter for public.source_system.endpoint. + */ + public void setEndpoint(String value) { + set(2, value); + } + + /** + * Getter for public.source_system.endpoint. + */ + public String getEndpoint() { + return (String) get(2); + } + + /** + * Setter for public.source_system.description. + */ + public void setDescription(String value) { + set(3, value); + } + + /** + * Getter for public.source_system.description. + */ + public String getDescription() { + return (String) get(3); + } + + /** + * Setter for public.source_system.created. + */ + public void setCreated(Instant value) { + set(4, value); + } + + /** + * Getter for public.source_system.created. + */ + public Instant getCreated() { + return (Instant) get(4); + } + + /** + * Setter for public.source_system.deleted. + */ + public void setDeleted(Instant value) { + set(5, value); + } + + /** + * Getter for public.source_system.deleted. + */ + public Instant getDeleted() { + return (Instant) get(5); + } + + /** + * Setter for public.source_system.mapping_id. + */ + public void setMappingId(String value) { + set(6, value); + } + + /** + * Getter for public.source_system.mapping_id. + */ + public String getMappingId() { + return (String) get(6); + } + + /** + * Setter for public.source_system.version. + */ + public void setVersion(Integer value) { + set(7, value); + } + + /** + * Getter for public.source_system.version. + */ + public Integer getVersion() { + return (Integer) get(7); + } + + /** + * Setter for public.source_system.creator. + */ + public void setCreator(String value) { + set(8, value); + } + + /** + * Getter for public.source_system.creator. + */ + public String getCreator() { + return (String) get(8); + } + + /** + * Setter for public.source_system.translator_type. + */ + public void setTranslatorType(Object value) { + set(9, value); + } + + /** + * Getter for public.source_system.translator_type. + */ + public Object getTranslatorType() { + return get(9); + } + + // ------------------------------------------------------------------------- + // Primary key information + // ------------------------------------------------------------------------- + + @Override + public Record1 key() { + return (Record1) super.key(); + } + + // ------------------------------------------------------------------------- + // Record10 type implementation + // ------------------------------------------------------------------------- + + @Override + public Row10 fieldsRow() { + return (Row10) super.fieldsRow(); + } + + @Override + public Row10 valuesRow() { + return (Row10) super.valuesRow(); + } + + @Override + public Field field1() { + return SourceSystem.SOURCE_SYSTEM.ID; + } + + @Override + public Field field2() { + return SourceSystem.SOURCE_SYSTEM.NAME; + } + + @Override + public Field field3() { + return SourceSystem.SOURCE_SYSTEM.ENDPOINT; + } + + @Override + public Field field4() { + return SourceSystem.SOURCE_SYSTEM.DESCRIPTION; + } + + @Override + public Field field5() { + return SourceSystem.SOURCE_SYSTEM.CREATED; + } + + @Override + public Field field6() { + return SourceSystem.SOURCE_SYSTEM.DELETED; + } + + @Override + public Field field7() { + return SourceSystem.SOURCE_SYSTEM.MAPPING_ID; + } + + @Override + public Field field8() { + return SourceSystem.SOURCE_SYSTEM.VERSION; + } + + @Override + public Field field9() { + return SourceSystem.SOURCE_SYSTEM.CREATOR; + } + + @Override + public Field field10() { + return SourceSystem.SOURCE_SYSTEM.TRANSLATOR_TYPE; + } + + @Override + public String component1() { + return getId(); + } + + @Override + public String component2() { + return getName(); + } + + @Override + public String component3() { + return getEndpoint(); + } + + @Override + public String component4() { + return getDescription(); + } + + @Override + public Instant component5() { + return getCreated(); + } + + @Override + public Instant component6() { + return getDeleted(); + } + + @Override + public String component7() { + return getMappingId(); + } + + @Override + public Integer component8() { + return getVersion(); + } + + @Override + public String component9() { + return getCreator(); + } + + @Override + public Object component10() { + return getTranslatorType(); + } + + @Override + public String value1() { + return getId(); + } + + @Override + public String value2() { + return getName(); + } + + @Override + public String value3() { + return getEndpoint(); + } + + @Override + public String value4() { + return getDescription(); + } + + @Override + public Instant value5() { + return getCreated(); + } + + @Override + public Instant value6() { + return getDeleted(); + } + + @Override + public String value7() { + return getMappingId(); + } + + @Override + public Integer value8() { + return getVersion(); + } + + @Override + public String value9() { + return getCreator(); + } + + @Override + public Object value10() { + return getTranslatorType(); + } + + @Override + public SourceSystemRecord value1(String value) { + setId(value); + return this; + } + + @Override + public SourceSystemRecord value2(String value) { + setName(value); + return this; + } + + @Override + public SourceSystemRecord value3(String value) { + setEndpoint(value); + return this; + } + + @Override + public SourceSystemRecord value4(String value) { + setDescription(value); + return this; + } + + @Override + public SourceSystemRecord value5(Instant value) { + setCreated(value); + return this; + } + + @Override + public SourceSystemRecord value6(Instant value) { + setDeleted(value); + return this; + } + + @Override + public SourceSystemRecord value7(String value) { + setMappingId(value); + return this; + } + + @Override + public SourceSystemRecord value8(Integer value) { + setVersion(value); + return this; + } + + @Override + public SourceSystemRecord value9(String value) { + setCreator(value); + return this; + } + + @Override + public SourceSystemRecord value10(Object value) { + setTranslatorType(value); + return this; + } + + @Override + public SourceSystemRecord values(String value1, String value2, String value3, String value4, Instant value5, Instant value6, String value7, Integer value8, String value9, Object value10) { + value1(value1); + value2(value2); + value3(value3); + value4(value4); + value5(value5); + value6(value6); + value7(value7); + value8(value8); + value9(value9); + value10(value10); + return this; + } + + // ------------------------------------------------------------------------- + // Constructors + // ------------------------------------------------------------------------- + + /** + * Create a detached SourceSystemRecord + */ + public SourceSystemRecord() { + super(SourceSystem.SOURCE_SYSTEM); + } + + /** + * Create a detached, initialised SourceSystemRecord + */ + public SourceSystemRecord(String id, String name, String endpoint, String description, Instant created, Instant deleted, String mappingId, Integer version, String creator, Object translatorType) { + super(SourceSystem.SOURCE_SYSTEM); + + setId(id); + setName(name); + setEndpoint(endpoint); + setDescription(description); + setCreated(created); + setDeleted(deleted); + setMappingId(mappingId); + setVersion(version); + setCreator(creator); + setTranslatorType(translatorType); + resetChangedOnNotNull(); + } } diff --git a/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/TranslatorJobRecordRecord.java b/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/TranslatorJobRecordRecord.java new file mode 100644 index 0000000..8f36868 --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/database/jooq/tables/records/TranslatorJobRecordRecord.java @@ -0,0 +1,335 @@ +/* + * This file is generated by jOOQ. + */ +package eu.dissco.core.translator.database.jooq.tables.records; + + +import eu.dissco.core.translator.database.jooq.enums.ErrorCode; +import eu.dissco.core.translator.database.jooq.enums.JobState; +import eu.dissco.core.translator.database.jooq.tables.TranslatorJobRecord; + +import java.time.Instant; +import java.util.UUID; + +import org.jooq.Field; +import org.jooq.Record2; +import org.jooq.Record7; +import org.jooq.Row7; +import org.jooq.impl.UpdatableRecordImpl; + + +/** + * This class is generated by jOOQ. + */ +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class TranslatorJobRecordRecord extends UpdatableRecordImpl implements Record7 { + + private static final long serialVersionUID = 1L; + + /** + * Setter for public.translator_job_record.job_id. + */ + public void setJobId(UUID value) { + set(0, value); + } + + /** + * Getter for public.translator_job_record.job_id. + */ + public UUID getJobId() { + return (UUID) get(0); + } + + /** + * Setter for public.translator_job_record.job_state. + */ + public void setJobState(JobState value) { + set(1, value); + } + + /** + * Getter for public.translator_job_record.job_state. + */ + public JobState getJobState() { + return (JobState) get(1); + } + + /** + * Setter for public.translator_job_record.source_system_id. + */ + public void setSourceSystemId(String value) { + set(2, value); + } + + /** + * Getter for public.translator_job_record.source_system_id. + */ + public String getSourceSystemId() { + return (String) get(2); + } + + /** + * Setter for public.translator_job_record.time_started. + */ + public void setTimeStarted(Instant value) { + set(3, value); + } + + /** + * Getter for public.translator_job_record.time_started. + */ + public Instant getTimeStarted() { + return (Instant) get(3); + } + + /** + * Setter for public.translator_job_record.time_completed. + */ + public void setTimeCompleted(Instant value) { + set(4, value); + } + + /** + * Getter for public.translator_job_record.time_completed. + */ + public Instant getTimeCompleted() { + return (Instant) get(4); + } + + /** + * Setter for public.translator_job_record.processed_records. + */ + public void setProcessedRecords(Integer value) { + set(5, value); + } + + /** + * Getter for public.translator_job_record.processed_records. + */ + public Integer getProcessedRecords() { + return (Integer) get(5); + } + + /** + * Setter for public.translator_job_record.error. + */ + public void setError(ErrorCode value) { + set(6, value); + } + + /** + * Getter for public.translator_job_record.error. + */ + public ErrorCode getError() { + return (ErrorCode) get(6); + } + + // ------------------------------------------------------------------------- + // Primary key information + // ------------------------------------------------------------------------- + + @Override + public Record2 key() { + return (Record2) super.key(); + } + + // ------------------------------------------------------------------------- + // Record7 type implementation + // ------------------------------------------------------------------------- + + @Override + public Row7 fieldsRow() { + return (Row7) super.fieldsRow(); + } + + @Override + public Row7 valuesRow() { + return (Row7) super.valuesRow(); + } + + @Override + public Field field1() { + return TranslatorJobRecord.TRANSLATOR_JOB_RECORD.JOB_ID; + } + + @Override + public Field field2() { + return TranslatorJobRecord.TRANSLATOR_JOB_RECORD.JOB_STATE; + } + + @Override + public Field field3() { + return TranslatorJobRecord.TRANSLATOR_JOB_RECORD.SOURCE_SYSTEM_ID; + } + + @Override + public Field field4() { + return TranslatorJobRecord.TRANSLATOR_JOB_RECORD.TIME_STARTED; + } + + @Override + public Field field5() { + return TranslatorJobRecord.TRANSLATOR_JOB_RECORD.TIME_COMPLETED; + } + + @Override + public Field field6() { + return TranslatorJobRecord.TRANSLATOR_JOB_RECORD.PROCESSED_RECORDS; + } + + @Override + public Field field7() { + return TranslatorJobRecord.TRANSLATOR_JOB_RECORD.ERROR; + } + + @Override + public UUID component1() { + return getJobId(); + } + + @Override + public JobState component2() { + return getJobState(); + } + + @Override + public String component3() { + return getSourceSystemId(); + } + + @Override + public Instant component4() { + return getTimeStarted(); + } + + @Override + public Instant component5() { + return getTimeCompleted(); + } + + @Override + public Integer component6() { + return getProcessedRecords(); + } + + @Override + public ErrorCode component7() { + return getError(); + } + + @Override + public UUID value1() { + return getJobId(); + } + + @Override + public JobState value2() { + return getJobState(); + } + + @Override + public String value3() { + return getSourceSystemId(); + } + + @Override + public Instant value4() { + return getTimeStarted(); + } + + @Override + public Instant value5() { + return getTimeCompleted(); + } + + @Override + public Integer value6() { + return getProcessedRecords(); + } + + @Override + public ErrorCode value7() { + return getError(); + } + + @Override + public TranslatorJobRecordRecord value1(UUID value) { + setJobId(value); + return this; + } + + @Override + public TranslatorJobRecordRecord value2(JobState value) { + setJobState(value); + return this; + } + + @Override + public TranslatorJobRecordRecord value3(String value) { + setSourceSystemId(value); + return this; + } + + @Override + public TranslatorJobRecordRecord value4(Instant value) { + setTimeStarted(value); + return this; + } + + @Override + public TranslatorJobRecordRecord value5(Instant value) { + setTimeCompleted(value); + return this; + } + + @Override + public TranslatorJobRecordRecord value6(Integer value) { + setProcessedRecords(value); + return this; + } + + @Override + public TranslatorJobRecordRecord value7(ErrorCode value) { + setError(value); + return this; + } + + @Override + public TranslatorJobRecordRecord values(UUID value1, JobState value2, String value3, Instant value4, Instant value5, Integer value6, ErrorCode value7) { + value1(value1); + value2(value2); + value3(value3); + value4(value4); + value5(value5); + value6(value6); + value7(value7); + return this; + } + + // ------------------------------------------------------------------------- + // Constructors + // ------------------------------------------------------------------------- + + /** + * Create a detached TranslatorJobRecordRecord + */ + public TranslatorJobRecordRecord() { + super(TranslatorJobRecord.TRANSLATOR_JOB_RECORD); + } + + /** + * Create a detached, initialised TranslatorJobRecordRecord + */ + public TranslatorJobRecordRecord(UUID jobId, JobState jobState, String sourceSystemId, Instant timeStarted, Instant timeCompleted, Integer processedRecords, ErrorCode error) { + super(TranslatorJobRecord.TRANSLATOR_JOB_RECORD); + + setJobId(jobId); + setJobState(jobState); + setSourceSystemId(sourceSystemId); + setTimeStarted(timeStarted); + setTimeCompleted(timeCompleted); + setProcessedRecords(processedRecords); + setError(error); + resetChangedOnNotNull(); + } +} diff --git a/src/main/java/eu/dissco/core/translator/domain/BioCasePartResult.java b/src/main/java/eu/dissco/core/translator/domain/BioCasePartResult.java new file mode 100644 index 0000000..1c1e47c --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/domain/BioCasePartResult.java @@ -0,0 +1,5 @@ +package eu.dissco.core.translator.domain; + +public record BioCasePartResult(boolean finished, boolean exception) { + +} diff --git a/src/main/java/eu/dissco/core/translator/domain/TranslatorJobResult.java b/src/main/java/eu/dissco/core/translator/domain/TranslatorJobResult.java new file mode 100644 index 0000000..e1c15a8 --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/domain/TranslatorJobResult.java @@ -0,0 +1,10 @@ +package eu.dissco.core.translator.domain; + +import eu.dissco.core.translator.database.jooq.enums.JobState; + +public record TranslatorJobResult( + JobState jobState, + int processedRecords +) { + +} diff --git a/src/main/java/eu/dissco/core/translator/repository/TranslatorJobRecordRepository.java b/src/main/java/eu/dissco/core/translator/repository/TranslatorJobRecordRepository.java new file mode 100644 index 0000000..de71dae --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/repository/TranslatorJobRecordRepository.java @@ -0,0 +1,42 @@ +package eu.dissco.core.translator.repository; + +import static eu.dissco.core.translator.database.jooq.Tables.TRANSLATOR_JOB_RECORD; + +import eu.dissco.core.translator.database.jooq.enums.ErrorCode; +import eu.dissco.core.translator.database.jooq.enums.JobState; +import eu.dissco.core.translator.domain.TranslatorJobResult; +import eu.dissco.core.translator.properties.WebClientProperties; +import java.time.Instant; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.jooq.DSLContext; +import org.springframework.stereotype.Repository; + +@Slf4j +@Repository +@AllArgsConstructor +public class TranslatorJobRecordRepository { + + private final DSLContext context; + + public void createNewJobRecord(UUID jobId, String sourceSystemId) { + context.insertInto(TRANSLATOR_JOB_RECORD) + .set(TRANSLATOR_JOB_RECORD.JOB_ID, jobId) + .set(TRANSLATOR_JOB_RECORD.SOURCE_SYSTEM_ID, sourceSystemId) + .set(TRANSLATOR_JOB_RECORD.JOB_STATE, JobState.RUNNING) + .set(TRANSLATOR_JOB_RECORD.TIME_STARTED, Instant.now()) + .execute(); + } + + public void updateJobState(UUID jobId, TranslatorJobResult processingResult, + ErrorCode errorCode) { + context.update(TRANSLATOR_JOB_RECORD) + .set(TRANSLATOR_JOB_RECORD.JOB_STATE, processingResult.jobState()) + .set(TRANSLATOR_JOB_RECORD.TIME_COMPLETED, Instant.now()) + .set(TRANSLATOR_JOB_RECORD.PROCESSED_RECORDS, processingResult.processedRecords()) + .set(TRANSLATOR_JOB_RECORD.ERROR, errorCode) + .where(TRANSLATOR_JOB_RECORD.JOB_ID.eq(jobId)) + .execute(); + } +} diff --git a/src/main/java/eu/dissco/core/translator/service/BioCaseService.java b/src/main/java/eu/dissco/core/translator/service/BioCaseService.java index f9e7885..51f1d53 100644 --- a/src/main/java/eu/dissco/core/translator/service/BioCaseService.java +++ b/src/main/java/eu/dissco/core/translator/service/BioCaseService.java @@ -13,11 +13,14 @@ import efg.MultiMediaObject; import efg.Unit; import eu.dissco.core.translator.Profiles; +import eu.dissco.core.translator.database.jooq.enums.JobState; +import eu.dissco.core.translator.domain.BioCasePartResult; import eu.dissco.core.translator.domain.DigitalMediaObject; import eu.dissco.core.translator.domain.DigitalMediaObjectEvent; import eu.dissco.core.translator.domain.DigitalSpecimenEvent; import eu.dissco.core.translator.domain.DigitalSpecimenWrapper; import eu.dissco.core.translator.domain.Enrichment; +import eu.dissco.core.translator.domain.TranslatorJobResult; import eu.dissco.core.translator.exception.DiSSCoDataException; import eu.dissco.core.translator.exception.DisscoEfgParsingException; import eu.dissco.core.translator.properties.EnrichmentProperties; @@ -39,11 +42,11 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicInteger; import javax.xml.namespace.QName; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; -import javax.xml.stream.events.XMLEvent; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import lombok.RequiredArgsConstructor; @@ -90,32 +93,43 @@ private boolean isAcceptedBasisOfRecord(Unit unit) { } @Override - public void retrieveData() { + public TranslatorJobResult retrieveData() { var uri = repository.getEndpoint(webClientProperties.getSourceSystemId()); var templateProperties = getTemplateProperties(); configuration.setNumberFormat("computer"); var finished = false; + var processedRecords = new AtomicInteger(0); while (!finished) { log.info("Currently at: {} still collecting...", templateProperties.get(START_AT)); StringWriter writer = fillTemplate(templateProperties); try { - finished = webClient.get().uri(uri + writer) + var partResult = webClient.get().uri(uri + writer) .retrieve() - .bodyToMono(String.class).publishOn(Schedulers.boundedElastic()).map(this::mapToABCD) + .bodyToMono(String.class).publishOn(Schedulers.boundedElastic()).map( + (String xml) -> mapToABCD(xml, processedRecords)) .toFuture().get(); + if (partResult.exception()) { + return new TranslatorJobResult(JobState.FAILED, processedRecords.get()); + } + finished = partResult.finished(); if (finished) { log.info("Unable to get records from xml"); } } catch (InterruptedException | ExecutionException e) { log.error("Failed to get response from uri", e); Thread.currentThread().interrupt(); - return; + return new TranslatorJobResult(JobState.FAILED, processedRecords.get()); } updateStartAtParameter(templateProperties); } + if (processedRecords.get() == 0) { + log.info("No records were successfully processed"); + return new TranslatorJobResult(JobState.FAILED, processedRecords.get()); + } + return new TranslatorJobResult(JobState.COMPLETED, processedRecords.get()); } - private boolean mapToABCD(String xml) { + private BioCasePartResult mapToABCD(String xml, AtomicInteger processedRecords) { var recordCount = 0; var recordDropped = 0; try { @@ -130,44 +144,45 @@ private boolean mapToABCD(String xml) { log.info("Received {} records in BioCase request, {} records dropped", recordCount, recordDropped); } - retrieveUnitData(xmlEventReader); + retrieveUnitData(xmlEventReader, processedRecords); } if ((recordCount + recordDropped) % webClientProperties.getItemsPerRequest() != 0) { log.info("Received records {} does not match requested records {}. " + "All records have been processed", (recordCount + recordDropped), webClientProperties.getItemsPerRequest()); - return true; + return new BioCasePartResult(true, false); } else { - return false; + return new BioCasePartResult(false, false); } } catch (XMLStreamException | JAXBException e) { log.error("Error converting response tot XML", e); + return new BioCasePartResult(true, true); } - return false; } - private void retrieveUnitData(XMLEventReader xmlEventReader) + private void retrieveUnitData(XMLEventReader xmlEventReader, AtomicInteger processedRecords) throws XMLStreamException, JAXBException { mapper.setSerializationInclusion(Include.NON_NULL); if (isStartElement(xmlEventReader.peek(), "DataSets")) { - mapABCD206(xmlEventReader); + mapABCD206(xmlEventReader, processedRecords); } } - private void mapABCD206(XMLEventReader xmlEventReader) throws JAXBException { + private void mapABCD206(XMLEventReader xmlEventReader, AtomicInteger processedRecords) + throws JAXBException { var context = JAXBContext.newInstance(DataSets.class); var datasetsMarshaller = context.createUnmarshaller().unmarshal(xmlEventReader, DataSets.class); var datasets = datasetsMarshaller.getValue().getDataSet().get(0); for (var unit : datasets.getUnits().getUnit()) { try { - processUnit(datasets, unit); + processUnit(datasets, unit, processedRecords); } catch (DisscoEfgParsingException | JsonProcessingException e) { log.error("Unit could not be processed due to error", e); } } } - private void processUnit(DataSet dataset, Unit unit) + private void processUnit(DataSet dataset, Unit unit, AtomicInteger processedRecords) throws JsonProcessingException, DisscoEfgParsingException { var unitAttributes = parseToJson(unit); var datasetAttribute = getData(mapper.valueToTree(dataset.getMetadata())); @@ -195,6 +210,7 @@ private void processUnit(DataSet dataset, Unit unit) enrichmentServices(false), digitalSpecimen, digitalMediaObjects)); + processedRecords.incrementAndGet(); } catch (DiSSCoDataException e) { log.error("Encountered data issue with record: {}", unitAttributes, e); } diff --git a/src/main/java/eu/dissco/core/translator/service/DwcaService.java b/src/main/java/eu/dissco/core/translator/service/DwcaService.java index 6f00da6..02b7134 100644 --- a/src/main/java/eu/dissco/core/translator/service/DwcaService.java +++ b/src/main/java/eu/dissco/core/translator/service/DwcaService.java @@ -5,11 +5,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import eu.dissco.core.translator.Profiles; +import eu.dissco.core.translator.database.jooq.enums.JobState; import eu.dissco.core.translator.domain.DigitalMediaObject; import eu.dissco.core.translator.domain.DigitalMediaObjectEvent; import eu.dissco.core.translator.domain.DigitalSpecimenEvent; import eu.dissco.core.translator.domain.DigitalSpecimenWrapper; import eu.dissco.core.translator.domain.Enrichment; +import eu.dissco.core.translator.domain.TranslatorJobResult; import eu.dissco.core.translator.exception.DiSSCoDataException; import eu.dissco.core.translator.exception.DisscoRepositoryException; import eu.dissco.core.translator.exception.OrganisationException; @@ -85,9 +87,10 @@ public class DwcaService extends WebClientService { "ROCK", "MINERAL", "METEORITE", "FOSSILSPECIMEN", "LIVINGSPECIMEN", "MATERIALSAMPLE"); @Override - public void retrieveData() { + public TranslatorJobResult retrieveData() { var endpoint = repository.getEndpoint(webClientProperties.getSourceSystemId()); Archive archive = null; + var processedRecords = new AtomicInteger(0); try { var file = Path.of(dwcaProperties.getDownloadFile()); var buffer = webClient.get().uri(URI.create(endpoint)).retrieve() @@ -96,25 +99,35 @@ public void retrieveData() { .then().toFuture().get(); archive = DwcFiles.fromCompressed(file, Path.of(dwcaProperties.getTempFolder())); var ids = postArchiveToDatabase(archive); - getSpecimenData(ids, archive); + getSpecimenData(ids, archive, processedRecords); } catch (IOException e) { log.error("Failed to open output stream for download file", e); + return new TranslatorJobResult(JobState.FAILED, processedRecords.get()); } catch (ExecutionException e) { log.error("Failed during downloading file with exception", e.getCause()); + return new TranslatorJobResult(JobState.FAILED, processedRecords.get()); } catch (InterruptedException e) { log.error("Failed during downloading file due to interruption", e); Thread.currentThread().interrupt(); + return new TranslatorJobResult(JobState.FAILED, processedRecords.get()); } catch (DisscoRepositoryException e) { log.error("Failed during batch copy into temp tables with exception", e); + return new TranslatorJobResult(JobState.FAILED, processedRecords.get()); } finally { if (archive != null) { log.info("Cleaning up database tables"); removeTempTables(archive); } } + if (processedRecords.get() == 0) { + log.info("No records were successfully processed"); + return new TranslatorJobResult(JobState.FAILED, processedRecords.get()); + } + return new TranslatorJobResult(JobState.COMPLETED, processedRecords.get()); } - public void getSpecimenData(Set ids, Archive archive) throws JsonProcessingException { + public void getSpecimenData(Set ids, Archive archive, AtomicInteger processedRecords) + throws JsonProcessingException { var batches = prepareChunks(ids, 10000); var optionalEmlData = addDatasetMeta(archive.getMetadataLocationFile()); for (var batch : batches) { @@ -123,7 +136,7 @@ public void getSpecimenData(Set ids, Archive archive) throws JsonProcess log.info("Got specimen batch: {}", batch.size()); addExtensionsToSpecimen(archive, batch, specimenData); log.info("Start translation and publishing of batch: {}", specimenData.values().size()); - processDigitalSpecimen(specimenData.values(), optionalEmlData); + processDigitalSpecimen(specimenData.values(), optionalEmlData, processedRecords); } log.info("Finished processing {} specimens", ids.size()); } @@ -149,7 +162,7 @@ private void addExtensionsToSpecimen(Archive archive, List batch, } private void processDigitalSpecimen(Collection fullRecords, - Optional> optionalEmlData) + Optional> optionalEmlData, AtomicInteger processedRecords) throws JsonProcessingException { for (var fullRecord : fullRecords) { if (fullRecord != null) { @@ -160,6 +173,7 @@ private void processDigitalSpecimen(Collection fullRecords, var translatorEvent = new DigitalSpecimenEvent(enrichmentServices(false), digitalObjects.getLeft(), digitalObjects.getRight()); kafkaService.sendMessage(translatorEvent); + processedRecords.incrementAndGet(); } catch (DiSSCoDataException e) { log.error("Encountered data issue with record: {}", fullRecord, e); } diff --git a/src/main/java/eu/dissco/core/translator/service/TranslatorJobRecordService.java b/src/main/java/eu/dissco/core/translator/service/TranslatorJobRecordService.java new file mode 100644 index 0000000..69f86e4 --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/service/TranslatorJobRecordService.java @@ -0,0 +1,40 @@ +package eu.dissco.core.translator.service; + +import eu.dissco.core.translator.database.jooq.enums.ErrorCode; +import eu.dissco.core.translator.database.jooq.enums.JobState; +import eu.dissco.core.translator.domain.TranslatorJobResult; +import eu.dissco.core.translator.properties.WebClientProperties; +import eu.dissco.core.translator.repository.TranslatorJobRecordRepository; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@AllArgsConstructor +public class TranslatorJobRecordService { + + private final TranslatorJobRecordRepository repository; + private final WebClientProperties properties; + + public UUID createNewJobRecord() { + var jobId = UUID.randomUUID(); + repository.createNewJobRecord(jobId, properties.getSourceSystemId()); + log.info("Created new job record with id: {}", jobId); + return jobId; + } + + public void updateJobState(UUID jobId, TranslatorJobResult processingResult) { + var jobState = processingResult.jobState(); + if (jobState == JobState.COMPLETED) { + log.info("Job with id {} finished successfully. Processed {} records", jobId, + processingResult.processedRecords()); + repository.updateJobState(jobId, processingResult, null); + } else if (jobState == JobState.FAILED) { + log.info("Job with id {} failed. Processed {} records", jobId, + processingResult.processedRecords()); + repository.updateJobState(jobId, processingResult, ErrorCode.DISSCO_EXCEPTION); + } + } +} diff --git a/src/main/java/eu/dissco/core/translator/service/WebClientService.java b/src/main/java/eu/dissco/core/translator/service/WebClientService.java index 3b0c2ee..20b99d3 100644 --- a/src/main/java/eu/dissco/core/translator/service/WebClientService.java +++ b/src/main/java/eu/dissco/core/translator/service/WebClientService.java @@ -1,10 +1,11 @@ package eu.dissco.core.translator.service; +import eu.dissco.core.translator.domain.TranslatorJobResult; import javax.xml.stream.events.XMLEvent; public abstract class WebClientService { - public abstract void retrieveData(); + public abstract TranslatorJobResult retrieveData(); protected boolean isStartElement(XMLEvent element, String field) { if (element != null) { diff --git a/src/main/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirector.java b/src/main/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirector.java index ec1db1b..58caabf 100644 --- a/src/main/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirector.java @@ -73,6 +73,10 @@ protected List assembleIdentifications(JsonNode data, boolean d iterateOverElements = false; } } + if (identifications.size() == 1 && identifications.get(0).getDwcIdentificationVerificationStatus() == null){ + //If there is only one identification, and it doesn't have a verification status, set it to true + identifications.get(0).setDwcIdentificationVerificationStatus(Boolean.TRUE); + } return identifications; } diff --git a/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java b/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java index 617af24..c864bf3 100644 --- a/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirector.java @@ -78,6 +78,11 @@ protected List assembleIdentifications(JsonNode data, boolean d } else { mappedIdentifications.add(createIdentification(data, dwc)); } + if (mappedIdentifications.size() == 1 + && mappedIdentifications.get(0).getDwcIdentificationVerificationStatus() == null) { + //If there is only one identification, and it doesn't have a verification status, set it to true + mappedIdentifications.get(0).setDwcIdentificationVerificationStatus(Boolean.TRUE); + } return mappedIdentifications; } } diff --git a/src/main/resources/jooq-configuration.xml b/src/main/resources/jooq-configuration.xml index 4f7fd18..b4f752f 100644 --- a/src/main/resources/jooq-configuration.xml +++ b/src/main/resources/jooq-configuration.xml @@ -13,7 +13,7 @@ org.jooq.meta.postgres.PostgresDatabase public - source_system | mapping + source_system | mapping | job_state | translator_job_record | error_code INSTANT diff --git a/src/test/java/eu/dissco/core/translator/TestUtils.java b/src/test/java/eu/dissco/core/translator/TestUtils.java index 0ae9ec7..a795607 100644 --- a/src/test/java/eu/dissco/core/translator/TestUtils.java +++ b/src/test/java/eu/dissco/core/translator/TestUtils.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Map; +import java.util.UUID; import java.util.stream.Stream; import org.junit.jupiter.params.provider.Arguments; import org.springframework.core.io.ClassPathResource; @@ -19,6 +20,8 @@ public class TestUtils { public static String INSTITUTION_ID = "https://ror.org/02y22ws83"; public static String NORMALISED_PHYSICAL_SPECIMEN_ID = "http://coldb.mnhn.fr/catalognumber/mnhn/ec/ec10867"; + public static UUID JOB_ID = UUID.fromString("4a9be957-b8f6-4467-a98e-d19cbd2fa6ec"); + public static String MOCK_DATE = "29-09-2023"; public static Map DEFAULT_MAPPING = Map.of( "ods:physicalSpecimenIdType", "cetaf", diff --git a/src/test/java/eu/dissco/core/translator/repository/MappingRepositoryIT.java b/src/test/java/eu/dissco/core/translator/repository/MappingRepositoryIT.java index 7e234bf..28f5cec 100644 --- a/src/test/java/eu/dissco/core/translator/repository/MappingRepositoryIT.java +++ b/src/test/java/eu/dissco/core/translator/repository/MappingRepositoryIT.java @@ -27,7 +27,7 @@ void setup() { @AfterEach void cleanup() { - context.truncate(SOURCE_SYSTEM).execute(); + context.truncate(SOURCE_SYSTEM).cascade().execute(); context.truncate(MAPPING).execute(); } diff --git a/src/test/java/eu/dissco/core/translator/repository/SourceSystemRepositoryIT.java b/src/test/java/eu/dissco/core/translator/repository/SourceSystemRepositoryIT.java index 21410be..4d86e55 100644 --- a/src/test/java/eu/dissco/core/translator/repository/SourceSystemRepositoryIT.java +++ b/src/test/java/eu/dissco/core/translator/repository/SourceSystemRepositoryIT.java @@ -21,7 +21,7 @@ void setup() { @AfterEach void cleanup() { - context.truncate(SOURCE_SYSTEM).execute(); + context.truncate(SOURCE_SYSTEM).cascade().execute(); } @Test diff --git a/src/test/java/eu/dissco/core/translator/repository/TranslatorJobRecordRepositoryIT.java b/src/test/java/eu/dissco/core/translator/repository/TranslatorJobRecordRepositoryIT.java new file mode 100644 index 0000000..018e59e --- /dev/null +++ b/src/test/java/eu/dissco/core/translator/repository/TranslatorJobRecordRepositoryIT.java @@ -0,0 +1,108 @@ +package eu.dissco.core.translator.repository; + +import static eu.dissco.core.translator.TestUtils.ENDPOINT; +import static eu.dissco.core.translator.TestUtils.SOURCE_SYSTEM_ID; +import static eu.dissco.core.translator.database.jooq.Tables.SOURCE_SYSTEM; +import static eu.dissco.core.translator.database.jooq.Tables.TRANSLATOR_JOB_RECORD; +import static org.assertj.core.api.Assertions.assertThat; + +import eu.dissco.core.translator.database.jooq.enums.ErrorCode; +import eu.dissco.core.translator.database.jooq.enums.JobState; +import eu.dissco.core.translator.domain.TranslatorJobResult; +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class TranslatorJobRecordRepositoryIT extends BaseRepositoryIT { + + private TranslatorJobRecordRepository repository; + + @BeforeEach + void setup() { + repository = new TranslatorJobRecordRepository(context); + } + + @AfterEach + void destroy() { + context.truncate(TRANSLATOR_JOB_RECORD).execute(); + context.truncate(SOURCE_SYSTEM).cascade().execute(); + } + + @Test + void testCreateNewJob() { + // Given + var jobId = UUID.randomUUID(); + insertSourceSystem(); + + // When + repository.createNewJobRecord(jobId, SOURCE_SYSTEM_ID); + + // Then + var result = context.fetchOne(TRANSLATOR_JOB_RECORD, TRANSLATOR_JOB_RECORD.JOB_ID.eq(jobId)); + assertThat(result).isNotNull(); + assertThat(result.getJobId()).isEqualTo(jobId); + assertThat(result.getSourceSystemId()).isEqualTo(SOURCE_SYSTEM_ID); + assertThat(result.getJobState()).isEqualTo(JobState.RUNNING); + assertThat(result.getTimeStarted()).isNotNull(); + } + + @Test + void testJobSuccessful() { + // Given + var jobId = UUID.randomUUID(); + insertSourceSystem(); + repository.createNewJobRecord(jobId, SOURCE_SYSTEM_ID); + + // When + repository.updateJobState(jobId, new TranslatorJobResult(JobState.COMPLETED, 50000), null); + + // Then + var result = context.fetchOne(TRANSLATOR_JOB_RECORD, TRANSLATOR_JOB_RECORD.JOB_ID.eq(jobId)); + assertThat(result).isNotNull(); + assertThat(result.getJobId()).isEqualTo(jobId); + assertThat(result.getSourceSystemId()).isEqualTo(SOURCE_SYSTEM_ID); + assertThat(result.getJobState()).isEqualTo(JobState.COMPLETED); + assertThat(result.getProcessedRecords()).isEqualTo(50000); + assertThat(result.getTimeCompleted()).isNotNull(); + assertThat(result.getTimeStarted()).isNotNull(); + assertThat(result.getError()).isNull(); + } + + @Test + void testJobFailed() { + // Given + var jobId = UUID.randomUUID(); + insertSourceSystem(); + repository.createNewJobRecord(jobId, SOURCE_SYSTEM_ID); + + // When + repository.updateJobState(jobId, new TranslatorJobResult(JobState.FAILED, 421312), + ErrorCode.DISSCO_EXCEPTION); + + // Then + var result = context.fetchOne(TRANSLATOR_JOB_RECORD, TRANSLATOR_JOB_RECORD.JOB_ID.eq(jobId)); + assertThat(result).isNotNull(); + assertThat(result.getJobId()).isEqualTo(jobId); + assertThat(result.getSourceSystemId()).isEqualTo(SOURCE_SYSTEM_ID); + assertThat(result.getJobState()).isEqualTo(JobState.FAILED); + assertThat(result.getProcessedRecords()).isEqualTo(421312); + assertThat(result.getTimeCompleted()).isNotNull(); + assertThat(result.getTimeStarted()).isNotNull(); + assertThat(result.getError()).isEqualTo(ErrorCode.DISSCO_EXCEPTION); + } + + private void insertSourceSystem() { + context.insertInto(SOURCE_SYSTEM) + .set(SOURCE_SYSTEM.ID, SOURCE_SYSTEM_ID) + .set(SOURCE_SYSTEM.NAME, "Royal Botanic Garden Edinburgh Living Plant Collections") + .set(SOURCE_SYSTEM.ENDPOINT, ENDPOINT) + .set(SOURCE_SYSTEM.DESCRIPTION, + "Source system for the DWCA of the Living Plant Collections") + .set(SOURCE_SYSTEM.CREATED, Instant.parse("2022-09-16T08:25:01.00Z")) + .set(SOURCE_SYSTEM.MAPPING_ID, "20.5000.1025/GW0-POP-XAS") + .execute(); + } + +} diff --git a/src/test/java/eu/dissco/core/translator/service/BioCaseServiceTest.java b/src/test/java/eu/dissco/core/translator/service/BioCaseServiceTest.java index 2e25b9a..9bdd73c 100644 --- a/src/test/java/eu/dissco/core/translator/service/BioCaseServiceTest.java +++ b/src/test/java/eu/dissco/core/translator/service/BioCaseServiceTest.java @@ -14,7 +14,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import eu.dissco.core.translator.database.jooq.enums.JobState; import eu.dissco.core.translator.domain.DigitalSpecimenEvent; +import eu.dissco.core.translator.domain.TranslatorJobResult; import eu.dissco.core.translator.properties.EnrichmentProperties; import eu.dissco.core.translator.properties.FdoProperties; import eu.dissco.core.translator.properties.WebClientProperties; @@ -83,6 +85,7 @@ void setup() throws IOException { @Test void testRetrieveData206() throws Exception { // Given + var expectedResult = new TranslatorJobResult(JobState.COMPLETED, 99); given(properties.getSourceSystemId()).willReturn("ABC-DDD-ASD"); given(repository.getEndpoint(anyString())).willReturn("https://endpoint.com"); given(responseSpec.bodyToMono(any(Class.class))).willReturn( @@ -94,9 +97,10 @@ void testRetrieveData206() throws Exception { .willReturn(givenDigitalSpecimen()); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expectedResult); then(webClient).should(times(2)).get(); then(kafkaService).should(times(99)).sendMessage(any( DigitalSpecimenEvent.class)); @@ -105,6 +109,7 @@ void testRetrieveData206() throws Exception { @Test void testRetrieveDataWithMedia206() throws Exception { // Given + var expectedResult = new TranslatorJobResult(JobState.COMPLETED, 100); given(properties.getSourceSystemId()).willReturn("ABC-DDD-ASD"); given(repository.getEndpoint(anyString())).willReturn("https://endpoint.com"); given(responseSpec.bodyToMono(any(Class.class))).willReturn( @@ -119,9 +124,10 @@ void testRetrieveDataWithMedia206() throws Exception { .willReturn(givenDigitalMediaObjects()); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expectedResult); then(webClient).should(times(1)).get(); then(kafkaService).should(times(100)).sendMessage( any( DigitalSpecimenEvent.class)); @@ -130,6 +136,7 @@ void testRetrieveDataWithMedia206() throws Exception { @Test void testRetrieveDataInvalidMedia() throws Exception { // Given + var expectedResult = new TranslatorJobResult(JobState.COMPLETED, 1); given(properties.getSourceSystemId()).willReturn("ABC-DDD-ASD"); given(repository.getEndpoint(anyString())).willReturn("https://endpoint.com"); given(responseSpec.bodyToMono(any(Class.class))).willReturn( @@ -142,9 +149,10 @@ void testRetrieveDataInvalidMedia() throws Exception { anyString())).willReturn(new DigitalEntity()); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expectedResult); var captor = ArgumentCaptor.forClass(DigitalSpecimenEvent.class); then(webClient).should(times(1)).get(); then(kafkaService).should(times(1)).sendMessage(captor.capture()); @@ -155,6 +163,7 @@ void testRetrieveDataInvalidMedia() throws Exception { @MethodSource("eu.dissco.core.translator.TestUtils#provideInvalidDigitalSpecimen") void testRetrieveDataInvalidSpecimen(DigitalSpecimen digitalSpecimen) throws Exception { // Given + var expectedResult = new TranslatorJobResult(JobState.FAILED, 0); given(properties.getSourceSystemId()).willReturn("ABC-DDD-ASD"); given(repository.getEndpoint(anyString())).willReturn("https://endpoint.com"); given(responseSpec.bodyToMono(any(Class.class))).willReturn( @@ -164,9 +173,10 @@ void testRetrieveDataInvalidSpecimen(DigitalSpecimen digitalSpecimen) throws Exc .willReturn(digitalSpecimen); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expectedResult); then(webClient).should(times(1)).get(); then(kafkaService).shouldHaveNoInteractions(); } diff --git a/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java b/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java index e31c591..43e5d3e 100644 --- a/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java +++ b/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java @@ -17,7 +17,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import eu.dissco.core.translator.TestUtils; +import eu.dissco.core.translator.database.jooq.enums.JobState; import eu.dissco.core.translator.domain.DigitalSpecimenEvent; +import eu.dissco.core.translator.domain.TranslatorJobResult; import eu.dissco.core.translator.exception.DisscoRepositoryException; import eu.dissco.core.translator.properties.DwcaProperties; import eu.dissco.core.translator.properties.EnrichmentProperties; @@ -105,6 +107,7 @@ void setup() { @Test void testRetrieveData() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.COMPLETED, 9); var captor = ArgumentCaptor.forClass(JsonNode.class); givenDWCA("/dwca-rbins.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(9)); @@ -113,9 +116,10 @@ void testRetrieveData() throws Exception { given(fdoProperties.getDigitalSpecimenType()).willReturn("Doi of the digital specimen"); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(2)).createTable(anyString()); then(dwcaRepository).should(times(2)).postRecords(anyString(), anyList()); then(kafkaService).should(times(9)).sendMessage(any( @@ -130,14 +134,16 @@ void testRetrieveData() throws Exception { @Test void testCopyTableFails() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.FAILED, 0); givenDWCA("/dwca-rbins.zip"); doThrow(new DisscoRepositoryException("", new Exception())).when(dwcaRepository) .postRecords(eq("temp_abc_ddd_asd_occurrence"), anyList()); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(2)).deleteTable(any()); then(dwcaRepository).should(times(2)).createTable(any()); then(dwcaRepository).shouldHaveNoMoreInteractions(); @@ -147,6 +153,7 @@ void testCopyTableFails() throws Exception { @Test void testRetrieveDataEmlException() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.COMPLETED, 9); var captor = ArgumentCaptor.forClass(JsonNode.class); givenDWCA("/dwca-rbins-invalid-eml.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(9)); @@ -155,9 +162,10 @@ void testRetrieveDataEmlException() throws Exception { given(fdoProperties.getDigitalSpecimenType()).willReturn("Doi of the digital specimen"); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(2)).createTable(anyString()); then(dwcaRepository).should(times(2)).postRecords(anyString(), anyList()); then(kafkaService).should(times(9)).sendMessage( any( @@ -170,6 +178,7 @@ void testRetrieveDataEmlException() throws Exception { @Test void testRetrieveDataWithLicenseText() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.COMPLETED, 9); var captor = ArgumentCaptor.forClass(JsonNode.class); givenDWCA("/dwca-rbins-license-text.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(9)); @@ -178,9 +187,10 @@ void testRetrieveDataWithLicenseText() throws Exception { given(fdoProperties.getDigitalSpecimenType()).willReturn("Doi of the digital specimen"); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(2)).createTable(anyString()); then(dwcaRepository).should(times(2)).postRecords(anyString(), anyList()); then(kafkaService).should(times(9)).sendMessage(any( @@ -196,15 +206,17 @@ void testRetrieveDataWithLicenseText() throws Exception { @MethodSource("eu.dissco.core.translator.TestUtils#provideInvalidDigitalSpecimen") void testRetrieveDataInvalidSpecimen(DigitalSpecimen digitalSpecimen) throws Exception { // Given + var expected = new TranslatorJobResult(JobState.FAILED, 0); givenDWCA("/dwca-rbins.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(9)); given(digitalSpecimenDirector.assembleDigitalSpecimenTerm(any(JsonNode.class), anyBoolean())) .willReturn(digitalSpecimen); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(2)).createTable(anyString()); then(dwcaRepository).should(times(2)).postRecords(anyString(), anyList()); then(kafkaService).shouldHaveNoInteractions(); @@ -227,6 +239,7 @@ private Map givenSpecimenMap(int amount) { @Test void testRetrieveDataWithGbifMedia() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.COMPLETED, 19); givenDWCA("/dwca-kew-gbif-media.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(19)); given(dwcaRepository.getRecords(anyList(), eq("temp_abc_ddd_asd_identification"))).willReturn( @@ -241,9 +254,10 @@ void testRetrieveDataWithGbifMedia() throws Exception { given(fdoProperties.getDigitalSpecimenType()).willReturn("Doi of the digital specimen"); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(3)).createTable(anyString()); then(dwcaRepository).should(times(2)).postRecords(anyString(), anyList()); then(kafkaService).should(times(19)).sendMessage(any( @@ -265,6 +279,7 @@ private Map> givenImageMap(int amount) { @Test void testRetrieveDataWithAcMedia() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.COMPLETED, 14); givenDWCA("/dwca-naturalis-ac-media.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(14)); given(dwcaRepository.getRecords(anyList(), @@ -277,9 +292,10 @@ void testRetrieveDataWithAcMedia() throws Exception { given(fdoProperties.getDigitalSpecimenType()).willReturn("Doi of the digital specimen"); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(2)).createTable(anyString()); then(dwcaRepository).should(times(2)).postRecords(anyString(), anyList()); then(kafkaService).should(times(14)).sendMessage(any( @@ -290,6 +306,7 @@ void testRetrieveDataWithAcMedia() throws Exception { @Test void testRetrieveDataWithInvalidAcMedia() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.COMPLETED, 1); givenDWCA("/dwca-invalid-ac-media.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(1)); given(dwcaRepository.getRecords(anyList(), @@ -301,9 +318,10 @@ void testRetrieveDataWithInvalidAcMedia() throws Exception { given(fdoProperties.getDigitalSpecimenType()).willReturn("Doi of the digital specimen"); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); var captor = ArgumentCaptor.forClass(DigitalSpecimenEvent.class); then(dwcaRepository).should(times(2)).createTable(anyString()); then(dwcaRepository).should(times(2)).postRecords(anyString(), anyList()); @@ -315,12 +333,14 @@ void testRetrieveDataWithInvalidAcMedia() throws Exception { @Test void testRetrieveOnlyOccurrence() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.FAILED, 0); givenDWCA("/dwca-only-occurrences.zip"); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(2)).createTable(anyString()); then(dwcaRepository).should(times(0)).postRecords(anyString(), anyList()); then(kafkaService).shouldHaveNoInteractions(); @@ -330,6 +350,7 @@ void testRetrieveOnlyOccurrence() throws Exception { @Test void testRetrieveDataWithAssociatedMedia() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.COMPLETED, 20); givenDWCA("/dwca-lux-associated-media.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn( givenSpecimenMapWithMedia(20)); @@ -341,9 +362,10 @@ void testRetrieveDataWithAssociatedMedia() throws Exception { given(fdoProperties.getDigitalSpecimenType()).willReturn("Doi of the digital specimen"); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(1)).createTable(anyString()); then(dwcaRepository).should(times(1)).postRecords(anyString(), anyList()); then(kafkaService).should(times(20)).sendMessage(any( @@ -385,15 +407,17 @@ private void givenDWCA(String file) { @Test void testRetrieveDataNull() throws Exception { // Given + var expected = new TranslatorJobResult(JobState.FAILED, 0); givenDWCA("/dwca-lux-associated-media.zip"); var nullMap = new HashMap(); nullMap.put("id", null); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(nullMap); // When - service.retrieveData(); + var result = service.retrieveData(); // Then + assertThat(result).isEqualTo(expected); then(dwcaRepository).should(times(1)).createTable(anyString()); then(dwcaRepository).should(times(1)).postRecords(anyString(), anyList()); then(kafkaService).shouldHaveNoInteractions(); diff --git a/src/test/java/eu/dissco/core/translator/service/TranslatorJobRecordServiceTest.java b/src/test/java/eu/dissco/core/translator/service/TranslatorJobRecordServiceTest.java new file mode 100644 index 0000000..6229962 --- /dev/null +++ b/src/test/java/eu/dissco/core/translator/service/TranslatorJobRecordServiceTest.java @@ -0,0 +1,71 @@ +package eu.dissco.core.translator.service; + +import static eu.dissco.core.translator.TestUtils.SOURCE_SYSTEM_ID; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; + +import eu.dissco.core.translator.TestUtils; +import eu.dissco.core.translator.database.jooq.enums.ErrorCode; +import eu.dissco.core.translator.database.jooq.enums.JobState; +import eu.dissco.core.translator.domain.TranslatorJobResult; +import eu.dissco.core.translator.properties.WebClientProperties; +import eu.dissco.core.translator.repository.TranslatorJobRecordRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class TranslatorJobRecordServiceTest { + + @Mock + private TranslatorJobRecordRepository repository; + @Mock + private WebClientProperties properties; + + private TranslatorJobRecordService service; + + @BeforeEach + void setup() { + service = new TranslatorJobRecordService(repository, properties); + } + + @Test + void testCreateNewJobRecord() { + // Given + given(properties.getSourceSystemId()).willReturn(SOURCE_SYSTEM_ID); + + // When + var jobId = service.createNewJobRecord(); + + // Then + assertThat(jobId).isNotNull(); + then(repository).should().createNewJobRecord(jobId, SOURCE_SYSTEM_ID); + } + + @Test + void testUpdateSuccessfulJob() { + // Given + var result = new TranslatorJobResult(JobState.COMPLETED, 50000); + + // When + service.updateJobState(TestUtils.JOB_ID, result); + + // Then + then(repository).should().updateJobState(TestUtils.JOB_ID, result, null); + } + + @Test + void testUpdateFailedJob() { + // Given + var result = new TranslatorJobResult(JobState.FAILED, 50000); + + // When + service.updateJobState(TestUtils.JOB_ID, result); + + // Then + then(repository).should().updateJobState(TestUtils.JOB_ID, result, ErrorCode.DISSCO_EXCEPTION); + } +} diff --git a/src/test/resources/db/migration/V1__init_db.sql b/src/test/resources/db/migration/V1__init_db.sql index a08079c..9513732 100644 --- a/src/test/resources/db/migration/V1__init_db.sql +++ b/src/test/resources/db/migration/V1__init_db.sql @@ -1,23 +1,42 @@ -CREATE TABLE public.mapping ( - id text NOT NULL, - "version" int4 NOT NULL, - "name" text NOT NULL, - description text NULL, - "mapping" jsonb NOT NULL, - created timestamptz NOT NULL, - creator text NOT NULL, - deleted timestamptz NULL, - CONSTRAINT new_mapping_pk PRIMARY KEY (id, version) +CREATE TABLE public.mapping +( + id text NOT NULL, + "version" int4 NOT NULL, + "name" text NOT NULL, + description text NULL, + "mapping" jsonb NOT NULL, + created timestamptz NOT NULL, + creator text NOT NULL, + deleted timestamptz NULL, + CONSTRAINT new_mapping_pk PRIMARY KEY (id, version) ); -CREATE TABLE public.source_system ( - id text NOT NULL, - "name" text NOT NULL, - endpoint text NOT NULL, - description text NULL, - created timestamptz NOT NULL, - deleted timestamptz NULL, - mapping_id text NOT NULL, - CONSTRAINT new_source_system_endpoint_key UNIQUE (endpoint), - CONSTRAINT new_source_system_pkey PRIMARY KEY (id) +CREATE TABLE public.source_system +( + id text NOT NULL, + "name" text NOT NULL, + endpoint text NOT NULL, + description text NULL, + created timestamptz NOT NULL, + deleted timestamptz NULL, + mapping_id text NOT NULL, + CONSTRAINT new_source_system_endpoint_key UNIQUE (endpoint), + CONSTRAINT new_source_system_pkey PRIMARY KEY (id) +); + +create type error_code as enum ('TIMEOUT', 'DISSCO_EXCEPTION'); + +create type job_state as enum ('SCHEDULED', 'RUNNING', 'FAILED', 'COMPLETED'); + +create table translator_job_record +( + job_id uuid not null, + job_state job_state not null, + source_system_id text not null, + time_started timestamp with time zone not null, + time_completed timestamp with time zone, + processed_records int, + error error_code, + PRIMARY KEY (job_id, source_system_id), + FOREIGN KEY (source_system_id) REFERENCES source_system (id) ); \ No newline at end of file