use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class UntypedTagService method findAttributeEntity.
private Entity findAttributeEntity(EntityType entityType, String attributeName) {
Entity entityTypeEntity = dataService.findOneById(ENTITY_TYPE_META_DATA, entityType.getId());
if (entityTypeEntity == null) {
throw new UnknownEntityTypeException(entityType.getId());
}
Optional<Entity> result = stream(entityTypeEntity.getEntities(ATTRIBUTES)).filter(att -> attributeName.equals(att.getString(AttributeMetadata.NAME))).findFirst();
return result.orElse(null);
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class RestControllerV2Test method testUpdateEntitiesSpecificAttributeUnknownEntity.
@Test
void testUpdateEntitiesSpecificAttributeUnknownEntity() throws Throwable {
String unknownEntityTypeId = "entity2";
doThrow(new UnknownEntityTypeException(unknownEntityTypeId)).when(dataService).getEntityType(unknownEntityTypeId);
try {
mockMvc.perform(put(BASE_URI + "/" + unknownEntityTypeId + "/" + "email").content("{entities:[{email:'test@email.com'}]}").contentType(APPLICATION_JSON));
} catch (NestedServletException e) {
Exception exception = assertThrows(UnknownEntityTypeException.class, () -> {
throw e.getCause();
});
assertThat(exception.getMessage()).containsPattern("id:entity2");
}
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class RestControllerV2Test method testUpdateEntitiesUnknownEntity.
@Test
void testUpdateEntitiesUnknownEntity() throws Throwable {
String unknownEntityTypeId = "entity2";
doThrow(new UnknownEntityTypeException(unknownEntityTypeId)).when(dataService).getEntityType(unknownEntityTypeId);
try {
mockMvc.perform(put(BASE_URI + "/" + "entity2").content("{entities:[{email:'test@email.com'}]}").contentType(APPLICATION_JSON));
} catch (NestedServletException e) {
Exception exception = assertThrows(UnknownEntityTypeException.class, () -> {
throw e.getCause();
});
assertThat(exception.getMessage()).containsPattern("id:entity2");
}
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class RestControllerV2 method copyEntity.
/**
* Copy an entity.
*
* @deprecated use the navigator in the ui to copy entities.
* @param entityTypeId name of the entity that will be copied.
* @param request CopyEntityRequestV2
* @param response HttpServletResponse
* @return String name of the new entity
*/
@Deprecated
@Transactional
@WithJsMagmaScriptContext
@PostMapping(value = "copy/{entityTypeId}", produces = APPLICATION_JSON_VALUE)
public String copyEntity(@PathVariable("entityTypeId") String entityTypeId, @RequestBody @Valid CopyEntityRequestV2 request, HttpServletResponse response) {
UriComponentsBuilder uriBuilder = createUriBuilder();
// No repo
if (!dataService.hasRepository(entityTypeId)) {
throw new UnknownEntityTypeException(entityTypeId);
}
Repository<Entity> repositoryToCopyFrom = dataService.getRepository(entityTypeId);
// Validate the new name
NameValidator.validateEntityName(request.getNewEntityName());
// Check if the entity already exists
String newFullName = EntityTypeUtils.buildFullName(repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName());
if (dataService.hasRepository(newFullName)) {
throw new RepositoryAlreadyExistsException(newFullName);
}
// Permission
boolean readPermission = permissionService.hasPermission(new EntityTypeIdentity(repositoryToCopyFrom.getName()), EntityTypePermission.READ_DATA);
if (!readPermission) {
throw new EntityTypePermissionDeniedException(EntityTypePermission.READ_DATA, entityTypeId);
}
// Capabilities
boolean writableCapabilities = dataService.getCapabilities(repositoryToCopyFrom.getName()).contains(RepositoryCapability.WRITABLE);
if (!writableCapabilities) {
throw new RepositoryNotCapableException(repositoryToCopyFrom.getName(), RepositoryCapability.WRITABLE);
}
// Copy
Repository<Entity> repository = repoCopier.copyRepository(repositoryToCopyFrom, request.getNewEntityName(), repositoryToCopyFrom.getEntityType().getPackage(), request.getNewEntityName());
// Retrieve new repo
permissionSystemService.giveUserWriteMetaPermissions(repository.getEntityType());
response.addHeader("Location", UriUtils.createEntityCollectionUriPath(uriBuilder, repository.getName()));
response.setStatus(HttpServletResponse.SC_CREATED);
return repository.getName();
}
use of org.molgenis.data.UnknownEntityTypeException in project molgenis by molgenis.
the class EntityTypeRequestMapperImpl method updateEntityType.
@SuppressWarnings({ "java:S1192" })
private // ATTRIBUTES constant in this class is not related to the one in this switch
void updateEntityType(EntityType entityType, Entry<String, Object> entry) {
switch(entry.getKey()) {
case "package":
String packageId = String.valueOf(entry.getValue());
Package pack = metaDataService.getPackage(packageId).orElseThrow(() -> new UnknownPackageException(packageId));
entityType.setPackage(pack);
break;
case "id":
case "abstract":
throw new ReadOnlyFieldException(entry.getKey(), "entityType");
case "extends":
String extendsValue = String.valueOf(entry.getValue());
EntityType parent = metaDataService.getEntityType(extendsValue).orElseThrow(() -> new UnknownEntityTypeException(extendsValue));
entityType.setExtends(parent);
break;
case "label":
I18nValue label = I18nValueMapper.toI18nValue(entry.getValue());
processI18nLabel(label, entityType);
break;
case "description":
I18nValue description = I18nValueMapper.toI18nValue(entry.getValue());
processI18nDescription(description, entityType);
break;
case "attributes":
if (entry.getValue() != null) {
Iterable<Attribute> attributes = mapAttributes(entityType, entry);
entityType.setOwnAllAttributes(attributes);
} else {
throw new EmptyAttributesException();
}
break;
case "tags":
case "backend":
throw new UnsupportedFieldException(entry.getKey());
default:
throw new InvalidKeyException("entityType", entry.getKey());
}
}
Aggregations