diff --git a/open-metadata-implementation/access-services/asset-manager/asset-manager-api/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/ffdc/AssetManagerErrorCode.java b/open-metadata-implementation/access-services/asset-manager/asset-manager-api/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/ffdc/AssetManagerErrorCode.java index c13ffe61f61..7979dc8d09b 100644 --- a/open-metadata-implementation/access-services/asset-manager/asset-manager-api/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/ffdc/AssetManagerErrorCode.java +++ b/open-metadata-implementation/access-services/asset-manager/asset-manager-api/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/ffdc/AssetManagerErrorCode.java @@ -35,14 +35,6 @@ public enum AssetManagerErrorCode implements ExceptionMessageSet "provide a scope for the external identifier.", "Ensure that the asset manager's unique identifier is passed on the request and then retry it."), - /** - * OMAS-ASSET-MANAGER-400-002 At least one of the properties supplied for a new relationship of type {0} are invalid. The {1} exception was returned with error message: {2} - */ - BAD_PARAMETER(400, "OMAS-ASSET-MANAGER-400-002", - "At least one of the properties supplied for a new relationship of type {0} are invalid. The {1} exception was returned with error message: {2}", - "The system is unable to create the requested relationship because it can not parse the properties.", - "Correct the caller's logic so that the properties passed are correctly formatted and retry the request."), - /** * OMAS-ASSET-MANAGER-404-001 The open metadata repository services are not initialized for the {0} operation */ diff --git a/open-metadata-implementation/access-services/asset-manager/asset-manager-client/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/client/exchange/DataAssetExchangeClient.java b/open-metadata-implementation/access-services/asset-manager/asset-manager-client/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/client/exchange/DataAssetExchangeClient.java index 279819ca373..11dae0dd36c 100644 --- a/open-metadata-implementation/access-services/asset-manager/asset-manager-client/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/client/exchange/DataAssetExchangeClient.java +++ b/open-metadata-implementation/access-services/asset-manager/asset-manager-client/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/client/exchange/DataAssetExchangeClient.java @@ -596,6 +596,7 @@ public String setupRelatedDataAsset(String userId, requestBody.setAssetManagerGUID(assetManagerGUID); requestBody.setAssetManagerName(assetManagerName); requestBody.setProperties(relationshipProperties); + requestBody.setEffectiveTime(effectiveTime); final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/data-assets/relationships/{2}/from-asset/{3}/to-asset/{4}?assetManagerIsHome={5}&forLineage={6}&forDuplicateProcessing={7}"; diff --git a/open-metadata-implementation/access-services/asset-manager/asset-manager-client/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/client/exchange/SchemaExchangeClientBase.java b/open-metadata-implementation/access-services/asset-manager/asset-manager-client/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/client/exchange/SchemaExchangeClientBase.java index c60048d74b1..5880f99d696 100644 --- a/open-metadata-implementation/access-services/asset-manager/asset-manager-client/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/client/exchange/SchemaExchangeClientBase.java +++ b/open-metadata-implementation/access-services/asset-manager/asset-manager-client/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/client/exchange/SchemaExchangeClientBase.java @@ -1084,6 +1084,7 @@ public String createSchemaAttributeFromTemplate(String use assetManagerName, externalIdentifierProperties, methodName)); + requestBody.setEffectiveTime(effectiveTime); final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-elements/{2}/schema-attributes/from-template/{3}?assetManagerIsHome={4}&forLineage={5}&forDuplicateProcessing={6}"; diff --git a/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/handlers/DataAssetExchangeHandler.java b/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/handlers/DataAssetExchangeHandler.java index 4a0e85aba2d..2261da844b8 100644 --- a/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/handlers/DataAssetExchangeHandler.java +++ b/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/handlers/DataAssetExchangeHandler.java @@ -721,8 +721,6 @@ public String setupRelatedDataAsset(String userId, String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, null, serviceName, methodName, repositoryHelper); InstanceProperties instanceProperties = null; - Date effectiveFrom = new Date(); - Date effectiveTo = new Date(); if (relationshipProperties != null) { @@ -752,8 +750,8 @@ public String setupRelatedDataAsset(String userId, relationshipTypeGUID, relationshipTypeName, instanceProperties, - effectiveFrom, - effectiveTo, + null, + null, effectiveTime, methodName); } @@ -774,8 +772,8 @@ public String setupRelatedDataAsset(String userId, relationshipTypeGUID, relationshipTypeName, instanceProperties, - effectiveFrom, - effectiveTo, + null, + null, effectiveTime, methodName); } @@ -846,7 +844,7 @@ public RelationshipElement getAssetRelationship(String userId, /** - * Concert an OMRS relationship into an Asset Manager's RelationshipElement. + * Convert an OMRS relationship into an Asset Manager's RelationshipElement. * * @param relationship retrieved relationship * @param methodName calling method diff --git a/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/handlers/SchemaExchangeHandler.java b/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/handlers/SchemaExchangeHandler.java index d2a057a888f..c5c3d24a80c 100644 --- a/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/handlers/SchemaExchangeHandler.java +++ b/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/handlers/SchemaExchangeHandler.java @@ -6,7 +6,6 @@ import org.odpi.openmetadata.accessservices.assetmanager.converters.ElementHeaderConverter; import org.odpi.openmetadata.accessservices.assetmanager.converters.SchemaAttributeConverter; import org.odpi.openmetadata.accessservices.assetmanager.converters.SchemaTypeConverter; -import org.odpi.openmetadata.accessservices.assetmanager.ffdc.AssetManagerErrorCode; import org.odpi.openmetadata.accessservices.assetmanager.metadataelements.*; import org.odpi.openmetadata.accessservices.assetmanager.properties.*; import org.odpi.openmetadata.commonservices.ffdc.InvalidParameterHandler; @@ -597,59 +596,26 @@ public void clearSchemaTypeParent(String userId, UserNotAuthorizedException, PropertyServerException { - final String schemaTypeGUIDParameterName = "schemaTypeGUID"; - final String parentElementGUIDParameterName = "parentElementGUID"; final String parentElementTypeParameterName = "parentElementTypeName"; invalidParameterHandler.validateName(parentElementTypeName, parentElementTypeParameterName, methodName); - if ((parentElementTypeName != null) && repositoryHelper.isTypeOf(serviceName, - parentElementTypeName, - OpenMetadataAPIMapper.PORT_TYPE_NAME)) - { - schemaTypeHandler.unlinkElementFromElement(userId, - false, - assetManagerGUID, - assetManagerName, - parentElementGUID, - parentElementGUIDParameterName, - parentElementTypeName, - schemaTypeGUID, - schemaTypeGUIDParameterName, - OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_GUID, - OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, - forLineage, - forDuplicateProcessing, - OpenMetadataAPIMapper.PORT_SCHEMA_RELATIONSHIP_TYPE_GUID, - OpenMetadataAPIMapper.PORT_SCHEMA_RELATIONSHIP_TYPE_NAME, - effectiveTime, - methodName); - } - else - { - schemaTypeHandler.unlinkElementFromElement(userId, - false, - assetManagerGUID, - assetManagerName, - parentElementGUID, - parentElementGUIDParameterName, - parentElementTypeName, - schemaTypeGUID, - schemaTypeGUIDParameterName, - OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_GUID, - OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, - forLineage, - forDuplicateProcessing, - OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_GUID, - OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_NAME, - effectiveTime, - methodName); - } + schemaTypeHandler.clearSchemaTypeParent(userId, + assetManagerGUID, + assetManagerName, + schemaTypeGUID, + parentElementGUID, + parentElementTypeName, + forLineage, + forDuplicateProcessing, + effectiveTime, + methodName); } /** - * Connect a schema type to a data asset, process or port. + * Create a relationship between two schema elements. The name of the desired relationship, and any properties (including effectivity dates) + * are passed on the API. * * @param userId calling user * @param assetManagerGUID unique identifier of software server capability representing the caller @@ -693,57 +659,43 @@ public void setupSchemaElementRelationship(String userId, final String relationshipTypeParameterName = "relationshipTypeName"; final String propertiesParameterName = "properties"; - invalidParameterHandler.validateName(relationshipTypeName, relationshipTypeParameterName, methodName); - - String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, - null, - serviceName, - methodName, - repositoryHelper); - - InstanceProperties instanceProperties = null; - - if ((properties != null) && (! properties.getExtendedProperties().isEmpty())) + if (properties != null) { - try - { - instanceProperties = repositoryHelper.addPropertyMapToInstance(serviceName, null, properties.getExtendedProperties(), methodName); - } - catch (Exception badPropertyException) - { - throw new InvalidParameterException(AssetManagerErrorCode.BAD_PARAMETER.getMessageDefinition(relationshipTypeName, - badPropertyException.getClass().getName(), - badPropertyException.getMessage()), - this.getClass().getName(), - methodName, - badPropertyException, - propertiesParameterName); - } + schemaTypeHandler.setupSchemaElementRelationship(userId, + this.getExternalSourceGUID(assetManagerGUID, assetManagerIsHome), + this.getExternalSourceName(assetManagerName, assetManagerIsHome), + endOneGUID, + endTwoGUID, + relationshipTypeName, + properties.getExtendedProperties(), + effectiveFrom, + effectiveTo, + forLineage, + forDuplicateProcessing, + effectiveTime, + methodName); + } + else + { + schemaTypeHandler.setupSchemaElementRelationship(userId, + this.getExternalSourceGUID(assetManagerGUID, assetManagerIsHome), + this.getExternalSourceName(assetManagerName, assetManagerIsHome), + endOneGUID, + endTwoGUID, + relationshipTypeName, + null, + effectiveFrom, + effectiveTo, + forLineage, + forDuplicateProcessing, + effectiveTime, + methodName); } - - schemaTypeHandler.linkElementToElement(userId, - this.getExternalSourceGUID(assetManagerGUID, assetManagerIsHome), - this.getExternalSourceName(assetManagerName, assetManagerIsHome), - endOneGUID, - endOneParameterName, - OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, - endTwoGUID, - endTwoParameterName, - OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, - forLineage, - forDuplicateProcessing, - relationshipTypeGUID, - relationshipTypeName, - instanceProperties, - effectiveFrom, - effectiveTo, - effectiveTime, - methodName); } /** - * Remove the relationship between a schema type and its parent data asset, process or port. + * Remove a relationship between two schema elements. The name of the desired relationship is passed on the API. * * @param userId calling user * @param assetManagerGUID unique identifier of software server capability representing the caller @@ -773,35 +725,20 @@ public void clearSchemaElementRelationship(String userId, UserNotAuthorizedException, PropertyServerException { - final String endOneParameterName = "endOneGUID"; - final String endTwoParameterName = "endTwoGUID"; final String relationshipTypeParameterName = "relationshipTypeName"; invalidParameterHandler.validateName(relationshipTypeName, relationshipTypeParameterName, methodName); - String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, - null, - serviceName, - methodName, - repositoryHelper); - - schemaTypeHandler.unlinkElementFromElement(userId, - false, - assetManagerGUID, - assetManagerName, - endOneGUID, - endOneParameterName, - OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, - endTwoGUID, - endTwoParameterName, - OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_GUID, - OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, - forLineage, - forDuplicateProcessing, - relationshipTypeGUID, - relationshipTypeName, - effectiveTime, - methodName); + schemaTypeHandler.clearSchemaElementRelationship(userId, + assetManagerGUID, + assetManagerName, + endOneGUID, + endTwoGUID, + relationshipTypeName, + forLineage, + forDuplicateProcessing, + effectiveTime, + methodName); } @@ -2084,7 +2021,7 @@ public List getNestedAttributes(String userId, UserNotAuthorizedException, PropertyServerException { - final String elementGUIDParameterName = "schemaAttributeGUID"; + final String elementGUIDParameterName = "parentSchemaElementGUID"; List results = schemaAttributeHandler.getAttachedSchemaAttributes(userId, parentSchemaElementGUID, diff --git a/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/server/SchemaExchangeRESTServices.java b/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/server/SchemaExchangeRESTServices.java index 54358d0a53d..71e5dcfd777 100644 --- a/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/server/SchemaExchangeRESTServices.java +++ b/open-metadata-implementation/access-services/asset-manager/asset-manager-server/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/server/SchemaExchangeRESTServices.java @@ -114,8 +114,7 @@ public GUIDResponse createSchemaType(String serverName, * @param templateGUID unique identifier of the metadata element to copy * @param requestBody properties that override the template * - * @return unique identifier of the new schema type - * + * @return unique identifier of the new schema type or * InvalidParameterException one of the parameters is invalid * UserNotAuthorizedException the user is not authorized to issue this request * PropertyServerException there is a problem reported in the open metadata server(s) @@ -1148,13 +1147,13 @@ public VoidResponse updateSchemaAttribute(String serverName, * UserNotAuthorizedException the user is not authorized to issue this request * PropertyServerException there is a problem reported in the open metadata server(s) */ - public VoidResponse setSchemaElementAsCalculatedValue(String serverName, - String userId, - String schemaElementGUID, - boolean assetManagerIsHome, - boolean forLineage, - boolean forDuplicateProcessing, - UpdateRequestBody requestBody) + public VoidResponse setSchemaElementAsCalculatedValue(String serverName, + String userId, + String schemaElementGUID, + boolean assetManagerIsHome, + boolean forLineage, + boolean forDuplicateProcessing, + CalculatedValueClassificationRequestBody requestBody) { final String methodName = "setSchemaElementAsCalculatedValue"; @@ -1176,7 +1175,7 @@ public VoidResponse setSchemaElementAsCalculatedValue(String serverNa requestBody.getMetadataCorrelationProperties().getAssetManagerName(), assetManagerIsHome, schemaElementGUID, - requestBody.getMetadataCorrelationProperties().getExternalIdentifier(), + requestBody.getFormula(), forLineage, forDuplicateProcessing, requestBody.getEffectiveTime(), diff --git a/open-metadata-implementation/access-services/asset-manager/asset-manager-spring/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/server/spring/SchemaExchangeResource.java b/open-metadata-implementation/access-services/asset-manager/asset-manager-spring/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/server/spring/SchemaExchangeResource.java index 485c24b2620..a072ad747a0 100644 --- a/open-metadata-implementation/access-services/asset-manager/asset-manager-spring/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/server/spring/SchemaExchangeResource.java +++ b/open-metadata-implementation/access-services/asset-manager/asset-manager-spring/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/server/spring/SchemaExchangeResource.java @@ -582,15 +582,15 @@ public VoidResponse updateSchemaAttribute(@PathVariable String */ @PostMapping(path = "/schema-elements/{schemaElementGUID}/is-calculated-value") - public VoidResponse setSchemaElementAsCalculatedValue(@PathVariable String serverName, - @PathVariable String userId, - @PathVariable String schemaElementGUID, - @RequestParam boolean assetManagerIsHome, + public VoidResponse setSchemaElementAsCalculatedValue(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaElementGUID, + @RequestParam boolean assetManagerIsHome, @RequestParam (required = false, defaultValue = "false") - boolean forLineage, + boolean forLineage, @RequestParam (required = false, defaultValue = "false") - boolean forDuplicateProcessing, - @RequestBody UpdateRequestBody requestBody) + boolean forDuplicateProcessing, + @RequestBody CalculatedValueClassificationRequestBody requestBody) { return restAPI.setSchemaElementAsCalculatedValue(serverName, userId, schemaElementGUID, assetManagerIsHome, forLineage, forDuplicateProcessing, requestBody); } diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetDecommissioningInterface.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetDecommissioningInterface.java index 7739d9b1234..6a3aa05a832 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetDecommissioningInterface.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetDecommissioningInterface.java @@ -19,10 +19,10 @@ public interface AssetDecommissioningInterface * Deletes an asset and all of its associated elements such as schema, connections (unless they are linked to * another asset), discovery reports and associated feedback. * - * Given the depth of the delete performed by this call, it should be used with care. + * Given the depth of the delete operation performed by this call, it should be used with care. * * @param userId calling user - * @param assetGUID unique identifier of the attest to attach the connection to + * @param assetGUID unique identifier of the asset to delete * @throws InvalidParameterException full path or userId is null * @throws PropertyServerException problem accessing property server * @throws UserNotAuthorizedException security access problem diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetOnboardingInterface.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetOnboardingInterface.java index 9940cb2da56..1e91a354326 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetOnboardingInterface.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetOnboardingInterface.java @@ -3,7 +3,10 @@ package org.odpi.openmetadata.accessservices.assetowner.api; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaAttributeElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaTypeElement; import org.odpi.openmetadata.accessservices.assetowner.properties.AssetProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.RelationshipProperties; import org.odpi.openmetadata.accessservices.assetowner.properties.SchemaAttributeProperties; import org.odpi.openmetadata.accessservices.assetowner.properties.SchemaTypeProperties; import org.odpi.openmetadata.accessservices.assetowner.properties.TemplateProperties; @@ -11,8 +14,7 @@ import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException; import org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException; import org.odpi.openmetadata.frameworks.connectors.properties.beans.Connection; -import org.odpi.openmetadata.frameworks.connectors.properties.beans.SchemaAttribute; -import org.odpi.openmetadata.frameworks.connectors.properties.beans.SchemaType; +import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementHeader; import java.util.List; import java.util.Map; @@ -109,6 +111,73 @@ void updateAsset(String userId, PropertyServerException; + + + /** + * Link two asset together. + * Use information from the relationship type definition to ensure the fromAssetGUID and toAssetGUID are the right way around. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to create + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param relationshipProperties unique identifier for this relationship + * + * @return unique identifier of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + String setupRelatedAsset(String userId, + String relationshipTypeName, + String fromAssetGUID, + String toAssetGUID, + RelationshipProperties relationshipProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Update relationship between two elements. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to update + * @param relationshipGUID unique identifier of the relationship + * @param relationshipProperties description and/or purpose of the relationship + * @param isMergeUpdate should the new properties be merged with the existing properties, or replace them entirely + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void updateAssetRelationship(String userId, + String relationshipTypeName, + String relationshipGUID, + boolean isMergeUpdate, + RelationshipProperties relationshipProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Remove the relationship between two elements. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param relationshipGUID unique identifier of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void clearAssetRelationship(String userId, + String relationshipTypeName, + String relationshipGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + /** * Stores the supplied schema details in the catalog and attaches it to the asset. If another schema is currently * attached to the asset, it is unlinked and deleted. If more attributes need to be added in addition to the @@ -175,7 +244,7 @@ void attachSchemaTypeToAsset(String userId, /** - * Unlinks the schema from the asset but does not delete it. This means it can be be reattached to a different asset. + * Unlinks the schema from the asset but does not delete it. This means it can be reattached to a different asset. * * @param userId calling user * @param assetGUID unique identifier of the asset that the schema is to be attached to @@ -201,17 +270,306 @@ String detachSchemaTypeFromAsset(String userId, * @throws PropertyServerException problem accessing property server * @throws UserNotAuthorizedException security access problem */ - void deleteAssetSchemaType(String userId, - String assetGUID) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException; + void deleteAssetSchemaType(String userId, + String assetGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + + /* ===================================================================================================================== + * A schemaType describes the structure of a data asset, process or port + */ + + /** + * Create a new metadata element to represent a schema type. + * + * @param userId calling user + * @param schemaTypeProperties properties about the schema type to store + * + * @return unique identifier of the new schema type + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + String createSchemaType(String userId, + SchemaTypeProperties schemaTypeProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Create a new metadata element to represent a schema type. + * + * @param userId calling user + * @param anchorGUID unique identifier of the intended anchor of the schema type + * @param schemaTypeProperties properties about the schema type to store + * + * @return unique identifier of the new schema type + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + String createAnchoredSchemaType(String userId, + String anchorGUID, + SchemaTypeProperties schemaTypeProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Create a new metadata element to represent a schema type using an existing metadata element as a template. + * + * @param userId calling user + * @param templateGUID unique identifier of the metadata element to copy + * @param templateProperties properties that override the template + * + * @return unique identifier of the new schema type + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + String createSchemaTypeFromTemplate(String userId, + String templateGUID, + TemplateProperties templateProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Update the metadata element representing a schema type. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the metadata element to update + * @param isMergeUpdate should the new properties be merged with existing properties (true) or completely replace them (false)? + * @param schemaTypeProperties new properties for the metadata element + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void updateSchemaType(String userId, + String schemaTypeGUID, + boolean isMergeUpdate, + SchemaTypeProperties schemaTypeProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Connect a schema type to a data asset, process or port. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param properties properties for the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void setupSchemaTypeParent(String userId, + String schemaTypeGUID, + String parentElementGUID, + String parentElementTypeName, + RelationshipProperties properties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Remove the relationship between a schema type and its parent data asset, process or port. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void clearSchemaTypeParent(String userId, + String schemaTypeGUID, + String parentElementGUID, + String parentElementTypeName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Create a relationship between two schema elements. The name of the desired relationship, and any properties (including effectivity dates) + * are passed on the API. + * + * @param userId calling user + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to create + * @param properties relationship properties + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void setupSchemaElementRelationship(String userId, + String endOneGUID, + String endTwoGUID, + String relationshipTypeName, + RelationshipProperties properties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Remove a relationship between two schema elements. The name of the desired relationship is passed on the API. + * + * @param userId calling user + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to delete + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void clearSchemaElementRelationship(String userId, + String endOneGUID, + String endTwoGUID, + String relationshipTypeName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Remove the metadata element representing a schema type. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the metadata element to remove + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void removeSchemaType(String userId, + String schemaTypeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the list of schema type metadata elements that contain the search string. + * The search string is treated as a regular expression. + * + * @param userId calling user + * @param searchString string to find in the properties + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * + * @return list of matching metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + List findSchemaType(String userId, + String searchString, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Return the schema type associated with a specific open metadata element (data asset, process or port). + * + * @param userId calling user + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * + * @return metadata element describing the schema type associated with the requested parent element + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + SchemaTypeElement getSchemaTypeForElement(String userId, + String parentElementGUID, + String parentElementTypeName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the list of schema type metadata elements with a matching qualified or display name. + * There are no wildcards supported on this request. + * + * @param userId calling user + * @param name name to search for + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * + * @return list of matching metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + List getSchemaTypeByName(String userId, + String name, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the schema type metadata element with the supplied unique identifier. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the requested metadata element + * + * @return requested metadata element + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + SchemaTypeElement getSchemaTypeByGUID(String userId, + String schemaTypeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the header of the metadata element connected to a schema type. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the requested metadata element + * + * @return header for parent element (data asset, process, port) + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + ElementHeader getSchemaTypeParent(String userId, + String schemaTypeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + /* =============================================================================== + * A schemaType typically contains many schema attributes, linked with relationships. + */ /** * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. * This method can be called repeatedly to add many attributes to a schema. * - * @param serverName name of the server instance to connect to * @param userId calling user * @param assetGUID unique identifier of the asset that the schema is to be attached to * @param parentGUID unique identifier of the schema element to anchor these attributes to. @@ -221,20 +579,19 @@ void deleteAssetSchemaType(String userId, * @throws PropertyServerException problem accessing property server * @throws UserNotAuthorizedException security access problem */ - void addSchemaAttributes(String serverName, - String userId, + void addSchemaAttributes(String userId, String assetGUID, String parentGUID, List schemaAttributes) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException; + /** * Adds an attribute to a complex schema type like a relational table, avro schema or a structured document. * This method can be called repeatedly to add many attributes to a schema. Since the GUID is returned, it is possible * to add nested schema attributes to another schema attribute. * - * @param serverName name of the server instance to connect to * @param userId calling user * @param assetGUID unique identifier of the asset that the schema is to be attached to * @param parentGUID unique identifier of the schema element to anchor these attributes to. @@ -246,8 +603,7 @@ void addSchemaAttributes(String serverName, * @throws PropertyServerException problem accessing property server * @throws UserNotAuthorizedException security access problem */ - String addSchemaAttribute(String serverName, - String userId, + String addSchemaAttribute(String userId, String assetGUID, String parentGUID, SchemaAttributeProperties schemaAttribute) throws InvalidParameterException, @@ -255,11 +611,189 @@ String addSchemaAttribute(String serverName, PropertyServerException; + + /** + * Create a new metadata element to represent a schema attribute using an existing metadata element as a template. + * + * @param userId calling user + * @param schemaElementGUID unique identifier of the schemaType or Schema Attribute where the schema attribute is connected to + * @param templateGUID unique identifier of the metadata element to copy + * @param templateProperties properties that override the template + * + * @return unique identifier of the new metadata element for the schema attribute + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + String createSchemaAttributeFromTemplate(String userId, + String schemaElementGUID, + String templateGUID, + TemplateProperties templateProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Update the properties of the metadata element representing a schema attribute. + * + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the schema attribute to update + * @param isMergeUpdate should the new properties be merged with existing properties (true) or completely replace them (false)? + * @param schemaAttributeProperties new properties for the schema attribute + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void updateSchemaAttribute(String userId, + String schemaAttributeGUID, + boolean isMergeUpdate, + SchemaAttributeProperties schemaAttributeProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Classify the schema type (or attribute if type is embedded) to indicate that it is a calculated value. + * + * @param userId calling user + * @param schemaElementGUID unique identifier of the metadata element to update + * @param formula description of the logic that maps data values to + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void setSchemaElementAsCalculatedValue(String userId, + String schemaElementGUID, + String formula) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Remove the calculated value designation from the schema element. + * + * @param userId calling user + * @param schemaElementGUID unique identifier of the metadata element to update + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void clearSchemaElementAsCalculatedValue(String userId, + String schemaElementGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Remove the metadata element representing a schema attribute. + * + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the metadata element to remove + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + void removeSchemaAttribute(String userId, + String schemaAttributeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the list of schema attribute metadata elements that contain the search string. + * The search string is treated as a regular expression. + * + * @param userId calling user + * @param searchString string to find in the properties + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * + * @return list of matching metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + List findSchemaAttributes(String userId, + String searchString, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the list of schema attributes associated with a schema element. + * + * @param userId calling user + * @param parentSchemaElementGUID unique identifier of the schema element of interest + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * + * @return list of associated metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + List getNestedSchemaAttributes(String userId, + String parentSchemaElementGUID, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the list of schema attribute metadata elements with a matching qualified or display name. + * There are no wildcards supported on this request. + * + * @param userId calling user + * @param name name to search for + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * + * @return list of matching metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + List getSchemaAttributesByName(String userId, + String name, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the schema attribute metadata element with the supplied unique identifier. + * + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the requested metadata element + * + * @return matching metadata element + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + SchemaAttributeElement getSchemaAttributeByGUID(String userId, + String schemaAttributeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + /** * Adds a connection to an asset. Assets can have multiple connections attached. * * @param userId calling user - * @param assetGUID unique identifier of the attest to attach the connection to + * @param assetGUID unique identifier of the asset to attach the connection to * @param assetSummary summary of the asset that is stored in the relationship between the asset and the connection. * @param connection connection object. If the connection is already stored (matching guid) * then the existing connection is used. diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetReviewInterface.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetReviewInterface.java index 7ca2d243154..73ed7675106 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetReviewInterface.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/api/AssetReviewInterface.java @@ -4,6 +4,7 @@ package org.odpi.openmetadata.accessservices.assetowner.api; import org.odpi.openmetadata.accessservices.assetowner.metadataelements.AssetElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.RelationshipElement; import org.odpi.openmetadata.frameworks.connectors.Connector; import org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException; import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException; @@ -13,6 +14,7 @@ import org.odpi.openmetadata.frameworks.discovery.properties.AnnotationStatus; import org.odpi.openmetadata.frameworks.discovery.properties.DiscoveryAnalysisReport; +import java.util.Date; import java.util.List; import java.util.Map; @@ -98,6 +100,77 @@ AssetUniverse getAssetProperties(String userId, UserNotAuthorizedException, PropertyServerException; + /** + * Retrieve the relationship between two elements. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to create + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * + * @return unique identifier and properties of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + RelationshipElement getAssetRelationship(String userId, + String relationshipTypeName, + String fromAssetGUID, + String toAssetGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + + /** + * Retrieve the requested relationships linked from a specific element at end 2. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param startFrom start position for results + * @param pageSize maximum number of results + * + * @return unique identifier and properties of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + List getRelatedAssetsAtEnd2(String userId, + String relationshipTypeName, + String fromAssetGUID, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + + /** + * Retrieve the relationships linked from a specific element at end 2 of the relationship. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param startFrom start position for results + * @param pageSize maximum number of results + * + * @return unique identifier and properties of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + List getRelatedAssetsAtEnd1(String userId, + String relationshipTypeName, + String toAssetGUID, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException; + + /** * Return a connector for the asset to enable the calling user to access the content. diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/metadataelements/RelationshipElement.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/metadataelements/RelationshipElement.java new file mode 100644 index 00000000000..06da1a28004 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/metadataelements/RelationshipElement.java @@ -0,0 +1,197 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.metadataelements; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.accessservices.assetowner.properties.RelationshipProperties; +import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementHeader; + +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * RelationshipElement contains the properties and header for a relationship retrieved from the metadata repository. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class RelationshipElement +{ + private ElementHeader relationshipHeader = null; + private RelationshipProperties relationshipProperties = null; + private ElementHeader end1GUID = null; + private ElementHeader end2GUID = null; + + /** + * Default constructor + */ + public RelationshipElement() + { + super(); + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public RelationshipElement(RelationshipElement template) + { + if (template != null) + { + relationshipHeader = template.getRelationshipHeader(); + relationshipProperties = template.getRelationshipProperties(); + end1GUID = template.getEnd1GUID(); + end2GUID = template.getEnd2GUID(); + } + } + + + /** + * Return the element header associated with the relationship. + * + * @return element header object + */ + public ElementHeader getRelationshipHeader() + { + return relationshipHeader; + } + + + /** + * Set up the element header associated with the relationship. + * + * @param relationshipHeader element header object + */ + public void setRelationshipHeader(ElementHeader relationshipHeader) + { + this.relationshipHeader = relationshipHeader; + } + + + /** + * Return details of the relationship + * + * @return relationship properties + */ + public RelationshipProperties getRelationshipProperties() + { + return relationshipProperties; + } + + + /** + * Set up relationship properties + * + * @param relationshipProperties relationship properties + */ + public void setRelationshipProperties(RelationshipProperties relationshipProperties) + { + this.relationshipProperties = relationshipProperties; + } + + + /** + * Return the element header associated with end 1 of the relationship. + * + * @return element header object + */ + public ElementHeader getEnd1GUID() + { + return end1GUID; + } + + + /** + * Set up the element header associated with end 1 of the relationship. + * + * @param end1GUID element header object + */ + public void setEnd1GUID(ElementHeader end1GUID) + { + this.end1GUID = end1GUID; + } + + + + /** + * Return the element header associated with end 2 of the relationship. + * + * @return element header object + */ + public ElementHeader getEnd2GUID() + { + return end2GUID; + } + + + /** + * Set up the element header associated with end 2 of the relationship. + * + * @param end2GUID element header object + */ + public void setEnd2GUID(ElementHeader end2GUID) + { + this.end2GUID = end2GUID; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "RelationshipElement{" + + "relationshipHeader=" + relationshipHeader + + ", relationshipProperties=" + relationshipProperties + + ", end1GUID=" + end1GUID + + ", end2GUID=" + end2GUID + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (objectToCompare == null || getClass() != objectToCompare.getClass()) + { + return false; + } + RelationshipElement that = (RelationshipElement) objectToCompare; + return Objects.equals(getRelationshipHeader(), that.getRelationshipHeader()) && + Objects.equals(getRelationshipProperties(), that.getRelationshipProperties()) && + Objects.equals(getEnd1GUID(), that.getEnd1GUID()) && + Objects.equals(getEnd2GUID(), that.getEnd2GUID()); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(super.hashCode(), relationshipHeader, relationshipProperties, end1GUID, end2GUID); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/DataContentForDataSetProperties.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/DataContentForDataSetProperties.java new file mode 100644 index 00000000000..2ed405e4b29 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/DataContentForDataSetProperties.java @@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ +package org.odpi.openmetadata.accessservices.assetowner.properties; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * DataContentForDataSetProperties defines a query on an asset that returns all or part of the values for a dataset. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class DataContentForDataSetProperties extends RelationshipProperties +{ + private String queryId = null; + private String query = null; + + + + /** + * Default constructor + */ + public DataContentForDataSetProperties() + { + super(); + } + + + /** + * Copy/clone constructor. + * + * @param template template to copy. + */ + public DataContentForDataSetProperties(DataContentForDataSetProperties template) + { + super(template); + + if (template != null) + { + queryId = template.getQueryId(); + query = template.getQuery(); + } + } + + + /** + * Return the query id - this is used to identify where the results of this query should be plugged into + * the other queries or the formula for the parent derived schema element. + * + * @return String query identifier + */ + public String getQueryId() { return queryId; } + + + /** + * Set up the query id - this is used to identify where the results of this query should be plugged into + * the other queries or the formula for the parent derived schema element. + * + * @param queryId String query identifier + */ + public void setQueryId(String queryId) + { + this.queryId = queryId; + } + + + /** + * Return the query string for this element. The query string may have placeholders for values returned + * by queries that have a lower queryId than this element. + * + * @return String query + */ + public String getQuery() { return query; } + + + /** + * Set up the query string for this element. The query string may have placeholders for values returned + * by queries that have a lower queryId than this element. + * + * @param query String query + */ + public void setQuery(String query) + { + this.query = query; + } + + + /** + * Standard toString method. + * + * @return print out of variables in a JSON-style + */ + @Override + public String toString() + { + return "DataContentForDataSetProperties{" + + "queryId='" + queryId + '\'' + + ", query='" + query + '\'' + + ", effectiveFrom=" + getEffectiveFrom() + + ", effectiveTo=" + getEffectiveTo() + + '}'; + } + + + /** + * Compare the values of the supplied object with those stored in the current object. + * + * @param objectToCompare supplied object + * @return boolean result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (!(objectToCompare instanceof DataContentForDataSetProperties)) + { + return false; + } + DataContentForDataSetProperties that = (DataContentForDataSetProperties) objectToCompare; + return Objects.equals(getQueryId(), that.getQueryId()) && + Objects.equals(getQuery(), that.getQuery()); + } + + + /** + * Create a hash code for this element type. + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(getQueryId(), getQuery()); + } +} \ No newline at end of file diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/ReferenceableProperties.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/ReferenceableProperties.java index 2cc0a2d2e39..5f6fd158ba0 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/ReferenceableProperties.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/ReferenceableProperties.java @@ -13,7 +13,7 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; /** - * ReferenceableProperties provides a structure for passing a referenceables' properties over the Java API. + * ReferenceableProperties provides a structure for passing a referenceable object's properties over the Java API. */ @JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) @JsonInclude(JsonInclude.Include.NON_NULL) @@ -37,6 +37,8 @@ public class ReferenceableProperties implements Serializable private String qualifiedName = null; private Map additionalProperties = null; + private Date effectiveFrom = null; + private Date effectiveTo = null; private String typeName = null; private Map extendedProperties = null; @@ -46,47 +48,39 @@ public class ReferenceableProperties implements Serializable */ public ReferenceableProperties() { + super(); } /** - * Copy/clone constructor + * Copy/clone constructor. Retrieve values from the supplied template * - * @param template object to copy + * @param template element to copy */ public ReferenceableProperties(ReferenceableProperties template) { if (template != null) { - this.qualifiedName = template.getQualifiedName(); - this.additionalProperties = template.getAdditionalProperties(); - this.typeName = template.getTypeName(); - this.extendedProperties = template.getExtendedProperties(); - } - } + qualifiedName = template.getQualifiedName(); + additionalProperties = template.getAdditionalProperties(); + effectiveFrom = template.getEffectiveFrom(); + effectiveTo = template.getEffectiveTo(); - /** - * Return the open metadata type name of this object - this is used to create a subtype of - * the referenceable. Any properties associated with this subtype are passed as extended properties. - * - * @return string type name - */ - public String getTypeName() - { - return typeName; + typeName = template.getTypeName(); + extendedProperties = template.getExtendedProperties(); + } } /** - * Set up the open metadata type name of this object - this is used to create a subtype of - * the referenceable. Any properties associated with this subtype are passed as extended properties. + * Set up the fully qualified name. * - * @param typeName string type name + * @param qualifiedName String name */ - public void setTypeName(String typeName) + public void setQualifiedName(String qualifiedName) { - this.typeName = typeName; + this.qualifiedName = qualifiedName; } @@ -103,13 +97,13 @@ public String getQualifiedName() /** - * Set up the fully qualified name. + * Set up additional properties. * - * @param qualifiedName String name + * @param additionalProperties Additional properties object */ - public void setQualifiedName(String qualifiedName) + public void setAdditionalProperties(Map additionalProperties) { - this.qualifiedName = qualifiedName; + this.additionalProperties = additionalProperties; } @@ -136,21 +130,76 @@ else if (additionalProperties.isEmpty()) /** - * Set up additional properties. + * Return the date/time that this element is effective from (null means effective from the epoch). * - * @param additionalProperties Additional properties object + * @return date object */ - public void setAdditionalProperties(Map additionalProperties) + public Date getEffectiveFrom() { - this.additionalProperties = additionalProperties; + return effectiveFrom; + } + + + /** + * Set up the date/time that this element is effective from (null means effective from the epoch). + * + * @param effectiveFrom date object + */ + public void setEffectiveFrom(Date effectiveFrom) + { + this.effectiveFrom = effectiveFrom; + } + + + /** + * Return the date/time that element is effective to (null means that it is effective indefinitely into the future). + * + * @return date object + */ + public Date getEffectiveTo() + { + return effectiveTo; + } + + + /** + * Set the date/time that element is effective to (null means that it is effective indefinitely into the future). + * + * @param effectiveTo date object + */ + public void setEffectiveTo(Date effectiveTo) + { + this.effectiveTo = effectiveTo; } /** - * Return the properties that are defined for a subtype of referenceable but are not explicitly - * supported by the bean. + * Return the name of the open metadata type for this metadata element. * - * @return map of properties + * @return string name + */ + public String getTypeName() + { + return typeName; + } + + + /** + * Set up the name of the open metadata type for this element. + * + * @param typeName string name + */ + public void setTypeName(String typeName) + { + this.typeName = typeName; + } + + + /** + * Return the properties that have been defined for a subtype of this object that are not supported explicitly + * by this bean. + * + * @return property map */ public Map getExtendedProperties() { @@ -170,10 +219,10 @@ else if (extendedProperties.isEmpty()) /** - * Set up the properties that are defined for a subtype of referenceable but are not explicitly - * supported by the bean. + * Set up the properties that have been defined for a subtype of this object that are not supported explicitly + * by this bean. * - * @param extendedProperties map of properties + * @param extendedProperties property map */ public void setExtendedProperties(Map extendedProperties) { @@ -181,28 +230,27 @@ public void setExtendedProperties(Map extendedProperties) } - - /** - * JSON-style toString. + * Standard toString method. * - * @return list of properties and their values. + * @return print out of variables in a JSON-style */ @Override public String toString() { return "ReferenceableProperties{" + - "qualifiedName='" + qualifiedName + '\'' + - ", additionalProperties=" + additionalProperties + - ", typeName='" + typeName + '\'' + - ", extendedProperties=" + extendedProperties + - '}'; + "qualifiedName='" + qualifiedName + '\'' + + ", additionalProperties=" + additionalProperties + + ", typeName='" + typeName + '\'' + + ", extendedProperties=" + extendedProperties + + '}'; } + /** - * Equals method that returns true if containing properties are the same. + * Compare the values of the supplied object with those stored in the current object. * - * @param objectToCompare object to compare + * @param objectToCompare supplied object * @return boolean result of comparison */ @Override @@ -218,19 +266,22 @@ public boolean equals(Object objectToCompare) } ReferenceableProperties that = (ReferenceableProperties) objectToCompare; return Objects.equals(qualifiedName, that.qualifiedName) && - Objects.equals(additionalProperties, that.additionalProperties) && - Objects.equals(typeName, that.typeName) && - Objects.equals(extendedProperties, that.extendedProperties); + Objects.equals(additionalProperties, that.additionalProperties) && + Objects.equals(effectiveFrom, that.effectiveFrom) && + Objects.equals(effectiveTo, that.effectiveTo) && + Objects.equals(typeName, that.typeName) && + Objects.equals(extendedProperties, that.extendedProperties); } + /** - * Return hash code for this object + * Return hash code based on properties. * - * @return int hash code + * @return int */ @Override public int hashCode() { - return Objects.hash(qualifiedName, additionalProperties, extendedProperties, typeName); + return Objects.hash(qualifiedName, additionalProperties, effectiveFrom, effectiveTo, typeName, extendedProperties); } } diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/RelationshipProperties.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/RelationshipProperties.java index 058e969c7e1..af9feceb258 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/RelationshipProperties.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/properties/RelationshipProperties.java @@ -29,6 +29,7 @@ property = "class") @JsonSubTypes( { + @JsonSubTypes.Type(value = DataContentForDataSetProperties.class, name = "DataContentForDataSetProperties"), @JsonSubTypes.Type(value = ResourceListProperties.class, name = "ResourceListProperties"), @JsonSubTypes.Type(value = LicenseProperties.class, name = "LicenseProperties"), @JsonSubTypes.Type(value = CertificationProperties.class, name = "CertificationProperties"), diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/CalculatedValueClassificationRequestBody.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/CalculatedValueClassificationRequestBody.java new file mode 100644 index 00000000000..16e8b64ddd6 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/CalculatedValueClassificationRequestBody.java @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * CalculatedValueClassificationRequestBody is used to identify the schema elements that are calculated (derived) + * rather than stored. Examples of this are relational database views. + */ +@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class CalculatedValueClassificationRequestBody extends UpdateRequestBody +{ + private String formula = null; + + + /** + * Default constructor + */ + public CalculatedValueClassificationRequestBody() + { + super(); + } + + + /** + * Copy/clone constructor for a primary key. + * + * @param template template object to copy. + */ + public CalculatedValueClassificationRequestBody(CalculatedValueClassificationRequestBody template) + { + super(template); + + if (template != null) + { + formula = template.getFormula(); + } + } + + + /** + * Return the formula used to calculate the value. + * + * @return string formula with placeholders + */ + public String getFormula() + { + return formula; + } + + + /** + * Set up the formula used to calculate the value. + * + * @param formula string description + */ + public void setFormula(String formula) + { + this.formula = formula; + } + + + /** + * Standard toString method. + * + * @return print out of variables in a JSON-style + */ + @Override + public String toString() + { + return "CalculatedValueClassificationRequestBody{" + + "formula='" + formula + '\'' + + ", effectiveTime=" + getEffectiveTime() + + '}'; + } + + + /** + * Compare the values of the supplied object with those stored in the current object. + * + * @param objectToCompare supplied object + * @return boolean result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (objectToCompare == null || getClass() != objectToCompare.getClass()) + { + return false; + } + if (! super.equals(objectToCompare)) + { + return false; + } + CalculatedValueClassificationRequestBody that = (CalculatedValueClassificationRequestBody) objectToCompare; + return Objects.equals(formula, that.formula); + } + + + /** + * Return hash code based on properties. + * + * @return int + */ + @Override + public int hashCode() + { + return Objects.hash(super.hashCode(), formula); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/EffectiveTimeQueryRequestBody.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/EffectiveTimeQueryRequestBody.java new file mode 100644 index 00000000000..31d3dc4a385 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/EffectiveTimeQueryRequestBody.java @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.Date; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * EffectiveTimeQueryRequestBody carries the date/time for a query. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class EffectiveTimeQueryRequestBody extends AssetOwnerOMASAPIRequestBody +{ + private Date effectiveTime = null; + + + /** + * Default constructor + */ + public EffectiveTimeQueryRequestBody() + { + super(); + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public EffectiveTimeQueryRequestBody(EffectiveTimeQueryRequestBody template) + { + super(template); + + if (template != null) + { + effectiveTime = template.getEffectiveTime(); + } + } + + + /** + * Return the date/time to use for the query. + * + * @return date object + */ + public Date getEffectiveTime() + { + return effectiveTime; + } + + + /** + * Set up the date/time to use for the query. + * + * @param effectiveTime date object + */ + public void setEffectiveTime(Date effectiveTime) + { + this.effectiveTime = effectiveTime; + } + + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "EffectiveTimeQueryRequestBody{" + + "effectiveTime=" + effectiveTime + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (objectToCompare == null || getClass() != objectToCompare.getClass()) + { + return false; + } + if (! super.equals(objectToCompare)) + { + return false; + } + EffectiveTimeQueryRequestBody that = (EffectiveTimeQueryRequestBody) objectToCompare; + return Objects.equals(effectiveTime, that.effectiveTime); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(super.hashCode(), effectiveTime); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/ElementHeaderResponse.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/ElementHeaderResponse.java new file mode 100644 index 00000000000..7aa0b80706e --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/ElementHeaderResponse.java @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementHeader; + +import java.io.Serial; +import java.util.Arrays; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + + +/** + * ElementHeaderResponse is the response structure used on the OMAS REST API calls that return the header + * for a element. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class ElementHeaderResponse extends AssetOwnerOMASAPIResponse +{ + @Serial + private static final long serialVersionUID = 1L; + + private ElementHeader element = null; + + + /** + * Default constructor + */ + public ElementHeaderResponse() + { + super(); + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public ElementHeaderResponse(ElementHeaderResponse template) + { + super(template); + + if (template != null) + { + this.element = template.getElement(); + } + } + + + /** + * Return the element result. + * + * @return bean + */ + public ElementHeader getElement() + { + return element; + } + + + /** + * Set up the element result. + * + * @param element bean + */ + public void setElement(ElementHeader element) + { + this.element = element; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "ElementHeaderResponse{" + + "element=" + element + + ", exceptionClassName='" + getExceptionClassName() + '\'' + + ", exceptionCausedBy='" + getExceptionCausedBy() + '\'' + + ", actionDescription='" + getActionDescription() + '\'' + + ", relatedHTTPCode=" + getRelatedHTTPCode() + + ", exceptionErrorMessage='" + getExceptionErrorMessage() + '\'' + + ", exceptionErrorMessageId='" + getExceptionErrorMessageId() + '\'' + + ", exceptionErrorMessageParameters=" + Arrays.toString(getExceptionErrorMessageParameters()) + + ", exceptionSystemAction='" + getExceptionSystemAction() + '\'' + + ", exceptionUserAction='" + getExceptionUserAction() + '\'' + + ", exceptionProperties=" + getExceptionProperties() + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (!(objectToCompare instanceof ElementHeaderResponse)) + { + return false; + } + if (!super.equals(objectToCompare)) + { + return false; + } + ElementHeaderResponse that = (ElementHeaderResponse) objectToCompare; + return Objects.equals(element, that.element); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(element); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipElementResponse.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipElementResponse.java new file mode 100644 index 00000000000..ba6e08498f3 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipElementResponse.java @@ -0,0 +1,137 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.RelationshipElement; + +import java.util.Arrays; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + + +/** + * RelationshipElementResponse is the response structure used on the OMAS REST API calls that return the properties + * for a relationship. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class RelationshipElementResponse extends AssetOwnerOMASAPIResponse +{ + private RelationshipElement element = null; + + + /** + * Default constructor + */ + public RelationshipElementResponse() + { + super(); + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public RelationshipElementResponse(RelationshipElementResponse template) + { + super(template); + + if (template != null) + { + this.element = template.getElement(); + } + } + + + /** + * Return the element result. + * + * @return bean + */ + public RelationshipElement getElement() + { + return element; + } + + + /** + * Set up the element result. + * + * @param element bean + */ + public void setElement(RelationshipElement element) + { + this.element = element; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "RelationshipElementResponse{" + + "element=" + element + + ", exceptionClassName='" + getExceptionClassName() + '\'' + + ", exceptionCausedBy='" + getExceptionCausedBy() + '\'' + + ", actionDescription='" + getActionDescription() + '\'' + + ", relatedHTTPCode=" + getRelatedHTTPCode() + + ", exceptionErrorMessage='" + getExceptionErrorMessage() + '\'' + + ", exceptionErrorMessageId='" + getExceptionErrorMessageId() + '\'' + + ", exceptionErrorMessageParameters=" + Arrays.toString(getExceptionErrorMessageParameters()) + + ", exceptionSystemAction='" + getExceptionSystemAction() + '\'' + + ", exceptionUserAction='" + getExceptionUserAction() + '\'' + + ", exceptionProperties=" + getExceptionProperties() + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (!(objectToCompare instanceof RelationshipElementResponse)) + { + return false; + } + if (!super.equals(objectToCompare)) + { + return false; + } + RelationshipElementResponse that = (RelationshipElementResponse) objectToCompare; + return Objects.equals(element, that.element); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(element); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipElementsResponse.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipElementsResponse.java new file mode 100644 index 00000000000..2c74d9e970a --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipElementsResponse.java @@ -0,0 +1,149 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.RelationshipElement; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * RelationshipElementsResponse is a response object for passing back a list of relationships + * or an exception if the request failed. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class RelationshipElementsResponse extends AssetOwnerOMASAPIResponse +{ + + private List elementList = null; + + + /** + * Default constructor + */ + public RelationshipElementsResponse() + { + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public RelationshipElementsResponse(RelationshipElementsResponse template) + { + super(template); + + if (template != null) + { + elementList = template.getElementList(); + } + } + + + /** + * Return the list of metadata elements. + * + * @return result object + */ + public List getElementList() + { + if (elementList == null) + { + return null; + } + else if (elementList.isEmpty()) + { + return null; + } + else + { + return new ArrayList<>(elementList); + } + } + + + /** + * Set up the metadata element to return. + * + * @param elementList result object + */ + public void setElementList(List elementList) + { + this.elementList = elementList; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "RelationshipElementsResponse{" + + "elementList=" + elementList + + ", exceptionClassName='" + getExceptionClassName() + '\'' + + ", exceptionCausedBy='" + getExceptionCausedBy() + '\'' + + ", actionDescription='" + getActionDescription() + '\'' + + ", relatedHTTPCode=" + getRelatedHTTPCode() + + ", exceptionErrorMessage='" + getExceptionErrorMessage() + '\'' + + ", exceptionErrorMessageId='" + getExceptionErrorMessageId() + '\'' + + ", exceptionErrorMessageParameters=" + Arrays.toString(getExceptionErrorMessageParameters()) + + ", exceptionSystemAction='" + getExceptionSystemAction() + '\'' + + ", exceptionUserAction='" + getExceptionUserAction() + '\'' + + ", exceptionProperties=" + getExceptionProperties() + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (objectToCompare == null || getClass() != objectToCompare.getClass()) + { + return false; + } + if (!super.equals(objectToCompare)) + { + return false; + } + RelationshipElementsResponse that = (RelationshipElementsResponse) objectToCompare; + return Objects.equals(elementList, that.elementList); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(super.hashCode(), elementList); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipRequestBody.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipRequestBody.java index 496cb03dfd9..30b3b9ea588 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipRequestBody.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/RelationshipRequestBody.java @@ -20,10 +20,8 @@ @JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown=true) -public class RelationshipRequestBody extends ExternalSourceRequestBody +public class RelationshipRequestBody extends EffectiveTimeQueryRequestBody { - private static final long serialVersionUID = 1L; - private String relationshipName = null; private RelationshipProperties properties = null; @@ -107,10 +105,9 @@ public void setProperties(RelationshipProperties properties) public String toString() { return "RelationshipRequestBody{" + - "externalSourceGUID='" + getExternalSourceGUID() + '\'' + - ", externalSourceName='" + getExternalSourceName() + '\'' + - ", relationshipTypeName=" + relationshipName + + "relationshipName='" + relationshipName + '\'' + ", properties=" + properties + + ", effectiveTime=" + getEffectiveTime() + '}'; } diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaAttributeElementResponse.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaAttributeElementResponse.java new file mode 100644 index 00000000000..3cac1455ee9 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaAttributeElementResponse.java @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaAttributeElement; + +import java.io.Serial; +import java.util.Arrays; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + + +/** + * SchemaAttributeElementResponse is the response structure used on the OMAS REST API calls that return the properties + * for a element. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class SchemaAttributeElementResponse extends AssetOwnerOMASAPIResponse +{ + @Serial + private static final long serialVersionUID = 1L; + + private SchemaAttributeElement element = null; + + + /** + * Default constructor + */ + public SchemaAttributeElementResponse() + { + super(); + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public SchemaAttributeElementResponse(SchemaAttributeElementResponse template) + { + super(template); + + if (template != null) + { + this.element = template.getElement(); + } + } + + + /** + * Return the element result. + * + * @return bean + */ + public SchemaAttributeElement getElement() + { + return element; + } + + + /** + * Set up the element result. + * + * @param element bean + */ + public void setElement(SchemaAttributeElement element) + { + this.element = element; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "SchemaAttributeElementResponse{" + + "element=" + element + + ", exceptionClassName='" + getExceptionClassName() + '\'' + + ", exceptionCausedBy='" + getExceptionCausedBy() + '\'' + + ", actionDescription='" + getActionDescription() + '\'' + + ", relatedHTTPCode=" + getRelatedHTTPCode() + + ", exceptionErrorMessage='" + getExceptionErrorMessage() + '\'' + + ", exceptionErrorMessageId='" + getExceptionErrorMessageId() + '\'' + + ", exceptionErrorMessageParameters=" + Arrays.toString(getExceptionErrorMessageParameters()) + + ", exceptionSystemAction='" + getExceptionSystemAction() + '\'' + + ", exceptionUserAction='" + getExceptionUserAction() + '\'' + + ", exceptionProperties=" + getExceptionProperties() + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (!(objectToCompare instanceof SchemaAttributeElementResponse)) + { + return false; + } + if (!super.equals(objectToCompare)) + { + return false; + } + SchemaAttributeElementResponse that = (SchemaAttributeElementResponse) objectToCompare; + return Objects.equals(element, that.element); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(element); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaAttributeElementsResponse.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaAttributeElementsResponse.java new file mode 100644 index 00000000000..993a1177430 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaAttributeElementsResponse.java @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaAttributeElement; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * SchemaAttributeElementsResponse is a response object for passing back a a list of glossaries + * or an exception if the request failed. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class SchemaAttributeElementsResponse extends AssetOwnerOMASAPIResponse +{ + private List elementList = null; + + + /** + * Default constructor + */ + public SchemaAttributeElementsResponse() + { + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public SchemaAttributeElementsResponse(SchemaAttributeElementsResponse template) + { + super(template); + + if (template != null) + { + elementList = template.getElementList(); + } + } + + + /** + * Return the list of metadata elements. + * + * @return result object + */ + public List getElementList() + { + if (elementList == null) + { + return null; + } + else if (elementList.isEmpty()) + { + return null; + } + else + { + return new ArrayList<>(elementList); + } + } + + + /** + * Set up the metadata element to return. + * + * @param elementList result object + */ + public void setElementList(List elementList) + { + this.elementList = elementList; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "SchemaAttributeElementsResponse{" + + "elementList=" + elementList + + ", exceptionClassName='" + getExceptionClassName() + '\'' + + ", exceptionCausedBy='" + getExceptionCausedBy() + '\'' + + ", actionDescription='" + getActionDescription() + '\'' + + ", relatedHTTPCode=" + getRelatedHTTPCode() + + ", exceptionErrorMessage='" + getExceptionErrorMessage() + '\'' + + ", exceptionErrorMessageId='" + getExceptionErrorMessageId() + '\'' + + ", exceptionErrorMessageParameters=" + Arrays.toString(getExceptionErrorMessageParameters()) + + ", exceptionSystemAction='" + getExceptionSystemAction() + '\'' + + ", exceptionUserAction='" + getExceptionUserAction() + '\'' + + ", exceptionProperties=" + getExceptionProperties() + + '}'; + } + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (objectToCompare == null || getClass() != objectToCompare.getClass()) + { + return false; + } + if (!super.equals(objectToCompare)) + { + return false; + } + SchemaAttributeElementsResponse that = (SchemaAttributeElementsResponse) objectToCompare; + return Objects.equals(elementList, that.elementList); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(super.hashCode(), elementList); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeElementResponse.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeElementResponse.java new file mode 100644 index 00000000000..3e425f46263 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeElementResponse.java @@ -0,0 +1,136 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaTypeElement; + +import java.util.Arrays; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + + +/** + * SchemaTypeElementResponse is the response structure used on the OMAS REST API calls that return the properties for an element. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class SchemaTypeElementResponse extends AssetOwnerOMASAPIResponse +{ + private SchemaTypeElement element = null; + + + /** + * Default constructor + */ + public SchemaTypeElementResponse() + { + super(); + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public SchemaTypeElementResponse(SchemaTypeElementResponse template) + { + super(template); + + if (template != null) + { + this.element = template.getElement(); + } + } + + + /** + * Return the element result. + * + * @return bean + */ + public SchemaTypeElement getElement() + { + return element; + } + + + /** + * Set up the element result. + * + * @param element bean + */ + public void setElement(SchemaTypeElement element) + { + this.element = element; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "SchemaTypeElementResponse{" + + "element=" + element + + ", exceptionClassName='" + getExceptionClassName() + '\'' + + ", exceptionCausedBy='" + getExceptionCausedBy() + '\'' + + ", actionDescription='" + getActionDescription() + '\'' + + ", relatedHTTPCode=" + getRelatedHTTPCode() + + ", exceptionErrorMessage='" + getExceptionErrorMessage() + '\'' + + ", exceptionErrorMessageId='" + getExceptionErrorMessageId() + '\'' + + ", exceptionErrorMessageParameters=" + Arrays.toString(getExceptionErrorMessageParameters()) + + ", exceptionSystemAction='" + getExceptionSystemAction() + '\'' + + ", exceptionUserAction='" + getExceptionUserAction() + '\'' + + ", exceptionProperties=" + getExceptionProperties() + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (!(objectToCompare instanceof SchemaTypeElementResponse)) + { + return false; + } + if (!super.equals(objectToCompare)) + { + return false; + } + SchemaTypeElementResponse that = (SchemaTypeElementResponse) objectToCompare; + return Objects.equals(element, that.element); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(element); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeElementsResponse.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeElementsResponse.java new file mode 100644 index 00000000000..d5dfe6896c5 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeElementsResponse.java @@ -0,0 +1,146 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaTypeElement; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * SchemaTypeElementsResponse is a response object for passing back a list of elements or an exception if the request failed. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class SchemaTypeElementsResponse extends AssetOwnerOMASAPIResponse +{ + private List elementList = null; + + + /** + * Default constructor + */ + public SchemaTypeElementsResponse() + { + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public SchemaTypeElementsResponse(SchemaTypeElementsResponse template) + { + super(template); + + if (template != null) + { + elementList = template.getElementList(); + } + } + + + /** + * Return the list of metadata elements. + * + * @return result object + */ + public List getElementList() + { + if (elementList == null) + { + return null; + } + else if (elementList.isEmpty()) + { + return null; + } + else + { + return new ArrayList<>(elementList); + } + } + + + /** + * Set up the metadata element to return. + * + * @param elementList result object + */ + public void setElementList(List elementList) + { + this.elementList = elementList; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "SchemaTypeElementsResponse{" + + "elementList=" + elementList + + ", exceptionClassName='" + getExceptionClassName() + '\'' + + ", exceptionCausedBy='" + getExceptionCausedBy() + '\'' + + ", actionDescription='" + getActionDescription() + '\'' + + ", relatedHTTPCode=" + getRelatedHTTPCode() + + ", exceptionErrorMessage='" + getExceptionErrorMessage() + '\'' + + ", exceptionErrorMessageId='" + getExceptionErrorMessageId() + '\'' + + ", exceptionErrorMessageParameters=" + Arrays.toString(getExceptionErrorMessageParameters()) + + ", exceptionSystemAction='" + getExceptionSystemAction() + '\'' + + ", exceptionUserAction='" + getExceptionUserAction() + '\'' + + ", exceptionProperties=" + getExceptionProperties() + + '}'; + } + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (objectToCompare == null || getClass() != objectToCompare.getClass()) + { + return false; + } + if (!super.equals(objectToCompare)) + { + return false; + } + SchemaTypeElementsResponse that = (SchemaTypeElementsResponse) objectToCompare; + return Objects.equals(elementList, that.elementList); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(super.hashCode(), elementList); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeRequestBody.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeRequestBody.java deleted file mode 100644 index d0442862ca9..00000000000 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/SchemaTypeRequestBody.java +++ /dev/null @@ -1,134 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ -/* Copyright Contributors to the ODPi Egeria project. */ -package org.odpi.openmetadata.accessservices.assetowner.rest; - -import com.fasterxml.jackson.annotation.*; -import org.odpi.openmetadata.accessservices.assetowner.properties.SchemaTypeProperties; - -import java.util.Objects; - -import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; -import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; - -/** - * SchemaTypeRequestBody carries the common parameters for creating or updating schema types. - */ -@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown=true) -@Deprecated -// Use SchemaTypeProperties -public class SchemaTypeRequestBody extends SchemaTypeProperties -{ - private static final long serialVersionUID = 1L; - - private SchemaTypeProperties schemaTypeProperties = null; - - /** - * Default constructor - */ - public SchemaTypeRequestBody() - { - super(); - } - - - /** - * Copy/clone Constructor. - * - * @param template template object to copy. - */ - public SchemaTypeRequestBody(SchemaTypeRequestBody template) - { - super(template); - - if (template != null) - { - schemaTypeProperties = template.getSchemaTypeProperties(); - } - } - - - /** - * Return the properties for the schema type. - * - * @return schema type properties - */ - public SchemaTypeProperties getSchemaTypeProperties() - { - return schemaTypeProperties; - } - - - /** - * Set up schema type - * - * @param schemaTypeProperties schema type properties - */ - public void setSchemaTypeProperties(SchemaTypeProperties schemaTypeProperties) - { - this.schemaTypeProperties = schemaTypeProperties; - } - - - /** - * Compare the values of the supplied object with those stored in the current object. - * - * @param objectToCompare supplied object - * @return boolean result of comparison - */ - @Override - public boolean equals(Object objectToCompare) - { - if (this == objectToCompare) - { - return true; - } - if (objectToCompare == null || getClass() != objectToCompare.getClass()) - { - return false; - } - SchemaTypeRequestBody that = (SchemaTypeRequestBody) objectToCompare; - return Objects.equals(schemaTypeProperties, that.schemaTypeProperties); - } - - - /** - * Return hash code for this object - * - * @return int hash code - */ - @Override - public int hashCode() - { - return Objects.hash(schemaTypeProperties); - } - - - /** - * Standard toString method. - * - * @return print out of variables in a JSON-style - */ - @Override - public String toString() - { - return "SchemaTypeRequestBody{" + - "schemaTypeProperties=" + schemaTypeProperties + - ", versionNumber='" + getVersionNumber() + '\'' + - ", author='" + getAuthor() + '\'' + - ", usage='" + getUsage() + '\'' + - ", encodingStandard='" + getEncodingStandard() + '\'' + - ", namespace='" + getNamespace() + '\'' + - ", formula='" + getFormula() + '\'' + - ", queries=" + getQueries() + - ", displayName='" + getDisplayName() + '\'' + - ", description='" + getDescription() + '\'' + - ", deprecated=" + getIsDeprecated() + - ", typeName='" + getTypeName() + '\'' + - ", qualifiedName='" + getQualifiedName() + '\'' + - ", additionalProperties=" + getAdditionalProperties() + - ", extendedProperties=" + getExtendedProperties() + - '}'; - } -} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/TemplateRequestBody.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/TemplateRequestBody.java new file mode 100644 index 00000000000..02d01dc904c --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/TemplateRequestBody.java @@ -0,0 +1,150 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ +package org.odpi.openmetadata.accessservices.assetowner.rest; + + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.odpi.openmetadata.accessservices.assetowner.properties.TemplateProperties; + +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + + +/** + * TemplateRequestBody describes the request body used to create/update elements from templates. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class TemplateRequestBody extends UpdateRequestBody +{ + private TemplateProperties elementProperties = null; + private String parentGUID = null; + + + /** + * Default constructor + */ + public TemplateRequestBody() + { + super(); + } + + + /** + * Copy/clone constructor. + * + * @param template object to copy + */ + public TemplateRequestBody(TemplateRequestBody template) + { + super(template); + + if (template != null) + { + elementProperties = template.getElementProperties(); + parentGUID = template.getParentGUID(); + } + } + + + /** + * Return the properties for the element. + * + * @return properties object + */ + public TemplateProperties getElementProperties() + { + return elementProperties; + } + + + /** + * Set up the properties for the element. + * + * @param elementProperties properties object + */ + public void setElementProperties(TemplateProperties elementProperties) + { + this.elementProperties = elementProperties; + } + + + /** + * Return an optional parent GUID to attach the new element to. + * + * @return guid + */ + public String getParentGUID() + { + return parentGUID; + } + + + /** + * Set up an optional parent GUID to attach the new element to. + * + * @param parentGUID guid + */ + public void setParentGUID(String parentGUID) + { + this.parentGUID = parentGUID; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "TemplateRequestBody{" + + "elementProperties=" + elementProperties + + ", parentGUID='" + parentGUID + '\'' + + ", effectiveTime=" + getEffectiveTime() + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (! (objectToCompare instanceof TemplateRequestBody that)) + { + return false; + } + if (! super.equals(objectToCompare)) + { + return false; + } + return Objects.equals(elementProperties, that.elementProperties) && Objects.equals(parentGUID, that.parentGUID); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(super.hashCode(), elementProperties, parentGUID); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/UpdateRequestBody.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/UpdateRequestBody.java new file mode 100644 index 00000000000..02c8feae045 --- /dev/null +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-api/src/main/java/org/odpi/openmetadata/accessservices/assetowner/rest/UpdateRequestBody.java @@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ +package org.odpi.openmetadata.accessservices.assetowner.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.Date; +import java.util.Objects; + +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; +import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +/** + * UpdateRequestBody carries the correlation properties and effective time for a create, update or delete request. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class UpdateRequestBody +{ + private Date effectiveTime = null; + + /** + * Default constructor + */ + public UpdateRequestBody() + { + super(); + } + + + /** + * Copy/clone constructor + * + * @param template object to copy + */ + public UpdateRequestBody(UpdateRequestBody template) + { + if (template != null) + { + effectiveTime = template.getEffectiveTime(); + } + } + + + /** + * Return the date/time to use for the query. + * + * @return date object + */ + public Date getEffectiveTime() + { + return effectiveTime; + } + + + /** + * Set up the date/time to use for the query. + * + * @param effectiveTime date object + */ + public void setEffectiveTime(Date effectiveTime) + { + this.effectiveTime = effectiveTime; + } + + + /** + * JSON-style toString + * + * @return return string containing the property names and values + */ + @Override + public String toString() + { + return "EffectiveTimeQueryRequestBody{" + + "effectiveTime=" + effectiveTime + + '}'; + } + + + /** + * Return comparison result based on the content of the properties. + * + * @param objectToCompare test object + * @return result of comparison + */ + @Override + public boolean equals(Object objectToCompare) + { + if (this == objectToCompare) + { + return true; + } + if (objectToCompare == null || getClass() != objectToCompare.getClass()) + { + return false; + } + UpdateRequestBody that = (UpdateRequestBody) objectToCompare; + return Objects.equals(effectiveTime, that.effectiveTime); + } + + + /** + * Return hash code for this object + * + * @return int hash code + */ + @Override + public int hashCode() + { + return Objects.hash(super.hashCode(), effectiveTime); + } +} diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/AssetOwner.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/AssetOwner.java index ae0a5561bee..6674c8c532e 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/AssetOwner.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/AssetOwner.java @@ -3,50 +3,67 @@ package org.odpi.openmetadata.accessservices.assetowner.client; -import org.odpi.openmetadata.accessservices.assetowner.api.*; +import org.odpi.openmetadata.accessservices.assetowner.api.AssetClassificationInterface; +import org.odpi.openmetadata.accessservices.assetowner.api.AssetConnectionManagementInterface; +import org.odpi.openmetadata.accessservices.assetowner.api.AssetDecommissioningInterface; +import org.odpi.openmetadata.accessservices.assetowner.api.AssetKnowledgeInterface; +import org.odpi.openmetadata.accessservices.assetowner.api.AssetOnboardingInterface; +import org.odpi.openmetadata.accessservices.assetowner.api.AssetReviewInterface; import org.odpi.openmetadata.accessservices.assetowner.client.rest.AssetOwnerRESTClient; -import org.odpi.openmetadata.accessservices.assetowner.metadataelements.*; -import org.odpi.openmetadata.accessservices.assetowner.properties.*; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.AssetElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.ConnectionElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.ConnectorTypeElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.EndpointElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.RelationshipElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaAttributeElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaTypeElement; +import org.odpi.openmetadata.accessservices.assetowner.properties.AssetProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.ConnectionProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.EndpointProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.RelationshipProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.SchemaAttributeProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.SchemaTypeProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.TemplateProperties; import org.odpi.openmetadata.accessservices.assetowner.rest.*; -import org.odpi.openmetadata.accessservices.assetowner.rest.ConnectionResponse; -import org.odpi.openmetadata.accessservices.assetowner.rest.ConnectorTypeResponse; -import org.odpi.openmetadata.commonservices.ffdc.rest.*; -import org.odpi.openmetadata.accessservices.assetowner.api.AssetKnowledgeInterface; -import org.odpi.openmetadata.frameworkservices.ocf.metadatamanagement.client.ConnectedAssetClientBase; +import org.odpi.openmetadata.commonservices.ffdc.rest.GUIDResponse; +import org.odpi.openmetadata.commonservices.ffdc.rest.NameListResponse; +import org.odpi.openmetadata.commonservices.ffdc.rest.NameRequestBody; +import org.odpi.openmetadata.commonservices.ffdc.rest.SearchStringRequestBody; +import org.odpi.openmetadata.commonservices.ffdc.rest.StringMapResponse; +import org.odpi.openmetadata.commonservices.ffdc.rest.StringRequestBody; import org.odpi.openmetadata.frameworks.auditlog.AuditLog; import org.odpi.openmetadata.frameworks.connectors.Connector; -import org.odpi.openmetadata.frameworks.connectors.ffdc.*; +import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectionCheckedException; +import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException; +import org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException; +import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException; +import org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException; import org.odpi.openmetadata.frameworks.connectors.properties.AssetUniverse; -import org.odpi.openmetadata.frameworks.connectors.properties.beans.*; +import org.odpi.openmetadata.frameworks.connectors.properties.beans.Connection; +import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementHeader; import org.odpi.openmetadata.frameworks.connectors.properties.beans.OwnerType; import org.odpi.openmetadata.frameworks.discovery.properties.Annotation; import org.odpi.openmetadata.frameworks.discovery.properties.AnnotationStatus; import org.odpi.openmetadata.frameworks.discovery.properties.DiscoveryAnalysisReport; -import java.util.Date; import java.util.List; import java.util.Map; + /** * AssetOwner provides the generic client-side interface for the Asset Owner Open Metadata Access Service (OMAS). * There are other clients that provide specialized methods for specific types of Asset. - * + *

* This client is initialized with the URL and name of the server that is running the Asset Owner OMAS. * This server is responsible for locating and managing the asset owner's definitions exchanged with this client. */ -public class AssetOwner extends ConnectedAssetClientBase implements AssetKnowledgeInterface, - AssetOnboardingInterface, - AssetClassificationInterface, - AssetConnectionManagementInterface, - AssetReviewInterface, - AssetDecommissioningInterface - +public class AssetOwner extends AssetOwnerBaseClient implements AssetKnowledgeInterface, + AssetOnboardingInterface, + AssetClassificationInterface, + AssetConnectionManagementInterface, + AssetReviewInterface, + AssetDecommissioningInterface { - protected AssetOwnerRESTClient restClient; /* Initialized in constructor */ - - private static final String serviceURLName = "asset-owner"; - private static final String defaultAssetType = "Asset"; - /** * Create a new client with no authentication embedded in the HTTP request. @@ -61,9 +78,7 @@ public AssetOwner(String serverName, String serverPlatformURLRoot, AuditLog auditLog) throws InvalidParameterException { - super(serverName, serverPlatformURLRoot, serviceURLName, auditLog); - - this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot, auditLog); + super(serverName, serverPlatformURLRoot, auditLog); } @@ -78,9 +93,7 @@ public AssetOwner(String serverName, public AssetOwner(String serverName, String serverPlatformURLRoot) throws InvalidParameterException { - super(serverName, serverPlatformURLRoot, serviceURLName); - - this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot); + super(serverName, serverPlatformURLRoot); } @@ -103,9 +116,7 @@ public AssetOwner(String serverName, String password, AuditLog auditLog) throws InvalidParameterException { - super(serverName, serverPlatformURLRoot, serviceURLName, auditLog); - - this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot, userId, password, auditLog); + super(serverName, serverPlatformURLRoot, userId, password, auditLog); } @@ -125,9 +136,7 @@ public AssetOwner(String serverName, String userId, String password) throws InvalidParameterException { - super(serverName, serverPlatformURLRoot, serviceURLName, userId, password); - - this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot, userId, password); + super(serverName, serverPlatformURLRoot, userId, password); } @@ -148,11 +157,7 @@ public AssetOwner(String serverName, int maxPageSize, AuditLog auditLog) throws InvalidParameterException { - super(serverName, serverPlatformURLRoot, serviceURLName, auditLog); - - invalidParameterHandler.setMaxPagingSize(maxPageSize); - - this.restClient = restClient; + super(serverName, serverPlatformURLRoot, restClient, maxPageSize, auditLog); } @@ -210,7 +215,7 @@ public List getTypesOfAsset(String userId) throws InvalidParameterExcep * Return the asset subtype names. * * @param userId calling user - * @return list of type names that are subtypes of asset + * @return map of type names that are subtypes of asset * @throws InvalidParameterException full path or userId is null * @throws PropertyServerException problem accessing property server * @throws UserNotAuthorizedException security access problem @@ -415,6 +420,288 @@ public void updateAsset(String userId, isMergeUpdate); } + /** + * Link two asset together. + * Use information from the relationship type definition to ensure the fromAssetGUID and toAssetGUID are the right way around. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to create + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param relationshipProperties unique identifier for this relationship + * + * @return unique identifier of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public String setupRelatedAsset(String userId, + String relationshipTypeName, + String fromAssetGUID, + String toAssetGUID, + RelationshipProperties relationshipProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "setupRelatedAsset"; + final String fromAssetGUIDParameterName = "fromAssetGUID"; + final String toAssetGUIDParameterName = "toAssetGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(fromAssetGUID, fromAssetGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(toAssetGUID, toAssetGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + RelationshipRequestBody requestBody = new RelationshipRequestBody(); + + requestBody.setProperties(relationshipProperties); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/assets/relationships/{2}/from-asset/{3}/to-asset/{4}"; + + GUIDResponse results = restClient.callGUIDPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + relationshipTypeName, + fromAssetGUID, + toAssetGUID); + + return results.getGUID(); + } + + + /** + * Retrieve the relationship between two elements. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to create + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * + * @return unique identifier and properties of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public RelationshipElement getAssetRelationship(String userId, + String relationshipTypeName, + String fromAssetGUID, + String toAssetGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "getAssetRelationship"; + final String fromAssetGUIDParameterName = "fromAssetGUID"; + final String toAssetGUIDParameterName = "toAssetGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(fromAssetGUID, fromAssetGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(toAssetGUID, toAssetGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/assets/relationships/{2}/from-asset/{3}/to-asset/{4}/retrieve"; + + + RelationshipElementResponse restResult = restClient.callRelationshipPostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + relationshipTypeName, + fromAssetGUID, + toAssetGUID); + + return restResult.getElement(); + } + + + /** + * Update relationship between two elements. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to update + * @param relationshipGUID unique identifier of the relationship + * @param relationshipProperties description and/or purpose of the relationship + * @param isMergeUpdate should the new properties be merged with the existing properties, or replace them entirely + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void updateAssetRelationship(String userId, + String relationshipTypeName, + String relationshipGUID, + boolean isMergeUpdate, + RelationshipProperties relationshipProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "updateAssetRelationship"; + final String relationshipGUIDParameterName = "relationshipGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(relationshipGUID, relationshipGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + RelationshipRequestBody requestBody = new RelationshipRequestBody(); + requestBody.setProperties(relationshipProperties); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/assets/relationships/{2}/{3}/update?isMergeUpdate={4}"; + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + relationshipTypeName, + relationshipGUID, + isMergeUpdate); + } + + + /** + * Remove the relationship between two elements. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param relationshipGUID unique identifier of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void clearAssetRelationship(String userId, + String relationshipTypeName, + String relationshipGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "clearAssetRelationship"; + final String relationshipGUIDParameterName = "relationshipGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(relationshipGUID, relationshipGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/assets/relationships/{2}/{3}/remove"; + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + relationshipTypeName, + relationshipGUID); + } + + + /** + * Retrieve the requested relationships linked from a specific element at end 2. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param startFrom start position for results + * @param pageSize maximum number of results + * + * @return unique identifier and properties of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public List getRelatedAssetsAtEnd2(String userId, + String relationshipTypeName, + String fromAssetGUID, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "getRelatedAssetsAtEnd2"; + final String fromAssetGUIDParameterName = "fromAssetGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(fromAssetGUID, fromAssetGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/assets/relationships/{2}/from-asset/{3}/retrieve/end2?startFrom={4}&pageSize={5}"; + + + RelationshipElementsResponse restResult = restClient.callRelationshipsPostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + relationshipTypeName, + fromAssetGUID, + startFrom, + pageSize); + + return restResult.getElementList(); + } + + + /** + * Retrieve the relationships linked from a specific element at end 2 of the relationship. + * + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param startFrom start position for results + * @param pageSize maximum number of results + * + * @return unique identifier and properties of the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public List getRelatedAssetsAtEnd1(String userId, + String relationshipTypeName, + String toAssetGUID, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "getRelatedAssetsAtEnd1"; + final String toAssetGUIDParameterName = "toAssetGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(toAssetGUID, toAssetGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/assets/relationships/{2}/to-asset/{3}/retrieve/end1?startFrom={4}&pageSize={5}"; + + RelationshipElementsResponse restResult = restClient.callRelationshipsPostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + relationshipTypeName, + toAssetGUID, + startFrom, + pageSize); + + return restResult.getElementList(); + } + /** * Stores the supplied schema details in the catalog and attaches it to the asset. If another schema is currently @@ -428,291 +715,1297 @@ public void updateAsset(String userId, * * @return guid of the schema type or * - * @throws InvalidParameterException full path or userId is null - * @throws PropertyServerException problem accessing property server - * @throws UserNotAuthorizedException security access problem + * @throws InvalidParameterException full path or userId is null + * @throws PropertyServerException problem accessing property server + * @throws UserNotAuthorizedException security access problem + */ + @Override + public String addCombinedSchemaToAsset(String userId, + String assetGUID, + SchemaTypeProperties schemaType, + List schemaAttributes) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "addCombinedSchemaToAsset"; + final String assetGUIDParameter = "assetGUID"; + final String schemaTypeParameter = "schemaType"; + final String urlTemplate = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/with-attributes"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + invalidParameterHandler.validateObject(schemaType, schemaTypeParameter, methodName); + + CombinedSchemaRequestBody requestBody = new CombinedSchemaRequestBody(); + + requestBody.setSchemaType(schemaType); + requestBody.setSchemaAttributes(schemaAttributes); + + GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + assetGUID); + + return restResult.getGUID(); + } + + + + /** + * Stores the supplied schema type in the catalog and attaches it to the asset. If another schema is currently + * attached to the asset, it is unlinked and deleted. + * + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param schemaType schema type to create and attach directly to the asset. + * + * @return guid of the new schema type or + * + * @throws InvalidParameterException full path or userId is null + * @throws PropertyServerException problem accessing property server + * @throws UserNotAuthorizedException security access problem + */ + @Override + public String addSchemaTypeToAsset(String userId, + String assetGUID, + SchemaTypeProperties schemaType) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "addSchemaTypeToAsset"; + final String assetGUIDParameter = "assetGUID"; + final String schemaTypeParameter = "schemaType"; + final String urlTemplate = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + invalidParameterHandler.validateObject(schemaType, schemaTypeParameter, methodName); + + GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, + urlTemplate, + schemaType, + serverName, + userId, + assetGUID); + + return restResult.getGUID(); + } + + + /** + * Links the supplied schema type directly to the asset. If this schema is either not found, or + * already attached to an asset, then an error occurs. If another schema is currently + * attached to the asset, it is unlinked and deleted. + * + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param schemaTypeGUID unique identifier of the schema type to attach + * + * @throws InvalidParameterException full path or userId is null + * @throws PropertyServerException problem accessing property server + * @throws UserNotAuthorizedException security access problem + */ + @Override + public void attachSchemaTypeToAsset(String userId, + String assetGUID, + String schemaTypeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "attachSchemaTypeToAsset"; + final String assetGUIDParameter = "assetGUID"; + final String schemaTypeParameter = "schemaTypeGUID"; + final String urlTemplate + = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/{3}/attach"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, schemaTypeParameter, methodName); + + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + nullRequestBody, + serverName, + userId, + assetGUID, + schemaTypeGUID); + } + + + /** + * Unlinks the schema from the asset but does not delete it. This means it can be reattached to a different asset. + * + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @return guid of detached schema type + * + * @throws InvalidParameterException full path or userId is null + * @throws PropertyServerException problem accessing property server + * @throws UserNotAuthorizedException security access problem + */ + @Override + public String detachSchemaTypeFromAsset(String userId, + String assetGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "detachSchemaTypeFromAsset"; + final String assetGUIDParameter = "assetGUID"; + final String urlTemplate + = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/detach"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + + GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, + urlTemplate, + nullRequestBody, + serverName, + userId, + assetGUID); + + return restResult.getGUID(); + } + + + /** + * Detaches and deletes an asset's schema. + * + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * + * @throws InvalidParameterException full path or userId is null + * @throws PropertyServerException problem accessing property server + * @throws UserNotAuthorizedException security access problem + */ + @Override + public void deleteAssetSchemaType(String userId, + String assetGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "deleteAssetSchemaType"; + final String assetGUIDParameter = "assetGUID"; + final String urlTemplate + = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/delete"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + nullRequestBody, + serverName, + userId, + assetGUID); + } + + + + + /* ===================================================================================================================== + * A schemaType describes the structure of a data asset, process or port + */ + + /** + * Create a new metadata element to represent a schema type. + * + * @param userId calling user + * @param schemaTypeProperties properties about the schema type to store + * + * @return unique identifier of the new schema type + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public String createSchemaType(String userId, + SchemaTypeProperties schemaTypeProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "createSchemaType"; + + return this.createSchemaType(userId, + null, + schemaTypeProperties, + methodName); + } + + + /** + * Create a new metadata element to represent a schema type. + * + * @param userId calling user + * @param anchorGUID unique identifier of the intended anchor of the schema type + * @param schemaTypeProperties properties about the schema type to store + * + * @return unique identifier of the new schema type + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public String createAnchoredSchemaType(String userId, + String anchorGUID, + SchemaTypeProperties schemaTypeProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "createAnchoredSchemaType"; + + return this.createSchemaType(userId, + anchorGUID, + schemaTypeProperties, + methodName); + } + + + /** + * Create a new metadata element to represent a schema type. + * + * @param userId calling user + * @param anchorGUID unique identifier of the intended anchor of the schema type + * @param schemaTypeProperties properties about the schema type to store + * @param methodName calling method + * + * @return unique identifier of the new schema type + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + private String createSchemaType(String userId, + String anchorGUID, + SchemaTypeProperties schemaTypeProperties, + String methodName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String propertiesParameterName = "schemaTypeProperties"; + final String qualifiedNameParameterName = "schemaTypeProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateObject(schemaTypeProperties, propertiesParameterName, methodName); + invalidParameterHandler.validateName(schemaTypeProperties.getQualifiedName(), qualifiedNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-types?anchorGUID={2}"; + + GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, + urlTemplate, + schemaTypeProperties, + serverName, + userId, + anchorGUID); + + return restResult.getGUID(); + } + + + /** + * Create a new metadata element to represent a schema type using an existing metadata element as a template. + * + * @param userId calling user + * @param templateGUID unique identifier of the metadata element to copy + * @param templateProperties properties that override the template + * + * @return unique identifier of the new schema type + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public String createSchemaTypeFromTemplate(String userId, + String templateGUID, + TemplateProperties templateProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "createSchemaTypeFromTemplate"; + final String templateGUIDParameterName = "templateGUID"; + final String propertiesParameterName = "templateProperties"; + final String qualifiedNameParameterName = "templateProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(templateGUID, templateGUIDParameterName, methodName); + invalidParameterHandler.validateObject(templateProperties, propertiesParameterName, methodName); + invalidParameterHandler.validateName(templateProperties.getQualifiedName(), qualifiedNameParameterName, methodName); + + TemplateRequestBody requestBody = new TemplateRequestBody(); + requestBody.setElementProperties(templateProperties); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-types/from-template/{2}"; + + GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + templateGUID); + + return restResult.getGUID(); + } + + + /** + * Update the metadata element representing a schema type. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the metadata element to update + * @param isMergeUpdate should the new properties be merged with existing properties (true) or completely replace them (false)? + * @param schemaTypeProperties new properties for the metadata element + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void updateSchemaType(String userId, + String schemaTypeGUID, + boolean isMergeUpdate, + SchemaTypeProperties schemaTypeProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "updateSchemaType"; + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + final String propertiesParameterName = "schemaTypeProperties"; + final String qualifiedNameParameterName = "schemaTypeProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, schemaTypeGUIDParameterName, methodName); + invalidParameterHandler.validateObject(schemaTypeProperties, propertiesParameterName, methodName); + invalidParameterHandler.validateName(schemaTypeProperties.getQualifiedName(), qualifiedNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-types/{2}?isMergeUpdate={3}"; + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + schemaTypeProperties, + serverName, + userId, + schemaTypeGUID, + isMergeUpdate); + } + + + /** + * Connect a schema type to a data asset, process or port. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param properties properties for the relationship + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void setupSchemaTypeParent(String userId, + String schemaTypeGUID, + String parentElementGUID, + String parentElementTypeName, + RelationshipProperties properties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "setupSchemaTypeParent"; + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + final String parentElementGUIDParameterName = "parentElementGUID"; + final String parentElementTypeParameterName = "parentElementTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, schemaTypeGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(parentElementGUID, parentElementGUIDParameterName, methodName); + invalidParameterHandler.validateName(parentElementTypeName, parentElementTypeParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/parents/{2}/{3}/schema-types/{4}"; + + RelationshipRequestBody requestBody = new RelationshipRequestBody(); + + requestBody.setProperties(properties); + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + parentElementGUID, + parentElementTypeName, + schemaTypeGUID); + } + + + /** + * Remove the relationship between a schema type and its parent data asset, process or port. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void clearSchemaTypeParent(String userId, + String schemaTypeGUID, + String parentElementGUID, + String parentElementTypeName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "clearSchemaTypeParent"; + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + final String parentElementGUIDParameterName = "parentElementGUID"; + final String parentElementTypeParameterName = "parentElementTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, schemaTypeGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(parentElementGUID, parentElementGUIDParameterName, methodName); + invalidParameterHandler.validateName(parentElementTypeName, parentElementTypeParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/parents/{2}/{3}/schema-types/{4}/remove"; + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + parentElementGUID, + parentElementTypeName, + schemaTypeGUID); + } + + + /** + * Create a relationship between two schema elements. The name of the desired relationship, and any properties + * are passed on the API. + * + * @param userId calling user + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to create + * @param properties relationship properties + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void setupSchemaElementRelationship(String userId, + String endOneGUID, + String endTwoGUID, + String relationshipTypeName, + RelationshipProperties properties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "setupSchemaElementRelationship"; + final String endOneGUIDParameterName = "endOneGUID"; + final String endTwoGUIDParameterName = "endTwoGUID"; + final String relationshipTypeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(endOneGUID, endOneGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(endTwoGUID, endTwoGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, relationshipTypeNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-elements/{2}/relationships/{3}/schema-elements/{4}"; + + RelationshipRequestBody requestBody = new RelationshipRequestBody(); + + requestBody.setProperties(properties); + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + endOneGUID, + relationshipTypeName, + endTwoGUID); + } + + + /** + * Remove a relationship between two schema elements. The name of the desired relationship is passed on the API. + * + * @param userId calling user + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to delete + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void clearSchemaElementRelationship(String userId, + String endOneGUID, + String endTwoGUID, + String relationshipTypeName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "clearSchemaElementRelationship"; + final String endOneGUIDParameterName = "endOneGUID"; + final String endTwoGUIDParameterName = "endTwoGUID"; + final String relationshipTypeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(endOneGUID, endOneGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(endTwoGUID, endTwoGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, relationshipTypeNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-elements/{2}/relationships/{3}/schema-elements/{4}/remove"; + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + endOneGUID, + relationshipTypeName, + endTwoGUID); + } + + + /** + * Remove the metadata element representing a schema type. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the metadata element to remove + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void removeSchemaType(String userId, + String schemaTypeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "removeSchemaType"; + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, schemaTypeGUIDParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-types/{2}/remove"; + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + new UpdateRequestBody(), + serverName, + userId, + schemaTypeGUID); + } + + + /** + * Retrieve the list of schema type metadata elements that contain the search string. + * The search string is treated as a regular expression. + * + * @param userId calling user + * @param searchString string to find in the properties + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * + * @return list of matching metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public List findSchemaType(String userId, + String searchString, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "findSchemaType"; + final String searchStringParameterName = "searchString"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateSearchString(searchString, searchStringParameterName, methodName); + int validatedPageSize = invalidParameterHandler.validatePaging(startFrom, pageSize, methodName); + + SearchStringRequestBody requestBody = new SearchStringRequestBody(); + + requestBody.setSearchString(searchString); + requestBody.setSearchStringParameterName(searchStringParameterName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-types/by-search-string?startFrom={2}&pageSize={3}"; + + SchemaTypeElementsResponse restResult = restClient.callSchemaTypesPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + startFrom, + validatedPageSize); + + return restResult.getElementList(); + } + + + /** + * Return the schema type associated with a specific open metadata element (data asset, process or port). + * + * @param userId calling user + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * + * @return metadata element describing the schema type associated with the requested parent element + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public SchemaTypeElement getSchemaTypeForElement(String userId, + String parentElementGUID, + String parentElementTypeName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "getSchemaTypeForElement"; + final String guidParameterName = "parentElementGUID"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(parentElementGUID, guidParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/parents/{2}/{3}/schema-types/retrieve"; + + SchemaTypeElementResponse restResult = restClient.callSchemaTypePostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + parentElementTypeName, + parentElementGUID); + + return restResult.getElement(); + } + + + /** + * Retrieve the list of schema type metadata elements with a matching qualified or display name. + * There are no wildcards supported on this request. + * + * @param userId calling user + * @param name name to search for + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * + * @return list of matching metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public List getSchemaTypeByName(String userId, + String name, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "getSchemaTypeByName"; + final String nameParameterName = "name"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateName(name, nameParameterName, methodName); + + int validatedPageSize = invalidParameterHandler.validatePaging(startFrom, pageSize, methodName); + + NameRequestBody requestBody = new NameRequestBody(); + + requestBody.setName(name); + requestBody.setNameParameterName(nameParameterName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-types/by-name?startFrom={2}&pageSize={3}"; + + SchemaTypeElementsResponse restResult = restClient.callSchemaTypesPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + startFrom, + validatedPageSize); + + return restResult.getElementList(); + } + + + /** + * Retrieve the schema type metadata element with the supplied unique identifier. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the requested metadata element + * + * @return requested metadata element + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public SchemaTypeElement getSchemaTypeByGUID(String userId, + String schemaTypeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "getSchemaTypeByGUID"; + final String guidParameterName = "schemaTypeGUID"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, guidParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-types/{2}/retrieve"; + + SchemaTypeElementResponse restResult = restClient.callSchemaTypePostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + schemaTypeGUID); + + return restResult.getElement(); + } + + + /** + * Retrieve the header of the metadata element connected to a schema type. + * + * @param userId calling user + * @param schemaTypeGUID unique identifier of the requested metadata element + * + * @return header for parent element (data asset, process, port) + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public ElementHeader getSchemaTypeParent(String userId, + String schemaTypeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "getSchemaTypeParent"; + final String guidParameterName = "schemaTypeGUID"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, guidParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/parents/schema-types/{2}/retrieve"; + + ElementHeaderResponse restResult = restClient.callElementHeaderPostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + schemaTypeGUID); + + return restResult.getElement(); + } + + + /* =============================================================================== + * A schemaType typically contains many schema attributes, linked with relationships. + */ + + + /** + * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. + * This method can be called repeatedly to add many attributes to a schema. + * + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param parentGUID unique identifier of the schema element to anchor these attributes to. + * @param schemaAttributes list of schema attribute objects. + * + * @throws InvalidParameterException full path or userId is null + * @throws PropertyServerException problem accessing property server + * @throws UserNotAuthorizedException security access problem + */ + @Override + public void addSchemaAttributes(String userId, + String assetGUID, + String parentGUID, + List schemaAttributes) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "addSchemaAttributesToSchemaType"; + final String assetGUIDParameter = "assetGUID"; + final String parentGUIDParameter = "parentGUID"; + final String schemaAttributesParameter = "schemaAttributes"; + final String schemaAttributeParameter = "schemaAttributes[x]"; + final String qualifiedNameParameter = "schemaAttribute[x].getQualifiedName()"; + final String urlTemplate + = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/{3}/schema-attributes/list"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + invalidParameterHandler.validateGUID(parentGUID, parentGUIDParameter, methodName); + invalidParameterHandler.validateObject(schemaAttributes, schemaAttributesParameter, methodName); + + for (SchemaAttributeProperties schemaAttributeProperties : schemaAttributes) + { + invalidParameterHandler.validateObject(schemaAttributeProperties, schemaAttributeParameter, methodName); + invalidParameterHandler.validateName(schemaAttributeProperties.getQualifiedName(), qualifiedNameParameter, methodName); + } + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + schemaAttributes, + serverName, + userId, + assetGUID, + parentGUID); + } + + + /** + * Adds a schema attribute to a complex schema type like a relational table, avro schema or a structured document. + * This method can be called repeatedly to add many attributes to a schema. The GUID returned can be used to add + * nested attributes. + * + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param parentGUID unique identifier of the schema element to anchor these attributes to. + * @param schemaAttribute schema attribute object to add. + * + * @return unique identifier for the new schema attribute or + * + * @throws InvalidParameterException full path or userId is null + * @throws PropertyServerException problem accessing property server + * @throws UserNotAuthorizedException security access problem + */ + @Override + public String addSchemaAttribute(String userId, + String assetGUID, + String parentGUID, + SchemaAttributeProperties schemaAttribute) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "addSchemaAttributes"; + final String assetGUIDParameter = "assetGUID"; + final String parentGUIDParameter = "parentGUID"; + final String schemaAttributeParameter = "schemaAttribute"; + final String qualifiedNameParameter = "schemaAttribute.getQualifiedName()"; + final String urlTemplate + = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/{3}/schema-attributes"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + invalidParameterHandler.validateGUID(parentGUID, parentGUIDParameter, methodName); + invalidParameterHandler.validateObject(schemaAttribute, schemaAttributeParameter, methodName); + invalidParameterHandler.validateName(schemaAttribute.getQualifiedName(), qualifiedNameParameter, methodName); + + GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, + urlTemplate, + schemaAttribute, + serverName, + userId, + assetGUID, + parentGUID); + + return restResult.getGUID(); + } + + + /** + * Create a new metadata element to represent a schema attribute using an existing metadata element as a template. + * + * @param userId calling user + * @param schemaElementGUID unique identifier of the schemaType or Schema Attribute where the schema attribute is connected to + * @param templateGUID unique identifier of the metadata element to copy + * @param templateProperties properties that override the template + * + * @return unique identifier of the new metadata element for the schema attribute + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public String createSchemaAttributeFromTemplate(String userId, + String schemaElementGUID, + String templateGUID, + TemplateProperties templateProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "createSchemaAttributeFromTemplate"; + final String schemaElementGUIDParameterName = "schemaElementGUID"; + final String templateGUIDParameterName = "templateGUID"; + final String propertiesParameterName = "templateProperties"; + final String qualifiedNameParameterName = "templateProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaElementGUID, schemaElementGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(templateGUID, templateGUIDParameterName, methodName); + invalidParameterHandler.validateObject(templateProperties, propertiesParameterName, methodName); + invalidParameterHandler.validateName(templateProperties.getQualifiedName(), qualifiedNameParameterName, methodName); + + TemplateRequestBody requestBody = new TemplateRequestBody(); + requestBody.setElementProperties(templateProperties); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-elements/{2}/schema-attributes/from-template/{3}"; + + GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + schemaElementGUID, + templateGUID); + + return restResult.getGUID(); + } + + + /** + * Update the properties of the metadata element representing a schema attribute. + * + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the schema attribute to update + * @param isMergeUpdate should the new properties be merged with existing properties (true) or completely replace them (false)? + * @param schemaAttributeProperties new properties for the schema attribute + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @Override + public void updateSchemaAttribute(String userId, + String schemaAttributeGUID, + boolean isMergeUpdate, + SchemaAttributeProperties schemaAttributeProperties) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String methodName = "updateSchemaAttribute"; + final String schemaAttributeGUIDParameterName = "schemaAttributeGUID"; + final String propertiesParameterName = "schemaAttributeProperties"; + final String qualifiedNameParameterName = "schemaAttributeProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaAttributeGUID, schemaAttributeGUIDParameterName, methodName); + invalidParameterHandler.validateObject(schemaAttributeProperties, propertiesParameterName, methodName); + invalidParameterHandler.validateName(schemaAttributeProperties.getQualifiedName(), qualifiedNameParameterName, methodName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-attributes/{2}?isMergeUpdate={3}"; + + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + schemaAttributeProperties, + serverName, + userId, + schemaAttributeGUID, + isMergeUpdate); + } + + + /** + * Classify the schema type (or attribute if type is embedded) to indicate that it is a calculated value. + * + * @param userId calling user + * @param schemaElementGUID unique identifier of the metadata element to update + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) */ @Override - public String addCombinedSchemaToAsset(String userId, - String assetGUID, - SchemaTypeProperties schemaType, - List schemaAttributes) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException + public void setSchemaElementAsCalculatedValue(String userId, + String schemaElementGUID, + String formula) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException { - final String methodName = "addCombinedSchemaToAsset"; - final String assetGUIDParameter = "assetGUID"; - final String schemaTypeParameter = "schemaType"; - final String urlTemplate = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/with-attributes"; + final String methodName = "setSchemaElementAsCalculatedValue"; + final String schemaElementGUIDParameterName = "schemaElementGUID"; invalidParameterHandler.validateUserId(userId, methodName); - invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); - invalidParameterHandler.validateObject(schemaType, schemaTypeParameter, methodName); + invalidParameterHandler.validateGUID(schemaElementGUID, schemaElementGUIDParameterName, methodName); - CombinedSchemaRequestBody requestBody = new CombinedSchemaRequestBody(); - - requestBody.setSchemaType(schemaType); - requestBody.setSchemaAttributes(schemaAttributes); + CalculatedValueClassificationRequestBody requestBody = new CalculatedValueClassificationRequestBody(); + requestBody.setFormula(formula); - GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, - urlTemplate, - requestBody, - serverName, - userId, - assetGUID); + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-elements/{2}/is-calculated-value"; - return restResult.getGUID(); + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + schemaElementGUID); } - /** - * Stores the supplied schema type in the catalog and attaches it to the asset. If another schema is currently - * attached to the asset, it is unlinked and deleted. + * Remove the calculated value designation from the schema element. * * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param schemaType schema type to create and attach directly to the asset. - * - * @return guid of the new schema type or + * @param schemaElementGUID unique identifier of the metadata element to update * - * @throws InvalidParameterException full path or userId is null - * @throws PropertyServerException problem accessing property server - * @throws UserNotAuthorizedException security access problem + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) */ @Override - public String addSchemaTypeToAsset(String userId, - String assetGUID, - SchemaTypeProperties schemaType) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException + public void clearSchemaElementAsCalculatedValue(String userId, + String schemaElementGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException { - final String methodName = "addSchemaTypeToAsset"; - final String assetGUIDParameter = "assetGUID"; - final String schemaTypeParameter = "schemaType"; - final String urlTemplate = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas"; + final String methodName = "clearSchemaElementAsCalculatedValue"; + final String schemaElementGUIDParameterName = "schemaElementGUID"; invalidParameterHandler.validateUserId(userId, methodName); - invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); - invalidParameterHandler.validateObject(schemaType, schemaTypeParameter, methodName); + invalidParameterHandler.validateGUID(schemaElementGUID, schemaElementGUIDParameterName, methodName); - GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, - urlTemplate, - schemaType, - serverName, - userId, - assetGUID); + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-elements/{2}/is-calculated-value/remove"; - return restResult.getGUID(); + restClient.callVoidPostRESTCall(methodName, + urlTemplate, + new UpdateRequestBody(), + serverName, + userId, + schemaElementGUID); } /** - * Links the supplied schema type directly to the asset. If this schema is either not found, or - * already attached to an asset, then an error occurs. If another schema is currently - * attached to the asset, it is unlinked and deleted. + * Remove the metadata element representing a schema attribute. * * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param schemaTypeGUID unique identifier of the schema type to attach + * @param schemaAttributeGUID unique identifier of the metadata element to remove * - * @throws InvalidParameterException full path or userId is null - * @throws PropertyServerException problem accessing property server - * @throws UserNotAuthorizedException security access problem + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) */ @Override - public void attachSchemaTypeToAsset(String userId, - String assetGUID, - String schemaTypeGUID) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException + public void removeSchemaAttribute(String userId, + String schemaAttributeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException { - final String methodName = "attachSchemaTypeToAsset"; - final String assetGUIDParameter = "assetGUID"; - final String schemaTypeParameter = "schemaTypeGUID"; - final String urlTemplate - = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/{3}/attach"; + final String methodName = "removeSchemaAttribute"; + final String schemaAttributeGUIDParameterName = "schemaAttributeGUID"; invalidParameterHandler.validateUserId(userId, methodName); - invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); - invalidParameterHandler.validateGUID(schemaTypeGUID, schemaTypeParameter, methodName); + invalidParameterHandler.validateGUID(schemaAttributeGUID, schemaAttributeGUIDParameterName, methodName); + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-attributes/{2}/remove"; restClient.callVoidPostRESTCall(methodName, urlTemplate, - nullRequestBody, + new UpdateRequestBody(), serverName, userId, - assetGUID, - schemaTypeGUID); + schemaAttributeGUID); } /** - * Unlinks the schema from the asset but does not delete it. This means it can be reattached to a different asset. + * Retrieve the list of schema attribute metadata elements that contain the search string. + * The search string is treated as a regular expression. * * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @return guid of detached schema type + * @param searchString string to find in the properties + * @param startFrom paging start point + * @param pageSize maximum results that can be returned * - * @throws InvalidParameterException full path or userId is null - * @throws PropertyServerException problem accessing property server - * @throws UserNotAuthorizedException security access problem + * @return list of matching metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) */ @Override - public String detachSchemaTypeFromAsset(String userId, - String assetGUID) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException + public List findSchemaAttributes(String userId, + String searchString, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException { - final String methodName = "detachSchemaTypeFromAsset"; - final String assetGUIDParameter = "assetGUID"; - final String urlTemplate - = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/detach"; + final String methodName = "findSchemaAttributes"; + final String searchStringParameterName = "searchString"; invalidParameterHandler.validateUserId(userId, methodName); - invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + invalidParameterHandler.validateSearchString(searchString, searchStringParameterName, methodName); + int validatedPageSize = invalidParameterHandler.validatePaging(startFrom, pageSize, methodName); - GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, - urlTemplate, - nullRequestBody, - serverName, - userId, - assetGUID); + SearchStringRequestBody requestBody = new SearchStringRequestBody(); + + requestBody.setSearchString(searchString); + requestBody.setSearchStringParameterName(searchStringParameterName); - return restResult.getGUID(); + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-attributes/by-search-string?startFrom={2}&pageSize={3}"; + + SchemaAttributeElementsResponse restResult = restClient.callSchemaAttributesPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + startFrom, + validatedPageSize); + + return restResult.getElementList(); } /** - * Detaches and deletes an asset's schema. + * Retrieve the list of schema attributes associated with a schema element. * * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param parentSchemaElementGUID unique identifier of the schema element of interest + * @param startFrom paging start point + * @param pageSize maximum results that can be returned * - * @throws InvalidParameterException full path or userId is null - * @throws PropertyServerException problem accessing property server - * @throws UserNotAuthorizedException security access problem + * @return list of associated metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) */ @Override - public void deleteAssetSchemaType(String userId, - String assetGUID) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException + public List getNestedSchemaAttributes(String userId, + String parentSchemaElementGUID, + int startFrom, + int pageSize) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException { - final String methodName = "deleteAssetSchemaType"; - final String assetGUIDParameter = "assetGUID"; - final String urlTemplate - = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/delete"; + final String methodName = "getNestedSchemaAttributes"; + final String guidParameterName = "parentSchemaElementGUID"; invalidParameterHandler.validateUserId(userId, methodName); - invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); + invalidParameterHandler.validateGUID(parentSchemaElementGUID, guidParameterName, methodName); + int validatedPageSize = invalidParameterHandler.validatePaging(startFrom, pageSize, methodName); - restClient.callGUIDPostRESTCall(methodName, - urlTemplate, - nullRequestBody, - serverName, - userId, - assetGUID); + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-elements/{2}/schema-attributes/retrieve?startFrom={3}&pageSize={4}"; + + SchemaAttributeElementsResponse restResult = restClient.callSchemaAttributesPostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + parentSchemaElementGUID, + startFrom, + validatedPageSize); + + return restResult.getElementList(); } /** - * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. - * This method can be called repeatedly to add many attributes to a schema. + * Retrieve the list of schema attribute metadata elements with a matching qualified or display name. + * There are no wildcards supported on this request. * - * @param serverName name of the server instance to connect to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param parentGUID unique identifier of the schema element to anchor these attributes to. - * @param schemaAttributes list of schema attribute objects. + * @param name name to search for + * @param startFrom paging start point + * @param pageSize maximum results that can be returned * - * @throws InvalidParameterException full path or userId is null - * @throws PropertyServerException problem accessing property server - * @throws UserNotAuthorizedException security access problem + * @return list of matching metadata elements + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) */ @Override - public void addSchemaAttributes(String serverName, - String userId, - String assetGUID, - String parentGUID, - List schemaAttributes) throws InvalidParameterException, + public List getSchemaAttributesByName(String userId, + String name, + int startFrom, + int pageSize) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { - final String methodName = "addSchemaAttributesToSchemaType"; - final String assetGUIDParameter = "assetGUID"; - final String parentGUIDParameter = "parentGUID"; - final String schemaAttributesParameter = "schemaAttributes"; - final String urlTemplate - = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/{3}/schema-attributes/list"; + final String methodName = "getSchemaAttributesByName"; + final String nameParameterName = "name"; invalidParameterHandler.validateUserId(userId, methodName); - invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); - invalidParameterHandler.validateGUID(parentGUID, parentGUIDParameter, methodName); - invalidParameterHandler.validateObject(schemaAttributes, schemaAttributesParameter, methodName); + invalidParameterHandler.validateName(name, nameParameterName, methodName); - restClient.callVoidPostRESTCall(methodName, - urlTemplate, - schemaAttributes, - serverName, - userId, - assetGUID, - parentGUID); + int validatedPageSize = invalidParameterHandler.validatePaging(startFrom, pageSize, methodName); + + NameRequestBody requestBody = new NameRequestBody(); + + requestBody.setName(name); + requestBody.setNameParameterName(nameParameterName); + + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-attributes/by-name?startFrom={2}&pageSize={3}"; + + SchemaAttributeElementsResponse restResult = restClient.callSchemaAttributesPostRESTCall(methodName, + urlTemplate, + requestBody, + serverName, + userId, + startFrom, + validatedPageSize); + + return restResult.getElementList(); } /** - * Adds a schema attribute to a complex schema type like a relational table, avro schema or a structured document. - * This method can be called repeatedly to add many attributes to a schema. The GUID returned can be used to add - * nested attributes. + * Retrieve the schema attribute metadata element with the supplied unique identifier. * - * @param serverName name of the server instance to connect to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param parentGUID unique identifier of the schema element to anchor these attributes to. - * @param schemaAttribute schema attribute object to add. + * @param schemaAttributeGUID unique identifier of the requested metadata element * - * @return unique identifier for the new schema attribute or + * @return matching metadata element * - * @throws InvalidParameterException full path or userId is null - * @throws PropertyServerException problem accessing property server - * @throws UserNotAuthorizedException security access problem + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) */ @Override - public String addSchemaAttribute(String serverName, - String userId, - String assetGUID, - String parentGUID, - SchemaAttributeProperties schemaAttribute) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException + public SchemaAttributeElement getSchemaAttributeByGUID(String userId, + String schemaAttributeGUID) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException { - final String methodName = "addSchemaAttributes"; - final String assetGUIDParameter = "assetGUID"; - final String parentGUIDParameter = "parentGUID"; - final String schemaAttributeParameter = "schemaAttribute"; - final String qualifiedNameParameter = "schemaAttribute.getQualifiedName()"; - final String urlTemplate - = serverPlatformURLRoot + "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/assets/{2}/schemas/{3}/schema-attributes"; + final String methodName = "getSchemaAttributeByGUID"; + final String guidParameterName = "schemaAttributeGUID"; invalidParameterHandler.validateUserId(userId, methodName); - invalidParameterHandler.validateGUID(assetGUID, assetGUIDParameter, methodName); - invalidParameterHandler.validateGUID(parentGUID, parentGUIDParameter, methodName); - invalidParameterHandler.validateObject(schemaAttribute, schemaAttributeParameter, methodName); - invalidParameterHandler.validateName(schemaAttribute.getQualifiedName(), qualifiedNameParameter, methodName); + invalidParameterHandler.validateGUID(schemaAttributeGUID, guidParameterName, methodName); - GUIDResponse restResult = restClient.callGUIDPostRESTCall(methodName, - urlTemplate, - schemaAttribute, - serverName, - userId, - assetGUID, - parentGUID); + final String urlTemplate = serverPlatformURLRoot + urlTemplatePrefix + "/schema-attributes/{2}/retrieve"; - return restResult.getGUID(); - } + SchemaAttributeElementResponse restResult = restClient.callSchemaAttributePostRESTCall(methodName, + urlTemplate, + new EffectiveTimeQueryRequestBody(), + serverName, + userId, + schemaAttributeGUID); + return restResult.getElement(); + } /** * Adds a connection to an asset. Assets can have multiple connections attached. @@ -2734,7 +4027,6 @@ public List getExtendedAnnotations(String userId, /** * Deletes an asset and all of its associated elements such as schema, connections (unless they are linked to * another asset), discovery reports and associated feedback. - * * Given the depth of the delete request performed by this call, it should be used with care. * * @param userId calling user diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/AssetOwnerBaseClient.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/AssetOwnerBaseClient.java index b9d798c9846..4ffb42f4bc4 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/AssetOwnerBaseClient.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/AssetOwnerBaseClient.java @@ -17,7 +17,6 @@ import org.odpi.openmetadata.accessservices.assetowner.rest.ReferenceableRequestBody; import org.odpi.openmetadata.accessservices.assetowner.rest.RelatedElementListResponse; import org.odpi.openmetadata.accessservices.assetowner.rest.RelationshipRequestBody; -import org.odpi.openmetadata.commonservices.ffdc.InvalidParameterHandler; import org.odpi.openmetadata.commonservices.ffdc.rest.GUIDResponse; import org.odpi.openmetadata.commonservices.ffdc.rest.NullRequestBody; import org.odpi.openmetadata.frameworks.auditlog.AuditLog; @@ -25,19 +24,20 @@ import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException; import org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException; import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementStub; +import org.odpi.openmetadata.frameworkservices.ocf.metadatamanagement.client.ConnectedAssetClientBase; import java.util.List; /** * AssetOwnerBaseClient supports the common properties and functions for the Community Profile OMAS. */ -public class AssetOwnerBaseClient implements RelatedElementsManagementInterface +public class AssetOwnerBaseClient extends ConnectedAssetClientBase implements RelatedElementsManagementInterface { - final String serverName; /* Initialized in constructor */ - final String serverPlatformURLRoot; /* Initialized in constructor */ + protected AssetOwnerRESTClient restClient; /* Initialized in constructor */ - final InvalidParameterHandler invalidParameterHandler = new InvalidParameterHandler(); - final AssetOwnerRESTClient restClient; /* Initialized in constructor */ + protected static final String serviceURLName = "asset-owner"; + protected static final String defaultAssetType = "Asset"; + final protected String urlTemplatePrefix = "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}"; private static final String elementsURLTemplatePrefix = "/servers/{0}/open-metadata/access-services/asset-owner/users/{1}/related-elements"; @@ -48,7 +48,6 @@ public class AssetOwnerBaseClient implements RelatedElementsManagementInterface * * @param serverName name of the server to connect to * @param serverPlatformURLRoot the network address of the server running the OMAS REST services - * @param maxPageSize pre-initialized parameter limit * @param auditLog logging destination * * @throws InvalidParameterException there is a problem creating the client-side components to issue any @@ -56,17 +55,31 @@ public class AssetOwnerBaseClient implements RelatedElementsManagementInterface */ public AssetOwnerBaseClient(String serverName, String serverPlatformURLRoot, - int maxPageSize, AuditLog auditLog) throws InvalidParameterException { - final String methodName = "Client Constructor"; + super(serverName, serverPlatformURLRoot, serviceURLName, auditLog); - invalidParameterHandler.validateOMAGServerPlatformURL(serverPlatformURLRoot, serverName, methodName); + this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot, auditLog); + } - this.serverName = serverName; - this.serverPlatformURLRoot = serverPlatformURLRoot; - invalidParameterHandler.setMaxPagingSize(maxPageSize); + /** + * Create a new client with no authentication embedded in the HTTP request. + * + * @param serverName name of the server to connect to + * @param serverPlatformURLRoot the network address of the server running the OMAS REST services + * @param maxPageSize pre-initialized parameter limit + * @param auditLog logging destination + * + * @throws InvalidParameterException there is a problem creating the client-side components to issue any + * REST API calls. + */ + public AssetOwnerBaseClient(String serverName, + String serverPlatformURLRoot, + int maxPageSize, + AuditLog auditLog) throws InvalidParameterException + { + super(serverName, serverPlatformURLRoot, serviceURLName, maxPageSize, auditLog); this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot, auditLog); } @@ -84,12 +97,7 @@ public AssetOwnerBaseClient(String serverName, public AssetOwnerBaseClient(String serverName, String serverPlatformURLRoot) throws InvalidParameterException { - final String methodName = "Client Constructor"; - - invalidParameterHandler.validateOMAGServerPlatformURL(serverPlatformURLRoot, serverName, methodName); - - this.serverName = serverName; - this.serverPlatformURLRoot = serverPlatformURLRoot; + super(serverName, serverPlatformURLRoot, serviceURLName); this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot); } @@ -112,14 +120,34 @@ public AssetOwnerBaseClient(String serverName, String userId, String password) throws InvalidParameterException { - final String methodName = "Client Constructor"; + super(serverName, serverPlatformURLRoot, serviceURLName, userId, password); + } - invalidParameterHandler.validateOMAGServerPlatformURL(serverPlatformURLRoot, serverName, methodName); - this.serverName = serverName; - this.serverPlatformURLRoot = serverPlatformURLRoot; + /** + * Create a new client that passes userId and password in each HTTP request. This is the + * userId/password of the calling server. The end user's userId is sent on each request. + * + * @param serverName name of the server to connect to + * @param serverPlatformURLRoot the network address of the server running the OMAS REST services + * @param userId caller's userId embedded in all HTTP requests + * @param password caller's userId embedded in all HTTP requests + * @param maxPageSize pre-initialized parameter limit + * @param auditLog logging destination + * + * @throws InvalidParameterException there is a problem creating the client-side components to issue any + * REST API calls. + */ + public AssetOwnerBaseClient(String serverName, + String serverPlatformURLRoot, + String userId, + String password, + int maxPageSize, + AuditLog auditLog) throws InvalidParameterException + { + super(serverName, serverPlatformURLRoot, serviceURLName, userId, password, auditLog); - this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot, userId, password); + invalidParameterHandler.setMaxPagingSize(maxPageSize); } @@ -131,7 +159,6 @@ public AssetOwnerBaseClient(String serverName, * @param serverPlatformURLRoot the network address of the server running the OMAS REST services * @param userId caller's userId embedded in all HTTP requests * @param password caller's userId embedded in all HTTP requests - * @param maxPageSize pre-initialized parameter limit * @param auditLog logging destination * * @throws InvalidParameterException there is a problem creating the client-side components to issue any @@ -141,19 +168,33 @@ public AssetOwnerBaseClient(String serverName, String serverPlatformURLRoot, String userId, String password, - int maxPageSize, AuditLog auditLog) throws InvalidParameterException { - final String methodName = "Client Constructor"; + super(serverName, serverPlatformURLRoot, serviceURLName, userId, password, auditLog); + } - invalidParameterHandler.validateOMAGServerPlatformURL(serverPlatformURLRoot, serverName, methodName); - this.serverName = serverName; - this.serverPlatformURLRoot = serverPlatformURLRoot; + /** + * Create a new client that is going to be used in an OMAG Server. + * + * @param serverName name of the server to connect to + * @param serverPlatformURLRoot the network address of the server running the OMAS REST services + * @param restClient client that issues the REST API calls + * @param maxPageSize maximum number of results supported by this server + * + * @throws InvalidParameterException there is a problem creating the client-side components to issue any + * REST API calls. + */ + public AssetOwnerBaseClient(String serverName, + String serverPlatformURLRoot, + AssetOwnerRESTClient restClient, + int maxPageSize) throws InvalidParameterException + { + super(serverName, serverPlatformURLRoot, serviceURLName); invalidParameterHandler.setMaxPagingSize(maxPageSize); - this.restClient = new AssetOwnerRESTClient(serverName, serverPlatformURLRoot, userId, password, auditLog); + this.restClient = restClient; } @@ -164,21 +205,18 @@ public AssetOwnerBaseClient(String serverName, * @param serverPlatformURLRoot the network address of the server running the OMAS REST services * @param restClient client that issues the REST API calls * @param maxPageSize maximum number of results supported by this server + * @param auditLog logging destination * * @throws InvalidParameterException there is a problem creating the client-side components to issue any * REST API calls. */ - public AssetOwnerBaseClient(String serverName, - String serverPlatformURLRoot, + public AssetOwnerBaseClient(String serverName, + String serverPlatformURLRoot, AssetOwnerRESTClient restClient, - int maxPageSize) throws InvalidParameterException + int maxPageSize, + AuditLog auditLog) throws InvalidParameterException { - final String methodName = "Client Constructor"; - - invalidParameterHandler.validateOMAGServerPlatformURL(serverPlatformURLRoot, serverName, methodName); - - this.serverName = serverName; - this.serverPlatformURLRoot = serverPlatformURLRoot; + super(serverName, serverPlatformURLRoot, serviceURLName, auditLog); invalidParameterHandler.setMaxPagingSize(maxPageSize); diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/rest/AssetOwnerRESTClient.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/rest/AssetOwnerRESTClient.java index b7022903eda..c1f20f4ab6d 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/rest/AssetOwnerRESTClient.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-client/src/main/java/org/odpi/openmetadata/accessservices/assetowner/client/rest/AssetOwnerRESTClient.java @@ -968,4 +968,201 @@ public LicenseTypeListResponse callLicenseTypeListPostRESTCall(String methodN } + + /** + * Issue a POST REST call that returns a SchemaAttributeElementResponse object. + * + * @param methodName name of the method being called. + * @param urlTemplate template of the URL for the REST API call with place-holders for the parameters. + * @param requestBody object that passes additional parameters + * @param params a list of parameters that are slotted into the url template. + * + * @return response object + * @throws InvalidParameterException one of the parameters is invalid. + * @throws UserNotAuthorizedException the user is not authorized to make this request. + * @throws PropertyServerException the repository is not available or not working properly. + */ + public SchemaAttributeElementResponse callSchemaAttributePostRESTCall(String methodName, + String urlTemplate, + Object requestBody, + Object... params) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + SchemaAttributeElementResponse restResult = this.callPostRESTCall(methodName, SchemaAttributeElementResponse.class, urlTemplate, requestBody, params); + + exceptionHandler.detectAndThrowStandardExceptions(methodName, restResult); + + return restResult; + } + + + /** + * Issue a POST REST call that returns a SchemaAttributeElementsResponse object. + * + * @param methodName name of the method being called. + * @param urlTemplate template of the URL for the REST API call with place-holders for the parameters. + * @param requestBody object that passes additional parameters + * @param params a list of parameters that are slotted into the url template. + * + * @return response object + * @throws InvalidParameterException one of the parameters is invalid. + * @throws UserNotAuthorizedException the user is not authorized to make this request. + * @throws PropertyServerException the repository is not available or not working properly. + */ + public SchemaAttributeElementsResponse callSchemaAttributesPostRESTCall(String methodName, + String urlTemplate, + Object requestBody, + Object... params) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + SchemaAttributeElementsResponse restResult = this.callPostRESTCall(methodName, SchemaAttributeElementsResponse.class, urlTemplate, requestBody, params); + + exceptionHandler.detectAndThrowStandardExceptions(methodName, restResult); + + return restResult; + } + + + /** + * Issue a POST REST call that returns a SchemaTypeElementResponse object. + * + * @param methodName name of the method being called. + * @param urlTemplate template of the URL for the REST API call with place-holders for the parameters. + * @param requestBody object that passes additional parameters + * @param params a list of parameters that are slotted into the url template. + * + * @return response object + * @throws InvalidParameterException one of the parameters is invalid. + * @throws UserNotAuthorizedException the user is not authorized to make this request. + * @throws PropertyServerException the repository is not available or not working properly. + */ + public SchemaTypeElementResponse callSchemaTypePostRESTCall(String methodName, + String urlTemplate, + Object requestBody, + Object... params) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + SchemaTypeElementResponse restResult = this.callPostRESTCall(methodName, SchemaTypeElementResponse.class, urlTemplate, requestBody, params); + + exceptionHandler.detectAndThrowStandardExceptions(methodName, restResult); + + return restResult; + } + + + /** + * Issue a POST REST call that returns a SchemaTypeElementsResponse object. + * + * @param methodName name of the method being called. + * @param urlTemplate template of the URL for the REST API call with place-holders for the parameters. + * @param requestBody object that passes additional parameters + * @param params a list of parameters that are slotted into the url template. + * + * @return response object + * @throws InvalidParameterException one of the parameters is invalid. + * @throws UserNotAuthorizedException the user is not authorized to make this request. + * @throws PropertyServerException the repository is not available or not working properly. + */ + public SchemaTypeElementsResponse callSchemaTypesPostRESTCall(String methodName, + String urlTemplate, + Object requestBody, + Object... params) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + SchemaTypeElementsResponse restResult = this.callPostRESTCall(methodName, SchemaTypeElementsResponse.class, urlTemplate, requestBody, params); + + exceptionHandler.detectAndThrowStandardExceptions(methodName, restResult); + + return restResult; + } + + /** + * Issue a POST REST call that returns a ElementHeaderResponse object. + * + * @param methodName name of the method being called. + * @param urlTemplate template of the URL for the REST API call with place-holders for the parameters. + * @param requestBody object that passes additional parameters + * @param params a list of parameters that are slotted into the url template. + * + * @return response object + * @throws InvalidParameterException one of the parameters is invalid. + * @throws UserNotAuthorizedException the user is not authorized to make this request. + * @throws PropertyServerException the repository is not available or not working properly. + */ + public ElementHeaderResponse callElementHeaderPostRESTCall(String methodName, + String urlTemplate, + Object requestBody, + Object... params) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + ElementHeaderResponse restResult = this.callPostRESTCall(methodName, + ElementHeaderResponse.class, + urlTemplate, + requestBody, + params); + + exceptionHandler.detectAndThrowStandardExceptions(methodName, restResult); + + return restResult; + } + + /** + * Issue a POST REST call that returns a RelationshipElementResponse object. + * + * @param methodName name of the method being called. + * @param urlTemplate template of the URL for the REST API call with place-holders for the parameters. + * @param requestBody object that passes additional parameters + * @param params a list of parameters that are slotted into the url template. + * + * @return response object + * @throws InvalidParameterException one of the parameters is invalid. + * @throws UserNotAuthorizedException the user is not authorized to make this request. + * @throws PropertyServerException the repository is not available or not working properly. + */ + public RelationshipElementResponse callRelationshipPostRESTCall(String methodName, + String urlTemplate, + Object requestBody, + Object... params) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + RelationshipElementResponse restResult = this.callPostRESTCall(methodName, RelationshipElementResponse.class, urlTemplate, requestBody, params); + + exceptionHandler.detectAndThrowStandardExceptions(methodName, restResult); + + return restResult; + } + + + /** + * Issue a POST REST call that returns a RelationshipElementsResponse object. + * + * @param methodName name of the method being called. + * @param urlTemplate template of the URL for the REST API call with place-holders for the parameters. + * @param requestBody object that passes additional parameters + * @param params a list of parameters that are slotted into the url template. + * + * @return response object + * @throws InvalidParameterException one of the parameters is invalid. + * @throws UserNotAuthorizedException the user is not authorized to make this request. + * @throws PropertyServerException the repository is not available or not working properly. + */ + public RelationshipElementsResponse callRelationshipsPostRESTCall(String methodName, + String urlTemplate, + Object requestBody, + Object... params) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + RelationshipElementsResponse restResult = this.callPostRESTCall(methodName, RelationshipElementsResponse.class, urlTemplate, requestBody, params); + + exceptionHandler.detectAndThrowStandardExceptions(methodName, restResult); + + return restResult; + } } diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/converters/ElementHeaderConverter.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/converters/ElementHeaderConverter.java index 32b1a007921..7bf24f405bf 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/converters/ElementHeaderConverter.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/converters/ElementHeaderConverter.java @@ -5,6 +5,7 @@ import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException; import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementHeader; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefCategory; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper; @@ -78,6 +79,96 @@ public B getNewBean(Class beanClass, } + /** + * Using the supplied instances, return a new instance of the bean. This is used for beans that + * contain a combination of the properties from an entity and that of a connected relationship. + * + * @param beanClass name of the class to create + * @param entity entity containing the properties + * @param methodName calling method + * @return bean populated with properties from the instances supplied + * @throws PropertyServerException there is a problem instantiating the bean + */ + @SuppressWarnings(value = "unchecked") + public B getNewBean(Class beanClass, + EntityProxy entity, + String methodName) throws PropertyServerException + { + try + { + /* + * This is initial confirmation that the generic converter has been initialized with an appropriate bean class. + */ + B returnBean = beanClass.getDeclaredConstructor().newInstance(); + + if (returnBean instanceof ElementHeader) + { + if (entity != null) + { + returnBean = (B) this.getMetadataElementHeader(beanClass, entity, null, methodName); + } + else + { + handleMissingMetadataInstance(beanClass.getName(), TypeDefCategory.ENTITY_DEF, methodName); + } + } + + return returnBean; + } + catch (IllegalAccessException | InstantiationException | ClassCastException | NoSuchMethodException | InvocationTargetException error) + { + super.handleInvalidBeanClass(beanClass.getName(), error, methodName); + } + + return null; + } + + + /** + * Using the supplied instances, return a new instance of the bean. This is used for beans that + * contain a combination of the properties from a relationship and that of a connected relationship. + * + * @param beanClass name of the class to create + * @param relationship relationship containing the properties + * @param methodName calling method + * @return bean populated with properties from the instances supplied + * @throws PropertyServerException there is a problem instantiating the bean + */ + @SuppressWarnings(value = "unchecked") + public B getNewBean(Class beanClass, + Relationship relationship, + String methodName) throws PropertyServerException + { + try + { + /* + * This is initial confirmation that the generic converter has been initialized with an appropriate bean class. + */ + B returnBean = beanClass.getDeclaredConstructor().newInstance(); + + if (returnBean instanceof ElementHeader) + { + if (relationship != null) + { + returnBean = (B) this.getMetadataElementHeader(beanClass, relationship, null, methodName); + } + else + { + handleMissingMetadataInstance(beanClass.getName(), TypeDefCategory.ENTITY_DEF, methodName); + } + } + + return returnBean; + } + catch (IllegalAccessException | InstantiationException | ClassCastException | NoSuchMethodException | InvocationTargetException error) + { + super.handleInvalidBeanClass(beanClass.getName(), error, methodName); + } + + return null; + } + + /** * Using the supplied instances, return a new instance of the bean. This is used for beans that * contain a combination of the properties from an entity and that of a connected relationship. diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/AssetOwnerRESTServices.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/AssetOwnerRESTServices.java index 6cf5d250909..38fcf614089 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/AssetOwnerRESTServices.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/AssetOwnerRESTServices.java @@ -3,6 +3,7 @@ package org.odpi.openmetadata.accessservices.assetowner.server; +import org.odpi.openmetadata.accessservices.assetowner.converters.ElementHeaderConverter; import org.odpi.openmetadata.accessservices.assetowner.metadataelements.*; import org.odpi.openmetadata.accessservices.assetowner.properties.*; import org.odpi.openmetadata.accessservices.assetowner.rest.*; @@ -12,17 +13,20 @@ import org.odpi.openmetadata.commonservices.ffdc.RESTCallToken; import org.odpi.openmetadata.commonservices.ffdc.RESTExceptionHandler; import org.odpi.openmetadata.commonservices.ffdc.rest.*; +import org.odpi.openmetadata.commonservices.repositoryhandler.RepositoryRelationshipsIterator; import org.odpi.openmetadata.frameworks.auditlog.AuditLog; import org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException; import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException; import org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException; import org.odpi.openmetadata.frameworks.connectors.properties.beans.Connection; +import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementHeader; import org.odpi.openmetadata.frameworks.discovery.properties.Annotation; import org.odpi.openmetadata.frameworks.discovery.properties.AnnotationStatus; import org.odpi.openmetadata.frameworks.discovery.properties.DiscoveryAnalysisReport; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceStatus; +import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship; import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper; import org.slf4j.LoggerFactory; @@ -41,6 +45,10 @@ public class AssetOwnerRESTServices private static final RESTCallLogger restCallLogger = new RESTCallLogger(LoggerFactory.getLogger(AssetOwnerRESTServices.class), instanceHandler.getServiceName()); + private final static String schemaTypeGUIDParameterName = "schemaTypeGUID"; + private final static String schemaAttributeGUIDParameterName = "schemaAttributeGUID"; + + private final InvalidParameterHandler invalidParameterHandler = new InvalidParameterHandler(); /** @@ -398,27 +406,32 @@ public VoidResponse updateAsset(String serverName, } + + /** - * Stores the supplied schema details in the catalog and attaches it to the asset. If another schema is currently - * attached to the asset, it is unlinked and deleted. If more attributes need to be added in addition to the - * ones supplied then this can be done with addSchemaAttributesToSchemaType(). + * Link two asset together. + * Use information from the relationship type definition to ensure the fromAssetGUID and toAssetGUID are the right way around. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param requestBody schema type to create and attach directly to the asset. + * @param relationshipTypeName type name of relationship to create + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param requestBody unique identifier for this relationship * - * @return guid of the schema type or - * InvalidParameterException full path or userId is null, or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return unique identifier of the relationship or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - public GUIDResponse addCombinedSchemaToAsset(String serverName, - String userId, - String assetGUID, - CombinedSchemaRequestBody requestBody) + public GUIDResponse setupRelatedAsset(String serverName, + String userId, + String relationshipTypeName, + String fromAssetGUID, + String toAssetGUID, + RelationshipRequestBody requestBody) { - final String methodName = "addCombinedSchemaToAsset"; + final String methodName = "setupRelatedDataAsset"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); @@ -427,42 +440,104 @@ public GUIDResponse addCombinedSchemaToAsset(String serverN try { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + + final String fromAssetGUIDParameterName = "fromAssetGUID"; + final String toAssetGUIDParameterName = "toAssetGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(fromAssetGUID, fromAssetGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(toAssetGUID, toAssetGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, + null, + handler.getServiceName(), + methodName, + handler.getRepositoryHelper()); + if (requestBody != null) { - if (requestBody.getSchemaType() != null) + if (requestBody.getProperties() instanceof DataContentForDataSetProperties dataContentForDataSetProperties) { - auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); - - response.setGUID(this.addAssociatedSchemaType(userId, - serverName, - assetGUID, - requestBody.getSchemaType(), + InstanceProperties instanceProperties = handler.getRepositoryHelper().addStringPropertyToInstance(handler.getServiceName(), + null, + OpenMetadataAPIMapper.QUERY_ID_PROPERTY_NAME, + dataContentForDataSetProperties.getQueryId(), + methodName); + instanceProperties = handler.getRepositoryHelper().addStringPropertyToInstance(handler.getServiceName(), + instanceProperties, + OpenMetadataAPIMapper.QUERY_PROPERTY_NAME, + dataContentForDataSetProperties.getQuery(), + methodName); + + response.setGUID(handler.linkElementToElement(userId, + null, + null, + fromAssetGUID, + fromAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + toAssetGUID, + toAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + false, + false, + handler.getSupportedZones(), + relationshipTypeGUID, + relationshipTypeName, + instanceProperties, + null, + null, + requestBody.getEffectiveTime(), methodName)); - - - if (requestBody.getSchemaAttributes() != null) - { - for (SchemaAttributeProperties schemaAttributeProperties : requestBody.getSchemaAttributes()) - { - this.addAssociatedSchemaAttribute(userId, - serverName, - assetGUID, - response.getGUID(), - schemaAttributeProperties, - methodName); - } - } } else { - final String parameterName = "requestBody.getSchemaType()"; - - restExceptionHandler.handleMissingValue(parameterName, methodName); + response.setGUID(handler.linkElementToElement(userId, + null, + null, + fromAssetGUID, + fromAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + toAssetGUID, + toAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + false, + false, + handler.getSupportedZones(), + relationshipTypeGUID, + relationshipTypeName, + null, + null, + null, + requestBody.getEffectiveTime(), + methodName)); } } else { - restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + response.setGUID(handler.linkElementToElement(userId, + null, + null, + fromAssetGUID, + fromAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + toAssetGUID, + toAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + false, + false, + handler.getSupportedZones(), + relationshipTypeGUID, + relationshipTypeName, + null, + null, + null, + null, + methodName)); } } catch (Exception error) @@ -471,52 +546,97 @@ public GUIDResponse addCombinedSchemaToAsset(String serverN } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } /** - * Stores the supplied schema type in the catalog and attaches it to the asset. If another schema is currently - * attached to the asset, it is unlinked and deleted. + * Retrieve the relationship between two elements. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param requestBody schema type to create and attach directly to the asset. + * @param relationshipTypeName type name of relationship to create + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param requestBody optional date for effective time of the query. Null means any effective time * - * @return guid of the new schema type or - * InvalidParameterException full path or userId is null, or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return unique identifier and properties of the relationship or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - public GUIDResponse addSchemaTypeToAsset(String serverName, - String userId, - String assetGUID, - SchemaTypeProperties requestBody) + public RelationshipElementResponse getAssetRelationship(String serverName, + String userId, + String relationshipTypeName, + String fromAssetGUID, + String toAssetGUID, + EffectiveTimeQueryRequestBody requestBody) { - final String methodName = "addSchemaTypeToAsset"; + final String methodName = "getAssetRelationship"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); - GUIDResponse response = new GUIDResponse(); - AuditLog auditLog = null; + RelationshipElementResponse response = new RelationshipElementResponse(); + AuditLog auditLog = null; try { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + + final String fromAssetGUIDParameterName = "fromAssetGUID"; + final String toAssetGUIDParameterName = "toAssetGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(fromAssetGUID, fromAssetGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(toAssetGUID, toAssetGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, + null, + instanceHandler.getServiceName(), + methodName, + handler.getRepositoryHelper()); + + Relationship relationship; + if (requestBody != null) { - response.setGUID(this.addAssociatedSchemaType(userId, - serverName, - assetGUID, - requestBody, - methodName)); + relationship = handler.getUniqueAttachmentLink(userId, + fromAssetGUID, + fromAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + relationshipTypeGUID, + relationshipTypeName, + toAssetGUID, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + 2, + false, + false, + requestBody.getEffectiveTime(), + methodName); } else { - restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + relationship = handler.getUniqueAttachmentLink(userId, + fromAssetGUID, + fromAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + relationshipTypeGUID, + relationshipTypeName, + toAssetGUID, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + 2, + false, + false, + null, + methodName); } + + response.setElement(getRelationshipElement(relationship, handler.getRepositoryHelper(), serverName, methodName)); } catch (Exception error) { @@ -524,61 +644,95 @@ public GUIDResponse addSchemaTypeToAsset(String serverName, } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } /** - * Stores the supplied schema type in the catalog and attaches it to the asset. If another schema is currently - * attached to the asset, it is unlinked and deleted. + * Update relationship between two elements. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param requestBody schema type to create and attach directly to the asset. + * @param relationshipTypeName type name of relationship to update + * @param relationshipGUID unique identifier of the relationship + * @param isMergeUpdate should the new properties be merged with the existing properties, or replace them entirely + * @param requestBody description and/or purpose of the relationship * - * @return guid of the new schema type or - * InvalidParameterException full path or userId is null, or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - @Deprecated - public GUIDResponse addSchemaTypeToAsset(String serverName, - String userId, - String assetGUID, - SchemaTypeRequestBody requestBody) + public VoidResponse updateAssetRelationship(String serverName, + String userId, + String relationshipTypeName, + String relationshipGUID, + boolean isMergeUpdate, + RelationshipRequestBody requestBody) { - final String methodName = "addSchemaTypeToAsset"; + final String methodName = "updateAssetRelationship"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); - GUIDResponse response = new GUIDResponse(); + VoidResponse response = new VoidResponse(); AuditLog auditLog = null; try { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + + final String relationshipGUIDParameterName = "relationshipGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(relationshipGUID, relationshipGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + if (requestBody != null) { - if (requestBody.getSchemaTypeProperties() != null) + InstanceProperties instanceProperties = null; + + if (requestBody.getProperties() != null) { - response.setGUID(this.addAssociatedSchemaType(userId, - serverName, - assetGUID, - requestBody.getSchemaTypeProperties(), - methodName)); + if (requestBody.getProperties() instanceof DataContentForDataSetProperties dataContentForDataSetProperties) + { + instanceProperties = handler.getRepositoryHelper().addStringPropertyToInstance(handler.getServiceName(), null, OpenMetadataAPIMapper.QUERY_ID_PROPERTY_NAME, dataContentForDataSetProperties.getQueryId(), methodName); + instanceProperties = handler.getRepositoryHelper().addStringPropertyToInstance(handler.getServiceName(), instanceProperties, OpenMetadataAPIMapper.QUERY_PROPERTY_NAME, dataContentForDataSetProperties.getQuery(), methodName); + } } - else - { - final String parameterName = "requestBody.getSchemaTypeProperties()"; - restExceptionHandler.handleMissingValue(parameterName, methodName); - } + handler.updateElementToElementLink(userId, + null, + null, + relationshipGUID, + relationshipGUIDParameterName, + relationshipTypeName, + false, + false, + handler.getSupportedZones(), + isMergeUpdate, + instanceProperties, + requestBody.getEffectiveTime(), + methodName); } else { - restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + handler.updateElementToElementLink(userId, + null, + null, + relationshipGUID, + relationshipGUIDParameterName, + relationshipTypeName, + false, + false, + handler.getSupportedZones(), + isMergeUpdate, + null, + null, + methodName); } } catch (Exception error) @@ -587,289 +741,2306 @@ public GUIDResponse addSchemaTypeToAsset(String serverName, } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } /** - * Request that the asset handler creates a schema type and links it to the asset. + * Remove the relationship between two elements. * + * @param serverName name of the server to route the request to * @param userId calling user - * @param serverName name of the server instance to connect to - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param schemaType properties for a schema type - * @param methodName calling method - * @return unique identifier of the newly created schema type - * @throws InvalidParameterException one of the parameters is invalid - * @throws UserNotAuthorizedException calling user is not permitted to perform this operation - * @throws PropertyServerException there was a problem in one of the repositories + * @param relationshipTypeName type name of relationship to delete + * @param relationshipGUID unique identifier of the relationship + * @param requestBody external source ids + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - private String addAssociatedSchemaType(String userId, - String serverName, - String assetGUID, - SchemaTypeProperties schemaType, - String methodName) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException + public VoidResponse clearAssetRelationship(String serverName, + String userId, + String relationshipTypeName, + String relationshipGUID, + EffectiveTimeQueryRequestBody requestBody) { - final String assetGUIDParameterName = "assetGUID"; - final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + final String methodName = "clearAssetRelationship"; - SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); - SchemaTypeBuilder schemaTypeBuilder = getSchemaTypeBuilder(schemaType, - handler.getRepositoryHelper(), - handler.getServiceName(), - serverName, - methodName); + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; - if (assetGUID != null) + try { - schemaTypeBuilder.setAnchors(userId, assetGUID, methodName); - } + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); - String schemaTypeGUID = handler.addSchemaType(userId, - null, - null, - schemaTypeBuilder, - null, - null, - false, - false, - new Date(), - methodName); + final String relationshipGUIDParameterName = "relationshipGUID"; + final String typeNameParameterName = "relationshipTypeName"; - if (schemaTypeGUID != null) + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(relationshipGUID, relationshipGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + if (requestBody != null) + { + handler.deleteRelationship(userId, + null, + null, + relationshipGUID, + relationshipGUIDParameterName, + relationshipTypeName, + false, + false, + requestBody.getEffectiveTime(), + methodName); + } + else + { + handler.deleteRelationship(userId, + null, + null, + relationshipGUID, + relationshipGUIDParameterName, + relationshipTypeName, + false, + false, + null, + methodName); + } + } + catch (Exception error) { - handler.linkElementToElement(userId, - null, - null, - assetGUID, - assetGUIDParameterName, - OpenMetadataAPIMapper.ASSET_TYPE_NAME, - schemaTypeGUID, - schemaTypeGUIDParameterName, - OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, - false, - false, - OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_GUID, - OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_NAME, - (InstanceProperties) null, - null, - null, - new Date(), - methodName); + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); } - return schemaTypeGUID; + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; } /** - * Recursively navigate through the schema type loading up a new schema type builder to pass to the - * schemaTypeHandler. + * Retrieve the requested relationships linked from a specific element at end 2. * - * @param schemaType supplied schema type - * @param repositoryHelper repository helper for this server - * @param serviceName calling service name - * @param serverName this server instance - * @param methodName calling method + * @param serverName name of the server to route the request to + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param startFrom start position for results + * @param pageSize maximum number of results + * @param requestBody the time that the retrieved elements must be effective for (null for any time, new Date() for now) * - * @return schema type builder - * @throws InvalidParameterException invalid type in one of the schema types + * @return unique identifier and properties of the relationships or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - private SchemaTypeBuilder getSchemaTypeBuilder(SchemaTypeProperties schemaType, - OMRSRepositoryHelper repositoryHelper, - String serviceName, - String serverName, - String methodName) throws InvalidParameterException + public RelationshipElementsResponse getRelatedAssetsAtEnd2(String serverName, + String userId, + String relationshipTypeName, + String fromAssetGUID, + int startFrom, + int pageSize, + EffectiveTimeQueryRequestBody requestBody) { - String typeName = OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME; + final String methodName = "getRelatedAssetsAtEnd2"; - if (schemaType.getTypeName() != null) + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + RelationshipElementsResponse response = new RelationshipElementsResponse(); + AuditLog auditLog = null; + + try { - typeName = schemaType.getTypeName(); - } + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); - String typeGUID = invalidParameterHandler.validateTypeName(typeName, - OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, - serviceName, - methodName, - repositoryHelper); + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); - SchemaTypeBuilder schemaTypeBuilder = new SchemaTypeBuilder(schemaType.getQualifiedName(), - schemaType.getDisplayName(), - schemaType.getDescription(), - schemaType.getVersionNumber(), - schemaType.getIsDeprecated(), - schemaType.getAuthor(), - schemaType.getUsage(), - schemaType.getEncodingStandard(), - schemaType.getNamespace(), - schemaType.getAdditionalProperties(), - typeGUID, - typeName, - schemaType.getExtendedProperties(), - repositoryHelper, - serviceName, - serverName); + final String fromAssetGUIDParameterName = "fromAssetGUID"; + final String typeNameParameterName = "relationshipTypeName"; - return schemaTypeBuilder; - } + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(fromAssetGUID, fromAssetGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, + null, + instanceHandler.getServiceName(), + methodName, + handler.getRepositoryHelper()); - /** - * Create a schema attribute and attach it to the supplied parent schema type. This method has 3 parts to it. - * First to create the schema attribute. Then to link the schema attribute to its parent schema so that the attribute - * count value is visible as soon as possible. Finally, to determine the style of type for the attribute - is it directly linked or - * is it indirectly linked through a schema link entity - and create these elements. - * - * @param userId calling user - * @param serverName this server - * @param assetGUID anchor GUID for the new schema type - * @param schemaAttribute properties for the new attribute + List relationships; + if (requestBody != null) + { + relationships = handler.getAttachmentLinks(userId, + fromAssetGUID, + fromAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + relationshipTypeGUID, + relationshipTypeName, + null, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + 2, + false, + false, + startFrom, + pageSize, + requestBody.getEffectiveTime(), + methodName); + } + else + { + relationships = handler.getAttachmentLinks(userId, + fromAssetGUID, + fromAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + relationshipTypeGUID, + relationshipTypeName, + null, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + 2, + false, + false, + startFrom, + pageSize, + null, + methodName); + } + + if (relationships != null) + { + List relationshipElements = new ArrayList<>(); + + for (Relationship relationship : relationships) + { + relationshipElements.add(getRelationshipElement(relationship, handler.getRepositoryHelper(), serverName, methodName)); + } + + response.setElementList(relationshipElements); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Retrieve the relationships linked from a specific element at end 2 of the relationship. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param startFrom start position for results + * @param pageSize maximum number of results + * @param requestBody the time that the retrieved elements must be effective for (null for any time, new Date() for now) + * + * @return unique identifier and properties of the relationships or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public RelationshipElementsResponse getRelatedAssetsAtEnd1(String serverName, + String userId, + String relationshipTypeName, + String toAssetGUID, + int startFrom, + int pageSize, + EffectiveTimeQueryRequestBody requestBody) + { + final String methodName = "getRelatedAssetsAtEnd1"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + RelationshipElementsResponse response = new RelationshipElementsResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + + final String toAssetGUIDParameterName = "toAssetGUID"; + final String typeNameParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(toAssetGUID, toAssetGUIDParameterName, methodName); + invalidParameterHandler.validateName(relationshipTypeName, typeNameParameterName, methodName); + + String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, + null, + instanceHandler.getServiceName(), + methodName, + handler.getRepositoryHelper()); + + List relationships; + if (requestBody != null) + { + relationships = handler.getAttachmentLinks(userId, + toAssetGUID, + toAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + relationshipTypeGUID, + relationshipTypeName, + null, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + 1, + false, + false, + startFrom, + pageSize, + requestBody.getEffectiveTime(), + methodName); + } + else + { + relationships = handler.getAttachmentLinks(userId, + toAssetGUID, + toAssetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + relationshipTypeGUID, + relationshipTypeName, + null, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + 1, + false, + false, + startFrom, + pageSize, + null, + methodName); + } + + if (relationships != null) + { + List relationshipElements = new ArrayList<>(); + + for (Relationship relationship : relationships) + { + relationshipElements.add(getRelationshipElement(relationship, handler.getRepositoryHelper(), serverName, methodName)); + } + + response.setElementList(relationshipElements); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + + /** + * Concert an OMRS relationship into an Asset Manager's RelationshipElement. + * + * @param relationship retrieved relationship + * @param repositoryHelper utility methods * @param methodName calling method - * @return unique identifier for the schema type - * @throws InvalidParameterException one of the properties is invalid - * @throws UserNotAuthorizedException the calling user is not authorized to perform this request - * @throws PropertyServerException there was a problem in the repositories + * @return element to return + */ + private RelationshipElement getRelationshipElement(Relationship relationship, + OMRSRepositoryHelper repositoryHelper, + String serverName, + String methodName) throws PropertyServerException + { + RelationshipElement relationshipElement = null; + + if (relationship != null) + { + ElementHeaderConverter elementHeaderConverter = new ElementHeaderConverter<>(repositoryHelper, instanceHandler.getServiceName(), serverName); + + relationshipElement = new RelationshipElement(); + + relationshipElement.setRelationshipHeader(elementHeaderConverter.getNewBean(ElementHeader.class, relationship, methodName)); + relationshipElement.setEnd1GUID(elementHeaderConverter.getNewBean(ElementHeader.class, relationship.getEntityOneProxy(), methodName)); + relationshipElement.setEnd2GUID(elementHeaderConverter.getNewBean(ElementHeader.class, relationship.getEntityTwoProxy(), methodName)); + + if (relationship.getProperties() != null) + { + if (OpenMetadataAPIMapper.DATA_CONTENT_FOR_DATA_SET_TYPE_NAME.equals(relationship.getType().getTypeDefName())) + { + DataContentForDataSetProperties properties = new DataContentForDataSetProperties(); + + properties.setQueryId(repositoryHelper.getStringProperty(instanceHandler.getServiceName(), OpenMetadataAPIMapper.QUERY_ID_PROPERTY_NAME, relationship.getProperties(), methodName)); + properties.setQuery(repositoryHelper.getStringProperty(instanceHandler.getServiceName(), OpenMetadataAPIMapper.QUERY_PROPERTY_NAME, relationship.getProperties(), methodName)); + + properties.setEffectiveFrom(relationship.getProperties().getEffectiveFromTime()); + properties.setEffectiveTo(relationship.getProperties().getEffectiveFromTime()); + + relationshipElement.setRelationshipProperties(properties); + } + else + { + RelationshipProperties properties = new RelationshipProperties(); + + properties.setEffectiveFrom(relationship.getProperties().getEffectiveFromTime()); + properties.setEffectiveTo(relationship.getProperties().getEffectiveFromTime()); + + relationshipElement.setRelationshipProperties(properties); + } + } + } + + return relationshipElement; + } + + + + /** + * Stores the supplied schema details in the catalog and attaches it to the asset. If another schema is currently + * attached to the asset, it is unlinked and deleted. If more attributes need to be added in addition to the + * ones supplied then this can be done with addSchemaAttributesToSchemaType(). + * + * @param serverName name of the server instance to connect to + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param requestBody schema type to create and attach directly to the asset. + * + * @return guid of the schema type or + * InvalidParameterException full path or userId is null, or + * PropertyServerException problem accessing property server or + * UserNotAuthorizedException security access problem + */ + public GUIDResponse addCombinedSchemaToAsset(String serverName, + String userId, + String assetGUID, + CombinedSchemaRequestBody requestBody) + { + final String methodName = "addCombinedSchemaToAsset"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + GUIDResponse response = new GUIDResponse(); + AuditLog auditLog = null; + + try + { + if (requestBody != null) + { + if (requestBody.getSchemaType() != null) + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + response.setGUID(this.addAssociatedSchemaType(userId, + serverName, + assetGUID, + requestBody.getSchemaType(), + methodName)); + + + if (requestBody.getSchemaAttributes() != null) + { + for (SchemaAttributeProperties schemaAttributeProperties : requestBody.getSchemaAttributes()) + { + this.addAssociatedSchemaAttribute(userId, + serverName, + assetGUID, + response.getGUID(), + schemaAttributeProperties, + methodName); + } + } + } + else + { + final String parameterName = "requestBody.getSchemaType()"; + + restExceptionHandler.handleMissingValue(parameterName, methodName); + } + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + return response; + } + + + /** + * Stores the supplied schema type in the catalog and attaches it to the asset. If another schema is currently + * attached to the asset, it is unlinked and deleted. + * + * @param serverName name of the server instance to connect to + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param requestBody schema type to create and attach directly to the asset. + * + * @return guid of the new schema type or + * InvalidParameterException full path or userId is null, or + * PropertyServerException problem accessing property server or + * UserNotAuthorizedException security access problem + */ + public GUIDResponse addSchemaTypeToAsset(String serverName, + String userId, + String assetGUID, + SchemaTypeProperties requestBody) + { + final String methodName = "addSchemaTypeToAsset"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + GUIDResponse response = new GUIDResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + response.setGUID(this.addAssociatedSchemaType(userId, + serverName, + assetGUID, + requestBody, + methodName)); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + return response; + } + + + /** + * Request that the asset handler creates a schema type and links it to the asset. + * + * @param userId calling user + * @param serverName name of the server instance to connect to + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param schemaType properties for a schema type + * @param methodName calling method + * @return unique identifier of the newly created schema type + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException calling user is not permitted to perform this operation + * @throws PropertyServerException there was a problem in one of the repositories + */ + private String addAssociatedSchemaType(String userId, + String serverName, + String assetGUID, + SchemaTypeProperties schemaType, + String methodName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String assetGUIDParameterName = "assetGUID"; + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + SchemaTypeBuilder schemaTypeBuilder = getSchemaTypeBuilder(schemaType, + handler.getRepositoryHelper(), + handler.getServiceName(), + serverName, + methodName); + + if (assetGUID != null) + { + schemaTypeBuilder.setAnchors(userId, assetGUID, methodName); + } + + String schemaTypeGUID = handler.addSchemaType(userId, + null, + null, + schemaTypeBuilder, + null, + null, + false, + false, + new Date(), + methodName); + + if (schemaTypeGUID != null) + { + handler.linkElementToElement(userId, + null, + null, + assetGUID, + assetGUIDParameterName, + OpenMetadataAPIMapper.ASSET_TYPE_NAME, + schemaTypeGUID, + schemaTypeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + false, + false, + OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_GUID, + OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_NAME, + (InstanceProperties) null, + null, + null, + new Date(), + methodName); + } + + return schemaTypeGUID; + } + + + /** + * Recursively navigate through the schema type loading up a new schema type builder to pass to the + * schemaTypeHandler. + * + * @param schemaType supplied schema type + * @param repositoryHelper repository helper for this server + * @param serviceName calling service name + * @param serverName this server instance + * @param methodName calling method + * + * @return schema type builder + * @throws InvalidParameterException invalid type in one of the schema types + */ + private SchemaTypeBuilder getSchemaTypeBuilder(SchemaTypeProperties schemaType, + OMRSRepositoryHelper repositoryHelper, + String serviceName, + String serverName, + String methodName) throws InvalidParameterException + { + String typeName = OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME; + + if (schemaType.getTypeName() != null) + { + typeName = schemaType.getTypeName(); + } + + String typeGUID = invalidParameterHandler.validateTypeName(typeName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + serviceName, + methodName, + repositoryHelper); + + return new SchemaTypeBuilder(schemaType.getQualifiedName(), + schemaType.getDisplayName(), + schemaType.getDescription(), + schemaType.getVersionNumber(), + schemaType.getIsDeprecated(), + schemaType.getAuthor(), + schemaType.getUsage(), + schemaType.getEncodingStandard(), + schemaType.getNamespace(), + schemaType.getAdditionalProperties(), + typeGUID, + typeName, + schemaType.getExtendedProperties(), + repositoryHelper, + serviceName, + serverName); + } + + + /** + * Create a schema attribute and attach it to the supplied parent schema type. This method has 3 parts to it. + * First to create the schema attribute. Then to link the schema attribute to its parent schema so that the attribute + * count value is visible as soon as possible. Finally, to determine the style of type for the attribute - is it directly linked or + * is it indirectly linked through a schema link entity - and create these elements. + * + * @param userId calling user + * @param serverName this server + * @param assetGUID anchor GUID for the new schema type + * @param schemaAttribute properties for the new attribute + * @param methodName calling method + * @return unique identifier for the schema type + * @throws InvalidParameterException one of the properties is invalid + * @throws UserNotAuthorizedException the calling user is not authorized to perform this request + * @throws PropertyServerException there was a problem in the repositories + */ + private String addAssociatedSchemaAttribute(String userId, + String serverName, + String assetGUID, + String schemaTypeGUID, + SchemaAttributeProperties schemaAttribute, + String methodName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + SchemaAttributeHandler handler = + instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); + + String schemaAttributeGUID = null; + + if (schemaAttribute != null) + { + int sortOrder = DataItemSortOrder.UNKNOWN.getOpenTypeOrdinal(); + + if (schemaAttribute.getSortOrder() != null) + { + sortOrder = schemaAttribute.getSortOrder().getOpenTypeOrdinal(); + } + + SchemaAttributeBuilder schemaAttributeBuilder = + new SchemaAttributeBuilder(schemaAttribute.getQualifiedName(), + schemaAttribute.getDisplayName(), + schemaAttribute.getDescription(), + schemaAttribute.getElementPosition(), + schemaAttribute.getMinCardinality(), + schemaAttribute.getMaxCardinality(), + schemaAttribute.getIsDeprecated(), + schemaAttribute.getDefaultValueOverride(), + schemaAttribute.getAllowsDuplicateValues(), + schemaAttribute.getOrderedValues(), + sortOrder, + schemaAttribute.getMinimumLength(), + schemaAttribute.getLength(), + schemaAttribute.getPrecision(), + schemaAttribute.getIsNullable(), + schemaAttribute.getNativeJavaClass(), + schemaAttribute.getAliases(), + schemaAttribute.getAdditionalProperties(), + null, + schemaAttribute.getTypeName(), + schemaAttribute.getExtendedProperties(), + handler.getRepositoryHelper(), + handler.getServiceName(), + serverName); + + if (assetGUID != null) + { + schemaAttributeBuilder.setAnchors(userId, assetGUID, methodName); + } + + if (schemaAttribute.getAttributeType() != null) + { + SchemaTypeProperties schemaTypeProperties = schemaAttribute.getAttributeType(); + SchemaTypeBuilder attributeSchemaTypeBuilder = new SchemaTypeBuilder(schemaTypeProperties.getQualifiedName(), + schemaTypeProperties.getDisplayName(), + schemaTypeProperties.getDescription(), + schemaTypeProperties.getVersionNumber(), + schemaTypeProperties.getIsDeprecated(), + schemaTypeProperties.getAuthor(), + schemaTypeProperties.getUsage(), + schemaTypeProperties.getEncodingStandard(), + schemaTypeProperties.getNamespace(), + schemaTypeProperties.getAdditionalProperties(), + null, + schemaTypeProperties.getTypeName(), + schemaTypeProperties.getExtendedProperties(), + handler.getRepositoryHelper(), + handler.getServiceName(), + serverName); + + attributeSchemaTypeBuilder.setAnchors(userId, assetGUID, methodName); + schemaAttributeBuilder.setSchemaType(userId, attributeSchemaTypeBuilder, methodName); + + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + final String qualifiedNameParameterName = "schemaAttribute.getQualifiedName()"; + + schemaAttributeGUID = handler.createNestedSchemaAttribute(userId, + null, + null, + schemaTypeGUID, + schemaTypeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + OpenMetadataAPIMapper.TYPE_TO_ATTRIBUTE_RELATIONSHIP_TYPE_GUID, + OpenMetadataAPIMapper.TYPE_TO_ATTRIBUTE_RELATIONSHIP_TYPE_NAME, + schemaAttribute.getQualifiedName(), + qualifiedNameParameterName, + schemaAttributeBuilder, + null, + null, + false, + false, + new Date(), + methodName); + } + else + { + final String parameterName = "attribute schema type"; + + restExceptionHandler.handleMissingValue(parameterName, methodName); + } + } + + return schemaAttributeGUID; + } + + + /** + * Links the supplied schema type directly to the asset. If this schema is either not found, or + * already attached to an asset, then an error occurs. If another schema is currently + * attached to the asset, it is unlinked and deleted. + * + * @param serverName name of the server instance to connect to + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param schemaTypeGUID unique identifier of the schema type to attach + * @param requestBody null + * + * @return void or + * InvalidParameterException full path or userId or one of the GUIDs is null or + * PropertyServerException problem accessing property server or + * UserNotAuthorizedException security access problem + */ + @SuppressWarnings(value = "unused") + public VoidResponse attachSchemaTypeToAsset(String serverName, + String userId, + String assetGUID, + String schemaTypeGUID, + NullRequestBody requestBody) + { + final String assetGUIDParameterName = "assetGUID"; + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + final String methodName = "attachSchemaTypeToAsset"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + + handler.attachSchemaTypeToAsset(userId, + null, + null, + assetGUID, + assetGUIDParameterName, + schemaTypeGUID, + schemaTypeGUIDParameterName, + null, + null, + false, + false, + new Date(), + methodName); + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + return response; + } + + + /** + * Unlinks the schema from the asset but does not delete it. This means it can be reattached to a different asset. + * + * @param serverName name of the server instance to connect to + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param requestBody null + * + * @return guid of the schema type or + * InvalidParameterException full path or userId or one of the GUIDs is null or + * PropertyServerException problem accessing property server or + * UserNotAuthorizedException security access problem + */ + @SuppressWarnings(value = "unused") + public GUIDResponse detachSchemaTypeFromAsset(String serverName, + String userId, + String assetGUID, + NullRequestBody requestBody) + { + final String assetGUIDParameterName = "assetGUID"; + final String methodName = "detachSchemaTypeFromAsset"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + GUIDResponse response = new GUIDResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + + response.setGUID(handler.detachSchemaTypeFromAsset(userId, + null, + null, + assetGUID, + assetGUIDParameterName, + false, + false, + new Date(), + methodName)); + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + return response; + } + + + /** + * Detaches and deletes an asset's schema. + * + * @param serverName name of the server instance to connect to + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param requestBody null + * + * @return void or + * InvalidParameterException full path or userId is null, or + * PropertyServerException problem accessing property server or + * UserNotAuthorizedException security access problem + */ + @SuppressWarnings(value = "unused") + public VoidResponse deleteAssetSchemaType(String serverName, + String userId, + String assetGUID, + NullRequestBody requestBody) + { + final String assetGUIDParameterName = "assetGUID"; + final String methodName = "deleteAssetSchemaType"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + + handler.removeAssociatedSchemaType(userId, + null, + null, + assetGUID, + assetGUIDParameterName, + false, + false, + new Date(), + methodName); + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + return response; + } + + + + /* ===================================================================================================================== + * A schemaType describes the structure of a data asset, process or port + */ + + /** + * Create a new metadata element to represent a schema type. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param anchorGUID unique identifier of the intended anchor of the schema type + * @param requestBody properties about the schema type to store + * + * @return unique identifier of the new schema type or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public GUIDResponse createSchemaType(String serverName, + String userId, + String anchorGUID, + SchemaTypeProperties requestBody) + { + final String methodName = "createSchemaType"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + GUIDResponse response = new GUIDResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + final String propertiesParameterName = "schemaTypeProperties"; + final String qualifiedNameParameterName = "schemaTypeProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateObject(requestBody, propertiesParameterName, methodName); + invalidParameterHandler.validateName(requestBody.getQualifiedName(), qualifiedNameParameterName, methodName); + + SchemaTypeBuilder builder = this.getSchemaTypeBuilder(requestBody, + instanceHandler.getRepositoryHelper(userId, serverName, methodName), + instanceHandler.getServiceName(), + serverName, + methodName); + + builder.setEffectivityDates(requestBody.getEffectiveFrom(), requestBody.getEffectiveTo()); + + if (anchorGUID != null) + { + builder.setAnchors(userId, anchorGUID, methodName); + } + + response.setGUID(handler.addSchemaType(userId, + null, + null, + builder, + requestBody.getEffectiveFrom(), + requestBody.getEffectiveTo(), + false, + false, + null, + methodName)); + + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Create a new metadata element to represent a schema type using an existing metadata element as a template. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param templateGUID unique identifier of the metadata element to copy + * @param requestBody properties that override the template + * + * @return unique identifier of the new schema type or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public GUIDResponse createSchemaTypeFromTemplate(String serverName, + String userId, + String templateGUID, + TemplateRequestBody requestBody) + { + final String methodName = "createSchemaTypeFromTemplate"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + GUIDResponse response = new GUIDResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + final String templateGUIDParameterName = "templateGUID"; + final String propertiesParameterName = "templateProperties"; + final String qualifiedNameParameterName = "templateProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(templateGUID, templateGUIDParameterName, methodName); + invalidParameterHandler.validateObject(requestBody.getElementProperties(), propertiesParameterName, methodName); + invalidParameterHandler.validateName(requestBody.getElementProperties().getQualifiedName(), qualifiedNameParameterName, methodName); + + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + response.setGUID(handler.createSchemaTypeFromTemplate(userId, + null, + null, + templateGUID, + requestBody.getElementProperties().getQualifiedName(), + requestBody.getElementProperties().getDisplayName(), + requestBody.getElementProperties().getDescription(), + methodName)); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Update the metadata element representing a schema type. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the metadata element to update + * @param isMergeUpdate should the new properties be merged with existing properties (true) or completely replace them (false)? + * @param requestBody new properties for the metadata element + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public VoidResponse updateSchemaType(String serverName, + String userId, + String schemaTypeGUID, + boolean isMergeUpdate, + SchemaTypeProperties requestBody) + { + final String methodName = "updateSchemaType"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + final String propertiesParameterName = "schemaTypeProperties"; + final String qualifiedNameParameterName = "schemaTypeProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, schemaTypeGUIDParameterName, methodName); + invalidParameterHandler.validateObject(requestBody, propertiesParameterName, methodName); + invalidParameterHandler.validateName(requestBody.getQualifiedName(), qualifiedNameParameterName, methodName); + + SchemaTypeBuilder builder = this.getSchemaTypeBuilder(requestBody, + instanceHandler.getRepositoryHelper(userId, serverName, methodName), + instanceHandler.getServiceName(), + serverName, + methodName); + + handler.updateSchemaType(userId, + null, + null, + schemaTypeGUID, + schemaTypeGUIDParameterName, + builder, + isMergeUpdate, + false, + false, + null, + methodName); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Connect a schema type to a data asset, process or port. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public VoidResponse setupSchemaTypeParent(String serverName, + String userId, + String parentElementGUID, + String parentElementTypeName, + String schemaTypeGUID, + RelationshipRequestBody requestBody) + { + final String methodName = "setupSchemaTypeParent"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + if (requestBody.getProperties() != null) + { + handler.setupSchemaTypeParent(userId, + null, + null, + schemaTypeGUID, + parentElementGUID, + parentElementTypeName, + requestBody.getProperties().getEffectiveFrom(), + requestBody.getProperties().getEffectiveTo(), + false, + false, + null, + methodName); + } + else + { + handler.setupSchemaTypeParent(userId, + null, + null, + schemaTypeGUID, + parentElementGUID, + parentElementTypeName, + null, + null, + false, + false, + null, + methodName); + } + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Remove the relationship between a schema type and its parent data asset, process or port. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public VoidResponse clearSchemaTypeParent(String serverName, + String userId, + String parentElementGUID, + String parentElementTypeName, + String schemaTypeGUID, + EffectiveTimeQueryRequestBody requestBody) + { + final String methodName = "clearSchemaTypeParent"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + handler.clearSchemaTypeParent(userId, + null, + null, + schemaTypeGUID, + parentElementGUID, + parentElementTypeName, + false, + false, + null, + methodName); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Create a relationship between two schema elements. The name of the desired relationship, and any properties (including effectivity dates) + * are passed on the API. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to create + * @param requestBody relationship properties + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public VoidResponse setupSchemaElementRelationship(String serverName, + String userId, + String endOneGUID, + String relationshipTypeName, + String endTwoGUID, + RelationshipRequestBody requestBody) + { + final String methodName = "setupSchemaElementRelationship"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + if (requestBody != null) + { + if (requestBody.getProperties() != null) + { + handler.setupSchemaElementRelationship(userId, + null, + null, + endOneGUID, + endTwoGUID, + relationshipTypeName, + requestBody.getProperties().getExtendedProperties(), + requestBody.getProperties().getEffectiveFrom(), + requestBody.getProperties().getEffectiveTo(), + false, + false, + requestBody.getEffectiveTime(), + methodName); + } + else + { + handler.setupSchemaElementRelationship(userId, + null, + null, + endOneGUID, + endTwoGUID, + relationshipTypeName, + null, + null, + null, + false, + false, + requestBody.getEffectiveTime(), + methodName); + } + } + else + { + handler.setupSchemaElementRelationship(userId, + null, + null, + endOneGUID, + endTwoGUID, + relationshipTypeName, + null, + null, + null, + false, + false, + null, + methodName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Remove a relationship between two schema elements. The name of the desired relationship is passed on the API. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to delete + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public VoidResponse clearSchemaElementRelationship(String serverName, + String userId, + String endOneGUID, + String relationshipTypeName, + String endTwoGUID, + EffectiveTimeQueryRequestBody requestBody) + { + final String methodName = "clearSchemaElementRelationship"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + if (requestBody != null) + { + handler.clearSchemaElementRelationship(userId, + null, + null, + endTwoGUID, + endOneGUID, + relationshipTypeName, + false, + false, + requestBody.getEffectiveTime(), + methodName); + } + else + { + handler.clearSchemaElementRelationship(userId, + null, + null, + endTwoGUID, + endOneGUID, + relationshipTypeName, + false, + false, + null, + methodName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Remove the metadata element representing a schema type. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the metadata element to remove + * @param requestBody unique identifier/name of software server capability representing the caller and external identifier of element + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public VoidResponse removeSchemaType(String serverName, + String userId, + String schemaTypeGUID, + UpdateRequestBody requestBody) + { + final String methodName = "removeSchemaType"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + if (requestBody != null) + { + handler.deleteBeanInRepository(userId, + null, + null, + schemaTypeGUID, + schemaTypeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_GUID, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + null, + null, + false, + false, + requestBody.getEffectiveTime(), + methodName); + } + else + { + handler.deleteBeanInRepository(userId, + null, + null, + schemaTypeGUID, + schemaTypeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_GUID, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + null, + null, + false, + false, + null, + methodName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Retrieve the list of schema type metadata elements that contain the search string. + * The search string is treated as a regular expression. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody string to find in the properties plus external identifiers + * + * @return list of matching metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public SchemaTypeElementsResponse findSchemaType(String serverName, + String userId, + int startFrom, + int pageSize, + SearchStringRequestBody requestBody) + { + final String methodName = "findSchemaType"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + SchemaTypeElementsResponse response = new SchemaTypeElementsResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + response.setElementList(handler.findSchemaTypes(userId, + null, + requestBody.getSearchString(), + startFrom, + pageSize, + false, + false, + requestBody.getEffectiveTime(), + methodName)); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Return the schema type associated with a specific open metadata element (data asset, process or port). + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return metadata element describing the schema type associated with the requested parent element or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public SchemaTypeElementResponse getSchemaTypeForElement(String serverName, + String userId, + String parentElementGUID, + String parentElementTypeName, + EffectiveTimeQueryRequestBody requestBody) + { + final String methodName = "getSchemaTypeForElement"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + SchemaTypeElementResponse response = new SchemaTypeElementResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + response.setElement(handler.getSchemaTypeForElement(userId, + parentElementGUID, + parentElementTypeName, + false, + false, + null, + methodName)); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Retrieve the list of schema type metadata elements with a matching qualified or display name. + * There are no wildcards supported on this request. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody name to search for plus identifiers + * + * @return list of matching metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public SchemaTypeElementsResponse getSchemaTypeByName(String serverName, + String userId, + int startFrom, + int pageSize, + NameRequestBody requestBody) + { + final String methodName = "getSchemaTypeByName"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + SchemaTypeElementsResponse response = new SchemaTypeElementsResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + response.setElementList(handler.getSchemaTypeByName(userId, + null, + requestBody.getName(), + startFrom, + pageSize, + false, + false, + null, + methodName)); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Retrieve the schema type metadata element with the supplied unique identifier. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the requested metadata element + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return requested metadata element or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public SchemaTypeElementResponse getSchemaTypeByGUID(String serverName, + String userId, + String schemaTypeGUID, + EffectiveTimeQueryRequestBody requestBody) + { + final String methodName = "getSchemaTypeByGUID"; + final String guidParameterName = "schemaTypeGUID"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + SchemaTypeElementResponse response = new SchemaTypeElementResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + if (requestBody != null) + { + response.setElement(handler.getSchemaType(userId, + schemaTypeGUID, + guidParameterName, + false, + false, + requestBody.getEffectiveTime(), + methodName)); + } + else + { + response.setElement(handler.getSchemaType(userId, + schemaTypeGUID, + guidParameterName, + false, + false, + null, + methodName)); } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Retrieve the header of the metadata element connected to a schema type. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the requested metadata element + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return header for parent element (data asset, process, port) or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public ElementHeaderResponse getSchemaTypeParent(String serverName, + String userId, + String schemaTypeGUID, + EffectiveTimeQueryRequestBody requestBody) + { + final String methodName = "getSchemaTypeParent"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + ElementHeaderResponse response = new ElementHeaderResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaTypeHandler handler = instanceHandler.getSchemaTypeHandler(userId, serverName, methodName); + + final String guidParameterName = "schemaTypeGUID"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaTypeGUID, guidParameterName, methodName); + + OMRSRepositoryHelper repositoryHelper = handler.getRepositoryHelper(); + + RepositoryRelationshipsIterator iterator = new RepositoryRelationshipsIterator(handler.getRepositoryHandler(), + invalidParameterHandler, + userId, + schemaTypeGUID, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + null, + null, + 1, + false, + false, + 0, + invalidParameterHandler.getMaxPagingSize(), + requestBody.getEffectiveTime(), + methodName); + + while (iterator.moreToReceive()) + { + Relationship relationship = iterator.getNext(); + + if ((relationship != null) && (relationship.getType() != null) && + ((repositoryHelper.isTypeOf(handler.getServiceName(), + relationship.getType().getTypeDefName(), + OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_NAME)) || + (repositoryHelper.isTypeOf(handler.getServiceName(), + relationship.getType().getTypeDefName(), + OpenMetadataAPIMapper.PORT_SCHEMA_RELATIONSHIP_TYPE_NAME)))) + { + final String parentGUIDParameterName = "relationship.getEntityOneProxy().getGUID()"; + + EntityDetail parentEntity = handler.getEntityFromRepository(userId, + relationship.getEntityOneProxy().getGUID(), + parentGUIDParameterName, + OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME, + null, + null, + false, + false, + requestBody.getEffectiveTime(), + methodName); + + ElementHeaderConverter headerConverter = new ElementHeaderConverter<>(repositoryHelper, handler.getServiceName(), serverName); + response.setElement(headerConverter.getNewBean(ElementHeader.class, parentEntity, methodName)); + } + } + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /* =============================================================================== + * A schemaType typically contains many schema attributes, linked with relationships. + */ + + + /** + * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. + * This method can be called repeatedly to add many attributes to a schema. + * The schema type may be attached both directly or indirectly via nested schema elements to the asset. + * + * @param serverName name of the server instance to connect to + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param parentGUID unique identifier of the schema element to anchor these attributes to. + * @param requestBody list of schema attribute objects. + * + * @return list of unique identifier for the new schema attribute returned in the same order as the supplied attribute or + * InvalidParameterException full path or userId is null or + * PropertyServerException problem accessing property server or + * UserNotAuthorizedException security access problem */ - private String addAssociatedSchemaAttribute(String userId, - String serverName, - String assetGUID, - String schemaTypeGUID, - SchemaAttributeProperties schemaAttribute, - String methodName) throws InvalidParameterException, - UserNotAuthorizedException, - PropertyServerException + public VoidResponse addSchemaAttributes(String serverName, + String userId, + String assetGUID, + String parentGUID, + List requestBody) { - SchemaAttributeHandler handler = - instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); + final String methodName = "addSchemaAttributes"; + final String schemaElementGUIDParameterName = "parentGUID"; + final String qualifiedNameParameterName = "qualifiedName"; - String schemaAttributeGUID = null; + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); - if (schemaAttribute != null) + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try { - int sortOrder = DataItemSortOrder.UNKNOWN.getOpenTypeOrdinal(); + if ((requestBody != null) && (! requestBody.isEmpty())) + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); - if (schemaAttribute.getSortOrder() != null) + for (SchemaAttributeProperties schemaAttributeProperties : requestBody) + { + SchemaAttributeBuilder schemaAttributeBuilder = this.getSchemaAttributeBuilder(userId, + schemaAttributeProperties, + handler.getRepositoryHelper(), + handler.getServerName(), + methodName); + + if (assetGUID != null) + { + schemaAttributeBuilder.setAnchors(userId, assetGUID, methodName); + } + + handler.createNestedSchemaAttribute(userId, + null, + null, + parentGUID, + schemaElementGUIDParameterName, + schemaAttributeProperties.getQualifiedName(), + qualifiedNameParameterName, + schemaAttributeBuilder, + schemaAttributeProperties.getEffectiveFrom(), + schemaAttributeProperties.getEffectiveTo(), + false, + false, + null, + methodName); + } + } + else { - sortOrder = schemaAttribute.getSortOrder().getOpenTypeOrdinal(); + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } - SchemaAttributeBuilder schemaAttributeBuilder = - new SchemaAttributeBuilder(schemaAttribute.getQualifiedName(), - schemaAttribute.getDisplayName(), - schemaAttribute.getDescription(), - schemaAttribute.getElementPosition(), - schemaAttribute.getMinCardinality(), - schemaAttribute.getMaxCardinality(), - schemaAttribute.getIsDeprecated(), - schemaAttribute.getDefaultValueOverride(), - schemaAttribute.getAllowsDuplicateValues(), - schemaAttribute.getOrderedValues(), - sortOrder, - schemaAttribute.getMinimumLength(), - schemaAttribute.getLength(), - schemaAttribute.getPrecision(), - schemaAttribute.getIsNullable(), - schemaAttribute.getNativeJavaClass(), - schemaAttribute.getAliases(), - schemaAttribute.getAdditionalProperties(), - null, - schemaAttribute.getTypeName(), - schemaAttribute.getExtendedProperties(), - handler.getRepositoryHelper(), - handler.getServiceName(), - serverName); + restCallLogger.logRESTCallReturn(token, response.toString()); + return response; + } - if (assetGUID != null) + + /** + * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. + * This method can be called repeatedly to add many attributes to a schema. + * The schema type may be attached both directly or indirectly via nested schema elements to the asset. + * + * @param serverName name of the server instance to connect to + * @param userId calling user + * @param assetGUID unique identifier of the asset that the schema is to be attached to + * @param parentGUID unique identifier of the schema element to anchor these attributes to. + * @param requestBody schema attribute object. + * + * @return list of unique identifiers for the new schema attributes returned in the same order as the supplied attribute or + * InvalidParameterException full path or userId is null or + * PropertyServerException problem accessing property server or + * UserNotAuthorizedException security access problem + */ + public GUIDResponse addSchemaAttribute(String serverName, + String userId, + String assetGUID, + String parentGUID, + SchemaAttributeProperties requestBody) + { + final String methodName = "addSchemaAttribute"; + final String schemaElementGUIDParameterName = "parentGUID"; + final String qualifiedNameParameterName = "qualifiedName"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + GUIDResponse response = new GUIDResponse(); + AuditLog auditLog = null; + + try + { + if (requestBody != null) { - schemaAttributeBuilder.setAnchors(userId, assetGUID, methodName); + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); + + SchemaAttributeBuilder schemaAttributeBuilder = this.getSchemaAttributeBuilder(userId, + requestBody, + handler.getRepositoryHelper(), + handler.getServerName(), + methodName); + + if (assetGUID != null) + { + schemaAttributeBuilder.setAnchors(userId, assetGUID, methodName); + } + + response.setGUID(handler.createNestedSchemaAttribute(userId, + null, + null, + parentGUID, + schemaElementGUIDParameterName, + requestBody.getQualifiedName(), + qualifiedNameParameterName, + schemaAttributeBuilder, + requestBody.getEffectiveFrom(), + requestBody.getEffectiveTo(), + false, + false, + null, + methodName)); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } - if (schemaAttribute.getAttributeType() != null) + restCallLogger.logRESTCallReturn(token, response.toString()); + return response; + } + + + /** + * Create a new metadata element to represent a schema attribute using an existing metadata element as a template. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaElementGUID unique identifier of the schemaType or Schema Attribute where the schema attribute is connected to + * @param templateGUID unique identifier of the metadata element to copy + * @param requestBody properties that override the template + * + * @return unique identifier of the new metadata element for the schema attribute or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public GUIDResponse createSchemaAttributeFromTemplate(String serverName, + String userId, + String schemaElementGUID, + String templateGUID, + TemplateRequestBody requestBody) + { + final String methodName = "createSchemaAttributeFromTemplate"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + GUIDResponse response = new GUIDResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) { - SchemaTypeProperties schemaTypeProperties = schemaAttribute.getAttributeType(); - SchemaTypeBuilder attributeSchemaTypeBuilder = new SchemaTypeBuilder(schemaTypeProperties.getQualifiedName(), - schemaTypeProperties.getDisplayName(), - schemaTypeProperties.getDescription(), - schemaTypeProperties.getVersionNumber(), - schemaTypeProperties.getIsDeprecated(), - schemaTypeProperties.getAuthor(), - schemaTypeProperties.getUsage(), - schemaTypeProperties.getEncodingStandard(), - schemaTypeProperties.getNamespace(), - schemaTypeProperties.getAdditionalProperties(), - null, - schemaTypeProperties.getTypeName(), - schemaTypeProperties.getExtendedProperties(), - handler.getRepositoryHelper(), - handler.getServiceName(), - serverName); + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); + + final String schemaElementGUIDParameterName = "schemaElementGUID"; + final String templateGUIDParameterName = "templateGUID"; + final String propertiesParameterName = "templateProperties"; + final String qualifiedNameParameterName = "templateProperties.qualifiedName"; + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaElementGUID, schemaElementGUIDParameterName, methodName); + invalidParameterHandler.validateGUID(templateGUID, templateGUIDParameterName, methodName); + invalidParameterHandler.validateObject(requestBody.getElementProperties(), propertiesParameterName, methodName); + invalidParameterHandler.validateName(requestBody.getElementProperties().getQualifiedName(), qualifiedNameParameterName, methodName); + + + response.setGUID(handler.createSchemaAttributeFromTemplate(userId, + null, + null, + schemaElementGUID, + schemaElementGUIDParameterName, + templateGUID, + requestBody.getElementProperties().getQualifiedName(), + requestBody.getElementProperties().getDisplayName(), + requestBody.getElementProperties().getDescription(), + false, + false, + null, + methodName)); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } - attributeSchemaTypeBuilder.setAnchors(userId, assetGUID, methodName); - schemaAttributeBuilder.setSchemaType(userId, attributeSchemaTypeBuilder, methodName); + restCallLogger.logRESTCallReturn(token, response.toString()); - final String schemaTypeGUIDParameterName = "schemaTypeGUID"; - final String qualifiedNameParameterName = "schemaAttribute.getQualifiedName()"; + return response; + } - schemaAttributeGUID = handler.createNestedSchemaAttribute(userId, - null, - null, - schemaTypeGUID, - schemaTypeGUIDParameterName, - OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, - OpenMetadataAPIMapper.TYPE_TO_ATTRIBUTE_RELATIONSHIP_TYPE_GUID, - OpenMetadataAPIMapper.TYPE_TO_ATTRIBUTE_RELATIONSHIP_TYPE_NAME, - schemaAttribute.getQualifiedName(), - qualifiedNameParameterName, - schemaAttributeBuilder, - null, - null, - false, - false, - new Date(), - methodName); + + /** + * Update the properties of the metadata element representing a schema attribute. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the schema attribute to update + * @param isMergeUpdate should the new properties be merged with existing properties (true) or completely replace them (false)? + * @param requestBody new properties for the schema attribute + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public VoidResponse updateSchemaAttribute(String serverName, + String userId, + String schemaAttributeGUID, + boolean isMergeUpdate, + SchemaAttributeProperties requestBody) + { + final String methodName = "updateSchemaAttribute"; + final String qualifiedNameParameterName = "schemaAttributeProperties.qualifiedName"; + final String propertiesParameterName = "schemaAttributeProperties"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + VoidResponse response = new VoidResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); + + invalidParameterHandler.validateUserId(userId, methodName); + invalidParameterHandler.validateGUID(schemaAttributeGUID, schemaAttributeGUIDParameterName, methodName); + invalidParameterHandler.validateObject(requestBody, propertiesParameterName, methodName); + if (! isMergeUpdate) + { + invalidParameterHandler.validateName(requestBody.getQualifiedName(), qualifiedNameParameterName, methodName); + } + + SchemaAttributeBuilder schemaAttributeBuilder = this.getSchemaAttributeBuilder(userId, + requestBody, + handler.getRepositoryHelper(), + serverName, + methodName); + handler.updateSchemaAttribute(userId, + null, + null, + schemaAttributeGUID, + schemaAttributeGUIDParameterName, + requestBody.getQualifiedName(), + qualifiedNameParameterName, + schemaAttributeBuilder, + schemaAttributeBuilder.getTypeName(), + isMergeUpdate, + false, + false, + null, + methodName); } else { - final String parameterName = "attribute schema type"; + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } + + + /** + * Return a schema attribute builder packed with the knowledge of the schema attribute from the schema attribute properties + * + * @param userId calling user + * @param schemaAttributeProperties properties from the caller + * @param repositoryHelper utility methods + * @param serverName name of called server + * @param methodName calling method + * + * @return schema attributes properties in a builder + * @throws InvalidParameterException schema type is invalid + */ + private SchemaAttributeBuilder getSchemaAttributeBuilder(String userId, + SchemaAttributeProperties schemaAttributeProperties, + OMRSRepositoryHelper repositoryHelper, + String serverName, + String methodName) throws InvalidParameterException + { + String typeName = OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_NAME; - restExceptionHandler.handleMissingValue(parameterName, methodName); - } + if (schemaAttributeProperties.getTypeName() != null) + { + typeName = schemaAttributeProperties.getTypeName(); } - return schemaAttributeGUID; + String typeGUID = invalidParameterHandler.validateTypeName(typeName, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_NAME, + instanceHandler.getServiceName(), + methodName, + repositoryHelper); + + int sortOrder = 0; + if (schemaAttributeProperties.getSortOrder() != null) + { + sortOrder = schemaAttributeProperties.getSortOrder().getOpenTypeOrdinal(); + } + + SchemaAttributeBuilder schemaAttributeBuilder = new SchemaAttributeBuilder(schemaAttributeProperties.getQualifiedName(), + schemaAttributeProperties.getDisplayName(), + schemaAttributeProperties.getDescription(), + schemaAttributeProperties.getElementPosition(), + schemaAttributeProperties.getMinCardinality(), + schemaAttributeProperties.getMaxCardinality(), + schemaAttributeProperties.getIsDeprecated(), + schemaAttributeProperties.getDefaultValueOverride(), + schemaAttributeProperties.getAllowsDuplicateValues(), + schemaAttributeProperties.getOrderedValues(), + sortOrder, + schemaAttributeProperties.getMinimumLength(), + schemaAttributeProperties.getLength(), + schemaAttributeProperties.getPrecision(), + schemaAttributeProperties.getIsNullable(), + schemaAttributeProperties.getNativeJavaClass(), + schemaAttributeProperties.getAliases(), + schemaAttributeProperties.getAdditionalProperties(), + typeGUID, + typeName, + schemaAttributeProperties.getExtendedProperties(), + repositoryHelper, + instanceHandler.getServiceName(), + serverName); + + if (schemaAttributeProperties.getAttributeType() != null) + { + SchemaTypeBuilder schemaTypeBuilder = this.getSchemaTypeBuilder(schemaAttributeProperties.getAttributeType(), + repositoryHelper, + instanceHandler.getServiceName(), + serverName, + methodName); + + schemaAttributeBuilder.setSchemaType(userId, schemaTypeBuilder, methodName); + } + + return schemaAttributeBuilder; } /** - * Links the supplied schema type directly to the asset. If this schema is either not found, or - * already attached to an asset, then an error occurs. If another schema is currently - * attached to the asset, it is unlinked and deleted. + * Classify the schema type (or attribute if type is embedded) to indicate that it is a calculated value. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param schemaTypeGUID unique identifier of the schema type to attach - * @param requestBody null + * @param schemaElementGUID unique identifier of the metadata element to update + * @param requestBody unique identifier/name of software server capability representing the caller and external identifier of element * * @return void or - * InvalidParameterException full path or userId or one of the GUIDs is null or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - @SuppressWarnings(value = "unused") - public VoidResponse attachSchemaTypeToAsset(String serverName, - String userId, - String assetGUID, - String schemaTypeGUID, - NullRequestBody requestBody) + public VoidResponse setSchemaElementAsCalculatedValue(String serverName, + String userId, + String schemaElementGUID, + CalculatedValueClassificationRequestBody requestBody) { - final String assetGUIDParameterName = "assetGUID"; - final String schemaTypeGUIDParameterName = "schemaTypeGUID"; - final String methodName = "attachSchemaTypeToAsset"; + final String methodName = "setSchemaElementAsCalculatedValue"; + final String schemaElementGUIDParameterName = "schemaElementGUID"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); @@ -880,21 +3051,48 @@ public VoidResponse attachSchemaTypeToAsset(String serverName, { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); - AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); - handler.attachSchemaTypeToAsset(userId, - null, - null, - assetGUID, - assetGUIDParameterName, - schemaTypeGUID, - schemaTypeGUIDParameterName, - null, - null, - false, - false, - new Date(), - methodName); + + if (requestBody != null) + { + InstanceProperties properties = instanceHandler.getRepositoryHelper(userId, serverName, methodName).addStringPropertyToInstance(instanceHandler.getServiceName(), + null, + OpenMetadataAPIMapper.FORMULA_PROPERTY_NAME, + requestBody.getFormula(), + methodName); + handler.setClassificationInRepository(userId, + null, + null, + schemaElementGUID, + schemaElementGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + OpenMetadataAPIMapper.CALCULATED_VALUE_CLASSIFICATION_TYPE_NAME, + OpenMetadataAPIMapper.CALCULATED_VALUE_CLASSIFICATION_TYPE_GUID, + properties, + false, + false, + false, + requestBody.getEffectiveTime(), + methodName); + } + else + { + handler.setClassificationInRepository(userId, + null, + null, + schemaElementGUID, + schemaElementGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + OpenMetadataAPIMapper.CALCULATED_VALUE_CLASSIFICATION_TYPE_NAME, + OpenMetadataAPIMapper.CALCULATED_VALUE_CLASSIFICATION_TYPE_GUID, + null, + false, + false, + false, + null, + methodName); + } } catch (Exception error) { @@ -902,52 +3100,72 @@ public VoidResponse attachSchemaTypeToAsset(String serverName, } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } /** - * Unlinks the schema from the asset but does not delete it. This means it can be reattached to a different asset. + * Remove the calculated value designation from the schema element. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param requestBody null + * @param schemaElementGUID unique identifier of the metadata element to update + * @param requestBody unique identifier/name of software server capability representing the caller and external identifier of element * - * @return guid of the schema type or - * InvalidParameterException full path or userId or one of the GUIDs is null or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - @SuppressWarnings(value = "unused") - public GUIDResponse detachSchemaTypeFromAsset(String serverName, - String userId, - String assetGUID, - NullRequestBody requestBody) + public VoidResponse clearSchemaElementAsCalculatedValue(String serverName, + String userId, + String schemaElementGUID, + UpdateRequestBody requestBody) { - final String assetGUIDParameterName = "assetGUID"; - final String methodName = "detachSchemaTypeFromAsset"; + final String methodName = "clearSchemaElementAsCalculatedValue"; + final String schemaElementGUIDParameterName = "schemaElementGUID"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); - GUIDResponse response = new GUIDResponse(); + VoidResponse response = new VoidResponse(); AuditLog auditLog = null; try { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); - AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); - - response.setGUID(handler.detachSchemaTypeFromAsset(userId, - null, - null, - assetGUID, - assetGUIDParameterName, - false, - false, - new Date(), - methodName)); + if (requestBody != null) + { + handler.removeClassificationFromRepository(userId, + null, + null, + schemaElementGUID, + schemaElementGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + OpenMetadataAPIMapper.CALCULATED_VALUE_CLASSIFICATION_TYPE_GUID, + OpenMetadataAPIMapper.CALCULATED_VALUE_CLASSIFICATION_TYPE_NAME, + false, + false, + requestBody.getEffectiveTime(), + methodName); + } + else + { + handler.removeClassificationFromRepository(userId, + null, + null, + schemaElementGUID, + schemaElementGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + OpenMetadataAPIMapper.CALCULATED_VALUE_CLASSIFICATION_TYPE_GUID, + OpenMetadataAPIMapper.CALCULATED_VALUE_CLASSIFICATION_TYPE_NAME, + false, + false, + null, + methodName); + } } catch (Exception error) { @@ -955,31 +3173,30 @@ public GUIDResponse detachSchemaTypeFromAsset(String serverName, } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } /** - * Detaches and deletes an asset's schema. + * Remove the metadata element representing a schema attribute. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param requestBody null + * @param schemaAttributeGUID unique identifier of the metadata element to remove + * @param requestBody unique identifier/name of software server capability representing the caller and external identifier of element * * @return void or - * InvalidParameterException full path or userId is null, or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - @SuppressWarnings(value = "unused") - public VoidResponse deleteAssetSchemaType(String serverName, - String userId, - String assetGUID, - NullRequestBody requestBody) + public VoidResponse removeSchemaAttribute(String serverName, + String userId, + String schemaAttributeGUID, + UpdateRequestBody requestBody) { - final String assetGUIDParameterName = "assetGUID"; - final String methodName = "deleteAssetSchemaType"; + final String methodName = "removeSchemaAttribute"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); @@ -990,17 +3207,28 @@ public VoidResponse deleteAssetSchemaType(String serverName, { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); - AssetHandler handler = instanceHandler.getAssetHandler(userId, serverName, methodName); + if (requestBody != null) + { + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); - handler.removeAssociatedSchemaType(userId, + handler.deleteBeanInRepository(userId, + null, + null, + schemaAttributeGUID, + schemaAttributeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_GUID, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_NAME, null, null, - assetGUID, - assetGUIDParameterName, false, false, - new Date(), + null, methodName); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } } catch (Exception error) { @@ -1008,56 +3236,61 @@ public VoidResponse deleteAssetSchemaType(String serverName, } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } /** - * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. - * This method can be called repeatedly to add many attributes to a schema. - * The schema type may be attached both directly or indirectly via nested schema elements to the asset. + * Retrieve the list of schema attribute metadata elements that contain the search string. + * The search string is treated as a regular expression. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param parentGUID unique identifier of the schema element to anchor these attributes to. - * @param requestBody list of schema attribute objects. + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody string to find in the properties plus external identifiers * - * @return list of unique identifiers for the new schema attributes returned in the same order as the supplied attribute or - * InvalidParameterException full path or userId is null or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return list of matching metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - public VoidResponse addSchemaAttributes(String serverName, - String userId, - String assetGUID, - String parentGUID, - SchemaAttributesRequestBody requestBody) + public SchemaAttributeElementsResponse findSchemaAttributes(String serverName, + String userId, + int startFrom, + int pageSize, + SearchStringRequestBody requestBody) { - final String methodName = "addSchemaAttributes"; + final String methodName = "findSchemaAttributes"; + final String searchStringParameterName = "searchString"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); - VoidResponse response = new VoidResponse(); - AuditLog auditLog = null; + SchemaAttributeElementsResponse response = new SchemaAttributeElementsResponse(); + AuditLog auditLog = null; try { - if ((requestBody != null) - && (requestBody.getSchemaAttributeProperties() != null) - && (! requestBody.getSchemaAttributeProperties().isEmpty())) - { - auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); - for (SchemaAttributeProperties schemaAttributeProperties : requestBody.getSchemaAttributeProperties()) - { - this.addAssociatedSchemaAttribute(userId, - serverName, - assetGUID, - parentGUID, - schemaAttributeProperties, - methodName); - } + if (requestBody != null) + { + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); + + response.setElementList(handler.findSchemaAttributes(userId, + requestBody.getSearchString(), + searchStringParameterName, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_GUID, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_NAME, + null, + null, + startFrom, + pageSize, + false, + false, + null, + methodName)); } else { @@ -1070,54 +3303,59 @@ public VoidResponse addSchemaAttributes(String serverName, } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } /** - * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. - * This method can be called repeatedly to add many attributes to a schema. - * The schema type may be attached both directly or indirectly via nested schema elements to the asset. + * Retrieve the list of schema attributes associated with a schemaType. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param parentGUID unique identifier of the schema element to anchor these attributes to. - * @param requestBody list of schema attribute objects. + * @param schemaTypeGUID unique identifier of the schemaType of interest + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody unique identifier/name of software server capability representing the caller * - * @return list of unique identifiers for the new schema attributes returned in the same order as the supplied attribute or - * InvalidParameterException full path or userId is null or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return list of associated metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - public VoidResponse addSchemaAttributes(String serverName, - String userId, - String assetGUID, - String parentGUID, - List requestBody) + public SchemaAttributeElementsResponse getNestedAttributes(String serverName, + String userId, + String schemaTypeGUID, + int startFrom, + int pageSize, + EffectiveTimeQueryRequestBody requestBody) { - final String methodName = "addSchemaAttributes"; + final String methodName = "getNestedAttributes"; + final String elementGUIDParameterName = "schemaAttributeGUID"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); - VoidResponse response = new VoidResponse(); - AuditLog auditLog = null; + SchemaAttributeElementsResponse response = new SchemaAttributeElementsResponse(); + AuditLog auditLog = null; try { - if ((requestBody != null) && (! requestBody.isEmpty())) - { - auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); - for (SchemaAttributeProperties schemaAttributeProperties : requestBody) - { - this.addAssociatedSchemaAttribute(userId, - serverName, - assetGUID, - parentGUID, - schemaAttributeProperties, - methodName); - } + if (requestBody != null) + { + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); + + response.setElementList(handler.getAttachedSchemaAttributes(userId, + schemaTypeGUID, + elementGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_NAME, + startFrom, + pageSize, + false, + false, + null, + methodName)); } else { @@ -1130,51 +3368,59 @@ public VoidResponse addSchemaAttributes(String serverNa } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } /** - * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. - * This method can be called repeatedly to add many attributes to a schema. - * The schema type may be attached both directly or indirectly via nested schema elements to the asset. + * Retrieve the list of schema attribute metadata elements with a matching qualified or display name. + * There are no wildcards supported on this request. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param parentGUID unique identifier of the schema element to anchor these attributes to. - * @param requestBody schema attribute object. + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody unique identifier/name of software server capability representing the caller * - * @return list of unique identifiers for the new schema attributes returned in the same order as the supplied attribute or - * InvalidParameterException full path or userId is null or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return list of matching metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - public GUIDResponse addSchemaAttribute(String serverName, - String userId, - String assetGUID, - String parentGUID, - SchemaAttributeProperties requestBody) + public SchemaAttributeElementsResponse getSchemaAttributesByName(String serverName, + String userId, + int startFrom, + int pageSize, + NameRequestBody requestBody) { - final String methodName = "addSchemaAttribute"; + final String methodName = "getSchemaAttributesByName"; RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); - GUIDResponse response = new GUIDResponse(); - AuditLog auditLog = null; + SchemaAttributeElementsResponse response = new SchemaAttributeElementsResponse(); + AuditLog auditLog = null; try { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + if (requestBody != null) { - auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); - response.setGUID(this.addAssociatedSchemaAttribute(userId, - serverName, - assetGUID, - parentGUID, - requestBody, - methodName)); + response.setElementList(handler.getSchemaAttributesByName(userId, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_GUID, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_NAME, + requestBody.getName(), + null, + null, + startFrom, + pageSize, + false, + false, + null, + methodName)); } else { @@ -1187,10 +3433,70 @@ public GUIDResponse addSchemaAttribute(String serverName, } restCallLogger.logRESTCallReturn(token, response.toString()); + return response; } + /** + * Retrieve the schema attribute metadata element with the supplied unique identifier. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the requested metadata element + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return matching metadata element or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + public SchemaAttributeElementResponse getSchemaAttributeByGUID(String serverName, + String userId, + String schemaAttributeGUID, + EffectiveTimeQueryRequestBody requestBody) + { + final String methodName = "getSchemaAttributeByGUID"; + final String guidParameterName = "schemaAttributeGUID"; + + RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName); + + SchemaAttributeElementResponse response = new SchemaAttributeElementResponse(); + AuditLog auditLog = null; + + try + { + auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); + + if (requestBody != null) + { + SchemaAttributeHandler handler = instanceHandler.getSchemaAttributeHandler(userId, serverName, methodName); + + response.setElement(handler.getSchemaAttribute(userId, + schemaAttributeGUID, + guidParameterName, + OpenMetadataAPIMapper.SCHEMA_ATTRIBUTE_TYPE_NAME, + null, + null, + false, + false, + null, + methodName)); + } + else + { + restExceptionHandler.handleNoRequestBody(userId, methodName, serverName); + } + } + catch (Exception error) + { + restExceptionHandler.captureExceptions(response, error, methodName, auditLog); + } + + restCallLogger.logRESTCallReturn(token, response.toString()); + + return response; + } /** @@ -2608,7 +4914,6 @@ public AnnotationListResponse getExtendedAnnotations(String serverNa /** * Deletes an asset and all of its associated elements such as schema, connections (unless they are linked to * another asset), discovery reports and associated feedback. - * * Given the depth of the delete request performed by this call, it should be used with care. * * @param serverName name of the server instance to connect to diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/CertificationRESTServices.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/CertificationRESTServices.java index ea081eb0bef..7e1c58f9211 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/CertificationRESTServices.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/CertificationRESTServices.java @@ -308,17 +308,15 @@ public GUIDResponse certifyElement(String serverName, { if (requestBody != null) { - if (requestBody.getProperties() instanceof CertificationProperties) + if (requestBody.getProperties() instanceof CertificationProperties properties) { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); CertificationHandler handler = instanceHandler.getCertificationTypeHandler(userId, serverName, methodName); - CertificationProperties properties = (CertificationProperties) requestBody.getProperties(); - response.setGUID(handler.certifyElement(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, elementGUID, elementGUIDParameterName, OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME, @@ -399,17 +397,15 @@ public VoidResponse updateCertification(String serverName, { if (requestBody != null) { - if (requestBody.getProperties() instanceof CertificationProperties) + if (requestBody.getProperties() instanceof CertificationProperties properties) { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); CertificationHandler handler = instanceHandler.getCertificationTypeHandler(userId, serverName, methodName); - CertificationProperties properties = (CertificationProperties) requestBody.getProperties(); - handler.updateCertification(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, certificationGUID, certificationGUIDParameterName, properties.getCertificateId(), @@ -486,30 +482,15 @@ public VoidResponse decertifyElement(String serverName, auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); CertificationHandler handler = instanceHandler.getCertificationTypeHandler(userId, serverName, methodName); - if (requestBody != null) - { - handler.decertifyElement(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), - certificationGUID, - certificationGUIDParameterName, - false, - false, - new Date(), - methodName); - } - else - { - handler.decertifyElement(userId, - null, - null, - certificationGUID, - certificationGUIDParameterName, - false, - false, - new Date(), - methodName); - } + handler.decertifyElement(userId, + null, + null, + certificationGUID, + certificationGUIDParameterName, + false, + false, + new Date(), + methodName); } catch (Exception error) { diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/ExternalReferenceRESTServices.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/ExternalReferenceRESTServices.java index cfcc2fcfb33..fbc804f2337 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/ExternalReferenceRESTServices.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/ExternalReferenceRESTServices.java @@ -77,13 +77,11 @@ public GUIDResponse createExternalReference(String serverNa { if (requestBody != null) { - if (requestBody.getProperties() instanceof ExternalReferenceProperties) + if (requestBody.getProperties() instanceof ExternalReferenceProperties properties) { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); ExternalReferenceHandler handler = instanceHandler.getExternalReferencesHandler(userId, serverName, methodName); - ExternalReferenceProperties properties = (ExternalReferenceProperties) requestBody.getProperties(); - response.setGUID(handler.createExternalReference(userId, null, null, @@ -154,13 +152,11 @@ public VoidResponse updateExternalReference(String serverNa { if (requestBody != null) { - if (requestBody.getProperties() instanceof ExternalReferenceProperties) + if (requestBody.getProperties() instanceof ExternalReferenceProperties properties) { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); ExternalReferenceHandler handler = instanceHandler.getExternalReferencesHandler(userId, serverName, methodName); - ExternalReferenceProperties properties = (ExternalReferenceProperties) requestBody.getProperties(); - handler.updateExternalReference(userId, null, null, @@ -306,11 +302,10 @@ public VoidResponse linkExternalReferenceToElement(String serve if (requestBody != null) { - if (requestBody.getProperties() instanceof ExternalReferenceLinkProperties) + if (requestBody.getProperties() instanceof ExternalReferenceLinkProperties properties) { OMRSRepositoryHelper repositoryHelper = instanceHandler.getRepositoryHelper(userId, serverName, methodName); String serviceName = instanceHandler.getServiceName(); - ExternalReferenceLinkProperties properties = (ExternalReferenceLinkProperties)requestBody.getProperties(); InstanceProperties relationshipProperties = repositoryHelper.addStringPropertyToInstance(serviceName, null, @@ -331,8 +326,8 @@ public VoidResponse linkExternalReferenceToElement(String serve methodName); handler.linkElementToElement(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, attachedToGUID, elementGUIDParameterName, OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME, @@ -352,8 +347,8 @@ public VoidResponse linkExternalReferenceToElement(String serve else if (requestBody.getProperties() == null) { handler.linkElementToElement(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, attachedToGUID, elementGUIDParameterName, OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME, @@ -425,8 +420,8 @@ public VoidResponse unlinkExternalReferenceFromElement(String s { handler.unlinkElementFromElement(userId, false, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, attachedToGUID, elementGUIDParameterName, OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME, diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/LicenseRESTServices.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/LicenseRESTServices.java index bac8691e1e5..519c9c85660 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/LicenseRESTServices.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/LicenseRESTServices.java @@ -307,17 +307,15 @@ public GUIDResponse licenseElement(String serverName, { if (requestBody != null) { - if (requestBody.getProperties() instanceof LicenseProperties) + if (requestBody.getProperties() instanceof LicenseProperties properties) { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); LicenseHandler handler = instanceHandler.getLicenseTypeHandler(userId, serverName, methodName); - LicenseProperties properties = (LicenseProperties) requestBody.getProperties(); - response.setGUID(handler.licenseElement(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, elementGUID, elementGUIDParameterName, OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME, @@ -398,40 +396,38 @@ public VoidResponse updateLicense(String serverName, { if (requestBody != null) { - if (requestBody.getProperties() instanceof LicenseProperties) + if (requestBody.getProperties() instanceof LicenseProperties properties) { auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); LicenseHandler handler = instanceHandler.getLicenseTypeHandler(userId, serverName, methodName); - LicenseProperties properties = (LicenseProperties) requestBody.getProperties(); - handler.updateLicense(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), - licenseGUID, - licenseGUIDParameterName, - properties.getLicenseId(), - properties.getStartDate(), - properties.getEndDate(), - properties.getConditions(), - properties.getLicensedBy(), - properties.getLicensedByTypeName(), - properties.getLicensedByPropertyName(), - properties.getCustodian(), - properties.getCustodianTypeName(), - properties.getCustodianPropertyName(), - properties.getLicensee(), - properties.getLicenseeTypeName(), - properties.getLicenseePropertyName(), - properties.getNotes(), - isMergeUpdate, - null, - null, - false, - false, - new Date(), - methodName); + null, + null, + licenseGUID, + licenseGUIDParameterName, + properties.getLicenseId(), + properties.getStartDate(), + properties.getEndDate(), + properties.getConditions(), + properties.getLicensedBy(), + properties.getLicensedByTypeName(), + properties.getLicensedByPropertyName(), + properties.getCustodian(), + properties.getCustodianTypeName(), + properties.getCustodianPropertyName(), + properties.getLicensee(), + properties.getLicenseeTypeName(), + properties.getLicenseePropertyName(), + properties.getNotes(), + isMergeUpdate, + null, + null, + false, + false, + new Date(), + methodName); } else { @@ -485,30 +481,15 @@ public VoidResponse unlicenseElement(String serverName, auditLog = instanceHandler.getAuditLog(userId, serverName, methodName); LicenseHandler handler = instanceHandler.getLicenseTypeHandler(userId, serverName, methodName); - if (requestBody != null) - { - handler.unlicenseElement(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), - licenseGUID, - licenseGUIDParameterName, - false, - false, - new Date(), - methodName); - } - else - { - handler.unlicenseElement(userId, - null, - null, - licenseGUID, - licenseGUIDParameterName, - false, - false, - new Date(), - methodName); - } + handler.unlicenseElement(userId, + null, + null, + licenseGUID, + licenseGUIDParameterName, + false, + false, + new Date(), + methodName); } catch (Exception error) { diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/RelatedElementRESTServices.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/RelatedElementRESTServices.java index 56693e838e6..b242ad718c4 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/RelatedElementRESTServices.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-server/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/RelatedElementRESTServices.java @@ -73,8 +73,8 @@ public VoidResponse setupMoreInformation(String serverName, if (requestBody.getProperties() != null) { handler.addMoreInformation(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, elementGUID, elementGUIDParameterName, detailGUID, @@ -89,8 +89,8 @@ public VoidResponse setupMoreInformation(String serverName, else { handler.addMoreInformation(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, elementGUID, elementGUIDParameterName, detailGUID, @@ -345,13 +345,11 @@ public VoidResponse setupStakeholder(String serverName, if (requestBody != null) { - if (requestBody.getProperties() instanceof StakeholderProperties) + if (requestBody.getProperties() instanceof StakeholderProperties properties) { - StakeholderProperties properties = (StakeholderProperties) requestBody.getProperties(); - handler.addStakeholder(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, elementGUID, elementGUIDParameterName, stakeholderGUID, @@ -367,8 +365,8 @@ public VoidResponse setupStakeholder(String serverName, else if (requestBody.getProperties() == null) { handler.addStakeholder(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, elementGUID, elementGUIDParameterName, stakeholderGUID, @@ -628,13 +626,12 @@ public VoidResponse setupResource(String serverName, if (requestBody != null) { - if (requestBody.getProperties() instanceof ResourceListProperties) + if (requestBody.getProperties() instanceof ResourceListProperties properties) { - ResourceListProperties properties = (ResourceListProperties) requestBody.getProperties(); handler.saveResourceListMember(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, elementGUID, elementGUIDParameterName, resourceGUID, @@ -651,8 +648,8 @@ public VoidResponse setupResource(String serverName, else if (requestBody.getProperties() == null) { handler.saveResourceListMember(userId, - requestBody.getExternalSourceGUID(), - requestBody.getExternalSourceName(), + null, + null, elementGUID, elementGUIDParameterName, resourceGUID, diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetCertificationsResource.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetCertificationsResource.java index f9cda160fd6..930c1a743ae 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetCertificationsResource.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetCertificationsResource.java @@ -28,8 +28,11 @@ @RestController @RequestMapping("/servers/{serverName}/open-metadata/access-services/asset-owner/users/{userId}") -@Tag(name="Asset Owner OMAS", description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of Asset Owners in protecting and enhancing their assets.\n" + - "\n", externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)",url="https://egeria-project.org/services/omas/asset-owner/overview/")) +@Tag(name="Asset Owner OMAS", + description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of " + + "Asset Owners in protecting and enhancing their assets.", + externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", + url="https://egeria-project.org/services/omas/asset-owner/overview/")) public class AssetCertificationsResource { diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetExternalReferenceResource.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetExternalReferenceResource.java index 8786a94f1d2..3de9c0c31a8 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetExternalReferenceResource.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetExternalReferenceResource.java @@ -31,8 +31,11 @@ @RestController @RequestMapping("/servers/{serverName}/open-metadata/access-services/asset-owner/users/{userId}") -@Tag(name="Asset Owner OMAS", description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of Asset Owners in protecting and enhancing their assets.\n" + - "\n", externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)",url="https://egeria-project.org/services/omas/asset-owner/overview/")) +@Tag(name="Asset Owner OMAS", + description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of " + + "Asset Owners in protecting and enhancing their assets.", + externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", + url="https://egeria-project.org/services/omas/asset-owner/overview/")) public class AssetExternalReferenceResource { diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetLicensesResource.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetLicensesResource.java index 19cb709f09e..bd75c2dcfed 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetLicensesResource.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetLicensesResource.java @@ -28,8 +28,11 @@ @RestController @RequestMapping("/servers/{serverName}/open-metadata/access-services/asset-owner/users/{userId}") -@Tag(name="Asset Owner OMAS", description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of Asset Owners in protecting and enhancing their assets.\n" + - "\n", externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)",url="https://egeria-project.org/services/omas/asset-owner/overview/")) +@Tag(name="Asset Owner OMAS", + description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of " + + "Asset Owners in protecting and enhancing their assets.", + externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", + url="https://egeria-project.org/services/omas/asset-owner/overview/")) public class AssetLicensesResource { diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetOwnerResource.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetOwnerResource.java index 6c21302430a..939d9d82b9e 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetOwnerResource.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetOwnerResource.java @@ -23,8 +23,11 @@ @RestController @RequestMapping("/servers/{serverName}/open-metadata/access-services/asset-owner/users/{userId}") -@Tag(name="Asset Owner OMAS", description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of Asset Owners in protecting and enhancing their assets.\n" + - "\n", externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)",url="https://egeria-project.org/services/omas/asset-owner/overview/")) +@Tag(name="Asset Owner OMAS", + description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of " + + "Asset Owners in protecting and enhancing their assets.", + externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", + url="https://egeria-project.org/services/omas/asset-owner/overview/")) public class AssetOwnerResource { @@ -167,6 +170,183 @@ public VoidResponse updateAsset(@PathVariable String serverName, } + + + /** + * Link two asset together. + * Use information from the relationship type definition to ensure the fromAssetGUID and toAssetGUID are the right way around. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param relationshipTypeName type name of relationship to create + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param requestBody unique identifier for this relationship + * + * @return unique identifier of the relationship or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/assets/relationships/{relationshipTypeName}/from-asset/{fromAssetGUID}/to-asset/{toAssetGUID}") + + public GUIDResponse setupRelatedAsset(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String relationshipTypeName, + @PathVariable String fromAssetGUID, + @PathVariable String toAssetGUID, + @RequestBody(required = false) + RelationshipRequestBody requestBody) + { + return restAPI.setupRelatedAsset(serverName, userId, relationshipTypeName, fromAssetGUID, toAssetGUID, requestBody); + } + + + /** + * Retrieve the relationship between two elements. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param relationshipTypeName type name of relationship to create + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param requestBody optional date for effective time of the query. Null means any effective time + * + * @return unique identifier and properties of the relationship or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/assets/relationships/{relationshipTypeName}/from-asset/{fromAssetGUID}/to-asset/{toAssetGUID}/retrieve") + + public RelationshipElementResponse getAssetRelationship(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String relationshipTypeName, + @PathVariable String fromAssetGUID, + @PathVariable String toAssetGUID, + @RequestBody(required = false) EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.getAssetRelationship(serverName, userId, relationshipTypeName, fromAssetGUID, toAssetGUID, requestBody); + } + + + /** + * Update relationship between two elements. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param relationshipTypeName type name of relationship to update + * @param relationshipGUID unique identifier of the relationship + * @param isMergeUpdate should the new properties be merged with the existing properties, or replace them entirely + * @param requestBody description and/or purpose of the relationship + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/assets/relationships/{relationshipTypeName}/{relationshipGUID}/update") + + public VoidResponse updateAssetRelationship(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String relationshipTypeName, + @PathVariable String relationshipGUID, + @RequestParam boolean isMergeUpdate, + @RequestBody(required = false) + RelationshipRequestBody requestBody) + { + return restAPI.updateAssetRelationship(serverName, userId, relationshipTypeName, relationshipGUID, isMergeUpdate, requestBody); + } + + + /** + * Remove the relationship between two elements. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param relationshipGUID unique identifier of the relationship + * @param requestBody external source ids + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/assets/relationships/{relationshipTypeName}/{relationshipGUID}/remove") + + public VoidResponse clearAssetRelationship(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String relationshipTypeName, + @PathVariable String relationshipGUID, + @RequestBody(required = false) + EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.clearAssetRelationship(serverName, userId, relationshipTypeName, relationshipGUID, requestBody); + } + + + /** + * Retrieve the requested relationships linked from a specific element at end 2. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param fromAssetGUID unique identifier of the asset at end 1 of the relationship + * @param startFrom start position for results + * @param pageSize maximum number of results + * @param requestBody effective time + * + * @return unique identifier and properties of the relationships or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/assets/relationships/{relationshipTypeName}/from-asset/{fromAssetGUID}/retrieve/end2") + + public RelationshipElementsResponse getRelatedAssetsAtEnd2(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String relationshipTypeName, + @PathVariable String fromAssetGUID, + @RequestParam int startFrom, + @RequestParam int pageSize, + @RequestBody(required = false) EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.getRelatedAssetsAtEnd2(serverName, userId, relationshipTypeName, fromAssetGUID, startFrom, pageSize, requestBody); + } + + + /** + * Retrieve the relationships linked from a specific element at end 2 of the relationship. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param relationshipTypeName type name of relationship to delete + * @param toAssetGUID unique identifier of the asset at end 2 of the relationship + * @param startFrom start position for results + * @param pageSize maximum number of results + * @param requestBody the time that the retrieved elements must be effective for (null for any time, new Date() for now) + * + * @return unique identifier and properties of the relationships or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/assets/assets/relationships/{relationshipTypeName}/to-asset/{toAssetGUID}/retrieve/end1") + + public RelationshipElementsResponse getRelatedAssetsAtEnd1(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String relationshipTypeName, + @PathVariable String toAssetGUID, + @RequestParam int startFrom, + @RequestParam int pageSize, + @RequestBody EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.getRelatedAssetsAtEnd1(serverName, userId, relationshipTypeName, toAssetGUID, startFrom, pageSize, requestBody); + } + + + /** * Stores the supplied schema details in the catalog and attaches it to the asset. If another schema is currently * attached to the asset, it is unlinked and deleted. If more attributes need to be added in addition to the @@ -245,31 +425,6 @@ public GUIDResponse addSchemaTypeToAsset(@PathVariable String s } - /** - * Stores the supplied schema type in the catalog and attaches it to the asset. If another schema is currently - * attached to the asset, it is unlinked and deleted. - * - * @param serverName name of the server instance to connect to - * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param schemaType schema type to create and attach directly to the asset. - * - * @return guid of the new schema type or - * InvalidParameterException full path or userId is null, or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem - */ - @PostMapping(path = "/assets/{assetGUID}/schemas/top-level-schema-type") - @Deprecated - public GUIDResponse addSchemaTypeToAsset(@PathVariable String serverName, - @PathVariable String userId, - @PathVariable String assetGUID, - @RequestBody SchemaTypeRequestBody schemaType) - { - return restAPI.addSchemaTypeToAsset(serverName, userId, assetGUID, schemaType); - } - - /** * Links the supplied schema type directly to the asset. If this schema is either not found, or * already attached to an asset, then an error occurs. If another schema is currently @@ -335,7 +490,7 @@ public GUIDResponse detachSchemaTypeFromAsset(@PathVariable S * PropertyServerException problem accessing property server or * UserNotAuthorizedException security access problem */ - @PostMapping(path = "/assets/{assetGUID}/schemas/top-level-schema-type/delete") + @PostMapping(path = "/assets/{assetGUID}/schemas/delete") public VoidResponse deleteAssetSchemaType(@PathVariable String serverName, @PathVariable String userId, @@ -346,33 +501,366 @@ public VoidResponse deleteAssetSchemaType(@PathVariable String } + + + /* ===================================================================================================================== + * A schemaType describes the structure of a data asset, process or port + */ + /** - * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. - * This method can be called repeatedly to add many attributes to a schema. + * Create a new metadata element to represent a schema type. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param parentGUID unique identifier of the schema element to anchor these attributes to. - * @param schemaAttributes list of schema attribute objects. + * @param anchorGUID unique identifier of the intended anchor of the schema type + * @param requestBody properties about the schema type to store * - * @return list of unique identifiers for the new schema attributes returned in the same order as the supplied attribute or - * InvalidParameterException full path or userId is null or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return unique identifier of the new schema type + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - @PostMapping(path = "/assets/{assetGUID}/schemas/{parentGUID}/schema-attributes/list/deprecated") + @PostMapping(path = "/schema-types") - public VoidResponse addSchemaAttributes(@PathVariable String serverName, - @PathVariable String userId, - @PathVariable String assetGUID, - @PathVariable String parentGUID, - @RequestBody SchemaAttributesRequestBody schemaAttributes) + public GUIDResponse createSchemaType(@PathVariable String serverName, + @PathVariable String userId, + @RequestParam (required = false, defaultValue = "null") + String anchorGUID, + @RequestBody SchemaTypeProperties requestBody) { - return restAPI.addSchemaAttributes(serverName, userId, assetGUID, parentGUID, schemaAttributes); + return restAPI.createSchemaType(serverName, userId, anchorGUID, requestBody); } + /** + * Create a new metadata element to represent a schema type using an existing metadata element as a template. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param templateGUID unique identifier of the metadata element to copy + * @param requestBody properties that override the template + * + * @return unique identifier of the new schema type + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-types/from-template/{templateGUID}") + + public GUIDResponse createSchemaTypeFromTemplate(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String templateGUID, + @RequestBody TemplateRequestBody requestBody) + { + return restAPI.createSchemaTypeFromTemplate(serverName, userId, templateGUID, requestBody); + } + + + /** + * Update the metadata element representing a schema type. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the metadata element to update + * @param isMergeUpdate should the new properties be merged with existing properties (true) or completely replace them (false)? + * @param requestBody new properties for the metadata element + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-types/{schemaTypeGUID}") + + public VoidResponse updateSchemaType(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaTypeGUID, + @RequestParam boolean isMergeUpdate, + @RequestBody SchemaTypeProperties requestBody) + { + return restAPI.updateSchemaType(serverName, userId, schemaTypeGUID, isMergeUpdate, requestBody); + } + + + /** + * Connect a schema type to a data asset, process or port. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/parents/{parentElementGUID}/{parentElementTypeName}/schema-types/{schemaTypeGUID}") + + public VoidResponse setupSchemaTypeParent(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String parentElementGUID, + @PathVariable String parentElementTypeName, + @PathVariable String schemaTypeGUID, + @RequestBody (required=false) + RelationshipRequestBody requestBody) + { + return restAPI.setupSchemaTypeParent(serverName, userId, parentElementGUID, parentElementTypeName, schemaTypeGUID, requestBody); + } + + + /** + * Remove the relationship between a schema type and its parent data asset, process or port. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/parents/{parentElementGUID}/{parentElementTypeName}/schema-types/{schemaTypeGUID}/remove") + + public VoidResponse clearSchemaTypeParent(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String parentElementGUID, + @PathVariable String parentElementTypeName, + @PathVariable String schemaTypeGUID, + @RequestBody (required=false) + EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.clearSchemaTypeParent(serverName, userId, parentElementGUID, parentElementTypeName, schemaTypeGUID, requestBody); + } + + + + + /** + * Create a relationship between two schema elements. The name of the desired relationship, and any properties (including effectivity dates) + * are passed on the API. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to create + * @param requestBody relationship properties + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-elements/{endOneGUID}/relationships/{relationshipTypeName}/schema-elements/{endTwoGUID}") + + public VoidResponse setupSchemaElementRelationship(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String endOneGUID, + @PathVariable String relationshipTypeName, + @PathVariable String endTwoGUID, + @RequestBody (required=false) + RelationshipRequestBody requestBody) + { + return restAPI.setupSchemaElementRelationship(serverName, userId, endOneGUID, relationshipTypeName, endTwoGUID, requestBody); + } + + + /** + * Remove a relationship between two schema elements. The name of the desired relationship is passed on the API. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to delete + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-elements/{endOneGUID}/relationships/{relationshipTypeName}/schema-elements/{endTwoGUID}/remove") + + public VoidResponse clearSchemaElementRelationship(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String endOneGUID, + @PathVariable String relationshipTypeName, + @PathVariable String endTwoGUID, + @RequestBody (required=false) + EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.clearSchemaElementRelationship(serverName, userId, endOneGUID, relationshipTypeName, endTwoGUID, requestBody); + } + + + /** + * Remove the metadata element representing a schema type. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the metadata element to remove + * @param requestBody unique identifier/name of software server capability representing the caller and external identifier of element + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-types/{schemaTypeGUID}/remove") + + public VoidResponse removeSchemaType(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaTypeGUID, + @RequestBody (required=false) + UpdateRequestBody requestBody) + { + return restAPI.removeSchemaType(serverName, userId, schemaTypeGUID, requestBody); + } + + + /** + * Retrieve the list of schema type metadata elements that contain the search string. + * The search string is treated as a regular expression. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody string to find in the properties plus external identifiers + * + * @return list of matching metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-types/by-search-string") + + public SchemaTypeElementsResponse findSchemaType(@PathVariable String serverName, + @PathVariable String userId, + @RequestParam int startFrom, + @RequestParam int pageSize, + @RequestBody SearchStringRequestBody requestBody) + { + return restAPI.findSchemaType(serverName, userId, startFrom, pageSize, requestBody); + } + + + /** + * Return the schema type associated with a specific open metadata element (data asset, process or port). + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return metadata element describing the schema type associated with the requested parent element or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/parents/{parentElementTypeName}/{parentElementGUID}/schema-types/retrieve") + + public SchemaTypeElementResponse getSchemaTypeForElement(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String parentElementGUID, + @PathVariable String parentElementTypeName, + @RequestBody(required = false) + EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.getSchemaTypeForElement(serverName, userId, parentElementGUID, parentElementTypeName, requestBody); + } + + + /** + * Retrieve the list of schema type metadata elements with a matching qualified or display name. + * There are no wildcards supported on this request. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody name to search for plus identifiers + * + * @return list of matching metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-types/by-name") + + public SchemaTypeElementsResponse getSchemaTypeByName(@PathVariable String serverName, + @PathVariable String userId, + @RequestParam int startFrom, + @RequestParam int pageSize, + @RequestBody NameRequestBody requestBody) + { + return restAPI.getSchemaTypeByName(serverName, userId, startFrom, pageSize, requestBody); + } + + + /** + * Retrieve the schema type metadata element with the supplied unique identifier. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the requested metadata element + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return requested metadata element or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-types/{schemaTypeGUID}/retrieve") + + public SchemaTypeElementResponse getSchemaTypeByGUID(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaTypeGUID, + @RequestBody(required = false) + EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.getSchemaTypeByGUID(serverName, userId, schemaTypeGUID, requestBody); + } + + + /** + * Retrieve the header of the metadata element connected to a schema type. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaTypeGUID unique identifier of the requested metadata element + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return header for parent element (data asset, process, port) or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/parents/schema-types/{schemaTypeGUID}/retrieve") + + public ElementHeaderResponse getSchemaTypeParent(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaTypeGUID, + @RequestBody(required = false) + EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.getSchemaTypeParent(serverName, userId, schemaTypeGUID, requestBody); + } + + + /* =============================================================================== + * A schemaType typically contains many schema attributes, linked with relationships. + */ + /** * Adds attributes to a complex schema type like a relational table, avro schema or a structured document. @@ -417,46 +905,247 @@ public VoidResponse addSchemaAttributes(@PathVariable String * PropertyServerException problem accessing property server or * UserNotAuthorizedException security access problem */ - @PostMapping(path = "/assets/{assetGUID}/schemas/{parentGUID}/schema-attributes/deprecated") - @Deprecated - public GUIDResponse addSchemaAttribute(@PathVariable String serverName, - @PathVariable String userId, - @PathVariable String assetGUID, - @PathVariable String parentGUID, - @RequestBody SchemaAttributeRequestBody schemaAttribute) + @PostMapping(path = "/assets/{assetGUID}/schemas/{parentGUID}/schema-attributes") + + public GUIDResponse addSchemaAttribute(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String assetGUID, + @PathVariable String parentGUID, + @RequestBody SchemaAttributeProperties schemaAttribute) { return restAPI.addSchemaAttribute(serverName, userId, assetGUID, parentGUID, schemaAttribute); } /** - * Adds the attribute to a complex schema type like a relational table, avro schema or a structured document. - * This method can be called repeatedly to add many attributes to a schema. The GUID returned can be used to add - * nested attributes. + * Create a new metadata element to represent a schema attribute using an existing metadata element as a template. * - * @param serverName name of the server instance to connect to + * @param serverName name of the server to route the request to * @param userId calling user - * @param assetGUID unique identifier of the asset that the schema is to be attached to - * @param parentGUID unique identifier of the schema element to anchor these attributes to. - * @param schemaAttribute schema attribute object. + * @param schemaElementGUID unique identifier of the schemaType or Schema Attribute where the schema attribute is connected to + * @param templateGUID unique identifier of the metadata element to copy + * @param requestBody properties that override the template * - * @return list of unique identifiers for the new schema attributes returned in the same order as the supplied attribute or - * InvalidParameterException full path or userId is null or - * PropertyServerException problem accessing property server or - * UserNotAuthorizedException security access problem + * @return unique identifier of the new metadata element for the schema attribute or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) */ - @PostMapping(path = "/assets/{assetGUID}/schemas/{parentGUID}/schema-attributes") + @PostMapping(path = "/schema-elements/{schemaElementGUID}/schema-attributes/from-template/{templateGUID}") - public GUIDResponse addSchemaAttribute(@PathVariable String serverName, - @PathVariable String userId, - @PathVariable String assetGUID, - @PathVariable String parentGUID, - @RequestBody SchemaAttributeProperties schemaAttribute) + public GUIDResponse createSchemaAttributeFromTemplate(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaElementGUID, + @PathVariable String templateGUID, + @RequestBody TemplateRequestBody requestBody) { - return restAPI.addSchemaAttribute(serverName, userId, assetGUID, parentGUID, schemaAttribute); + return restAPI.createSchemaAttributeFromTemplate(serverName, userId, schemaElementGUID, templateGUID, requestBody); } + /** + * Update the properties of the metadata element representing a schema attribute. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the schema attribute to update + * @param isMergeUpdate should the new properties be merged with existing properties (true) or completely replace them (false)? + * @param requestBody new properties for the schema attribute + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-attributes/{schemaAttributeGUID}") + + public VoidResponse updateSchemaAttribute(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaAttributeGUID, + @RequestParam boolean isMergeUpdate, + @RequestBody SchemaAttributeProperties requestBody) + { + return restAPI.updateSchemaAttribute(serverName, userId, schemaAttributeGUID, isMergeUpdate, requestBody); + } + + + /** + * Classify the schema type (or attribute if type is embedded) to indicate that it is a calculated value. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaElementGUID unique identifier of the metadata element to update + * @param requestBody unique identifier/name of software server capability representing the caller and external identifier of element + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-elements/{schemaElementGUID}/is-calculated-value") + + public VoidResponse setSchemaElementAsCalculatedValue(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaElementGUID, + @RequestBody CalculatedValueClassificationRequestBody requestBody) + { + return restAPI.setSchemaElementAsCalculatedValue(serverName, userId, schemaElementGUID, requestBody); + } + + + /** + * Remove the calculated value designation from the schema element. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaElementGUID unique identifier of the metadata element to update + * @param requestBody unique identifier/name of software server capability representing the caller and external identifier of element + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-elements/{schemaElementGUID}/is-calculated-value/remove") + + public VoidResponse clearSchemaElementAsCalculatedValue(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaElementGUID, + @RequestBody UpdateRequestBody requestBody) + { + return restAPI.clearSchemaElementAsCalculatedValue(serverName, userId, schemaElementGUID, requestBody); + } + + + /** + * Remove the metadata element representing a schema attribute. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the metadata element to remove + * @param requestBody unique identifier/name of software server capability representing the caller and external identifier of element + * + * @return void or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-attributes/{schemaAttributeGUID}/remove") + + public VoidResponse removeSchemaAttribute(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaAttributeGUID, + @RequestBody UpdateRequestBody requestBody) + { + return restAPI.removeSchemaAttribute(serverName, userId, schemaAttributeGUID, requestBody); + } + + + /** + * Retrieve the list of schema attribute metadata elements that contain the search string. + * The search string is treated as a regular expression. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody string to find in the properties plus external identifiers + * + * @return list of matching metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-attributes/by-search-string") + + public SchemaAttributeElementsResponse findSchemaAttributes(@PathVariable String serverName, + @PathVariable String userId, + @RequestParam int startFrom, + @RequestParam int pageSize, + @RequestBody SearchStringRequestBody requestBody) + { + return restAPI.findSchemaAttributes(serverName, userId, startFrom, pageSize, requestBody); + } + + + /** + * Retrieve the list of schema attributes associated with a schema element. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param parentSchemaElementGUID unique identifier of the schema element of interest + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return list of associated metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-elements/{parentSchemaElementGUID}/schema-attributes/retrieve") + + public SchemaAttributeElementsResponse getNestedAttributes(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String parentSchemaElementGUID, + @RequestParam int startFrom, + @RequestParam int pageSize, + @RequestBody EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.getNestedAttributes(serverName, userId, parentSchemaElementGUID, startFrom, pageSize, requestBody); + } + + + /** + * Retrieve the list of schema attribute metadata elements with a matching qualified or display name. + * There are no wildcards supported on this request. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param startFrom paging start point + * @param pageSize maximum results that can be returned + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return list of matching metadata elements or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-attributes/by-name") + + public SchemaAttributeElementsResponse getSchemaAttributesByName(@PathVariable String serverName, + @PathVariable String userId, + @RequestParam int startFrom, + @RequestParam int pageSize, + @RequestBody NameRequestBody requestBody) + { + return restAPI.getSchemaAttributesByName(serverName, userId, startFrom, pageSize, requestBody); + } + + + /** + * Retrieve the schema attribute metadata element with the supplied unique identifier. + * + * @param serverName name of the server to route the request to + * @param userId calling user + * @param schemaAttributeGUID unique identifier of the requested metadata element + * @param requestBody unique identifier/name of software server capability representing the caller + * + * @return matching metadata element or + * InvalidParameterException one of the parameters is invalid + * UserNotAuthorizedException the user is not authorized to issue this request + * PropertyServerException there is a problem reported in the open metadata server(s) + */ + @PostMapping(path = "/schema-attributes/{schemaAttributeGUID}/retrieve") + + public SchemaAttributeElementResponse getSchemaAttributeByGUID(@PathVariable String serverName, + @PathVariable String userId, + @PathVariable String schemaAttributeGUID, + @RequestBody EffectiveTimeQueryRequestBody requestBody) + { + return restAPI.getSchemaAttributeByGUID(serverName, userId, schemaAttributeGUID, requestBody); + } + /** * Adds a connection to an asset. Assets can have multiple connections attached. * @@ -1095,7 +1784,6 @@ public AnnotationListResponse getExtendedAnnotations(@PathVariable String /** * Deletes an asset and all of its associated elements such as schema, connections (unless they are linked to * another asset), discovery reports and associated feedback. - * * Given the depth of the elements deleted by this call, it should be used with care. * * @param serverName name of the server instance to connect to diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetRelationshipsResource.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetRelationshipsResource.java index 0197448ddf7..8022847b78e 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetRelationshipsResource.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/AssetRelationshipsResource.java @@ -27,9 +27,10 @@ @RestController @RequestMapping("/servers/{serverName}/open-metadata/access-services/asset-owner/users/{userId}") -@Tag(name="Governance Program OMAS", - description="The Governance Program OMAS provides APIs and events for tools and applications focused on defining a data strategy, planning support for a regulation and/or developing a governance program for the data landscape.", - externalDocs=@ExternalDocumentation(description="Governance Program Open Metadata Access Service (OMAS)", +@Tag(name="Asset Owner OMAS", + description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of " + + "Asset Owners in protecting and enhancing their assets.", + externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", url="https://egeria-project.org/services/omas/asset-owner/overview/")) public class AssetRelationshipsResource diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/ConnectionsBuildingResource.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/ConnectionsBuildingResource.java index fd8ea4f5b65..5dda689f6c2 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/ConnectionsBuildingResource.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/ConnectionsBuildingResource.java @@ -35,9 +35,11 @@ @RestController @RequestMapping("/servers/{serverName}/open-metadata/access-services/asset-owner/users/{userId}") -@Tag(name="Asset Owner OMAS", description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of Asset Owners in protecting and enhancing their assets.\n" + - "\n", externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", - url="https://egeria-project.org/services/omas/asset-owner/overview/")) +@Tag(name="Asset Owner OMAS", + description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of " + + "Asset Owners in protecting and enhancing their assets.", + externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", + url="https://egeria-project.org/services/omas/asset-owner/overview/")) public class ConnectionsBuildingResource diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/FileSystemOnboardingResource.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/FileSystemOnboardingResource.java index afb36ccb072..3a51c07dfbd 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/FileSystemOnboardingResource.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/FileSystemOnboardingResource.java @@ -19,8 +19,11 @@ @RestController @RequestMapping("/servers/{serverName}/open-metadata/access-services/asset-owner/users/{userId}") -@Tag(name="Asset Owner OMAS", description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of Asset Owners in protecting and enhancing their assets.\n" + - "\n", externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)",url="https://egeria-project.org/services/omas/asset-owner/overview/")) +@Tag(name="Asset Owner OMAS", + description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of " + + "Asset Owners in protecting and enhancing their assets.", + externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", + url="https://egeria-project.org/services/omas/asset-owner/overview/")) public class FileSystemOnboardingResource { diff --git a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/ValidValuesOnboardingResource.java b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/ValidValuesOnboardingResource.java index 063d77de154..ecc05545152 100644 --- a/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/ValidValuesOnboardingResource.java +++ b/open-metadata-implementation/access-services/asset-owner/asset-owner-spring/src/main/java/org/odpi/openmetadata/accessservices/assetowner/server/spring/ValidValuesOnboardingResource.java @@ -25,11 +25,13 @@ @RestController @RequestMapping("/servers/{serverName}/open-metadata/access-services/asset-owner/users/{userId}") -@Tag(name="Asset Owner OMAS", description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of Asset Owners in protecting and enhancing their assets.\n" + - "\n", externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", url="https://egeria.odpi" + - ".org/open-metadata-implementation/access-services/asset-owner/")) -public class ValidValuesOnboardingResource +@Tag(name="Asset Owner OMAS", + description="The Asset Owner OMAS provides APIs and notifications for tools and applications supporting the work of " + + "Asset Owners in protecting and enhancing their assets.", + externalDocs=@ExternalDocumentation(description="Asset Owner Open Metadata Access Service (OMAS)", + url="https://egeria-project.org/services/omas/asset-owner/overview/")) +public class ValidValuesOnboardingResource { private final ValidValuesRESTServices restAPI = new ValidValuesRESTServices(); diff --git a/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/SchemaElementHandler.java b/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/SchemaElementHandler.java index 7700ca41bce..3e03223ace7 100644 --- a/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/SchemaElementHandler.java +++ b/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/SchemaElementHandler.java @@ -3,6 +3,7 @@ package org.odpi.openmetadata.commonservices.generichandlers; import org.odpi.openmetadata.commonservices.ffdc.InvalidParameterHandler; +import org.odpi.openmetadata.commonservices.generichandlers.ffdc.GenericHandlersErrorCode; import org.odpi.openmetadata.commonservices.repositoryhandler.RepositoryHandler; import org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException; import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException; @@ -15,6 +16,7 @@ import java.util.Date; import java.util.List; +import java.util.Map; /** * SchemaElementHandler manages common methods fof SchemaType and Schema Attribute objects. It runs server-side in @@ -299,7 +301,6 @@ else if (repositoryHelper.isTypeOf(serviceName, schemaTypeBuilder.getTypeName(), mapFromGUID = addSchemaType(userId, externalSourceGUID, externalSourceName, - mapFromBuilder.qualifiedName, mapFromBuilder, effectiveFrom, effectiveTo, @@ -337,7 +338,6 @@ else if (repositoryHelper.isTypeOf(serviceName, schemaTypeBuilder.getTypeName(), mapToGUID = addSchemaType(userId, externalSourceGUID, externalSourceName, - mapToBuilder.qualifiedName, mapToBuilder, effectiveFrom, effectiveTo, @@ -383,7 +383,6 @@ else if (repositoryHelper.isTypeOf(serviceName, schemaTypeBuilder.getTypeName(), String optionGUID = addSchemaType(userId, externalSourceGUID, externalSourceName, - schemaOptionBuilder.qualifiedName, schemaOptionBuilder, effectiveFrom, effectiveTo, @@ -445,7 +444,6 @@ else if (repositoryHelper.isTypeOf(serviceName, schemaTypeBuilder.getTypeName(), private String addSchemaType(String userId, String externalSourceGUID, String externalSourceName, - String qualifiedName, SchemaTypeBuilder schemaTypeBuilder, Date effectiveFrom, Date effectiveTo, @@ -510,18 +508,16 @@ int countSchemaAttributes(String userId, invalidParameterHandler.validateUserId(userId, methodName); invalidParameterHandler.validateGUID(schemaElementGUID, guidParameterName, methodName); - int count = repositoryHandler.countAttachedRelationshipsByType(userId, - schemaElementGUID, - OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, - OpenMetadataAPIMapper.NESTED_ATTRIBUTE_RELATIONSHIP_TYPE_GUID, - OpenMetadataAPIMapper.NESTED_ATTRIBUTE_RELATIONSHIP_TYPE_NAME, - 2, - false, - false, - effectiveTime, - methodName); - - return count; + return repositoryHandler.countAttachedRelationshipsByType(userId, + schemaElementGUID, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + OpenMetadataAPIMapper.NESTED_ATTRIBUTE_RELATIONSHIP_TYPE_GUID, + OpenMetadataAPIMapper.NESTED_ATTRIBUTE_RELATIONSHIP_TYPE_NAME, + 2, + false, + false, + effectiveTime, + methodName); } @@ -738,4 +734,158 @@ public void clearQueryTargetRelationship(String userId, } + /** + * Create a relationship between two schema elements. The name of the desired relationship, and any properties (including effectivity dates) + * are passed on the API. + * + * @param userId calling user + * @param externalSourceGUID unique identifier of software server capability representing the caller + * @param externalSourceName unique name of software server capability representing the caller + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to create + * @param properties properties for the new relationship + * @param effectiveFrom the date when this element is active - null for active now + * @param effectiveTo the date when this element becomes inactive - null for active until deleted + * @param forLineage return elements marked with the Memento classification? + * @param forDuplicateProcessing do not merge elements marked as duplicates? + * @param effectiveTime when should the elements be effected for - null is anytime; new Date() is now + * @param methodName calling method + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + @SuppressWarnings(value = "unused") + public void setupSchemaElementRelationship(String userId, + String externalSourceGUID, + String externalSourceName, + String endOneGUID, + String endTwoGUID, + String relationshipTypeName, + Map properties, + Date effectiveFrom, + Date effectiveTo, + boolean forLineage, + boolean forDuplicateProcessing, + Date effectiveTime, + String methodName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String endOneParameterName = "endOneGUID"; + final String endTwoParameterName = "endTwoGUID"; + final String relationshipTypeParameterName = "relationshipTypeName"; + final String propertiesParameterName = "properties"; + + invalidParameterHandler.validateName(relationshipTypeName, relationshipTypeParameterName, methodName); + + String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, + null, + serviceName, + methodName, + repositoryHelper); + + InstanceProperties instanceProperties = null; + + if ((properties != null) && (! properties.isEmpty())) + { + try + { + instanceProperties = repositoryHelper.addPropertyMapToInstance(serviceName, null, properties, methodName); + } + catch (Exception badPropertyException) + { + throw new InvalidParameterException(GenericHandlersErrorCode.BAD_PARAMETER.getMessageDefinition(relationshipTypeName, + badPropertyException.getClass().getName(), + badPropertyException.getMessage()), + this.getClass().getName(), + methodName, + badPropertyException, + propertiesParameterName); + } + } + + this.linkElementToElement(userId, + externalSourceGUID, + externalSourceName, + endOneGUID, + endOneParameterName, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + endTwoGUID, + endTwoParameterName, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + forLineage, + forDuplicateProcessing, + relationshipTypeGUID, + relationshipTypeName, + instanceProperties, + effectiveFrom, + effectiveTo, + effectiveTime, + methodName); + } + + + /** + * Remove a relationship between two schema elements. The name of the desired relationship is passed on the API. + * + * @param userId calling user + * @param externalSourceGUID unique identifier of software server capability representing the caller + * @param externalSourceName unique name of software server capability representing the caller + * @param endOneGUID unique identifier of the schema element at end one of the relationship + * @param endTwoGUID unique identifier of the schema element at end two of the relationship + * @param relationshipTypeName type of the relationship to create + * @param forLineage return elements marked with the Memento classification? + * @param forDuplicateProcessing do not merge elements marked as duplicates? + * @param effectiveTime when should the elements be effected for - null is anytime; new Date() is now + * @param methodName calling method + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + public void clearSchemaElementRelationship(String userId, + String externalSourceGUID, + String externalSourceName, + String endOneGUID, + String endTwoGUID, + String relationshipTypeName, + boolean forLineage, + boolean forDuplicateProcessing, + Date effectiveTime, + String methodName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String endOneParameterName = "endOneGUID"; + final String endTwoParameterName = "endTwoGUID"; + final String relationshipTypeParameterName = "relationshipTypeName"; + + invalidParameterHandler.validateName(relationshipTypeName, relationshipTypeParameterName, methodName); + + String relationshipTypeGUID = invalidParameterHandler.validateTypeName(relationshipTypeName, + null, + serviceName, + methodName, + repositoryHelper); + + this.unlinkElementFromElement(userId, + false, + externalSourceGUID, + externalSourceName, + endOneGUID, + endOneParameterName, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + endTwoGUID, + endTwoParameterName, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_GUID, + OpenMetadataAPIMapper.SCHEMA_ELEMENT_TYPE_NAME, + forLineage, + forDuplicateProcessing, + relationshipTypeGUID, + relationshipTypeName, + effectiveTime, + methodName); + } } diff --git a/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/SchemaTypeHandler.java b/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/SchemaTypeHandler.java index b2d9273b47d..08230eec1de 100644 --- a/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/SchemaTypeHandler.java +++ b/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/SchemaTypeHandler.java @@ -1338,6 +1338,172 @@ public B getSchemaTypeForParent(String userId, methodName); } + /** + * Connect a schema type to a data asset, process or port. + * + * @param userId calling user + * @param externalSourceGUID unique identifier of software server capability representing the caller + * @param externalSourceName unique name of software server capability representing the caller + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param effectiveFrom the date when this element is active - null for active now + * @param effectiveTo the date when this element becomes inactive - null for active until deleted + * @param forLineage return elements marked with the Memento classification? + * @param forDuplicateProcessing do not merge elements marked as duplicates? + * @param effectiveTime when should the elements be effected for - null is anytime; new Date() is now + * @param methodName calling method + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + public void setupSchemaTypeParent(String userId, + String externalSourceGUID, + String externalSourceName, + String schemaTypeGUID, + String parentElementGUID, + String parentElementTypeName, + Date effectiveFrom, + Date effectiveTo, + boolean forLineage, + boolean forDuplicateProcessing, + Date effectiveTime, + String methodName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + final String parentElementGUIDParameterName = "parentElementGUID"; + final String parentElementTypeParameterName = "parentElementTypeName"; + + invalidParameterHandler.validateName(parentElementTypeName, parentElementTypeParameterName, methodName); + + if (repositoryHelper.isTypeOf(serviceName, parentElementTypeName, OpenMetadataAPIMapper.PORT_TYPE_NAME)) + { + this.linkElementToElement(userId, + externalSourceGUID, + externalSourceName, + parentElementGUID, + parentElementGUIDParameterName, + parentElementTypeName, + schemaTypeGUID, + schemaTypeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + forLineage, + forDuplicateProcessing, + OpenMetadataAPIMapper.PORT_SCHEMA_RELATIONSHIP_TYPE_GUID, + OpenMetadataAPIMapper.PORT_SCHEMA_RELATIONSHIP_TYPE_NAME, + null, + effectiveFrom, + effectiveTo, + effectiveTime, + methodName); + } + else + { + this.linkElementToElement(userId, + externalSourceGUID, + externalSourceName, + parentElementGUID, + parentElementGUIDParameterName, + parentElementTypeName, + schemaTypeGUID, + schemaTypeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + forLineage, + forDuplicateProcessing, + OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_GUID, + OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_NAME, + null, + effectiveFrom, + effectiveTo, + effectiveTime, + methodName); + } + } + + + /** + * Remove the relationship between a schema type and its parent data asset, process or port. + * + * @param userId calling user + * @param externalSourceGUID unique identifier of software server capability representing the caller + * @param externalSourceName unique name of software server capability representing the caller + * @param schemaTypeGUID unique identifier of the schema type to connect + * @param parentElementGUID unique identifier of the open metadata element that this schema type is to be connected to + * @param parentElementTypeName unique type name of the open metadata element that this schema type is to be connected to + * @param forLineage return elements marked with the Memento classification? + * @param forDuplicateProcessing do not merge elements marked as duplicates? + * @param effectiveTime when should the elements be effected for - null is anytime; new Date() is now + * @param methodName calling method + * + * @throws InvalidParameterException one of the parameters is invalid + * @throws UserNotAuthorizedException the user is not authorized to issue this request + * @throws PropertyServerException there is a problem reported in the open metadata server(s) + */ + public void clearSchemaTypeParent(String userId, + String externalSourceGUID, + String externalSourceName, + String schemaTypeGUID, + String parentElementGUID, + String parentElementTypeName, + boolean forLineage, + boolean forDuplicateProcessing, + Date effectiveTime, + String methodName) throws InvalidParameterException, + UserNotAuthorizedException, + PropertyServerException + { + final String schemaTypeGUIDParameterName = "schemaTypeGUID"; + final String parentElementGUIDParameterName = "parentElementGUID"; + final String parentElementTypeParameterName = "parentElementTypeName"; + + invalidParameterHandler.validateName(parentElementTypeName, parentElementTypeParameterName, methodName); + + if ((parentElementTypeName != null) && repositoryHelper.isTypeOf(serviceName, + parentElementTypeName, + OpenMetadataAPIMapper.PORT_TYPE_NAME)) + { + this.unlinkElementFromElement(userId, + false, + externalSourceGUID, + externalSourceName, + parentElementGUID, + parentElementGUIDParameterName, + parentElementTypeName, + schemaTypeGUID, + schemaTypeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_GUID, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + forLineage, + forDuplicateProcessing, + OpenMetadataAPIMapper.PORT_SCHEMA_RELATIONSHIP_TYPE_GUID, + OpenMetadataAPIMapper.PORT_SCHEMA_RELATIONSHIP_TYPE_NAME, + effectiveTime, + methodName); + } + else + { + this.unlinkElementFromElement(userId, + false, + externalSourceGUID, + externalSourceName, + parentElementGUID, + parentElementGUIDParameterName, + parentElementTypeName, + schemaTypeGUID, + schemaTypeGUIDParameterName, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_GUID, + OpenMetadataAPIMapper.SCHEMA_TYPE_TYPE_NAME, + forLineage, + forDuplicateProcessing, + OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_GUID, + OpenMetadataAPIMapper.ASSET_TO_SCHEMA_TYPE_TYPE_NAME, + effectiveTime, + methodName); + } + } /** * Return the list of schema types nested in the parent schema type - this is typically schema type options or APIOperations in a APISchemaType. diff --git a/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/ffdc/GenericHandlersAuditCode.java b/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/ffdc/GenericHandlersAuditCode.java index e7a667b8821..d1c753565ee 100644 --- a/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/ffdc/GenericHandlersAuditCode.java +++ b/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/ffdc/GenericHandlersAuditCode.java @@ -134,11 +134,11 @@ public enum GenericHandlersAuditCode implements AuditLogMessageSet ; - private String logMessageId; - private OMRSAuditLogRecordSeverity severity; - private String logMessage; - private String systemAction; - private String userAction; + private final String logMessageId; + private final OMRSAuditLogRecordSeverity severity; + private final String logMessage; + private final String systemAction; + private final String userAction; /** diff --git a/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/ffdc/GenericHandlersErrorCode.java b/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/ffdc/GenericHandlersErrorCode.java index fe75d469b71..ec2448cfb3f 100644 --- a/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/ffdc/GenericHandlersErrorCode.java +++ b/open-metadata-implementation/common-services/generic-handlers/src/main/java/org/odpi/openmetadata/commonservices/generichandlers/ffdc/GenericHandlersErrorCode.java @@ -106,6 +106,15 @@ public enum GenericHandlersErrorCode implements ExceptionMessageSet "Either set up the caller to use the correct name or create a GovernanceActionProcess entity with the requested qualifiedName. " + "Then retry the request once the definition is added."), + /** + * OMAG-GENERIC-HANDLERS-400-012 At least one of the properties supplied for a new relationship of type {0} are invalid. The {1} exception was returned with error message: {2} + */ + BAD_PARAMETER(400, "OMAG-GENERIC-HANDLERS-400-012", + "At least one of the properties supplied for a new relationship of type {0} are invalid. The {1} exception was returned with error message: {2}", + "The system is unable to create the requested relationship because it can not parse the properties.", + "Correct the caller's logic so that the properties passed are correctly formatted and retry the request."), + + ONLY_CREATOR_CAN_DELETE(403, "OMAG-GENERIC-HANDLERS-403-001", "The {0} method is unable to delete the requested relationship between {1} {2} and {3} {4} because it " + "was not created by the requesting user {5}", @@ -233,7 +242,7 @@ public enum GenericHandlersErrorCode implements ExceptionMessageSet ; - private ExceptionMessageDefinition messageDefinition; + private final ExceptionMessageDefinition messageDefinition; /** diff --git a/open-metadata-implementation/framework-services/ocf-metadata-management/ocf-metadata-client/src/main/java/org/odpi/openmetadata/frameworkservices/ocf/metadatamanagement/client/ConnectedAssetClientBase.java b/open-metadata-implementation/framework-services/ocf-metadata-management/ocf-metadata-client/src/main/java/org/odpi/openmetadata/frameworkservices/ocf/metadatamanagement/client/ConnectedAssetClientBase.java index 336687708ee..217722a93fe 100644 --- a/open-metadata-implementation/framework-services/ocf-metadata-management/ocf-metadata-client/src/main/java/org/odpi/openmetadata/frameworkservices/ocf/metadatamanagement/client/ConnectedAssetClientBase.java +++ b/open-metadata-implementation/framework-services/ocf-metadata-management/ocf-metadata-client/src/main/java/org/odpi/openmetadata/frameworkservices/ocf/metadatamanagement/client/ConnectedAssetClientBase.java @@ -60,7 +60,6 @@ public ConnectedAssetClientBase(String serverName, this.auditLog = auditLog; this.ocfrestClient = new OCFRESTClient(serverName, serverPlatformURLRoot, auditLog); - } diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-manager-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/fvt/dataassets/CreateDatabaseTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-manager-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/fvt/dataassets/CreateDatabaseTest.java index f8a9ac55b25..348d5ba24f1 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-manager-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/fvt/dataassets/CreateDatabaseTest.java +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-manager-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetmanager/fvt/dataassets/CreateDatabaseTest.java @@ -383,7 +383,7 @@ private DataAssetExchangeClient getDataAssetExchangeClient(String serverName, String serverPlatformRootURL, AuditLog auditLog) throws FVTUnexpectedCondition { - final String activityName = "getDatabaseManagerClient"; + final String activityName = "getAssetOwnerClient"; try { diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-manager-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetmanager/fvt/execution/AssetManagerOMASCreateSchemasIT.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-manager-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetmanager/fvt/execution/AssetManagerOMASCreateSchemasIT.java index 1c146342c02..e444232759d 100644 --- a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-manager-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetmanager/fvt/execution/AssetManagerOMASCreateSchemasIT.java +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-manager-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetmanager/fvt/execution/AssetManagerOMASCreateSchemasIT.java @@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** - * AssetManagerOMASCreateSchemasIT is the failsafe wrapper for CreateDatabaseTest and CreateSchemasTest. + * AssetManagerOMASCreateSchemasIT is the failsafe wrapper for CreateSchemasTest. */ public class AssetManagerOMASCreateSchemasIT { diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/CreateDatabaseTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/CreateDatabaseTest.java new file mode 100644 index 00000000000..69e01b727f0 --- /dev/null +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/CreateDatabaseTest.java @@ -0,0 +1,1318 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.fvt.dataassets; + +import org.odpi.openmetadata.accessservices.assetowner.client.AssetOwner; +import org.odpi.openmetadata.accessservices.assetowner.client.rest.AssetOwnerRESTClient; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.AssetElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.MetadataElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.RelationshipElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaAttributeElement; +import org.odpi.openmetadata.accessservices.assetowner.properties.AssetProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.SchemaAttributeProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.SchemaTypeProperties; +import org.odpi.openmetadata.adminservices.configuration.registration.AccessServiceDescription; +import org.odpi.openmetadata.frameworks.auditlog.AuditLog; +import org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException; +import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementClassification; +import org.odpi.openmetadata.fvt.utilities.FVTResults; +import org.odpi.openmetadata.fvt.utilities.auditlog.FVTAuditLogDestination; +import org.odpi.openmetadata.fvt.utilities.exceptions.FVTUnexpectedCondition; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * CreateDatabaseTest calls the AssetOwner client to create a database with schemas tables and columns + * and then retrieve the results. + */ +public class CreateDatabaseTest +{ + private final static String testCaseName = "CreateDatabaseTest"; + + private final static int maxPageSize = 100; + + + private final static String databaseName = "TestDatabase"; + private final static String databaseDisplayName = "Database displayName"; + private final static String databaseDescription = "Database description"; + private final static String databaseType = "Database type"; + private final static String databaseVersion = "Database version"; + + private final static String databaseSchemaName = "TestDatabaseSchema"; + private final static String databaseSchemaDisplayName = "DatabaseSchema displayName"; + private final static String databaseSchemaDescription = "DatabaseSchema description"; + + private final static String databaseTableName = "TestDatabaseTable"; + private final static String databaseTableDisplayName = "DatabaseTable displayName"; + private final static String databaseTableDescription = "DatabaseTable description"; + + + private final static String databaseColumnName = "TestDatabaseColumn"; + private final static String databaseColumnDisplayName = "DatabaseColumn displayName"; + private final static String databaseColumnDescription = "DatabaseColumn description"; + private final static String databaseColumnType = "string"; + + private final static String databaseColumnTwoName = "TestDatabaseColumn2"; + private final static String databaseColumnTwoDisplayName = "DatabaseColumn2 displayName"; + private final static String databaseColumnTwoDescription = "DatabaseColumn2 description"; + private final static String databaseColumnTwoType = "date"; + + + /** + * Run all the defined tests and capture the results. + * + * @param serverName name of the server to connect to + * @param serverPlatformRootURL the network address of the server running the OMAS REST servers + * @param userId calling user + * @return results of running test + */ + public static FVTResults performFVT(String serverName, + String serverPlatformRootURL, + String userId) + { + FVTResults results = new FVTResults(testCaseName); + + results.incrementNumberOfTests(); + try + { + CreateDatabaseTest.runIt(serverPlatformRootURL, serverName, userId, results.getAuditLogDestination()); + results.incrementNumberOfSuccesses(); + } + catch (Exception error) + { + results.addCapturedError(error); + } + + return results; + } + + + /** + * Run all the tests in this class. + * + * @param serverPlatformRootURL root url of the server + * @param serverName name of the server + * @param userId calling user + * @param auditLogDestination logging destination + * @throws FVTUnexpectedCondition the test case failed + */ + private static void runIt(String serverPlatformRootURL, + String serverName, + String userId, + FVTAuditLogDestination auditLogDestination) throws FVTUnexpectedCondition + { + CreateDatabaseTest thisTest = new CreateDatabaseTest(); + + AuditLog auditLog = new AuditLog(auditLogDestination, + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceCode(), + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceDevelopmentStatus(), + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceName(), + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceDescription(), + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceWiki()); + + AssetOwner client = thisTest.getAssetOwnerClient(serverName, serverPlatformRootURL, auditLog); + + String databaseGUID = thisTest.getDatabase(client, userId); + String databaseSchemaGUID = thisTest.getDatabaseSchema(client, databaseGUID, userId); + String databaseTableGUID = thisTest.createDatabaseTable(client, databaseSchemaGUID, userId); + String databaseColumnGUID = thisTest.createDatabaseColumn(client, databaseSchemaGUID, databaseTableGUID, userId); + + String activityName = "cascadedDelete - remove Database"; + + System.out.println("activityName = " + activityName); + System.out.println("databaseGUID = " + databaseGUID); + System.out.println("databaseSchemaGUID = " + databaseSchemaGUID); + System.out.println("databaseTableGUID = " + databaseTableGUID); + System.out.println("databaseColumnGUID = " + databaseColumnGUID); + + /* + * Check that all elements are deleted when the database is deleted. + */ + try + { + client.deleteAsset(userId, databaseGUID); + + thisTest.checkDatabaseGone(client, databaseGUID, activityName, userId); + thisTest.checkDatabaseColumnOK(client, databaseColumnGUID, databaseTableGUID, activityName, userId); + thisTest.checkDatabaseTableOK(client, databaseTableGUID, activityName, userId); + thisTest.checkDatabaseSchemaOK(client, databaseSchemaGUID, null, activityName, userId); + + activityName = "cascadedDelete - remove DatabaseSchema"; + + client.deleteAsset(userId, databaseSchemaGUID); + + thisTest.checkDatabaseSchemaGone(client, databaseSchemaGUID, null, activityName, userId); + thisTest.checkDatabaseTableGone(client, databaseTableGUID, activityName, userId); + thisTest.checkDatabaseColumnGone(client, databaseColumnGUID, null, activityName, userId); + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + + + /* + * Recreate database + */ + activityName= "deleteOneByOne"; + + System.out.println("activityName = " + activityName); + databaseGUID = thisTest.getDatabase(client, userId); + databaseSchemaGUID = thisTest.getDatabaseSchema(client, databaseGUID, userId); + databaseTableGUID = thisTest.createDatabaseTable(client, databaseSchemaGUID, userId); + databaseColumnGUID = thisTest.createDatabaseColumn(client, databaseSchemaGUID, databaseTableGUID, userId); + + System.out.println("databaseGUID = " + databaseGUID); + System.out.println("databaseSchemaGUID = " + databaseSchemaGUID); + System.out.println("databaseTableGUID = " + databaseTableGUID); + System.out.println("databaseColumnGUID = " + databaseColumnGUID); + + + /* + * Check that elements can be deleted one by one + */ + + try + { + activityName = "deleteOneByOne - pre-validate"; + thisTest.checkDatabaseColumnOK(client, databaseColumnGUID, databaseTableGUID, activityName, userId); + thisTest.checkDatabaseTableOK(client, databaseTableGUID, activityName, userId); + thisTest.checkDatabaseSchemaOK(client, databaseSchemaGUID, databaseGUID, activityName, userId); + thisTest.checkDatabaseOK(client, databaseGUID, activityName, userId); + + client.removeSchemaAttribute(userId, databaseColumnGUID); + + activityName = "deleteOneByOne - column gone"; + thisTest.checkDatabaseColumnGone(client, databaseColumnGUID, databaseTableGUID, activityName, userId); + + activityName = "deleteOneByOne - column gone - check table: " + databaseTableGUID; + + thisTest.checkDatabaseTableOK(client, databaseTableGUID, activityName, userId); + + activityName = "deleteOneByOne - column gone - check schema"; + + thisTest.checkDatabaseSchemaOK(client, databaseSchemaGUID, databaseGUID, activityName, userId); + + activityName = "deleteOneByOne - column gone - check DB"; + + thisTest.checkDatabaseOK(client, databaseGUID, activityName, userId); + + activityName = "deleteOneByOne - remove table"; + + client.removeSchemaAttribute(userId, databaseTableGUID); + + activityName = "deleteOneByOne - table gone"; + thisTest.checkDatabaseTableGone(client, databaseTableGUID, activityName, userId); + thisTest.checkDatabaseSchemaOK(client, databaseSchemaGUID, databaseGUID, activityName, userId); + thisTest.checkDatabaseOK(client, databaseGUID, activityName, userId); + + client.deleteAsset(userId, databaseSchemaGUID); + + activityName = "deleteOneByOne - schema gone"; + thisTest.checkDatabaseSchemaGone(client, databaseSchemaGUID, databaseGUID, activityName, userId); + thisTest.checkDatabaseOK(client, databaseGUID, activityName, userId); + + client.deleteAsset(userId, databaseGUID); + + activityName = "deleteOneByOne - database gone"; + thisTest.checkDatabaseGone(client, databaseGUID, activityName, userId); + + /* + * Recreate database + */ + activityName= "deleteOneByOne"; + + databaseGUID = thisTest.getDatabase(client, userId); + databaseSchemaGUID = thisTest.getDatabaseSchema(client, databaseGUID, userId); + databaseTableGUID = thisTest.createDatabaseTable(client, databaseSchemaGUID, userId); + databaseColumnGUID = thisTest.createDatabaseColumn(client, databaseSchemaGUID, databaseTableGUID, userId); + + System.out.println("databaseGUID = " + databaseGUID); + System.out.println("databaseSchemaGUID = " + databaseSchemaGUID); + System.out.println("databaseTableGUID = " + databaseTableGUID); + System.out.println("databaseColumnGUID = " + databaseColumnGUID); + + /* + * Update tests + */ + activityName = "updateNonExistentColumn"; + + String databaseColumnTwoGUID = "Blah Blah"; + SchemaAttributeProperties databaseColumnTwoProperties = new SchemaAttributeProperties(); + databaseColumnTwoProperties.setQualifiedName(databaseColumnTwoName); + databaseColumnTwoProperties.setDisplayName(databaseColumnDisplayName); // Note wrong value + databaseColumnTwoProperties.setDescription(databaseColumnTwoDescription); + + SchemaTypeProperties attributeType = new SchemaTypeProperties(); + attributeType.setTypeName("PrimitiveSchemaType"); + databaseColumnTwoProperties.setAttributeType(attributeType); + + + try + { + + client.updateSchemaAttribute(userId, databaseColumnTwoGUID, true, databaseColumnTwoProperties); + throw new FVTUnexpectedCondition(testCaseName, activityName); + } + catch (InvalidParameterException expectedError) + { + // very good + } + + activityName = "updateColumnWithSameProperties"; + + databaseColumnTwoGUID = client.addSchemaAttribute(userId, databaseSchemaGUID, databaseTableGUID, databaseColumnTwoProperties); + + SchemaAttributeElement beforeElement = client.getSchemaAttributeByGUID(userId, databaseColumnTwoGUID); + + client.updateSchemaAttribute(userId, databaseColumnTwoGUID, true, databaseColumnTwoProperties); + + SchemaAttributeElement afterElement = client.getSchemaAttributeByGUID(userId, databaseColumnTwoGUID); + + /* + * No change should occur in the version number because the properties are not different. + */ + if (! beforeElement.getElementHeader().getVersions().equals(afterElement.getElementHeader().getVersions())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(version changed from " + beforeElement.getElementHeader().getVersions() + " to " + afterElement.getElementHeader().getVersions() + ")"); + } + + activityName = "updateColumnClassificationProperties"; + + /* + * This change effects the classification of the column + */ + SchemaTypeProperties schemaType = new SchemaTypeProperties(); + + Map extendedProperties = new HashMap<>(); + + extendedProperties.put("dataType", databaseColumnTwoType); + + schemaType.setExtendedProperties(extendedProperties); + databaseColumnTwoProperties.setAttributeType(schemaType); + client.updateSchemaAttribute(userId, databaseColumnTwoGUID, true, databaseColumnTwoProperties); + + afterElement = client.getSchemaAttributeByGUID(userId, databaseColumnTwoGUID); + + /* + * No change should occur in the version number because the entity properties are not different. + */ + if (! beforeElement.getElementHeader().getVersions().equals(afterElement.getElementHeader().getVersions())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(version changed from " + beforeElement.getElementHeader().getVersions() + " to " + afterElement.getElementHeader().getVersions() + ")"); + } + + Object dataType = afterElement.getSchemaAttributeProperties().getAttributeType().getExtendedProperties().get("dataType"); + if (! databaseColumnTwoType.equals(dataType)) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(data type should be " + databaseColumnTwoType + " rather than " + dataType + "). Returned element: " + afterElement); + } + + /* + * This change affects the entity + */ + activityName = "updateColumnProperties"; + + databaseColumnTwoProperties.setDisplayName(databaseColumnTwoDisplayName); + + client.updateSchemaAttribute(userId, databaseColumnTwoGUID, true, databaseColumnTwoProperties); + + afterElement = client.getSchemaAttributeByGUID(userId, databaseColumnTwoGUID); + + /* + * The change should have taken effect. + */ + if (beforeElement.getElementHeader().getVersions().equals(afterElement.getElementHeader().getVersions())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(version did not change from " + beforeElement.getElementHeader().getVersions() + ")"); + } + + if (! databaseColumnTwoDisplayName.equals(afterElement.getSchemaAttributeProperties().getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(display name should be " + databaseColumnTwoDisplayName + " rather than " + afterElement.getSchemaAttributeProperties().getDisplayName() + ")"); + } + + /* + * Check that all elements are deleted when the database is deleted. + */ + activityName = "cascadedDelete"; + try + { + client.deleteAsset(userId, databaseGUID); + + thisTest.checkDatabaseGone(client, databaseGUID, activityName, userId); + + client.deleteAsset(userId, databaseSchemaGUID); + + thisTest.checkDatabaseSchemaGone(client, databaseSchemaGUID, null, activityName, userId); + thisTest.checkDatabaseTableGone(client, databaseTableGUID, activityName, userId); + thisTest.checkDatabaseColumnGone(client, databaseColumnGUID, null, activityName, userId); + thisTest.checkDatabaseColumnGone(client, databaseColumnTwoGUID, null, activityName, userId); + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Create and return a client. + * + * @param serverName name of the server to connect to + * @param serverPlatformRootURL the network address of the server running the OMAS REST servers + * @param auditLog logging destination + * @return client + * @throws FVTUnexpectedCondition the test case failed + */ + private AssetOwner getAssetOwnerClient(String serverName, + String serverPlatformRootURL, + AuditLog auditLog) throws FVTUnexpectedCondition + { + final String activityName = "getAssetOwnerClient"; + + try + { + AssetOwnerRESTClient restClient = new AssetOwnerRESTClient(serverName, serverPlatformRootURL); + + return new AssetOwner(serverName, serverPlatformRootURL, restClient, maxPageSize, auditLog); + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a database is gone. + * + * @param client interface to Asset Owner OMAS + * @param databaseGUID unique id of the database to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkDatabaseGone(AssetOwner client, + String databaseGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + AssetElement retrievedElement = client.getAssetSummary(userId, databaseGUID); + + if (retrievedElement != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Database returned from Retrieve)"); + } + + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Retrieve returned)"); + } + catch (InvalidParameterException expectedException) + { + // all ok + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + + /** + * Check database is ok. + * + * @param client interface to Asset Owner OMAS + * @param databaseGUID unique id of the database + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkDatabaseOK(AssetOwner client, + String databaseGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + AssetElement retrievedElement = client.getAssetSummary(userId, databaseGUID); + + if (retrievedElement == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no DatabaseElement from Retrieve)"); + } + + AssetProperties retrievedDatabase = retrievedElement.getAssetProperties(); + + if (retrievedDatabase == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no DatabaseProperties from Retrieve)"); + } + + if (! databaseName.equals(retrievedDatabase.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad qualifiedName from Retrieve)"); + } + if (! databaseDisplayName.equals(retrievedDatabase.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad displayName from Retrieve)"); + } + if (! databaseDescription.equals(retrievedDatabase.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad description from Retrieve)"); + } + + Map databaseExtendedProperties = retrievedDatabase.getExtendedProperties(); + + if (! databaseType.equals(databaseExtendedProperties.get("deployedImplementationType"))) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad databaseType from Retrieve). Retrieve Element: " + retrievedDatabase); + } + if (! databaseVersion.equals(databaseExtendedProperties.get("databaseVersion"))) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad databaseVersion from Retrieve). Retrieve Element: " + retrievedDatabase); + } + + List databaseList = client.getAssetsByName(userId, databaseName, 0, maxPageSize); + + if (databaseList == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no Database for RetrieveByName)"); + } + else if (databaseList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Empty Database list for RetrieveByName)"); + } + else if (databaseList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + "(Database list for RetrieveByName contains" + databaseList.size() + + " elements)"); + } + + retrievedElement = databaseList.get(0); + retrievedDatabase = retrievedElement.getAssetProperties(); + + if (! databaseName.equals(retrievedDatabase.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad qualifiedName from RetrieveByName)"); + } + if (! databaseDisplayName.equals(retrievedDatabase.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad displayName from RetrieveByName)"); + } + if (! databaseDescription.equals(retrievedDatabase.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad description from RetrieveByName)"); + } + + databaseExtendedProperties = retrievedDatabase.getExtendedProperties(); + + if (! databaseType.equals(databaseExtendedProperties.get("deployedImplementationType"))) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad databaseType from RetrieveByName). Retrieve Element: " + retrievedDatabase); + } + if (! databaseVersion.equals(databaseExtendedProperties.get("databaseVersion"))) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad databaseVersion from RetrieveByName). Retrieve Element: " + retrievedDatabase); + } + + databaseList = client.getAssetsByName(userId, databaseName, 1, maxPageSize); + + if (databaseList != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no Database for RetrieveByName)"); + } + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Create a database and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param userId calling user + * @return GUID of database + * @throws FVTUnexpectedCondition the test case failed + */ + private String getDatabase(AssetOwner client, + String userId) throws FVTUnexpectedCondition + { + final String activityName = "getDatabase"; + + try + { + AssetProperties properties = new AssetProperties(); + + properties.setQualifiedName(databaseName); + properties.setDisplayName(databaseDisplayName); + properties.setDescription(databaseDescription); + + properties.setTypeName("Database"); + + Map extendedProperties = new HashMap<>(); + extendedProperties.put("deployedImplementationType", databaseType); + extendedProperties.put("databaseVersion" , databaseVersion); + properties.setExtendedProperties(extendedProperties); + + String databaseGUID = client.addAssetToCatalog(userId, properties); + + if (databaseGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for Create)"); + } + else + { + checkDatabaseOK(client, databaseGUID, activityName, userId); + } + + return databaseGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a database column is gone. + * + * @param client interface to Asset Owner OMAS + * @param databaseSchemaGUID unique id of the database schema to test + * @param databaseGUID unique id of the database to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkDatabaseSchemaGone(AssetOwner client, + String databaseSchemaGUID, + String databaseGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + AssetElement retrievedElement = client.getAssetSummary(userId, databaseSchemaGUID); + + if (retrievedElement != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(DatabaseSchema returned from Retrieve)"); + } + + throw new FVTUnexpectedCondition(testCaseName, activityName + "(getDatabaseSchemaByGUID returned"); + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (InvalidParameterException expectedError) + { + // all ok + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + + if (databaseGUID != null) + { + try + { + /* + * Only one schema created so nothing should be tied to the database. + */ + List relationshipList = client.getRelatedAssetsAtEnd2(userId, "DataContentForDataSet", databaseGUID, 0, maxPageSize); + + if (relationshipList != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(No DatabaseSchema returned for getSchemasForDatabase)"); + } + } + catch(FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch(Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + } + + + /** + * Check a database schema is correctly stored. + * + * @param client interface to Asset Owner OMAS + * @param databaseSchemaGUID unique id of the database schema + * @param databaseGUID unique id of the database + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkDatabaseSchemaOK(AssetOwner client, + String databaseSchemaGUID, + String databaseGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + AssetElement retrievedElement = client.getAssetSummary(userId, databaseSchemaGUID); + + if (retrievedElement == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no DatabaseSchemaElement from Retrieve)"); + } + + validateAnchorGUID(activityName, retrievedElement); + + AssetProperties retrievedSchema = retrievedElement.getAssetProperties(); + + if (retrievedSchema == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no DatabaseSchemaProperties from Retrieve)"); + } + + if (! databaseSchemaName.equals(retrievedSchema.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad qualifiedName from Retrieve)"); + } + if (! databaseSchemaDisplayName.equals(retrievedSchema.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad displayName from Retrieve)"); + } + if (! databaseSchemaDescription.equals(retrievedSchema.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad description from Retrieve)"); + } + + + List databaseSchemaList = client.getAssetsByName(userId, databaseSchemaName, 0, maxPageSize); + + if (databaseSchemaList == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no DatabaseSchema for RetrieveByName)"); + } + else if (databaseSchemaList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Empty DatabaseSchema list for RetrieveByName)"); + } + else if (databaseSchemaList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + "(DatabaseSchema list for RetrieveByName contains" + databaseSchemaList.size() + + " elements)"); + } + + retrievedElement = databaseSchemaList.get(0); + retrievedSchema = retrievedElement.getAssetProperties(); + + if (! databaseSchemaName.equals(retrievedSchema.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad qualifiedName from RetrieveByName)"); + } + if (! databaseSchemaDisplayName.equals(retrievedSchema.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad displayName from RetrieveByName)"); + } + if (! databaseSchemaDescription.equals(retrievedSchema.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad description from RetrieveByName)"); + } + + if (databaseGUID != null) + { + List relationshipElements = client.getRelatedAssetsAtEnd2(userId, "DataContentForDataSet", databaseGUID, 0, maxPageSize); + + if (relationshipElements == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no DatabaseSchema for getSchemasForDatabase)"); + } + else if (databaseSchemaList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Empty DatabaseSchema list for getSchemasForDatabase)"); + } + else if (databaseSchemaList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + "(DatabaseSchema list for getSchemasForDatabase contains" + databaseSchemaList.size() + + " elements)"); + } + } + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Create a database schema and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param databaseGUID unique id of the database + * @param userId calling user + * @return GUID of database + * @throws FVTUnexpectedCondition the test case failed + */ + private String getDatabaseSchema(AssetOwner client, + String databaseGUID, + String userId) throws FVTUnexpectedCondition + { + final String activityName = "getDatabaseSchema"; + + try + { + AssetProperties properties = new AssetProperties(); + + properties.setQualifiedName(databaseSchemaName); + properties.setDisplayName(databaseSchemaDisplayName); + properties.setDescription(databaseSchemaDescription); + properties.setTypeName("DeployedDatabaseSchema"); + + String databaseSchemaGUID = client.addAssetToCatalog(userId, properties); + + client.setupRelatedAsset(userId, "DataContentForDataSet", databaseGUID, databaseSchemaGUID, null); + + if (databaseSchemaGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for schemaCreate)"); + } + else + { + checkDatabaseSchemaOK(client, databaseSchemaGUID, databaseGUID, activityName, userId); + } + + return databaseSchemaGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a database table is gone. + * + * @param client interface to Asset Owner OMAS + * @param databaseTableGUID unique id of the database table to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkDatabaseTableGone(AssetOwner client, + String databaseTableGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + SchemaAttributeElement retrievedElement = client.getSchemaAttributeByGUID(userId, databaseTableGUID); + + if (retrievedElement != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(DatabaseTable returned from Retrieve)"); + } + + throw new FVTUnexpectedCondition(testCaseName, activityName + "(getDatabaseTableByGUID returned"); + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (InvalidParameterException expectedError) + { + // all ok + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a database table is stored OK. + * + * @param client interface to Asset Owner OMAS + * @param databaseTableGUID unique id of the databaseSchema + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkDatabaseTableOK(AssetOwner client, + String databaseTableGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + + try + { + SchemaAttributeElement retrievedElement = client.getSchemaAttributeByGUID(userId, databaseTableGUID); + + validateDatabaseTable(activityName + "(getSchemaAttributeByGUID)", retrievedElement); + + List databaseTableList = client.getSchemaAttributesByName(userId, databaseTableName, 0, maxPageSize); + + validateDatabaseTableList(activityName + "(getSchemaAttributesByName)", databaseTableList); + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + private void validateDatabaseTableList(String activityName, + List databaseTableList) throws FVTUnexpectedCondition + { + + if (databaseTableList == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - no DatabaseTable"); + } + else if (databaseTableList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Empty DatabaseTable list"); + } + else if (databaseTableList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + " - DatabaseTable list contains " + databaseTableList.size() + " elements)"); + } + + validateDatabaseTable(activityName, databaseTableList.get(0)); + } + + + private void validateDatabaseTable(String activityName, + SchemaAttributeElement retrievedElement) throws FVTUnexpectedCondition + { + if (retrievedElement == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - no DatabaseTableElement"); + } + + System.out.println("Database Table: " + retrievedElement); + + SchemaAttributeProperties retrievedTable = retrievedElement.getSchemaAttributeProperties(); + + if (retrievedTable == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - no DatabaseTableProperties"); + } + + if (! databaseTableName.equals(retrievedTable.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad qualifiedName: " + retrievedTable.getQualifiedName() + " rather than " + databaseTableName); + } + if (! databaseTableDisplayName.equals(retrievedTable.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad displayName: " + retrievedTable.getDisplayName() + " rather than " + databaseTableDisplayName); + } + if (! databaseTableDescription.equals(retrievedTable.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad description: " + retrievedTable.getDescription() + " rather than " + databaseTableDescription); + } + + validateAnchorGUID(activityName, retrievedElement); + } + + + /** + * Create a database table and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param databaseSchemaGUID unique id of the databaseSchema + * @param userId calling user + * @return GUID of database + * @throws FVTUnexpectedCondition the test case failed + */ + private String createDatabaseTable(AssetOwner client, + String databaseSchemaGUID, + String userId) throws FVTUnexpectedCondition + { + final String activityName = "createDatabaseTable"; + + try + { + SchemaTypeProperties schemaTypeProperties = new SchemaTypeProperties(); + schemaTypeProperties.setTypeName("RelationalDBSchemaType"); + schemaTypeProperties.setQualifiedName("SchemaOf:" + databaseSchemaName); + + String databaseSchemaTypeGUID = client.createAnchoredSchemaType(userId, databaseSchemaGUID, schemaTypeProperties); + + client.setupSchemaTypeParent(userId, databaseSchemaTypeGUID, databaseSchemaGUID, "Asset", null); + + SchemaAttributeProperties properties = new SchemaAttributeProperties(); + + properties.setQualifiedName(databaseTableName); + properties.setDisplayName(databaseTableDisplayName); + properties.setDescription(databaseTableDescription); + properties.setTypeName("RelationalTable"); + + SchemaTypeProperties attributeType = new SchemaTypeProperties(); + attributeType.setTypeName("RelationalTableType"); + properties.setAttributeType(attributeType); + + String databaseTableGUID = client.addSchemaAttribute(userId, databaseSchemaGUID, databaseSchemaTypeGUID, properties); + + if (databaseTableGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for tableCreate)"); + } + else + { + checkDatabaseTableOK(client, databaseTableGUID, activityName, userId); + } + + return databaseTableGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Create a database table and attach it to the supplied schema type and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param databaseSchemaGUID unique id of the databaseSchema + * @param databaseSchemaTypeGUID unique id of the databaseSchemaType + * @param userId calling user + * @return GUID of database + * @throws FVTUnexpectedCondition the test case failed + */ + private String createDatabaseTableForSchemaType(AssetOwner client, + String databaseSchemaGUID, + String databaseSchemaTypeGUID, + String userId) throws FVTUnexpectedCondition + { + final String activityName = "createDatabaseTableForSchemaType"; + + try + { + SchemaAttributeProperties properties = new SchemaAttributeProperties(); + + properties.setQualifiedName(databaseTableName); + properties.setDisplayName(databaseTableDisplayName); + properties.setDescription(databaseTableDescription); + properties.setTypeName("RelationalTable"); + + SchemaTypeProperties attributeType = new SchemaTypeProperties(); + attributeType.setTypeName("RelationalTableType"); + properties.setAttributeType(attributeType); + + String databaseTableGUID = client.addSchemaAttribute(userId, databaseSchemaGUID, databaseSchemaTypeGUID, properties); + + if (databaseTableGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for tableCreate)"); + } + else + { + checkDatabaseTableOK(client, databaseTableGUID, activityName, userId); + } + + return databaseTableGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a database column is gone. + * + * @param client interface to Asset Owner OMAS + * @param databaseColumnGUID unique id of the database column to test + * @param databaseTableGUID unique id of the database table to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkDatabaseColumnGone(AssetOwner client, + String databaseColumnGUID, + String databaseTableGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + SchemaAttributeElement retrievedElement = client.getSchemaAttributeByGUID(userId, databaseColumnGUID); + + if (retrievedElement != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(DatabaseColumn returned from Retrieve)"); + } + + throw new FVTUnexpectedCondition(testCaseName, activityName + "(getDatabaseColumnByGUID returned"); + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (InvalidParameterException expectedError) + { + // all ok + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + + if (databaseTableGUID != null) + { + try + { + /* + * Only one column created so nothing should be tied to the table. + */ + List databaseColumnList = client.getNestedSchemaAttributes(userId, databaseTableGUID, 0, maxPageSize); + + if (databaseColumnList != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(DatabaseColumn returned for getColumnsForDatabaseTable)"); + } + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + } + + + /** + * Check that the database column is ok. + * + * @param client interface to Asset Owner OMAS + * @param databaseColumnGUID unique id of the database column to test + * @param databaseTableGUID unique id of the database table to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkDatabaseColumnOK(AssetOwner client, + String databaseColumnGUID, + String databaseTableGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + SchemaAttributeElement retrievedElement = client.getSchemaAttributeByGUID(userId, databaseColumnGUID); + + validateColumn(activityName + "(getSchemaAttributeByGUID)", retrievedElement); + + List databaseColumnList = client.getSchemaAttributesByName(userId, databaseColumnName, 0, maxPageSize); + + validateColumnList(activityName + "(getSchemaAttributesByName)", databaseColumnList); + + databaseColumnList = client.getNestedSchemaAttributes(userId, databaseTableGUID, 0, maxPageSize); + + validateColumnList(activityName + "(getColumnsForDatabaseTable)", databaseColumnList); + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + private void validateColumnList(String activityName, + List databaseColumnList) throws FVTUnexpectedCondition + { + if (databaseColumnList == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "- no DatabaseColumn List"); + } + else if (databaseColumnList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Empty DatabaseColumn list"); + } + else if (databaseColumnList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(DatabaseColumn list contains" + databaseColumnList.size() + " elements)"); + } + + this.validateColumn(activityName, databaseColumnList.get(0)); + } + + + private void validateColumn(String activityName, + SchemaAttributeElement retrievedElement) throws FVTUnexpectedCondition + { + if (retrievedElement == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "- no DatabaseColumnElement"); + } + + System.out.println("Database Column: " + retrievedElement); + + SchemaAttributeProperties retrievedColumn = retrievedElement.getSchemaAttributeProperties(); + + if (retrievedColumn == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "- no DatabaseColumnProperties"); + } + + if (! databaseColumnName.equals(retrievedColumn.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad qualifiedName: " + retrievedColumn.getQualifiedName() + " rather than " + databaseColumnName); + } + if (! databaseColumnDisplayName.equals(retrievedColumn.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad displayName: " + retrievedColumn.getDisplayName() + " rather than " + databaseColumnDisplayName); + } + if (! databaseColumnDescription.equals(retrievedColumn.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad description: " + retrievedColumn.getDescription() + " rather than " + databaseColumnDescription); + } + + validateAnchorGUID(activityName, retrievedElement); + } + + + /** + * Create a database column and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param databaseSchemaGUID unique id of the database schema that is the anchor + * @param databaseTableGUID unique id of the database table to connect the column to + * @param userId calling user + * @return GUID of database + * @throws FVTUnexpectedCondition the test case failed + */ + private String createDatabaseColumn(AssetOwner client, + String databaseSchemaGUID, + String databaseTableGUID, + String userId) throws FVTUnexpectedCondition + { + final String activityName = "createDatabaseColumn"; + + try + { + SchemaAttributeProperties properties = new SchemaAttributeProperties(); + + properties.setQualifiedName(databaseColumnName); + properties.setDisplayName(databaseColumnDisplayName); + properties.setDescription(databaseColumnDescription); + properties.setTypeName("RelationalColumn"); + + SchemaTypeProperties schemaTypeProperties = new SchemaTypeProperties(); + + Map extendedProperties = new HashMap<>(); + + extendedProperties.put("dataType", databaseColumnType); + + schemaTypeProperties.setTypeName("PrimitiveSchemaType"); + schemaTypeProperties.setQualifiedName("SchemaType:" + databaseColumnName); + schemaTypeProperties.setExtendedProperties(extendedProperties); + + properties.setAttributeType(schemaTypeProperties); + + String databaseColumnGUID = client.addSchemaAttribute(userId, databaseSchemaGUID, databaseTableGUID, properties); + + if (databaseColumnGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for columnCreate)"); + } + else + { + checkDatabaseColumnOK(client, databaseColumnGUID, databaseTableGUID, activityName, userId); + } + + return databaseColumnGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + private void validateAnchorGUID(String activityName, + MetadataElement metadataElement) + { + if (metadataElement.getElementHeader() != null) + { + if (metadataElement.getElementHeader().getClassifications() != null) + { + for (ElementClassification classification : metadataElement.getElementHeader().getClassifications()) + { + if ("Anchors".equals(classification.getClassificationName())) + { + System.out.println(metadataElement.getElementHeader().getType().getTypeName() + " element " + metadataElement.getElementHeader().getGUID() + " has anchor of " + classification.getClassificationProperties() + " in activity " + activityName); + } + } + } + } + } +} diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/CreateSchemasTest.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/CreateSchemasTest.java new file mode 100644 index 00000000000..54aec0aebcd --- /dev/null +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/CreateSchemasTest.java @@ -0,0 +1,1159 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.fvt.dataassets; + +import org.odpi.openmetadata.accessservices.assetowner.client.AssetOwner; +import org.odpi.openmetadata.accessservices.assetowner.client.rest.AssetOwnerRESTClient; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.AssetElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.MetadataElement; +import org.odpi.openmetadata.accessservices.assetowner.metadataelements.SchemaTypeElement; +import org.odpi.openmetadata.accessservices.assetowner.properties.AssetProperties; +import org.odpi.openmetadata.accessservices.assetowner.properties.SchemaTypeProperties; +import org.odpi.openmetadata.adminservices.configuration.registration.AccessServiceDescription; +import org.odpi.openmetadata.frameworks.auditlog.AuditLog; +import org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException; +import org.odpi.openmetadata.frameworks.connectors.properties.beans.ElementClassification; +import org.odpi.openmetadata.fvt.utilities.FVTResults; +import org.odpi.openmetadata.fvt.utilities.auditlog.FVTAuditLogDestination; +import org.odpi.openmetadata.fvt.utilities.exceptions.FVTUnexpectedCondition; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * CreateSchemasTest builds complex schema structures. + */ +public class CreateSchemasTest +{ + private final static String testCaseName = "CreateSchemaTest"; + + private final static int maxPageSize = 100; + + private final static String assetName = "TestAsset"; + private final static String assetDisplayName = "Asset displayName"; + private final static String assetDescription = "Asset description"; + + private final static String optionSchemaName = "TestSchemaTypeOption"; + private final static String optionSchemaDisplayName = "TestSchemaTypeOption displayName"; + private final static String optionSchemaDescription = "TestSchemaTypeOption description"; + + private final static String primitive1Name = "TestPrimitive1"; + private final static String primitive1DisplayName = "TestPrimitive1 displayName"; + private final static String primitive1Description = "TestPrimitive1 description"; + private final static String primitive1DataType = "int"; + + + private final static String primitive2Name = "TestPrimitive2"; + private final static String primitive2DisplayName = "TestPrimitive2 displayName"; + private final static String primitive2Description = "TestPrimitive2 description"; + private final static String primitive2DataType = "string"; + + + private final static String mapName = "TestMap"; + private final static String mapDisplayName = "TestMap displayName"; + private final static String mapDescription = "TestMap description"; + + private final static String primitiveFromName = "TestPrimitiveFrom"; + private final static String primitiveFromDisplayName = "TestPrimitiveFrom displayName"; + private final static String primitiveFromDescription = "TestPrimitiveFrom description"; + private final static String primitiveFromType = "date"; + + private final static String primitiveToName = "TestPrimitiveTo"; + private final static String primitiveToDisplayName = "TestPrimitiveTo displayName"; + private final static String primitiveToDescription = "TestPrimitiveTo description"; + private final static String primitiveToType = "long"; + + + /** + * Run all the defined tests and capture the results. + * + * @param serverName name of the server to connect to + * @param serverPlatformRootURL the network address of the server running the OMAS REST servers + * @param userId calling user + * @return results of running test + */ + public static FVTResults performFVT(String serverName, + String serverPlatformRootURL, + String userId) + { + FVTResults results = new FVTResults(testCaseName); + + results.incrementNumberOfTests(); + try + { + CreateSchemasTest.runIt(serverPlatformRootURL, serverName, userId, results.getAuditLogDestination()); + results.incrementNumberOfSuccesses(); + } + catch (Exception error) + { + results.addCapturedError(error); + } + + return results; + } + + + /** + * Run all the tests in this class. + * + * @param serverPlatformRootURL root url of the server + * @param serverName name of the server + * @param userId calling user + * @param auditLogDestination logging destination + * @throws FVTUnexpectedCondition the test case failed + */ + private static void runIt(String serverPlatformRootURL, + String serverName, + String userId, + FVTAuditLogDestination auditLogDestination) throws FVTUnexpectedCondition + { + CreateSchemasTest thisTest = new CreateSchemasTest(); + + AuditLog auditLog = new AuditLog(auditLogDestination, + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceCode(), + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceDevelopmentStatus(), + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceName(), + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceDescription(), + AccessServiceDescription.ASSET_OWNER_OMAS.getAccessServiceWiki()); + + AssetOwner client = thisTest.getAssetOwnerClient(serverName, serverPlatformRootURL, auditLog); + + String assetGUID = thisTest.getAsset(client, userId); + String primitive1GUID = thisTest.createPrimitive(client, assetGUID, userId, primitive1Name, primitive1DisplayName, primitive1Description, primitive1DataType); + String primitive2GUID = thisTest.createPrimitive(client, assetGUID, userId, primitive2Name, primitive2DisplayName, primitive2Description, primitive2DataType); + String primitiveFromGUID = thisTest.createPrimitive(client, assetGUID, userId, primitiveFromName, primitiveFromDisplayName, primitiveFromDescription, primitiveFromType); + String primitiveToGUID = thisTest.createPrimitive(client, assetGUID, userId, primitiveToName, primitiveToDisplayName, primitiveToDescription, primitiveToType); + String mapGUID = thisTest.createMap(client, assetGUID, userId, primitiveFromGUID, primitiveToGUID); + + List optionGUIDs = new ArrayList<>(); + + optionGUIDs.add(primitive1GUID); + optionGUIDs.add(primitive2GUID); + optionGUIDs.add(mapGUID); + + String schemaOptionGUID = thisTest.getSchemaOption(client, assetGUID, userId, optionGUIDs); + + String activityName = "cascadedDelete"; + + System.out.println("activityName: " + activityName); + System.out.println("assetGUID: " + assetGUID); + System.out.println("schemaOptionGUID: " + schemaOptionGUID); + System.out.println("mapGUID: " + mapGUID); + System.out.println("primitive1GUID: " + primitive1GUID); + System.out.println("primitive2GUID: " + primitive2GUID); + System.out.println("primitiveFromGUID: " + primitiveFromGUID); + System.out.println("primitiveToGUID: " + primitiveToGUID); + + /* + * Check that all elements are deleted when the asset is deleted. + */ + try + { + client.deleteAsset(userId, assetGUID); + + thisTest.checkAssetGone(client, assetGUID, activityName, userId); + thisTest.checkSchemaOptionGone(client, schemaOptionGUID, null, activityName, userId); + thisTest.checkMapGone(client, mapGUID, activityName, userId); + thisTest.checkPrimitiveGone(client, primitive1GUID, activityName, userId); + thisTest.checkPrimitiveGone(client, primitive2GUID, activityName, userId); + thisTest.checkPrimitiveGone(client, primitiveFromGUID, activityName, userId); + thisTest.checkPrimitiveGone(client, primitiveToGUID, activityName, userId); + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + + + /* + * Recreate asset with schema + */ + activityName= "deleteOneByOne"; + + assetGUID = thisTest.getAsset(client, userId); + primitive1GUID = thisTest.createPrimitive(client, assetGUID, userId, primitive1Name, primitive1DisplayName, primitive1Description, primitive1DataType); + primitive2GUID = thisTest.createPrimitive(client, assetGUID, userId, primitive2Name, primitive2DisplayName, primitive2Description, primitive2DataType); + primitiveFromGUID = thisTest.createPrimitive(client, assetGUID, userId, primitiveFromName, primitiveFromDisplayName, primitiveFromDescription, primitiveFromType); + primitiveToGUID = thisTest.createPrimitive(client, assetGUID, userId, primitiveToName, primitiveToDisplayName, primitiveToDescription, primitiveToType); + mapGUID = thisTest.createMap(client, assetGUID, userId, primitiveFromGUID, primitiveToGUID); + + optionGUIDs = new ArrayList<>(); + + optionGUIDs.add(primitive1GUID); + optionGUIDs.add(primitive2GUID); + optionGUIDs.add(mapGUID); + + schemaOptionGUID = thisTest.getSchemaOption(client, assetGUID, userId, optionGUIDs); + + System.out.println("activityName: " + activityName); + System.out.println("assetGUID: " + assetGUID); + System.out.println("schemaOptionGUID: " + schemaOptionGUID); + System.out.println("mapGUID: " + mapGUID); + System.out.println("primitive1GUID: " + primitive1GUID); + System.out.println("primitive2GUID: " + primitive2GUID); + System.out.println("primitiveFromGUID: " + primitiveFromGUID); + System.out.println("primitiveToGUID: " + primitiveToGUID); + + /* + * Check that elements can be deleted one by one + */ + + try + { + client.removeSchemaType(userId, primitive1GUID); + + activityName = "deleteOneByOne - primitive 1 gone"; + thisTest.checkPrimitiveGone(client, primitive1GUID, activityName, userId); + thisTest.checkPrimitiveOK(client, primitive2GUID, activityName, userId, primitive2Name, primitive2DisplayName, primitive2Description, primitive2DataType); + thisTest.checkPrimitiveOK(client, primitiveFromGUID, activityName, userId, primitiveFromName, primitiveFromDisplayName, primitiveFromDescription, primitiveFromType); + thisTest.checkPrimitiveOK(client, primitiveToGUID, activityName, userId, primitiveToName, primitiveToDisplayName, primitiveToDescription, primitiveToType); + thisTest.checkMapOK(client, mapGUID, activityName, userId, primitiveFromGUID, primitiveToGUID); + optionGUIDs = new ArrayList<>(); + optionGUIDs.add(primitive2GUID); + optionGUIDs.add(mapGUID); + thisTest.checkSchemaOptionOK(client, schemaOptionGUID, activityName, userId, assetGUID, optionGUIDs); + thisTest.checkAssetOK(client, assetGUID, activityName, userId); + + client.removeSchemaType(userId, primitive2GUID); + + activityName = "deleteOneByOne - primitive 2 gone"; + thisTest.checkPrimitiveGone(client, primitive2GUID, activityName, userId); + thisTest.checkMapOK(client, mapGUID, activityName, userId, primitiveFromGUID, primitiveToGUID); + optionGUIDs = new ArrayList<>(); + optionGUIDs.add(mapGUID); + thisTest.checkSchemaOptionOK(client, schemaOptionGUID, activityName, userId, assetGUID, optionGUIDs); + thisTest.checkAssetOK(client, assetGUID, activityName, userId); + + client.removeSchemaType(userId, primitiveFromGUID); + + activityName = "deleteOneByOne - primitive From gone - " + primitiveFromGUID; + thisTest.checkPrimitiveGone(client, primitiveFromGUID, activityName, userId); + thisTest.checkMapOK(client, mapGUID, activityName, userId, null, primitiveToGUID); + thisTest.checkSchemaOptionOK(client, schemaOptionGUID, activityName, userId, assetGUID, optionGUIDs); + thisTest.checkAssetOK(client, assetGUID, activityName, userId); + + client.removeSchemaType(userId, primitiveToGUID); + + activityName = "deleteOneByOne - primitive To gone" + primitiveToGUID; + thisTest.checkPrimitiveGone(client, primitiveToGUID, activityName, userId); + thisTest.checkMapOK(client, mapGUID, activityName, userId, null, null); + thisTest.checkSchemaOptionOK(client, schemaOptionGUID, activityName, userId, assetGUID, optionGUIDs); + thisTest.checkAssetOK(client, assetGUID, activityName, userId); + + client.removeSchemaType(userId, mapGUID); + + activityName = "deleteOneByOne - map gone"; + thisTest.checkMapGone(client, mapGUID, activityName, userId); + thisTest.checkSchemaOptionOK(client, schemaOptionGUID, activityName, userId, assetGUID, null); + thisTest.checkAssetOK(client, assetGUID, activityName, userId); + + client.removeSchemaType(userId, schemaOptionGUID); + + activityName = "deleteOneByOne - schema option gone"; + thisTest.checkSchemaOptionGone(client, schemaOptionGUID, assetGUID, activityName, userId); + thisTest.checkAssetOK(client, assetGUID, activityName, userId); + + client.deleteAsset(userId, assetGUID); + + activityName = "deleteOneByOne - asset gone"; + thisTest.checkAssetGone(client, assetGUID, activityName, userId); + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Create and return a client. + * + * @param serverName name of the server to connect to + * @param serverPlatformRootURL the network address of the server running the OMAS REST servers + * @param auditLog logging destination + * @return client + * @throws FVTUnexpectedCondition the test case failed + */ + private AssetOwner getAssetOwnerClient(String serverName, + String serverPlatformRootURL, + AuditLog auditLog) throws FVTUnexpectedCondition + { + final String activityName = "getSchemaManagerClient"; + + try + { + AssetOwnerRESTClient restClient = new AssetOwnerRESTClient(serverName, serverPlatformRootURL); + + return new AssetOwner(serverName, serverPlatformRootURL, restClient, maxPageSize, auditLog); + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + + + /** + * Check the asset is gone. + * + * @param client interface to Asset Owner OMAS + * @param assetGUID unique id of the asset to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkAssetGone(AssetOwner client, + String assetGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + AssetElement retrievedElement = client.getAssetSummary(userId, assetGUID); + + if (retrievedElement != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Asset returned from Retrieve)"); + } + + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Retrieve returned)"); + } + catch (InvalidParameterException expectedException) + { + // all ok + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + + /** + * Check asset is ok. + * + * @param client interface to Asset Owner OMAS + * @param assetGUID unique id of the asset + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkAssetOK(AssetOwner client, + String assetGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + AssetElement retrievedElement = client.getAssetSummary(userId, assetGUID); + + if (retrievedElement == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no AssetElement from Retrieve)"); + } + + System.out.println("Asset Element: " + retrievedElement); + validateAnchorGUID(activityName, retrievedElement); + + AssetProperties retrievedAsset = retrievedElement.getAssetProperties(); + + if (retrievedAsset == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no assetProperties from Retrieve)"); + } + + if (! assetName.equals(retrievedAsset.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad qualifiedName from Retrieve)"); + } + if (! assetDisplayName.equals(retrievedAsset.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad displayName from Retrieve)"); + } + if (! assetDescription.equals(retrievedAsset.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad description from Retrieve)"); + } + + List assetList = client.getAssetsByName(userId, assetName, 0, maxPageSize); + + if (assetList == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no Asset for RetrieveByName)"); + } + else if (assetList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Empty Asset list for RetrieveByName)"); + } + else if (assetList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + "(Asset list for RetrieveByName contains" + assetList.size() + + " elements)"); + } + + retrievedElement = assetList.get(0); + retrievedAsset = retrievedElement.getAssetProperties(); + + if (! assetName.equals(retrievedAsset.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad qualifiedName from RetrieveByName)"); + } + if (! assetDisplayName.equals(retrievedAsset.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad displayName from RetrieveByName)"); + } + if (! assetDescription.equals(retrievedAsset.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad description from RetrieveByName)"); + } + + assetList = client.getAssetsByName(userId, assetName, 1, maxPageSize); + + if (assetList != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no Asset for RetrieveByName)"); + } + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Create an asset and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param userId calling user + * @return GUID of asset + * @throws FVTUnexpectedCondition the test case failed + */ + private String getAsset(AssetOwner client, + String userId) throws FVTUnexpectedCondition + { + final String activityName = "getAsset"; + + try + { + AssetProperties properties = new AssetProperties(); + + properties.setQualifiedName(assetName); + properties.setDisplayName(assetDisplayName); + properties.setDescription(assetDescription); + + properties.setTypeName("AvroFile"); + + String assetGUID = client.addAssetToCatalog(userId, properties); + + if (assetGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for Create)"); + } + else + { + checkAssetOK(client, assetGUID, activityName, userId); + } + + return assetGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a schema option is gone. + * + * @param client interface to Asset Owner OMAS + * @param schemaOptionGUID unique id of the schema to test + * @param assetGUID unique id of the asset to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkSchemaOptionGone(AssetOwner client, + String schemaOptionGUID, + String assetGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + SchemaTypeElement retrievedElement = client.getSchemaTypeByGUID(userId, schemaOptionGUID); + + if (retrievedElement != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(SchemaOption returned from Retrieve)"); + } + + throw new FVTUnexpectedCondition(testCaseName, activityName + "(getSchemaOptionByGUID returned"); + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (InvalidParameterException expectedError) + { + // all ok + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + + if (assetGUID != null) + { + try + { + /* + * Only one schema created so nothing should be tied to the asset. + */ + SchemaTypeElement assetSchemaType = client.getSchemaTypeForElement(userId, assetGUID,"Asset"); + + if (assetSchemaType != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(No SchemaOption returned for getSchemaTypeForElement)"); + } + } + catch(FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch(Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + } + + + /** + * Check a schema choice is correctly stored. + * + * @param client interface to Asset Owner OMAS + * @param schemaOptionGUID unique id of the schema + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkSchemaOptionOK(AssetOwner client, + String schemaOptionGUID, + String activityName, + String userId, + String assetGUID, + List optionGUIDs) throws FVTUnexpectedCondition + { + try + { + SchemaTypeElement retrievedElement = client.getSchemaTypeByGUID(userId, schemaOptionGUID); + + this.validateSchemaOption(activityName + "(getSchemaTypeByGUID)", retrievedElement); + + List schemaOptionList = client.getSchemaTypeByName(userId, optionSchemaName, 0, maxPageSize); + + if (schemaOptionList == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no SchemaOption for RetrieveByName)"); + } + else if (schemaOptionList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Empty SchemaOption list for RetrieveByName)"); + } + else if (schemaOptionList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + "(SchemaOption list for RetrieveByName contains" + schemaOptionList.size() + + " elements)"); + } + + validateSchemaOption(activityName, schemaOptionList.get(0)); + + if (assetGUID != null) + { + retrievedElement = client.getSchemaTypeForElement(userId, assetGUID, "Asset"); + + this.validateSchemaOption(activityName + "(getSchemaTypeForElement)", retrievedElement); + } + + if (optionGUIDs != null) + { + List optionElements = retrievedElement.getSchemaOptions(); + + if (optionElements == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no attached SchemaOption Elements)"); + } + else if (optionElements.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Empty attached SchemaOption Elements)"); + } + else if (optionElements.size() != optionGUIDs.size()) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + "(Attached SchemaOption Elements contains" + optionElements.size() + + " elements)"); + } + + for (SchemaTypeElement optionElement : optionElements) + { + if (! optionGUIDs.contains(optionElement.getElementHeader().getGUID())) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + "(Bad SchemaOption Element: " + optionElement + " not in " + optionGUIDs + ")"); + } + } + } + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + private void validateSchemaOption(String activityName, + SchemaTypeElement retrievedElement) throws FVTUnexpectedCondition + { + if (retrievedElement == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - no SchemaOptionElement)"); + } + + System.out.println("Schema Option Element: " + retrievedElement); + validateAnchorGUID(activityName, retrievedElement); + + SchemaTypeProperties retrievedSchema = retrievedElement.getSchemaTypeProperties(); + + if (retrievedSchema == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "- no SchemaOptionProperties"); + } + + if (! optionSchemaName.equals(retrievedSchema.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad qualifiedName"); + } + if (! optionSchemaDisplayName.equals(retrievedSchema.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad displayName"); + } + if (! optionSchemaDescription.equals(retrievedSchema.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " - Bad description"); + } + } + + + /** + * Create a schema type choice and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param assetGUID unique id of the asset + * @param userId calling user + * @return GUID of schema option + * @throws FVTUnexpectedCondition the test case failed + */ + private String getSchemaOption(AssetOwner client, + String assetGUID, + String userId, + List optionGUIDs) throws FVTUnexpectedCondition + { + final String activityName = "getSchemaOption"; + + try + { + SchemaTypeProperties properties = new SchemaTypeProperties(); + + properties.setQualifiedName(optionSchemaName); + properties.setDisplayName(optionSchemaDisplayName); + properties.setDescription(optionSchemaDescription); + properties.setTypeName("SchemaTypeChoice"); + + String schemaOptionGUID = client.createAnchoredSchemaType(userId, assetGUID, properties); + + if (schemaOptionGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for schemaCreate)"); + } + else + { + client.setupSchemaTypeParent(userId, schemaOptionGUID, assetGUID, "Asset", null); + + if (optionGUIDs != null) + { + for (String optionGUID : optionGUIDs) + { + client.setupSchemaElementRelationship(userId, schemaOptionGUID, optionGUID, "SchemaTypeOption", null); + } + } + + checkSchemaOptionOK(client, schemaOptionGUID, activityName, userId, assetGUID, optionGUIDs); + } + + return schemaOptionGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a map is gone. + * + * @param client interface to Asset Owner OMAS + * @param mapGUID unique id of the map to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkMapGone(AssetOwner client, + String mapGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + SchemaTypeElement retrievedElement = client.getSchemaTypeByGUID(userId, mapGUID); + + if (retrievedElement != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Map returned from Retrieve)"); + } + + throw new FVTUnexpectedCondition(testCaseName, activityName + "(getMapByGUID returned"); + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (InvalidParameterException expectedError) + { + // all ok + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a map is stored OK. + * + * @param client interface to Asset Owner OMAS + * @param mapGUID unique id of the schemaOption + * @param activityName name of calling activity + * @param userId calling user + * @param mapFromGUID schema type to map from + * @param mapToGUID schema type to map to + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkMapOK(AssetOwner client, + String mapGUID, + String activityName, + String userId, + String mapFromGUID, + String mapToGUID) throws FVTUnexpectedCondition + { + + try + { + SchemaTypeElement retrievedElement = client.getSchemaTypeByGUID(userId, mapGUID); + + if (retrievedElement == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no MapElement from Retrieve)"); + } + + System.out.println("Map Element: " + retrievedElement); + validateAnchorGUID(activityName, retrievedElement); + + SchemaTypeProperties retrievedMap = retrievedElement.getSchemaTypeProperties(); + + if (retrievedMap == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no MapProperties from Retrieve)"); + } + + if (! mapName.equals(retrievedMap.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad qualifiedName from Retrieve)"); + } + if (! mapDisplayName.equals(retrievedMap.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad displayName from Retrieve)"); + } + if (! mapDescription.equals(retrievedMap.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad description from Retrieve)"); + } + + List mapList = client.getSchemaTypeByName(userId, mapName, 0, maxPageSize); + + if (mapList == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no Map for RetrieveByName)"); + } + else if (mapList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Empty Map list for RetrieveByName)"); + } + else if (mapList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + "(Map list for RetrieveByName contains" + mapList.size() + + " elements)"); + } + + retrievedElement = mapList.get(0); + retrievedMap = retrievedElement.getSchemaTypeProperties(); + + if (! mapName.equals(retrievedMap.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad qualifiedName from RetrieveByName)"); + } + if (! mapDisplayName.equals(retrievedMap.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad displayName from RetrieveByName)"); + } + if (! mapDescription.equals(retrievedMap.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad description from RetrieveByName)"); + } + + if ((mapFromGUID == null) && (retrievedElement.getMapFromElement() != null)) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Unexpected MapFrom from RetrieveByName) Retrieved element is: " + retrievedElement); + } + + if ((mapFromGUID != null) && (! mapFromGUID.equals(retrievedElement.getMapFromElement().getElementHeader().getGUID()))) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad MapFrom from RetrieveByName) Retrieved element is: " + retrievedElement); + } + + if ((mapToGUID == null) && (retrievedElement.getMapToElement() != null)) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Unexpected MapTo from RetrieveByName) Retrieved element is: " + retrievedElement); + } + + if ((mapToGUID != null) && (! mapToGUID.equals(retrievedElement.getMapToElement().getElementHeader().getGUID()))) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Bad MapTo from RetrieveByName) Retrieved element is: " + retrievedElement); + } + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Create a map and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param assetGUID unique identifier of anchor asset + * @param userId calling user + * @param mapFromGUID schema type to map from + * @param mapToGUID schema type to map to + * @return GUID of map + * @throws FVTUnexpectedCondition the test case failed + */ + private String createMap(AssetOwner client, + String assetGUID, + String userId, + String mapFromGUID, + String mapToGUID) throws FVTUnexpectedCondition + { + final String activityName = "createMap"; + + try + { + SchemaTypeProperties properties = new SchemaTypeProperties(); + + properties.setQualifiedName(mapName); + properties.setDisplayName(mapDisplayName); + properties.setDescription(mapDescription); + properties.setTypeName("MapSchemaType"); + + String mapGUID = client.createAnchoredSchemaType(userId, assetGUID, properties); + + if (mapGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for mapCreate)"); + } + + if (mapFromGUID != null) + { + client.setupSchemaElementRelationship(userId, mapGUID, mapFromGUID, "MapFromElementType", null); + } + + if (mapToGUID != null) + { + client.setupSchemaElementRelationship(userId, mapGUID, mapToGUID, "MapToElementType", null); + } + + checkMapOK(client, mapGUID, activityName, userId, mapFromGUID, mapToGUID); + + return mapGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a primitive is gone. + * + * @param client interface to Asset Owner OMAS + * @param primitiveGUID unique id of the primitive to test + * @param activityName name of calling activity + * @param userId calling user + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkPrimitiveGone(AssetOwner client, + String primitiveGUID, + String activityName, + String userId) throws FVTUnexpectedCondition + { + try + { + SchemaTypeElement retrievedElement = client.getSchemaTypeByGUID(userId, primitiveGUID); + + if (retrievedElement != null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(Primitive returned from Retrieve)"); + } + + throw new FVTUnexpectedCondition(testCaseName, activityName + "(getPrimitiveByGUID returned"); + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (InvalidParameterException expectedError) + { + // all ok + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Check a primitive + * + * @param client interface to Asset Owner OMAS + * @param primitiveGUID unique id of the primitive to test + * @param activityName name of calling activity + * @param userId calling user + * @param primitiveName qualified name of primitive + * @param primitiveDisplayName display name of primitive + * @param primitiveDescription description of primitive + * @param primitiveDataType data type of primitive + * @throws FVTUnexpectedCondition the test case failed + */ + private void checkPrimitiveOK(AssetOwner client, + String primitiveGUID, + String activityName, + String userId, + String primitiveName, + String primitiveDisplayName, + String primitiveDescription, + String primitiveDataType) throws FVTUnexpectedCondition + { + try + { + SchemaTypeElement retrievedElement = client.getSchemaTypeByGUID(userId, primitiveGUID); + + if (retrievedElement == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (no PrimitiveElement from Retrieve)"); + } + + System.out.println("Primitive: " + retrievedElement); + validateAnchorGUID(activityName, retrievedElement); + + SchemaTypeProperties retrievedType = retrievedElement.getSchemaTypeProperties(); + + if (retrievedType == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (no PrimitiveProperties from Retrieve). Element is " + retrievedElement); + } + + if (! primitiveName.equals(retrievedType.getQualifiedName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (Bad qualifiedName " + primitiveName + " from Retrieve). Element is " + retrievedElement); + } + if (! primitiveDisplayName.equals(retrievedType.getDisplayName())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (Bad displayName from Retrieve). Element is " + retrievedElement); + } + if (! primitiveDescription.equals(retrievedType.getDescription())) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (Bad description from Retrieve). Element is " + retrievedElement); + } + + Map extendedProperties = retrievedType.getExtendedProperties(); + + if (extendedProperties == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (Bad extendedProperties from Retrieve). Element is " + retrievedElement); + } + else if (! primitiveDataType.equals(extendedProperties.get("dataType"))) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (Bad data type from Retrieve). Element is " + retrievedElement); + } + + List primitiveList = client.getSchemaTypeByName(userId, primitiveName, 0, maxPageSize); + + if (primitiveList == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (no Primitive for RetrieveByName). Element is " + retrievedElement); + } + else if (primitiveList.isEmpty()) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + " (Empty Primitive list for RetrieveByName). Element is \" + retrievedElement"); + } + else if (primitiveList.size() != 1) + { + throw new FVTUnexpectedCondition(testCaseName, + activityName + " (Primitive list for RetrieveByName contains" + primitiveList.size() + + " elements)"); + } + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + /** + * Create a primitive and return its GUID. + * + * @param client interface to Asset Owner OMAS + * @param assetGUID unique id of the map to connect the column to + * @param userId calling user + * @param primitiveName qualified name of primitive + * @param primitiveDisplayName display name of primitive + * @param primitiveDescription description of primitive + * @param primitiveDataType data type of primitive + * @return GUID of schema + * @throws FVTUnexpectedCondition the test case failed + */ + private String createPrimitive(AssetOwner client, + String assetGUID, + String userId, + String primitiveName, + String primitiveDisplayName, + String primitiveDescription, + String primitiveDataType) throws FVTUnexpectedCondition + { + final String activityName = "createPrimitive"; + + try + { + SchemaTypeProperties properties = new SchemaTypeProperties(); + + properties.setQualifiedName(primitiveName); + properties.setDisplayName(primitiveDisplayName); + properties.setDescription(primitiveDescription); + + Map extendedProperties = new HashMap<>(); + + extendedProperties.put("dataType", primitiveDataType); + + properties.setTypeName("PrimitiveSchemaType"); + properties.setExtendedProperties(extendedProperties); + + String columnGUID = client.createAnchoredSchemaType(userId, assetGUID, properties); + + if (columnGUID == null) + { + throw new FVTUnexpectedCondition(testCaseName, activityName + "(no GUID for columnCreate)"); + } + else + { + checkPrimitiveOK(client, columnGUID, activityName, userId, primitiveName, primitiveDisplayName, primitiveDescription, primitiveDataType); + } + + return columnGUID; + } + catch (FVTUnexpectedCondition testCaseError) + { + throw testCaseError; + } + catch (Exception unexpectedError) + { + throw new FVTUnexpectedCondition(testCaseName, activityName, unexpectedError); + } + } + + + private void validateAnchorGUID(String activityName, + MetadataElement metadataElement) + { + if (metadataElement.getElementHeader() != null) + { + if (metadataElement.getElementHeader().getClassifications() != null) + { + for (ElementClassification classification : metadataElement.getElementHeader().getClassifications()) + { + if ("Anchors".equals(classification.getClassificationName())) + { + System.out.println(metadataElement.getElementHeader().getType().getTypeName() + " element " + metadataElement.getElementHeader().getGUID() + " has anchor of " + classification.getClassificationProperties() + " in activity " + activityName); + } + } + } + } + } +} diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/package-info.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/package-info.java new file mode 100644 index 00000000000..7920ed350ba --- /dev/null +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/main/java/org/odpi/openmetadata/accessservices/assetowner/fvt/dataassets/package-info.java @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +/** + * This package contains tests for managing data asset metadata. + */ + +package org.odpi.openmetadata.accessservices.assetowner.fvt.dataassets; diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetowner/fvt/execution/AssetOwnerOMASCreateDatabaseIT.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetowner/fvt/execution/AssetOwnerOMASCreateDatabaseIT.java new file mode 100644 index 00000000000..1aa77c561cc --- /dev/null +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetowner/fvt/execution/AssetOwnerOMASCreateDatabaseIT.java @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.fvt.execution; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.odpi.openmetadata.accessservices.assetowner.fvt.dataassets.CreateDatabaseTest; +import org.odpi.openmetadata.fvt.utilities.FVTConstants; +import org.odpi.openmetadata.fvt.utilities.FVTResults; +import org.odpi.openmetadata.http.HttpHelper; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * AssetOwnerOMASCreateDatabaseIT is the failsafe wrapper for CreateDatabaseTest. + */ +public class AssetOwnerOMASCreateDatabaseIT +{ + @BeforeAll + public static void disableStrictSSL(){ + HttpHelper.noStrictSSL(); + } + + @ParameterizedTest + @ValueSource(strings = {FVTConstants.IN_MEMORY_SERVER}) + public void testDatabase(String serverName) + { + FVTResults results = CreateDatabaseTest.performFVT(serverName, StringUtils.defaultIfEmpty(System.getProperty("fvt.url"), FVTConstants.SERVER_PLATFORM_URL_ROOT), FVTConstants.USERID); + + results.printResults(serverName); + assertTrue(results.isSuccessful()); + } +} diff --git a/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetowner/fvt/execution/AssetOwnerOMASCreateSchemasIT.java b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetowner/fvt/execution/AssetOwnerOMASCreateSchemasIT.java new file mode 100644 index 00000000000..f45b2437cc6 --- /dev/null +++ b/open-metadata-test/open-metadata-fvt/access-services-fvt/asset-owner-fvt/src/test/java/org/odpi/openmetadata/accessservices/assetowner/fvt/execution/AssetOwnerOMASCreateSchemasIT.java @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright Contributors to the ODPi Egeria project. */ + +package org.odpi.openmetadata.accessservices.assetowner.fvt.execution; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.odpi.openmetadata.accessservices.assetowner.fvt.dataassets.CreateSchemasTest; +import org.odpi.openmetadata.fvt.utilities.FVTConstants; +import org.odpi.openmetadata.fvt.utilities.FVTResults; +import org.odpi.openmetadata.http.HttpHelper; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * AssetOwnerOMASCreateSchemasIT is the failsafe wrapper for CreateSchemasTest. + */ +public class AssetOwnerOMASCreateSchemasIT +{ + @BeforeAll + public static void disableStrictSSL(){ + HttpHelper.noStrictSSL(); + } + + + @ParameterizedTest + @ValueSource(strings = {FVTConstants.IN_MEMORY_SERVER}) + public void testExoticSchemaTypes(String serverName) + { + FVTResults results = CreateSchemasTest.performFVT(serverName, StringUtils.defaultIfEmpty(System.getProperty("fvt.url"), FVTConstants.SERVER_PLATFORM_URL_ROOT), FVTConstants.USERID); + + results.printResults(serverName); + assertTrue(results.isSuccessful()); + } +}