Search in sources :

Example 1 with PrivateNamespaceQuotaExceededException

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);
    }
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ResponseEntity(org.springframework.http.ResponseEntity) DoesNotExistException(org.eclipse.vorto.repository.services.exceptions.DoesNotExistException) OperationForbiddenException(org.eclipse.vorto.repository.services.exceptions.OperationForbiddenException) PrivateNamespaceQuotaExceededException(org.eclipse.vorto.repository.services.exceptions.PrivateNamespaceQuotaExceededException) CollisionException(org.eclipse.vorto.repository.services.exceptions.CollisionException) NameSyntaxException(org.eclipse.vorto.repository.services.exceptions.NameSyntaxException) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

IUserContext (org.eclipse.vorto.repository.core.IUserContext)1 CollisionException (org.eclipse.vorto.repository.services.exceptions.CollisionException)1 DoesNotExistException (org.eclipse.vorto.repository.services.exceptions.DoesNotExistException)1 NameSyntaxException (org.eclipse.vorto.repository.services.exceptions.NameSyntaxException)1 OperationForbiddenException (org.eclipse.vorto.repository.services.exceptions.OperationForbiddenException)1 PrivateNamespaceQuotaExceededException (org.eclipse.vorto.repository.services.exceptions.PrivateNamespaceQuotaExceededException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1