Search in sources :

Example 1 with CreateEntityTypeRequest

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());
}
Also used : CreateAttributeRequest(org.molgenis.api.metadata.v3.model.CreateAttributeRequest) Attribute(org.molgenis.data.meta.model.Attribute) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList)

Example 2 with CreateEntityTypeRequest

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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) RepositoryCollection(org.molgenis.data.RepositoryCollection) CreateAttributeRequest(org.molgenis.api.metadata.v3.model.CreateAttributeRequest) CreateEntityTypeRequest(org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest) I18nValue(org.molgenis.api.metadata.v3.model.I18nValue) Package(org.molgenis.data.meta.model.Package) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 3 with CreateEntityTypeRequest

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) CreateEntityTypeRequest(org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 4 with CreateEntityTypeRequest

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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) MetadataUpsertJobExecution(org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution) CreateEntityTypeRequest(org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 5 with 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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) CreateAttributeRequest(org.molgenis.api.metadata.v3.model.CreateAttributeRequest) CreateEntityTypeRequest(org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest) Attribute(org.molgenis.data.meta.model.Attribute) Range(org.molgenis.api.metadata.v3.model.Range) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

Test (org.junit.jupiter.api.Test)4 CreateEntityTypeRequest (org.molgenis.api.metadata.v3.model.CreateEntityTypeRequest)4 EntityType (org.molgenis.data.meta.model.EntityType)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)4 CreateAttributeRequest (org.molgenis.api.metadata.v3.model.CreateAttributeRequest)3 URI (java.net.URI)2 Attribute (org.molgenis.data.meta.model.Attribute)2 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MetadataUpsertJobExecution (org.molgenis.api.metadata.v3.job.MetadataUpsertJobExecution)1 I18nValue (org.molgenis.api.metadata.v3.model.I18nValue)1 Range (org.molgenis.api.metadata.v3.model.Range)1 RepositoryCollection (org.molgenis.data.RepositoryCollection)1 Package (org.molgenis.data.meta.model.Package)1