Search in sources :

Example 1 with MetadataUpsertJobExecution

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

the class MetadataApiControllerTest method testUpdateAttribute.

@Test
void testUpdateAttribute() throws URISyntaxException {
    String entityTypeId = "MyEntityTypeId";
    String attibuteId = "myAttributeId";
    CreateAttributeRequest createAttributeRequest = CreateAttributeRequest.builder().setId(attibuteId).setName("updatedMyAttribute").build();
    EntityType entityType = mock(EntityType.class);
    Attribute currentAttribute = when(mock(Attribute.class).getIdentifier()).thenReturn(attibuteId).getMock();
    when(entityType.getOwnAllAttributes()).thenReturn(singletonList(currentAttribute));
    when(entityType.getOwnAttributeById(attibuteId)).thenReturn(currentAttribute);
    when(metadataApiService.findEntityType(entityTypeId)).thenReturn(entityType);
    Attribute newAttribute = when(mock(Attribute.class).getIdentifier()).thenReturn(attibuteId).getMock();
    when(attributeRequestMapper.toAttribute(createAttributeRequest, entityType)).thenReturn(newAttribute);
    EntityType jobEntityType = mock(EntityType.class);
    when(jobEntityType.getId()).thenReturn("MyJobEntityTypeId");
    MetadataUpsertJobExecution metadataUpsertJobExecution = mock(MetadataUpsertJobExecution.class);
    when(metadataUpsertJobExecution.getEntityType()).thenReturn(jobEntityType);
    when(metadataUpsertJobExecution.getIdentifier()).thenReturn("MyJobEntityId");
    when(metadataApiService.updateEntityTypeAsync(entityType)).thenReturn(metadataUpsertJobExecution);
    ResponseEntity<?> responseEntity = ResponseEntity.accepted().location(new URI("http://localhost/api/data/MyJobEntityTypeId/MyJobEntityId")).build();
    assertEquals(responseEntity, metadataApiController.updateAttribute(entityTypeId, attibuteId, createAttributeRequest));
    verify(entityType).setOwnAllAttributes(singletonList(newAttribute));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution) CreateAttributeRequest(org.molgenis.api.metadata.v3.model.CreateAttributeRequest) Attribute(org.molgenis.data.meta.model.Attribute) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 2 with MetadataUpsertJobExecution

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

the class MetadataApiControllerTest method testUpdatePartialAttribute.

@Test
void testUpdatePartialAttribute() throws URISyntaxException {
    String entityTypeId = "MyEntityTypeId";
    String attibuteId = "myAttributeId";
    Map<String, Object> attributeValues = singletonMap("unique", true);
    EntityType entityType = mock(EntityType.class);
    Attribute currentAttribute = mock(Attribute.class);
    when(entityType.getOwnAttributeById(attibuteId)).thenReturn(currentAttribute);
    when(metadataApiService.findEntityType(entityTypeId)).thenReturn(entityType);
    EntityType jobEntityType = mock(EntityType.class);
    when(jobEntityType.getId()).thenReturn("MyJobEntityTypeId");
    MetadataUpsertJobExecution metadataUpsertJobExecution = mock(MetadataUpsertJobExecution.class);
    when(metadataUpsertJobExecution.getEntityType()).thenReturn(jobEntityType);
    when(metadataUpsertJobExecution.getIdentifier()).thenReturn("MyJobEntityId");
    when(metadataApiService.updateEntityTypeAsync(entityType)).thenReturn(metadataUpsertJobExecution);
    ResponseEntity<?> responseEntity = ResponseEntity.accepted().location(new URI("http://localhost/api/data/MyJobEntityTypeId/MyJobEntityId")).build();
    assertEquals(responseEntity, metadataApiController.updatePartialAttribute(entityTypeId, attibuteId, attributeValues));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution) Attribute(org.molgenis.data.meta.model.Attribute) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 3 with MetadataUpsertJobExecution

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

the class MetadataApiJobServiceImplTest method testScheduleCreate.

@Test
void testScheduleCreate() {
    EntityType entityType = mock(EntityType.class);
    MetadataUpsertJobExecution jobExecution = mock(MetadataUpsertJobExecution.class);
    when(metadataUpsertJobExecutionFactory.create()).thenReturn(jobExecution);
    when(entityTypeSerializer.serializeEntityType(entityType)).thenReturn("entity data");
    MetadataUpsertJobExecution actualJobExecution = metadataApiJobService.scheduleCreate(entityType);
    assertAll(() -> assertEquals(jobExecution, actualJobExecution), () -> verify(jobExecution).setEntityTypeData("entity data"), () -> verify(jobExecutor).submit(jobExecution));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 4 with MetadataUpsertJobExecution

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution 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 5 with MetadataUpsertJobExecution

use of org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution 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

MetadataUpsertJobExecution (org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution)11 Test (org.junit.jupiter.api.Test)9 EntityType (org.molgenis.data.meta.model.EntityType)9 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)9 URI (java.net.URI)4 Attribute (org.molgenis.data.meta.model.Attribute)3 CreateAttributeRequest (org.molgenis.api.metadata.v3.model.CreateAttributeRequest)2 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Action (org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecutionMetadata.Action)1 CreateEntityTypeRequest (org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest)1 DeleteAttributesRequest (org.molgenis.api.metadata.v3.model.DeleteAttributesRequest)1 Query (org.molgenis.api.model.Query)1 MetaDataService (org.molgenis.data.meta.MetaDataService)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