\r
package org.onap.dmaap.datarouter.provisioning.beans;\r
\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
import java.io.InvalidObjectException;\r
import java.sql.Connection;\r
import java.sql.PreparedStatement;\r
import java.sql.ResultSet;\r
import java.sql.SQLException;\r
import java.sql.Statement;\r
-import java.util.*;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Date;\r
+import java.util.List;\r
+import java.util.Objects;\r
import org.json.JSONObject;\r
import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
\r
*/\r
public class Group extends Syncable {\r
\r
+ private static final String GROUP_ID_CONST = "groupid";\r
private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
- private static int next_groupid = getMaxGroupID() + 1;\r
+ private static int nextGroupid = getMaxGroupID() + 1;\r
private static final String SQLEXCEPTION = "SQLException: ";\r
\r
private int groupid;\r
private String members;\r
private Date last_mod;\r
\r
+ public Group() {\r
+ this("", "", "");\r
+ }\r
+\r
+ public Group(String name, String desc, String members) {\r
+ this.groupid = -1;\r
+ this.authid = "";\r
+ this.name = name;\r
+ this.description = desc;\r
+ this.members = members;\r
+ this.classification = "";\r
+ this.last_mod = new Date();\r
+ }\r
+\r
+\r
+ public Group(ResultSet rs) throws SQLException {\r
+ this.groupid = rs.getInt("GROUPID");\r
+ this.authid = rs.getString("AUTHID");\r
+ this.name = rs.getString("NAME");\r
+ this.description = rs.getString("DESCRIPTION");\r
+ this.classification = rs.getString("CLASSIFICATION");\r
+ this.members = rs.getString("MEMBERS");\r
+ this.last_mod = rs.getDate("LAST_MOD");\r
+ }\r
+\r
+\r
+ public Group(JSONObject jo) throws InvalidObjectException {\r
+ this("", "", "");\r
+ try {\r
+ // The JSONObject is assumed to contain a vnd.dmaap-dr.group representation\r
+ this.groupid = jo.optInt(GROUP_ID_CONST, -1);\r
+ String gname = jo.getString("name");\r
+ String gdescription = jo.getString("description");\r
+\r
+ this.authid = jo.getString("authid");\r
+ this.name = gname;\r
+ this.description = gdescription;\r
+ this.classification = jo.getString("classification");\r
+ this.members = jo.getString("members");\r
+\r
+ if (gname.length() > 50) {\r
+ throw new InvalidObjectException("Group name is too long");\r
+ }\r
+ if (gdescription.length() > 256) {\r
+ throw new InvalidObjectException("Group Description is too long");\r
+ }\r
+ } catch (InvalidObjectException e) {\r
+ throw e;\r
+ } catch (Exception e) {\r
+ intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+ throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
+ }\r
+ }\r
+\r
\r
public static Group getGroupMatching(Group gup) {\r
String sql = String.format(\r
gup.getName()\r
);\r
List<Group> list = getGroupsForSQL(sql);\r
- return list.size() > 0 ? list.get(0) : null;\r
+ return !list.isEmpty() ? list.get(0) : null;\r
}\r
\r
public static Group getGroupMatching(Group gup, int groupid) {\r
gup.getGroupid()\r
);\r
List<Group> list = getGroupsForSQL(sql);\r
- return list.size() > 0 ? list.get(0) : null;\r
+ return !list.isEmpty() ? list.get(0) : null;\r
}\r
\r
public static Group getGroupById(int id) {\r
String sql = "select * from GROUPS where GROUPID = " + id;\r
List<Group> list = getGroupsForSQL(sql);\r
- return list.size() > 0 ? list.get(0) : null;\r
+ return !list.isEmpty() ? list.get(0) : null;\r
}\r
\r
- public static Group getGroupByAuthId(String id) {\r
+ static Group getGroupByAuthId(String id) {\r
String sql = "select * from GROUPS where AUTHID = '" + id + "'";\r
List<Group> list = getGroupsForSQL(sql);\r
- return list.size() > 0 ? list.get(0) : null;\r
+ return !list.isEmpty() ? list.get(0) : null;\r
}\r
\r
public static Collection<Group> getAllgroups() {\r
}\r
\r
private static List<Group> getGroupsForSQL(String sql) {\r
- List<Group> list = new ArrayList<Group>();\r
+ List<Group> list = new ArrayList<>();\r
try {\r
DB db = new DB();\r
@SuppressWarnings("resource")\r
return list;\r
}\r
\r
- public static int getMaxGroupID() {\r
+ private static int getMaxGroupID() {\r
int max = 0;\r
try {\r
DB db = new DB();\r
return max;\r
}\r
\r
- public Group() {\r
- this("", "", "");\r
- }\r
-\r
- public Group(String name, String desc, String members) {\r
- this.groupid = -1;\r
- this.authid = "";\r
- this.name = name;\r
- this.description = desc;\r
- this.members = members;\r
- this.classification = "";\r
- this.last_mod = new Date();\r
- }\r
-\r
-\r
- public Group(ResultSet rs) throws SQLException {\r
- this.groupid = rs.getInt("GROUPID");\r
- this.authid = rs.getString("AUTHID");\r
- this.name = rs.getString("NAME");\r
- this.description = rs.getString("DESCRIPTION");\r
- this.classification = rs.getString("CLASSIFICATION");\r
- this.members = rs.getString("MEMBERS");\r
- this.last_mod = rs.getDate("LAST_MOD");\r
- }\r
-\r
-\r
- public Group(JSONObject jo) throws InvalidObjectException {\r
- this("", "", "");\r
- try {\r
- // The JSONObject is assumed to contain a vnd.dmaap-dr.group representation\r
- this.groupid = jo.optInt("groupid", -1);\r
- String gname = jo.getString("name");\r
- String gdescription = jo.getString("description");\r
-\r
- this.authid = jo.getString("authid");\r
- this.name = gname;\r
- this.description = gdescription;\r
- this.classification = jo.getString("classification");\r
- this.members = jo.getString("members");\r
-\r
- if (gname.length() > 50) {\r
- throw new InvalidObjectException("Group name is too long");\r
- }\r
- if (gdescription.length() > 256) {\r
- throw new InvalidObjectException("Group Description is too long");\r
- }\r
- } catch (InvalidObjectException e) {\r
- throw e;\r
- } catch (Exception e) {\r
- intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
- throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
- }\r
- }\r
-\r
public int getGroupid() {\r
return groupid;\r
}\r
@Override\r
public JSONObject asJSONObject() {\r
JSONObject jo = new JSONObject();\r
- jo.put("groupid", groupid);\r
+ jo.put(GROUP_ID_CONST, groupid);\r
jo.put("authid", authid);\r
jo.put("name", name);\r
jo.put("description", description);\r
try {\r
if (groupid == -1) {\r
// No feed ID assigned yet, so assign the next available one\r
- setGroupid(next_groupid++);\r
+ setGroupid(nextGroupid++);\r
}\r
// In case we insert a gropup from synchronization\r
- if (groupid > next_groupid) {\r
- next_groupid = groupid + 1;\r
+ if (groupid > nextGroupid) {\r
+ nextGroupid = groupid + 1;\r
}\r
\r
// Create the GROUPS row\r