Fixe .gitignore for top level
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / configuration / ApplicationConfigParser.java
index 578ff12..059016d 100644 (file)
@@ -23,6 +23,7 @@ package org.oransc.policyagent.configuration;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
+
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -31,37 +32,55 @@ import java.util.List;
 import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
+
 import javax.validation.constraints.NotNull;
-import lombok.Getter;
+
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
 import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
 import org.oransc.policyagent.exceptions.ServiceException;
 import org.springframework.http.MediaType;
 
+/**
+ * Parser for the Json representing of the component configuration.
+ */
 public class ApplicationConfigParser {
 
     private static final String CONFIG = "config";
 
-    @Getter
-    private List<RicConfig> ricConfigs;
-    @Getter
-    private Properties dmaapPublisherConfig = new Properties();
-    @Getter
-    private Properties dmaapConsumerConfig = new Properties();
+    @Value.Immutable
+    @Gson.TypeAdapters
+    public interface ConfigParserResult {
+        List<RicConfig> ricConfigs();
+
+        Properties dmaapPublisherConfig();
+
+        Properties dmaapConsumerConfig();
+    }
+
+    public ConfigParserResult parse(JsonObject root) throws ServiceException {
+
+        Properties dmaapPublisherConfig = new Properties();
+        Properties dmaapConsumerConfig = new Properties();
 
-    public void parse(JsonObject root) throws ServiceException {
         JsonObject agentConfigJson = root.getAsJsonObject(CONFIG);
-        ricConfigs = parseRics(agentConfigJson);
+        List<RicConfig> ricConfigs = parseRics(agentConfigJson);
 
         JsonObject json = agentConfigJson.getAsJsonObject("streams_publishes");
         if (json != null) {
-            this.dmaapPublisherConfig = parseDmaapConfig(json);
+            dmaapPublisherConfig = parseDmaapConfig(json);
         }
 
         json = agentConfigJson.getAsJsonObject("streams_subscribes");
         if (json != null) {
-            this.dmaapConsumerConfig = parseDmaapConfig(json);
+            dmaapConsumerConfig = parseDmaapConfig(json);
         }
 
+        return ImmutableConfigParserResult.builder() //
+            .dmaapConsumerConfig(dmaapConsumerConfig) //
+            .dmaapPublisherConfig(dmaapPublisherConfig) //
+            .ricConfigs(ricConfigs) //
+            .build();
     }
 
     private List<RicConfig> parseRics(JsonObject config) throws ServiceException {