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