diff options
author | Jim Hahn <jrh3@att.com> | 2020-06-17 08:37:15 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-06-17 11:45:16 -0400 |
commit | 611f63a4bb71d677cf2665b1794e91148ba42a51 (patch) | |
tree | c6f82e5ffcd10712e0279c40bf8e59ed49f2332e /integrity-monitor/src/main/java/org | |
parent | 3bd6679bd7d8f67b4827a610c25ed9671b74d89c (diff) |
Cleanup various sonar issues in policy-common
Addressed the following issues:
- unused imports
- unused method parameters
- use assertEquals, assertSame instead of assertTrue
- provide the parametrized type for this generic
Also fixed some checkstyle issues:
- removed blank lines between "import" groups
Issue-ID: POLICY-2650
Change-Id: I004bb650ac10c49ccd0fc405f6959896fec39f9b
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-monitor/src/main/java/org')
6 files changed, 95 insertions, 91 deletions
diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java index d12a9bde..33c51e21 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java @@ -43,6 +43,7 @@ import javax.persistence.FlushModeType; import javax.persistence.LockModeType; import javax.persistence.Persistence; import javax.persistence.Query; +import javax.persistence.TypedQuery; import org.apache.commons.lang3.StringUtils; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.onap.policy.common.im.jmx.ComponentAdmin; @@ -287,15 +288,15 @@ public class IntegrityMonitor { } protected void createOrUpdateForwardProgress(String resourceName) { - Query fquery = em.createQuery(QUERY_STRING); + TypedQuery<ForwardProgressEntity> fquery = em.createQuery(QUERY_STRING, ForwardProgressEntity.class); fquery.setParameter("rn", resourceName); - @SuppressWarnings("rawtypes") - List fpList = fquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + List<ForwardProgressEntity> fpList = + fquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); ForwardProgressEntity fpx = null; if (!fpList.isEmpty()) { // ignores multiple results - fpx = (ForwardProgressEntity) fpList.get(0); + fpx = fpList.get(0); // refresh the object from DB in case cached data was returned em.refresh(fpx); if (logger.isDebugEnabled()) { @@ -318,15 +319,17 @@ public class IntegrityMonitor { } protected void createOrUpdateResourceReg(String resourceName, String jmxUrl, EntityTransaction et) { - Query rquery = em.createQuery("Select r from ResourceRegistrationEntity r where r.resourceName=:rn"); + TypedQuery<ResourceRegistrationEntity> rquery = + em.createQuery("Select r from ResourceRegistrationEntity r where r.resourceName=:rn", + ResourceRegistrationEntity.class); rquery.setParameter("rn", resourceName); - @SuppressWarnings("rawtypes") - List rrList = rquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + List<ResourceRegistrationEntity> rrList = + rquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); ResourceRegistrationEntity rrx = null; if (!rrList.isEmpty()) { // ignores multiple results - rrx = (ResourceRegistrationEntity) rrList.get(0); + rrx = rrList.get(0); // refresh the object from DB in case cached data was returned em.refresh(rrx); if (logger.isDebugEnabled()) { @@ -555,41 +558,44 @@ public class IntegrityMonitor { AtomicReference<StateManagementEntity> stateManagementEntity = new AtomicReference<>(); String errorMsg = - withinTransaction(dep + ": ForwardProgressEntity DB operation failed with exception: ", () -> { - Query query = - em.createQuery("Select p from ForwardProgressEntity p where p.resourceName=:resource"); - query.setParameter(LC_RESOURCE_STRING, dep); + withinTransaction(dep + ": ForwardProgressEntity DB operation failed with exception: ", () -> { + TypedQuery<ForwardProgressEntity> query = em.createQuery( + "Select p from ForwardProgressEntity p where p.resourceName=:resource", + ForwardProgressEntity.class); + query.setParameter(LC_RESOURCE_STRING, dep); - @SuppressWarnings("rawtypes") - List fpList = - query.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + List<ForwardProgressEntity> fpList = query.setLockMode(LockModeType.NONE) + .setFlushMode(FlushModeType.COMMIT).getResultList(); - if (!fpList.isEmpty()) { - // exists - forwardProgressEntity.set((ForwardProgressEntity) fpList.get(0)); - // refresh the object from DB in case cached data was - // returned - em.refresh(forwardProgressEntity.get()); - logger.debug("Found entry in ForwardProgressEntity table for dependent Resource={}", dep); - return null; - - } else { - return dep + ": resource not found in ForwardProgressEntity database table"; - } - }); + if (!fpList.isEmpty()) { + // exists + forwardProgressEntity.set(fpList.get(0)); + // refresh the object from DB in case cached data was + // returned + em.refresh(forwardProgressEntity.get()); + logger.debug("Found entry in ForwardProgressEntity table for dependent Resource={}", + dep); + return null; + + } else { + return dep + ": resource not found in ForwardProgressEntity database table"; + } + }); if (errorMsg == null) { errorMsg = withinTransaction(dep + ": StateManagementEntity DB read failed with exception: ", () -> { // query if StateManagement entry exists for dependent resource - Query query = em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource"); + TypedQuery<StateManagementEntity> query = + em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource", + StateManagementEntity.class); query.setParameter(LC_RESOURCE_STRING, dep); - @SuppressWarnings("rawtypes") - List smList = query.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + List<StateManagementEntity> smList = + query.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); if (!smList.isEmpty()) { // exist - stateManagementEntity.set((StateManagementEntity) smList.get(0)); + stateManagementEntity.set(smList.get(0)); // refresh the object from DB in case cached data was // returned em.refresh(stateManagementEntity.get()); @@ -713,15 +719,15 @@ public class IntegrityMonitor { } private String fpCheck2(String dep) { - Query fquery = em.createQuery(QUERY_STRING); + TypedQuery<ForwardProgressEntity> fquery = em.createQuery(QUERY_STRING, ForwardProgressEntity.class); fquery.setParameter("rn", dep); - @SuppressWarnings("rawtypes") - List fpList = fquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + List<ForwardProgressEntity> fpList = + fquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); ForwardProgressEntity fpx; if (!fpList.isEmpty()) { // ignores multiple results - fpx = (ForwardProgressEntity) fpList.get(0); + fpx = fpList.get(0); // refresh the object from DB in case cached data was returned em.refresh(fpx); if (logger.isDebugEnabled()) { @@ -794,16 +800,18 @@ public class IntegrityMonitor { private String getJmxUrlFromDb(String dep, AtomicReference<String> jmxUrl) { // query if ResourceRegistration entry exists for resourceName - Query rquery = em.createQuery("Select r from ResourceRegistrationEntity r where r.resourceName=:rn"); + TypedQuery<ResourceRegistrationEntity> rquery = + em.createQuery("Select r from ResourceRegistrationEntity r where r.resourceName=:rn", + ResourceRegistrationEntity.class); rquery.setParameter("rn", dep); - @SuppressWarnings("rawtypes") - List rrList = rquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + List<ResourceRegistrationEntity> rrList = + rquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); ResourceRegistrationEntity rrx = null; if (!rrList.isEmpty()) { // ignores multiple results - rrx = (ResourceRegistrationEntity) rrList.get(0); + rrx = rrList.get(0); // refresh the object from DB in case cached data was // returned em.refresh(rrx); @@ -1197,15 +1205,15 @@ public class IntegrityMonitor { try { // query if ForwardProgress entry exists for resourceName - Query fquery = em.createQuery(QUERY_STRING); + TypedQuery<ForwardProgressEntity> fquery = em.createQuery(QUERY_STRING, ForwardProgressEntity.class); fquery.setParameter("rn", resourceName); - @SuppressWarnings("rawtypes") - List fpList = fquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + List<ForwardProgressEntity> fpList = + fquery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); ForwardProgressEntity fpx; if (!fpList.isEmpty()) { // ignores multiple results - fpx = (ForwardProgressEntity) fpList.get(0); + fpx = fpList.get(0); // refresh the object from DB in case cached data was returned em.refresh(fpx); if (logger.isDebugEnabled()) { @@ -1544,14 +1552,16 @@ public class IntegrityMonitor { try { // query if StateManagement entry exists for fpe resource - Query query = em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource"); + TypedQuery<StateManagementEntity> query = + em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource", + StateManagementEntity.class); query.setParameter(LC_RESOURCE_STRING, fpe.getResourceName()); - @SuppressWarnings("rawtypes") - List smList = query.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); + List<StateManagementEntity> smList = + query.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList(); if (!smList.isEmpty()) { // exists - sme = (StateManagementEntity) smList.get(0); + sme = smList.get(0); // refresh the object from DB in case cached data was // returned em.refresh(sme); diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java index bd7ed7b5..cf7a968f 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jmx/ComponentAdmin.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,7 +22,6 @@ package org.onap.policy.common.im.jmx; import java.util.ArrayList; import java.util.Iterator; - import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceNotFoundException; import javax.management.MBeanRegistrationException; @@ -31,7 +30,6 @@ import javax.management.MBeanServerFactory; import javax.management.MalformedObjectNameException; import javax.management.NotCompliantMBeanException; import javax.management.ObjectName; - import org.onap.policy.common.im.IntegrityMonitor; import org.onap.policy.common.im.IntegrityMonitorException; import org.onap.policy.common.im.StateManagement; @@ -54,7 +52,7 @@ public class ComponentAdmin implements ComponentAdminMBean { /** * Constructor. - * + * * @param name the MBean name * @param integrityMonitor the integrity monitor * @param stateManager the state manager @@ -81,7 +79,7 @@ public class ComponentAdmin implements ComponentAdminMBean { /** * Registers with the MBean server. - * + * * @throws ComponentAdminException a JMX exception */ public synchronized void register() throws ComponentAdminException { @@ -114,7 +112,7 @@ public class ComponentAdmin implements ComponentAdminMBean { /** * Checks if this MBean is registered with the MBeanServer. - * + * * @return true if this MBean is registered with the MBeanServer. */ public boolean isRegistered() { @@ -123,7 +121,7 @@ public class ComponentAdmin implements ComponentAdminMBean { /** * Unregisters with the MBean server. - * + * * @throws ComponentAdminException a JMX exception */ public synchronized void unregister() throws ComponentAdminException { @@ -151,7 +149,7 @@ public class ComponentAdmin implements ComponentAdminMBean { /** * Finds the MBeanServer. - * + * * @return the MBeanServer, or null if it is not found */ public static MBeanServer findMBeanServer() { @@ -172,7 +170,7 @@ public class ComponentAdmin implements ComponentAdminMBean { /** * Creates the MBeanServer (intended for unit testing only). - * + * * @return the MBeanServer */ public static MBeanServer createMBeanServer() { @@ -181,7 +179,7 @@ public class ComponentAdmin implements ComponentAdminMBean { /** * Get the MBean object name for the specified feature name. - * + * * @param componentName component name * @return the object name * @throws MalformedObjectNameException a JMX exception diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java index f0ea2c00..0e0c24c6 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ForwardProgressEntity.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,7 +22,6 @@ package org.onap.policy.common.im.jpa; import java.io.Serializable; import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -91,7 +90,7 @@ public class ForwardProgressEntity implements Serializable { /** * Get the forward progress Id. - * + * * @return the Id */ public long getForwardProgressId() { @@ -108,7 +107,7 @@ public class ForwardProgressEntity implements Serializable { /** * Get the fpcCount. - * + * * @return the fpcCount */ public long getFpcCount() { @@ -117,7 +116,7 @@ public class ForwardProgressEntity implements Serializable { /** * Set the fpcCount. - * + * * @param fpcCount the fpcCount to set */ public void setFpcCount(long fpcCount) { @@ -126,7 +125,7 @@ public class ForwardProgressEntity implements Serializable { /** * Get the lastUpdated. - * + * * @return the lastUpdated */ public Date getLastUpdated() { @@ -135,7 +134,7 @@ public class ForwardProgressEntity implements Serializable { /** * Set the lastUpdated. - * + * * @param lastUpdated the lastUpdated to set */ public void setLastUpdated(Date lastUpdated) { diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ImTestEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ImTestEntity.java index 1822578b..6c710f27 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ImTestEntity.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ImTestEntity.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,7 +22,6 @@ package org.onap.policy.common.im.jpa; import java.io.Serializable; import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -87,7 +86,7 @@ public class ImTestEntity implements Serializable { /** * Get the Im test Id. - * + * * @return the Id */ public long getImTestId() { @@ -96,7 +95,7 @@ public class ImTestEntity implements Serializable { /** * Get the createdBy. - * + * * @return the createdBy */ public String getCreatedBy() { @@ -105,7 +104,7 @@ public class ImTestEntity implements Serializable { /** * Set the createdBy. - * + * * @param createdBy the createdBy to set */ public void setCreatedBy(String createdBy) { @@ -114,7 +113,7 @@ public class ImTestEntity implements Serializable { /** * Get the modifiedBy. - * + * * @return the modifiedBy */ public String getModifiedBy() { @@ -123,7 +122,7 @@ public class ImTestEntity implements Serializable { /** * Set the ModifiedBy. - * + * * @param modifiedBy the modifiedBy to set */ public void setModifiedBy(String modifiedBy) { @@ -132,7 +131,7 @@ public class ImTestEntity implements Serializable { /** * Get the modifiedDate. - * + * * @return the modifiedDate */ public Date getModifiedDate() { @@ -141,7 +140,7 @@ public class ImTestEntity implements Serializable { /** * Set the modifiedDate. - * + * * @param modifiedDate the modifiedDate to set */ public void setModifiedDate(Date modifiedDate) { @@ -150,7 +149,7 @@ public class ImTestEntity implements Serializable { /** * Get the createdDate. - * + * * @return the createdDate */ public Date getCreatedDate() { diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java index 42e141aa..e23553fa 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/ResourceRegistrationEntity.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,7 +22,6 @@ package org.onap.policy.common.im.jpa; import java.io.Serializable; import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -99,7 +98,7 @@ public class ResourceRegistrationEntity implements Serializable { /** * Get the resource registration Id. - * + * * @return the Id */ public long getResourceRegistrationId() { @@ -140,7 +139,7 @@ public class ResourceRegistrationEntity implements Serializable { /** * Get the createdDate. - * + * * @return the createdDate */ public Date getCreatedDate() { @@ -149,7 +148,7 @@ public class ResourceRegistrationEntity implements Serializable { /** * Get the lastUpdated. - * + * * @return the lastUpdated */ public Date getLastUpdated() { @@ -158,7 +157,7 @@ public class ResourceRegistrationEntity implements Serializable { /** * Set the lastUpdated. - * + * * @param lastUpdated the lastUpdated to set */ public void setLastUpdated(Date lastUpdated) { diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/StateManagementEntity.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/StateManagementEntity.java index 494931d2..30677814 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/StateManagementEntity.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/jpa/StateManagementEntity.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ package org.onap.policy.common.im.jpa; import java.io.Serializable; import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; |