use of com.hortonworks.registries.storage.exception.AlreadyExistsException in project streamline by hortonworks.
the class NamespaceCatalogResource method addNamespace.
@Timed
@POST
@Path("/namespaces")
public Response addNamespace(Namespace namespace, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_ADMIN);
try {
String namespaceName = namespace.getName();
Namespace result = environmentService.getNamespaceByName(namespaceName);
if (result != null) {
throw new AlreadyExistsException("Namespace entity already exists with name " + namespaceName);
}
Namespace created = environmentService.addNamespace(namespace);
SecurityUtil.addAcl(authorizer, securityContext, Namespace.NAMESPACE, created.getId(), EnumSet.allOf(Permission.class));
return WSUtils.respondEntity(created, CREATED);
} catch (ProcessingException ex) {
throw BadRequestException.of();
}
}
use of com.hortonworks.registries.storage.exception.AlreadyExistsException in project streamline by hortonworks.
the class ServiceBundleResource method addServiceBundle.
/**
* Add a new service bundle.
*/
@POST
@Path("/servicebundles")
@Timed
public Response addServiceBundle(ServiceBundle serviceBundle) throws IOException, ComponentConfigException {
try {
String serviceName = serviceBundle.getName();
ServiceBundle result = environmentService.getServiceBundleByName(serviceName);
if (result != null) {
throw new AlreadyExistsException("Service bundle for " + serviceName + " is already registered.");
}
ServiceBundle created = environmentService.addServiceBundle(serviceBundle);
return WSUtils.respondEntity(created, CREATED);
} catch (ProcessingException ex) {
throw BadRequestException.of();
}
}
Aggregations