use of org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest in project molgenis by molgenis.
the class AttributeRequestMapperImpl method toAttributes.
@Override
public List<Attribute> toAttributes(List<CreateAttributeRequest> attributes, CreateEntityTypeRequest entityTypeRequest, EntityType entityType) {
Map<String, Attribute> mappedAttributes = Maps.newHashMapWithExpectedSize(attributes.size());
AtomicInteger index = new AtomicInteger(0);
for (CreateAttributeRequest attribute : attributes) {
Attribute mappedAttribute = toAttribute(attribute, entityType, index.getAndIncrement());
mappedAttributes.put(mappedAttribute.getIdentifier(), mappedAttribute);
}
resolveMappedBy(attributes, mappedAttributes, entityTypeRequest.getExtends());
return new ArrayList<>(mappedAttributes.values());
}
use of org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest in project molgenis by molgenis.
the class EntityTypeRequestMapperImplTest method toEntityType.
@Test
void toEntityType() {
String id = "MyEntityTypeId";
I18nValue label = I18nValue.builder().setDefaultValue("My Entity Type").build();
String packageId = "MyPackageId";
String extendsEntityTypeId = "MyExtendsEntityTypeId";
ImmutableList<CreateAttributeRequest> attributes = ImmutableList.of();
CreateEntityTypeRequest createEntityTypeRequest = CreateEntityTypeRequest.builder().setId(id).setLabel(label).setDescription(null).setAbstract(false).setPackage(packageId).setExtends(extendsEntityTypeId).setAttributes(attributes).build();
Package aPackage = mock(Package.class);
when(metaDataService.getPackage(packageId)).thenReturn(Optional.of(aPackage));
EntityType extendsEntityType = mock(EntityType.class);
when(metaDataService.getEntityType(extendsEntityTypeId)).thenReturn(Optional.of(extendsEntityType));
EntityType entityType = mock(EntityType.class);
RepositoryCollection repositoryCollection = mock(RepositoryCollection.class);
when(repositoryCollection.getName()).thenReturn("PostgreSQL");
when(metaDataService.getDefaultBackend()).thenReturn(repositoryCollection);
when(entityTypeFactory.create()).thenReturn(entityType);
EntityType mappedEntityType = entityTypeRequestMapper.toEntityType(createEntityTypeRequest);
assertAll(() -> verify(mappedEntityType).setId("MyEntityTypeId"), () -> verify(mappedEntityType).setLabel("My Entity Type"), () -> verify(mappedEntityType).setBackend("PostgreSQL"), () -> verify(mappedEntityType).setPackage(aPackage), () -> verify(mappedEntityType).setExtends(extendsEntityType), () -> verify(mappedEntityType).setOwnAllAttributes(emptyList()), () -> verify(mappedEntityType).setAbstract(false), () -> verifyNoMoreInteractions(mappedEntityType));
}
use of org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest in project molgenis by molgenis.
the class MetadataApiControllerTest method testCreateEntityType.
@Test
void testCreateEntityType() throws URISyntaxException {
CreateEntityTypeRequest createEntityTypeRequest = mock(CreateEntityTypeRequest.class);
String entityTypeId = "MyEntityTypeId";
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
when(entityTypeRequestMapper.toEntityType(createEntityTypeRequest)).thenReturn(entityType);
ResponseEntity<?> responseEntity = ResponseEntity.created(new URI("http://localhost/api/metadata/" + entityTypeId)).build();
assertEquals(responseEntity, metadataApiController.createEntityType(createEntityTypeRequest));
verify(metadataApiService).createEntityType(entityType);
}
use of org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest in project molgenis by molgenis.
the class MetadataApiControllerTest method testUpdateEntityType.
@Test
void testUpdateEntityType() throws URISyntaxException {
String entityTypeId = "MyEntityTypeId";
CreateEntityTypeRequest createEntityTypeRequest = mock(CreateEntityTypeRequest.class);
EntityType entityType = when(mock(EntityType.class).getId()).thenReturn(entityTypeId).getMock();
when(entityTypeRequestMapper.toEntityType(createEntityTypeRequest)).thenReturn(entityType);
MetadataUpsertJobExecution metadataUpsertJobExecution = mock(MetadataUpsertJobExecution.class);
when(metadataUpsertJobExecution.getEntityType()).thenReturn(entityType);
when(metadataApiService.updateEntityTypeAsync(entityType)).thenReturn(metadataUpsertJobExecution);
ResponseEntity<?> responseEntity = ResponseEntity.accepted().location(new URI("http://localhost/api/data/MyEntityTypeId")).build();
assertEquals(responseEntity, metadataApiController.updateEntityType(entityTypeId, createEntityTypeRequest));
}
use of org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest in project molgenis by molgenis.
the class AttributeRequestMapperTest method toAttributes.
@Test
void toAttributes() {
Attribute attribute = mock(Attribute.class);
when(attributeFactory.create()).thenReturn(attribute);
CreateAttributeRequest createAttributeRequest = CreateAttributeRequest.builder().setId("MyAttributeId").setName("MyAttributeName").setType("long").setRange(Range.create(-1L, 1L)).build();
CreateEntityTypeRequest entityTypeRequest = CreateEntityTypeRequest.builder().setLabel(I18nValue.builder().setDefaultValue("My Entity Type").build()).setPackage("MyPackageId").setAttributes(ImmutableList.of(createAttributeRequest)).build();
EntityType entityType = mock(EntityType.class);
List<Attribute> attributes = attributeRequestMapper.toAttributes(singletonList(createAttributeRequest), entityTypeRequest, entityType);
assertAll(() -> assertEquals(1, attributes.size()), () -> verify(attribute).setIdAttribute(null), () -> verify(attribute).setLabelAttribute(null), () -> verify(attribute).setLookupAttributeIndex(null), () -> verify(attribute).setIdentifier("MyAttributeId"), () -> verify(attribute).setName("MyAttributeName"), () -> verify(attribute).setEntity(entityType), () -> verify(attribute).setSequenceNumber(0), () -> verify(attribute).setDataType(AttributeType.LONG), () -> verify(attribute).setOrderBy(null), () -> verify(attribute).setExpression(null), () -> verify(attribute).setRange(new org.molgenis.data.Range(-1L, 1L)), () -> verify(attribute).setNullableExpression(null), () -> verify(attribute).setVisibleExpression(null), () -> verify(attribute).setValidationExpression(null), () -> verify(attribute).setDefaultValue(null), () -> verify(attribute).getIdentifier(), () -> verifyNoMoreInteractions(attribute));
}
Aggregations