X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdbcapi%2Fresources%2FDR_SubResource.java;h=498454edd0d82b137df52e001adb2cd060fe897c;hb=d6ac6f8b10e90411dd650d6f7a9ee51179e39bfc;hp=03a8e2ff951d4c714ac5f9a5c33f94d0545c94d3;hpb=a05efb7b7b3cfc77f5e3fda11e8434834829f56a;p=dmaap%2Fdbcapi.git diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java index 03a8e2f..498454e 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java +++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java @@ -3,6 +3,8 @@ * org.onap.dmaap * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +22,6 @@ package org.onap.dmaap.dbcapi.resources; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; - import java.util.ArrayList; import java.util.List; @@ -43,13 +40,17 @@ import javax.ws.rs.core.Response.Status; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.model.ApiError; -import org.onap.dmaap.dbcapi.model.DR_Pub; import org.onap.dmaap.dbcapi.model.DR_Sub; import org.onap.dmaap.dbcapi.model.Feed; import org.onap.dmaap.dbcapi.service.ApiService; import org.onap.dmaap.dbcapi.service.DR_SubService; import org.onap.dmaap.dbcapi.service.FeedService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + @Path("/dr_subs") @Api( value= "dr_subs", description = "Endpoint for a Data Router client that implements a Subscriber" ) @@ -63,7 +64,7 @@ public class DR_SubResource extends BaseLoggingClass { notes = "Returns array of `DR_Sub` objects. Add filter for feedId.", response = DR_Sub.class) @ApiResponses( value = { - @ApiResponse( code = 200, message = "Success", response = DR_Pub.class), + @ApiResponse( code = 200, message = "Success", response = DR_Sub.class), @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) public Response getDr_Subs() { @@ -83,7 +84,7 @@ public class DR_SubResource extends BaseLoggingClass { notes = "Create a `DR_Sub` object. ", response = DR_Sub.class) @ApiResponses( value = { - @ApiResponse( code = 200, message = "Success", response = DR_Pub.class), + @ApiResponse( code = 200, message = "Success", response = DR_Sub.class), @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) public Response addDr_Sub( @@ -91,24 +92,41 @@ public class DR_SubResource extends BaseLoggingClass { ) { ApiService resp = new ApiService(); - + FeedService feeds = new FeedService(); + Feed fnew = null; try { resp.required( "feedId", sub.getFeedId(), ""); + } catch ( RequiredFieldException rfe ) { + try { + resp.required( "feedName", sub.getFeedName(), ""); + }catch ( RequiredFieldException rfe2 ) { + logger.debug( resp.toString() ); + return resp.error(); + } + // if we found a FeedName instead of a FeedId then try to look it up. + List nfeeds = feeds.getAllFeeds( sub.getFeedName(), sub.getFeedVersion(), "equals"); + if ( nfeeds.size() != 1 ) { + logger.debug( "Attempt to match "+ sub.getFeedName() + " ver="+sub.getFeedVersion() + " matched " + nfeeds.size() ); + return resp.error(); + } + fnew = nfeeds.get(0); + } + + try { resp.required( "dcaeLocationName", sub.getDcaeLocationName(), ""); - } catch ( RequiredFieldException rfe ) { logger.debug( resp.toString() ); return resp.error(); } - - FeedService feeds = new FeedService(); - Feed fnew = feeds.getFeed( sub.getFeedId(), resp.getErr() ); + // we may have fnew already if located by FeedName if ( fnew == null ) { - logger.warn( "Specified feed " + sub.getFeedId() + " not known to Bus Controller"); + fnew = feeds.getFeed( sub.getFeedId(), resp.getErr() ); + } + if ( fnew == null ) { + logger.warn( "Specified feed " + sub.getFeedId() + " or " + sub.getFeedName() + " not known to Bus Controller"); resp.setCode(Status.NOT_FOUND.getStatusCode()); return resp.error(); } - DR_SubService dr_subService = new DR_SubService( fnew.getSubscribeURL()); ArrayList subs = fnew.getSubs(); logger.info( "num existing subs before = " + subs.size() ); @@ -121,8 +139,6 @@ public class DR_SubResource extends BaseLoggingClass { fnew.setSubs(subs); logger.info( "update feed"); - //feeds.updateFeed( fnew, err ); - return resp.success(Status.CREATED.getStatusCode(), snew); } @@ -132,7 +148,7 @@ public class DR_SubResource extends BaseLoggingClass { notes = "Update a `DR_Sub` object, selected by subId", response = DR_Sub.class) @ApiResponses( value = { - @ApiResponse( code = 200, message = "Success", response = DR_Pub.class), + @ApiResponse( code = 200, message = "Success", response = DR_Sub.class), @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) @Path("/{subId}") @@ -158,7 +174,7 @@ public class DR_SubResource extends BaseLoggingClass { logger.warn( "Specified feed " + sub.getFeedId() + " not known to Bus Controller"); return resp.error(); } - + DR_SubService dr_subService = new DR_SubService(); sub.setSubId(name); DR_Sub nsub = dr_subService.updateDr_Sub(sub, resp.getErr() ); @@ -173,7 +189,7 @@ public class DR_SubResource extends BaseLoggingClass { notes = "Delete a `DR_Sub` object, selected by subId", response = DR_Sub.class) @ApiResponses( value = { - @ApiResponse( code = 200, message = "Success", response = DR_Pub.class), + @ApiResponse( code = 200, message = "Success", response = DR_Sub.class), @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) @Path("/{subId}") @@ -202,7 +218,7 @@ public class DR_SubResource extends BaseLoggingClass { notes = "Retrieve a `DR_Sub` object, selected by subId", response = DR_Sub.class) @ApiResponses( value = { - @ApiResponse( code = 200, message = "Success", response = DR_Pub.class), + @ApiResponse( code = 200, message = "Success", response = DR_Sub.class), @ApiResponse( code = 400, message = "Error", response = ApiError.class ) }) @Path("/{subId}")