use of org.molgenis.data.RepositoryNotCapableException 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();
}
Aggregations