From 0bc3587c7e370d1a7ea8e02486b095fb87a1c12d Mon Sep 17 00:00:00 2001 From: Alexandra Bucur Date: Fri, 16 Dec 2022 14:36:35 +0200 Subject: [PATCH 1/8] Create Jackson object mapper, reader and writers at class level Signed-off-by: Alexandra Bucur --- .../OpenMetadataConformanceTestReport.java | 9 +- .../assets/DatabaseContextHandler.java | 54 ++++++--- .../converters/AssetConverter.java | 15 +-- .../utils/AnalyticsAssetUtils.java | 19 +-- .../AssetCatalogSearchPublisher.java | 13 +- .../AssetConsumerOutTopicServerConnector.java | 7 +- .../outtopic/AssetLineagePublisher.java | 5 +- .../AssetManagerOutTopicServerConnector.java | 7 +- .../AssetOwnerOutTopicServerConnector.java | 7 +- ...mmunityProfileOutTopicServerConnector.java | 7 +- .../listeners/DataEngineInTopicListener.java | 11 +- .../processors/DataEngineEventProcessor.java | 114 +++++++++--------- .../DataEngineInTopicClientConnector.java | 7 +- .../DataManagerOutTopicServerConnector.java | 7 +- ...alArchitectureOutTopicServerConnector.java | 7 +- ...vernanceEngineOutTopicServerConnector.java | 7 +- ...InfrastructureOutTopicServerConnector.java | 6 +- ...ecurityManagerOutTopicServerConnector.java | 7 +- .../publisher/SecurityOfficerPublisher.java | 5 +- ...ecurityOfficerOutTopicServerConnector.java | 7 +- ...wardshipActionOutTopicServerConnector.java | 7 +- .../outtopic/SubjectAreaPublisher.java | 6 +- ...edFileBasedServerConfigStoreConnector.java | 14 ++- .../FileBasedServerConfigStoreConnector.java | 16 ++- ...OriginSeekerGovernanceActionConnector.java | 5 +- .../ElasticsearchIntegrationConnector.java | 6 +- .../OpenAPIMonitorIntegrationConnector.java | 5 +- .../OpenLineageLogStoreConnectorBase.java | 6 +- .../file/FileBasedAuditLogStoreConnector.java | 6 +- .../file/FileBasedRegistryStoreConnector.java | 14 ++- ...irectoryBasedOpenMetadataArchiveStore.java | 16 ++- ...BasedOpenMetadataArchiveStoreIterator.java | 5 +- ...asedOpenMetadataArchiveStoreConnector.java | 13 +- .../GraphOMRSClassificationMapper.java | 52 +++++--- .../GraphOMRSEntityMapper.java | 38 +++--- .../GraphOMRSRelationshipMapper.java | 30 ++--- .../listeners/OpenLineageInTopicListener.java | 35 +++--- .../LineageIntegratorContextManager.java | 10 +- .../omrstopic/OMRSTopicConnector.java | 15 ++- ...penMetadataTopicListenerConnectorBase.java | 6 +- .../OMRSAuditLogStoreConnectorBase.java | 7 +- .../archiveutilities/OMRSArchiveGUIDMap.java | 12 +- .../springboot/auth/AuthService.java | 6 +- .../springboot/auth/TokenService.java | 10 +- .../synchronization/SynchronizationTest.java | 14 +-- .../fvt/opentypes/model/OmrsBeanModel.java | 25 +++- .../test/unittest/utilities/BeanTestBase.java | 11 +- 47 files changed, 426 insertions(+), 285 deletions(-) diff --git a/open-metadata-conformance-suite/open-metadata-conformance-suite-client/src/main/java/org/odpi/openmetadata/conformance/client/OpenMetadataConformanceTestReport.java b/open-metadata-conformance-suite/open-metadata-conformance-suite-client/src/main/java/org/odpi/openmetadata/conformance/client/OpenMetadataConformanceTestReport.java index 9da5c39f0c7..3b9d0770582 100644 --- a/open-metadata-conformance-suite/open-metadata-conformance-suite-client/src/main/java/org/odpi/openmetadata/conformance/client/OpenMetadataConformanceTestReport.java +++ b/open-metadata-conformance-suite/open-metadata-conformance-suite-client/src/main/java/org/odpi/openmetadata/conformance/client/OpenMetadataConformanceTestReport.java @@ -3,6 +3,7 @@ package org.odpi.openmetadata.conformance.client; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; import org.odpi.openmetadata.adapters.connectors.restclients.ffdc.exceptions.RESTConfigurationException; import org.odpi.openmetadata.adapters.connectors.restclients.ffdc.exceptions.RESTServerException; @@ -25,12 +26,14 @@ */ public class OpenMetadataConformanceTestReport { + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + private String serverName; /* Initialized in constructor */ private String serverURLRoot; /* Initialized in constructor */ private String testClientUserId; /* Initialized in constructor */ private RESTClient restClient; /* Initialized in constructor */ - private final ObjectMapper objectMapper; private RESTExceptionHandler exceptionHandler = new RESTExceptionHandler(); /** @@ -49,7 +52,6 @@ private OpenMetadataConformanceTestReport(String serverName, this.serverURLRoot = serverURLRoot; this.testClientUserId = testClientUserId; - this.objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); this.restClient = new RESTClient(serverName, serverURLRoot); } @@ -72,7 +74,6 @@ private OpenMetadataConformanceTestReport(String serverName, this.serverURLRoot = serverURLRoot; this.testClientUserId = testClientUserId; - this.objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); this.restClient = new RESTClient(serverName, serverURLRoot, testClientUserId, testClientPassword); } @@ -290,7 +291,7 @@ private void writeJsonToFile(String path, Object value) throws IOException { String noSpaces = path.replaceAll("\\s+", "_"); File file = new File(noSpaces); - objectMapper.writeValue(file, value); + OBJECT_WRITER.writeValue(file, value); } diff --git a/open-metadata-implementation/access-services/analytics-modeling/analytics-modeling-server/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/assets/DatabaseContextHandler.java b/open-metadata-implementation/access-services/analytics-modeling/analytics-modeling-server/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/assets/DatabaseContextHandler.java index 225452a35d1..1ae6b76795b 100644 --- a/open-metadata-implementation/access-services/analytics-modeling/analytics-modeling-server/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/assets/DatabaseContextHandler.java +++ b/open-metadata-implementation/access-services/analytics-modeling/analytics-modeling-server/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/assets/DatabaseContextHandler.java @@ -2,21 +2,9 @@ /* Copyright Contributors to the ODPi Egeria project. */ package org.odpi.openmetadata.accessservices.analyticsmodeling.assets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.TreeMap; -import java.util.stream.Collectors; -import java.util.stream.Stream; - +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.apache.commons.collections4.CollectionUtils; import org.odpi.openmetadata.accessservices.analyticsmodeling.contentmanager.OMEntityDao; import org.odpi.openmetadata.accessservices.analyticsmodeling.converter.GlossaryTermConverter; @@ -25,8 +13,20 @@ import org.odpi.openmetadata.accessservices.analyticsmodeling.metadata.Database; import org.odpi.openmetadata.accessservices.analyticsmodeling.metadata.GlossaryTerm; import org.odpi.openmetadata.accessservices.analyticsmodeling.metadata.Schema; -import org.odpi.openmetadata.accessservices.analyticsmodeling.model.*; -import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.*; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.ModuleTableFilter; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.ResponseContainerDatabase; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.ResponseContainerDatabaseSchema; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.ResponseContainerModule; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.ResponseContainerSchemaTables; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.BaseObjectType; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.Column; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.DataSource; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.ForeignColumn; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.ForeignKey; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.MetadataModule; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.PrimaryKey; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.Table; +import org.odpi.openmetadata.accessservices.analyticsmodeling.model.module.TableItem; import org.odpi.openmetadata.accessservices.analyticsmodeling.model.response.Messages; import org.odpi.openmetadata.accessservices.analyticsmodeling.utils.Constants; import org.odpi.openmetadata.accessservices.analyticsmodeling.utils.ExecutionContext; @@ -42,8 +42,20 @@ import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.TreeMap; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * The class builds data content of the Analytics Modeling OMAS responses.
@@ -64,6 +76,8 @@ */ public class DatabaseContextHandler { + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + public static final String DATA_SOURCE_GUID = "dataSourceGUID"; private RelationalDataHandler { + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + public AssetConverter(OMRSRepositoryHelper repositoryHelper, String serviceName, String serverName) { super(repositoryHelper, serviceName, serverName); } @@ -63,7 +64,7 @@ public AnalyticsAsset getNewBean(Class beanClass, String jsonReference = props.get(Constants.REFERENCE); if (jsonReference != null && !jsonReference.isEmpty()) { try { - bean.setReference(new ObjectMapper() + bean.setReference(OBJECT_MAPPER .readValue(jsonReference.getBytes(), new TypeReference>(){})); } catch (IOException e) { // log warning into execution context diff --git a/open-metadata-implementation/access-services/analytics-modeling/analytics-modeling-server/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/utils/AnalyticsAssetUtils.java b/open-metadata-implementation/access-services/analytics-modeling/analytics-modeling-server/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/utils/AnalyticsAssetUtils.java index adb60b44220..6d0dd87a616 100644 --- a/open-metadata-implementation/access-services/analytics-modeling/analytics-modeling-server/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/utils/AnalyticsAssetUtils.java +++ b/open-metadata-implementation/access-services/analytics-modeling/analytics-modeling-server/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/utils/AnalyticsAssetUtils.java @@ -3,17 +3,17 @@ package org.odpi.openmetadata.accessservices.analyticsmodeling.utils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.analyticsmodeling.synchronization.model.AnalyticsAsset; import org.odpi.openmetadata.accessservices.analyticsmodeling.synchronization.model.AssetReference; import org.odpi.openmetadata.accessservices.analyticsmodeling.synchronization.model.MetadataContainer; import org.odpi.openmetadata.accessservices.analyticsmodeling.synchronization.model.MetadataItem; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; /** * Class provides useful operations with bean class @@ -22,6 +22,11 @@ */ public class AnalyticsAssetUtils { + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + + private AnalyticsAssetUtils() { + } + /** * Add container to the asset. * @param asset to add new container to. @@ -129,7 +134,7 @@ public static Map buildAdditionalProperties(AnalyticsAsset asset if (asset.getReference() != null ) { try { - String references = new ObjectMapper().writeValueAsString(asset.getReference()); + String references = OBJECT_WRITER.writeValueAsString(asset.getReference()); additionalProperties.put(Constants.REFERENCE, references); } catch (JsonProcessingException e) { // log to execution context diff --git a/open-metadata-implementation/access-services/asset-catalog/asset-catalog-server/src/main/java/org/odpi/openmetadata/accessservices/assetcatalog/publishers/AssetCatalogSearchPublisher.java b/open-metadata-implementation/access-services/asset-catalog/asset-catalog-server/src/main/java/org/odpi/openmetadata/accessservices/assetcatalog/publishers/AssetCatalogSearchPublisher.java index f759d2f021d..85b24374be2 100644 --- a/open-metadata-implementation/access-services/asset-catalog/asset-catalog-server/src/main/java/org/odpi/openmetadata/accessservices/assetcatalog/publishers/AssetCatalogSearchPublisher.java +++ b/open-metadata-implementation/access-services/asset-catalog/asset-catalog-server/src/main/java/org/odpi/openmetadata/accessservices/assetcatalog/publishers/AssetCatalogSearchPublisher.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.repositoryservices.connectors.openmetadatatopic.OpenMetadataTopicConnector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,7 +16,8 @@ */ public class AssetCatalogSearchPublisher { - private static final Logger log = LoggerFactory.getLogger(AssetCatalogSearchPublisher.class); + private static final Logger LOG = LoggerFactory.getLogger(AssetCatalogSearchPublisher.class); + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); private final OpenMetadataTopicConnector topicConnector; @@ -35,21 +37,20 @@ public void publishEvent(Serializable event) { if (topicConnector != null) { - ObjectMapper objectMapper = new ObjectMapper(); - topicConnector.sendEvent(objectMapper.writeValueAsString(event)); + topicConnector.sendEvent(OBJECT_WRITER.writeValueAsString(event)); } else { - log.error("Cannot publish event: topic connector is null!"); + LOG.error("Cannot publish event: topic connector is null!"); } } catch (JsonProcessingException e) { - log.error("Unable to create json for publishing: " + event.toString(), e); + LOG.error("Unable to create json for publishing: " + event.toString(), e); } catch (Exception e) { - log.error("Unable to publish new asset event", e); + LOG.error("Unable to publish new asset event", e); } } } diff --git a/open-metadata-implementation/access-services/asset-consumer/asset-consumer-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetconsumer/connectors/outtopic/AssetConsumerOutTopicServerConnector.java b/open-metadata-implementation/access-services/asset-consumer/asset-consumer-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetconsumer/connectors/outtopic/AssetConsumerOutTopicServerConnector.java index 089abeccc51..52e1c54e04a 100644 --- a/open-metadata-implementation/access-services/asset-consumer/asset-consumer-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetconsumer/connectors/outtopic/AssetConsumerOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/asset-consumer/asset-consumer-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetconsumer/connectors/outtopic/AssetConsumerOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.assetconsumer.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.assetconsumer.events.AssetConsumerOutTopicEvent; import org.odpi.openmetadata.accessservices.assetconsumer.ffdc.AssetConsumerAuditCode; import org.odpi.openmetadata.accessservices.assetconsumer.ffdc.AssetConsumerErrorCode; @@ -18,6 +19,9 @@ */ public class AssetConsumerOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class AssetConsumerOutTopicServerConnector extends OpenMetadataTopicSende public void sendEvent(AssetConsumerOutTopicEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/asset-lineage/asset-lineage-server/src/main/java/org/odpi/openmetadata/accessservices/assetlineage/outtopic/AssetLineagePublisher.java b/open-metadata-implementation/access-services/asset-lineage/asset-lineage-server/src/main/java/org/odpi/openmetadata/accessservices/assetlineage/outtopic/AssetLineagePublisher.java index 31fa189a86d..714406d880b 100644 --- a/open-metadata-implementation/access-services/asset-lineage/asset-lineage-server/src/main/java/org/odpi/openmetadata/accessservices/assetlineage/outtopic/AssetLineagePublisher.java +++ b/open-metadata-implementation/access-services/asset-lineage/asset-lineage-server/src/main/java/org/odpi/openmetadata/accessservices/assetlineage/outtopic/AssetLineagePublisher.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import org.apache.commons.collections4.CollectionUtils; @@ -54,6 +55,7 @@ public class AssetLineagePublisher { private static final Logger log = LoggerFactory.getLogger(AssetLineagePublisher.class); + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); private static final AssetLineageInstanceHandler instanceHandler = new AssetLineageInstanceHandler(); private final OpenMetadataTopicConnector outTopicConnector; private final String serverUserName; @@ -314,8 +316,7 @@ public void publishEvent(AssetLineageEventHeader event) throws JsonProcessingExc if (outTopicConnector == null) return; - ObjectMapper objectMapper = new ObjectMapper(); - outTopicConnector.sendEvent(objectMapper.writeValueAsString(event)); + outTopicConnector.sendEvent(OBJECT_WRITER.writeValueAsString(event)); } diff --git a/open-metadata-implementation/access-services/asset-manager/asset-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/connectors/outtopic/AssetManagerOutTopicServerConnector.java b/open-metadata-implementation/access-services/asset-manager/asset-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/connectors/outtopic/AssetManagerOutTopicServerConnector.java index 1be2710f4c6..1207759ffc6 100644 --- a/open-metadata-implementation/access-services/asset-manager/asset-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/connectors/outtopic/AssetManagerOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/asset-manager/asset-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/connectors/outtopic/AssetManagerOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.assetmanager.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.assetmanager.ffdc.AssetManagerAuditCode; import org.odpi.openmetadata.accessservices.assetmanager.events.AssetManagerOutTopicEvent; import org.odpi.openmetadata.accessservices.assetmanager.ffdc.AssetManagerErrorCode; @@ -18,6 +19,9 @@ */ public class AssetManagerOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class AssetManagerOutTopicServerConnector extends OpenMetadataTopicSender public void sendEvent(AssetManagerOutTopicEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetowner/connectors/outtopic/AssetOwnerOutTopicServerConnector.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetowner/connectors/outtopic/AssetOwnerOutTopicServerConnector.java index 555d986c880..9b397198c24 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetowner/connectors/outtopic/AssetOwnerOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/assetowner/connectors/outtopic/AssetOwnerOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.assetowner.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.assetowner.events.AssetOwnerOutTopicEvent; import org.odpi.openmetadata.accessservices.assetowner.ffdc.AssetOwnerAuditCode; import org.odpi.openmetadata.accessservices.assetowner.ffdc.AssetOwnerErrorCode; @@ -18,6 +19,9 @@ */ public class AssetOwnerOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class AssetOwnerOutTopicServerConnector extends OpenMetadataTopicSenderCo public void sendEvent(AssetOwnerOutTopicEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/community-profile/community-profile-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/communityprofile/connectors/outtopic/CommunityProfileOutTopicServerConnector.java b/open-metadata-implementation/access-services/community-profile/community-profile-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/communityprofile/connectors/outtopic/CommunityProfileOutTopicServerConnector.java index 843ceff2bbf..6b8235fb4bd 100644 --- a/open-metadata-implementation/access-services/community-profile/community-profile-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/communityprofile/connectors/outtopic/CommunityProfileOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/community-profile/community-profile-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/communityprofile/connectors/outtopic/CommunityProfileOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.communityprofile.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.communityprofile.events.CommunityProfileOutboundEvent; import org.odpi.openmetadata.accessservices.communityprofile.ffdc.CommunityProfileAuditCode; import org.odpi.openmetadata.accessservices.communityprofile.ffdc.CommunityProfileErrorCode; @@ -18,6 +19,9 @@ */ public class CommunityProfileOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class CommunityProfileOutTopicServerConnector extends OpenMetadataTopicSe public void sendEvent(CommunityProfileOutboundEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/data-engine/data-engine-server/src/main/java/org/odpi/openmetadata/accessservices/dataengine/server/listeners/DataEngineInTopicListener.java b/open-metadata-implementation/access-services/data-engine/data-engine-server/src/main/java/org/odpi/openmetadata/accessservices/dataengine/server/listeners/DataEngineInTopicListener.java index 8d33dc205f2..86717fad45d 100644 --- a/open-metadata-implementation/access-services/data-engine/data-engine-server/src/main/java/org/odpi/openmetadata/accessservices/dataengine/server/listeners/DataEngineInTopicListener.java +++ b/open-metadata-implementation/access-services/data-engine/data-engine-server/src/main/java/org/odpi/openmetadata/accessservices/dataengine/server/listeners/DataEngineInTopicListener.java @@ -3,8 +3,8 @@ package org.odpi.openmetadata.accessservices.dataengine.server.listeners; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; import org.odpi.openmetadata.accessservices.dataengine.event.DataEngineEventHeader; import org.odpi.openmetadata.accessservices.dataengine.ffdc.DataEngineAuditCode; import org.odpi.openmetadata.accessservices.dataengine.server.processors.DataEngineEventProcessor; @@ -13,13 +13,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; + /** * The Data Engine in topic processor is listening events from external data engines about * metadata changes. It will handle different types of events defined in Data Engine OMAS API module. */ public class DataEngineInTopicListener implements OpenMetadataTopicListener { private static final Logger log = LoggerFactory.getLogger(DataEngineInTopicListener.class); - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectReader OBJECT_READER = new ObjectMapper().reader(); private final AuditLog auditLog; private final DataEngineEventProcessor dataEngineEventProcessor; @@ -49,7 +51,7 @@ public void processEvent(String dataEngineEvent) { } else { try { - DataEngineEventHeader dataEngineEventHeader = OBJECT_MAPPER.readValue(dataEngineEvent, DataEngineEventHeader.class); + DataEngineEventHeader dataEngineEventHeader = OBJECT_READER.readValue(dataEngineEvent, DataEngineEventHeader.class); if ((dataEngineEventHeader != null)) { switch (dataEngineEventHeader.getDataEngineEventType()) { @@ -145,12 +147,11 @@ public void processEvent(String dataEngineEvent) { } else { log.debug("Ignored instance event - null Data Engine event type"); } - } catch (JsonProcessingException e) { + } catch (IOException e) { log.debug("Exception processing event from in Data Engine In Topic", e); auditLog.logException("process Data Engine inTopic Event", DataEngineAuditCode.PROCESS_EVENT_EXCEPTION.getMessageDefinition(e.getMessage()), e); - } } } diff --git a/open-metadata-implementation/access-services/data-engine/data-engine-server/src/main/java/org/odpi/openmetadata/accessservices/dataengine/server/processors/DataEngineEventProcessor.java b/open-metadata-implementation/access-services/data-engine/data-engine-server/src/main/java/org/odpi/openmetadata/accessservices/dataengine/server/processors/DataEngineEventProcessor.java index 27b9911d280..4d8d900305e 100644 --- a/open-metadata-implementation/access-services/data-engine/data-engine-server/src/main/java/org/odpi/openmetadata/accessservices/dataengine/server/processors/DataEngineEventProcessor.java +++ b/open-metadata-implementation/access-services/data-engine/data-engine-server/src/main/java/org/odpi/openmetadata/accessservices/dataengine/server/processors/DataEngineEventProcessor.java @@ -2,8 +2,8 @@ /* Copyright Contributors to the ODPi Egeria project. */ package org.odpi.openmetadata.accessservices.dataengine.server.processors; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.odpi.openmetadata.accessservices.dataengine.event.DataEngineRegistrationEvent; @@ -37,6 +37,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; + import static org.odpi.openmetadata.commonservices.generichandlers.OpenMetadataAPIMapper.PORT_ALIAS_TYPE_NAME; import static org.odpi.openmetadata.commonservices.generichandlers.OpenMetadataAPIMapper.PORT_IMPLEMENTATION_TYPE_NAME; import static org.odpi.openmetadata.commonservices.generichandlers.OpenMetadataAPIMapper.PORT_TYPE_NAME; @@ -48,7 +50,7 @@ */ public class DataEngineEventProcessor { - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectReader OBJECT_READER = new ObjectMapper().reader(); private static final Logger log = LoggerFactory.getLogger(DataEngineEventProcessor.class); private static final String DEBUG_MESSAGE_METHOD = "Calling method: {}"; @@ -81,11 +83,11 @@ public void processDataEngineRegistrationEvent(String dataEngineEvent) { log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DataEngineRegistrationEvent dataEngineRegistrationEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DataEngineRegistrationEvent.class); + DataEngineRegistrationEvent dataEngineRegistrationEvent = OBJECT_READER.readValue(dataEngineEvent, DataEngineRegistrationEvent.class); dataEngineRESTServices.createExternalDataEngine(dataEngineRegistrationEvent.getUserId(), serverName, dataEngineRegistrationEvent.getEngine()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -100,7 +102,7 @@ public void processPortAliasEvent(String dataEngineEvent) { log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - PortAliasEvent portAliasEvent = OBJECT_MAPPER.readValue(dataEngineEvent, PortAliasEvent.class); + PortAliasEvent portAliasEvent = OBJECT_READER.readValue(dataEngineEvent, PortAliasEvent.class); String userId = portAliasEvent.getUserId(); String externalSourceName = portAliasEvent.getExternalSourceName(); @@ -113,7 +115,7 @@ public void processPortAliasEvent(String dataEngineEvent) { processGUID, externalSourceName); dataEngineRESTServices.updateProcessStatus(userId, serverName, processGUID, InstanceStatus.ACTIVE, externalSourceName); - } catch (JsonProcessingException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) { + } catch (IOException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -128,13 +130,13 @@ public void processProcessHierarchyEvent(String dataEngineEvent) { log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - ProcessHierarchyEvent processHierarchyEvent = OBJECT_MAPPER.readValue(dataEngineEvent, ProcessHierarchyEvent.class); + ProcessHierarchyEvent processHierarchyEvent = OBJECT_READER.readValue(dataEngineEvent, ProcessHierarchyEvent.class); dataEngineRESTServices.addProcessHierarchyToProcess(processHierarchyEvent.getUserId(), serverName, processHierarchyEvent.getProcessHierarchy(), processHierarchyEvent.getExternalSourceName()); - } catch (JsonProcessingException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) { + } catch (IOException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -149,7 +151,7 @@ public void processPortImplementationEvent(String dataEngineEvent) { log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - PortImplementationEvent portImplementationEvent = OBJECT_MAPPER.readValue(dataEngineEvent, PortImplementationEvent.class); + PortImplementationEvent portImplementationEvent = OBJECT_READER.readValue(dataEngineEvent, PortImplementationEvent.class); String externalSourceName = portImplementationEvent.getExternalSourceName(); String userId = portImplementationEvent.getUserId(); PortImplementation portImplementation = portImplementationEvent.getPortImplementation(); @@ -165,7 +167,7 @@ public void processPortImplementationEvent(String dataEngineEvent) { externalSourceName); dataEngineRESTServices.updateProcessStatus(userId, serverName, processGUID, InstanceStatus.ACTIVE, externalSourceName); - } catch (JsonProcessingException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException | FunctionNotSupportedException e) { + } catch (IOException | PropertyServerException | UserNotAuthorizedException | InvalidParameterException | FunctionNotSupportedException e) { logException(dataEngineEvent, methodName, e); } } @@ -181,7 +183,7 @@ public void processLineageMappingsEvent(String dataEngineEvent) { log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - LineageMappingsEvent lineageMappingsEvent = OBJECT_MAPPER.readValue(dataEngineEvent, LineageMappingsEvent.class); + LineageMappingsEvent lineageMappingsEvent = OBJECT_READER.readValue(dataEngineEvent, LineageMappingsEvent.class); if (CollectionUtils.isEmpty(lineageMappingsEvent.getLineageMappings())) { return; @@ -190,7 +192,7 @@ public void processLineageMappingsEvent(String dataEngineEvent) { FFDCResponseBase response = new FFDCResponseBase(); dataEngineRESTServices.addLineageMappings(lineageMappingsEvent.getUserId(), serverName, lineageMappingsEvent.getLineageMappings(), response, lineageMappingsEvent.getExternalSourceName()); - } catch (JsonProcessingException | UserNotAuthorizedException | InvalidParameterException | PropertyServerException e) { + } catch (IOException | UserNotAuthorizedException | InvalidParameterException | PropertyServerException e) { logException(dataEngineEvent, methodName, e); } } @@ -205,11 +207,11 @@ public void processProcessEvent(String dataEngineEvent) { log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - ProcessEvent processesEvent = OBJECT_MAPPER.readValue(dataEngineEvent, ProcessEvent.class); + ProcessEvent processesEvent = OBJECT_READER.readValue(dataEngineEvent, ProcessEvent.class); dataEngineRESTServices.upsertProcess(processesEvent.getUserId(), serverName, processesEvent.getProcess(), processesEvent.getExternalSourceName()); - } catch (JsonProcessingException e) { + } catch (IOException e) { log.debug("Exception in parsing event from in Data Engine In Topic", e); logException(dataEngineEvent, methodName, e); } @@ -224,7 +226,7 @@ public void processSchemaTypeEvent(String schemaTypeEvent) { final String methodName = "processSchemaTypeEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - SchemaTypeEvent schemaEvent = OBJECT_MAPPER.readValue(schemaTypeEvent, SchemaTypeEvent.class); + SchemaTypeEvent schemaEvent = OBJECT_READER.readValue(schemaTypeEvent, SchemaTypeEvent.class); String portGUID = null; if (StringUtils.isNotEmpty(schemaEvent.getPortQualifiedName())) { @@ -233,7 +235,7 @@ public void processSchemaTypeEvent(String schemaTypeEvent) { } dataEngineRESTServices.upsertSchemaType(schemaEvent.getUserId(), serverName, portGUID, schemaEvent.getSchemaType(), schemaEvent.getExternalSourceName()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { logException(schemaTypeEvent, methodName, e); } } @@ -247,11 +249,11 @@ public void processDeleteSchemaTypeEvent(String dataEngineEvent) { final String methodName = "processDeleteSchemaTypeEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteSchemaType(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -265,11 +267,11 @@ public void processDeleteDataEngineEvent(String dataEngineEvent) { final String methodName = "processDeleteDataEngineEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteExternalDataEngine(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException e) { logException(dataEngineEvent, methodName, e); } } @@ -283,11 +285,11 @@ public void processDeleteProcessEvent(String dataEngineEvent) { final String methodName = "processDeleteProcessEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteProcess(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -316,11 +318,11 @@ public void processDatabaseEvent(String dataEngineEvent) { final String methodName = "processDatabaseEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DatabaseEvent databaseEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DatabaseEvent.class); + DatabaseEvent databaseEvent = OBJECT_READER.readValue(dataEngineEvent, DatabaseEvent.class); dataEngineRESTServices.upsertDatabase(databaseEvent.getUserId(), serverName, databaseEvent.getDatabase(), databaseEvent.getExternalSourceName()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -334,13 +336,13 @@ public void processDatabaseSchemaEvent(String dataEngineEvent) { final String methodName = "processDatabaseSchemaEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DatabaseSchemaEvent databaseSchemaEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DatabaseSchemaEvent.class); + DatabaseSchemaEvent databaseSchemaEvent = OBJECT_READER.readValue(dataEngineEvent, DatabaseSchemaEvent.class); dataEngineRESTServices.upsertDatabaseSchema(databaseSchemaEvent.getUserId(), serverName, databaseSchemaEvent.getDatabaseQualifiedName(), databaseSchemaEvent.getDatabaseSchema(), databaseSchemaEvent.getExternalSourceName()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -354,12 +356,12 @@ public void processRelationalTableEvent(String dataEngineEvent) { final String methodName = "processRelationalTableEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - RelationalTableEvent relationalTableEvent = OBJECT_MAPPER.readValue(dataEngineEvent, RelationalTableEvent.class); + RelationalTableEvent relationalTableEvent = OBJECT_READER.readValue(dataEngineEvent, RelationalTableEvent.class); dataEngineRESTServices.upsertRelationalTable(relationalTableEvent.getUserId(), serverName, relationalTableEvent.getDatabaseSchemaQualifiedName(), relationalTableEvent.getRelationalTable(), relationalTableEvent.getExternalSourceName()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -373,11 +375,11 @@ public void processDataFileEvent(String dataEngineEvent) { final String methodName = "processDataFileEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DataFileEvent dataFileEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DataFileEvent.class); + DataFileEvent dataFileEvent = OBJECT_READER.readValue(dataEngineEvent, DataFileEvent.class); dataEngineRESTServices.upsertDataFile(dataFileEvent.getUserId(), serverName, dataFileEvent.getDataFile(), dataFileEvent.getExternalSourceName()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -391,11 +393,11 @@ public void processDeleteDatabaseEvent(String dataEngineEvent) { final String methodName = "processDeleteDatabaseEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteDatabase(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -409,11 +411,11 @@ public void processDeleteDatabaseSchemaEvent(String dataEngineEvent) { final String methodName = "processDeleteDatabaseSchemaEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteDatabaseSchema(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -427,11 +429,11 @@ public void processDeleteRelationalTableEvent(String dataEngineEvent) { final String methodName = "processDeleteRelationalTableEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteRelationalTable(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -445,11 +447,11 @@ public void processDeleteDataFileEvent(String dataEngineEvent) { final String methodName = "processDeleteDataFileEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteDataFile(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -463,11 +465,11 @@ public void processDeleteFolderEvent(String dataEngineEvent) { final String methodName = "processDeleteFolderEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteFolder(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -481,11 +483,11 @@ public void processDeleteConnectionEvent(String dataEngineEvent) { final String methodName = "processDeleteConnectionEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteConnection(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -499,11 +501,11 @@ public void processDeleteEndpointEvent(String dataEngineEvent) { final String methodName = "processDeleteEndpointEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteEndpoint(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -517,10 +519,10 @@ public void processTopicEvent(String dataEngineEvent) { final String methodName = "processTopicEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - TopicEvent topicEvent = OBJECT_MAPPER.readValue(dataEngineEvent, TopicEvent.class); + TopicEvent topicEvent = OBJECT_READER.readValue(dataEngineEvent, TopicEvent.class); dataEngineRESTServices.upsertTopic(topicEvent.getUserId(), serverName, topicEvent.getTopic(), topicEvent.getExternalSourceName()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -534,13 +536,13 @@ public void processEventTypeEvent(String dataEngineEvent) { final String methodName = "processEventTypeEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - EventTypeEvent eventTypeEvent = OBJECT_MAPPER.readValue(dataEngineEvent, EventTypeEvent.class); + EventTypeEvent eventTypeEvent = OBJECT_READER.readValue(dataEngineEvent, EventTypeEvent.class); String topicGUID = dataEngineRESTServices.getTopicGUID(eventTypeEvent.getUserId(), serverName, eventTypeEvent.getTopicQualifiedName(), methodName); dataEngineRESTServices.upsertEventType(eventTypeEvent.getUserId(), serverName, eventTypeEvent.getEventType(), topicGUID, eventTypeEvent.getExternalSourceName()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException e) { logException(dataEngineEvent, methodName, e); } } @@ -554,11 +556,11 @@ public void processDeleteTopicEvent(String dataEngineEvent) { final String methodName = "processDeleteTopicEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteTopic(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -572,11 +574,11 @@ public void processDeleteEventTypeEvent(String dataEngineEvent) { final String methodName = "processDeleteEventTypeEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deleteEventType(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } @@ -590,11 +592,11 @@ public void processProcessingStateEvent(String dataEngineEvent) { final String methodName = "processProcessingStateEvent"; log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - ProcessingStateEvent event = OBJECT_MAPPER.readValue(dataEngineEvent, ProcessingStateEvent.class); + ProcessingStateEvent event = OBJECT_READER.readValue(dataEngineEvent, ProcessingStateEvent.class); dataEngineRESTServices.upsertProcessingState(event.getUserId(), serverName, event.getProcessingState(), event.getExternalSourceName()); - } catch (JsonProcessingException e) { + } catch (IOException e) { logException(dataEngineEvent, methodName, e); } } @@ -602,11 +604,11 @@ public void processProcessingStateEvent(String dataEngineEvent) { private void deletePort(String dataEngineEvent, String methodName, String portType) { log.trace(DEBUG_MESSAGE_METHOD, methodName); try { - DeleteEvent deleteEvent = OBJECT_MAPPER.readValue(dataEngineEvent, DeleteEvent.class); + DeleteEvent deleteEvent = OBJECT_READER.readValue(dataEngineEvent, DeleteEvent.class); dataEngineRESTServices.deletePort(deleteEvent.getUserId(), serverName, deleteEvent.getExternalSourceName(), deleteEvent.getGuid(), deleteEvent.getQualifiedName(), portType, deleteEvent.getDeleteSemantic()); - } catch (JsonProcessingException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { + } catch (IOException | UserNotAuthorizedException | PropertyServerException | InvalidParameterException | FunctionNotSupportedException | EntityNotDeletedException e) { logException(dataEngineEvent, methodName, e); } } diff --git a/open-metadata-implementation/access-services/data-engine/data-engine-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/dataengine/connectors/intopic/DataEngineInTopicClientConnector.java b/open-metadata-implementation/access-services/data-engine/data-engine-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/dataengine/connectors/intopic/DataEngineInTopicClientConnector.java index 522555d3a1a..ea9a8f26994 100644 --- a/open-metadata-implementation/access-services/data-engine/data-engine-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/dataengine/connectors/intopic/DataEngineInTopicClientConnector.java +++ b/open-metadata-implementation/access-services/data-engine/data-engine-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/dataengine/connectors/intopic/DataEngineInTopicClientConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.dataengine.connectors.intopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.dataengine.event.DataEngineEventHeader; import org.odpi.openmetadata.accessservices.dataengine.ffdc.DataEngineAuditCode; import org.odpi.openmetadata.accessservices.dataengine.ffdc.DataEngineErrorCode; @@ -20,6 +21,8 @@ public class DataEngineInTopicClientConnector extends OpenMetadataTopicSenderConnectorBase { + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -30,12 +33,10 @@ public class DataEngineInTopicClientConnector extends OpenMetadataTopicSenderCon public void sendEvent(DataEngineEventHeader event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/data-manager/data-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/datamanager/connectors/outtopic/DataManagerOutTopicServerConnector.java b/open-metadata-implementation/access-services/data-manager/data-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/datamanager/connectors/outtopic/DataManagerOutTopicServerConnector.java index 0e7ef66e2f0..610cc38a008 100644 --- a/open-metadata-implementation/access-services/data-manager/data-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/datamanager/connectors/outtopic/DataManagerOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/data-manager/data-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/datamanager/connectors/outtopic/DataManagerOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.datamanager.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.datamanager.events.DataManagerOutboundEvent; import org.odpi.openmetadata.accessservices.datamanager.ffdc.DataManagerAuditCode; import org.odpi.openmetadata.accessservices.datamanager.ffdc.DataManagerErrorCode; @@ -18,6 +19,9 @@ */ public class DataManagerOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class DataManagerOutTopicServerConnector extends OpenMetadataTopicSenderC public void sendEvent(DataManagerOutboundEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/digital-architecture/digital-architecture-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/digitalarchitecture/connectors/outtopic/DigitalArchitectureOutTopicServerConnector.java b/open-metadata-implementation/access-services/digital-architecture/digital-architecture-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/digitalarchitecture/connectors/outtopic/DigitalArchitectureOutTopicServerConnector.java index b0fc84425d3..af5f4d97852 100644 --- a/open-metadata-implementation/access-services/digital-architecture/digital-architecture-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/digitalarchitecture/connectors/outtopic/DigitalArchitectureOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/digital-architecture/digital-architecture-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/digitalarchitecture/connectors/outtopic/DigitalArchitectureOutTopicServerConnector.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.digitalarchitecture.events.DigitalArchitectureOutTopicEvent; import org.odpi.openmetadata.accessservices.digitalarchitecture.ffdc.DigitalArchitectureAuditCode; import org.odpi.openmetadata.accessservices.digitalarchitecture.ffdc.DigitalArchitectureErrorCode; @@ -19,6 +20,9 @@ */ public class DigitalArchitectureOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -29,11 +33,10 @@ public class DigitalArchitectureOutTopicServerConnector extends OpenMetadataTopi public void sendEvent(DigitalArchitectureOutTopicEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/governance-engine/governance-engine-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/connectors/outtopic/GovernanceEngineOutTopicServerConnector.java b/open-metadata-implementation/access-services/governance-engine/governance-engine-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/connectors/outtopic/GovernanceEngineOutTopicServerConnector.java index 4303f3a87d3..919d4766417 100644 --- a/open-metadata-implementation/access-services/governance-engine/governance-engine-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/connectors/outtopic/GovernanceEngineOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/governance-engine/governance-engine-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/governanceengine/connectors/outtopic/GovernanceEngineOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.governanceengine.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.governanceengine.ffdc.GovernanceEngineAuditCode; import org.odpi.openmetadata.accessservices.governanceengine.events.GovernanceEngineEvent; import org.odpi.openmetadata.accessservices.governanceengine.ffdc.GovernanceEngineErrorCode; @@ -18,6 +19,9 @@ */ public class GovernanceEngineOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class GovernanceEngineOutTopicServerConnector extends OpenMetadataTopicSe public void sendEvent(GovernanceEngineEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/it-infrastructure/it-infrastructure-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/itinfrastructure/connectors/outtopic/ITInfrastructureOutTopicServerConnector.java b/open-metadata-implementation/access-services/it-infrastructure/it-infrastructure-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/itinfrastructure/connectors/outtopic/ITInfrastructureOutTopicServerConnector.java index 8301ea9788e..846d725fe9f 100644 --- a/open-metadata-implementation/access-services/it-infrastructure/it-infrastructure-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/itinfrastructure/connectors/outtopic/ITInfrastructureOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/it-infrastructure/it-infrastructure-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/itinfrastructure/connectors/outtopic/ITInfrastructureOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.itinfrastructure.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.itinfrastructure.events.ITInfrastructureOutTopicEvent; import org.odpi.openmetadata.accessservices.itinfrastructure.ffdc.ITInfrastructureAuditCode; import org.odpi.openmetadata.accessservices.itinfrastructure.ffdc.ITInfrastructureErrorCode; @@ -18,6 +19,8 @@ */ public class ITInfrastructureOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +31,10 @@ public class ITInfrastructureOutTopicServerConnector extends OpenMetadataTopicSe public void sendEvent(ITInfrastructureOutTopicEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/security-manager/security-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/securitymanager/connectors/outtopic/SecurityManagerOutTopicServerConnector.java b/open-metadata-implementation/access-services/security-manager/security-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/securitymanager/connectors/outtopic/SecurityManagerOutTopicServerConnector.java index 733c832bad8..8e301238534 100644 --- a/open-metadata-implementation/access-services/security-manager/security-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/securitymanager/connectors/outtopic/SecurityManagerOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/security-manager/security-manager-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/securitymanager/connectors/outtopic/SecurityManagerOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.securitymanager.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.securitymanager.events.SecurityManagerOutTopicEvent; import org.odpi.openmetadata.accessservices.securitymanager.ffdc.SecurityManagerAuditCode; import org.odpi.openmetadata.accessservices.securitymanager.ffdc.SecurityManagerErrorCode; @@ -18,6 +19,9 @@ */ public class SecurityManagerOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class SecurityManagerOutTopicServerConnector extends OpenMetadataTopicSen public void sendEvent(SecurityManagerOutTopicEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/security-officer/security-officer-server/src/main/java/org/odpi/openmetadata/accessservices/securityofficer/server/publisher/SecurityOfficerPublisher.java b/open-metadata-implementation/access-services/security-officer/security-officer-server/src/main/java/org/odpi/openmetadata/accessservices/securityofficer/server/publisher/SecurityOfficerPublisher.java index b87ea84e278..db4ad877aed 100644 --- a/open-metadata-implementation/access-services/security-officer/security-officer-server/src/main/java/org/odpi/openmetadata/accessservices/securityofficer/server/publisher/SecurityOfficerPublisher.java +++ b/open-metadata-implementation/access-services/security-officer/security-officer-server/src/main/java/org/odpi/openmetadata/accessservices/securityofficer/server/publisher/SecurityOfficerPublisher.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.securityofficer.api.ffdc.SecurityOfficerAuditCode; import org.odpi.openmetadata.accessservices.securityofficer.api.events.SecurityOfficerEvent; import org.odpi.openmetadata.accessservices.securityofficer.api.events.SecurityOfficerTagEvent; @@ -37,7 +38,7 @@ public class SecurityOfficerPublisher extends OMRSInstanceEventProcessor { private static final Logger log = LoggerFactory.getLogger(SecurityOfficerPublisher.class); private static final String eventPublisherName = "Security Officer OMAS Event Publisher"; - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); private SecurityOfficerEventProcessor securityOfficerEventProcessor; private OpenMetadataTopicConnector openMetadataTopicConnector; private AuditLog auditLog; @@ -219,7 +220,7 @@ public void processConflictingTypeEvent(String sourceName, String originatorMeta public void publishEvent(SecurityOfficerEvent securityOfficerEvent) { try { - String event = OBJECT_MAPPER.writeValueAsString(securityOfficerEvent); + String event = OBJECT_WRITER.writeValueAsString(securityOfficerEvent); openMetadataTopicConnector.sendEvent(event); } catch (ConnectorCheckedException | JsonProcessingException e) { diff --git a/open-metadata-implementation/access-services/security-officer/security-officer-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/securityofficer/connectors/outtopic/SecurityOfficerOutTopicServerConnector.java b/open-metadata-implementation/access-services/security-officer/security-officer-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/securityofficer/connectors/outtopic/SecurityOfficerOutTopicServerConnector.java index af0894aba72..8c23b468345 100644 --- a/open-metadata-implementation/access-services/security-officer/security-officer-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/securityofficer/connectors/outtopic/SecurityOfficerOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/security-officer/security-officer-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/securityofficer/connectors/outtopic/SecurityOfficerOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.securityofficer.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.securityofficer.api.ffdc.SecurityOfficerAuditCode; import org.odpi.openmetadata.accessservices.securityofficer.api.events.SecurityOfficerEvent; import org.odpi.openmetadata.accessservices.securityofficer.api.ffdc.SecurityOfficerErrorCode; @@ -18,6 +19,9 @@ */ public class SecurityOfficerOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class SecurityOfficerOutTopicServerConnector extends OpenMetadataTopicSen public void sendEvent(SecurityOfficerEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/stewardship-action/stewardship-action-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/stewardshipaction/connectors/outtopic/StewardshipActionOutTopicServerConnector.java b/open-metadata-implementation/access-services/stewardship-action/stewardship-action-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/stewardshipaction/connectors/outtopic/StewardshipActionOutTopicServerConnector.java index 24445ccfb47..76f7dd5babe 100644 --- a/open-metadata-implementation/access-services/stewardship-action/stewardship-action-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/stewardshipaction/connectors/outtopic/StewardshipActionOutTopicServerConnector.java +++ b/open-metadata-implementation/access-services/stewardship-action/stewardship-action-topic-connectors/src/main/java/org/odpi/openmetadata/accessservices/stewardshipaction/connectors/outtopic/StewardshipActionOutTopicServerConnector.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.stewardshipaction.connectors.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.stewardshipaction.events.StewardshipActionOutTopicEvent; import org.odpi.openmetadata.accessservices.stewardshipaction.ffdc.StewardshipActionAuditCode; import org.odpi.openmetadata.accessservices.stewardshipaction.ffdc.StewardshipActionErrorCode; @@ -18,6 +19,9 @@ */ public class StewardshipActionOutTopicServerConnector extends OpenMetadataTopicSenderConnectorBase { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + /** * Send the request to the embedded event bus connector(s). * @@ -28,11 +32,10 @@ public class StewardshipActionOutTopicServerConnector extends OpenMetadataTopicS public void sendEvent(StewardshipActionOutTopicEvent event) throws InvalidParameterException, ConnectorCheckedException { final String methodName = "sendEvent"; - ObjectMapper objectMapper = new ObjectMapper(); try { - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); super.sendEvent(eventString); if (super.auditLog != null) diff --git a/open-metadata-implementation/access-services/subject-area/subject-area-server/src/main/java/org/odpi/openmetadata/accessservices/subjectarea/outtopic/SubjectAreaPublisher.java b/open-metadata-implementation/access-services/subject-area/subject-area-server/src/main/java/org/odpi/openmetadata/accessservices/subjectarea/outtopic/SubjectAreaPublisher.java index 09f39eb5e8c..3f1d256c328 100644 --- a/open-metadata-implementation/access-services/subject-area/subject-area-server/src/main/java/org/odpi/openmetadata/accessservices/subjectarea/outtopic/SubjectAreaPublisher.java +++ b/open-metadata-implementation/access-services/subject-area/subject-area-server/src/main/java/org/odpi/openmetadata/accessservices/subjectarea/outtopic/SubjectAreaPublisher.java @@ -3,6 +3,7 @@ package org.odpi.openmetadata.accessservices.subjectarea.outtopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.subjectarea.events.SubjectAreaEvent; import org.odpi.openmetadata.accessservices.subjectarea.ffdc.SubjectAreaErrorCode; import org.odpi.openmetadata.adminservices.ffdc.exception.OMAGConfigurationErrorException; @@ -24,6 +25,8 @@ public class SubjectAreaPublisher { private static final Logger log = LoggerFactory.getLogger(SubjectAreaPublisher.class); + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + private OpenMetadataTopicConnector connector = null; @@ -181,7 +184,6 @@ private OpenMetadataTopicConnector getTopicConnector(Connection topicConnection */ private String getJSONPayload(SubjectAreaEvent event) { - ObjectMapper objectMapper = new ObjectMapper(); String jsonString = null; /* @@ -189,7 +191,7 @@ private String getJSONPayload(SubjectAreaEvent event) */ try { - jsonString = objectMapper.writeValueAsString(event); + jsonString = OBJECT_WRITER.writeValueAsString(event); } catch (Exception error) { diff --git a/open-metadata-implementation/adapters/open-connectors/configuration-store-connectors/configuration-encrypted-file-store-connector/src/main/java/org/odpi/openmetadata/adapters/adminservices/configurationstore/encryptedfile/EncryptedFileBasedServerConfigStoreConnector.java b/open-metadata-implementation/adapters/open-connectors/configuration-store-connectors/configuration-encrypted-file-store-connector/src/main/java/org/odpi/openmetadata/adapters/adminservices/configurationstore/encryptedfile/EncryptedFileBasedServerConfigStoreConnector.java index 2005f6c494d..7647a107570 100644 --- a/open-metadata-implementation/adapters/open-connectors/configuration-store-connectors/configuration-encrypted-file-store-connector/src/main/java/org/odpi/openmetadata/adapters/adminservices/configurationstore/encryptedfile/EncryptedFileBasedServerConfigStoreConnector.java +++ b/open-metadata-implementation/adapters/open-connectors/configuration-store-connectors/configuration-encrypted-file-store-connector/src/main/java/org/odpi/openmetadata/adapters/adminservices/configurationstore/encryptedfile/EncryptedFileBasedServerConfigStoreConnector.java @@ -3,6 +3,8 @@ package org.odpi.openmetadata.adapters.adminservices.configurationstore.encryptedfile; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import com.google.crypto.tink.*; import com.google.crypto.tink.aead.AeadConfig; import com.google.crypto.tink.aead.AeadKeyTemplates; @@ -45,6 +47,9 @@ public class EncryptedFileBasedServerConfigStoreConnector extends OMAGServerConf private static final String DEFAULT_FILENAME_TEMPLATE = "data/servers/" + INSERT_FOR_FILENAME_TEMPLATE + "/config/" + INSERT_FOR_FILENAME_TEMPLATE + ".config"; private static final KeyTemplate KEY_TEMPLATE = AeadKeyTemplates.CHACHA20_POLY1305; private static final Logger log = LoggerFactory.getLogger(EncryptedFileBasedServerConfigStoreConnector.class); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); private static SecureRandom rng = null; private String configStoreName = null; @@ -129,8 +134,7 @@ public void saveServerConfig(OMAGServerConfig omagServerConfig) { log.debug("Writing encrypted server configuration."); Aead aead = getAead(true); if (aead != null) { - ObjectMapper objectMapper = new ObjectMapper(); - String configStoreFileContents = objectMapper.writeValueAsString(omagServerConfig); + String configStoreFileContents = OBJECT_WRITER.writeValueAsString(omagServerConfig); byte[] ciphertext = aead.encrypt(configStoreFileContents.getBytes(StandardCharsets.UTF_8), null); FileUtils.writeByteArrayToFile(configStoreFile, ciphertext, false); } else { @@ -168,8 +172,7 @@ public OMAGServerConfig retrieveServerConfig() { try { log.debug("Attempting to retrieve clear-text server configuration properties"); String configStoreFileContents = FileUtils.readFileToString(configStoreFile, "UTF-8"); - ObjectMapper objectMapper = new ObjectMapper(); - newConfigProperties = objectMapper.readValue(configStoreFileContents, OMAGServerConfig.class); + newConfigProperties = OBJECT_READER.readValue(configStoreFileContents, OMAGServerConfig.class); // Assuming we are able to read it (unencrypted), immediately auto-encrypt it log.info("Found unencrypted configuration document -- automatically encrypting it."); saveServerConfig(newConfigProperties); @@ -196,8 +199,7 @@ public OMAGServerConfig retrieveServerConfig() { byte[] ciphertext = FileUtils.readFileToByteArray(configStoreFile); byte[] decrypted = aead.decrypt(ciphertext, null); String configStoreFileContents = new String(decrypted, StandardCharsets.UTF_8); - ObjectMapper objectMapper = new ObjectMapper(); - newConfigProperties = objectMapper.readValue(configStoreFileContents, OMAGServerConfig.class); + newConfigProperties = OBJECT_READER.readValue(configStoreFileContents, OMAGServerConfig.class); } else { // If we have a configuration file, but no key anywhere to use to decrypt it, throw an error immediately throw new OCFRuntimeException(DocStoreErrorCode.NO_KEYSTORE.getMessageDefinition(), diff --git a/open-metadata-implementation/adapters/open-connectors/configuration-store-connectors/configuration-file-store-connector/src/main/java/org/odpi/openmetadata/adapters/adminservices/configurationstore/file/FileBasedServerConfigStoreConnector.java b/open-metadata-implementation/adapters/open-connectors/configuration-store-connectors/configuration-file-store-connector/src/main/java/org/odpi/openmetadata/adapters/adminservices/configurationstore/file/FileBasedServerConfigStoreConnector.java index 3a93a132d25..bbb591c04e5 100644 --- a/open-metadata-implementation/adapters/open-connectors/configuration-store-connectors/configuration-file-store-connector/src/main/java/org/odpi/openmetadata/adapters/adminservices/configurationstore/file/FileBasedServerConfigStoreConnector.java +++ b/open-metadata-implementation/adapters/open-connectors/configuration-store-connectors/configuration-file-store-connector/src/main/java/org/odpi/openmetadata/adapters/adminservices/configurationstore/file/FileBasedServerConfigStoreConnector.java @@ -3,6 +3,8 @@ package org.odpi.openmetadata.adapters.adminservices.configurationstore.file; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.adminservices.store.OMAGServerConfigStoreRetrieveAll; import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException; import org.odpi.openmetadata.frameworks.connectors.ffdc.OCFRuntimeException; @@ -48,6 +50,12 @@ public class FileBasedServerConfigStoreConnector extends OMAGServerConfigStoreCo */ private static final Logger log = LoggerFactory.getLogger(FileBasedServerConfigStoreConnector.class); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); + /** * Default constructor @@ -114,9 +122,7 @@ public void saveServerConfig(OMAGServerConfig omagServerConfig) } else { - ObjectMapper objectMapper = new ObjectMapper(); - - String configStoreFileContents = objectMapper.writeValueAsString(omagServerConfig); + String configStoreFileContents = OBJECT_WRITER.writeValueAsString(omagServerConfig); FileUtils.writeStringToFile(configStoreFile, configStoreFileContents, (String)null,false); } @@ -145,9 +151,7 @@ public OMAGServerConfig retrieveServerConfig() String configStoreFileContents = FileUtils.readFileToString(configStoreFile, "UTF-8"); - ObjectMapper objectMapper = new ObjectMapper(); - - newConfigProperties = objectMapper.readValue(configStoreFileContents, OMAGServerConfig.class); + newConfigProperties = OBJECT_READER.readValue(configStoreFileContents, OMAGServerConfig.class); } catch (IOException ioException) { diff --git a/open-metadata-implementation/adapters/open-connectors/governance-action-connectors/src/main/java/org/odpi/openmetadata/adapters/connectors/governanceactions/remediation/OriginSeekerGovernanceActionConnector.java b/open-metadata-implementation/adapters/open-connectors/governance-action-connectors/src/main/java/org/odpi/openmetadata/adapters/connectors/governanceactions/remediation/OriginSeekerGovernanceActionConnector.java index ae7a4816c58..c1c7ad83f44 100644 --- a/open-metadata-implementation/adapters/open-connectors/governance-action-connectors/src/main/java/org/odpi/openmetadata/adapters/connectors/governanceactions/remediation/OriginSeekerGovernanceActionConnector.java +++ b/open-metadata-implementation/adapters/open-connectors/governance-action-connectors/src/main/java/org/odpi/openmetadata/adapters/connectors/governanceactions/remediation/OriginSeekerGovernanceActionConnector.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.adapters.connectors.governanceactions.ffdc.GovernanceActionConnectorsErrorCode; import org.odpi.openmetadata.frameworks.connectors.ffdc.*; import org.odpi.openmetadata.frameworks.governanceaction.OpenMetadataStore; @@ -33,6 +34,7 @@ public class OriginSeekerGovernanceActionConnector extends RemediationGovernance { private static final String assetOriginClassification = "AssetOrigin"; private static final String detectedOriginsProperty = "detectedOrigins"; + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); /** @@ -128,8 +130,7 @@ else if (originClassifications.size() == 1) */ newRequestParameters = new HashMap<>(); - ObjectMapper objectMapper = new ObjectMapper(); - String jsonString = objectMapper.writeValueAsString(originClassifications); + String jsonString = OBJECT_WRITER.writeValueAsString(originClassifications); newRequestParameters.put(detectedOriginsProperty, jsonString); diff --git a/open-metadata-implementation/adapters/open-connectors/integration-connectors/elasticsearch-integration-connector/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/elasticsearch/ElasticsearchIntegrationConnector.java b/open-metadata-implementation/adapters/open-connectors/integration-connectors/elasticsearch-integration-connector/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/elasticsearch/ElasticsearchIntegrationConnector.java index b9370bbcdf7..1dd7d2e55dd 100644 --- a/open-metadata-implementation/adapters/open-connectors/integration-connectors/elasticsearch-integration-connector/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/elasticsearch/ElasticsearchIntegrationConnector.java +++ b/open-metadata-implementation/adapters/open-connectors/integration-connectors/elasticsearch-integration-connector/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/elasticsearch/ElasticsearchIntegrationConnector.java @@ -9,6 +9,7 @@ import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.rest_client.RestClientTransport; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.apache.http.HttpHost; import org.elasticsearch.client.RestClient; import org.odpi.openmetadata.accessservices.assetcatalog.model.AssetCatalogEvent; @@ -33,6 +34,7 @@ */ public class ElasticsearchIntegrationConnector extends SearchIntegratorConnector { private static final Logger log = LoggerFactory.getLogger(ElasticsearchIntegrationConnector.class); + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); private static final String INDEX_NAME = "indexName"; private static final String ASSETS_INDEX_NAME = "assets"; @@ -41,7 +43,6 @@ public class ElasticsearchIntegrationConnector extends SearchIntegratorConnector private SearchIntegratorContext myContext = null; private ElasticsearchClient client; private String indexName = "test"; - private ObjectMapper objectMapper; /** * Initialize the connector. @@ -65,7 +66,6 @@ public void initialize(String connectorInstanceId, ConnectionProperties connecti String configuredIndexName = (String) configurationProperties.get(INDEX_NAME); this.indexName = Objects.requireNonNullElse(configuredIndexName, ASSETS_INDEX_NAME); - this.objectMapper = new ObjectMapper(); } @@ -149,7 +149,7 @@ public void saveAsset(AssetCatalogEvent assetCatalogEvent) { } log.debug("saving to elasticsearch {}", asset); try { - String jsonAsset = objectMapper.writeValueAsString(asset); + String jsonAsset = OBJECT_WRITER.writeValueAsString(asset); client.index(s-> s.index(jsonAsset).index(indexName).id(asset.getGUID())); } catch (IOException ioException) { diff --git a/open-metadata-implementation/adapters/open-connectors/integration-connectors/openapi-integration-connector/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/openapis/OpenAPIMonitorIntegrationConnector.java b/open-metadata-implementation/adapters/open-connectors/integration-connectors/openapi-integration-connector/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/openapis/OpenAPIMonitorIntegrationConnector.java index 7c7189233d7..43cad0df23e 100644 --- a/open-metadata-implementation/adapters/open-connectors/integration-connectors/openapi-integration-connector/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/openapis/OpenAPIMonitorIntegrationConnector.java +++ b/open-metadata-implementation/adapters/open-connectors/integration-connectors/openapi-integration-connector/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/openapis/OpenAPIMonitorIntegrationConnector.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; import org.odpi.openmetadata.accessservices.datamanager.api.DataManagerEventListener; import org.odpi.openmetadata.accessservices.datamanager.events.DataManagerOutboundEvent; import org.odpi.openmetadata.accessservices.datamanager.metadataelements.APIElement; @@ -46,6 +47,7 @@ public class OpenAPIMonitorIntegrationConnector extends APIIntegratorConnector i private final Map restClients = new HashMap<>(); private APIIntegratorContext myContext = null; + public static final ObjectReader OBJECT_READER = new ObjectMapper().reader(); /** * Initialize the connector. @@ -338,8 +340,7 @@ public void refresh() throws ConnectorCheckedException if (openAPIJSON != null) { - ObjectMapper objectMapper = new ObjectMapper(); - OpenAPISpecification openAPISpecification = objectMapper.readValue(openAPIJSON, OpenAPISpecification.class); + OpenAPISpecification openAPISpecification = OBJECT_READER.readValue(openAPIJSON, OpenAPISpecification.class); String title = ""; if (openAPISpecification != null) diff --git a/open-metadata-implementation/adapters/open-connectors/integration-connectors/openlineage-integration-connectors/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/openlineage/OpenLineageLogStoreConnectorBase.java b/open-metadata-implementation/adapters/open-connectors/integration-connectors/openlineage-integration-connectors/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/openlineage/OpenLineageLogStoreConnectorBase.java index 8ea8f19e8d2..6feb891cbc5 100644 --- a/open-metadata-implementation/adapters/open-connectors/integration-connectors/openlineage-integration-connectors/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/openlineage/OpenLineageLogStoreConnectorBase.java +++ b/open-metadata-implementation/adapters/open-connectors/integration-connectors/openlineage-integration-connectors/src/main/java/org/odpi/openmetadata/adapters/connectors/integration/openlineage/OpenLineageLogStoreConnectorBase.java @@ -3,6 +3,7 @@ package org.odpi.openmetadata.adapters.connectors.integration.openlineage; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.adapters.connectors.integration.openlineage.ffdc.OpenLineageIntegrationConnectorAuditCode; import org.odpi.openmetadata.adapters.connectors.integration.openlineage.ffdc.OpenLineageIntegrationConnectorErrorCode; import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException; @@ -30,6 +31,8 @@ public abstract class OpenLineageLogStoreConnectorBase extends LineageIntegratorConnector implements OpenLineageLogStore, OpenLineageEventListener { + + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); protected String destinationName = " maintainedByList = classification.getMaintainedBy(); if (maintainedByList != null && !maintainedByList.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(maintainedByList); + jsonString = OBJECT_WRITER.writeValueAsString(maintainedByList); vertex.property(PROPERTY_KEY_CLASSIFICATION_MAINTAINED_BY, jsonString); } catch (Exception exc) { @@ -330,10 +350,9 @@ public void mapInstanceAuditHeaderToVertex(Classification classification, Vertex Map mappingProperties = classification.getMappingProperties(); if (mappingProperties != null && !mappingProperties.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(mappingProperties); + jsonString = OBJECT_WRITER.writeValueAsString(mappingProperties); vertex.property(PROPERTY_KEY_CLASSIFICATION_MAPPING_PROPERTIES, jsonString); } catch (Exception exc) { @@ -369,9 +388,8 @@ public void mapVertexToClassification(Vertex vertex, Classification classificati String stringProps = (String) getVertexProperty(vertex, "classificationProperties"); if (stringProps != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { - InstanceProperties instanceProperties = objectMapper.readValue(stringProps, InstanceProperties.class); + InstanceProperties instanceProperties = OBJECT_READER.readValue(stringProps, InstanceProperties.class); log.debug("{} classification has deserialized properties {}", methodName, instanceProperties); classification.setProperties(instanceProperties); } catch (Exception exc) { @@ -445,9 +463,8 @@ public void mapVertexToInstanceAuditHeader(Vertex vertex, Classification classif // maintainedBy String maintainedByString = (String) getVertexProperty(vertex, PROPERTY_KEY_CLASSIFICATION_MAINTAINED_BY); if (maintainedByString != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { - List maintainedByList = (List) objectMapper.readValue(maintainedByString, List.class); + List maintainedByList = (List) OBJECT_READER.readValue(maintainedByString, List.class); log.debug("{} vertex has deserialized maintainedBy list {}", methodName, maintainedByList); classification.setMaintainedBy(maintainedByList); @@ -466,10 +483,9 @@ public void mapVertexToInstanceAuditHeader(Vertex vertex, Classification classif // mappingProperties String mappingPropertiesString = (String) getVertexProperty(vertex, PROPERTY_KEY_CLASSIFICATION_MAPPING_PROPERTIES); if (mappingPropertiesString != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { TypeReference> typeReference = new TypeReference>() {}; - Map mappingPropertiesMap = objectMapper.readValue(mappingPropertiesString, typeReference); + Map mappingPropertiesMap = OBJECT_MAPPER.readValue(mappingPropertiesString, typeReference); log.debug("{} vertex has deserialized mappingProperties {}", methodName, mappingPropertiesMap); classification.setMappingProperties(mappingPropertiesMap); diff --git a/open-metadata-implementation/adapters/open-connectors/repository-services-connectors/open-metadata-collection-store-connectors/graph-repository-connector/src/main/java/org/odpi/openmetadata/adapters/repositoryservices/graphrepository/repositoryconnector/GraphOMRSEntityMapper.java b/open-metadata-implementation/adapters/open-connectors/repository-services-connectors/open-metadata-collection-store-connectors/graph-repository-connector/src/main/java/org/odpi/openmetadata/adapters/repositoryservices/graphrepository/repositoryconnector/GraphOMRSEntityMapper.java index fe225090394..af01a2efa35 100644 --- a/open-metadata-implementation/adapters/open-connectors/repository-services-connectors/open-metadata-collection-store-connectors/graph-repository-connector/src/main/java/org/odpi/openmetadata/adapters/repositoryservices/graphrepository/repositoryconnector/GraphOMRSEntityMapper.java +++ b/open-metadata-implementation/adapters/open-connectors/repository-services-connectors/open-metadata-collection-store-connectors/graph-repository-connector/src/main/java/org/odpi/openmetadata/adapters/repositoryservices/graphrepository/repositoryconnector/GraphOMRSEntityMapper.java @@ -5,6 +5,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -43,16 +45,18 @@ public class GraphOMRSEntityMapper { private static final Logger log = LoggerFactory.getLogger(GraphOMRSEntityMapper.class); - private String metadataCollectionId; - private String repositoryName; - private OMRSRepositoryHelper repositoryHelper; - private GraphOMRSClassificationMapper classificationMapper; + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + + private final String repositoryName; + private final OMRSRepositoryHelper repositoryHelper; + private final GraphOMRSClassificationMapper classificationMapper; GraphOMRSEntityMapper(String metadataCollectionId, String repositoryName, OMRSRepositoryHelper repositoryHelper) { - this.metadataCollectionId = metadataCollectionId; this.repositoryName = repositoryName; this.repositoryHelper = repositoryHelper; @@ -130,10 +134,9 @@ void mapEntityDetailToVertex(EntityDetail entity, Vertex vertex) if (instanceProperties != null) { // First write properties as json - useful for handling collections and possibly for full text/string matching??? - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(instanceProperties); + jsonString = OBJECT_WRITER.writeValueAsString(instanceProperties); log.debug("{} entity has serialized properties {}", methodName, jsonString); vertex.property("instanceProperties", jsonString); } catch (Exception exc) { @@ -192,10 +195,9 @@ void mapEntityProxyToVertex(EntityProxy entity, Vertex vertex) InstanceProperties uniqueProperties = entity.getUniqueProperties(); if (uniqueProperties != null) { // First approach was to write properties as json - could be useful for text/string matching??? - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(uniqueProperties); + jsonString = OBJECT_WRITER.writeValueAsString(uniqueProperties); log.debug("{} entity proxy has serialized unique properties {}", methodName, jsonString); vertex.property("instanceProperties", jsonString); } catch (Exception exc) { @@ -379,10 +381,9 @@ private void mapEntitySummaryToVertex(EntitySummary entity, Vertex vertex) // can be indexed even on Relationships. Queries can use textRegex to search/retrieve. if (entity.getMaintainedBy() != null) { List maintainers = entity.getMaintainedBy(); - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(maintainers); + jsonString = OBJECT_WRITER.writeValueAsString(maintainers); log.debug("{} entity maintainedBy serialized to {}", methodName, jsonString); vertex.property(PROPERTY_KEY_ENTITY_MAINTAINED_BY, jsonString); } @@ -413,10 +414,9 @@ private void mapEntitySummaryToVertex(EntitySummary entity, Vertex vertex) // anticipated that it will be used for search, more for correlation. if (entity.getMappingProperties() != null) { Map mappingProperties = entity.getMappingProperties(); - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(mappingProperties); + jsonString = OBJECT_WRITER.writeValueAsString(mappingProperties); log.debug("{} entity maintainedBy serialized to {}", methodName, jsonString); vertex.property(PROPERTY_KEY_ENTITY_MAPPING_PROPERTIES, jsonString); } @@ -469,9 +469,8 @@ void mapVertexToEntityDetail(Vertex vertex, EntityDetail entity) String stringProps = (String) getVertexProperty(vertex, "instanceProperties"); if (stringProps != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { - InstanceProperties instanceProperties = objectMapper.readValue(stringProps, InstanceProperties.class); + InstanceProperties instanceProperties = OBJECT_READER.readValue(stringProps, InstanceProperties.class); log.debug("{} entity has deserialized properties {}", methodName, instanceProperties); entity.setProperties(instanceProperties); } catch (Exception exc) { @@ -520,9 +519,8 @@ void mapVertexToEntityProxy(Vertex vertex, EntityProxy entity) String stringProps = (String) getVertexProperty(vertex, "instanceProperties"); if (stringProps != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { - InstanceProperties instanceProperties = objectMapper.readValue(stringProps, InstanceProperties.class); + InstanceProperties instanceProperties = OBJECT_READER.readValue(stringProps, InstanceProperties.class); log.debug("{} entity has deserialized properties {}", methodName, instanceProperties); List propertiesDefinition = repositoryHelper.getAllPropertiesForTypeDef(repositoryName, typeDef, methodName); InstanceProperties uniqueAttributes = new InstanceProperties(); @@ -624,9 +622,8 @@ void mapVertexToEntitySummary(Vertex vertex, EntitySummary entity) String maintainedByString = (String) getVertexProperty(vertex, PROPERTY_KEY_ENTITY_MAINTAINED_BY); if (maintainedByString != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { - List maintainedByList = (List) objectMapper.readValue(maintainedByString, List.class); + List maintainedByList = (List) OBJECT_READER.readValue(maintainedByString, List.class); log.debug("{} entity has deserialized maintainedBy {}", methodName, maintainedByList); entity.setMaintainedBy(maintainedByList); } catch (Exception exc) { @@ -644,10 +641,9 @@ void mapVertexToEntitySummary(Vertex vertex, EntitySummary entity) String mappingPropertiesString = (String) getVertexProperty(vertex, PROPERTY_KEY_ENTITY_MAPPING_PROPERTIES); if (mappingPropertiesString != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { TypeReference> typeReference = new TypeReference>() {}; - Map mappingPropertiesMap = objectMapper.readValue(mappingPropertiesString, typeReference); + Map mappingPropertiesMap = OBJECT_MAPPER.readValue(mappingPropertiesString, typeReference); log.debug("{} entity has deserialized mappingProperties {}", methodName, mappingPropertiesMap); entity.setMappingProperties(mappingPropertiesMap); } catch (Exception exc) { diff --git a/open-metadata-implementation/adapters/open-connectors/repository-services-connectors/open-metadata-collection-store-connectors/graph-repository-connector/src/main/java/org/odpi/openmetadata/adapters/repositoryservices/graphrepository/repositoryconnector/GraphOMRSRelationshipMapper.java b/open-metadata-implementation/adapters/open-connectors/repository-services-connectors/open-metadata-collection-store-connectors/graph-repository-connector/src/main/java/org/odpi/openmetadata/adapters/repositoryservices/graphrepository/repositoryconnector/GraphOMRSRelationshipMapper.java index a7cbc25de79..60652a2977e 100644 --- a/open-metadata-implementation/adapters/open-connectors/repository-services-connectors/open-metadata-collection-store-connectors/graph-repository-connector/src/main/java/org/odpi/openmetadata/adapters/repositoryservices/graphrepository/repositoryconnector/GraphOMRSRelationshipMapper.java +++ b/open-metadata-implementation/adapters/open-connectors/repository-services-connectors/open-metadata-collection-store-connectors/graph-repository-connector/src/main/java/org/odpi/openmetadata/adapters/repositoryservices/graphrepository/repositoryconnector/GraphOMRSRelationshipMapper.java @@ -6,6 +6,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Property; @@ -36,9 +38,13 @@ class GraphOMRSRelationshipMapper { private static final Logger log = LoggerFactory.getLogger(GraphOMRSRelationshipMapper.class); - private String repositoryName; - private String metadataCollectionId; - private OMRSRepositoryHelper repositoryHelper; + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + + private final String repositoryName; + private final String metadataCollectionId; + private final OMRSRepositoryHelper repositoryHelper; GraphOMRSRelationshipMapper(String metadataCollectionId, String repositoryName, @@ -248,10 +254,9 @@ void mapRelationshipToEdge(Relationship relationship, Edge edge) List maintainedByList = relationship.getMaintainedBy(); if (maintainedByList != null && !maintainedByList.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(maintainedByList); + jsonString = OBJECT_WRITER.writeValueAsString(maintainedByList); edge.property(PROPERTY_KEY_RELATIONSHIP_MAINTAINED_BY, jsonString); } catch (Exception exc) { @@ -284,10 +289,9 @@ void mapRelationshipToEdge(Relationship relationship, Edge edge) Map mappingProperties = relationship.getMappingProperties(); if (mappingProperties != null && !mappingProperties.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(mappingProperties); + jsonString = OBJECT_WRITER.writeValueAsString(mappingProperties); edge.property(PROPERTY_KEY_RELATIONSHIP_MAPPING_PROPERTIES, jsonString); } catch (Exception exc) { @@ -315,11 +319,10 @@ void mapRelationshipToEdge(Relationship relationship, Edge edge) InstanceProperties instanceProperties = relationship.getProperties(); if (instanceProperties != null) { // First approach is to write properties as json - useful for handling collections and possibly for full text/string matching??? - ObjectMapper objectMapper = new ObjectMapper(); String jsonString; try { - jsonString = objectMapper.writeValueAsString(instanceProperties); + jsonString = OBJECT_WRITER.writeValueAsString(instanceProperties); edge.property("relationshipProperties", jsonString); } catch (Exception exc) { @@ -429,9 +432,8 @@ void mapEdgeToRelationship(Edge edge, Relationship relationship) // maintainedBy String maintainedByString = (String) getEdgeProperty(edge, PROPERTY_KEY_RELATIONSHIP_MAINTAINED_BY); if (maintainedByString != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { - List maintainedByList = (List) objectMapper.readValue(maintainedByString, List.class); + List maintainedByList = (List) OBJECT_READER.readValue(maintainedByString, List.class); log.debug("{} edge has deserialized maintainedBy list {}", methodName, maintainedByList); relationship.setMaintainedBy(maintainedByList); @@ -452,10 +454,9 @@ void mapEdgeToRelationship(Edge edge, Relationship relationship) // mappingProperties String mappingPropertiesString = (String) getEdgeProperty(edge, PROPERTY_KEY_RELATIONSHIP_MAPPING_PROPERTIES); if (mappingPropertiesString != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { TypeReference> typeReference = new TypeReference>() {}; - Map mappingPropertiesMap = objectMapper.readValue(mappingPropertiesString, typeReference); + Map mappingPropertiesMap = OBJECT_MAPPER.readValue(mappingPropertiesString, typeReference); log.debug("{} edge has deserialized mappingProperties {}", methodName, mappingPropertiesMap); relationship.setMappingProperties(mappingPropertiesMap); @@ -474,9 +475,8 @@ void mapEdgeToRelationship(Edge edge, Relationship relationship) // relationshipProperties String stringProps = (String) (getEdgeProperty(edge, "relationshipProperties")); if (stringProps != null) { - ObjectMapper objectMapper = new ObjectMapper(); try { - InstanceProperties instanceProperties = objectMapper.readValue(stringProps, InstanceProperties.class); + InstanceProperties instanceProperties = OBJECT_READER.readValue(stringProps, InstanceProperties.class); log.debug("{} relationship has deserialized properties {}", methodName, instanceProperties); relationship.setProperties(instanceProperties); diff --git a/open-metadata-implementation/governance-servers/open-lineage-services/open-lineage-services-server/src/main/java/org/odpi/openmetadata/governanceservers/openlineage/listeners/OpenLineageInTopicListener.java b/open-metadata-implementation/governance-servers/open-lineage-services/open-lineage-services-server/src/main/java/org/odpi/openmetadata/governanceservers/openlineage/listeners/OpenLineageInTopicListener.java index 34f05a73e49..d7f74e64099 100644 --- a/open-metadata-implementation/governance-servers/open-lineage-services/open-lineage-services-server/src/main/java/org/odpi/openmetadata/governanceservers/openlineage/listeners/OpenLineageInTopicListener.java +++ b/open-metadata-implementation/governance-servers/open-lineage-services/open-lineage-services-server/src/main/java/org/odpi/openmetadata/governanceservers/openlineage/listeners/OpenLineageInTopicListener.java @@ -2,8 +2,8 @@ /* Copyright Contributors to the ODPi Egeria project. */ package org.odpi.openmetadata.governanceservers.openlineage.listeners; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; import org.apache.commons.collections4.CollectionUtils; import org.odpi.openmetadata.accessservices.assetlineage.event.AssetLineageEventHeader; import org.odpi.openmetadata.accessservices.assetlineage.event.AssetLineageEventListener; @@ -24,6 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.util.List; import java.util.Optional; import java.util.Set; @@ -31,7 +32,7 @@ public class OpenLineageInTopicListener extends AssetLineageEventListener { private static final Logger log = LoggerFactory.getLogger(OpenLineageInTopicListener.class); - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectReader OBJECT_READER = new ObjectMapper().reader(); private final OMRSAuditLog auditLog; private final StoringServices storingServices; private final OpenLineageAssetContextHandler assetContextHandler; @@ -56,7 +57,7 @@ public void processEvent(String assetLineageEvent) { if (!assetLineageEvent.isEmpty()) { processEventBasedOnType(assetLineageEvent); } - } catch (JsonProcessingException e) { + } catch (IOException e) { logException(assetLineageEvent, e); } catch (Exception e) { log.error("Exception processing the in topic event", e); @@ -74,8 +75,8 @@ public void processEvent(String assetLineageEvent) { } - private void processEventBasedOnType(String assetLineageEvent) throws JsonProcessingException { - AssetLineageEventHeader assetLineageEventHeader = OBJECT_MAPPER.readValue(assetLineageEvent, AssetLineageEventHeader.class); + private void processEventBasedOnType(String assetLineageEvent) throws IOException { + AssetLineageEventHeader assetLineageEventHeader = OBJECT_READER.readValue(assetLineageEvent, AssetLineageEventHeader.class); if (assetLineageEventHeader == null) { return; @@ -90,54 +91,54 @@ private void processEventBasedOnType(String assetLineageEvent) throws JsonProces case TERM_CATEGORIZATIONS_EVENT: case TERM_ANCHORS_EVENT: case CATEGORY_ANCHORS_EVENT: - lineageRelationshipsEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); + lineageRelationshipsEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); storingServices.upsertEntityContext(lineageRelationshipsEvent); break; case CLASSIFICATION_CONTEXT_EVENT: case LINEAGE_MAPPINGS_EVENT: case PROCESS_CONTEXT_EVENT: - lineageRelationshipsEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); + lineageRelationshipsEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); storingServices.addEntityContext(lineageRelationshipsEvent); break; case COLUMN_CONTEXT_EVENT: - lineageRelationshipsEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); + lineageRelationshipsEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); requestAssetContext(lineageRelationshipsEvent); storingServices.addEntityContext(lineageRelationshipsEvent); break; case ASSET_CONTEXT_EVENT: - lineageRelationshipsEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); + lineageRelationshipsEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); storeAssetContext(lineageRelationshipsEvent); break; case NEW_RELATIONSHIP_EVENT: - lineageRelationshipEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipEvent.class); + lineageRelationshipEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipEvent.class); storingServices.upsertRelationship(lineageRelationshipEvent); break; case UPDATE_ENTITY_EVENT: - lineageEntityEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageEntityEvent.class); + lineageEntityEvent = OBJECT_READER.readValue(assetLineageEvent, LineageEntityEvent.class); storingServices.updateEntity(lineageEntityEvent); break; case UPDATE_RELATIONSHIP_EVENT: - lineageRelationshipEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipEvent.class); + lineageRelationshipEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipEvent.class); storingServices.updateRelationship(lineageRelationshipEvent); break; case RECLASSIFIED_ENTITY_EVENT: - lineageRelationshipsEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); + lineageRelationshipsEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); storingServices.updateClassification(lineageRelationshipsEvent); break; case DELETE_ENTITY_EVENT: - lineageEntityEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageEntityEvent.class); + lineageEntityEvent = OBJECT_READER.readValue(assetLineageEvent, LineageEntityEvent.class); storingServices.deleteEntity(lineageEntityEvent); break; case DELETE_RELATIONSHIP_EVENT: - lineageRelationshipEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipEvent.class); + lineageRelationshipEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipEvent.class); storingServices.deleteRelationship(lineageRelationshipEvent); break; case DECLASSIFIED_ENTITY_EVENT: - lineageRelationshipsEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); + lineageRelationshipsEvent = OBJECT_READER.readValue(assetLineageEvent, LineageRelationshipsEvent.class); storingServices.deleteClassification(lineageRelationshipsEvent); break; case LINEAGE_SYNC_EVENT: - lineageSyncEvent = OBJECT_MAPPER.readValue(assetLineageEvent, LineageSyncEvent.class); + lineageSyncEvent = OBJECT_READER.readValue(assetLineageEvent, LineageSyncEvent.class); storingServices.apply(lineageSyncEvent); break; default: diff --git a/open-metadata-implementation/integration-services/lineage-integrator/lineage-integrator-server/src/main/java/org/odpi/openmetadata/integrationservices/lineage/contextmanager/LineageIntegratorContextManager.java b/open-metadata-implementation/integration-services/lineage-integrator/lineage-integrator-server/src/main/java/org/odpi/openmetadata/integrationservices/lineage/contextmanager/LineageIntegratorContextManager.java index e6498581760..a63f516f47a 100644 --- a/open-metadata-implementation/integration-services/lineage-integrator/lineage-integrator-server/src/main/java/org/odpi/openmetadata/integrationservices/lineage/contextmanager/LineageIntegratorContextManager.java +++ b/open-metadata-implementation/integration-services/lineage-integrator/lineage-integrator-server/src/main/java/org/odpi/openmetadata/integrationservices/lineage/contextmanager/LineageIntegratorContextManager.java @@ -4,6 +4,8 @@ package org.odpi.openmetadata.integrationservices.lineage.contextmanager; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.accessservices.assetmanager.client.*; import org.odpi.openmetadata.accessservices.assetmanager.client.rest.AssetManagerRESTClient; import org.odpi.openmetadata.accessservices.assetmanager.properties.AssetManagerProperties; @@ -40,7 +42,9 @@ public class LineageIntegratorContextManager extends IntegrationContextManager i private GovernanceExchangeClient governanceExchangeClient; private StewardshipExchangeClient stewardshipExchangeClient; - private final ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); private final List registeredEventListeners = new ArrayList<>(); @@ -288,7 +292,7 @@ public synchronized void publishOpenLineageRunEvent(String rawEvent) { try { - event = objectMapper.readValue(rawEvent, OpenLineageRunEvent.class); + event = OBJECT_READER.readValue(rawEvent, OpenLineageRunEvent.class); } catch (Exception error) { @@ -320,7 +324,7 @@ public synchronized void publishOpenLineageRunEvent(OpenLineageRunEvent event) { try { - rawEvent = objectMapper.writeValueAsString(event); + rawEvent = OBJECT_WRITER.writeValueAsString(event); } catch (Exception error) { diff --git a/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/omrstopic/OMRSTopicConnector.java b/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/omrstopic/OMRSTopicConnector.java index 997f6e94f28..55635813d0c 100644 --- a/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/omrstopic/OMRSTopicConnector.java +++ b/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/omrstopic/OMRSTopicConnector.java @@ -3,6 +3,8 @@ package org.odpi.openmetadata.repositoryservices.connectors.omrstopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.frameworks.auditlog.AuditLog; import org.odpi.openmetadata.frameworks.auditlog.AuditLoggingComponent; import org.odpi.openmetadata.frameworks.auditlog.ComponentDescription; @@ -10,7 +12,6 @@ import org.odpi.openmetadata.frameworks.connectors.ConnectorBase; import org.odpi.openmetadata.frameworks.connectors.VirtualConnectorExtension; import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException; -import org.odpi.openmetadata.repositoryservices.ffdc.OMRSAuditCode; import org.odpi.openmetadata.repositoryservices.auditlog.OMRSAuditingComponent; import org.odpi.openmetadata.repositoryservices.connectors.openmetadatatopic.OpenMetadataTopicConnector; import org.odpi.openmetadata.repositoryservices.connectors.openmetadatatopic.OpenMetadataTopicListener; @@ -20,6 +21,7 @@ import org.odpi.openmetadata.repositoryservices.events.OMRSTypeDefEvent; import org.odpi.openmetadata.repositoryservices.events.beans.OMRSEventBean; import org.odpi.openmetadata.repositoryservices.events.beans.v1.OMRSEventV1; +import org.odpi.openmetadata.repositoryservices.ffdc.OMRSAuditCode; import org.odpi.openmetadata.repositoryservices.ffdc.OMRSErrorCode; import org.odpi.openmetadata.repositoryservices.ffdc.exception.OMRSLogicErrorException; import org.slf4j.Logger; @@ -62,6 +64,10 @@ public class OMRSTopicConnector extends ConnectorBase implements OMRSTopic, { private static final Logger log = LoggerFactory.getLogger(OMRSTopicConnector.class); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + private List embeddedConnectors = null; private final List internalTopicListeners = new ArrayList<>(); @@ -415,9 +421,8 @@ private void sendEvent(OMRSEventV1 event, { try { - ObjectMapper objectMapper = new ObjectMapper(); - String eventString = objectMapper.writeValueAsString(event); + String eventString = OBJECT_WRITER.writeValueAsString(event); if ((auditLog != null) && (logEvent)) { @@ -485,9 +490,7 @@ public void processEvent(String event) */ try { - ObjectMapper objectMapper = new ObjectMapper(); - - eventBean = objectMapper.readValue(event, OMRSEventBean.class); + eventBean = OBJECT_READER.readValue(event, OMRSEventBean.class); } catch (Exception exception) { diff --git a/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/openmetadatatopic/OpenMetadataTopicListenerConnectorBase.java b/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/openmetadatatopic/OpenMetadataTopicListenerConnectorBase.java index 2215e58baa4..80579e0dc68 100644 --- a/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/openmetadatatopic/OpenMetadataTopicListenerConnectorBase.java +++ b/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/openmetadatatopic/OpenMetadataTopicListenerConnectorBase.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.repositoryservices.connectors.openmetadatatopic; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; import org.odpi.openmetadata.frameworks.connectors.Connector; import org.odpi.openmetadata.frameworks.connectors.VirtualConnectorExtension; import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException; @@ -21,6 +22,8 @@ public abstract class OpenMetadataTopicListenerConnectorBase extends OpenMetadat VirtualConnectorExtension { + private static final ObjectReader OBJECT_READER = new ObjectMapper().reader(); + /** * Set up the list of connectors that this virtual connector will use to support its interface. * The connectors are initialized waiting to start. When start() is called on the @@ -72,9 +75,8 @@ protected T getEventBean(String event, /* * Parse the string (JSON) event into a bean. */ - ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.readValue(event, eventClass); + return OBJECT_READER.readValue(event, eventClass); } diff --git a/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/stores/auditlogstore/OMRSAuditLogStoreConnectorBase.java b/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/stores/auditlogstore/OMRSAuditLogStoreConnectorBase.java index 726be5b90e0..f8619d32338 100644 --- a/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/stores/auditlogstore/OMRSAuditLogStoreConnectorBase.java +++ b/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/stores/auditlogstore/OMRSAuditLogStoreConnectorBase.java @@ -3,6 +3,7 @@ package org.odpi.openmetadata.repositoryservices.connectors.stores.auditlogstore; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; import org.odpi.openmetadata.frameworks.auditlog.AuditLogRecord; import org.odpi.openmetadata.frameworks.connectors.ConnectorBase; import org.odpi.openmetadata.frameworks.connectors.properties.ConnectionProperties; @@ -30,6 +31,8 @@ public abstract class OMRSAuditLogStoreConnectorBase extends ConnectorBase imple { private static final Logger log = LoggerFactory.getLogger(OMRSAuditLogStoreConnectorBase.class); + private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writer(); + private String destinationName = " supportedSeverities = null; @@ -288,11 +291,9 @@ protected String getJSONLogRecord(OMRSAuditLogRecord logRecord, { final String parameterName = "logRecord"; - ObjectMapper objectMapper = new ObjectMapper(); - try { - return objectMapper.writeValueAsString(logRecord); + return OBJECT_WRITER.writeValueAsString(logRecord); } catch (Exception exc) { diff --git a/open-metadata-implementation/repository-services/repository-services-archive-utilities/src/main/java/org/odpi/openmetadata/repositoryservices/archiveutilities/OMRSArchiveGUIDMap.java b/open-metadata-implementation/repository-services/repository-services-archive-utilities/src/main/java/org/odpi/openmetadata/repositoryservices/archiveutilities/OMRSArchiveGUIDMap.java index 7bd00fa0278..8644c5dfc5c 100644 --- a/open-metadata-implementation/repository-services/repository-services-archive-utilities/src/main/java/org/odpi/openmetadata/repositoryservices/archiveutilities/OMRSArchiveGUIDMap.java +++ b/open-metadata-implementation/repository-services/repository-services-archive-utilities/src/main/java/org/odpi/openmetadata/repositoryservices/archiveutilities/OMRSArchiveGUIDMap.java @@ -3,6 +3,8 @@ package org.odpi.openmetadata.repositoryservices.archiveutilities; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,6 +23,10 @@ public class OMRSArchiveGUIDMap { private static final Logger log = LoggerFactory.getLogger(OMRSArchiveGUIDMap.class); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); + private final String guidMapFileName; private Map idToGUIDMap; @@ -45,7 +51,6 @@ public OMRSArchiveGUIDMap(String guidMapFileName) private void loadGUIDs() { File idFile = new File(guidMapFileName); - ObjectMapper objectMapper = new ObjectMapper(); try { @@ -53,7 +58,7 @@ private void loadGUIDs() String idFileContents = FileUtils.readFileToString(idFile, "UTF-8"); - idToGUIDMap = objectMapper.readValue(idFileContents, Map.class); + idToGUIDMap = OBJECT_READER.readValue(idFileContents, Map.class); } catch (Exception error) { @@ -116,7 +121,6 @@ public String queryGUID(String id) public void saveGUIDs() { File idFile = new File(guidMapFileName); - ObjectMapper objectMapper = new ObjectMapper(); try { @@ -130,7 +134,7 @@ public void saveGUIDs() { log.debug("Writing id file " + guidMapFileName); - String mapContents = objectMapper.writeValueAsString(idToGUIDMap); + String mapContents = OBJECT_WRITER.writeValueAsString(idToGUIDMap); FileUtils.writeStringToFile(idFile, mapContents, (String)null,false); } diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/AuthService.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/AuthService.java index ab1296d4ca0..b25ec01f1bf 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/AuthService.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/AuthService.java @@ -2,8 +2,6 @@ /* Copyright Contributors to the ODPi Egeria project. */ package org.odpi.openmetadata.userinterface.uichassis.springboot.auth; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.jsonwebtoken.Jwts; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; @@ -11,8 +9,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.*; +import java.util.Collection; +import java.util.Set; import java.util.stream.Collectors; public interface AuthService { diff --git a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenService.java b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenService.java index aaff4df0c10..3df80c1b91b 100644 --- a/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenService.java +++ b/open-metadata-implementation/user-interfaces/ui-chassis/ui-chassis-spring/src/main/java/org/odpi/openmetadata/userinterface/uichassis/springboot/auth/TokenService.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import org.springframework.beans.factory.annotation.Value; @@ -13,6 +15,10 @@ public class TokenService extends RoleService{ + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + @Value("${token.secret}") protected String tokenSecret; @@ -38,7 +44,7 @@ public long getTokenTimeout(){ */ public String toJSON(Object obj) { try { - return new ObjectMapper().writeValueAsString(obj); + return OBJECT_WRITER.writeValueAsString(obj); } catch (JsonProcessingException e) { throw new IllegalStateException(e); } @@ -80,7 +86,7 @@ public TokenUser parseUserFromToken(String token, String secret) { */ public TokenUser fromJSON(final String userJSON) { try { - return new ObjectMapper().readValue(userJSON, TokenUser.class); + return OBJECT_READER.readValue(userJSON, TokenUser.class); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java index e2ac54e2b5f..a31f9cd4665 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java @@ -3,10 +3,8 @@ package org.odpi.openmetadata.accessservices.analyticsmodeling.fvt.synchronization; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; import org.odpi.openmetadata.accessservices.analyticsmodeling.client.SynchronizationClient; import org.odpi.openmetadata.accessservices.analyticsmodeling.fvt.RepositoryService; import org.odpi.openmetadata.accessservices.analyticsmodeling.fvt.common.AnalyticsModelingTestBase; @@ -18,7 +16,9 @@ import org.odpi.openmetadata.fvt.utilities.auditlog.FVTAuditLogDestination; import org.odpi.openmetadata.fvt.utilities.exceptions.FVTUnexpectedCondition; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; /** @@ -38,6 +38,7 @@ public class SynchronizationTest extends AnalyticsModelingTestBase private static final String INPUT_FOLDER = "/src/test/resources/synchronization/input/"; + private static final ObjectReader OBJECT_READER = new ObjectMapper().reader(); /** * Run all of the defined tests and capture the results. @@ -188,7 +189,6 @@ public static T readObjectJson(String folder, String fileName { String root = Paths.get(".").toAbsolutePath().normalize().toString(); String input = root + folder + fileName + ".json"; - ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(new String(Files.readAllBytes(Paths.get(input))), cls); + return OBJECT_READER.readValue(new String(Files.readAllBytes(Paths.get(input))), cls); } } diff --git a/open-metadata-test/open-metadata-fvt/open-types-fvt/open-types-test-generator/src/main/java/org/odpi/openmetadata/fvt/opentypes/model/OmrsBeanModel.java b/open-metadata-test/open-metadata-fvt/open-types-fvt/open-types-test-generator/src/main/java/org/odpi/openmetadata/fvt/opentypes/model/OmrsBeanModel.java index 57ba945c3bc..4f43f85ae0b 100644 --- a/open-metadata-test/open-metadata-fvt/open-types-fvt/open-types-test-generator/src/main/java/org/odpi/openmetadata/fvt/opentypes/model/OmrsBeanModel.java +++ b/open-metadata-test/open-metadata-fvt/open-types-fvt/open-types-test-generator/src/main/java/org/odpi/openmetadata/fvt/opentypes/model/OmrsBeanModel.java @@ -2,14 +2,33 @@ /* Copyright Contributors to the ODPi Egeria project. */ package org.odpi.openmetadata.fvt.opentypes.model; -import org.odpi.openmetadata.fvt.opentypes.utils.GeneratorUtilities; import com.fasterxml.jackson.databind.ObjectMapper; +import org.odpi.openmetadata.fvt.opentypes.utils.GeneratorUtilities; import org.odpi.openmetadata.opentypes.OpenMetadataTypesArchive; import org.odpi.openmetadata.repositoryservices.connectors.stores.archivestore.properties.OpenMetadataArchive; -import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.*; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.AttributeCardinality; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.AttributeTypeDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.AttributeTypeDefCategory; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.ClassificationDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.EntityDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.EnumDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.EnumElementDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.PrimitiveDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.PrimitiveDefCategory; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.RelationshipDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.RelationshipEndCardinality; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.RelationshipEndDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefAttribute; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefLink; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * The Omrs bean model is a representation of entities attributes and references in a form that can be easily used by the generator diff --git a/open-metadata-test/open-metadata-ut/src/main/java/org/odpi/openmetadata/test/unittest/utilities/BeanTestBase.java b/open-metadata-test/open-metadata-ut/src/main/java/org/odpi/openmetadata/test/unittest/utilities/BeanTestBase.java index bd16cfa009f..d13bfe34695 100644 --- a/open-metadata-test/open-metadata-ut/src/main/java/org/odpi/openmetadata/test/unittest/utilities/BeanTestBase.java +++ b/open-metadata-test/open-metadata-ut/src/main/java/org/odpi/openmetadata/test/unittest/utilities/BeanTestBase.java @@ -4,6 +4,8 @@ package org.odpi.openmetadata.test.unittest.utilities; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import static org.testng.Assert.*; @@ -12,6 +14,10 @@ */ public class BeanTestBase { + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(); + private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writer(); + /** * Validate that 2 different objects with the same content are evaluated as equal. * Also that different objects are considered not equal. @@ -57,7 +63,6 @@ private void testStringEqualsHashcode(T testObject, */ protected T testJSON(T testObject, Class testObjectClass) { - ObjectMapper objectMapper = new ObjectMapper(); String jsonString = null; /* @@ -65,7 +70,7 @@ protected T testJSON(T testObject, Class testObjectClass) */ try { - jsonString = objectMapper.writeValueAsString(testObject); + jsonString = OBJECT_WRITER.writeValueAsString(testObject); } catch (Throwable exc) { @@ -74,7 +79,7 @@ protected T testJSON(T testObject, Class testObjectClass) try { - return objectMapper.readValue(jsonString, testObjectClass); + return OBJECT_READER.readValue(jsonString, testObjectClass); } catch (Throwable exc) { From 4307e58ff4ce22104d1e97e815413f2aacb49f2a Mon Sep 17 00:00:00 2001 From: Alexandra Bucur Date: Fri, 16 Dec 2022 15:38:52 +0200 Subject: [PATCH 2/8] Fix Maven build Signed-off-by: Alexandra Bucur --- .../access-services/data-engine/data-engine-server/pom.xml | 5 ----- .../open-lineage-services-server/pom.xml | 5 ----- 2 files changed, 10 deletions(-) diff --git a/open-metadata-implementation/access-services/data-engine/data-engine-server/pom.xml b/open-metadata-implementation/access-services/data-engine/data-engine-server/pom.xml index 40eeed2d661..b700c41a5da 100644 --- a/open-metadata-implementation/access-services/data-engine/data-engine-server/pom.xml +++ b/open-metadata-implementation/access-services/data-engine/data-engine-server/pom.xml @@ -124,11 +124,6 @@ jackson-databind - - com.fasterxml.jackson.core - jackson-core - - org.apache.commons commons-lang3 diff --git a/open-metadata-implementation/governance-servers/open-lineage-services/open-lineage-services-server/pom.xml b/open-metadata-implementation/governance-servers/open-lineage-services/open-lineage-services-server/pom.xml index edde5d81b1c..b03246dce10 100644 --- a/open-metadata-implementation/governance-servers/open-lineage-services/open-lineage-services-server/pom.xml +++ b/open-metadata-implementation/governance-servers/open-lineage-services/open-lineage-services-server/pom.xml @@ -91,11 +91,6 @@ asset-lineage-client - - com.fasterxml.jackson.core - jackson-core - - org.apache.commons commons-collections4 From 3a5e287820e48221193e4fe3b0b9234e1d8aab01 Mon Sep 17 00:00:00 2001 From: Alexandra Bucur Date: Mon, 19 Dec 2022 15:25:47 +0200 Subject: [PATCH 3/8] Update charset Signed-off-by: Alexandra Bucur Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com> --- .../fvt/synchronization/SynchronizationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java index a31f9cd4665..ce03405e298 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java @@ -189,6 +189,6 @@ public static T readObjectJson(String folder, String fileName { String root = Paths.get(".").toAbsolutePath().normalize().toString(); String input = root + folder + fileName + ".json"; - return OBJECT_READER.readValue(new String(Files.readAllBytes(Paths.get(input))), cls); + return OBJECT_READER.readValue(new String(Files.readAllBytes(Paths.get(input)), Charset.defaultCharset()), cls); } } From cb2af6fec9ee5c1ec27deab9623f75aa7108a2a9 Mon Sep 17 00:00:00 2001 From: Alexandra Bucur Date: Mon, 19 Dec 2022 15:39:32 +0200 Subject: [PATCH 4/8] Update charset Signed-off-by: Alexandra Bucur --- .../fvt/synchronization/SynchronizationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java index ce03405e298..169bd30c643 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java @@ -17,6 +17,7 @@ import org.odpi.openmetadata.fvt.utilities.exceptions.FVTUnexpectedCondition; import java.io.IOException; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; From 8ecd1f7bc0c37a059669c179ec3dcd9c134d8899 Mon Sep 17 00:00:00 2001 From: Alexandra Bucur Date: Mon, 19 Dec 2022 16:27:18 +0200 Subject: [PATCH 5/8] Normalize filepath Signed-off-by: Alexandra Bucur --- .../fvt/synchronization/SynchronizationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java index 169bd30c643..ee57f67ab6f 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java @@ -190,6 +190,6 @@ public static T readObjectJson(String folder, String fileName { String root = Paths.get(".").toAbsolutePath().normalize().toString(); String input = root + folder + fileName + ".json"; - return OBJECT_READER.readValue(new String(Files.readAllBytes(Paths.get(input)), Charset.defaultCharset()), cls); + return OBJECT_READER.readValue(Files.readString(Paths.get(input).normalize(), Charset.defaultCharset()), cls); } } From 4fabe9e030c207eea2a363493825ea9ef2069623 Mon Sep 17 00:00:00 2001 From: Alexandra Bucur Date: Tue, 20 Dec 2022 15:24:00 +0200 Subject: [PATCH 6/8] Fix sonar issue Signed-off-by: Alexandra Bucur --- .../fvt/synchronization/SynchronizationTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java index ee57f67ab6f..21421fdddce 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; +import org.apache.commons.io.FilenameUtils; import org.odpi.openmetadata.accessservices.analyticsmodeling.client.SynchronizationClient; import org.odpi.openmetadata.accessservices.analyticsmodeling.fvt.RepositoryService; import org.odpi.openmetadata.accessservices.analyticsmodeling.fvt.common.AnalyticsModelingTestBase; @@ -190,6 +191,7 @@ public static T readObjectJson(String folder, String fileName { String root = Paths.get(".").toAbsolutePath().normalize().toString(); String input = root + folder + fileName + ".json"; - return OBJECT_READER.readValue(Files.readString(Paths.get(input).normalize(), Charset.defaultCharset()), cls); + String name = FilenameUtils.getName(input); + return OBJECT_READER.readValue(Files.readString(Paths.get(name), Charset.defaultCharset()), cls); } } From 16f88d90dcedff68c61176446d571a1ad1719d41 Mon Sep 17 00:00:00 2001 From: Alexandra Bucur Date: Tue, 20 Dec 2022 17:22:28 +0200 Subject: [PATCH 7/8] Add dependency to build + fix FVT Signed-off-by: Alexandra Bucur --- .../access-services-fvt/analytics-modeling-fvt/build.gradle | 1 + .../access-services-fvt/analytics-modeling-fvt/pom.xml | 5 +++++ .../fvt/synchronization/SynchronizationTest.java | 5 ++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/build.gradle b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/build.gradle index 0bc7fff7e1b..1663f481633 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/build.gradle +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/build.gradle @@ -24,6 +24,7 @@ dependencies { implementation project(':open-metadata-test:open-metadata-fvt:fvt-utilities') implementation project(':open-metadata-implementation:common-services:generic-handlers') implementation 'com.fasterxml.jackson.core:jackson-databind' + implementation 'commons-io:commons-io' testImplementation project(':open-metadata-distribution:open-metadata-assemblies') testImplementation 'org.junit.jupiter:junit-jupiter-api' diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/pom.xml b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/pom.xml index 17c33f2ef89..2ec684eee8e 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/pom.xml +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/pom.xml @@ -114,6 +114,11 @@ test + + commons-io + commons-io + + diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java index 21421fdddce..77491deb674 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/analytics-modeling-fvt/src/main/java/org/odpi/openmetadata/accessservices/analyticsmodeling/fvt/synchronization/SynchronizationTest.java @@ -190,8 +190,7 @@ public static T readObjectJson(String folder, String fileName throws IOException { String root = Paths.get(".").toAbsolutePath().normalize().toString(); - String input = root + folder + fileName + ".json"; - String name = FilenameUtils.getName(input); - return OBJECT_READER.readValue(Files.readString(Paths.get(name), Charset.defaultCharset()), cls); + String input = root + folder + FilenameUtils.getName(fileName) + ".json"; + return OBJECT_READER.readValue(Files.readString(Paths.get(input).normalize(), Charset.defaultCharset()), cls); } } From b9117beb37189d1732c815ab2d1c0bcb84ff0773 Mon Sep 17 00:00:00 2001 From: Alexandra Bucur Date: Wed, 25 Jan 2023 14:26:10 +0200 Subject: [PATCH 8/8] Minor fix from review Signed-off-by: Alexandra Bucur --- .../connectors/omrstopic/OMRSTopicConnector.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/omrstopic/OMRSTopicConnector.java b/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/omrstopic/OMRSTopicConnector.java index 8cac658a8db..f26285ce632 100644 --- a/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/omrstopic/OMRSTopicConnector.java +++ b/open-metadata-implementation/repository-services/repository-services-apis/src/main/java/org/odpi/openmetadata/repositoryservices/connectors/omrstopic/OMRSTopicConnector.java @@ -441,8 +441,6 @@ private boolean sendEventTask(OMRSEventV1 event, final String methodName = "sendEventTask"; try { - ObjectMapper objectMapper = new ObjectMapper(); - String eventString = OBJECT_WRITER.writeValueAsString(event); if ((auditLog != null) && logEvent)