From d00c73842c6f8e7bb00b29d2fb5dd63b9cde4bfe Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 12 May 2021 13:25:06 -0400 Subject: Fix sonars in policy models Fixed: - a few other "var" cases - use re2j instead of java.util.regex - use correct class for constants - remove unused constants Issue-ID: POLICY-3094 Change-Id: Ifcb2b0623e8df0527f0a279e666d062422978ded Signed-off-by: Jim Hahn --- .../java/org/onap/policy/models/dao/PfFilter.java | 3 +- .../onap/policy/models/dao/PfFilterFactory.java | 5 +- .../onap/policy/models/dao/impl/DefaultPfDao.java | 57 ++++++++++------------ 3 files changed, 31 insertions(+), 34 deletions(-) (limited to 'models-dao') diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/PfFilter.java b/models-dao/src/main/java/org/onap/policy/models/dao/PfFilter.java index fbe81b3ff..9ba2b4ee6 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/PfFilter.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/PfFilter.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -57,7 +58,7 @@ public abstract class PfFilter { public String addFilter(final String inputFilterString, final String name, final Instant startTime, final Instant endTime, final Map filterMap, final String sortOrder, final int getRecordNum) { - StringBuilder filterQueryString = new StringBuilder(inputFilterString); + var filterQueryString = new StringBuilder(inputFilterString); if (filterMap != null) { for (String key : filterMap.keySet()) { filterQueryString.append(getKeyPrefix() + key + "= :" + key + AND); diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/PfFilterFactory.java b/models-dao/src/main/java/org/onap/policy/models/dao/PfFilterFactory.java index 643481f39..fbfad18c2 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/PfFilterFactory.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/PfFilterFactory.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -20,8 +21,6 @@ package org.onap.policy.models.dao; -import java.time.Instant; -import java.util.Map; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.dao.impl.PfNonTimestampKeyFilter; import org.onap.policy.models.dao.impl.PfReferenceTimestampKeyFilter; @@ -67,7 +66,7 @@ public class PfFilterFactory { */ private String getKeyName(final Class someClass) { try { - String fullClassName = someClass.getDeclaredField("key").getType().toString(); + var fullClassName = someClass.getDeclaredField("key").getType().toString(); return fullClassName.substring(fullClassName.lastIndexOf('.') + 1); } catch (NoSuchFieldException e) { LOGGER.error("Error getting the key:", e); diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java index 1bd2e09da..42a06acc4 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java @@ -72,7 +72,6 @@ public class DefaultPfDao implements PfDao { private static final String WHERE = " WHERE "; private static final String AND = " AND "; - private static final String ORDER = " ORDER BY "; private static final String NAME_FILTER = "c.key.name = :name"; private static final String VERSION_FILTER = "c.key.version = :version"; @@ -83,8 +82,6 @@ public class DefaultPfDao implements PfDao { private static final String PARENT_VERSION_FILTER = "c.key.parentKeyVersion = :parentversion"; private static final String LOCAL_NAME_FILTER = "c.key.localName = :localname"; - private static final String PARENT_NAME_REF_FILTER = "c.key.referenceKey.parentKeyName = :parentKeyName"; - private static final String CLONE_ERR_MSG = "Could not clone object of class \"{}\""; private static final String DELETE_BY_CONCEPT_KEY = @@ -168,7 +165,7 @@ public class DefaultPfDao implements PfDao { if (obj == null) { return; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { mg.getTransaction().begin(); mg.merge(obj); @@ -183,7 +180,7 @@ public class DefaultPfDao implements PfDao { if (obj == null) { return; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { mg.getTransaction().begin(); mg.remove(mg.contains(obj) ? obj : mg.merge(obj)); @@ -198,7 +195,7 @@ public class DefaultPfDao implements PfDao { if (key == null) { return; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { // @formatter:off mg.getTransaction().begin(); @@ -218,7 +215,7 @@ public class DefaultPfDao implements PfDao { if (key == null) { return; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { // @formatter:off mg.getTransaction().begin(); @@ -239,7 +236,7 @@ public class DefaultPfDao implements PfDao { if (key == null) { return; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { // @formatter:off mg.getTransaction().begin(); @@ -260,7 +257,7 @@ public class DefaultPfDao implements PfDao { if (key == null) { return; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { // @formatter:off mg.getTransaction().begin(); @@ -281,7 +278,7 @@ public class DefaultPfDao implements PfDao { if (objs == null || objs.isEmpty()) { return; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { mg.getTransaction().begin(); for (final T t : objs) { @@ -298,7 +295,7 @@ public class DefaultPfDao implements PfDao { if (objs == null || objs.isEmpty()) { return; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { mg.getTransaction().begin(); for (final T t : objs) { @@ -315,8 +312,8 @@ public class DefaultPfDao implements PfDao { if (keys == null || keys.isEmpty()) { return 0; } - int deletedCount = 0; - final EntityManager mg = getEntityManager(); + var deletedCount = 0; + final var mg = getEntityManager(); try { // @formatter:off mg.getTransaction().begin(); @@ -340,8 +337,8 @@ public class DefaultPfDao implements PfDao { if (keys == null || keys.isEmpty()) { return 0; } - int deletedCount = 0; - final EntityManager mg = getEntityManager(); + var deletedCount = 0; + final var mg = getEntityManager(); try { // @formatter:off mg.getTransaction().begin(); @@ -362,7 +359,7 @@ public class DefaultPfDao implements PfDao { @Override public void deleteAll(final Class someClass) { - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { mg.getTransaction().begin(); mg.createQuery(setQueryTable(DELETE_FROM_TABLE, someClass), someClass).executeUpdate(); @@ -383,7 +380,7 @@ public class DefaultPfDao implements PfDao { return getAllVersions(someClass, name); } - T foundConcept = get(someClass, new PfConceptKey(name, version)); + var foundConcept = get(someClass, new PfConceptKey(name, version)); return (foundConcept == null ? Collections.emptyList() : Collections.singletonList(foundConcept)); } @@ -392,9 +389,9 @@ public class DefaultPfDao implements PfDao { public List getFiltered(final Class someClass, final String name, final String version, final Instant startTime, final Instant endTime, final Map filterMap, final String sortOrder, final int getRecordNum) { - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); - String filterQueryString = SELECT_FROM_TABLE + WHERE; + var filterQueryString = SELECT_FROM_TABLE + WHERE; try { PfFilter timeStampFilter = new PfFilterFactory().createFilter(someClass); @@ -464,9 +461,9 @@ public class DefaultPfDao implements PfDao { if (someClass == null) { return null; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { - final T t = mg.find(someClass, key); + final var t = mg.find(someClass, key); if (t != null) { mg.refresh(t); } @@ -481,7 +478,7 @@ public class DefaultPfDao implements PfDao { if (someClass == null) { return Collections.emptyList(); } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { return mg.createQuery(setQueryTable(SELECT_FROM_TABLE, someClass), someClass).getResultList(); } finally { @@ -494,7 +491,7 @@ public class DefaultPfDao implements PfDao { if (someClass == null) { return Collections.emptyList(); } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { // @formatter:off return mg.createQuery(setQueryTable(SELECT_ALL_FOR_PARENT, someClass), someClass) @@ -512,7 +509,7 @@ public class DefaultPfDao implements PfDao { if (someClass == null || parentKeyName == null) { return Collections.emptyList(); } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { // @formatter:off return mg.createQuery(setQueryTable(SELECT_ALL_VERSIONS_FOR_PARENT, someClass), someClass) @@ -529,7 +526,7 @@ public class DefaultPfDao implements PfDao { if (someClass == null || conceptName == null) { return Collections.emptyList(); } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { // @formatter:off return mg.createQuery(setQueryTable(SELECT_ALL_VERSIONS, someClass), someClass) @@ -549,7 +546,7 @@ public class DefaultPfDao implements PfDao { return Collections.emptyList(); } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); try { // @formatter:off return mg.createQuery(setQueryTable(SELECT_BY_TIMESTAMP_NOKEY, someClass), someClass) @@ -568,7 +565,7 @@ public class DefaultPfDao implements PfDao { if (someClass == null || key == null) { return null; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); List ret; try { // @formatter:off @@ -589,7 +586,7 @@ public class DefaultPfDao implements PfDao { if (someClass == null || key == null) { return null; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); List ret; try { // @formatter:off @@ -608,7 +605,7 @@ public class DefaultPfDao implements PfDao { @Override public T update(final T obj) { - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); T ret; try { mg.getTransaction().begin(); @@ -626,7 +623,7 @@ public class DefaultPfDao implements PfDao { if (someClass == null) { return 0; } - final EntityManager mg = getEntityManager(); + final var mg = getEntityManager(); long size = 0; try { size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) -- cgit 1.2.3-korg