* See the License for the specific language governing permissions and\r
* limitations under the License.\r
*/\r
-\r
package org.onap.holmes.common.dcae.utils;\r
\r
+import com.alibaba.fastjson.JSON;\r
+import com.alibaba.fastjson.JSONObject;\r
import java.util.Arrays;\r
import java.util.List;\r
import java.util.Map.Entry;\r
import java.util.Set;\r
import java.util.stream.Stream;\r
-import net.sf.json.JSONObject;\r
import org.apache.commons.lang3.StringUtils;\r
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;\r
import org.onap.holmes.common.dcae.entity.Rule;\r
\r
public class DcaeConfigurationParser {\r
\r
+ private static final String RULE_CONTENT_SPLIT = "\\$\\$\\$";\r
+\r
private static final List<String> OBJECT_ATTRS = Arrays\r
.asList(new String[]{"streams_subscribes", "streams_publishes", "services_calls", "services_provides"});\r
\r
public static DcaeConfigurations parse(String jsonStr) throws CorrelationException {\r
if (StringUtils.isEmpty(jsonStr)) {\r
throw new CorrelationException(\r
- "Can not resolve configurations from DCAE. The configuration string is empty");\r
+ "Can not resolve configurations from DCAE. The configuration string is empty.");\r
}\r
\r
DcaeConfigurations ret = new DcaeConfigurations();\r
\r
JSONObject jsonObject = null;\r
try {\r
- jsonObject = JSONObject.fromObject(jsonStr);\r
+ jsonObject = JSON.parseObject(jsonStr);\r
} catch (Exception e) {\r
throw new CorrelationException(e.getMessage(), e);\r
}\r
\r
fillInRules(ret, jsonObject);\r
fillInPublishesInfo(ret, jsonObject);\r
-\r
- if (jsonObject.containsKey("streams_subscribes")) {\r
-\r
- }\r
+ fillInSubscribesInfo(ret, jsonObject);\r
\r
JSONObject finalJsonObject = jsonObject;\r
Stream.of(jsonObject.keySet().toArray(new String[0]))\r
.filter(key -> !OBJECT_ATTRS.contains(key))\r
- .forEach(key -> ret.put(key.toString(), finalJsonObject.getString(String.valueOf(key))));\r
+ .forEach(key -> ret.put(key, finalJsonObject.getString(String.valueOf(key))));\r
return ret;\r
}\r
\r
}\r
}\r
\r
+ private static void fillInSubscribesInfo(DcaeConfigurations ret, JSONObject jsonObject) {\r
+ if (jsonObject.containsKey("streams_subscribes")) {\r
+ JSONObject subscribes = jsonObject.getJSONObject("streams_subscribes");\r
+ for (Object key : subscribes.keySet()) {\r
+ ret.addSubSecInfo((String) key,\r
+ createSecurityInfo((String) key, subscribes.getJSONObject((String) key)));\r
+ }\r
+ }\r
+ }\r
+\r
private static SecurityInfo createSecurityInfo(String key, JSONObject entity) {\r
SecurityInfo securityInfo = new SecurityInfo();\r
- securityInfo.setType(entity.getString("type"));\r
- if (!entity.get("aaf_password").equals("null")) {\r
+ if (entity.containsKey("type")) {\r
+ securityInfo.setType(entity.getString("type"));\r
+ }\r
+ if (entity.containsKey("aaf_password")) {\r
securityInfo.setAafPassword(entity.getString("aaf_password"));\r
}\r
- if (!entity.get("aaf_username").equals("null")) {\r
+ if (entity.containsKey("aaf_username")) {\r
securityInfo.setAafUsername(entity.getString("aaf_username"));\r
}\r
securityInfo.setSecureTopic(!key.endsWith("unsecure"));\r
\r
private static void fillInDmaapInfo(SecurityInfo securityInfo, JSONObject jsonDmaapInfo) {\r
SecurityInfo.DmaapInfo dmaapInfo = securityInfo.getDmaapInfo();\r
- dmaapInfo.setLocation(jsonDmaapInfo.getString("location"));\r
- dmaapInfo.setTopicUrl(jsonDmaapInfo.getString("topic_url"));\r
- if (!jsonDmaapInfo.get("client_id").equals("null")) {\r
+ if (jsonDmaapInfo.containsKey("location")){\r
+ dmaapInfo.setLocation(jsonDmaapInfo.getString("location"));\r
+ }\r
+ if (jsonDmaapInfo.containsKey("topic_url")) {\r
+ dmaapInfo.setTopicUrl(jsonDmaapInfo.getString("topic_url"));\r
+ }\r
+ if (jsonDmaapInfo.containsKey("client_id")) {\r
dmaapInfo.setClientId(jsonDmaapInfo.getString("client_id"));\r
}\r
- if (!jsonDmaapInfo.get("client_role").equals("null")) {\r
+ if (jsonDmaapInfo.containsKey("client_role")) {\r
dmaapInfo.setClientRole(jsonDmaapInfo.getString("client_role"));\r
}\r
+ if (jsonDmaapInfo.containsKey("type")) {\r
+ dmaapInfo.setType(jsonDmaapInfo.getString("type"));\r
+ }\r
}\r
\r
private static void fillInRules(DcaeConfigurations ret, JSONObject jsonObject) {\r
Set<Entry<String, Object>> entries = jsonObject.entrySet();\r
for (Entry<String, Object> entry : entries) {\r
if (entry.getKey().startsWith("holmes.default.rule")) {\r
- ret.addDefaultRule(new Rule(entry.getKey(), (String) entry.getValue()));\r
+ String value = (String) entry.getValue();\r
+ String[] contents = value.split(RULE_CONTENT_SPLIT);\r
+ ret.addDefaultRule(new Rule(entry.getKey(), contents[0], contents[1], 1));\r
}\r
}\r
}\r