use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class EntityTypeRequestMapperImpl method toEntityType.
@Override
public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) {
EntityType entityType = entityTypeFactory.create();
String entityTypeId = entityTypeRequest.getId();
if (entityTypeId != null) {
entityType.setId(entityTypeId);
}
String packageId = entityTypeRequest.getPackage();
Package pack = null;
if (packageId != null) {
pack = metaDataService.getPackage(packageId).orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage()));
}
entityType.setPackage(pack);
String extendsEntityTypeId = entityTypeRequest.getExtends();
if (extendsEntityTypeId != null) {
EntityType extendsEntityType = metaDataService.getEntityType(extendsEntityTypeId).orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId));
entityType.setExtends(extendsEntityType);
}
processI18nLabel(entityTypeRequest.getLabel(), entityType);
processI18nDescription(entityTypeRequest.getDescription(), entityType);
List<Attribute> ownAttributes = attributeRequestMapper.toAttributes(entityTypeRequest.getAttributes(), entityTypeRequest, entityType);
entityType.setOwnAllAttributes(ownAttributes);
Boolean abstractEntityType = entityTypeRequest.getAbstract();
if (abstractEntityType != null) {
entityType.setAbstract(abstractEntityType);
}
entityType.setBackend(metaDataService.getDefaultBackend().getName());
processSelfReferencingAttributes(entityType, ownAttributes);
return entityType;
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class RestControllerTest method retrieveAttributeUnknownEntity.
@Test
void retrieveAttributeUnknownEntity() throws Throwable {
String entityTypeId = "unknown";
when(dataService.getEntityType(entityTypeId)).thenThrow(new UnknownEntityTypeException(entityTypeId));
String HREF_UNKNOWN_ENTITY_META = BASE_URI + "/" + entityTypeId + "/meta";
try {
mockMvc.perform(get(HREF_UNKNOWN_ENTITY_META + "/attribute"));
} catch (NestedServletException e) {
Exception exception = assertThrows(UnknownEntityTypeException.class, () -> {
throw e.getCause();
});
assertThat(exception.getMessage()).containsPattern("id:unknown");
}
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class RestControllerTest method handleUnknownEntityException.
@Test
void handleUnknownEntityException() throws Throwable {
String entityTypeId = "bogus";
when(dataService.getEntityType(entityTypeId)).thenThrow(new UnknownEntityTypeException(entityTypeId));
try {
mockMvc.perform(get(BASE_URI + "/" + entityTypeId + "/1"));
} catch (NestedServletException e) {
assertThrows(UnknownEntityTypeException.class, () -> {
throw e.getCause();
});
}
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class MetaDataServiceImpl method updateEntityType.
@Transactional
@Override
public void updateEntityType(EntityType entityType) {
EntityType existingEntityType = dataService.query(ENTITY_TYPE_META_DATA, EntityType.class).eq(EntityTypeMetadata.ID, entityType.getId()).fetch(getEntityTypeFetch()).findOne();
if (existingEntityType == null) {
throw new UnknownEntityTypeException(entityType.getId());
}
updateEntityType(entityType, existingEntityType);
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class EntityTypeRepositoryDecorator method deleteById.
@Override
public void deleteById(Object id) {
EntityType entityType = findOneById(id);
if (entityType == null) {
throw new UnknownEntityTypeException(id.toString());
}
deleteEntityType(entityType);
}
Aggregations