summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2023-09-25 13:35:47 +0100
committerPriyank Maheshwari <priyank.maheshwari@est.tech>2023-09-29 15:01:10 +0000
commita6acaeae5e3d1b857d29001bee81c9a9add90dcc (patch)
treefa9db435d020e1b64cf4d2bfb22debb7d500798c
parentd91a707f99a42b9b2f230ec47a2ef6573431beea (diff)
Fix Sonar Code Smells
- convert normal java strings to text block - feature from java 15 - handling callback for legacy events. Once the deprecated methods are removed then this would not be needed. Issue-ID: CPS-89 Change-Id: I9b537ebee2c284c8109e6cc6c8961a430ee9599d Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java37
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDog.java2
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java26
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java93
4 files changed, 88 insertions, 70 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java
index 49e455e580..355e5cdf79 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/EventsPublisher.java
@@ -64,8 +64,8 @@ public class EventsPublisher<T> {
cloudEventKafkaTemplate.send(topicName, eventKey, event);
eventFuture.whenComplete((result, e) -> {
if (e == null) {
- log.debug("Successfully published event to topic : {} , Event : {}",
- result.getRecordMetadata().topic(), result.getProducerRecord().value());
+ log.debug("Successfully published event to topic : {} , Event : {}", result.getRecordMetadata().topic(),
+ result.getProducerRecord().value());
} else {
log.error("Unable to publish event to topic : {} due to {}", topicName, e.getMessage());
@@ -85,14 +85,7 @@ public class EventsPublisher<T> {
public void publishEvent(final String topicName, final String eventKey, final T event) {
final CompletableFuture<SendResult<String, T>> eventFuture =
legacyKafkaEventTemplate.send(topicName, eventKey, event);
- eventFuture.whenComplete((result, e) -> {
- if (e == null) {
- log.debug("Successfully published event to topic : {} , Event : {}",
- result.getRecordMetadata().topic(), result.getProducerRecord().value());
- } else {
- log.error("Unable to publish event to topic : {} due to {}", topicName, e.getMessage());
- }
- });
+ handleLegacyEventCallback(topicName, eventFuture);
}
/**
@@ -107,16 +100,8 @@ public class EventsPublisher<T> {
final ProducerRecord<String, T> producerRecord =
new ProducerRecord<>(topicName, null, eventKey, event, eventHeaders);
- final CompletableFuture<SendResult<String, T>> eventFuture =
- legacyKafkaEventTemplate.send(producerRecord);
- eventFuture.whenComplete((result, ex) -> {
- if (ex != null) {
- log.error("Unable to publish event to topic : {} due to {}", topicName, ex.getMessage());
- } else {
- log.debug("Successfully published event to topic : {} , Event : {}",
- result.getRecordMetadata().topic(), result.getProducerRecord().value());
- }
- });
+ final CompletableFuture<SendResult<String, T>> eventFuture = legacyKafkaEventTemplate.send(producerRecord);
+ handleLegacyEventCallback(topicName, eventFuture);
}
/**
@@ -133,6 +118,18 @@ public class EventsPublisher<T> {
publishEvent(topicName, eventKey, convertToKafkaHeaders(eventHeaders), event);
}
+ private void handleLegacyEventCallback(final String topicName,
+ final CompletableFuture<SendResult<String, T>> eventFuture) {
+ eventFuture.whenComplete((result, e) -> {
+ if (e != null) {
+ log.error("Unable to publish event to topic : {} due to {}", topicName, e.getMessage());
+ } else {
+ log.debug("Successfully published event to topic : {} , Event : {}", result.getRecordMetadata().topic(),
+ result.getProducerRecord().value());
+ }
+ });
+ }
+
private Headers convertToKafkaHeaders(final Map<String, Object> eventMessageHeaders) {
final Headers eventHeaders = new RecordHeaders();
eventMessageHeaders.forEach((key, value) -> eventHeaders.add(key, SerializationUtils.serialize(value)));
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDog.java
index dac32aa736..d3b95eacbf 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDog.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDog.java
@@ -46,7 +46,7 @@ public class DMiPluginWatchDog {
*/
@Scheduled(fixedDelayString = "${ncmp.timers.trust-evel.dmi-availability-watchdog-ms:30000}")
public void watchDmiPluginAliveness() {
- trustLevelPerDmiPlugin.keySet().forEach((dmiPluginName) -> {
+ trustLevelPerDmiPlugin.keySet().forEach(dmiPluginName -> {
final DmiPluginStatus dmiPluginStatus = dmiRestClient.getDmiPluginStatus(dmiPluginName);
log.debug("Trust level for dmi-plugin: {} is {}", dmiPluginName, dmiPluginStatus.toString());
if (DmiPluginStatus.UP.equals(dmiPluginStatus)) {
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
index b8503a7fea..19646c5239 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
@@ -70,13 +70,25 @@ public interface AnchorRepository extends JpaRepository<AnchorEntity, Long> {
Integer countByDataspace(DataspaceEntity dataspaceEntity);
- @Query(value = "SELECT anchor.* FROM yang_resource\n"
- + "JOIN schema_set_yang_resources ON schema_set_yang_resources.yang_resource_id = yang_resource.id\n"
- + "JOIN schema_set ON schema_set.id = schema_set_yang_resources.schema_set_id\n"
- + "JOIN anchor ON anchor.schema_set_id = schema_set.id\n"
- + "WHERE schema_set.dataspace_id = :dataspaceId AND module_name = ANY (:moduleNames)\n"
- + "GROUP BY anchor.id, anchor.name, anchor.dataspace_id, anchor.schema_set_id\n"
- + "HAVING COUNT(DISTINCT module_name) = :sizeOfModuleNames", nativeQuery = true)
+ @Query(value = """
+ SELECT
+ anchor.*
+ FROM
+ yang_resource
+ JOIN schema_set_yang_resources ON schema_set_yang_resources.yang_resource_id = yang_resource.id
+ JOIN schema_set ON schema_set.id = schema_set_yang_resources.schema_set_id
+ JOIN anchor ON anchor.schema_set_id = schema_set.id
+ WHERE
+ schema_set.dataspace_id = :dataspaceId
+ AND module_name = ANY ( :moduleNames )
+ GROUP BY
+ anchor.id,
+ anchor.name,
+ anchor.dataspace_id,
+ anchor.schema_set_id
+ HAVING
+ COUNT(DISTINCT module_name) = :sizeOfModuleNames
+ """, nativeQuery = true)
Collection<AnchorEntity> getAnchorsByDataspaceIdAndModuleNames(@Param("dataspaceId") int dataspaceId,
@Param("moduleNames") String[] moduleNames,
@Param("sizeOfModuleNames") int sizeOfModuleNames);
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
index df21ccc52e..e833796337 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
@@ -41,56 +41,65 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity
return findAllByChecksumIn(checksums.toArray(new String[0]));
}
- @Query(value = "SELECT DISTINCT\n"
- + "yang_resource.module_name AS module_name,\n"
- + "yang_resource.revision AS revision\n"
- + "FROM\n"
- + "dataspace\n"
- + "JOIN schema_set ON schema_set.dataspace_id = dataspace.id\n"
- + "JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = "
- + "schema_set.id\n"
- + "JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id\n"
- + "WHERE\n"
- + "dataspace.name = :dataspaceName", nativeQuery = true)
+ @Query(value = """
+ SELECT DISTINCT
+ yang_resource.module_name AS module_name,
+ yang_resource.revision AS revision
+ FROM
+ dataspace
+ JOIN schema_set ON schema_set.dataspace_id = dataspace.id
+ JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id
+ JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id
+ WHERE
+ dataspace.name = :dataspaceName
+ """, nativeQuery = true)
Set<YangResourceModuleReference> findAllModuleReferencesByDataspace(@Param("dataspaceName") String dataspaceName);
- @Query(value = "SELECT DISTINCT\n"
- + "yang_resource.module_Name AS module_name,\n"
- + "yang_resource.revision AS revision\n"
- + "FROM\n"
- + "dataspace\n"
- + "JOIN anchor ON anchor.dataspace_id = dataspace.id\n"
- + "JOIN schema_set ON schema_set.id = anchor.schema_set_id\n"
- + "JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = "
- + "schema_set.id\n"
- + "JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id\n"
- + "WHERE\n"
- + "dataspace.name = :dataspaceName AND\n"
- + "anchor.name =:anchorName", nativeQuery = true)
+ @Query(value = """
+ SELECT DISTINCT
+ yang_resource.module_name AS module_name,
+ yang_resource.revision AS revision
+ FROM
+ dataspace
+ JOIN anchor ON anchor.dataspace_id = dataspace.id
+ JOIN schema_set ON schema_set.id = anchor.schema_set_id
+ JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id
+ JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id
+ WHERE
+ dataspace.name = :dataspaceName
+ AND anchor.name = :anchorName
+ """, nativeQuery = true)
Set<YangResourceModuleReference> findAllModuleReferencesByDataspaceAndAnchor(
@Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
- @Query(value = "SELECT DISTINCT yang_resource.*\n"
- + "FROM dataspace\n"
- + "JOIN anchor ON anchor.dataspace_id = dataspace.id\n"
- + "JOIN schema_set ON schema_set.id = anchor.schema_set_id\n"
- + "JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id\n"
- + "JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id\n"
- + "WHERE dataspace.name = :dataspaceName "
- + "AND anchor.name =:anchorName", nativeQuery = true)
+ @Query(value = """
+ SELECT DISTINCT
+ yang_resource.*
+ FROM
+ dataspace
+ JOIN anchor ON anchor.dataspace_id = dataspace.id
+ JOIN schema_set ON schema_set.id = anchor.schema_set_id
+ JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id
+ JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id
+ WHERE
+ dataspace.name = :dataspaceName
+ AND anchor.name = :anchorName
+ """, nativeQuery = true)
Set<YangResourceEntity> findAllModuleDefinitionsByDataspaceAndAnchor(
@Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
- @Query(value = "SELECT DISTINCT\n"
- + "yang_resource.*\n"
- + "FROM\n"
- + "dataspace\n"
- + "JOIN schema_set ON schema_set.dataspace_id = dataspace.id\n"
- + "JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = "
- + "schema_set.id\n"
- + "JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id\n"
- + "WHERE\n"
- + "dataspace.name = :dataspaceName and yang_resource.module_Name = ANY (:moduleNames)", nativeQuery = true)
+ @Query(value = """
+ SELECT DISTINCT
+ yang_resource.*
+ FROM
+ dataspace
+ JOIN schema_set ON schema_set.dataspace_id = dataspace.id
+ JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id
+ JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id
+ WHERE
+ dataspace.name = :dataspaceName
+ AND yang_resource.module_name = ANY ( :moduleNames )
+ """, nativeQuery = true)
Set<YangResourceModuleReference> findAllModuleReferencesByDataspaceAndModuleNames(
@Param("dataspaceName") String dataspaceName, @Param("moduleNames") String[] moduleNames);