use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class MetaDataServiceIT method testAddAttribute.
@WithMockUser(username = USERNAME)
@Test
@Order(8)
public void testAddAttribute() {
EntityType entityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
;
Attribute attribute = attributeFactory.create().setName("newAttribute");
attribute.setEntity(entityType);
metaDataService.addAttribute(attribute);
EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
;
assertTrue(EntityUtils.equals(attribute, updatedEntityType.getAttribute("newAttribute")));
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class MetaDataServiceIT method testDeleteAttribute.
@WithMockUser(username = USERNAME)
@Test
@Order(10)
public void testDeleteAttribute() {
EntityType entityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
;
String attributeId = entityType.getAttribute("newAttribute").getIdentifier();
metaDataService.deleteAttributeById(attributeId);
EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
;
org.junit.jupiter.api.Assertions.assertNull(updatedEntityType.getAttribute("newAttribute"));
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class MetaDataServiceIT method testUpdateEntityTypeNotAllowed.
@SuppressWarnings("deprecation")
@WithMockUser(username = USERNAME)
@Test
@Order(4)
public void testUpdateEntityTypeNotAllowed() {
EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
updatedEntityType.getAttribute(ATTR_COMPOUND_CHILD_INT).setDataType(DATE_TIME);
Exception exception = assertThrows(MolgenisDataException.class, () -> metaDataService.updateEntityType(updatedEntityType));
assertThat(exception.getMessage()).containsPattern("Attribute data type update from \\[INT\\] to \\[DATE_TIME\\] not allowed, allowed types are \\[BOOL, CATEGORICAL, DECIMAL, ENUM, LONG, STRING, TEXT, XREF\\]");
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class MetaDataServiceIT method testUpdateAttribute.
@WithMockUser(username = USERNAME)
@Test
@Order(9)
public void testUpdateAttribute() {
EntityType entityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
Attribute attribute = entityType.getAttribute("newAttribute");
attribute.setLabel("updated-label");
attribute.setEntity(entityType);
dataService.update(ATTRIBUTE_META_DATA, attribute);
EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID).orElseThrow(() -> new UnknownEntityTypeException(ENTITY_TYPE_ID));
;
assertTrue(EntityUtils.equals(attribute, updatedEntityType.getAttribute("newAttribute")));
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class RestController method getAttributePostInternal.
private AttributeResponse getAttributePostInternal(String entityTypeId, String attributeName, Set<String> attributeSet, Map<String, Set<String>> attributeExpandSet) {
EntityType meta = dataService.getEntityType(entityTypeId);
Attribute attribute = meta.getAttribute(attributeName);
if (attribute != null) {
return new AttributeResponse(entityTypeId, meta, attribute, attributeSet, attributeExpandSet, permissionService, dataService);
} else {
throw new UnknownEntityTypeException(entityTypeId);
}
}
Aggregations