import org.onap.dmaap.dbcapi.service.MR_ClusterService;
import org.onap.dmaap.dbcapi.service.TopicService;
+import static javax.ws.rs.core.Response.Status.NO_CONTENT;
+
@Path("/mr_clients")
@Api( value= "MR_Clients", description = "Endpoint for a Message Router Client that implements a Publisher or a Subscriber" )
public class MR_ClientResource extends BaseLoggingClass {
private MR_ClientService mr_clientService = new MR_ClientService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
+ private RequiredChecker checker = new RequiredChecker();
@GET
@ApiOperation( value = "return MR_Client details",
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response getMr_Clients() {
- ApiService resp = new ApiService();
-
List<MR_Client> clients = mr_clientService.getAllMr_Clients();
GenericEntity<List<MR_Client>> list = new GenericEntity<List<MR_Client>>(clients) {
};
- return resp.success(list);
+ return responseBuilder.success(list);
}
@POST
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response addMr_Client(
- MR_Client client
- ) {
+ MR_Client client) {
ApiService resp = new ApiService();
try {
- resp.required( "fqtn", client.getFqtn(), "");
- resp.required( "dcaeLocationName", client.getDcaeLocationName(), "");
+ checker.required( "fqtn", client.getFqtn());
+ checker.required( "dcaeLocationName", client.getDcaeLocationName());
String s = client.getClientRole();
if ( s == null ) {
s = client.getClientIdentity();
}
- resp.required( "clientRole or clientIdentity", s, "" );
- resp.required( "action", client.getAction(), "");
+ checker.required( "clientRole or clientIdentity", s);
+ checker.required( "action", client.getAction());
} catch ( RequiredFieldException rfe ) {
- logger.debug( resp.toString() );
- return resp.error();
+ logger.debug( rfe.getApiError().toString() );
+ return responseBuilder.error(rfe.getApiError());
}
MR_ClusterService clusters = new MR_ClusterService();
resp.setMessage( "MR_Cluster alias not found for dcaeLocation: " + client.getDcaeLocationName());
resp.setFields("dcaeLocationName");
logger.warn( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
String url = cluster.getFqdn();
if ( url == null || url.isEmpty() ) {
resp.setMessage("FQDN not set for dcaeLocation " + client.getDcaeLocationName() );
resp.setFields("fqdn");
logger.warn( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
TopicService topics = new TopicService();
Topic t = topics.getTopic(client.getFqtn(), resp.getErr() );
if ( t == null ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
MR_Client nClient = mr_clientService.addMr_Client(client, t, resp.getErr());
if ( resp.getErr().is2xx()) {
t = topics.getTopic(client.getFqtn(), resp.getErr());
topics.checkForBridge(t, resp.getErr());
- return resp.success(nClient);
+ return responseBuilder.success(nClient);
}
else {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
}
ApiService resp = new ApiService();
try {
- resp.required( "fqtn", client.getFqtn(), "");
- resp.required( "dcaeLocationName", client.getDcaeLocationName(), "");
- resp.required( "clientRole", client.getClientRole(), "" );
- resp.required( "action", client.getAction(), "");
+ checker.required( "fqtn", client.getFqtn());
+ checker.required( "dcaeLocationName", client.getDcaeLocationName());
+ checker.required( "clientRole", client.getClientRole());
+ checker.required( "action", client.getAction());
} catch ( RequiredFieldException rfe ) {
- logger.debug( resp.toString() );
- return resp.error();
+ logger.debug( rfe.getApiError().toString() );
+ return responseBuilder.error(rfe.getApiError());
}
client.setMrClientId(clientId);
MR_Client nClient = mr_clientService.updateMr_Client(client, resp.getErr() );
ApiService resp = new ApiService();
try {
- resp.required( "clientId", id, "");
+ checker.required( "clientId", id);
} catch ( RequiredFieldException rfe ) {
- logger.debug( resp.toString() );
- return resp.error();
+ logger.debug( rfe.getApiError().toString() );
+ return responseBuilder.error(rfe.getApiError());
}
mr_clientService.removeMr_Client(id, true, resp.getErr() );
if ( resp.getErr().is2xx()) {
- return resp.success(Status.NO_CONTENT.getStatusCode(), null);
+ return responseBuilder.success(NO_CONTENT.getStatusCode(), null);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@GET
ApiService resp = new ApiService();
try {
- resp.required( "clientId", id, "");
+ checker.required( "clientId", id);
} catch ( RequiredFieldException rfe ) {
- logger.debug( resp.toString() );
- return resp.error();
+ logger.debug( rfe.getApiError().toString() );
+ return responseBuilder.error(rfe.getApiError());
}
MR_Client nClient = mr_clientService.getMr_Client( id, resp.getErr() );
if ( resp.getErr().is2xx()) {
- return resp.success(nClient);
+ return responseBuilder.success(nClient);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
}