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));
}
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));
}
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));
}
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;
}
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);
}
}
};
}
Aggregations