Search in sources :

Example 1 with Action

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecutionMetadata.Action in project molgenis by molgenis.

the class MetadataApiJobServiceImpl method scheduleUpsert.

private MetadataUpsertJobExecution scheduleUpsert(Action action, EntityType entityType) {
    MetadataUpsertJobExecution jobExecution = metadataUpsertJobExecutionFactory.create();
    jobExecution.setAction(action);
    jobExecution.setEntityTypeData(entityTypeSerializer.serializeEntityType(entityType));
    jobExecutor.submit(jobExecution);
    return jobExecution;
}
Also used : MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution)

Example 2 with Action

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecutionMetadata.Action in project molgenis by molgenis.

the class MetadataUpsertConfig method metadataUpsertJobExecutionJobFactory.

@Bean
public JobFactory<MetadataUpsertJobExecution> metadataUpsertJobExecutionJobFactory() {
    return new JobFactory<>() {

        @Override
        public Job createJob(MetadataUpsertJobExecution metadataUpsertJobExecution) {
            String entityTypeData = metadataUpsertJobExecution.getEntityTypeData();
            EntityType entityType = entityTypeSerializer.deserializeEntityType(entityTypeData);
            Action action = metadataUpsertJobExecution.getAction();
            switch(action) {
                case CREATE:
                    throw new UnsupportedOperationException();
                case UPDATE:
                    return progress -> updateEntityType(entityType);
                default:
                    throw new UnexpectedEnumException(action);
            }
        }
    };
}
Also used : JobFactory(org.molgenis.jobs.JobFactory) EntityType(org.molgenis.data.meta.model.EntityType) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) Configuration(org.springframework.context.annotation.Configuration) Action(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecutionMetadata.Action) Job(org.molgenis.jobs.Job) JobFactory(org.molgenis.jobs.JobFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) Bean(org.springframework.context.annotation.Bean) EntityType(org.molgenis.data.meta.model.EntityType) MetaDataService(org.molgenis.data.meta.MetaDataService) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) Action(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecutionMetadata.Action) Bean(org.springframework.context.annotation.Bean)

Aggregations

Objects.requireNonNull (java.util.Objects.requireNonNull)1 MetadataUpsertJobExecution (org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution)1 Action (org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecutionMetadata.Action)1 MetaDataService (org.molgenis.data.meta.MetaDataService)1 EntityType (org.molgenis.data.meta.model.EntityType)1 Job (org.molgenis.jobs.Job)1 JobFactory (org.molgenis.jobs.JobFactory)1 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1