Search in sources :

Example 1 with JobFactory

use of org.molgenis.jobs.JobFactory 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 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