diff --git a/manager/api/core/src/main/java/io/apiman/manager/api/core/IIdmStorage.java b/manager/api/core/src/main/java/io/apiman/manager/api/core/IIdmStorage.java index 46d792405b..cee0179815 100644 --- a/manager/api/core/src/main/java/io/apiman/manager/api/core/IIdmStorage.java +++ b/manager/api/core/src/main/java/io/apiman/manager/api/core/IIdmStorage.java @@ -21,8 +21,6 @@ import io.apiman.manager.api.beans.idm.UserBean; import io.apiman.manager.api.beans.search.SearchCriteriaBean; import io.apiman.manager.api.beans.search.SearchResultsBean; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import java.util.Set; @@ -45,25 +43,22 @@ public interface IIdmStorage { * Creates a user in the IDM system. * @param user * @throws StorageException - * @throws AlreadyExistsException */ - public void createUser(UserBean user) throws StorageException, AlreadyExistsException; + public void createUser(UserBean user) throws StorageException; /** * Gets a user by id. * @param userId * @throws StorageException - * @throws DoesNotExistException */ - public UserBean getUser(String userId) throws StorageException, DoesNotExistException; + public UserBean getUser(String userId) throws StorageException; /** * Updates the personal information about a user. * @param user * @throws StorageException - * @throws DoesNotExistException */ - public void updateUser(UserBean user) throws StorageException, DoesNotExistException; + public void updateUser(UserBean user) throws StorageException; /** * Returns a list of users that match the given search criteria. @@ -78,34 +73,30 @@ public interface IIdmStorage { * memberhip in those roles will grant. * @param role * @throws StorageException - * @throws AlreadyExistsException */ - public void createRole(RoleBean role) throws StorageException, AlreadyExistsException; + public void createRole(RoleBean role) throws StorageException; /** * Gets a role by id. * @param roleId * @throws StorageException - * @throws DoesNotExistException */ - public RoleBean getRole(String roleId) throws StorageException, DoesNotExistException; + public RoleBean getRole(String roleId) throws StorageException; /** * Updates a single role (typically with new permissions). * @param role * @throws StorageException - * @throws AlreadyExistsException */ - public void updateRole(RoleBean role) throws StorageException, DoesNotExistException; + public void updateRole(RoleBean role) throws StorageException; /** * Deletes a role from the system. This would also remove all memberships in * that role. This should be done very infrequently! * @param role * @throws StorageException - * @throws DoesNotExistException */ - public void deleteRole(RoleBean role) throws StorageException, DoesNotExistException; + public void deleteRole(RoleBean role) throws StorageException; /** * Returns a list of users that match the given search criteria. @@ -118,9 +109,8 @@ public interface IIdmStorage { * Grants membership into a role for a user. * @param membership * @throws StorageException - * @throws AlreadyExistsException */ - public void createMembership(RoleMembershipBean membership) throws StorageException, AlreadyExistsException; + public void createMembership(RoleMembershipBean membership) throws StorageException; /** * Deletes a single membership. @@ -128,9 +118,8 @@ public interface IIdmStorage { * @param roleId * @param organizationId * @throws StorageException - * @throws DoesNotExistException */ - public void deleteMembership(String userId, String roleId, String organizationId) throws StorageException, DoesNotExistException; + public void deleteMembership(String userId, String roleId, String organizationId) throws StorageException; /** * Deletes all role memberships for a user in a given organization. diff --git a/manager/api/core/src/main/java/io/apiman/manager/api/core/IStorage.java b/manager/api/core/src/main/java/io/apiman/manager/api/core/IStorage.java index 2ab138f4c4..1c209982ff 100644 --- a/manager/api/core/src/main/java/io/apiman/manager/api/core/IStorage.java +++ b/manager/api/core/src/main/java/io/apiman/manager/api/core/IStorage.java @@ -28,8 +28,6 @@ import io.apiman.manager.api.beans.policies.PolicyDefinitionBean; import io.apiman.manager.api.beans.services.ServiceBean; import io.apiman.manager.api.beans.services.ServiceVersionBean; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; /** @@ -51,69 +49,69 @@ public interface IStorage { * Various creation methods. These are called by the REST layer to create stuff. */ - public void createOrganization(OrganizationBean organization) throws StorageException, AlreadyExistsException; - public void createApplication(ApplicationBean application) throws StorageException, AlreadyExistsException; - public void createApplicationVersion(ApplicationVersionBean version) throws StorageException, AlreadyExistsException; - public void createContract(ContractBean contract) throws StorageException, AlreadyExistsException; - public void createService(ServiceBean service) throws StorageException, AlreadyExistsException; - public void createServiceVersion(ServiceVersionBean version) throws StorageException, AlreadyExistsException; - public void createPlan(PlanBean plan) throws StorageException, AlreadyExistsException; - public void createPlanVersion(PlanVersionBean version) throws StorageException, AlreadyExistsException; - public void createPolicy(PolicyBean policy) throws StorageException, AlreadyExistsException; - public void createGateway(GatewayBean gateway) throws StorageException, AlreadyExistsException; - public void createPolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException, AlreadyExistsException; - public void createRole(RoleBean role) throws StorageException, AlreadyExistsException; + public void createOrganization(OrganizationBean organization) throws StorageException; + public void createApplication(ApplicationBean application) throws StorageException; + public void createApplicationVersion(ApplicationVersionBean version) throws StorageException; + public void createContract(ContractBean contract) throws StorageException; + public void createService(ServiceBean service) throws StorageException; + public void createServiceVersion(ServiceVersionBean version) throws StorageException; + public void createPlan(PlanBean plan) throws StorageException; + public void createPlanVersion(PlanVersionBean version) throws StorageException; + public void createPolicy(PolicyBean policy) throws StorageException; + public void createGateway(GatewayBean gateway) throws StorageException; + public void createPolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException; + public void createRole(RoleBean role) throws StorageException; public void createAuditEntry(AuditEntryBean entry) throws StorageException; /* * Various update methods. These are called by the REST layer to update stuff. */ - public void updateOrganization(OrganizationBean organization) throws StorageException, DoesNotExistException; - public void updateApplication(ApplicationBean application) throws StorageException, DoesNotExistException; - public void updateApplicationVersion(ApplicationVersionBean version) throws StorageException, DoesNotExistException; - public void updateContract(ContractBean contract) throws StorageException, DoesNotExistException; - public void updateService(ServiceBean service) throws StorageException, DoesNotExistException; - public void updateServiceVersion(ServiceVersionBean version) throws StorageException, DoesNotExistException; - public void updatePlan(PlanBean plan) throws StorageException, DoesNotExistException; - public void updatePlanVersion(PlanVersionBean version) throws StorageException, DoesNotExistException; - public void updatePolicy(PolicyBean policy) throws StorageException, DoesNotExistException; - public void updateGateway(GatewayBean gateway) throws StorageException, DoesNotExistException; - public void updatePolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException, DoesNotExistException; - public void updateRole(RoleBean role) throws StorageException, DoesNotExistException; + public void updateOrganization(OrganizationBean organization) throws StorageException; + public void updateApplication(ApplicationBean application) throws StorageException; + public void updateApplicationVersion(ApplicationVersionBean version) throws StorageException; + public void updateContract(ContractBean contract) throws StorageException; + public void updateService(ServiceBean service) throws StorageException; + public void updateServiceVersion(ServiceVersionBean version) throws StorageException; + public void updatePlan(PlanBean plan) throws StorageException; + public void updatePlanVersion(PlanVersionBean version) throws StorageException; + public void updatePolicy(PolicyBean policy) throws StorageException; + public void updateGateway(GatewayBean gateway) throws StorageException; + public void updatePolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException; + public void updateRole(RoleBean role) throws StorageException; /* * Various delete methods. These are called by the REST layer to delete stuff. */ - public void deleteOrganization(OrganizationBean organization) throws StorageException, DoesNotExistException; - public void deleteApplication(ApplicationBean application) throws StorageException, DoesNotExistException; - public void deleteApplicationVersion(ApplicationVersionBean version) throws StorageException, DoesNotExistException; - public void deleteContract(ContractBean contract) throws StorageException, DoesNotExistException; - public void deleteService(ServiceBean service) throws StorageException, DoesNotExistException; - public void deleteServiceVersion(ServiceVersionBean version) throws StorageException, DoesNotExistException; - public void deletePlan(PlanBean plan) throws StorageException, DoesNotExistException; - public void deletePlanVersion(PlanVersionBean version) throws StorageException, DoesNotExistException; - public void deletePolicy(PolicyBean policy) throws StorageException, DoesNotExistException; - public void deleteGateway(GatewayBean gateway) throws StorageException, DoesNotExistException; - public void deletePolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException, DoesNotExistException; - public void deleteRole(RoleBean role) throws StorageException, DoesNotExistException; + public void deleteOrganization(OrganizationBean organization) throws StorageException; + public void deleteApplication(ApplicationBean application) throws StorageException; + public void deleteApplicationVersion(ApplicationVersionBean version) throws StorageException; + public void deleteContract(ContractBean contract) throws StorageException; + public void deleteService(ServiceBean service) throws StorageException; + public void deleteServiceVersion(ServiceVersionBean version) throws StorageException; + public void deletePlan(PlanBean plan) throws StorageException; + public void deletePlanVersion(PlanVersionBean version) throws StorageException; + public void deletePolicy(PolicyBean policy) throws StorageException; + public void deleteGateway(GatewayBean gateway) throws StorageException; + public void deletePolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException; + public void deleteRole(RoleBean role) throws StorageException; /* * Various get methods. These are called by the REST layer to get stuff. */ - public OrganizationBean getOrganization(String id) throws StorageException, DoesNotExistException; - public ApplicationBean getApplication(String organizationId, String id) throws StorageException, DoesNotExistException; - public ApplicationVersionBean getApplicationVersion(String organizationId, String applicationId, String version) throws StorageException, DoesNotExistException; - public ContractBean getContract(Long id) throws StorageException, DoesNotExistException; - public ServiceBean getService(String organizationId, String id) throws StorageException, DoesNotExistException; - public ServiceVersionBean getServiceVersion(String organizationId, String serviceId, String version) throws StorageException, DoesNotExistException; - public PlanBean getPlan(String organizationId, String id) throws StorageException, DoesNotExistException; - public PlanVersionBean getPlanVersion(String organizationId, String planId, String version) throws StorageException, DoesNotExistException; - public PolicyBean getPolicy(Long id) throws StorageException, DoesNotExistException; - public GatewayBean getGateway(String id) throws StorageException, DoesNotExistException; - public PolicyDefinitionBean getPolicyDefinition(String id) throws StorageException, DoesNotExistException; - public RoleBean getRole(String id) throws StorageException, DoesNotExistException; + public OrganizationBean getOrganization(String id) throws StorageException; + public ApplicationBean getApplication(String organizationId, String id) throws StorageException; + public ApplicationVersionBean getApplicationVersion(String organizationId, String applicationId, String version) throws StorageException; + public ContractBean getContract(Long id) throws StorageException; + public ServiceBean getService(String organizationId, String id) throws StorageException; + public ServiceVersionBean getServiceVersion(String organizationId, String serviceId, String version) throws StorageException; + public PlanBean getPlan(String organizationId, String id) throws StorageException; + public PlanVersionBean getPlanVersion(String organizationId, String planId, String version) throws StorageException; + public PolicyBean getPolicy(Long id) throws StorageException; + public GatewayBean getGateway(String id) throws StorageException; + public PolicyDefinitionBean getPolicyDefinition(String id) throws StorageException; + public RoleBean getRole(String id) throws StorageException; } diff --git a/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/AlreadyExistsException.java b/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/AlreadyExistsException.java deleted file mode 100644 index 53159b45c2..0000000000 --- a/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/AlreadyExistsException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2014 JBoss Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.apiman.manager.api.core.exceptions; - -/** - * Exception thrown when an entity already exists. - * - * @author eric.wittmann@redhat.com - */ -public class AlreadyExistsException extends StorageException { - - private static final long serialVersionUID = -8861679618736432651L; - - /** - * Constructor. - */ - public AlreadyExistsException() { - } - -} diff --git a/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/ConstraintViolationException.java b/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/ConstraintViolationException.java deleted file mode 100644 index dc578af857..0000000000 --- a/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/ConstraintViolationException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2014 JBoss Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.apiman.manager.api.core.exceptions; - -/** - * Exception thrown when there is a contraint violation error. - * - * @author eric.wittmann@redhat.com - */ -public class ConstraintViolationException extends StorageException { - - private static final long serialVersionUID = 6100964937829691323L; - - /** - * Constructor. - * @param cause - */ - public ConstraintViolationException(Throwable cause) { - super(cause); - } - -} diff --git a/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/DoesNotExistException.java b/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/DoesNotExistException.java deleted file mode 100644 index 0c227a009b..0000000000 --- a/manager/api/core/src/main/java/io/apiman/manager/api/core/exceptions/DoesNotExistException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2014 JBoss Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.apiman.manager.api.core.exceptions; - -/** - * - * - * @author eric.wittmann@redhat.com - */ -public class DoesNotExistException extends StorageException { - - private static final long serialVersionUID = -7445754147775177820L; - - /** - * Constructor. - */ - public DoesNotExistException() { - } - -} diff --git a/manager/api/jpa-idm/src/main/java/io/apiman/manager/api/jpa/roles/JpaIdmStorage.java b/manager/api/jpa-idm/src/main/java/io/apiman/manager/api/jpa/roles/JpaIdmStorage.java index fe7e5c7599..8962aa19ab 100644 --- a/manager/api/jpa-idm/src/main/java/io/apiman/manager/api/jpa/roles/JpaIdmStorage.java +++ b/manager/api/jpa-idm/src/main/java/io/apiman/manager/api/jpa/roles/JpaIdmStorage.java @@ -23,8 +23,6 @@ import io.apiman.manager.api.beans.search.SearchCriteriaBean; import io.apiman.manager.api.beans.search.SearchResultsBean; import io.apiman.manager.api.core.IIdmStorage; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import io.apiman.manager.api.jpa.AbstractJpaStorage; @@ -64,15 +62,12 @@ public JpaIdmStorage() { * @see io.apiman.manager.api.core.IIdmStorage#createUser(io.apiman.manager.api.beans.idm.UserBean) */ @Override - public void createUser(UserBean user) throws StorageException, AlreadyExistsException { + public void createUser(UserBean user) throws StorageException { user.setJoinedOn(new Date()); beginTx(); try { super.create(user); commitTx(); - } catch (AlreadyExistsException e) { - rollbackTx(); - throw e; } catch (StorageException e) { rollbackTx(); throw e; @@ -83,7 +78,7 @@ public void createUser(UserBean user) throws StorageException, AlreadyExistsExce * @see io.apiman.manager.api.core.IIdmStorage#getUser(java.lang.String) */ @Override - public UserBean getUser(String userId) throws StorageException, DoesNotExistException { + public UserBean getUser(String userId) throws StorageException { beginTx(); try { return super.get(userId, UserBean.class); @@ -96,7 +91,7 @@ public UserBean getUser(String userId) throws StorageException, DoesNotExistExce * @see io.apiman.manager.api.core.IIdmStorage#updateUser(io.apiman.manager.api.beans.idm.UserBean) */ @Override - public void updateUser(UserBean user) throws StorageException, DoesNotExistException { + public void updateUser(UserBean user) throws StorageException { beginTx(); try { super.update(user); @@ -122,7 +117,7 @@ public SearchResultsBean findUsers(SearchCriteriaBean criteria) throws * @see io.apiman.manager.api.core.IIdmStorage#createRole(io.apiman.manager.api.beans.idm.RoleBean) */ @Override - public void createRole(RoleBean role) throws StorageException, AlreadyExistsException { + public void createRole(RoleBean role) throws StorageException { beginTx(); try { super.create(role); @@ -135,7 +130,7 @@ public void createRole(RoleBean role) throws StorageException, AlreadyExistsExce * @see io.apiman.manager.api.core.IIdmStorage#updateRole(io.apiman.manager.api.beans.idm.RoleBean) */ @Override - public void updateRole(RoleBean role) throws StorageException, DoesNotExistException { + public void updateRole(RoleBean role) throws StorageException { beginTx(); try { super.update(role); @@ -148,7 +143,7 @@ public void updateRole(RoleBean role) throws StorageException, DoesNotExistExcep * @see io.apiman.manager.api.core.IIdmStorage#deleteRole(io.apiman.manager.api.beans.idm.RoleBean) */ @Override - public void deleteRole(RoleBean role) throws StorageException, DoesNotExistException { + public void deleteRole(RoleBean role) throws StorageException { beginTx(); try { EntityManager entityManager = getActiveEntityManager(); @@ -175,7 +170,7 @@ public void deleteRole(RoleBean role) throws StorageException, DoesNotExistExcep * @see io.apiman.manager.api.core.IIdmStorage#getRole(java.lang.String) */ @Override - public RoleBean getRole(String roleId) throws StorageException, DoesNotExistException { + public RoleBean getRole(String roleId) throws StorageException { beginTx(); try { return getRoleInternal(roleId); @@ -201,8 +196,7 @@ public SearchResultsBean findRoles(SearchCriteriaBean criteria) throws * @see io.apiman.manager.api.core.IIdmStorage#createMembership(io.apiman.manager.api.beans.idm.RoleMembershipBean) */ @Override - public void createMembership(RoleMembershipBean membership) throws StorageException, - AlreadyExistsException { + public void createMembership(RoleMembershipBean membership) throws StorageException { beginTx(); try { super.create(membership); @@ -215,8 +209,7 @@ public void createMembership(RoleMembershipBean membership) throws StorageExcept * @see io.apiman.manager.api.core.IIdmStorage#deleteMembership(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void deleteMembership(String userId, String roleId, String organizationId) - throws StorageException, DoesNotExistException { + public void deleteMembership(String userId, String roleId, String organizationId) throws StorageException { beginTx(); try { EntityManager entityManager = getActiveEntityManager(); @@ -224,12 +217,8 @@ public void deleteMembership(String userId, String roleId, String organizationId query.setParameter("roleId", roleId); //$NON-NLS-1$ query.setParameter("userId", userId); //$NON-NLS-1$ query.setParameter("orgId", organizationId); //$NON-NLS-1$ - if (query.executeUpdate() == 0) - throw new DoesNotExistException(); + query.executeUpdate(); commitTx(); - } catch (DoesNotExistException dne) { - rollbackTx(); - throw dne; } catch (Throwable t) { logger.error(t.getMessage(), t); rollbackTx(); @@ -374,7 +363,7 @@ public Set getPermissions(String userId) throws StorageException * @throws StorageException * @throws DoesNotExistException */ - protected RoleBean getRoleInternal(String roleId) throws StorageException, DoesNotExistException { + protected RoleBean getRoleInternal(String roleId) throws StorageException { return super.get(roleId, RoleBean.class); } diff --git a/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/AbstractJpaStorage.java b/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/AbstractJpaStorage.java index 996905a09a..11c733fe56 100644 --- a/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/AbstractJpaStorage.java +++ b/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/AbstractJpaStorage.java @@ -22,9 +22,6 @@ import io.apiman.manager.api.beans.search.SearchCriteriaBean; import io.apiman.manager.api.beans.search.SearchCriteriaFilterBean; import io.apiman.manager.api.beans.search.SearchResultsBean; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.ConstraintViolationException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import java.util.ArrayList; @@ -33,7 +30,6 @@ import javax.inject.Inject; import javax.persistence.EntityExistsException; import javax.persistence.EntityManager; -import javax.persistence.PersistenceException; import javax.persistence.RollbackException; import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaBuilder; @@ -90,15 +86,10 @@ protected void commitTx() throws StorageException { activeEM.get().close(); activeEM.set(null); } catch (EntityExistsException e) { - throw new AlreadyExistsException(); + throw new StorageException(e); } catch (RollbackException e) { - if (JpaUtil.isConstraintViolation(e)) { - logger.error(e.getMessage(), e); - throw new ConstraintViolationException(e); - } else { - logger.error(e.getMessage(), e); - throw new StorageException(e); - } + logger.error(e.getMessage(), e); + throw new StorageException(e); } catch (Throwable t) { logger.error(t.getMessage(), t); throw new StorageException(t); @@ -135,32 +126,13 @@ protected EntityManager getActiveEntityManager() throws StorageException { /** * @see io.apiman.manager.api.core.IStorage#create(java.lang.Object) */ - public void create(T bean) throws StorageException, AlreadyExistsException { + public void create(T bean) throws StorageException { if (bean == null) { return; } EntityManager entityManager = getActiveEntityManager(); try { entityManager.persist(bean); - } catch (EntityExistsException e) { - logger.error(e.getMessage(), e); - throw new AlreadyExistsException(); - } catch (RollbackException e) { - if (JpaUtil.isConstraintViolation(e)) { - logger.error(e.getMessage(), e); - throw new ConstraintViolationException(e); - } else { - logger.error(e.getMessage(), e); - throw new StorageException(e); - } - } catch (PersistenceException e) { - if (JpaUtil.isConstraintViolation(e)) { - logger.error(e.getMessage(), e); - throw new ConstraintViolationException(e); - } else { - logger.error(e.getMessage(), e); - throw new StorageException(e); - } } catch (Throwable t) { logger.error(t.getMessage(), t); throw new StorageException(t); @@ -170,21 +142,10 @@ public void create(T bean) throws StorageException, AlreadyExistsException { /** * @see io.apiman.manager.api.core.IStorage#update(java.lang.Object) */ - public void update(T bean) throws StorageException, DoesNotExistException { + public void update(T bean) throws StorageException { EntityManager entityManager = getActiveEntityManager(); try { entityManager.merge(bean); - } catch (IllegalArgumentException e) { - logger.error(e.getMessage(), e); - throw new DoesNotExistException(); - } catch (RollbackException e) { - if (JpaUtil.isConstraintViolation(e)) { - logger.error(e.getMessage(), e); - throw new ConstraintViolationException(e); - } else { - logger.error(e.getMessage(), e); - throw new StorageException(e); - } } catch (Throwable t) { logger.error(t.getMessage(), t); throw new StorageException(t); @@ -194,21 +155,10 @@ public void update(T bean) throws StorageException, DoesNotExistException { /** * @see io.apiman.manager.api.core.IStorage#delete(java.lang.Object) */ - public void delete(T bean) throws StorageException, DoesNotExistException { + public void delete(T bean) throws StorageException { EntityManager entityManager = getActiveEntityManager(); try { entityManager.remove(bean); - } catch (IllegalArgumentException e) { - logger.error(e.getMessage(), e); - throw new DoesNotExistException(); - } catch (RollbackException e) { - if (JpaUtil.isConstraintViolation(e)) { - logger.error(e.getMessage(), e); - throw new ConstraintViolationException(e); - } else { - logger.error(e.getMessage(), e); - throw new StorageException(e); - } } catch (Throwable t) { logger.error(t.getMessage(), t); throw new StorageException(t); @@ -218,7 +168,7 @@ public void delete(T bean) throws StorageException, DoesNotExistException { /** * @see io.apiman.manager.api.core.IStorage#get(java.lang.Long, java.lang.Class) */ - public T get(Long id, Class type) throws StorageException, DoesNotExistException { + public T get(Long id, Class type) throws StorageException { T rval = null; EntityManager entityManager = getActiveEntityManager(); try { @@ -227,15 +177,13 @@ public T get(Long id, Class type) throws StorageException, DoesNotExistEx logger.error(t.getMessage(), t); throw new StorageException(t); } - if (rval == null) - throw new DoesNotExistException(); return rval; } /** * @see io.apiman.manager.api.core.IStorage#get(java.lang.String, java.lang.Class) */ - public T get(String id, Class type) throws StorageException, DoesNotExistException { + public T get(String id, Class type) throws StorageException { T rval = null; EntityManager entityManager = getActiveEntityManager(); try { @@ -244,15 +192,13 @@ public T get(String id, Class type) throws StorageException, DoesNotExist logger.error(t.getMessage(), t); throw new StorageException(t); } - if (rval == null) - throw new DoesNotExistException(); return rval; } /** * @see io.apiman.manager.api.core.IStorage#get(java.lang.String, java.lang.String, java.lang.Class) */ - public T get(String organizationId, String id, Class type) throws StorageException, DoesNotExistException { + public T get(String organizationId, String id, Class type) throws StorageException { T rval = null; EntityManager entityManager = getActiveEntityManager(); try { @@ -263,8 +209,6 @@ public T get(String organizationId, String id, Class type) throws Storage logger.error(t.getMessage(), t); throw new StorageException(t); } - if (rval == null) - throw new DoesNotExistException(); return rval; } diff --git a/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java b/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java index 093af414e2..6a71c24f67 100644 --- a/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java +++ b/manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java @@ -54,8 +54,6 @@ import io.apiman.manager.api.core.IApiKeyGenerator; import io.apiman.manager.api.core.IStorage; import io.apiman.manager.api.core.IStorageQuery; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import io.apiman.manager.api.core.util.PolicyTemplateUtil; @@ -117,8 +115,7 @@ public void rollbackTx() { * @see io.apiman.manager.api.core.IStorage#createApplication(io.apiman.manager.api.beans.apps.ApplicationBean) */ @Override - public void createApplication(ApplicationBean application) throws StorageException, - AlreadyExistsException { + public void createApplication(ApplicationBean application) throws StorageException { super.create(application); } @@ -126,8 +123,7 @@ public void createApplication(ApplicationBean application) throws StorageExcepti * @see io.apiman.manager.api.core.IStorage#createApplicationVersion(io.apiman.manager.api.beans.apps.ApplicationVersionBean) */ @Override - public void createApplicationVersion(ApplicationVersionBean version) throws StorageException, - AlreadyExistsException { + public void createApplicationVersion(ApplicationVersionBean version) throws StorageException { super.create(version); } @@ -135,7 +131,7 @@ public void createApplicationVersion(ApplicationVersionBean version) throws Stor * @see io.apiman.manager.api.core.IStorage#createContract(io.apiman.manager.api.beans.contracts.ContractBean) */ @Override - public void createContract(ContractBean contract) throws StorageException, AlreadyExistsException { + public void createContract(ContractBean contract) throws StorageException { super.create(contract); } @@ -143,7 +139,7 @@ public void createContract(ContractBean contract) throws StorageException, Alrea * @see io.apiman.manager.api.core.IStorage#createGateway(io.apiman.manager.api.beans.gateways.GatewayBean) */ @Override - public void createGateway(GatewayBean gateway) throws StorageException, AlreadyExistsException { + public void createGateway(GatewayBean gateway) throws StorageException { super.create(gateway); } @@ -151,8 +147,7 @@ public void createGateway(GatewayBean gateway) throws StorageException, AlreadyE * @see io.apiman.manager.api.core.IStorage#createOrganization(io.apiman.manager.api.beans.orgs.OrganizationBean) */ @Override - public void createOrganization(OrganizationBean organization) throws StorageException, - AlreadyExistsException { + public void createOrganization(OrganizationBean organization) throws StorageException { super.create(organization); } @@ -160,7 +155,7 @@ public void createOrganization(OrganizationBean organization) throws StorageExce * @see io.apiman.manager.api.core.IStorage#createPlan(io.apiman.manager.api.beans.plans.PlanBean) */ @Override - public void createPlan(PlanBean plan) throws StorageException, AlreadyExistsException { + public void createPlan(PlanBean plan) throws StorageException { super.create(plan); } @@ -168,7 +163,7 @@ public void createPlan(PlanBean plan) throws StorageException, AlreadyExistsExce * @see io.apiman.manager.api.core.IStorage#createPlanVersion(io.apiman.manager.api.beans.plans.PlanVersionBean) */ @Override - public void createPlanVersion(PlanVersionBean version) throws StorageException, AlreadyExistsException { + public void createPlanVersion(PlanVersionBean version) throws StorageException { super.create(version); } @@ -176,7 +171,7 @@ public void createPlanVersion(PlanVersionBean version) throws StorageException, * @see io.apiman.manager.api.core.IStorage#createPolicy(io.apiman.manager.api.beans.policies.PolicyBean) */ @Override - public void createPolicy(PolicyBean policy) throws StorageException, AlreadyExistsException { + public void createPolicy(PolicyBean policy) throws StorageException { super.create(policy); } @@ -184,8 +179,7 @@ public void createPolicy(PolicyBean policy) throws StorageException, AlreadyExis * @see io.apiman.manager.api.core.IStorage#createPolicyDefinition(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) */ @Override - public void createPolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException, - AlreadyExistsException { + public void createPolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException { super.create(policyDef); } @@ -193,7 +187,7 @@ public void createPolicyDefinition(PolicyDefinitionBean policyDef) throws Storag * @see io.apiman.manager.api.core.IStorage#createRole(io.apiman.manager.api.beans.idm.RoleBean) */ @Override - public void createRole(RoleBean role) throws StorageException, AlreadyExistsException { + public void createRole(RoleBean role) throws StorageException { super.create(role); } @@ -201,7 +195,7 @@ public void createRole(RoleBean role) throws StorageException, AlreadyExistsExce * @see io.apiman.manager.api.core.IStorage#createService(io.apiman.manager.api.beans.services.ServiceBean) */ @Override - public void createService(ServiceBean service) throws StorageException, AlreadyExistsException { + public void createService(ServiceBean service) throws StorageException { super.create(service); } @@ -209,8 +203,7 @@ public void createService(ServiceBean service) throws StorageException, AlreadyE * @see io.apiman.manager.api.core.IStorage#createServiceVersion(io.apiman.manager.api.beans.services.ServiceVersionBean) */ @Override - public void createServiceVersion(ServiceVersionBean version) throws StorageException, - AlreadyExistsException { + public void createServiceVersion(ServiceVersionBean version) throws StorageException { super.create(version); } @@ -218,7 +211,7 @@ public void createServiceVersion(ServiceVersionBean version) throws StorageExcep * @see io.apiman.manager.api.core.IStorage#updateApplication(io.apiman.manager.api.beans.apps.ApplicationBean) */ @Override - public void updateApplication(ApplicationBean application) throws StorageException, DoesNotExistException { + public void updateApplication(ApplicationBean application) throws StorageException { super.update(application); } @@ -226,8 +219,7 @@ public void updateApplication(ApplicationBean application) throws StorageExcepti * @see io.apiman.manager.api.core.IStorage#updateApplicationVersion(io.apiman.manager.api.beans.apps.ApplicationVersionBean) */ @Override - public void updateApplicationVersion(ApplicationVersionBean version) throws StorageException, - DoesNotExistException { + public void updateApplicationVersion(ApplicationVersionBean version) throws StorageException { super.update(version); } @@ -235,7 +227,7 @@ public void updateApplicationVersion(ApplicationVersionBean version) throws Stor * @see io.apiman.manager.api.core.IStorage#updateContract(io.apiman.manager.api.beans.contracts.ContractBean) */ @Override - public void updateContract(ContractBean contract) throws StorageException, DoesNotExistException { + public void updateContract(ContractBean contract) throws StorageException { super.update(contract); } @@ -243,7 +235,7 @@ public void updateContract(ContractBean contract) throws StorageException, DoesN * @see io.apiman.manager.api.core.IStorage#updateGateway(io.apiman.manager.api.beans.gateways.GatewayBean) */ @Override - public void updateGateway(GatewayBean gateway) throws StorageException, DoesNotExistException { + public void updateGateway(GatewayBean gateway) throws StorageException { super.update(gateway); } @@ -251,8 +243,7 @@ public void updateGateway(GatewayBean gateway) throws StorageException, DoesNotE * @see io.apiman.manager.api.core.IStorage#updateOrganization(io.apiman.manager.api.beans.orgs.OrganizationBean) */ @Override - public void updateOrganization(OrganizationBean organization) throws StorageException, - DoesNotExistException { + public void updateOrganization(OrganizationBean organization) throws StorageException { super.update(organization); } @@ -260,7 +251,7 @@ public void updateOrganization(OrganizationBean organization) throws StorageExce * @see io.apiman.manager.api.core.IStorage#updatePlan(io.apiman.manager.api.beans.plans.PlanBean) */ @Override - public void updatePlan(PlanBean plan) throws StorageException, DoesNotExistException { + public void updatePlan(PlanBean plan) throws StorageException { super.update(plan); } @@ -268,7 +259,7 @@ public void updatePlan(PlanBean plan) throws StorageException, DoesNotExistExcep * @see io.apiman.manager.api.core.IStorage#updatePlanVersion(io.apiman.manager.api.beans.plans.PlanVersionBean) */ @Override - public void updatePlanVersion(PlanVersionBean version) throws StorageException, DoesNotExistException { + public void updatePlanVersion(PlanVersionBean version) throws StorageException { super.update(version); } @@ -276,7 +267,7 @@ public void updatePlanVersion(PlanVersionBean version) throws StorageException, * @see io.apiman.manager.api.core.IStorage#updatePolicy(io.apiman.manager.api.beans.policies.PolicyBean) */ @Override - public void updatePolicy(PolicyBean policy) throws StorageException, DoesNotExistException { + public void updatePolicy(PolicyBean policy) throws StorageException { super.update(policy); } @@ -284,8 +275,7 @@ public void updatePolicy(PolicyBean policy) throws StorageException, DoesNotExis * @see io.apiman.manager.api.core.IStorage#updatePolicyDefinition(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) */ @Override - public void updatePolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException, - DoesNotExistException { + public void updatePolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException { super.update(policyDef); } @@ -293,7 +283,7 @@ public void updatePolicyDefinition(PolicyDefinitionBean policyDef) throws Storag * @see io.apiman.manager.api.core.IStorage#updateRole(io.apiman.manager.api.beans.idm.RoleBean) */ @Override - public void updateRole(RoleBean role) throws StorageException, DoesNotExistException { + public void updateRole(RoleBean role) throws StorageException { super.update(role); } @@ -301,7 +291,7 @@ public void updateRole(RoleBean role) throws StorageException, DoesNotExistExcep * @see io.apiman.manager.api.core.IStorage#updateService(io.apiman.manager.api.beans.services.ServiceBean) */ @Override - public void updateService(ServiceBean service) throws StorageException, DoesNotExistException { + public void updateService(ServiceBean service) throws StorageException { super.update(service); } @@ -309,8 +299,7 @@ public void updateService(ServiceBean service) throws StorageException, DoesNotE * @see io.apiman.manager.api.core.IStorage#updateServiceVersion(io.apiman.manager.api.beans.services.ServiceVersionBean) */ @Override - public void updateServiceVersion(ServiceVersionBean version) throws StorageException, - DoesNotExistException { + public void updateServiceVersion(ServiceVersionBean version) throws StorageException { super.update(version); } @@ -319,8 +308,7 @@ public void updateServiceVersion(ServiceVersionBean version) throws StorageExcep * @see io.apiman.manager.api.core.IStorage#deleteOrganization(io.apiman.manager.api.beans.orgs.OrganizationBean) */ @Override - public void deleteOrganization(OrganizationBean organization) throws StorageException, - DoesNotExistException { + public void deleteOrganization(OrganizationBean organization) throws StorageException { super.delete(organization); } @@ -328,7 +316,7 @@ public void deleteOrganization(OrganizationBean organization) throws StorageExce * @see io.apiman.manager.api.core.IStorage#deleteApplication(io.apiman.manager.api.beans.apps.ApplicationBean) */ @Override - public void deleteApplication(ApplicationBean application) throws StorageException, DoesNotExistException { + public void deleteApplication(ApplicationBean application) throws StorageException { super.delete(application); } @@ -336,8 +324,7 @@ public void deleteApplication(ApplicationBean application) throws StorageExcepti * @see io.apiman.manager.api.core.IStorage#deleteApplicationVersion(io.apiman.manager.api.beans.apps.ApplicationVersionBean) */ @Override - public void deleteApplicationVersion(ApplicationVersionBean version) throws StorageException, - DoesNotExistException { + public void deleteApplicationVersion(ApplicationVersionBean version) throws StorageException { super.delete(version); } @@ -345,7 +332,7 @@ public void deleteApplicationVersion(ApplicationVersionBean version) throws Stor * @see io.apiman.manager.api.core.IStorage#deleteContract(io.apiman.manager.api.beans.contracts.ContractBean) */ @Override - public void deleteContract(ContractBean contract) throws StorageException, DoesNotExistException { + public void deleteContract(ContractBean contract) throws StorageException { super.delete(contract); } @@ -353,7 +340,7 @@ public void deleteContract(ContractBean contract) throws StorageException, DoesN * @see io.apiman.manager.api.core.IStorage#deleteService(io.apiman.manager.api.beans.services.ServiceBean) */ @Override - public void deleteService(ServiceBean service) throws StorageException, DoesNotExistException { + public void deleteService(ServiceBean service) throws StorageException { super.delete(service); } @@ -361,8 +348,7 @@ public void deleteService(ServiceBean service) throws StorageException, DoesNotE * @see io.apiman.manager.api.core.IStorage#deleteServiceVersion(io.apiman.manager.api.beans.services.ServiceVersionBean) */ @Override - public void deleteServiceVersion(ServiceVersionBean version) throws StorageException, - DoesNotExistException { + public void deleteServiceVersion(ServiceVersionBean version) throws StorageException { super.delete(version); } @@ -370,7 +356,7 @@ public void deleteServiceVersion(ServiceVersionBean version) throws StorageExcep * @see io.apiman.manager.api.core.IStorage#deletePlan(io.apiman.manager.api.beans.plans.PlanBean) */ @Override - public void deletePlan(PlanBean plan) throws StorageException, DoesNotExistException { + public void deletePlan(PlanBean plan) throws StorageException { super.delete(plan); } @@ -378,7 +364,7 @@ public void deletePlan(PlanBean plan) throws StorageException, DoesNotExistExcep * @see io.apiman.manager.api.core.IStorage#deletePlanVersion(io.apiman.manager.api.beans.plans.PlanVersionBean) */ @Override - public void deletePlanVersion(PlanVersionBean version) throws StorageException, DoesNotExistException { + public void deletePlanVersion(PlanVersionBean version) throws StorageException { super.delete(version); } @@ -386,7 +372,7 @@ public void deletePlanVersion(PlanVersionBean version) throws StorageException, * @see io.apiman.manager.api.core.IStorage#deletePolicy(io.apiman.manager.api.beans.policies.PolicyBean) */ @Override - public void deletePolicy(PolicyBean policy) throws StorageException, DoesNotExistException { + public void deletePolicy(PolicyBean policy) throws StorageException { super.delete(policy); } @@ -394,7 +380,7 @@ public void deletePolicy(PolicyBean policy) throws StorageException, DoesNotExis * @see io.apiman.manager.api.core.IStorage#deleteGateway(io.apiman.manager.api.beans.gateways.GatewayBean) */ @Override - public void deleteGateway(GatewayBean gateway) throws StorageException, DoesNotExistException { + public void deleteGateway(GatewayBean gateway) throws StorageException { super.delete(gateway); } @@ -402,8 +388,7 @@ public void deleteGateway(GatewayBean gateway) throws StorageException, DoesNotE * @see io.apiman.manager.api.core.IStorage#deletePolicyDefinition(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) */ @Override - public void deletePolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException, - DoesNotExistException { + public void deletePolicyDefinition(PolicyDefinitionBean policyDef) throws StorageException { super.delete(policyDef); } @@ -411,7 +396,7 @@ public void deletePolicyDefinition(PolicyDefinitionBean policyDef) throws Storag * @see io.apiman.manager.api.core.IStorage#deleteRole(io.apiman.manager.api.beans.idm.RoleBean) */ @Override - public void deleteRole(RoleBean role) throws StorageException, DoesNotExistException { + public void deleteRole(RoleBean role) throws StorageException { super.delete(role); } @@ -420,7 +405,7 @@ public void deleteRole(RoleBean role) throws StorageException, DoesNotExistExcep * @see io.apiman.manager.api.core.IStorage#getOrganization(java.lang.String) */ @Override - public OrganizationBean getOrganization(String id) throws StorageException, DoesNotExistException { + public OrganizationBean getOrganization(String id) throws StorageException { return super.get(id, OrganizationBean.class); } @@ -428,8 +413,7 @@ public OrganizationBean getOrganization(String id) throws StorageException, Does * @see io.apiman.manager.api.core.IStorage#getApplication(java.lang.String, java.lang.String) */ @Override - public ApplicationBean getApplication(String organizationId, String id) throws StorageException, - DoesNotExistException { + public ApplicationBean getApplication(String organizationId, String id) throws StorageException { return super.get(organizationId, id, ApplicationBean.class); } @@ -437,7 +421,7 @@ public ApplicationBean getApplication(String organizationId, String id) throws S * @see io.apiman.manager.api.core.IStorage#getContract(java.lang.Long) */ @Override - public ContractBean getContract(Long id) throws StorageException, DoesNotExistException { + public ContractBean getContract(Long id) throws StorageException { return super.get(id, ContractBean.class); } @@ -445,8 +429,7 @@ public ContractBean getContract(Long id) throws StorageException, DoesNotExistEx * @see io.apiman.manager.api.core.IStorage#getService(java.lang.String, java.lang.String) */ @Override - public ServiceBean getService(String organizationId, String id) throws StorageException, - DoesNotExistException { + public ServiceBean getService(String organizationId, String id) throws StorageException { return super.get(organizationId, id, ServiceBean.class); } @@ -454,7 +437,7 @@ public ServiceBean getService(String organizationId, String id) throws StorageEx * @see io.apiman.manager.api.core.IStorage#getPlan(java.lang.String, java.lang.String) */ @Override - public PlanBean getPlan(String organizationId, String id) throws StorageException, DoesNotExistException { + public PlanBean getPlan(String organizationId, String id) throws StorageException { return super.get(organizationId, id, PlanBean.class); } @@ -462,7 +445,7 @@ public PlanBean getPlan(String organizationId, String id) throws StorageExceptio * @see io.apiman.manager.api.core.IStorage#getPolicy(java.lang.Long) */ @Override - public PolicyBean getPolicy(Long id) throws StorageException, DoesNotExistException { + public PolicyBean getPolicy(Long id) throws StorageException { return super.get(id, PolicyBean.class); } @@ -470,7 +453,7 @@ public PolicyBean getPolicy(Long id) throws StorageException, DoesNotExistExcept * @see io.apiman.manager.api.core.IStorage#getGateway(java.lang.String) */ @Override - public GatewayBean getGateway(String id) throws StorageException, DoesNotExistException { + public GatewayBean getGateway(String id) throws StorageException { return super.get(id, GatewayBean.class); } @@ -478,7 +461,7 @@ public GatewayBean getGateway(String id) throws StorageException, DoesNotExistEx * @see io.apiman.manager.api.core.IStorage#getPolicyDefinition(java.lang.String) */ @Override - public PolicyDefinitionBean getPolicyDefinition(String id) throws StorageException, DoesNotExistException { + public PolicyDefinitionBean getPolicyDefinition(String id) throws StorageException { return super.get(id, PolicyDefinitionBean.class); } @@ -486,7 +469,7 @@ public PolicyDefinitionBean getPolicyDefinition(String id) throws StorageExcepti * @see io.apiman.manager.api.core.IStorage#getRole(java.lang.String) */ @Override - public RoleBean getRole(String id) throws StorageException, DoesNotExistException { + public RoleBean getRole(String id) throws StorageException { return super.get(id, RoleBean.class); } diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/DtApiApplication.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ApiManagerApplication.java similarity index 87% rename from manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/DtApiApplication.java rename to manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ApiManagerApplication.java index 645c5e3476..87582f4342 100644 --- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/DtApiApplication.java +++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/ApiManagerApplication.java @@ -21,11 +21,11 @@ /** - * The jax-rs application for the APIMan DT API. + * The jax-rs application for the API Manager rest api. * * @author eric.wittmann@redhat.com */ @ApplicationPath("/") -public class DtApiApplication extends Application { +public class ApiManagerApplication extends Application { } diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/CurrentUserResourceImpl.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/CurrentUserResourceImpl.java index b046ada2b3..8e0929beba 100644 --- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/CurrentUserResourceImpl.java +++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/CurrentUserResourceImpl.java @@ -25,8 +25,6 @@ import io.apiman.manager.api.beans.summary.ServiceSummaryBean; import io.apiman.manager.api.core.IIdmStorage; import io.apiman.manager.api.core.IStorageQuery; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import io.apiman.manager.api.rest.contract.ICurrentUserResource; import io.apiman.manager.api.rest.contract.exceptions.SystemErrorException; @@ -70,29 +68,26 @@ public CurrentUserBean getInfo() { try { CurrentUserBean rval = new CurrentUserBean(); UserBean user = idmStorage.getUser(userId); - rval.initFromUser(user); - Set permissions = idmStorage.getPermissions(userId); - rval.setPermissions(permissions); - rval.setAdmin(securityContext.isAdmin()); - return rval; - } catch (DoesNotExistException e) { - UserBean user = new UserBean(); - user.setUsername(userId); - user.setFullName(userId); - user.setEmail(userId + "@example.org"); //$NON-NLS-1$ - user.setJoinedOn(new Date()); - try { - idmStorage.createUser(user); - } catch (AlreadyExistsException e1) { - throw new SystemErrorException(e); - } catch (StorageException e1) { - throw new SystemErrorException(e); + if (user == null) { + user = new UserBean(); + user.setUsername(userId); + user.setFullName(userId); + user.setEmail(userId + "@example.org"); //$NON-NLS-1$ + user.setJoinedOn(new Date()); + try { + idmStorage.createUser(user); + } catch (StorageException e1) { + throw new SystemErrorException(e1); + } + rval.initFromUser(user); + rval.setAdmin(securityContext.isAdmin()); + rval.setPermissions(new HashSet()); + } else { + rval.initFromUser(user); + Set permissions = idmStorage.getPermissions(userId); + rval.setPermissions(permissions); + rval.setAdmin(securityContext.isAdmin()); } - - CurrentUserBean rval = new CurrentUserBean(); - rval.initFromUser(user); - rval.setAdmin(securityContext.isAdmin()); - rval.setPermissions(new HashSet()); return rval; } catch (StorageException e) { throw new SystemErrorException(e); @@ -106,6 +101,9 @@ public CurrentUserBean getInfo() { public void updateInfo(UserBean info) { try { UserBean user = idmStorage.getUser(securityContext.getCurrentUser()); + if (user == null) { + throw new StorageException("User not found: " + securityContext.getCurrentUser()); //$NON-NLS-1$ + } if (info.getEmail() != null) { user.setEmail(info.getEmail()); } diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/GatewayResourceImpl.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/GatewayResourceImpl.java index a6897c088d..296e8784ff 100644 --- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/GatewayResourceImpl.java +++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/GatewayResourceImpl.java @@ -21,10 +21,9 @@ import io.apiman.manager.api.beans.summary.GatewaySummaryBean; import io.apiman.manager.api.core.IStorage; import io.apiman.manager.api.core.IStorageQuery; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import io.apiman.manager.api.rest.contract.IGatewayResource; +import io.apiman.manager.api.rest.contract.exceptions.AbstractRestException; import io.apiman.manager.api.rest.contract.exceptions.GatewayAlreadyExistsException; import io.apiman.manager.api.rest.contract.exceptions.GatewayNotFoundException; import io.apiman.manager.api.rest.contract.exceptions.NotAuthorizedException; @@ -85,14 +84,17 @@ public GatewayBean create(GatewayBean bean) throws GatewayAlreadyExistsException bean.setModifiedOn(now); try { storage.beginTx(); + if (storage.getGateway(bean.getId()) != null) { + throw ExceptionFactory.gatewayAlreadyExistsException(bean.getName()); + } // Store/persist the new gateway storage.createGateway(bean); storage.commitTx(); return bean; - } catch (AlreadyExistsException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.gatewayAlreadyExistsException(bean.getName()); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -106,15 +108,18 @@ public GatewayBean get(String gatewayId) throws GatewayNotFoundException, NotAut try { storage.beginTx(); GatewayBean bean = storage.getGateway(gatewayId); + if (bean == null) { + throw ExceptionFactory.gatewayNotFoundException(gatewayId); + } if (!securityContext.isAdmin()) { bean.setConfiguration(null); } storage.commitTx(); return bean; - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.gatewayNotFoundException(gatewayId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -134,6 +139,9 @@ public void update(String gatewayId, GatewayBean bean) bean.setId(gatewayId); GatewayBean gbean = storage.getGateway(gatewayId); + if (gbean == null) { + throw ExceptionFactory.gatewayNotFoundException(gatewayId); + } gbean.setModifiedBy(securityContext.getCurrentUser()); gbean.setModifiedOn(now); if (bean.getName() != null) @@ -146,10 +154,10 @@ public void update(String gatewayId, GatewayBean bean) gbean.setConfiguration(bean.getConfiguration()); storage.updateGateway(gbean); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.gatewayNotFoundException(gatewayId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -166,12 +174,15 @@ public void delete(String gatewayId) throws GatewayNotFoundException, try { storage.beginTx(); GatewayBean gbean = storage.getGateway(gatewayId); + if (gbean == null) { + throw ExceptionFactory.gatewayNotFoundException(gatewayId); + } storage.deleteGateway(gbean); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.gatewayNotFoundException(gatewayId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java index 1c9a36cfa1..1a0340ac12 100644 --- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java +++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java @@ -69,9 +69,6 @@ import io.apiman.manager.api.core.IServiceValidator; import io.apiman.manager.api.core.IStorage; import io.apiman.manager.api.core.IStorageQuery; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.ConstraintViolationException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import io.apiman.manager.api.core.util.PolicyTemplateUtil; import io.apiman.manager.api.gateway.IGatewayLink; @@ -174,6 +171,9 @@ public OrganizationBean create(OrganizationBean bean) throws OrganizationAlready try { // Store/persist the new organization storage.beginTx(); + if (storage.getOrganization(bean.getId()) != null) { + throw ExceptionFactory.organizationAlreadyExistsException(bean.getName()); + } storage.createOrganization(bean); storage.createAuditEntry(AuditUtils.organizationCreated(bean, securityContext)); storage.commitTx(); @@ -187,13 +187,10 @@ public OrganizationBean create(OrganizationBean bean) throws OrganizationAlready idmStorage.createMembership(membership); } return bean; - } catch (AlreadyExistsException e) { - storage.rollbackTx(); - throw ExceptionFactory.organizationAlreadyExistsException(bean.getName()); - } catch (ConstraintViolationException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.organizationAlreadyExistsException(bean.getName()); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -207,12 +204,15 @@ public OrganizationBean get(String organizationId) throws OrganizationNotFoundEx try { storage.beginTx(); OrganizationBean organizationBean = storage.getOrganization(organizationId); + if (organizationBean == null) { + throw ExceptionFactory.organizationNotFoundException(organizationId); + } storage.commitTx(); return organizationBean; - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.organizationNotFoundException(organizationId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -230,6 +230,9 @@ public void update(String organizationId, OrganizationBean bean) bean.setId(organizationId); storage.beginTx(); OrganizationBean organization = storage.getOrganization(bean.getId()); + if (organization == null) { + throw ExceptionFactory.organizationNotFoundException(organizationId); + } EntityUpdatedData auditData = new EntityUpdatedData(); if (AuditUtils.valueChanged(organization.getDescription(), bean.getDescription())) { @@ -239,10 +242,10 @@ public void update(String organizationId, OrganizationBean bean) storage.updateOrganization(organization); storage.createAuditEntry(AuditUtils.organizationUpdated(organization, auditData, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.organizationNotFoundException(organizationId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -267,7 +270,10 @@ public SearchResultsBean activity(String organizationId, int pag paging.setPageSize(pageSize); rval = query.auditEntity(organizationId, null, null, null, paging); return rval; - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { throw new SystemErrorException(e); } } @@ -291,18 +297,23 @@ public ApplicationBean createApp(String organizationId, ApplicationBean bean) // Store/persist the new application storage.beginTx(); OrganizationBean org = storage.getOrganization(organizationId); + if (org == null) { + throw ExceptionFactory.organizationNotFoundException(organizationId); + } newApp.setOrganization(org); + + if (storage.getApplication(org.getId(), newApp.getId()) != null) { + throw ExceptionFactory.organizationAlreadyExistsException(bean.getName()); + } + storage.createApplication(newApp); storage.createAuditEntry(AuditUtils.applicationCreated(newApp, securityContext)); storage.commitTx(); return newApp; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.organizationNotFoundException(organizationId); - } catch (AlreadyExistsException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.applicationAlreadyExistsException(newApp.getName()); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -317,12 +328,15 @@ public ApplicationBean getApp(String organizationId, String applicationId) try { storage.beginTx(); ApplicationBean applicationBean = storage.getApplication(organizationId, applicationId); + if (applicationBean == null) { + throw ExceptionFactory.applicationNotFoundException(applicationId); + } storage.commitTx(); return applicationBean; - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.applicationNotFoundException(applicationId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -347,7 +361,10 @@ public SearchResultsBean getAppActivity(String organizationId, S paging.setPageSize(pageSize); rval = query.auditEntity(organizationId, applicationId, null, ApplicationBean.class, paging); return rval; - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { throw new SystemErrorException(e); } } @@ -378,6 +395,9 @@ public void updateApp(String organizationId, String applicationId, ApplicationBe try { storage.beginTx(); ApplicationBean app = storage.getApplication(organizationId, applicationId); + if (app == null) { + throw ExceptionFactory.applicationNotFoundException(applicationId); + } EntityUpdatedData auditData = new EntityUpdatedData(); if (AuditUtils.valueChanged(app.getDescription(), bean.getDescription())) { auditData.addChange("description", app.getDescription(), bean.getDescription()); //$NON-NLS-1$ @@ -386,10 +406,10 @@ public void updateApp(String organizationId, String applicationId, ApplicationBe storage.updateApplication(app); storage.createAuditEntry(AuditUtils.applicationUpdated(app, auditData, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.applicationNotFoundException(applicationId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -407,6 +427,9 @@ public ApplicationVersionBean createAppVersion(String organizationId, String app try { storage.beginTx(); ApplicationBean application = storage.getApplication(organizationId, applicationId); + if (application == null) { + throw ExceptionFactory.applicationNotFoundException(applicationId); + } ApplicationVersionBean newVersion = new ApplicationVersionBean(); newVersion.setApplication(application); @@ -422,12 +445,9 @@ public ApplicationVersionBean createAppVersion(String organizationId, String app storage.createAuditEntry(AuditUtils.applicationVersionCreated(newVersion, securityContext)); storage.commitTx(); return newVersion; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.applicationNotFoundException(applicationId); - } catch (StorageException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw new SystemErrorException(e); + throw e; } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); @@ -447,13 +467,10 @@ public ApplicationVersionBean getAppVersion(String organizationId, String applic throw ExceptionFactory.applicationVersionNotFoundException(applicationId, version); storage.commitTx(); return applicationVersion; - } catch (ApplicationVersionNotFoundException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); throw e; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.applicationNotFoundException(applicationId); - } catch (StorageException e) { + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -479,7 +496,10 @@ public SearchResultsBean getAppVersionActivity(String organizati paging.setPageSize(pageSize); rval = query.auditEntity(organizationId, applicationId, version, ApplicationBean.class, paging); return rval; - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { throw new SystemErrorException(e); } } @@ -515,12 +535,9 @@ public void updateAppVersion(String organizationId, String applicationId, String storage.updateApplicationVersion(avb); storage.createAuditEntry(AuditUtils.applicationVersionUpdated(avb, data, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.applicationNotFoundException(applicationId); - } catch (StorageException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw new SystemErrorException(e); + throw e; } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); @@ -538,8 +555,6 @@ public List listAppVersions(String organizationId try { return query.getApplicationVersions(organizationId, applicationId); - } catch (DoesNotExistException e) { - throw ExceptionFactory.applicationNotFoundException(applicationId); } catch (StorageException e) { throw new SystemErrorException(e); } @@ -621,9 +636,6 @@ public ContractBean createContract(String organizationId, String applicationId, } catch (AbstractRestException e) { storage.rollbackTx(); throw e; - } catch (StorageException e) { - storage.rollbackTx(); - throw new SystemErrorException(e); } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); @@ -651,10 +663,10 @@ public ContractBean getContract(String organizationId, String applicationId, Str } return contract; - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.contractNotFoundException(contractId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -677,10 +689,10 @@ public void deleteContract(String organizationId, String applicationId, String v storage.createAuditEntry(AuditUtils.contractBrokenFromApp(contract, securityContext)); storage.createAuditEntry(AuditUtils.contractBrokenToService(contract, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.contractNotFoundException(contractId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -708,7 +720,10 @@ public List getApplicationVersionContracts(String organizat } return contracts; - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { throw new SystemErrorException(e); } } @@ -827,6 +842,9 @@ public void updateAppPolicy(String organizationId, String applicationId, String try { storage.beginTx(); PolicyBean policy = this.storage.getPolicy(policyId); + if (policy == null) { + throw ExceptionFactory.policyNotFoundException(policyId); + } if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) { policy.setConfiguration(bean.getConfiguration()); // TODO figure out what changed an include that in the audit entry @@ -836,10 +854,10 @@ public void updateAppPolicy(String organizationId, String applicationId, String storage.updatePolicy(policy); storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Application, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyNotFoundException(policyId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -861,13 +879,16 @@ public void deleteAppPolicy(String organizationId, String applicationId, String try { storage.beginTx(); PolicyBean policy = this.storage.getPolicy(policyId); + if (policy == null) { + throw ExceptionFactory.policyNotFoundException(policyId); + } storage.deletePolicy(policy); storage.createAuditEntry(AuditUtils.policyRemoved(policy, PolicyType.Application, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyNotFoundException(policyId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -913,7 +934,10 @@ public void reorderApplicationPolicies(String organizationId, String application } storage.createAuditEntry(AuditUtils.policiesReordered(avb, PolicyType.Application, securityContext)); storage.commitTx(); - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -937,19 +961,22 @@ public ServiceBean createService(String organizationId, ServiceBean bean) try { storage.beginTx(); OrganizationBean orgBean = storage.getOrganization(organizationId); + if (orgBean == null) { + throw ExceptionFactory.organizationNotFoundException(organizationId); + } + if (storage.getService(orgBean.getId(), newService.getId()) != null) { + throw ExceptionFactory.serviceAlreadyExistsException(bean.getName()); + } newService.setOrganization(orgBean); // Store/persist the new service storage.createService(newService); storage.createAuditEntry(AuditUtils.serviceCreated(newService, securityContext)); storage.commitTx(); return newService; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.organizationNotFoundException(organizationId); - } catch (AlreadyExistsException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.serviceAlreadyExistsException(bean.getName()); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -964,12 +991,15 @@ public ServiceBean getService(String organizationId, String serviceId) try { storage.beginTx(); ServiceBean bean = storage.getService(organizationId, serviceId); + if (bean == null) { + throw ExceptionFactory.serviceNotFoundException(serviceId); + } storage.commitTx(); return bean; - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.serviceNotFoundException(serviceId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1026,6 +1056,9 @@ public void updateService(String organizationId, String serviceId, ServiceBean b try { storage.beginTx(); ServiceBean service = storage.getService(organizationId, serviceId); + if (service == null) { + throw ExceptionFactory.serviceNotFoundException(serviceId); + } EntityUpdatedData auditData = new EntityUpdatedData(); if (AuditUtils.valueChanged(service.getDescription(), bean.getDescription())) { auditData.addChange("description", service.getDescription(), bean.getDescription()); //$NON-NLS-1$ @@ -1034,10 +1067,10 @@ public void updateService(String organizationId, String serviceId, ServiceBean b storage.updateService(service); storage.createAuditEntry(AuditUtils.serviceUpdated(service, auditData, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.serviceNotFoundException(serviceId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1056,6 +1089,9 @@ public ServiceVersionBean createServiceVersion(String organizationId, String ser storage.beginTx(); ServiceBean service = storage.getService(organizationId, serviceId); + if (service == null) { + throw ExceptionFactory.serviceNotFoundException(serviceId); + } ServiceVersionBean newVersion = new ServiceVersionBean(); newVersion.setCreatedBy(securityContext.getCurrentUser()); @@ -1105,12 +1141,9 @@ public ServiceVersionBean createServiceVersion(String organizationId, String ser storage.createAuditEntry(AuditUtils.serviceVersionCreated(newVersion, securityContext)); storage.commitTx(); return newVersion; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.serviceNotFoundException(serviceId); - } catch (StorageException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw new SystemErrorException(e); + throw e; } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); @@ -1135,13 +1168,10 @@ public ServiceVersionBean getServiceVersion(String organizationId, String servic serviceVersion.setGateways(null); } return serviceVersion; - } catch (ServiceVersionNotFoundException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); throw e; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.serviceNotFoundException(serviceId); - } catch (StorageException e) { + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1255,12 +1285,9 @@ public void updateServiceVersion(String organizationId, String serviceId, String storage.updateServiceVersion(svb); storage.createAuditEntry(AuditUtils.serviceVersionUpdated(svb, data, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.serviceNotFoundException(serviceId); - } catch (StorageException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw new SystemErrorException(e); + throw e; } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); @@ -1278,8 +1305,6 @@ public List listServiceVersions(String organizationId try { return query.getServiceVersions(organizationId, serviceId); - } catch (DoesNotExistException e) { - throw ExceptionFactory.serviceNotFoundException(serviceId); } catch (StorageException e) { throw new SystemErrorException(e); } @@ -1296,8 +1321,6 @@ public List getServiceVersionPlans(String organizationId try { return query.getServiceVersionPlans(organizationId, serviceId, version); - } catch (DoesNotExistException e) { - throw ExceptionFactory.serviceNotFoundException(serviceId); } catch (StorageException e) { throw new SystemErrorException(e); } @@ -1358,6 +1381,9 @@ public void updateServicePolicy(String organizationId, String serviceId, String try { storage.beginTx(); PolicyBean policy = storage.getPolicy(policyId); + if (policy == null) { + throw ExceptionFactory.policyNotFoundException(policyId); + } // TODO capture specific change values when auditing policy updates if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) { policy.setConfiguration(bean.getConfiguration()); @@ -1367,10 +1393,10 @@ public void updateServicePolicy(String organizationId, String serviceId, String storage.updatePolicy(policy); storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Service, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyNotFoundException(policyId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1392,13 +1418,16 @@ public void deleteServicePolicy(String organizationId, String serviceId, String try { storage.beginTx(); PolicyBean policy = this.storage.getPolicy(policyId); + if (policy == null) { + throw ExceptionFactory.policyNotFoundException(policyId); + } storage.deletePolicy(policy); storage.createAuditEntry(AuditUtils.policyRemoved(policy, PolicyType.Service, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyNotFoundException(policyId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1444,7 +1473,10 @@ public void reorderServicePolicies(String organizationId, String serviceId, Stri } storage.createAuditEntry(AuditUtils.policiesReordered(svb, PolicyType.Service, securityContext)); storage.commitTx(); - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1537,18 +1569,21 @@ public PlanBean createPlan(String organizationId, PlanBean bean) // Store/persist the new plan storage.beginTx(); OrganizationBean orgBean = storage.getOrganization(organizationId); + if (orgBean == null) { + throw ExceptionFactory.organizationNotFoundException(organizationId); + } + if (storage.getPlan(orgBean.getId(), newPlan.getId()) != null) { + throw ExceptionFactory.planAlreadyExistsException(newPlan.getName()); + } newPlan.setOrganization(orgBean); storage.createPlan(newPlan); storage.createAuditEntry(AuditUtils.planCreated(newPlan, securityContext)); storage.commitTx(); return newPlan; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.organizationNotFoundException(organizationId); - } catch (AlreadyExistsException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.planAlreadyExistsException(newPlan.getName()); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1563,12 +1598,15 @@ public PlanBean getPlan(String organizationId, String planId) try { storage.beginTx(); PlanBean bean = storage.getPlan(organizationId, planId); + if (bean == null) { + throw ExceptionFactory.planNotFoundException(planId); + } storage.commitTx(); return bean; - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.planNotFoundException(planId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1625,18 +1663,20 @@ public void updatePlan(String organizationId, String planId, PlanBean bean) try { storage.beginTx(); PlanBean plan = storage.getPlan(organizationId, planId); + if (plan == null) { + throw ExceptionFactory.planNotFoundException(planId); + } if (AuditUtils.valueChanged(plan.getDescription(), bean.getDescription())) { auditData.addChange("description", plan.getDescription(), bean.getDescription()); //$NON-NLS-1$ plan.setDescription(bean.getDescription()); - } - // Nothing to update (yet?) + } storage.updatePlan(plan); storage.createAuditEntry(AuditUtils.planUpdated(plan, auditData, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.planNotFoundException(planId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1653,7 +1693,10 @@ public PlanVersionBean createPlanVersion(String organizationId, String planId, P try { storage.beginTx(); PlanBean plan = storage.getPlan(organizationId, planId); - + if (plan == null) { + throw ExceptionFactory.planNotFoundException(planId); + } + PlanVersionBean newVersion = new PlanVersionBean(); newVersion.setCreatedBy(securityContext.getCurrentUser()); newVersion.setCreatedOn(new Date()); @@ -1666,10 +1709,10 @@ public PlanVersionBean createPlanVersion(String organizationId, String planId, P storage.createAuditEntry(AuditUtils.planVersionCreated(newVersion, securityContext)); storage.commitTx(); return newVersion; - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.planNotFoundException(planId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1689,13 +1732,10 @@ public PlanVersionBean getPlanVersion(String organizationId, String planId, Stri } storage.commitTx(); return planVersion; - } catch (PlanVersionNotFoundException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); throw e; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.planNotFoundException(planId); - } catch (StorageException e) { + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1734,18 +1774,20 @@ public void updatePlanVersion(String organizationId, String planId, String versi throws PlanVersionNotFoundException, NotAuthorizedException { if (!securityContext.hasPermission(PermissionType.planEdit, organizationId)) throw ExceptionFactory.notAuthorizedException(); - // TODO throw error if version is not in the right state PlanVersionBean pvb = getPlanVersion(organizationId, planId, version); + if (pvb.getStatus() == PlanStatus.Locked) { + throw ExceptionFactory.invalidPlanStatusException(); + } EntityUpdatedData data = new EntityUpdatedData(); try { storage.beginTx(); storage.updatePlanVersion(pvb); storage.createAuditEntry(AuditUtils.planVersionUpdated(pvb, data, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.planNotFoundException(planId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1762,8 +1804,6 @@ public List listPlanVersions(String organizationId, Stri try { return query.getPlanVersions(organizationId, planId); - } catch (DoesNotExistException e) { - throw ExceptionFactory.planNotFoundException(planId); } catch (StorageException e) { throw new SystemErrorException(e); } @@ -1825,6 +1865,9 @@ public void updatePlanPolicy(String organizationId, String planId, String versio try { storage.beginTx(); PolicyBean policy = storage.getPolicy(policyId); + if (policy == null) { + throw ExceptionFactory.policyNotFoundException(policyId); + } if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) { policy.setConfiguration(bean.getConfiguration()); // TODO figure out what changed an include that in the audit entry @@ -1834,10 +1877,10 @@ public void updatePlanPolicy(String organizationId, String planId, String versio storage.updatePolicy(policy); storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Plan, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyNotFoundException(policyId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1859,13 +1902,16 @@ public void deletePlanPolicy(String organizationId, String planId, String versio try { storage.beginTx(); PolicyBean policy = this.storage.getPolicy(policyId); + if (policy == null) { + throw ExceptionFactory.policyNotFoundException(policyId); + } storage.deletePolicy(policy); storage.createAuditEntry(AuditUtils.policyRemoved(policy, PolicyType.Plan, securityContext)); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyNotFoundException(policyId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1911,7 +1957,10 @@ public void reorderPlanPolicies(String organizationId, String planId, String ver } storage.createAuditEntry(AuditUtils.policiesReordered(pvb, PolicyType.Plan, securityContext)); storage.commitTx(); - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1938,12 +1987,15 @@ protected PolicyBean doCreatePolicy(String organizationId, String entityId, Stri try { storage.beginTx(); def = storage.getPolicyDefinition(bean.getDefinition().getId()); + if (def == null) { + ExceptionFactory.policyDefNotFoundException(bean.getDefinition().getId()); + } bean.setDefinition(def); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - ExceptionFactory.policyDefNotFoundException(bean.getDefinition().getId()); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -1974,6 +2026,9 @@ protected PolicyBean doCreatePolicy(String organizationId, String entityId, Stri PolicyTemplateUtil.generatePolicyDescription(bean); storage.commitTx(); return bean; + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); @@ -2004,8 +2059,6 @@ public void grant(String organizationId, GrantRolesBean bean) throws Organizatio idmStorage.createMembership(membership); auditData.addRole(roleId); } - } catch (AlreadyExistsException e) { - // Do nothing - re-granting is OK. } catch (StorageException e) { throw new SystemErrorException(e); } @@ -2013,7 +2066,10 @@ public void grant(String organizationId, GrantRolesBean bean) throws Organizatio storage.beginTx(); storage.createAuditEntry(AuditUtils.membershipGranted(organizationId, auditData, securityContext)); storage.commitTx(); - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -2039,8 +2095,6 @@ public void revoke(String organizationId, String roleId, String userId) idmStorage.deleteMembership(userId, roleId, organizationId); auditData.addRole(roleId); revoked = true; - } catch (DoesNotExistException e) { - // Do nothing - revoking something that doesn't exist is OK. } catch (StorageException e) { throw new SystemErrorException(e); } @@ -2050,7 +2104,10 @@ public void revoke(String organizationId, String roleId, String userId) storage.beginTx(); storage.createAuditEntry(AuditUtils.membershipRevoked(organizationId, auditData, securityContext)); storage.commitTx(); - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -2070,8 +2127,6 @@ public void revokeAll(String organizationId, String userId) throws OrganizationN try { idmStorage.deleteMemberships(userId, organizationId); - } catch (DoesNotExistException e) { - // Do nothing - revoking something that doesn't exist is OK. } catch (StorageException e) { throw new SystemErrorException(e); } @@ -2083,7 +2138,10 @@ public void revokeAll(String organizationId, String userId) throws OrganizationN storage.beginTx(); storage.createAuditEntry(AuditUtils.membershipRevoked(organizationId, auditData, securityContext)); storage.commitTx(); - } catch (StorageException e) { + } catch (AbstractRestException e) { + storage.rollbackTx(); + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -2144,6 +2202,9 @@ protected PolicyBean doGetPolicy(PolicyType type, String organizationId, String try { storage.beginTx(); PolicyBean policy = storage.getPolicy(policyId); + if (policy == null) { + throw ExceptionFactory.policyNotFoundException(policyId); + } storage.commitTx(); if (policy.getType() != type) { throw ExceptionFactory.policyNotFoundException(policyId); @@ -2159,12 +2220,9 @@ protected PolicyBean doGetPolicy(PolicyType type, String organizationId, String } PolicyTemplateUtil.generatePolicyDescription(policy); return policy; - } catch (DoesNotExistException e) { - storage.rollbackTx(); - throw ExceptionFactory.policyNotFoundException(policyId); - } catch (StorageException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw new SystemErrorException(e); + throw e; } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/PolicyDefinitionResourceImpl.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/PolicyDefinitionResourceImpl.java index b22ad794db..768d9a9753 100644 --- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/PolicyDefinitionResourceImpl.java +++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/PolicyDefinitionResourceImpl.java @@ -21,10 +21,9 @@ import io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean; import io.apiman.manager.api.core.IStorage; import io.apiman.manager.api.core.IStorageQuery; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import io.apiman.manager.api.rest.contract.IPolicyDefinitionResource; +import io.apiman.manager.api.rest.contract.exceptions.AbstractRestException; import io.apiman.manager.api.rest.contract.exceptions.NotAuthorizedException; import io.apiman.manager.api.rest.contract.exceptions.PolicyDefinitionAlreadyExistsException; import io.apiman.manager.api.rest.contract.exceptions.PolicyDefinitionNotFoundException; @@ -77,14 +76,17 @@ public PolicyDefinitionBean create(PolicyDefinitionBean bean) throws PolicyDefin bean.setId(BeanUtils.idFromName(bean.getName())); try { storage.beginTx(); + if (storage.getPolicyDefinition(bean.getId()) != null) { + throw ExceptionFactory.policyDefAlreadyExistsException(bean.getName()); + } // Store/persist the new policyDef storage.createPolicyDefinition(bean); storage.commitTx(); return bean; - } catch (AlreadyExistsException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyDefAlreadyExistsException(bean.getName()); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -98,12 +100,15 @@ public PolicyDefinitionBean get(String policyDefinitionId) throws PolicyDefiniti try { storage.beginTx(); PolicyDefinitionBean bean = storage.getPolicyDefinition(policyDefinitionId); + if (bean == null) { + throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId); + } storage.commitTx(); return bean; - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -121,6 +126,9 @@ public void update(String policyDefinitionId, PolicyDefinitionBean bean) storage.beginTx(); bean.setId(policyDefinitionId); PolicyDefinitionBean pdb = storage.getPolicyDefinition(policyDefinitionId); + if (pdb == null) { + throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId); + } if (bean.getName() != null) pdb.setName(bean.getName()); if (bean.getDescription() != null) @@ -129,10 +137,10 @@ public void update(String policyDefinitionId, PolicyDefinitionBean bean) pdb.setIcon(bean.getIcon()); storage.updatePolicyDefinition(pdb); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } @@ -149,12 +157,15 @@ public void delete(String policyDefinitionId) throws PolicyDefinitionNotFoundExc try { storage.beginTx(); PolicyDefinitionBean pdb = storage.getPolicyDefinition(policyDefinitionId); + if (pdb == null) { + throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId); + } storage.deletePolicyDefinition(pdb); storage.commitTx(); - } catch (DoesNotExistException e) { + } catch (AbstractRestException e) { storage.rollbackTx(); - throw ExceptionFactory.policyDefNotFoundException(policyDefinitionId); - } catch (StorageException e) { + throw e; + } catch (Exception e) { storage.rollbackTx(); throw new SystemErrorException(e); } diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/RoleResourceImpl.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/RoleResourceImpl.java index 486e0ac32a..17c7c7df18 100644 --- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/RoleResourceImpl.java +++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/RoleResourceImpl.java @@ -21,8 +21,6 @@ import io.apiman.manager.api.beans.search.SearchCriteriaBean; import io.apiman.manager.api.beans.search.SearchResultsBean; import io.apiman.manager.api.core.IIdmStorage; -import io.apiman.manager.api.core.exceptions.AlreadyExistsException; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import io.apiman.manager.api.rest.contract.IRoleResource; import io.apiman.manager.api.rest.contract.exceptions.InvalidSearchCriteriaException; @@ -71,10 +69,11 @@ public RoleBean create(RoleBean bean) throws RoleAlreadyExistsException, NotAuth bean.setCreatedBy(securityContext.getCurrentUser()); bean.setCreatedOn(new Date()); try { + if (idmStorage.getRole(bean.getId()) != null) { + throw ExceptionFactory.roleAlreadyExistsException(bean.getId()); + } idmStorage.createRole(bean); return bean; - } catch (AlreadyExistsException e) { - throw ExceptionFactory.roleAlreadyExistsException(bean.getId()); } catch (StorageException e) { throw new SystemErrorException(e); } @@ -86,9 +85,11 @@ public RoleBean create(RoleBean bean) throws RoleAlreadyExistsException, NotAuth @Override public RoleBean get(String roleId) throws RoleNotFoundException, NotAuthorizedException { try { - return idmStorage.getRole(roleId); - } catch (DoesNotExistException e) { - throw ExceptionFactory.roleNotFoundException(roleId); + RoleBean role = idmStorage.getRole(roleId); + if (role == null) { + throw ExceptionFactory.roleNotFoundException(roleId); + } + return role; } catch (StorageException e) { throw new SystemErrorException(e); } @@ -103,6 +104,9 @@ public void update(String roleId, RoleBean bean) throws RoleNotFoundException, N throw ExceptionFactory.notAuthorizedException(); try { RoleBean role = idmStorage.getRole(roleId); + if (role == null) { + throw ExceptionFactory.roleNotFoundException(roleId); + } if (bean.getDescription() != null) { role.setDescription(bean.getDescription()); } @@ -117,8 +121,6 @@ public void update(String roleId, RoleBean bean) throws RoleNotFoundException, N role.getPermissions().addAll(bean.getPermissions()); } idmStorage.updateRole(role); - } catch (DoesNotExistException e) { - throw ExceptionFactory.roleNotFoundException(roleId); } catch (StorageException e) { throw new SystemErrorException(e); } @@ -134,8 +136,6 @@ public void delete(String roleId) throws RoleNotFoundException, NotAuthorizedExc RoleBean bean = get(roleId); try { idmStorage.deleteRole(bean); - } catch (DoesNotExistException e) { - throw ExceptionFactory.roleNotFoundException(roleId); } catch (StorageException e) { throw new SystemErrorException(e); } diff --git a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/UserResourceImpl.java b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/UserResourceImpl.java index 04517d8ac5..cce37a9f18 100644 --- a/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/UserResourceImpl.java +++ b/manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/UserResourceImpl.java @@ -30,7 +30,6 @@ import io.apiman.manager.api.core.IIdmStorage; import io.apiman.manager.api.core.IStorage; import io.apiman.manager.api.core.IStorageQuery; -import io.apiman.manager.api.core.exceptions.DoesNotExistException; import io.apiman.manager.api.core.exceptions.StorageException; import io.apiman.manager.api.rest.contract.IUserResource; import io.apiman.manager.api.rest.contract.exceptions.InvalidSearchCriteriaException; @@ -77,9 +76,11 @@ public UserResourceImpl() { @Override public UserBean get(String userId) throws UserNotFoundException { try { - return idmStorage.getUser(userId); - } catch (DoesNotExistException e) { - throw ExceptionFactory.userNotFoundException(userId); + UserBean user = idmStorage.getUser(userId); + if (user == null) { + throw ExceptionFactory.userNotFoundException(userId); + } + return user; } catch (StorageException e) { throw new SystemErrorException(e); } @@ -94,6 +95,9 @@ public void update(String userId, UserBean user) throws UserNotFoundException, N throw ExceptionFactory.notAuthorizedException(); try { UserBean updatedUser = idmStorage.getUser(userId); + if (updatedUser == null) { + throw ExceptionFactory.userNotFoundException(userId); + } if (user.getEmail() != null) { updatedUser.setEmail(user.getEmail()); } @@ -101,8 +105,6 @@ public void update(String userId, UserBean user) throws UserNotFoundException, N updatedUser.setFullName(user.getFullName()); } idmStorage.updateUser(updatedUser); - } catch (DoesNotExistException e) { - throw ExceptionFactory.userNotFoundException(userId); } catch (StorageException e) { throw new SystemErrorException(e); } diff --git a/manager/test/api/src/main/java/io/apiman/manager/test/server/TestManagerApiApplication.java b/manager/test/api/src/main/java/io/apiman/manager/test/server/TestManagerApiApplication.java index bb1b2d2c5e..de06f3a9cf 100644 --- a/manager/test/api/src/main/java/io/apiman/manager/test/server/TestManagerApiApplication.java +++ b/manager/test/api/src/main/java/io/apiman/manager/test/server/TestManagerApiApplication.java @@ -17,7 +17,7 @@ import io.apiman.manager.api.rest.impl.ActionResourceImpl; import io.apiman.manager.api.rest.impl.CurrentUserResourceImpl; -import io.apiman.manager.api.rest.impl.DtApiApplication; +import io.apiman.manager.api.rest.impl.ApiManagerApplication; import io.apiman.manager.api.rest.impl.GatewayResourceImpl; import io.apiman.manager.api.rest.impl.OrganizationResourceImpl; import io.apiman.manager.api.rest.impl.PermissionsResourceImpl; @@ -36,7 +36,7 @@ * * @author eric.wittmann@redhat.com */ -public class TestManagerApiApplication extends DtApiApplication { +public class TestManagerApiApplication extends ApiManagerApplication { private Set singletons = new HashSet(); private Set> classes = new HashSet>();