@Post("application/json") public String getList(Representation entity) { System.out.println(" --------------------------------------------------------------------- "); System.out.println("ComponentRegisteredListWebService - Starting getList"); JsonObject jsonObjectRespond = new JsonObject(); try { wsCommunicationCloudServer = (WsCommunicationCloudServer) getContext().getAttributes().get(WebServicesApplication.PLUGIN_ROOT_ATT_NAME); /* * Construct the json object */ JSONObject requestParametersJsonObject = (new JsonRepresentation(entity)).getJsonObject(); System.out.println( "ComponentRegisteredListWebService - requestParametersJsonObject = " + requestParametersJsonObject); String clientIdentityPublicKey = requestParametersJsonObject.getString(JsonAttNamesConstants.NAME_IDENTITY); DiscoveryQueryParameters discoveryQueryParameters = new DiscoveryQueryParametersCommunication() .fromJson( requestParametersJsonObject.getString(JsonAttNamesConstants.DISCOVERY_PARAM)); /* * hold the result list */ List<PlatformComponentProfile> resultList = null; if (discoveryQueryParameters.getFromOtherPlatformComponentType() == null && discoveryQueryParameters.getFromOtherNetworkServiceType() == null) { resultList = applyDiscoveryQueryParameters(discoveryQueryParameters, clientIdentityPublicKey); } else { resultList = applyDiscoveryQueryParametersFromOtherComponent( discoveryQueryParameters, clientIdentityPublicKey); } System.out.println( "ComponentRegisteredListWebService - filteredLis.size() =" + resultList.size()); /* * Convert the list to json representation */ String jsonListRepresentation = gson.toJson( resultList, new TypeToken<List<PlatformComponentProfileCommunication>>() {}.getType()); /* * Create the respond */ jsonObjectRespond.addProperty(JsonAttNamesConstants.RESULT_LIST, jsonListRepresentation); } catch (Exception e) { System.out.println("ComponentRegisteredListWebService - requested list is not available"); jsonObjectRespond.addProperty( JsonAttNamesConstants.FAILURE, "Requested list is not available"); e.printStackTrace(); } String jsonString = gson.toJson(jsonObjectRespond); JsonRepresentation jsonRepresentationRespond = new JsonRepresentation(jsonString.trim()); System.out.println( "ComponentRegisteredListWebService - jsonString.length() = " + jsonString.length()); System.out.println( "ComponentRegisteredListWebService - jsonRepresentationRespond.getSize() = " + jsonRepresentationRespond.getSize()); return jsonString; }
/** * Filter the PlatformComponentProfiles that match with the discoveryQueryParameters that get from * other component * * @param discoveryQueryParameters * @param clientIdentityPublicKey * @return List<PlatformComponentProfile> */ private List<PlatformComponentProfile> applyDiscoveryQueryParametersFromOtherComponent( DiscoveryQueryParameters discoveryQueryParameters, String clientIdentityPublicKey) { System.out.println( "ComponentRegisteredListWebService - applyDiscoveryQueryParametersFromOtherComponent = "); List<PlatformComponentProfile> filteredListFromOtherComponentType = new ArrayList<>(); /* * Get the list from the cache that match with the other componet */ List<PlatformComponentProfile> otherComponentList = (List<PlatformComponentProfile>) new ArrayList<>( searchProfile( discoveryQueryParameters.getFromOtherPlatformComponentType(), discoveryQueryParameters.getFromOtherNetworkServiceType(), discoveryQueryParameters.getIdentityPublicKey())) .clone(); System.out.println( "ComponentRegisteredListWebService - otherComponentList = " + otherComponentList.size()); /* * Find the other component that match with the identity */ for (PlatformComponentProfile platformComponentProfile : otherComponentList) { if (discoveryQueryParameters.getIdentityPublicKey() != null && discoveryQueryParameters.getIdentityPublicKey() != "") { List<PlatformComponentProfile> newList = searchProfileByCommunicationCloudClientIdentity( discoveryQueryParameters.getPlatformComponentType(), discoveryQueryParameters.getNetworkServiceType(), platformComponentProfile.getCommunicationCloudClientIdentity()); filteredListFromOtherComponentType.addAll(newList); } } /* * Remove the requester from the list */ Iterator<PlatformComponentProfile> iterator = filteredListFromOtherComponentType.iterator(); while (iterator.hasNext()) { PlatformComponentProfile platformComponentProfileRegistered = iterator.next(); if (platformComponentProfileRegistered .getCommunicationCloudClientIdentity() .equals(clientIdentityPublicKey)) { System.out.println( "ComponentRegisteredListWebService - removing =" + platformComponentProfileRegistered.getName()); iterator.remove(); } } System.out.println( "ComponentRegisteredListWebService - filteredListFromOtherComponentType = " + filteredListFromOtherComponentType.size()); return filteredListFromOtherComponentType; }