Search in sources :

Example 6 with CreateAttributeRequest

use of org.molgenis.api.metadata.v3.model.CreateAttributeRequest 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)

Example 7 with CreateAttributeRequest

use of org.molgenis.api.metadata.v3.model.CreateAttributeRequest in project molgenis by molgenis.

the class AttributeRequestMapperImpl method resolveMappedBy.

private void resolveMappedBy(List<CreateAttributeRequest> attributes, Map<String, Attribute> attributeMap, String parentEntityId) {
    for (CreateAttributeRequest attributeRequest : attributes) {
        if (attributeRequest.getMappedByAttribute() != null) {
            Attribute mappedBy;
            if (attributeMap.containsKey(attributeRequest.getMappedByAttribute())) {
                mappedBy = attributeMap.get(attributeRequest.getMappedByAttribute());
            } else {
                mappedBy = getAttributeFromParent(parentEntityId, attributeRequest);
            }
            if (mappedBy != null) {
                Attribute attr = attributeMap.get(attributeRequest.getId());
                attr.setMappedBy(mappedBy);
            }
        }
    }
}
Also used : CreateAttributeRequest(org.molgenis.api.metadata.v3.model.CreateAttributeRequest) Attribute(org.molgenis.data.meta.model.Attribute)

Aggregations

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