use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException in project egeria-connector-sas-viya by odpi.
the class RepositoryEventMapper method getMappedEntity.
/**
* Retrieve the mapped OMRS entity for the provided SAS Catalog entity.
*
* @param entity the SAS Catalog entity to translate to OMRS
* @return EntityDetail
*/
private EntityDetail getMappedEntity(SASCatalogObject entity, String prefix) {
EntityDetail result = null;
EntityMappingSASCatalog2OMRS mapping = new EntityMappingSASCatalog2OMRS(catalogOMRSRepositoryConnector, catalogOMRSMetadataCollection.getTypeDefStore(), null, /*catalogOMRSMetadataCollection.getAttributeTypeDefStore(),*/
entity, prefix, null);
try {
result = mapping.getEntityDetail();
} catch (RepositoryErrorException e) {
log.error("Unable to map entity to OMRS EntityDetail: {}", entity, e);
}
return result;
}
use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException in project egeria-connector-sas-viya by odpi.
the class EntityMappingSASCatalog2OMRS method getRelationships.
/**
* Retrieves relationships for this entity based on the provided criteria.
*
* @param relationships the Catalog objects for which we wish to
* return relationships
* @param relationshipTypeGUID the OMRS GUID of the relationship TypeDef to
* which to limit the results
* @param fromRelationshipElement the starting element for multiple pages of
* relationships
* @param sequencingProperty the property by which to order results (or
* null)
* @param sequencingOrder the ordering sequence to use for ordering
* results
* @param pageSize the number of results to include per page
* @return {@code List<Relationship>}
* @throws RepositoryErrorException when unable to retrieve the mapped
* Relationships
*/
@SuppressWarnings("unchecked")
public List<Relationship> getRelationships(List<SASCatalogObject> relationships, String relationshipTypeGUID, int fromRelationshipElement, String sequencingProperty, SequencingOrder sequencingOrder, int pageSize) throws RepositoryErrorException {
final String methodName = "getRelationships";
List<Relationship> omrsRelationships = new ArrayList<>();
String repositoryName = sasRepositoryConnector.getRepositoryName();
for (SASCatalogObject relationship : relationships) {
String catalogRelationshipType = relationship.getTypeName();
String relationshipGuid = relationship.getGuid();
Map<String, String> omrsPrefixToType = typeDefStore.getMappedOMRSTypeDefNameWithPrefixes(catalogRelationshipType);
for (Map.Entry<String, String> entry : omrsPrefixToType.entrySet()) {
String relationshipPrefix = entry.getKey();
String omrsRelationshipType = entry.getValue();
TypeDef omrsTypeDef = typeDefStore.getTypeDefByName(omrsRelationshipType);
String omrsTypeDefGuid = omrsTypeDef.getGUID();
// this type GUID
if (relationshipTypeGUID == null || omrsTypeDefGuid.equals(relationshipTypeGUID)) {
log.debug("EntityMappingSASCatalog2OMRS:create relationship mapping");
RelationshipMapping mapping = new RelationshipMapping(sasRepositoryConnector, typeDefStore, null, new SASCatalogGuid(relationshipGuid, relationshipPrefix), relationship, userId);
log.debug("EntityMappingSASCatalog2OMRS:get relationship from mapping");
try {
Relationship omrsRelationship = mapping.getRelationship();
if (omrsRelationship != null) {
omrsRelationships.add(omrsRelationship);
}
} catch (Exception e) {
log.error("Unable to find relationship with guid {} and prefix {}", relationshipGuid, relationshipPrefix);
log.error("Exception Message: {}", e.getMessage());
}
}
}
}
// SAS but different entities in OMRS)
if (relationshipTypeGUID == null) {
Map<String, TypeDefStore.EndpointMapping> mappedRelationships = typeDefStore.getAllEndpointMappingsFromCatalogName(sasEntity.getTypeName());
for (Map.Entry<String, TypeDefStore.EndpointMapping> entry : mappedRelationships.entrySet()) {
String relationshipPrefix = entry.getKey();
// already above)
if (relationshipPrefix != null) {
// TODO: assumes that all generated relationships have the same Catalog entity on
// both ends ie relationshipTable <--> relationshipTableType
SASCatalogGuid sasGuid = new SASCatalogGuid(sasEntity.getGuid(), relationshipPrefix);
Relationship omrsRelationship = RelationshipMapping.getSelfReferencingRelationship(sasRepositoryConnector, typeDefStore, sasGuid, sasEntity);
if (omrsRelationship != null) {
omrsRelationships.add(omrsRelationship);
} else {
raiseRepositoryErrorException(ErrorCode.RELATIONSHIP_NOT_KNOWN, methodName, null, sasGuid.toString(), methodName, repositoryName);
}
}
}
} else {
TypeDef typeDef = typeDefStore.getTypeDefByGUID(relationshipTypeGUID);
if (typeDef != null) {
String omrsTypeDefName = typeDef.getName();
Map<String, String> sasTypesByPrefix = typeDefStore.getAllMappedCatalogTypeDefNames(omrsTypeDefName);
for (Map.Entry<String, String> entry : sasTypesByPrefix.entrySet()) {
String prefixForType = entry.getKey();
String sasTypeNames = entry.getValue();
// covered already above)
if (prefixForType != null) {
log.info("Have not yet implemented this relationship: ({}) {}", prefixForType, sasTypeNames);
}
}
}
}
if (omrsRelationships != null) {
// Now sort the results, if requested
Comparator<Relationship> comparator = SequencingUtils.getRelationshipComparator(sequencingOrder, sequencingProperty);
if (comparator != null) {
omrsRelationships.sort(comparator);
}
// And finally limit the results, if requested
int endOfPageMarker = Math.min(fromRelationshipElement + pageSize, omrsRelationships.size());
if (pageSize != 0) {
// treating 0 as unlimited for now
if (fromRelationshipElement != 0 || endOfPageMarker < omrsRelationships.size()) {
omrsRelationships = omrsRelationships.subList(fromRelationshipElement, endOfPageMarker);
}
}
}
return (omrsRelationships.isEmpty() ? null : omrsRelationships);
}
use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException in project egeria-connector-sas-viya by odpi.
the class RelationshipMapping method getSkeletonRelationship.
/**
* Create the base skeleton of a Relationship, irrespective of the specific SAS object.
*
* @param SASRepositoryConnector connectivity to an SAS environment
* @param omrsRelationshipDef the OMRS RelationshipDef for which to create a skeleton Relationship
* @return Relationship
* @throws RepositoryErrorException when unable to create a new skeletal Relationship
*/
static Relationship getSkeletonRelationship(RepositoryConnector SASRepositoryConnector, RelationshipDef omrsRelationshipDef) throws RepositoryErrorException {
final String methodName = "getSkeletonRelationship";
Relationship relationship = new Relationship();
try {
InstanceType instanceType = SASRepositoryConnector.getRepositoryHelper().getNewInstanceType(SASRepositoryConnector.getRepositoryName(), omrsRelationshipDef);
relationship.setType(instanceType);
} catch (TypeErrorException e) {
throw new RepositoryErrorException(ErrorCode.INVALID_INSTANCE.getMessageDefinition(methodName, omrsRelationshipDef.getName()), RelationshipMapping.class.getName(), methodName, e);
}
return relationship;
}
use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException in project egeria-connector-sas-viya by odpi.
the class RelationshipMapping method getRelationship.
/**
* Create a mapped relationship based on the provided criteria
*
* @param SASRepositoryConnector connectivity to an SAS environment
* @param typeDefStore store of TypeDef mappings
* @param omrsRelationshipType the type of the OMRS relationship to map
* @param relationshipGUID the GUID of the relationship
* @param relationshipStatus the status of the relationship
* @param ep1 the proxy to map to endpoint 1
* @param ep2 the proxy to map to endpoint 2
* @param createdBy the relationship creator
* @param updatedBy the relationship updator
* @param createTime the time the relationship was created
* @param updateTime the time the relationship was updated
* @param omrsRelationshipProperties the properties to set on the relationship
* @return Relationship
* @throws RepositoryErrorException when unable to map the Relationship
*/
private static Relationship getRelationship(RepositoryConnector SASRepositoryConnector, TypeDefStore typeDefStore, String omrsRelationshipType, SASCatalogGuid relationshipGUID, InstanceStatus relationshipStatus, EntityProxy ep1, EntityProxy ep2, String createdBy, String updatedBy, Date createTime, Date updateTime, InstanceProperties omrsRelationshipProperties) throws RepositoryErrorException {
final String methodName = "getRelationship";
String repositoryName = SASRepositoryConnector.getRepositoryName();
Relationship omrsRelationship = RelationshipMapping.getSkeletonRelationship(SASRepositoryConnector, (RelationshipDef) typeDefStore.getTypeDefByName(omrsRelationshipType));
omrsRelationship.setGUID(relationshipGUID.toString());
omrsRelationship.setMetadataCollectionId(SASRepositoryConnector.getMetadataCollectionId());
omrsRelationship.setStatus(relationshipStatus);
omrsRelationship.setInstanceProvenanceType(InstanceProvenanceType.LOCAL_COHORT);
omrsRelationship.setVersion(updateTime.getTime());
omrsRelationship.setCreateTime(createTime);
omrsRelationship.setCreatedBy(createdBy);
omrsRelationship.setUpdatedBy(updatedBy);
omrsRelationship.setUpdateTime(updateTime);
if (ep1 != null && ep2 != null) {
omrsRelationship.setEntityOneProxy(ep1);
omrsRelationship.setEntityTwoProxy(ep2);
} else {
throw new RepositoryErrorException(ErrorCode.INVALID_RELATIONSHIP_ENDS.getMessageDefinition(methodName, repositoryName, omrsRelationshipType, ep1 == null ? "null" : ep1.getGUID(), ep2 == null ? "null" : ep2.getGUID()), RelationshipMapping.class.getName(), methodName);
}
if (omrsRelationshipProperties != null) {
omrsRelationship.setProperties(omrsRelationshipProperties);
}
return omrsRelationship;
}
use of org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException in project egeria-connector-sas-viya by odpi.
the class MetadataCollection method getRelationshipsForEntity.
@Override
public List<Relationship> getRelationshipsForEntity(String userId, String entityGUID, String relationshipTypeGUID, int fromRelationshipElement, List<InstanceStatus> limitResultsByStatus, Date asOfTime, String sequencingProperty, SequencingOrder sequencingOrder, int pageSize) throws InvalidParameterException, TypeErrorException, RepositoryErrorException, EntityNotKnownException, PagingErrorException, FunctionNotSupportedException, UserNotAuthorizedException {
final String methodName = "getRelationshipsForEntity";
getRelationshipsForEntityParameterValidation(userId, entityGUID, relationshipTypeGUID, fromRelationshipElement, limitResultsByStatus, asOfTime, sequencingProperty, sequencingOrder, pageSize);
List<Relationship> alRelationships = null;
// Immediately throw unimplemented exception if trying to retrieve historical view or sequence by property
if (asOfTime != null) {
raiseFunctionNotSupportedException(ErrorCode.NO_HISTORY, methodName, repositoryName);
} else if (limitResultsByStatus == null || (limitResultsByStatus.size() == 1 && limitResultsByStatus.contains(InstanceStatus.ACTIVE))) {
// Otherwise, only bother searching if we are after ACTIVE (or "all") entities -- non-ACTIVE means we
// will just return an empty list
// Guid cannot be null here, as validation above ensures it is non-null
SASCatalogGuid sasCatalogGuid = SASCatalogGuid.fromGuid(entityGUID);
String prefix = sasCatalogGuid.getGeneratedPrefix();
// 1. retrieve entity from Catalog by GUID (and its relationships)
SASCatalogObject asset = null;
List<SASCatalogObject> relationships = null;
try {
asset = repositoryConnector.getEntityByGUID(sasCatalogGuid.getSASCatalogGuid());
relationships = repositoryConnector.getRelationshipsForEntity(sasCatalogGuid.getSASCatalogGuid());
} catch (Exception e) {
raiseEntityNotKnownException(ErrorCode.ENTITY_NOT_KNOWN, methodName, e, entityGUID, methodName, repositoryName);
}
// Ensure the entity actually exists (if not, throw error to that effect)
if (asset == null || relationships == null) {
raiseEntityNotKnownException(ErrorCode.ENTITY_NOT_KNOWN, methodName, null, entityGUID, methodName, repositoryName);
} else {
EntityMappingSASCatalog2OMRS entityMap = new EntityMappingSASCatalog2OMRS(repositoryConnector, typeDefStore, attributeTypeDefStore, asset, prefix, userId);
// 2. Apply the mapping to the object, and retrieve the resulting relationships
alRelationships = entityMap.getRelationships(relationships, relationshipTypeGUID, fromRelationshipElement, sequencingProperty, sequencingOrder, pageSize);
}
}
return alRelationships;
}
Aggregations