use of org.eclipse.vorto.repository.services.exceptions.PrivateNamespaceQuotaExceededException in project vorto by eclipse.
the class NamespaceController method createNamespace.
/**
* Creates a new namespace with the given name for the authenticated user. <br/>
* Automatically adds the user as owner and gives them all applicable roles on the namespace.<br/>
* Subject to restrictions in terms of number of private namespaces owned, and whether the user
* has the sufficient repository privileges to own a non-private namespace.
*
* @param namespace
* @return
*/
@PutMapping(value = "/{namespace:.+}", produces = "application/json")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<OperationResult> createNamespace(@ApiParam(value = "The name of the namespace to be created", required = true) @PathVariable final String namespace) {
try {
IUserContext userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication());
namespaceService.create(userContext.getUsername(), userContext.getUsername(), namespace);
return new ResponseEntity<>(OperationResult.success(), HttpStatus.CREATED);
} catch (DoesNotExistException | NameSyntaxException e) {
return new ResponseEntity<>(OperationResult.failure(e.getMessage()), HttpStatus.BAD_REQUEST);
} catch (PrivateNamespaceQuotaExceededException pnqee) {
return new ResponseEntity<>(OperationResult.failure(pnqee.getMessage()), HttpStatus.FORBIDDEN);
}// omitting explicit collision message and just going with status here
catch (CollisionException ce) {
return new ResponseEntity<>(OperationResult.failure(""), HttpStatus.CONFLICT);
} catch (OperationForbiddenException ofe) {
return new ResponseEntity<>(OperationResult.failure(ofe.getMessage()), HttpStatus.FORBIDDEN);
}
}
Aggregations