Change-Id: I31a373cd5870633ed0ce2b0e624e8d48eaa33efa
Issue-ID: DMAAP-1211
Signed-off-by: piotr.karas <piotr.karas@nokia.com>
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
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;
import org.json.simple.*;
import org.json.simple.parser.*;
import javax.xml.bind.annotation.XmlRootElement;
private String subscriberRole;
@ApiModelProperty( value="an array of `MR_Client` objects associated to this `Topic`")
private String subscriberRole;
@ApiModelProperty( value="an array of `MR_Client` objects associated to this `Topic`")
- private ArrayList<MR_Client> clients;
+ private List<MR_Client> clients;
- public void setClients(ArrayList<MR_Client> clients) {
+ public void setClients(List<MR_Client> clients) {
this.clients = clients;
}
this.clients = clients;
}
- public ArrayList<MR_Client> getClients() {
+ public List<MR_Client> getClients() {
public class MR_ClientService extends BaseLoggingClass{
public class MR_ClientService extends BaseLoggingClass{
+ private static final String MR_CLIENT_ID = "mrClientId";
private int deleteLevel;
private Map<String, MR_Client> mr_clients = DatabaseClass.getMr_clients();
private Map<String, MR_Cluster> clusters = DatabaseClass.getMr_clusters();
private int deleteLevel;
private Map<String, MR_Client> mr_clients = DatabaseClass.getMr_clients();
private Map<String, MR_Cluster> clusters = DatabaseClass.getMr_clusters();
- private Map<String, Topic> topics = DatabaseClass.getTopics();
private Map<String, DcaeLocation> locations = DatabaseClass.getDcaeLocations();
private DmaapService dmaap = new DmaapService();
private String centralCname;
private Map<String, DcaeLocation> locations = DatabaseClass.getDcaeLocations();
private DmaapService dmaap = new DmaapService();
private String centralCname;
centralCname = p.getProperty("MR.CentralCname", "MRcname.not.set");
deleteLevel = Integer.valueOf(p.getProperty("MR.ClientDeleteLevel", "0" ));
}
centralCname = p.getProperty("MR.CentralCname", "MRcname.not.set");
deleteLevel = Integer.valueOf(p.getProperty("MR.ClientDeleteLevel", "0" ));
}
-
- public Map<String, MR_Client> getMR_Clients() {
- return mr_clients;
- }
public List<MR_Client> getAllMr_Clients() {
public List<MR_Client> getAllMr_Clients() {
- return new ArrayList<MR_Client>(mr_clients.values());
+ return new ArrayList<>(mr_clients.values());
- public ArrayList<MR_Client> getAllMrClients(String fqtn) {
+ List<MR_Client> getAllMrClients(String fqtn) {
ArrayList<MR_Client> results = new ArrayList<>();
for (Map.Entry<String, MR_Client> entry : mr_clients.entrySet())
{
ArrayList<MR_Client> results = new ArrayList<>();
for (Map.Entry<String, MR_Client> entry : mr_clients.entrySet())
{
- public ArrayList<MR_Client> getClientsByLocation(String location) {
- ArrayList<MR_Client> results = new ArrayList<MR_Client>();
+ List<MR_Client> getClientsByLocation(String location) {
+ List<MR_Client> results = new ArrayList<>();
for (Map.Entry<String, MR_Client> entry : mr_clients.entrySet())
{
MR_Client client = entry.getValue();
for (Map.Entry<String, MR_Client> entry : mr_clients.entrySet())
{
MR_Client client = entry.getValue();
-
- public void refreshClients( String location ) {
- ApiError err = new ApiError();
- ArrayList<MR_Client> 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());
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);
}
} else {
apiError.setCode(200);
}
} else {
logger.warn( "Client references a dcaeLocation that doesn't exist:" + client.getDcaeLocationName());
client.setStatus( DmaapObject_Status.STAGED);
} else {
logger.warn( "Client references a dcaeLocation that doesn't exist:" + client.getDcaeLocationName());
client.setStatus( DmaapObject_Status.STAGED);
}
mr_clients.put( client.getMrClientId(), client );
}
mr_clients.put( client.getMrClientId(), client );
MrProvConnection prov = new MrProvConnection();
logger.info( "POST topic " + topic.getFqtn() + " to cluster " + cluster.getFqdn() + " in loc " + cluster.getDcaeLocationName());
if ( prov.makeTopicConnection(cluster)) {
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;
logger.info( "response code: " + err.getCode() );
if ( err.is2xx() || err.getCode() == 409 ) {
return DmaapObject_Status.VALID;
MR_Client c = mr_clients.get( client.getMrClientId());
if ( c == null ) {
apiError.setCode(Status.NOT_FOUND.getStatusCode());
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);
apiError.setMessage("mrClientId " + client.getMrClientId() + " not found" );
} else {
apiError.setCode(200);
MR_Client client = mr_clients.get( key );
if ( client == null ) {
apiError.setCode(Status.NOT_FOUND.getStatusCode());
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);
}
apiError.setMessage("mrClientId " + key + " not found" );
return;
} else {
apiError.setCode(200);
}
- if ( updateTopicView == true ) {
TopicService topics = new TopicService();
Topic t = topics.getTopic(client.getFqtn(), apiError );
if ( t != null ) {
TopicService topics = new TopicService();
Topic t = topics.getTopic(client.getFqtn(), apiError );
if ( t != null ) {
- ArrayList<MR_Client> tc = t.getClients();
+ List<MR_Client> tc = t.getClients();
for( MR_Client c: tc) {
if ( c.getMrClientId().equals(client.getMrClientId())) {
tc.remove(c);
for( MR_Client c: tc) {
if ( c.getMrClientId().equals(client.getMrClientId())) {
tc.remove(c);
// remove from AAF
if ( deleteLevel >= 2 ) {
revokeClientPerms( client, apiError );
// remove from AAF
if ( deleteLevel >= 2 ) {
revokeClientPerms( client, apiError );
if ( deleteLevel >= 1 ) {
mr_clients.remove(key);
}
if ( deleteLevel >= 1 ) {
mr_clients.remove(key);
}
public void test4() {
List<MR_Client> l = cls.getAllMr_Clients();
public void test4() {
List<MR_Client> l = cls.getAllMr_Clients();
- ArrayList<MR_Client> al = cls.getAllMrClients( "foo" );
+ List<MR_Client> al = cls.getAllMrClients( "foo" );
- ArrayList<MR_Client> al2 = cls.getClientsByLocation( "central" );
+ List<MR_Client> al2 = cls.getClientsByLocation( "central" );