Skip to content

Commit

Permalink
Merge pull request #7623 from LeeVi3w/assetmanager-getanchorasset
Browse files Browse the repository at this point in the history
Added getAnchorAssetForEntity endpoint/method in Asset Manager.
  • Loading branch information
mandy-chessell authored Apr 27, 2023
2 parents 32c276b + 83af111 commit 7c668d9
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,41 @@ protected String getAssetForConnection(OCFRESTClient restClient,
}


/**
* Returns the anchor asset.
*
* @param userId the userId of the requesting user.
* @param guid unique identifier for the metadata element.
*
* @return the anchor asset.
*
* @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.
*/
public Asset getAnchorAssetFromGUID(String userId,
String guid) throws InvalidParameterException,
PropertyServerException,
UserNotAuthorizedException
{
final String methodName = "getAnchorAssetFromGUID";
final String guidParameterName = "guid";
final String urlTemplate = "/servers/{0}/open-metadata/framework-services/{1}/connected-asset/users/{2}/assets/from-anchor/{3}";

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

AssetResponse restResult = ocfrestClient.callOCFAssetGetRESTCall(methodName,
serverPlatformURLRoot + urlTemplate,
serverName,
serviceURLMarker,
userId,
guid);

return restResult.getAsset();
}


/*
* ===============================================
* ConnectorFactoryInterface
Expand Down Expand Up @@ -647,4 +682,6 @@ public Connector getConnectorByConnection(String userId,

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


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.odpi.openmetadata.commonservices.ffdc.RESTExceptionHandler;
import org.odpi.openmetadata.commonservices.ffdc.rest.GUIDResponse;
import org.odpi.openmetadata.commonservices.generichandlers.*;
import org.odpi.openmetadata.commonservices.repositoryhandler.RepositoryHandler;
import org.odpi.openmetadata.frameworkservices.ocf.metadatamanagement.rest.*;
import org.odpi.openmetadata.frameworks.auditlog.AuditLog;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.*;
Expand Down Expand Up @@ -1745,4 +1746,93 @@ else if (repositoryHelper.isTypeOf(serviceURLName, relationship.getType().getTyp

return response;
}

/**
* Returns the anchor asset.
*
* @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 guid String unique id for the metadata element.
*
* @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 getAnchorAssetFromGUID(String serverName,
String serviceURLName,
String userId,
String guid)
{
final String methodName = "getAnchorAssetFromGUID";

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

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

Date effectiveTime = new Date();

try
{
ReferenceableHandler<Referenceable> referenceableHandler = instanceHandler.getReferenceableHandler(userId, serverName, methodName);
RepositoryHandler repositoryHandler = instanceHandler.getRepositoryHandler(userId, serverName, methodName);
auditLog = instanceHandler.getAuditLog(userId, serverName, methodName);

EntityDetail entity = repositoryHandler.getEntityByGUID(userId,
guid,
OpenMetadataAPIMapper.GUID_PROPERTY_NAME,
OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME,
false,
false,
effectiveTime,
methodName);

if (entity != null)
{
if (repositoryHandler.isEntityATypeOf(userId,
guid,
OpenMetadataAPIMapper.GUID_PROPERTY_NAME,
OpenMetadataAPIMapper.ASSET_TYPE_NAME,
effectiveTime,
methodName))
{
response = getAssetResponse(serverName, serviceURLName, userId, guid, null, methodName);
}
else
{
EntityDetail anchorEntity = referenceableHandler.validateAnchorEntity(userId,
guid,
OpenMetadataAPIMapper.REFERENCEABLE_TYPE_NAME,
entity,
OpenMetadataAPIMapper.GUID_PROPERTY_NAME,
false,
false,
false,
null,
effectiveTime,
methodName);
if (anchorEntity != null && repositoryHandler.isEntityATypeOf(userId,
anchorEntity.getGUID(),
OpenMetadataAPIMapper.GUID_PROPERTY_NAME,
OpenMetadataAPIMapper.ASSET_TYPE_NAME,
effectiveTime,
methodName))
{
response = getAssetResponse(serverName, serviceURLName, userId, anchorEntity.getGUID(), 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.
*
* @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 guid String unique id for the metadata element.
* @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/{guid}")

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


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

0 comments on commit 7c668d9

Please sign in to comment.