Search in sources :

Example 71 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class SystemEntityTypeRegistryImplTest method testGetSystemAttributeCompound.

@Test
public void testGetSystemAttributeCompound() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    Attribute attr = when(mock(Attribute.class).getIdentifier()).thenReturn("attr").getMock();
    when(attr.getDataType()).thenReturn(AttributeType.STRING);
    Attribute compoundAttr = when(mock(Attribute.class).getIdentifier()).thenReturn("compoundAttr").getMock();
    when(compoundAttr.getDataType()).thenReturn(AttributeType.COMPOUND);
    when(compoundAttr.getChildren()).thenReturn(singletonList(attr));
    when(systemEntityType.getAllAttributes()).thenReturn(singletonList(compoundAttr));
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(true);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    assertEquals(systemEntityTypeRegistry.getSystemAttribute("attr"), attr);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 72 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class SystemEntityTypeRegistryImplTest method testGetSystemAttributeCompoundNotExists.

@Test
public void testGetSystemAttributeCompoundNotExists() {
    String entityTypeId = "entityType";
    SystemEntityType systemEntityType = mock(SystemEntityType.class);
    when(systemEntityType.getId()).thenReturn(entityTypeId);
    Attribute attr = when(mock(Attribute.class).getIdentifier()).thenReturn("attr").getMock();
    when(attr.getDataType()).thenReturn(AttributeType.STRING);
    Attribute compoundAttr = when(mock(Attribute.class).getIdentifier()).thenReturn("compoundAttr").getMock();
    when(compoundAttr.getDataType()).thenReturn(AttributeType.COMPOUND);
    when(compoundAttr.getChildren()).thenReturn(singletonList(attr));
    when(systemEntityType.getAllAttributes()).thenReturn(singletonList(compoundAttr));
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.COUNT)).thenReturn(true);
    systemEntityTypeRegistry.addSystemEntityType(systemEntityType);
    assertNull(systemEntityTypeRegistry.getSystemAttribute("unknownAttr"));
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) SystemEntityType(org.molgenis.data.meta.SystemEntityType) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 73 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class RestService method convertMref.

private List<?> convertMref(Attribute attr, Object paramValue) {
    List<?> value;
    if (paramValue != null) {
        List<?> mrefParamValues;
        if (paramValue instanceof String) {
            mrefParamValues = asList(StringUtils.split((String) paramValue, ','));
        } else if (paramValue instanceof List<?>) {
            mrefParamValues = (List<?>) paramValue;
        } else {
            throw new MolgenisDataException(format("Attribute [%s] value is of type [%s] instead of [%s] or [%s]", attr.getName(), paramValue.getClass().getSimpleName(), String.class.getSimpleName(), List.class.getSimpleName()));
        }
        EntityType mrefEntity = attr.getRefEntity();
        Attribute mrefEntityIdAttr = mrefEntity.getIdAttribute();
        value = mrefParamValues.stream().map(mrefParamValue -> toEntityValue(mrefEntityIdAttr, mrefParamValue, null)).map(mrefIdValue -> entityManager.getReference(mrefEntity, mrefIdValue)).collect(toList());
    } else {
        value = emptyList();
    }
    return value;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) IdGenerator(org.molgenis.data.populate.IdGenerator) ONE_TO_MANY(org.molgenis.data.meta.AttributeType.ONE_TO_MANY) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.molgenis.data.meta.model.Attribute) FileStore(org.molgenis.data.file.FileStore) FileDownloadController(org.molgenis.core.ui.file.FileDownloadController) FileMetaFactory(org.molgenis.data.file.model.FileMetaFactory) Service(org.springframework.stereotype.Service) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) POPULATE(org.molgenis.data.EntityManager.CreationMode.POPULATE) AttributeType(org.molgenis.data.meta.AttributeType) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) MolgenisDateFormat(org.molgenis.data.util.MolgenisDateFormat) EntityType(org.molgenis.data.meta.model.EntityType) FILENAME(org.molgenis.data.file.model.FileMetaMetaData.FILENAME) String.format(java.lang.String.format) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) FileMeta(org.molgenis.data.file.model.FileMeta) FILE_META(org.molgenis.data.file.model.FileMetaMetaData.FILE_META) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) StreamSupport.stream(java.util.stream.StreamSupport.stream) LocalDate(java.time.LocalDate) DataService(org.molgenis.data.DataService) MultipartFile(org.springframework.web.multipart.MultipartFile) MolgenisDataException(org.molgenis.data.MolgenisDataException) EntityManager(org.molgenis.data.EntityManager) Entity(org.molgenis.data.Entity) UriComponents(org.springframework.web.util.UriComponents) MolgenisDataException(org.molgenis.data.MolgenisDataException) Attribute(org.molgenis.data.meta.model.Attribute) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 74 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmGeneratorServiceImplTest method testConvertUnitsAlgorithm.

@Test
public void testConvertUnitsAlgorithm() {
    EntityType targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
    targetAttribute.setLabel("height in m");
    targetAttribute.setDataType(DECIMAL);
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceEntityType = entityTypeFactory.create("source");
    Attribute sourceAttribute = attrMetaFactory.create().setName("sourceHeight");
    sourceAttribute.setDataType(DECIMAL);
    sourceAttribute.setLabel("body length in cm");
    sourceEntityType.addAttribute(sourceAttribute);
    String actualAlgorithm = algorithmGeneratorService.generate(targetAttribute, Lists.newArrayList(sourceAttribute), targetEntityType, sourceEntityType);
    String expectedAlgorithm = "$('sourceHeight').unit('cm').toUnit('m').value();";
    assertEquals(actualAlgorithm, expectedAlgorithm);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) ExplainedQueryString(org.molgenis.semanticsearch.explain.bean.ExplainedQueryString) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 75 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AttributeMappingRepositoryImplTest method testRetrieveAttributesFromAlgorithm.

@Test
public void testRetrieveAttributesFromAlgorithm() {
    String algorithm = "$('attribute_1').value()$('attribute_2').value()";
    Attribute attr1 = attrMetaFactory.create().setName("attribute_1");
    Attribute attr2 = attrMetaFactory.create().setName("attribute_2");
    EntityType sourceEntityType = entityTypeFactory.create("source");
    sourceEntityType.addAttribute(attr1);
    sourceEntityType.addAttribute(attr2);
    List<Attribute> sourceAttributes = newArrayList();
    sourceAttributes.add(attr1);
    sourceAttributes.add(attr2);
    assertEquals(attributeMappingRepository.retrieveAttributesFromAlgorithm(algorithm, sourceEntityType), sourceAttributes);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)600 Test (org.testng.annotations.Test)351 EntityType (org.molgenis.data.meta.model.EntityType)321 Entity (org.molgenis.data.Entity)109 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)54 DynamicEntity (org.molgenis.data.support.DynamicEntity)53 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)47 Stream (java.util.stream.Stream)39 AttributeType (org.molgenis.data.meta.AttributeType)34 QueryImpl (org.molgenis.data.support.QueryImpl)29 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)29 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)28 BeforeMethod (org.testng.annotations.BeforeMethod)20 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Collectors.toList (java.util.stream.Collectors.toList)17 Relation (org.molgenis.data.semantic.Relation)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 MolgenisDataException (org.molgenis.data.MolgenisDataException)16 Package (org.molgenis.data.meta.model.Package)16