Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added getAnchorAssetForEntity endpoint/method in Asset Manager. #7623

Merged
merged 6 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.Asset;
LeeVi3w marked this conversation as resolved.
Show resolved Hide resolved
import org.odpi.openmetadata.frameworks.connectors.properties.beans.Connection;


Expand Down Expand Up @@ -108,4 +109,20 @@ Connector getConnectorByConnection(String userId,
ConnectionCheckedException,
ConnectorCheckedException,
PropertyServerException;
/**
* Returns the anchor asset of the supplied entity.
*
* @param userId userId of user making request.
* @param entityGUID unique identifier of the requested entity.
*
* @return anchor asset of the entity.
*
* @throws InvalidParameterException one of the parameters is null or invalid.
* @throws PropertyServerException there is a problem retrieving information from the property server(s).
* @throws UserNotAuthorizedException the requesting user is not authorized to issue this request.
*/
Asset getAnchorAssetForEntity(String userId,
davidradl marked this conversation as resolved.
Show resolved Hide resolved
String entityGUID) throws InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,40 @@ protected String getAssetForConnection(OCFRESTClient restClient,
return restResult.getGUID();
}

/**
* Returns the anchor asset of the supplied entity.
*
* @param restClient initialized client for calling REST APIs.
* @param serviceName name of the calling service.
* @param userId the userId of the requesting user.
* @param entityGUID unique identifier for the entity.
*
* @return anchor asset of the entity.
LeeVi3w marked this conversation as resolved.
Show resolved Hide resolved
*
* @throws InvalidParameterException one of the parameters is null or invalid.
* @throws PropertyServerException there is a problem retrieving information from the property server.
* @throws UserNotAuthorizedException the requesting user is not authorized to issue this request.
*/
protected Asset getAnchorAssetForEntity(OCFRESTClient restClient,
String serviceName,
String userId,
String entityGUID) throws InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException
{
final String methodName = "getAnchorAssetForEntity";
final String urlTemplate = "/servers/{0}/open-metadata/framework-services/{1}/connected-asset/users/{2}/assets/from-anchor/{3}";

AssetResponse restResult = restClient.callOCFAssetGetRESTCall(methodName,
serverPlatformURLRoot + urlTemplate,
serverName,
serviceName,
userId,
entityGUID);

return restResult.getAsset();
}


/*
* ===============================================
Expand Down Expand Up @@ -647,4 +681,31 @@ public Connector getConnectorByConnection(String userId,

return this.getConnectorForConnection(ocfrestClient, serviceURLMarker, userId, connection, methodName);
}

/**
* Returns the anchor asset of the supplied entity.
*
* @param userId the userId of the requesting user.
* @param entityGUID unique identifier for the entity.
*
* @return anchor asset of the entity.
*
* @throws InvalidParameterException one of the parameters is null or invalid.
* @throws PropertyServerException there is a problem retrieving information from the property server.
* @throws UserNotAuthorizedException the requesting user is not authorized to issue this request.
*/
@Override
public Asset getAnchorAssetForEntity(String userId,
String entityGUID) throws InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException
{
final String methodName = "getAnchorAssetForEntity";
final String guidParameterName = "guid";

invalidParameterHandler.validateUserId(userId, methodName);
invalidParameterHandler.validateGUID(entityGUID, guidParameterName, methodName);

return this.getAnchorAssetForEntity(ocfrestClient, serviceURLMarker, userId, entityGUID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1745,4 +1745,64 @@ else if (repositoryHelper.isTypeOf(serviceURLName, relationship.getType().getTyp

return response;
}

/**
* Returns the anchor asset of the supplied entity.
*
* @param serverName String name of server instance to call.
* @param serviceURLName String name of the service that created the connector that issued this request.
* @param userId String userId of user making request.
* @param entityGUID String unique id for the entity.
*
* @return a bean with the basic properties about the anchor asset or
* InvalidParameterException - the userId is null or invalid or
* UnrecognizedAssetGUIDException - the GUID is null or invalid or
* PropertyServerException - there is a problem retrieving the asset properties from the property server or
* UserNotAuthorizedException - the requesting user is not authorized to issue this request.
*/
public AssetResponse getAnchorAssetForEntity(String serverName,
String serviceURLName,
String userId,
String entityGUID)
{
final String methodName = "getAnchorAssetForEntity";

RESTCallToken token = restCallLogger.logRESTCall(serverName, userId, methodName);

AssetResponse response = new AssetResponse();
AuditLog auditLog = null;

Date effectiveTime = new Date();

try
{
auditLog = instanceHandler.getAuditLog(userId, serverName, methodName);

ReferenceableHandler<Referenceable> referenceableHandler = instanceHandler.getReferenceableHandler(userId, serverName, methodName);
EntityDetail entity = referenceableHandler.getEntityFromRepository(userId,
entityGUID,
OpenMetadataAPIMapper.GUID_PROPERTY_NAME,
OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME,
null,
null,
false,
false,
effectiveTime,
methodName);

if (entity != null)
{
String anchorGUID = referenceableHandler.getAnchorGUIDFromAnchorsClassification(entity, methodName);
LeeVi3w marked this conversation as resolved.
Show resolved Hide resolved
response = getAssetResponse(serverName, serviceURLName, userId, anchorGUID, null, methodName);
}
}
catch (Exception error)
{
restExceptionHandler.captureExceptions(response, error, methodName, auditLog);
}

restCallLogger.logRESTCallReturn(token, response.toString());

return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,30 @@ public AssetResponse getConnectedAssetSummary(@PathVariable String serverName,
}


/**
* Returns the anchor asset of an entity.
*
* @param serverName String name of server instance to call.
davidradl marked this conversation as resolved.
Show resolved Hide resolved
* @param serviceURLName String name of the service that created the connector that issued this request.
* @param userId String userId of user making request.
* @param entityGUID String unique id for the entity.
* @return a bean with the basic properties about the anchor asset or
* InvalidParameterException - the userId is null or invalid or
* UnrecognizedAssetGUIDException - the GUID is null or invalid or
* PropertyServerException - there is a problem retrieving the asset properties from the property server or
* UserNotAuthorizedException - the requesting user is not authorized to issue this request.
*/
@GetMapping(path = "/assets/from-anchor/{entityGUID}")

public AssetResponse getAnchorAssetForEntity(@PathVariable String serverName,
@PathVariable String serviceURLName,
@PathVariable String userId,
@PathVariable String entityGUID)
{
return restAPI.getAnchorAssetForEntity(serverName, serviceURLName, userId, entityGUID);
}


/**
* Returns the basic information about the asset.
*
Expand Down