From 5eeb7b8e6f7c4bbe5da8d08a8145109e2f05329f Mon Sep 17 00:00:00 2001 From: pkaras Date: Wed, 29 May 2019 10:21:51 +0200 Subject: [PATCH] not used methods were removed, minor sonar fixes Change-Id: I31a373cd5870633ed0ce2b0e624e8d48eaa33efa Issue-ID: DMAAP-1211 Signed-off-by: piotr.karas --- .../java/org/onap/dmaap/dbcapi/model/Topic.java | 8 ++-- .../dmaap/dbcapi/service/MR_ClientService.java | 46 ++++++---------------- .../dmaap/dbcapi/service/MR_ClientServiceTest.java | 4 +- 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/Topic.java b/src/main/java/org/onap/dmaap/dbcapi/model/Topic.java index b715a24..c143db8 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/Topic.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/Topic.java @@ -24,6 +24,8 @@ import com.google.common.base.Objects; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; +import java.util.List; + import org.json.simple.*; import org.json.simple.parser.*; import javax.xml.bind.annotation.XmlRootElement; @@ -70,7 +72,7 @@ public class Topic extends DmaapObject { private String subscriberRole; @ApiModelProperty( value="an array of `MR_Client` objects associated to this `Topic`") - private ArrayList clients; + private List clients; @@ -229,11 +231,11 @@ public class Topic extends DmaapObject { } - public void setClients(ArrayList clients) { + public void setClients(List clients) { this.clients = clients; } - public ArrayList getClients() { + public List getClients() { return clients; } diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClientService.java b/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClientService.java index 6010784..d0407c2 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClientService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClientService.java @@ -54,10 +54,10 @@ import org.onap.dmaap.dbcapi.util.DmaapConfig; public class MR_ClientService extends BaseLoggingClass{ + private static final String MR_CLIENT_ID = "mrClientId"; private int deleteLevel; private Map mr_clients = DatabaseClass.getMr_clients(); private Map clusters = DatabaseClass.getMr_clusters(); - private Map topics = DatabaseClass.getTopics(); private Map locations = DatabaseClass.getDcaeLocations(); private DmaapService dmaap = new DmaapService(); private String centralCname; @@ -68,16 +68,12 @@ public class MR_ClientService extends BaseLoggingClass{ centralCname = p.getProperty("MR.CentralCname", "MRcname.not.set"); deleteLevel = Integer.valueOf(p.getProperty("MR.ClientDeleteLevel", "0" )); } - - public Map getMR_Clients() { - return mr_clients; - } public List getAllMr_Clients() { - return new ArrayList(mr_clients.values()); + return new ArrayList<>(mr_clients.values()); } - public ArrayList getAllMrClients(String fqtn) { + List getAllMrClients(String fqtn) { ArrayList results = new ArrayList<>(); for (Map.Entry entry : mr_clients.entrySet()) { @@ -89,8 +85,8 @@ public class MR_ClientService extends BaseLoggingClass{ return results; } - public ArrayList getClientsByLocation(String location) { - ArrayList results = new ArrayList(); + List getClientsByLocation(String location) { + List results = new ArrayList<>(); for (Map.Entry entry : mr_clients.entrySet()) { MR_Client client = entry.getValue(); @@ -100,26 +96,14 @@ public class MR_ClientService extends BaseLoggingClass{ } return results; } - - public void refreshClients( String location ) { - ApiError err = new ApiError(); - ArrayList clients = getClientsByLocation( location ); - for( MR_Client client : clients ) { - Topic topic = topics.get(client.getFqtn()); - if ( topic != null ) { - addMr_Client( client, topic, err); - } - - - } - } + public MR_Client getMr_Client( String key, ApiError apiError ) { MR_Client c = mr_clients.get( key ); if ( c == null ) { apiError.setCode(Status.NOT_FOUND.getStatusCode()); - apiError.setFields( "mrClientId"); - apiError.setMessage("mrClientId " + key + " not found" ); + apiError.setFields(MR_CLIENT_ID); + apiError.setMessage(MR_CLIENT_ID+ " " + key + " not found" ); } else { apiError.setCode(200); } @@ -183,7 +167,6 @@ public class MR_ClientService extends BaseLoggingClass{ } else { logger.warn( "Client references a dcaeLocation that doesn't exist:" + client.getDcaeLocationName()); client.setStatus( DmaapObject_Status.STAGED); - //return null; } mr_clients.put( client.getMrClientId(), client ); @@ -198,7 +181,7 @@ public class MR_ClientService extends BaseLoggingClass{ MrProvConnection prov = new MrProvConnection(); logger.info( "POST topic " + topic.getFqtn() + " to cluster " + cluster.getFqdn() + " in loc " + cluster.getDcaeLocationName()); if ( prov.makeTopicConnection(cluster)) { - String resp = prov.doPostTopic(topic, err); + prov.doPostTopic(topic, err); logger.info( "response code: " + err.getCode() ); if ( err.is2xx() || err.getCode() == 409 ) { return DmaapObject_Status.VALID; @@ -271,7 +254,7 @@ public class MR_ClientService extends BaseLoggingClass{ MR_Client c = mr_clients.get( client.getMrClientId()); if ( c == null ) { apiError.setCode(Status.NOT_FOUND.getStatusCode()); - apiError.setFields( "mrClientId"); + apiError.setFields(MR_CLIENT_ID); apiError.setMessage("mrClientId " + client.getMrClientId() + " not found" ); } else { apiError.setCode(200); @@ -284,20 +267,20 @@ public class MR_ClientService extends BaseLoggingClass{ MR_Client client = mr_clients.get( key ); if ( client == null ) { apiError.setCode(Status.NOT_FOUND.getStatusCode()); - apiError.setFields( "mrClientId"); + apiError.setFields(MR_CLIENT_ID); apiError.setMessage("mrClientId " + key + " not found" ); return; } else { apiError.setCode(200); } - if ( updateTopicView == true ) { + if (updateTopicView) { TopicService topics = new TopicService(); Topic t = topics.getTopic(client.getFqtn(), apiError ); if ( t != null ) { - ArrayList tc = t.getClients(); + List tc = t.getClients(); for( MR_Client c: tc) { if ( c.getMrClientId().equals(client.getMrClientId())) { tc.remove(c); @@ -310,7 +293,6 @@ public class MR_ClientService extends BaseLoggingClass{ } - // remove from AAF if ( deleteLevel >= 2 ) { revokeClientPerms( client, apiError ); @@ -322,8 +304,6 @@ public class MR_ClientService extends BaseLoggingClass{ if ( deleteLevel >= 1 ) { mr_clients.remove(key); } - - return; } } diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java index bfa4126..0456d10 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java @@ -108,9 +108,9 @@ public class MR_ClientServiceTest { public void test4() { List l = cls.getAllMr_Clients(); - ArrayList al = cls.getAllMrClients( "foo" ); + List al = cls.getAllMrClients( "foo" ); - ArrayList al2 = cls.getClientsByLocation( "central" ); + List al2 = cls.getClientsByLocation( "central" ); } @Test -- 2.16.6