Skip to content

Commit

Permalink
Throw KapuaException instead of Exception
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Mezzasalma <claudio.mezzasalma@eurotech.com>
  • Loading branch information
Claudio Mezzasalma committed Mar 19, 2020
1 parent dad78a8 commit d8a2962
Show file tree
Hide file tree
Showing 39 changed files with 376 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.kapua.app.api.resources.v1.resources;

import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.app.api.resources.v1.resources.model.CountResult;
import org.eclipse.kapua.app.api.resources.v1.resources.model.EntityId;
import org.eclipse.kapua.app.api.resources.v1.resources.model.ScopeId;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class AccessInfos extends AbstractKapuaResource {
* @param offset The result set offset.
* @param limit The result set limit.
* @return The {@link AccessInfoListResult} of all the {@link AccessInfo}s associated to the current selected scope.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@GET
Expand All @@ -68,7 +69,7 @@ public AccessInfoListResult simpleQuery(
@PathParam("scopeId") ScopeId scopeId,
@QueryParam("userId") EntityId userId,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws Exception {
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {

AccessInfoQuery query = accessInfoFactory.newQuery(scopeId);

Expand All @@ -90,7 +91,7 @@ public AccessInfoListResult simpleQuery(
* @param scopeId The {@link ScopeId} in which to search results.
* @param query The {@link AccessInfoQuery} to use to filter results.
* @return The {@link AccessInfoListResult} of all the result matching the given {@link AccessInfoQuery} parameter.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
Expand All @@ -99,7 +100,7 @@ public AccessInfoListResult simpleQuery(
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public AccessInfoListResult query(
@PathParam("scopeId") ScopeId scopeId,
AccessInfoQuery query) throws Exception {
AccessInfoQuery query) throws KapuaException {
query.setScopeId(scopeId);

return accessInfoService.query(query);
Expand All @@ -111,7 +112,7 @@ public AccessInfoListResult query(
* @param scopeId The {@link ScopeId} in which to count results.
* @param query The {@link AccessInfoQuery} to use to filter count results.
* @return The count of all the result matching the given {@link AccessInfoQuery} parameter.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
Expand All @@ -120,7 +121,7 @@ public AccessInfoListResult query(
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public CountResult count(
@PathParam("scopeId") ScopeId scopeId,
AccessInfoQuery query) throws Exception {
AccessInfoQuery query) throws KapuaException {
query.setScopeId(scopeId);

return new CountResult(accessInfoService.count(query));
Expand All @@ -133,15 +134,15 @@ public CountResult count(
* @param scopeId The {@link ScopeId} in which to create the {@link AccessInfo}.
* @param accessInfoCreator Provides the information for the new {@link AccessInfo} to be created.
* @return The newly created {@link AccessInfo} object.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response create(
@PathParam("scopeId") ScopeId scopeId, //
AccessInfoCreator accessInfoCreator) throws Exception {
AccessInfoCreator accessInfoCreator) throws KapuaException {
accessInfoCreator.setScopeId(scopeId);

return returnCreated(accessInfoService.create(accessInfoCreator));
Expand All @@ -153,15 +154,15 @@ public Response create(
* @param scopeId The {@link ScopeId} of the requested {@link AccessInfo}.
* @param accessInfoId The id of the requested {@link AccessInfo}.
* @return The requested {@link AccessInfo} object.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@GET
@Path("{accessInfoId}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public AccessInfo find(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId) throws Exception {
@PathParam("accessInfoId") EntityId accessInfoId) throws KapuaException {
AccessInfo accessInfo = accessInfoService.find(scopeId, accessInfoId);

if (accessInfo == null) {
Expand All @@ -177,14 +178,14 @@ public AccessInfo find(
* @param scopeId The {@link ScopeId} of the {@link AccessInfo} to be deleted.
* @param accessInfoId The id of the {@link AccessInfo} to be deleted.
* @return HTTP 200 if operation has completed successfully.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@DELETE
@Path("{accessInfoId}")
public Response deleteAccessInfo(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId) throws Exception {
@PathParam("accessInfoId") EntityId accessInfoId) throws KapuaException {
accessInfoService.delete(scopeId, accessInfoId);

return returnNoContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.kapua.app.api.resources.v1.resources;

import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.app.api.resources.v1.resources.model.CountResult;
import org.eclipse.kapua.app.api.resources.v1.resources.model.EntityId;
import org.eclipse.kapua.app.api.resources.v1.resources.model.ScopeId;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class AccessPermissions extends AbstractKapuaResource {
* @param offset The result set offset.
* @param limit The result set limit.
* @return The {@link AccessPermissionListResult} of all the {@link AccessPermission}s associated to the current selected scope.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@GET
Expand All @@ -68,7 +69,7 @@ public AccessPermissionListResult simpleQuery(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws Exception {
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
AccessPermissionQuery query = accessPermissionFactory.newQuery(scopeId);

query.setPredicate(query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfoId));
Expand All @@ -86,7 +87,7 @@ public AccessPermissionListResult simpleQuery(
* @param accessInfoId The {@link AccessInfo} id in which to search results.
* @param query The {@link AccessPermissionQuery} to use to filter results.
* @return The {@link AccessPermissionListResult} of all the result matching the given {@link AccessPermissionQuery} parameter.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
Expand All @@ -96,7 +97,7 @@ public AccessPermissionListResult simpleQuery(
public AccessPermissionListResult query(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
AccessPermissionQuery query) throws Exception {
AccessPermissionQuery query) throws KapuaException {

query.setScopeId(scopeId);

Expand All @@ -112,7 +113,7 @@ public AccessPermissionListResult query(
* @param accessInfoId The {@link AccessInfo} id in which to count results.
* @param query The {@link AccessPermissionQuery} to use to filter count results.
* @return The count of all the result matching the given {@link AccessPermissionQuery} parameter.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
Expand All @@ -122,7 +123,7 @@ public AccessPermissionListResult query(
public CountResult count(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
AccessPermissionQuery query) throws Exception {
AccessPermissionQuery query) throws KapuaException {
query.setScopeId(scopeId);

query.setPredicate(query.attributePredicate(AccessPermissionAttributes.ACCESS_INFO_ID, accessInfoId));
Expand All @@ -138,7 +139,7 @@ public CountResult count(
* @param accessInfoId The {@link AccessInfo} id in which to create the AccessPermission.
* @param accessPermissionCreator Provides the information for the new {@link AccessPermission} to be created.
* @return The newly created {@link AccessPermission} object.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
Expand All @@ -147,7 +148,7 @@ public CountResult count(
public Response create(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
AccessPermissionCreator accessPermissionCreator) throws Exception {
AccessPermissionCreator accessPermissionCreator) throws KapuaException {
accessPermissionCreator.setScopeId(scopeId);
accessPermissionCreator.setAccessInfoId(accessInfoId);

Expand All @@ -161,7 +162,7 @@ public Response create(
* @param accessInfoId The {@link AccessInfo} id of the requested {@link AccessPermission}.
* @param accessPermissionId The id of the requested AccessPermission.
* @return The requested AccessPermission object.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@GET
Expand All @@ -170,7 +171,7 @@ public Response create(
public AccessPermission find(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
@PathParam("accessPermissionId") EntityId accessPermissionId) throws Exception {
@PathParam("accessPermissionId") EntityId accessPermissionId) throws KapuaException {
AccessPermissionQuery query = accessPermissionFactory.newQuery(scopeId);

AndPredicate andPredicate = query.andPredicate(
Expand Down Expand Up @@ -198,15 +199,15 @@ public AccessPermission find(
* @param accessInfoId The {@link AccessInfo} id of the {@link AccessPermission} to delete.
* @param accessPermissionId The id of the AccessPermission to be deleted.
* @return HTTP 200 if operation has completed successfully.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@DELETE
@Path("{accessPermissionId}")
public Response deleteAccessPermission(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
@PathParam("accessPermissionId") EntityId accessPermissionId) throws Exception {
@PathParam("accessPermissionId") EntityId accessPermissionId) throws KapuaException {
accessPermissionService.delete(scopeId, accessPermissionId);

return returnNoContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.kapua.app.api.resources.v1.resources;

import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.app.api.resources.v1.resources.model.CountResult;
import org.eclipse.kapua.app.api.resources.v1.resources.model.EntityId;
import org.eclipse.kapua.app.api.resources.v1.resources.model.ScopeId;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class AccessRoles extends AbstractKapuaResource {
* @param offset The result set offset.
* @param limit The result set limit.
* @return The {@link AccessRoleListResult} of all the accessRoles associated to the current selected scope.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@GET
Expand All @@ -61,7 +62,7 @@ public AccessRoleListResult simpleQuery(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws Exception {
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
AccessRoleQuery query = accessRoleFactory.newQuery(scopeId);

query.setPredicate(query.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfoId));
Expand All @@ -78,7 +79,7 @@ public AccessRoleListResult simpleQuery(
* @param scopeId The {@link ScopeId} in which to search results.
* @param query The {@link AccessRoleQuery} to use to filter results.
* @return The {@link AccessRoleListResult} of all the result matching the given {@link AccessRoleQuery} parameter.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
Expand All @@ -88,7 +89,7 @@ public AccessRoleListResult simpleQuery(
public AccessRoleListResult query(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
AccessRoleQuery query) throws Exception {
AccessRoleQuery query) throws KapuaException {
query.setScopeId(scopeId);

query.setPredicate(query.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfoId));
Expand All @@ -102,7 +103,7 @@ public AccessRoleListResult query(
* @param scopeId The {@link ScopeId} in which to search results.
* @param query The {@link AccessRoleQuery} to use to filter results.
* @return The count of all the result matching the given {@link AccessRoleQuery} parameter.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
Expand All @@ -112,7 +113,7 @@ public AccessRoleListResult query(
public CountResult count(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
AccessRoleQuery query) throws Exception {
AccessRoleQuery query) throws KapuaException {
query.setScopeId(scopeId);

query.setPredicate(query.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfoId));
Expand All @@ -127,7 +128,7 @@ public CountResult count(
* @param scopeId The {@link ScopeId} in which to create the {@link AccessRole}.
* @param accessRoleCreator Provides the information for the new AccessRole to be created.
* @return The newly created {@link AccessRole} object.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@POST
Expand All @@ -136,7 +137,7 @@ public CountResult count(
public Response create(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
AccessRoleCreator accessRoleCreator) throws Exception {
AccessRoleCreator accessRoleCreator) throws KapuaException {
accessRoleCreator.setScopeId(scopeId);
accessRoleCreator.setAccessInfoId(accessInfoId);

Expand All @@ -149,7 +150,7 @@ public Response create(
* @param scopeId The {@link ScopeId} of the requested {@link AccessRole}.
* @param accessRoleId The id of the requested {@link AccessRole}.
* @return The requested {@link AccessRole} object.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@GET
Expand All @@ -158,7 +159,7 @@ public Response create(
public AccessRole find(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
@PathParam("accessRoleId") EntityId accessRoleId) throws Exception {
@PathParam("accessRoleId") EntityId accessRoleId) throws KapuaException {
AccessRoleQuery query = accessRoleFactory.newQuery(scopeId);

AndPredicate andPredicate = query.andPredicate(
Expand All @@ -184,15 +185,15 @@ public AccessRole find(
*
* @param accessRoleId The id of the AccessRole to be deleted.
* @return HTTP 200 if operation has completed successfully.
* @throws Exception Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @throws KapuaException Whenever something bad happens. See specific {@link KapuaService} exceptions.
* @since 1.0.0
*/
@DELETE
@Path("{accessRoleId}")
public Response deleteAccessRole(
@PathParam("scopeId") ScopeId scopeId,
@PathParam("accessInfoId") EntityId accessInfoId,
@PathParam("accessRoleId") EntityId accessRoleId) throws Exception {
@PathParam("accessRoleId") EntityId accessRoleId) throws KapuaException {
accessRoleService.delete(scopeId, accessRoleId);

return returnNoContent();
Expand Down
Loading

0 comments on commit d8a2962

Please sign in to comment.