-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6847 from popa-raluca/dedup-connector
Add sample deduplication connector
- Loading branch information
Showing
2 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
...rs/governanceactions/remediation/QualifiedNamePeerDuplicateGovernanceActionConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* SPDX-License-Identifier: Apache 2.0 */ | ||
/* Copyright Contributors to the ODPi Egeria project. */ | ||
package org.odpi.openmetadata.adapters.connectors.governanceactions.remediation; | ||
|
||
|
||
import org.odpi.openmetadata.adapters.connectors.governanceactions.ffdc.GovernanceActionConnectorsErrorCode; | ||
import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException; | ||
import org.odpi.openmetadata.frameworks.connectors.ffdc.OCFCheckedExceptionBase; | ||
import org.odpi.openmetadata.frameworks.governanceaction.OpenMetadataClient; | ||
import org.odpi.openmetadata.frameworks.governanceaction.RemediationGovernanceActionService; | ||
import org.odpi.openmetadata.frameworks.governanceaction.properties.ActionTargetElement; | ||
import org.odpi.openmetadata.frameworks.governanceaction.properties.CompletionStatus; | ||
import org.odpi.openmetadata.frameworks.governanceaction.properties.OpenMetadataElement; | ||
import org.odpi.openmetadata.frameworks.governanceaction.search.MatchCriteria; | ||
import org.odpi.openmetadata.frameworks.governanceaction.search.PrimitiveTypeCategory; | ||
import org.odpi.openmetadata.frameworks.governanceaction.search.PrimitiveTypePropertyValue; | ||
import org.odpi.openmetadata.frameworks.governanceaction.search.PropertyComparisonOperator; | ||
import org.odpi.openmetadata.frameworks.governanceaction.search.PropertyCondition; | ||
import org.odpi.openmetadata.frameworks.governanceaction.search.SearchProperties; | ||
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.PrimitiveDefCategory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* QualifiedNamePeerDuplicateGovernanceActionConnector checks the qualified name to determine the duplicates of the entity that is passed | ||
* as an action target. | ||
*/ | ||
public class QualifiedNamePeerDuplicateGovernanceActionConnector extends RemediationGovernanceActionService { | ||
private static final String QUALIFIED_NAME_PROPERTY = "qualifiedName"; | ||
|
||
/** | ||
* Indicates that the governance action service is completely configured and can begin processing. | ||
* <p> | ||
* This is a standard method from the Open Connector Framework (OCF) so | ||
* be sure to call super.start() at the start of your overriding version. | ||
* | ||
* @throws ConnectorCheckedException there is a problem within the governance action service. | ||
*/ | ||
@Override | ||
public void start() throws ConnectorCheckedException { | ||
final String methodName = "start"; | ||
|
||
super.start(); | ||
|
||
List<String> outputGuards = new ArrayList<>(); | ||
CompletionStatus completionStatus = CompletionStatus.INVALID; | ||
|
||
try { | ||
if (governanceContext.getActionTargetElements() == null) { | ||
completionStatus = CompletionStatus.FAILED; | ||
outputGuards.add(QualifiedNamePeerDuplicateGovernanceActionProvider.NO_TARGETS_DETECTED_GUARD); | ||
} else if (governanceContext.getActionTargetElements().size() == 1) { | ||
ActionTargetElement actionTarget = governanceContext.getActionTargetElements().get(0); | ||
OpenMetadataElement targetElement = actionTarget.getTargetElement(); | ||
|
||
OpenMetadataClient store = (OpenMetadataClient) governanceContext.getOpenMetadataStore(); | ||
|
||
String qualifiedName = targetElement.getElementProperties().getPropertyValueMap().get(QUALIFIED_NAME_PROPERTY).valueAsString(); | ||
SearchProperties searchProperties = getSearchProperties(qualifiedName); | ||
List<OpenMetadataElement> elements = store.findMetadataElements(targetElement.getType().getTypeId(), | ||
null, searchProperties, null, null, null, | ||
null, false, true, new Date(), 0, 0); | ||
|
||
if (elements != null) { | ||
String targetElementGUID = targetElement.getElementGUID(); | ||
if (elements.size() == 1 && elements.get(0).getElementGUID().equalsIgnoreCase(targetElementGUID)) { | ||
outputGuards.add(QualifiedNamePeerDuplicateGovernanceActionProvider.NO_DUPLICATION_DETECTED_GUARD); | ||
completionStatus = CompletionStatus.INVALID; | ||
} | ||
for (OpenMetadataElement duplicateAsset : elements) { | ||
String duplicateAssetGUID = duplicateAsset.getElementGUID(); | ||
if (duplicateAssetGUID.equalsIgnoreCase(targetElementGUID)) { | ||
continue; | ||
} | ||
store.linkElementsAsPeerDuplicates(targetElementGUID, duplicateAssetGUID, 1, | ||
null, null, null, null, null, true); | ||
outputGuards.add(QualifiedNamePeerDuplicateGovernanceActionProvider.DUPLICATE_ASSIGNED_GUARD); | ||
completionStatus = CompletionStatus.ACTIONED; | ||
} | ||
} | ||
} | ||
|
||
governanceContext.recordCompletionStatus(completionStatus, outputGuards); | ||
} catch (OCFCheckedExceptionBase error) { | ||
throw new ConnectorCheckedException(error.getReportedErrorMessage(), error); | ||
} catch (Exception error) { | ||
throw new ConnectorCheckedException(GovernanceActionConnectorsErrorCode.UNEXPECTED_EXCEPTION.getMessageDefinition(governanceServiceName, | ||
error.getClass().getName(), error.getMessage()), error.getClass().getName(), methodName, error); | ||
} | ||
} | ||
|
||
private SearchProperties getSearchProperties(String qualifiedName) { | ||
SearchProperties searchProperties = new SearchProperties(); | ||
List<PropertyCondition> conditions = new ArrayList<>(); | ||
PropertyCondition condition = new PropertyCondition(); | ||
PrimitiveTypePropertyValue primitivePropertyValue = new PrimitiveTypePropertyValue(); | ||
|
||
primitivePropertyValue.setPrimitiveTypeCategory(PrimitiveTypeCategory.OM_PRIMITIVE_TYPE_STRING); | ||
primitivePropertyValue.setPrimitiveValue(qualifiedName); | ||
primitivePropertyValue.setTypeName(PrimitiveDefCategory.OM_PRIMITIVE_TYPE_STRING.getName()); | ||
|
||
condition.setProperty(QUALIFIED_NAME_PROPERTY); | ||
condition.setOperator(PropertyComparisonOperator.EQ); | ||
condition.setValue(primitivePropertyValue); | ||
|
||
conditions.add(condition); | ||
|
||
searchProperties.setConditions(conditions); | ||
searchProperties.setMatchCriteria(MatchCriteria.ALL); | ||
return searchProperties; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ors/governanceactions/remediation/QualifiedNamePeerDuplicateGovernanceActionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
/* Copyright Contributors to the ODPi Egeria project. */ | ||
|
||
package org.odpi.openmetadata.adapters.connectors.governanceactions.remediation; | ||
|
||
import org.odpi.openmetadata.frameworks.connectors.properties.beans.ConnectorType; | ||
import org.odpi.openmetadata.frameworks.governanceaction.GovernanceActionServiceProviderBase; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* QualifiedNamePeerDuplicateGovernanceActionProvider is the OCF connector provider for the Deduplication Governance Action Service. | ||
* This is a Remediation Governance Action Service. | ||
*/ | ||
public class QualifiedNamePeerDuplicateGovernanceActionProvider extends GovernanceActionServiceProviderBase | ||
{ | ||
private static final String connectorTypeGUID = "346939c4-de2c-44aa-a044-0ec64df0560f"; | ||
private static final String connectorTypeQualifiedName = "Egeria:GovernanceActionService:Remediation:Deduplication"; | ||
private static final String connectorTypeDisplayName = "Deduplication Governance Action Service"; | ||
private static final String connectorTypeDescription = "Checks the qualified name of an action target element to determine its duplicates."; | ||
|
||
static final String DUPLICATE_ASSIGNED_GUARD = "duplicate-detected"; | ||
static final String DUPLICATE_ALREADY_ASSIGNED_GUARD = "duplicate-already-assigned"; | ||
static final String NO_DUPLICATION_DETECTED_GUARD = "no-duplication-detected"; | ||
static final String DUPLICATE_DETECTION_FAILED_GUARD = "duplicate-detection-failed"; | ||
static final String NO_TARGETS_DETECTED_GUARD = "no-targets-detected"; | ||
|
||
private static final String connectorClassName = QualifiedNamePeerDuplicateGovernanceActionConnector.class.getName(); | ||
|
||
|
||
/** | ||
* Constructor used to initialize the ConnectorProviderBase with the Java class name of the specific | ||
* store implementation. | ||
*/ | ||
public QualifiedNamePeerDuplicateGovernanceActionProvider() | ||
{ | ||
super(); | ||
super.setConnectorClassName(connectorClassName); | ||
|
||
supportedGuards = new ArrayList<>(); | ||
supportedGuards.add(DUPLICATE_ASSIGNED_GUARD); | ||
supportedGuards.add(DUPLICATE_ALREADY_ASSIGNED_GUARD); | ||
supportedGuards.add(NO_DUPLICATION_DETECTED_GUARD); | ||
supportedGuards.add(DUPLICATE_DETECTION_FAILED_GUARD); | ||
supportedGuards.add(NO_TARGETS_DETECTED_GUARD); | ||
|
||
super.setConnectorClassName(connectorClassName); | ||
|
||
ConnectorType connectorType = new ConnectorType(); | ||
connectorType.setType(ConnectorType.getConnectorTypeType()); | ||
connectorType.setGUID(connectorTypeGUID); | ||
connectorType.setQualifiedName(connectorTypeQualifiedName); | ||
connectorType.setDisplayName(connectorTypeDisplayName); | ||
connectorType.setDescription(connectorTypeDescription); | ||
connectorType.setConnectorProviderClassName(this.getClass().getName()); | ||
|
||
super.connectorTypeBean = connectorType; | ||
} | ||
} |