+ /*
+ * Remove duplicate values from 'lookup' dictionary tables
+ */
+ private void removeDuplicateValuesFromLookup(CommonClassDaoImpl dbConnection) {
+ String protoDelete = "DELETE FROM protocollist USING protocollist, protocollist p1 "
+ + "WHERE protocollist.id > p1.id AND protocollist.protocolname = p1.protocolname;";
+ dbConnection.updateQuery(protoDelete);
+
+ // PortList Table
+ String portListDelete = "DELETE FROM portlist USING portlist, portlist p1 "
+ + "WHERE portlist.id > p1.id AND portlist.portname = p1.portname; ";
+ dbConnection.updateQuery(portListDelete);
+
+ // PrefixList Table
+ String prefixListDelete = "DELETE FROM prefixlist USING prefixlist, prefixlist p1 "
+ + "WHERE prefixlist.id > p1.id AND prefixlist.pl_name = p1.pl_name AND "
+ + "prefixlist.pl_value = p1.pl_value AND prefixlist.description = p1.description; ";
+ dbConnection.updateQuery(prefixListDelete);
+
+ // GroupServiceList
+ String groupServiceDelete = "DELETE FROM groupservicelist USING groupservicelist, groupservicelist g1 "
+ + "WHERE groupservicelist.id > g1.id AND groupservicelist.name = g1.name AND "
+ + "groupservicelist.serviceList = g1.serviceList; ";
+ dbConnection.updateQuery(groupServiceDelete);
+ }
+
+ private void saveGroupServiceListTableToDb(CommonClassDaoImpl dbConnection, String serviceListName,
+ JsonArray membersArray) {
+ String name = null;
+ for (int membersIndex = 0; membersIndex < membersArray.size(); membersIndex++) {
+ JsonObject membersObj = membersArray.getJsonObject(membersIndex);
+ String type = membersObj.get("type").toString().replace("\"", "");
+
+ name = getName(name, membersObj, type);
+ }
+ String nameInsert = "'" + name + "'";
+ GroupServiceList groupServiceEntry = new GroupServiceList();
+ groupServiceEntry.setGroupName(serviceListName);
+ groupServiceEntry.setServiceList(nameInsert);
+ dbConnection.save(groupServiceEntry);
+ }
+
+ private String getName(String name, JsonObject membersObj, String type) {
+ String value;
+ if (type.equals("REFERENCE") || type.equals("GROUP") || type.equals("SERVICE")) {
+ value = membersObj.get("name").toString();
+ } else if (type.equalsIgnoreCase("ANY")) {
+ value = null;
+ } else {
+ value = membersObj.get("value").toString();
+ }
+
+ name = getLeftOrRight(name, value);
+ return name;
+ }
+
+ private String getLeftOrRight(String name, String value) {
+ if (value != null) {
+ value = value.replace("\"", "");
+ }
+
+ if (name != null) {
+ name = name.concat(",").concat(value);
+ } else {
+ name = value.replace("\"", "");;
+ }
+ return name;
+ }