Sonar cleanup for integrity-audit

Modified classes in integrity-audit module to resolve major sonar issues.

Issue-ID: [POLICY-96]
Change-Id: I5ef0abb8d2a3ea1ae93edc00363c4d2bea1747e2
Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java
index e7e16a6..2e15da5 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java
@@ -26,7 +26,6 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Properties;
-//import org.apache.log4j.Logger;
 
 
 import org.onap.policy.common.ia.jpa.IntegrityAuditEntity;
@@ -146,8 +145,8 @@
 
 			DbAudit dbAudit = new DbAudit(dbDAO);
 
-			IntegrityAuditEntity entityCurrentlyDesignated = null;
-			IntegrityAuditEntity thisEntity = null;
+			IntegrityAuditEntity entityCurrentlyDesignated;
+			IntegrityAuditEntity thisEntity;
 			integrityAudit.setThreadInitialized(true); // An exception will set
 														// it to false
 
@@ -702,7 +701,7 @@
 					+ thisEntity.getLastUpdated());
 		}
 
-		long timeDifference = -1;
+		long timeDifference;
 
 		Date currentTime = new Date();
 		Date lastUpdated = thisEntity.getLastUpdated();
@@ -752,9 +751,8 @@
 					+ this.persistenceUnit + " on resourceName="
 					+ this.resourceName);
 		}
-		if (IntegrityAudit.isUnitTesting) {
-			dbAudit.dbAuditSimulate(this.resourceName, this.persistenceUnit,
-					this.nodeType);
+		if (IntegrityAudit.isUnitTesting()) {
+			dbAudit.dbAuditSimulate(this.resourceName, this.persistenceUnit);
 		} else {
 			dbAudit.dbAudit(this.resourceName, this.persistenceUnit,
 					this.nodeType);
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
index 8312daa..8a1a521 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
@@ -33,7 +33,6 @@
 import org.apache.commons.lang3.builder.RecursiveToStringStyle;
 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
-//import org.apache.log4j.Logger;
 
 
 
@@ -140,7 +139,7 @@
 		 * This is the map of mismatched entries indexed by className. For
 		 * each class name there is a list of mismatched entries
 		 */
-		HashMap<String,HashSet<Object>> misMatchedMap = new HashMap<String,HashSet<Object>>();
+		HashMap<String,HashSet<Object>> misMatchedMap = new HashMap<>();
 		
 		// We need to keep track of how long the audit is taking
 		long startTime = System.currentTimeMillis();
@@ -350,8 +349,7 @@
 	 * @throws InterruptedException
 	 * @throws DbDaoTransactionException
 	 */
-	public void dbAuditSimulate(String resourceName, String persistenceUnit,
-			String nodeType) throws InterruptedException,
+	public void dbAuditSimulate(String resourceName, String persistenceUnit) throws InterruptedException,
 			DbDaoTransactionException {
 
 		logger.info("dbAuditSimulate: Starting audit simulation for resourceName="
@@ -386,7 +384,7 @@
 		 * it is currently working on.
 		 * 
 		 */
-		HashSet<Object> misMatchedKeySet = new HashSet<Object>();
+		HashSet<Object> misMatchedKeySet = new HashSet<>();
 		for(Object key: myEntries.keySet()){
 			byte[] mySerializedEntry = SerializationUtils.serialize((Serializable) myEntries.get(key));
 			byte[] theirSerializedEntry = SerializationUtils.serialize((Serializable) theirEntries.get(key));
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
index 0db43bb..20132ae 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java
@@ -40,7 +40,6 @@
 import javax.persistence.metamodel.ManagedType;
 import javax.persistence.metamodel.Metamodel;
 
-//import org.apache.log4j.Logger;
 
 import org.onap.policy.common.ia.jpa.IntegrityAuditEntity;
 import org.onap.policy.common.logging.flexlogger.FlexLogger; 
@@ -125,7 +124,7 @@
 	public HashMap<Object, Object> getAllMyEntries(String className) {
 		logger.debug("getAllMyEntries: Entering, className="
 				+ className);
-		HashMap<Object, Object> resultMap = new HashMap<Object,Object>();
+		HashMap<Object, Object> resultMap = new HashMap<>();
 		EntityManager em = emf.createEntityManager();
 		try{
 			CriteriaBuilder cb = em.getCriteriaBuilder();
@@ -162,7 +161,7 @@
 		logger.debug("getAllMyEntries: Entering, className="
 				+ className + ",\n keySet=" + keySet);
 
-		HashMap<Object, Object> resultMap = new HashMap<Object,Object>();
+		HashMap<Object, Object> resultMap = new HashMap<>();
 		EntityManager em = emf.createEntityManager();
 		try{
 			Class<?> clazz = Class.forName(className);
@@ -193,7 +192,7 @@
 		
 		logger.debug("getAllEntries: Entering, persistenceUnit="
 				+ persistenceUnit + ",\n className=" + className);
-		HashMap<Object, Object> resultMap = new HashMap<Object,Object>();
+		HashMap<Object, Object> resultMap = new HashMap<>();
 
 		EntityManagerFactory theEmf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
 		EntityManager em = theEmf.createEntityManager();
@@ -238,7 +237,7 @@
 				+ persistenceUnit + ",\n properties= " + properties + ",\n className=" + className + ",\n keySet= " + keySet);
 		EntityManagerFactory theEmf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
 		EntityManager em = theEmf.createEntityManager();
-		HashMap<Object, Object> resultMap = new HashMap<Object,Object>();
+		HashMap<Object, Object> resultMap = new HashMap<>();
 		try{
 			Class<?> clazz = Class.forName(className);
 			for(Object key : keySet){
@@ -386,7 +385,7 @@
 	 */
 	public HashSet<String> getPersistenceClassNames(){
 		logger.debug("DbDAO: getPersistenceClassNames() entry");
-		HashSet<String> returnList = new HashSet<String>();
+		HashSet<String> returnList = new HashSet<>();
 		final Metamodel mm = emf.getMetamodel();
 		logger.debug("\n" + persistenceUnit +" persistence unit classes:");
 		for (final ManagedType<?> managedType : mm.getManagedTypes()) {
@@ -417,7 +416,7 @@
 
 			@SuppressWarnings("rawtypes")
 			List iaeList = iaequery.getResultList();
-			IntegrityAuditEntity iae = null;
+			IntegrityAuditEntity iae;
 
 			//If it already exists, we just want to update the properties and lastUpdated date
 			if(!iaeList.isEmpty()){
@@ -453,7 +452,7 @@
 			et.commit();
 			em.close();
 		}catch (Exception e){
-			String msg = "DbDAO: " + "register() " + "ecountered a problem in execution: ";
+			String msg = "DbDAO: " + "register() " + "encountered a problem in execution: ";
 			logger.error(msg + e);
 			System.out.println(new Date());
 			e.printStackTrace();
@@ -486,7 +485,7 @@
 
 			@SuppressWarnings("rawtypes")
 			List iaeList = iaequery.getResultList();
-			IntegrityAuditEntity iae = null;
+			IntegrityAuditEntity iae;
 
 			if(!iaeList.isEmpty()){
 				//ignores multiple results
@@ -539,7 +538,7 @@
 
 			@SuppressWarnings("rawtypes")
 			List iaeList = iaequery.getResultList();
-			IntegrityAuditEntity iae = null;
+			IntegrityAuditEntity iae;
 
 			if(!iaeList.isEmpty()){
 				//ignores multiple results
@@ -582,7 +581,7 @@
 		
 		try{
 			
-			if (!IntegrityAudit.isUnitTesting) {
+			if (!IntegrityAudit.isUnitTesting()) {
 				String msg = "DbDAO: " + "deleteAllIntegrityAuditEntities() " + "should only be invoked during JUnit testing";
 				logger.error(msg);
 				throw new DbDaoTransactionException(msg);
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
index 5ec6229..50fc693 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
@@ -22,7 +22,6 @@
 
 import java.util.Properties;
 
-//import org.apache.log4j.Logger;
 
 import org.onap.policy.common.ia.IntegrityAuditProperties.NodeTypeEnum;
 import org.onap.policy.common.logging.flexlogger.FlexLogger; 
@@ -36,7 +35,7 @@
 	
 	private static final Logger logger = FlexLogger.getLogger(IntegrityAudit.class);
 
-	public static boolean isUnitTesting;
+	private static boolean isUnitTesting;
 	private boolean isThreadInitialized = false; 
 	
 	AuditThread auditThread = null;
@@ -65,7 +64,7 @@
 	 * @param properties
 	 * @throws Exception
 	 */
-	public IntegrityAudit(String resourceName, String persistenceUnit, Properties properties) throws Exception {
+	public IntegrityAudit(String resourceName, String persistenceUnit, Properties properties) throws IntegrityAuditException {
 		
 		logger.info("Constructor: Entering and checking for nulls");
 		String parmList = "";
@@ -73,7 +72,7 @@
 			logger.error("Constructor: Parms contain nulls; cannot run audit for resourceName="
 					+ resourceName + ", persistenceUnit=" + persistenceUnit
 					+ ", bad parameters: " + parmList);
-			throw new Exception(
+			throw new IntegrityAuditException(
 					"Constructor: Parms contain nulls; cannot run audit for resourceName="
 							+ resourceName + ", persistenceUnit="
 							+ persistenceUnit
@@ -238,4 +237,12 @@
 		logger.info("setThreadInitialized: Setting isThreadInitialized=" + isThreadInitialized);
 		this.isThreadInitialized = isThreadInitialized;
 	}
+
+	public static boolean isUnitTesting() {
+		return isUnitTesting;
+	}
+
+	public static void setUnitTesting(boolean isUnitTesting) {
+		IntegrityAudit.isUnitTesting = isUnitTesting;
+	}
 }
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditException.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditException.java
new file mode 100644
index 0000000..4068ffe
--- /dev/null
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditException.java
@@ -0,0 +1,17 @@
+package org.onap.policy.common.ia;
+
+public class IntegrityAuditException extends Exception{
+	private static final long serialVersionUID = 1L;
+	public IntegrityAuditException() {
+	}
+	public IntegrityAuditException(String message) {
+		super(message);
+	}
+
+	public IntegrityAuditException(Throwable cause) {
+		super(cause);
+	}
+	public IntegrityAuditException(String message, Throwable cause) {
+		super(message, cause);
+	}
+}
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
index 3f87cf2..d0781e9 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
@@ -38,7 +38,7 @@
 	public static final String SITE_NAME = "site_name";
 	public static final String NODE_TYPE = "node_type";
 	
-	public static enum NodeTypeEnum {
+	public enum NodeTypeEnum {
 		pdp_xacml,
 		pdp_drools,
 		pap,
@@ -51,4 +51,8 @@
 
 	}
 	
+	private IntegrityAuditProperties() {
+		
+	}
+	
 }
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java
index 2b68a51..50e2515 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java
@@ -49,7 +49,7 @@
 public class IntegrityAuditEntity implements Serializable {
 	private static final long serialVersionUID = 1L;
 
-	public static boolean isUnitTesting;
+	private static boolean isUnitTesting;
 	
 	@Id
 	@GeneratedValue(strategy = GenerationType.AUTO)
@@ -104,7 +104,7 @@
 	
 	@PreUpdate
 	public void preUpdate() {
-		if (!isUnitTesting) {
+		if (!isUnitTesting()) {
 			this.lastUpdated = new Date();
 		}
 	}
@@ -200,4 +200,12 @@
 	public void setCreatedDate(Date created) {
 		this.createdDate = created;
 	}
+
+	public static boolean isUnitTesting() {
+		return isUnitTesting;
+	}
+
+	public static void setUnitTesting(boolean isUnitTesting) {
+		IntegrityAuditEntity.isUnitTesting = isUnitTesting;
+	}
 }
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/AuditPeriodTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/AuditPeriodTest.java
index 52f847c..848f670 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/AuditPeriodTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/AuditPeriodTest.java
@@ -74,7 +74,7 @@
 
 		logger.info("setUp: Entering");
 
-		IntegrityAudit.isUnitTesting = true;
+		IntegrityAudit.setUnitTesting(true);
 		
 		properties = new Properties();
 		properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java
index 8a81136..c41803a 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java
@@ -80,7 +80,7 @@
 
 		logger.info("setUp: Entering");
 
-		IntegrityAudit.isUnitTesting = true;
+		IntegrityAudit.setUnitTesting(true);
 		
 		properties = new Properties();
 		properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);
@@ -446,7 +446,7 @@
 
 		logger.info("Setting up DB");
 
-		IntegrityAudit.isUnitTesting = true;
+		IntegrityAudit.setUnitTesting(true);
 		
 		properties = new Properties();
 		properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditTest.java
index fd1172a..e2aa998 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditTest.java
@@ -113,8 +113,8 @@
 
 		logger.info("setUp: Entering");
 
-		IntegrityAudit.isUnitTesting = true;
-		IntegrityAuditEntity.isUnitTesting = true;
+		IntegrityAudit.setUnitTesting(true);
+		IntegrityAuditEntity.setUnitTesting(true);
 		
 		properties = new Properties();
 		properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/IntegrityAuditDesignationTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/IntegrityAuditDesignationTest.java
index f74b354..91371b9 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/IntegrityAuditDesignationTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/IntegrityAuditDesignationTest.java
@@ -79,7 +79,7 @@
 
 		logger.info("setUp: Entering");
 
-		IntegrityAudit.isUnitTesting = true;
+		IntegrityAudit.setUnitTesting(true);
 		
 		properties = new Properties();
 		properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);