Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Asset Catalog to use Generic Handlers #6328

Merged
merged 21 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
964592a
Refactor Asset Catalog to use Generic Handlers
Oct 22, 2021
bad049b
Merge branch 'master' into asset-catalog-generic-handlers
Oct 22, 2021
16236aa
Fix gradle build
Oct 22, 2021
4aa9347
Merge remote-tracking branch 'fork/asset-catalog-generic-handlers' in…
Oct 22, 2021
acd6459
Fix conflicts
Nov 2, 2021
0c94916
Merge branch 'master' into asset-catalog-generic-handlers
Nov 3, 2021
660adf9
Merge branch 'master' of github.com:odpi/egeria into asset-catalog-ge…
Feb 15, 2022
b510a01
Asset Catalog - Merge conflict and fix search method
Feb 15, 2022
d30ecff
Asset Catalog - Merge conflict and fix search method
Feb 15, 2022
47d45e5
Asset Catalog - Use existing method in generic handlers for search
Feb 16, 2022
d7aaa62
Merge branch 'master' into asset-catalog-generic-handlers
Feb 16, 2022
413ca23
Merge branch 'master' of github.com:odpi/egeria into asset-catalog-ge…
Feb 18, 2022
7b2c371
Asset Catalog - Remove unused error codes
Feb 18, 2022
bf8f1c7
Merge branch 'master' into asset-catalog-generic-handlers
Feb 28, 2022
7330b1a
Merge branch 'master' into asset-catalog-generic-handlers
lcpopa Mar 3, 2022
9766bd6
Merge branch 'master' of github.com:odpi/egeria into asset-catalog-ge…
Mar 15, 2022
c3f3ff2
Merge branch 'master' of github.com:odpi/egeria into asset-catalog-ge…
Mar 15, 2022
05c66cb
Asset Catalog - add server name to getRelationshipBetweenEntities
Mar 16, 2022
06562a1
Merge branch 'master' into asset-catalog-generic-handlers-2
Mar 16, 2022
613142f
Merge branch 'master' into asset-catalog-generic-handlers-2
Mar 21, 2022
dd46671
Merge branch 'master' into asset-catalog-generic-handlers-2
Mar 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,17 @@ public enum AssetCatalogErrorCode implements ExceptionMessageSet {
"The system is unable to retrieve the assets neighborhood from the specified asset identifier.",
"Check that the unique identifier for the asset is correct."),

LINKING_RELATIONSHIPS_NOT_FOUND(404, "OMAS-ASSET-CATALOG-404-015 ",
"There is no intermediate relationships that connect the {0} with the {1} in OMAS Server {2}",
"The system is unable to retrieve the linking relationship.",
"Check that the unique identifier for the asset is correct."),

LINKING_ASSETS_NOT_FOUND(404, "OMAS-ASSET-CATALOG-404-016 ",
"There is no intermediate assets that connect the {0} with the {1} in OMAS Server {2}",
"The system is unable to retrieve linking assets.",
"Check that the unique identifier for the asset is correct."),

TYPE_DEF_NOT_FOUND(404, "OMAS-ASSET-CATALOG-404-017 ",
"The provided entity type/s are non known to the OMAS Server",
"The provided entity type {0} is non known to the OMAS Server",
"The system is unable to retrieve assets of an unknown type/s.",
"Check that the entity type/s provided is/are correct."),

SERVICE_NOT_INITIALIZED(503, "OMAS-ASSET-CATALOG-503-001 ",
"The access service has not been initialized for server {0} and can not support REST API calls",
"The server has received a call to one of its open metadata access services but is unable to process it because the access service is not active for the requested server.",
"If the server is supposed to have this access service activated, correct the server configuration and restart the server.");
"The server has received a call to one of its open metadata access services but is unable to " +
"process it because the access service is not active for the requested server.",
"If the server is supposed to have this access service activated, correct the server configuration " +
"and restart the server.");

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ Once you have an instance of the client, you can use it to:

* Fetch the classification for a specific asset - [getClassificationsForAsset]()

* Returns a sub-graph of intermediate assets that connected two assets - [getLinkingAssets]()

* Return a sub-graph of relationships that connect two assets - [getLinkingRelationships]()

* Returns a list of supported asset types - [getSupportedTypes]()

* Returns the sub-graph that represents the list of assets that in neighborhood of the given asset - [getAssetsFromNeighborhood]()

* Return a list of assets matching the search criteria without the full context [searchByType](). Entity types are case
insensitive, so proper values should be given in the request, otherwise an EntityNotKnownException will be thrown. If
* Return a list of assets matching the search criteria without the full context [searchByType](). Entity types are case
insensitive, so proper values should be given in the request, otherwise an EntityNotKnownException will be thrown. If
no type will be provided the operation will be made using the default search types. In order to determine de supported types
call [getSupportedTypes]() before.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public class AssetCatalog extends OCFRESTClient implements AssetCatalogInterface
private static final String ASSET_UNIVERSE = "/asset-universe/{2}?assetType={3}";
private static final String ASSET_RELATIONSHIPS = "/asset-relationships/{2}?assetType={3}&relationshipType={4}&from={5}&pageSize={6}";
private static final String ASSET_CLASSIFICATIONS = "/asset-classifications/{2}?assetType={3}&classificationName={4}";
private static final String LINKING_ASSET = "/linking-assets/from/{2}/to/{3}";
private static final String LINKING_RELATIONSHIPS = "/linking-assets-relationships/from/{2}/to/{3}";
private static final String ASSETS_FROM_NEIGHBORHOOD = "/assets-from-neighborhood/{2}";
private static final String SEARCH = "/search?searchCriteria={2}";
private static final String ASSET_CONTEXT = "/asset-context/{2}?assetType={3}";
private static final String RELATIONSHIP_BETWEEN_ENTITIES = "/relationship-between-entities/{2}/{3}?relationshipType={4}";
Expand All @@ -50,8 +47,8 @@ public class AssetCatalog extends OCFRESTClient implements AssetCatalogInterface
private static final String SEARCH_PARAMETERS = "searchParameters";


private InvalidParameterHandler invalidParameterHandler = new InvalidParameterHandler();
private RESTExceptionHandler restExceptionHandler = new RESTExceptionHandler();
private final InvalidParameterHandler invalidParameterHandler = new InvalidParameterHandler();
private final RESTExceptionHandler restExceptionHandler = new RESTExceptionHandler();

/**
* Create a new AssetCatalog client.
Expand Down Expand Up @@ -153,66 +150,6 @@ public ClassificationListResponse getClassificationsForAsset(String userId,
return classificationListResponse;
}

/**
* {@inheritDoc}
*/
@Override
public AssetCatalogListResponse getLinkingAssets(String userId,
String startAssetGUID,
String endAssetGUID)
throws InvalidParameterException, PropertyServerException {
String methodName = "getLinkingAssets";

validateStartAndEndAssetsGUIDs(userId, startAssetGUID, endAssetGUID, methodName);

AssetCatalogListResponse response = callGetRESTCall(methodName, AssetCatalogListResponse.class,
serverPlatformURLRoot + BASE_PATH + LINKING_ASSET, serverName,
userId, startAssetGUID, endAssetGUID);

detectExceptions(response);
return response;
}

/**
* {@inheritDoc}
*/
@Override
public RelationshipListResponse getLinkingRelationships(String userId,
String startAssetGUID,
String endAssetGUID)
throws InvalidParameterException, PropertyServerException {
String methodName = "getLinkingRelationships";

validateStartAndEndAssetsGUIDs(userId, startAssetGUID, endAssetGUID, methodName);

RelationshipListResponse response = callGetRESTCall(methodName, RelationshipListResponse.class,
serverPlatformURLRoot + BASE_PATH + LINKING_RELATIONSHIPS, serverName,
userId, startAssetGUID, endAssetGUID);
detectExceptions(response);

return response;
}

/**
* {@inheritDoc}
*/
@Override
public AssetCatalogListResponse getAssetsFromNeighborhood(String userId,
String assetGUID,
SearchParameters searchParameters)
throws InvalidParameterException, PropertyServerException {
String methodName = "getAssetsFromNeighborhood";

validateSearchParams(userId, assetGUID, searchParameters, methodName);

AssetCatalogListResponse response = callPostRESTCall(methodName, AssetCatalogListResponse.class,
serverPlatformURLRoot + BASE_PATH + ASSETS_FROM_NEIGHBORHOOD, searchParameters, serverName, userId, assetGUID);

detectExceptions(response);

return response;
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.odpi.openmetadata.accessservices.assetcatalog.model.rest.body.SearchParameters;
import org.odpi.openmetadata.accessservices.assetcatalog.model.rest.responses.AssetCatalogResponse;
import org.odpi.openmetadata.accessservices.assetcatalog.model.rest.responses.AssetCatalogSupportedTypes;
import org.odpi.openmetadata.accessservices.assetcatalog.model.rest.responses.AssetCatalogListResponse;
import org.odpi.openmetadata.accessservices.assetcatalog.model.rest.responses.AssetListResponse;
import org.odpi.openmetadata.accessservices.assetcatalog.model.rest.responses.AssetResponse;
import org.odpi.openmetadata.accessservices.assetcatalog.model.rest.responses.ClassificationListResponse;
Expand Down Expand Up @@ -77,42 +76,6 @@ public interface AssetCatalogInterface {
*/
ClassificationListResponse getClassificationsForAsset(String userId, String assetGUID, String assetType, String classificationName) throws InvalidParameterException, PropertyServerException;

/**
* Returns a sub-graph of intermediate assets that connected two assets
*
* @param userId the unique identifier for the user
* @param startAssetGUID the starting asset identifier of the query
* @param endAssetGUID the ending asset identifier of the query
* @return a list of assets between the given assets
* @throws PropertyServerException if a problem occurs while serving the request
* @throws InvalidParameterException if parameter validation fails
*/
AssetCatalogListResponse getLinkingAssets(String userId, String startAssetGUID, String endAssetGUID) throws InvalidParameterException, PropertyServerException;

/**
* Return a sub-graph of relationships that connect two assets
*
* @param userId the unique identifier for the user
* @param startAssetGUID the starting asset identifier of the query
* @param endAssetGUID the ending asset identifier of the query
* @return a list of relationships that connects the assets
* @throws PropertyServerException if a problem occurs while serving the request
* @throws InvalidParameterException if parameter validation fails
*/
RelationshipListResponse getLinkingRelationships(String userId, String startAssetGUID, String endAssetGUID) throws InvalidParameterException, PropertyServerException;

/**
* Returns the sub-graph that represents the list of assets that in neighborhood of the given asset
*
* @param userId the unique identifier for the user
* @param assetGUID the starting asset identifier of the query
* @param searchParameters constrains to make the assets's search results more precise
* @return a list of assets that in neighborhood of the given asset
* @throws PropertyServerException if a problem occurs while serving the request
* @throws InvalidParameterException if parameter validation fails
*/
AssetCatalogListResponse getAssetsFromNeighborhood(String userId, String assetGUID, SearchParameters searchParameters) throws InvalidParameterException, PropertyServerException;

/**
* Return a list of assets matching the search criteria without the full context
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,66 +140,6 @@ public void testGetClassificationsForAsset() throws Exception {
Assert.assertEquals(CLASSIFICATION_NAME, classificationListResponse.getClassifications().get(0).getName());
}

@Test
public void testGetLinkingAssets() throws Exception {
AssetCatalogListResponse response = mockAssetDescriptionListResponse();

when(connector.callGetRESTCall(eq("getLinkingAssets"),
eq(AssetCatalogListResponse.class),
anyString(),
eq(SERVER_NAME),
eq(USER_ID),
eq(ASSET_ID),
eq(SECOND_ASSET_ID))).thenReturn(response);

AssetCatalogListResponse assetCatalogListResponse = assetCatalog.getLinkingAssets(USER_ID,
ASSET_ID,
SECOND_ASSET_ID);

Assert.assertEquals(ASSET_ID, assetCatalogListResponse.getAssetCatalogBeanList().get(0).getGuid());
}

@Test
public void testGetLinkingRelationships() throws Exception {
RelationshipListResponse response = mockRelationshipsResponse();

when(connector.callGetRESTCall(eq("getLinkingRelationships"),
eq(RelationshipListResponse.class),
anyString(),
eq(SERVER_NAME),
eq(USER_ID),
eq(ASSET_ID),
eq(SECOND_ASSET_ID))).thenReturn(response);

RelationshipListResponse relationshipListResponse = assetCatalog.getLinkingRelationships(USER_ID,
ASSET_ID,
SECOND_ASSET_ID);

Assert.assertEquals(ASSET_ID, relationshipListResponse.getRelationships().get(0).getFromEntity().getGuid());
Assert.assertEquals(SECOND_ASSET_ID, relationshipListResponse.getRelationships().get(0).getToEntity().getGuid());
}

@Test
public void testGetAssetsFromNeighborhood() throws Exception {
AssetCatalogListResponse response = mockAssetDescriptionListResponse();
SearchParameters searchParameters = mockSearchParameters();

when(connector.callPostRESTCall(eq("getAssetsFromNeighborhood"),
eq(AssetCatalogListResponse.class),
anyString(),
eq(searchParameters),
eq(SERVER_NAME),
eq(USER_ID),
eq(ASSET_ID)
)).thenReturn(response);

AssetCatalogListResponse assetsFromNeighborhood = assetCatalog.getAssetsFromNeighborhood(USER_ID,
ASSET_ID,
searchParameters);

Assert.assertEquals(ASSET_ID, assetsFromNeighborhood.getAssetCatalogBeanList().get(0).getGuid());
}

@Test
public void testSearchByType() throws Exception {
AssetListResponse response = mockAssetListResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ dependencies {
implementation project(':open-metadata-implementation:admin-services:admin-services-registration')
implementation project(':open-metadata-implementation:repository-services:repository-services-apis')
implementation project(':open-metadata-implementation:common-services:multi-tenant')
implementation project(':open-metadata-implementation:common-services:generic-handlers')
implementation 'org.apache.commons:commons-collections4'
implementation project(':open-metadata-implementation:common-services:repository-handler')
implementation project(':open-metadata-implementation:frameworks:open-connector-framework')
implementation project(':open-metadata-implementation:common-services:ffdc-services')
implementation project(':open-metadata-implementation:common-services:ocf-metadata-management:ocf-metadata-handlers')
implementation project(':open-metadata-implementation:common-services:metadata-security:metadata-security-server')
implementation 'org.slf4j:slf4j-api'
implementation 'org.springframework:spring-core'
implementation 'com.fasterxml.jackson.core:jackson-databind'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
<artifactId>ocf-metadata-handlers</artifactId>
</dependency>

<dependency>
<groupId>org.odpi.egeria</groupId>
<artifactId>generic-handlers</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package org.odpi.openmetadata.accessservices.assetcatalog.admin;

import org.odpi.openmetadata.accessservices.assetcatalog.auditlog.AssetCatalogAuditCode;
import org.odpi.openmetadata.accessservices.assetcatalog.listenenrs.AssetCatalogOMRSTopicListener;
import org.odpi.openmetadata.accessservices.assetcatalog.listeners.AssetCatalogOMRSTopicListener;
import org.odpi.openmetadata.adminservices.configuration.properties.AccessServiceConfig;
import org.odpi.openmetadata.adminservices.configuration.registration.AccessServiceAdmin;
import org.odpi.openmetadata.adminservices.configuration.registration.AccessServiceDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import lombok.Getter;
import org.odpi.openmetadata.accessservices.assetcatalog.connectors.outtopic.AssetCatalogOutTopicClientProvider;
import org.odpi.openmetadata.accessservices.assetcatalog.converters.AssetCatalogConverter;
import org.odpi.openmetadata.accessservices.assetcatalog.exception.AssetCatalogErrorCode;
import org.odpi.openmetadata.accessservices.assetcatalog.handlers.AssetCatalogHandler;
import org.odpi.openmetadata.accessservices.assetcatalog.handlers.CommonHandler;
import org.odpi.openmetadata.accessservices.assetcatalog.handlers.RelationshipHandler;
import org.odpi.openmetadata.accessservices.assetcatalog.model.AssetCatalogBean;
import org.odpi.openmetadata.adminservices.configuration.registration.AccessServiceDescription;
import org.odpi.openmetadata.commonservices.generichandlers.OpenMetadataAPIGenericHandler;
import org.odpi.openmetadata.commonservices.multitenant.OMASServiceInstance;
import org.odpi.openmetadata.commonservices.multitenant.ffdc.exceptions.NewInstanceException;
import org.odpi.openmetadata.frameworks.auditlog.AuditLog;
Expand Down Expand Up @@ -69,12 +71,21 @@ class AssetCatalogServicesInstance extends OMASServiceInstance {
super.supportedZones = supportedZones;

if (repositoryHandler != null) {
AssetCatalogConverter<AssetCatalogBean> assetCatalogConverter =
new AssetCatalogConverter<>(repositoryHelper, serviceName, serverName);

assetCatalogHandler = new AssetCatalogHandler(serverName, sourceName, invalidParameterHandler, repositoryHandler, repositoryHelper,
errorHandler, supportedZones, supportedTypesForSearch);
CommonHandler commonHandler = new CommonHandler(sourceName, repositoryHandler, repositoryHelper, errorHandler);
relationshipHandler = new RelationshipHandler(sourceName, invalidParameterHandler, repositoryHandler, repositoryHelper, errorHandler,
commonHandler);
OpenMetadataAPIGenericHandler<AssetCatalogBean> assetHandler =
new OpenMetadataAPIGenericHandler<>(new AssetCatalogConverter<>(repositoryHelper, serviceName, serverName),
AssetCatalogBean.class, serviceName, serverName, invalidParameterHandler, repositoryHandler,
repositoryHelper, localServerUserId, securityVerifier, supportedZones, defaultZones, publishZones,
auditLog);

assetCatalogHandler = new AssetCatalogHandler(serverName, sourceName, invalidParameterHandler,
repositoryHandler, repositoryHelper, assetHandler, assetCatalogConverter, errorHandler,
supportedZones, supportedTypesForSearch);

relationshipHandler = new RelationshipHandler(sourceName, invalidParameterHandler, repositoryHandler,
repositoryHelper, assetHandler, errorHandler);
} else {
final String methodName = "new ServiceInstance";
throw new NewInstanceException(AssetCatalogErrorCode.OMRS_NOT_INITIALIZED.getMessageDefinition(serverName),
Expand Down
Loading