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>
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;
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
+ thisEntity.getLastUpdated());
}
- long timeDifference = -1;
+ long timeDifference;
Date currentTime = new Date();
Date lastUpdated = thisEntity.getLastUpdated();
+ 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);
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;
* 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();
* @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="
* 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));
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;
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();
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);
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();
+ 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){
*/
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()) {
@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()){
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();
@SuppressWarnings("rawtypes")
List iaeList = iaequery.getResultList();
- IntegrityAuditEntity iae = null;
+ IntegrityAuditEntity iae;
if(!iaeList.isEmpty()){
//ignores multiple results
@SuppressWarnings("rawtypes")
List iaeList = iaequery.getResultList();
- IntegrityAuditEntity iae = null;
+ IntegrityAuditEntity iae;
if(!iaeList.isEmpty()){
//ignores multiple results
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);
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;
private static final Logger logger = FlexLogger.getLogger(IntegrityAudit.class);
- public static boolean isUnitTesting;
+ private static boolean isUnitTesting;
private boolean isThreadInitialized = false;
AuditThread auditThread = null;
* @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 = "";
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
logger.info("setThreadInitialized: Setting isThreadInitialized=" + isThreadInitialized);
this.isThreadInitialized = isThreadInitialized;
}
+
+ public static boolean isUnitTesting() {
+ return isUnitTesting;
+ }
+
+ public static void setUnitTesting(boolean isUnitTesting) {
+ IntegrityAudit.isUnitTesting = isUnitTesting;
+ }
}
--- /dev/null
+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);
+ }
+}
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,
}
+ private IntegrityAuditProperties() {
+
+ }
+
}
public class IntegrityAuditEntity implements Serializable {
private static final long serialVersionUID = 1L;
- public static boolean isUnitTesting;
+ private static boolean isUnitTesting;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@PreUpdate
public void preUpdate() {
- if (!isUnitTesting) {
+ if (!isUnitTesting()) {
this.lastUpdated = new Date();
}
}
public void setCreatedDate(Date created) {
this.createdDate = created;
}
+
+ public static boolean isUnitTesting() {
+ return isUnitTesting;
+ }
+
+ public static void setUnitTesting(boolean isUnitTesting) {
+ IntegrityAuditEntity.isUnitTesting = isUnitTesting;
+ }
}
logger.info("setUp: Entering");
- IntegrityAudit.isUnitTesting = true;
+ IntegrityAudit.setUnitTesting(true);
properties = new Properties();
properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);
logger.info("setUp: Entering");
- IntegrityAudit.isUnitTesting = true;
+ IntegrityAudit.setUnitTesting(true);
properties = new Properties();
properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);
logger.info("Setting up DB");
- IntegrityAudit.isUnitTesting = true;
+ IntegrityAudit.setUnitTesting(true);
properties = new Properties();
properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);
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);
logger.info("setUp: Entering");
- IntegrityAudit.isUnitTesting = true;
+ IntegrityAudit.setUnitTesting(true);
properties = new Properties();
properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER);