Search in sources :

Example 1 with TypeDefStore

use of org.odpi.openmetadata.connector.sas.repository.connector.stores.TypeDefStore in project egeria-connector-sas-viya by odpi.

the class RelationshipMapping method getSelfReferencingRelationship.

/**
 * Setup a self-referencing relationship using the provided prefix and SAS entity.
 *
 * @param SASRepositoryConnector connectivity to a SAS environment
 * @param typeDefStore store of TypeDef mappings
 * @param relationshipGUID the GUID of the relationship
 * @param entity the entity for which the self-referencing relationship should be generated
 * @return Relationship
 * @throws RepositoryErrorException when unable to map the Relationship
 */
public static Relationship getSelfReferencingRelationship(RepositoryConnector SASRepositoryConnector, TypeDefStore typeDefStore, SASCatalogGuid relationshipGUID, SASCatalogObject entity) throws RepositoryErrorException {
    Relationship omrsRelationship = null;
    String prefix = relationshipGUID.getGeneratedPrefix();
    if (prefix != null) {
        RelationshipDef relationshipDef = (RelationshipDef) typeDefStore.getTypeDefByPrefix(prefix);
        String omrsRelationshipType = relationshipDef.getName();
        TypeDefStore.EndpointMapping mapping = typeDefStore.getEndpointMappingFromCatalogName(entity.getTypeName(), prefix);
        EntityProxy ep1 = RelationshipMapping.getEntityProxyForObject(SASRepositoryConnector, typeDefStore, entity, mapping.getPrefixOne(), null);
        EntityProxy ep2 = RelationshipMapping.getEntityProxyForObject(SASRepositoryConnector, typeDefStore, entity, mapping.getPrefixTwo(), null);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
        // TODO: assumes that properties on a self-generated relationship are always empty
        try {
            omrsRelationship = getRelationship(SASRepositoryConnector, typeDefStore, omrsRelationshipType, relationshipGUID, InstanceStatus.ACTIVE, ep1, ep2, (String) entity.get("instance.createdBy"), (String) entity.get("instance.modifiedBy"), format.parse((String) entity.get("instance.creationTimeStamp")), format.parse((String) entity.get("instance.modifiedTimeStamp")), new InstanceProperties());
        } catch (ParseException e) {
            log.error("Relationship entity timestamp could not be parsed");
        }
    } else {
        log.error("A self-referencing, generated relationship was requested, but there is no prefix: {}", relationshipGUID);
    }
    return omrsRelationship;
}
Also used : RelationshipDef(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.RelationshipDef) EntityProxy(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy) InstanceProperties(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties) Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship) AttributeTypeDefStore(org.odpi.openmetadata.connector.sas.repository.connector.stores.AttributeTypeDefStore) TypeDefStore(org.odpi.openmetadata.connector.sas.repository.connector.stores.TypeDefStore) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with TypeDefStore

use of org.odpi.openmetadata.connector.sas.repository.connector.stores.TypeDefStore in project egeria-connector-sas-viya by odpi.

the class RelationshipMapping method getRelationship.

/**
 * Retrieve the mapped OMRS Relationship from the SAS relationship used to construct this mapping object.
 *
 * @return Relationship
 * @throws RepositoryErrorException when unable to retrieve the Relationship
 */
public Relationship getRelationship() throws RepositoryErrorException {
    final String methodName = "getRelationship";
    String repositoryName = SASRepositoryConnector.getRepositoryName();
    String SASRelationshipType = relationship.getTypeName();
    String relationshipPrefix = sasCatalogGuid.getGeneratedPrefix();
    TypeDefStore.EndpointMapping mapping = typeDefStore.getEndpointMappingFromCatalogName(SASRelationshipType, relationshipPrefix);
    Relationship omrsRelationship = null;
    if (mapping != null) {
        String ep1Id = (String) relationship.get("instance.endpoint1Id");
        String ep2Id = (String) relationship.get("instance.endpoint2Id");
        SASCatalogObject ep1Object = null;
        SASCatalogObject ep2Object = null;
        try {
            ep1Object = SASRepositoryConnector.getEntityByGUID(ep1Id);
            ep2Object = SASRepositoryConnector.getEntityByGUID(ep2Id);
        } catch (Exception e) {
            raiseRepositoryErrorException(ErrorCode.ENTITY_NOT_KNOWN, methodName, e, ep1Id, methodName, repositoryName);
        }
        EntityProxy ep1 = null;
        EntityProxy ep2 = null;
        try {
            ep1 = RelationshipMapping.getEntityProxyForObject(SASRepositoryConnector, typeDefStore, ep1Object, mapping.getPrefixOne(), userId);
        } catch (Exception e) {
            raiseRepositoryErrorException(ErrorCode.ENTITY_NOT_KNOWN, methodName, e, ep1Id, methodName, repositoryName);
        }
        try {
            ep2 = RelationshipMapping.getEntityProxyForObject(SASRepositoryConnector, typeDefStore, ep2Object, mapping.getPrefixTwo(), userId);
        } catch (Exception e) {
            raiseRepositoryErrorException(ErrorCode.ENTITY_NOT_KNOWN, methodName, e, ep2Id, methodName, repositoryName);
        }
        if (ep1 != null && ep2 != null) {
            omrsRelationship = getRelationship(SASRelationshipType, ep1, ep2);
        }
    }
    return omrsRelationship;
}
Also used : EntityProxy(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy) Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship) AttributeTypeDefStore(org.odpi.openmetadata.connector.sas.repository.connector.stores.AttributeTypeDefStore) TypeDefStore(org.odpi.openmetadata.connector.sas.repository.connector.stores.TypeDefStore) TypeErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException) RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException) ParseException(java.text.ParseException)

Aggregations

ParseException (java.text.ParseException)2 AttributeTypeDefStore (org.odpi.openmetadata.connector.sas.repository.connector.stores.AttributeTypeDefStore)2 TypeDefStore (org.odpi.openmetadata.connector.sas.repository.connector.stores.TypeDefStore)2 EntityProxy (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityProxy)2 Relationship (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship)2 SimpleDateFormat (java.text.SimpleDateFormat)1 InstanceProperties (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceProperties)1 RelationshipDef (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.RelationshipDef)1 RepositoryErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)1 TypeErrorException (org.odpi.openmetadata.repositoryservices.ffdc.exception.TypeErrorException)1