X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdbcapi%2Fresources%2FDcaeLocationResource.java;h=89c9b49ecc4375fdec3e4d1f4b03432c49d2080d;hb=18eaae524174fac4f21d83c94bb8347a29d9f879;hp=8cb5336f78f24d4eb11955742a21330a484beffc;hpb=99a69b81bca73117846e55bd0129cf3172d4ee08;p=dmaap%2Fdbcapi.git diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java index 8cb5336..89c9b49 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java +++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java @@ -41,13 +41,14 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.apache.log4j.Logger; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.model.ApiError; import org.onap.dmaap.dbcapi.model.DcaeLocation; -import org.onap.dmaap.dbcapi.service.ApiService; import org.onap.dmaap.dbcapi.service.DcaeLocationService; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.NO_CONTENT; + @Path("/dcaeLocations") @Api( value= "dcaeLocations", description = "an OpenStack tenant purposed for OpenDCAE (i.e. where OpenDCAE components might be deployed)" ) @@ -55,8 +56,8 @@ import org.onap.dmaap.dbcapi.service.DcaeLocationService; @Produces(MediaType.APPLICATION_JSON) @Authorization public class DcaeLocationResource extends BaseLoggingClass { - static final Logger logger = Logger.getLogger(DcaeLocationResource.class); - DcaeLocationService locationService = new DcaeLocationService(); + private DcaeLocationService locationService = new DcaeLocationService(); + private ResponseBuilder responseBuilder = new ResponseBuilder(); @GET @ApiOperation( value = "return dcaeLocation details", @@ -67,13 +68,10 @@ public class DcaeLocationResource extends BaseLoggingClass { @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) public Response getDcaeLocations() { - ApiService check = new ApiService(); - List locs = locationService.getAllDcaeLocations(); - GenericEntity> list = new GenericEntity>(locs) { - }; - return check.success(list); + GenericEntity> list = new GenericEntity>(locs) {}; + return responseBuilder.success(list); } @POST @@ -84,22 +82,14 @@ public class DcaeLocationResource extends BaseLoggingClass { @ApiResponse( code = 200, message = "Success", response = DcaeLocation.class), @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) - public Response addDcaeLocation( - DcaeLocation location - ) { - ApiService check = new ApiService(); + public Response addDcaeLocation(DcaeLocation location) { if ( locationService.getDcaeLocation(location.getDcaeLocationName()) != null ) { - - check.setCode(Status.CONFLICT.getStatusCode()); - check.setMessage("dcaeLocation already exists"); - check.setFields("dcaeLocation"); - - return check.error(); - + return responseBuilder.error(new ApiError(Status.CONFLICT.getStatusCode(), + "dcaeLocation already exists", "dcaeLocation")); } DcaeLocation loc = locationService.addDcaeLocation(location); - return check.success(Status.CREATED.getStatusCode(), loc); + return responseBuilder.success(Status.CREATED.getStatusCode(), loc); } @PUT @@ -112,25 +102,15 @@ public class DcaeLocationResource extends BaseLoggingClass { }) @Path("/{locationName}") public Response updateDcaeLocation( - @PathParam("locationName") String name, - DcaeLocation location - ) { - ApiService check = new ApiService(); + @PathParam("locationName") String name, DcaeLocation location) { location.setDcaeLocationName(name); if ( locationService.getDcaeLocation(location.getDcaeLocationName()) == null ) { - ApiError err = new ApiError(); - - err.setCode(Status.NOT_FOUND.getStatusCode()); - err.setMessage("dcaeLocation does not exist"); - err.setFields("dcaeLocation"); - - return check.notFound(); - + return responseBuilder.notFound(); } DcaeLocation loc = locationService.updateDcaeLocation(location); - return check.success(Status.CREATED.getStatusCode(), loc ); + return responseBuilder.success(Status.CREATED.getStatusCode(), loc ); } @DELETE @@ -143,10 +123,8 @@ public class DcaeLocationResource extends BaseLoggingClass { public Response deleteDcaeLocation( @PathParam("locationName") String name ){ - ApiService check = new ApiService(); - locationService.removeDcaeLocation(name); - return check.success(Status.NO_CONTENT.getStatusCode(), null); + return responseBuilder.success(NO_CONTENT.getStatusCode(), null); } @GET @@ -157,23 +135,19 @@ public class DcaeLocationResource extends BaseLoggingClass { }) @Path("/{locationName}") public Response getDcaeLocation( - @PathParam("locationName") String name - ) { - ApiService check = new ApiService(); + @PathParam("locationName") String name) { DcaeLocation loc = locationService.getDcaeLocation( name ); if ( loc == null ) { ApiError err = new ApiError(); - err.setCode(Status.NOT_FOUND.getStatusCode()); + err.setCode(NOT_FOUND.getStatusCode()); err.setMessage("dcaeLocation does not exist"); err.setFields("dcaeLocation"); - return check.error(); - - + return responseBuilder.error(err); } - return check.success(loc); + return responseBuilder.success(loc); } }