summaryrefslogtreecommitdiffstats
path: root/integrity-audit/src/main/java/org
diff options
context:
space:
mode:
authorMagnusen, Drew (dm741q) <dm741q@att.com>2017-08-09 14:09:59 -0500
committerMagnusen, Drew (dm741q) <dm741q@att.com>2017-08-11 10:30:41 -0500
commit8e9b3d288bc5b51f691183715d5862489f09d95d (patch)
tree097f6f624b4bae9b19637c989f3d94d51580c017 /integrity-audit/src/main/java/org
parent96bca95f4610edfdabf1fddb981416235158312d (diff)
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>
Diffstat (limited to 'integrity-audit/src/main/java/org')
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java12
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java8
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java21
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java15
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditException.java17
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java6
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/jpa/IntegrityAuditEntity.java12
7 files changed, 61 insertions, 30 deletions
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 e7e16a64..2e15da5f 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.Comparator;
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 @@ public class AuditThread extends Thread {
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 @@ public class AuditThread extends Thread {
+ thisEntity.getLastUpdated());
}
- long timeDifference = -1;
+ long timeDifference;
Date currentTime = new Date();
Date lastUpdated = thisEntity.getLastUpdated();
@@ -752,9 +751,8 @@ public class AuditThread extends Thread {
+ 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 8312daa3..8a1a521b 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.SerializationUtils;
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 @@ public class DbAudit {
* 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 @@ public class DbAudit {
* @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 @@ public class DbAudit {
* 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 0db43bbc..20132ae1 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.criteria.Root;
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 class DbDAO {
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 @@ public class DbDAO {
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 @@ public class DbDAO {
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 @@ public class DbDAO {
+ 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 class DbDAO {
*/
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 @@ public class DbDAO {
@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 @@ public class DbDAO {
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 @@ public class DbDAO {
@SuppressWarnings("rawtypes")
List iaeList = iaequery.getResultList();
- IntegrityAuditEntity iae = null;
+ IntegrityAuditEntity iae;
if(!iaeList.isEmpty()){
//ignores multiple results
@@ -539,7 +538,7 @@ public class DbDAO {
@SuppressWarnings("rawtypes")
List iaeList = iaequery.getResultList();
- IntegrityAuditEntity iae = null;
+ IntegrityAuditEntity iae;
if(!iaeList.isEmpty()){
//ignores multiple results
@@ -582,7 +581,7 @@ public class DbDAO {
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 5ec6229c..50fc6932 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 @@ package org.onap.policy.common.ia;
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 @@ public class IntegrityAudit {
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 @@ public class IntegrityAudit {
* @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 @@ public class IntegrityAudit {
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 @@ public class IntegrityAudit {
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 00000000..4068ffe2
--- /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 3f87cf26..d0781e9c 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 class IntegrityAuditProperties {
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 @@ public class IntegrityAuditProperties {
}
+ 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 2b68a51d..50e25159 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 @@ import javax.persistence.TemporalType;
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 @@ public class IntegrityAuditEntity implements Serializable {
@PreUpdate
public void preUpdate() {
- if (!isUnitTesting) {
+ if (!isUnitTesting()) {
this.lastUpdated = new Date();
}
}
@@ -200,4 +200,12 @@ public class IntegrityAuditEntity implements Serializable {
public void setCreatedDate(Date created) {
this.createdDate = created;
}
+
+ public static boolean isUnitTesting() {
+ return isUnitTesting;
+ }
+
+ public static void setUnitTesting(boolean isUnitTesting) {
+ IntegrityAuditEntity.isUnitTesting = isUnitTesting;
+ }
}