Skip to content

Commit

Permalink
Merge pull request #8484 from mandy-chessell/oak2024
Browse files Browse the repository at this point in the history
Add metadataCollectionId to classifications
  • Loading branch information
mandy-chessell authored Nov 10, 2024
2 parents 8e2eb51 + f1f43ad commit 41b1461
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public enum JDBCErrorCode implements ExceptionMessageSet


/**
* JDBC-RESOURCE-CONNECTOR-500-003 - The JDBC resource connector for database {0} received an unexpected SQL exception from request '{1}' during method {2}; the error message was: {4}
* JDBC-RESOURCE-CONNECTOR-500-003 - The JDBC resource connector for database {0} received an unexpected SQL exception from request '{1}' during method {2}; the error message was: {3}
*/
UNEXPECTED_SQL_EXCEPTION(500, "JDBC-RESOURCE-CONNECTOR-500-003",
"The JDBC resource connector for database {0} received an unexpected SQL exception from request '{1}' during method {2}; the error message was: {4}",
"The JDBC resource connector for database {0} received an unexpected SQL exception from request \"{1}\" during method {2}; the error message was: {3}",
"The connector is unable to process the current request because the database returned an unexpected error.",
"Use the details from the SQL error message and the SQL request to determine the cause of the error and retry the request once it is resolved."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public EntityDetail addEntity(String userId,
EntityDetail newEntity = repositoryHelper.getNewEntity(repositoryName,
metadataCollectionId,
InstanceProvenanceType.LOCAL_COHORT,
null,
userId,
typeDef.getName(),
initialProperties,
Expand Down Expand Up @@ -243,6 +244,7 @@ public EntityDetail addExternalEntity(String userId,
EntityDetail newEntity = repositoryHelper.getNewEntity(repositoryName,
externalSourceGUID,
InstanceProvenanceType.EXTERNAL_SOURCE,
metadataCollectionId,
userId,
typeDef.getName(),
initialProperties,
Expand All @@ -252,8 +254,6 @@ public EntityDetail addExternalEntity(String userId,
* Ensure metadataCollectionName also set
*/
newEntity.setMetadataCollectionName(externalSourceName);
newEntity.setReplicatedBy(metadataCollectionId);


/*
* If an initial status is supplied then override the default value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ public EntityDetail addEntity(String userId,
metadataCollectionId,
metadataCollectionName,
InstanceProvenanceType.LOCAL_COHORT,
null,
userId,
typeDef.getName(),
initialProperties,
Expand Down Expand Up @@ -1497,13 +1498,12 @@ public EntityDetail addExternalEntity(String userId,
externalSourceGUID,
externalSourceName,
InstanceProvenanceType.EXTERNAL_SOURCE,
metadataCollectionId,
userId,
typeDef.getName(),
initialProperties,
initialClassifications);

newEntity.setMetadataCollectionName(externalSourceName);
newEntity.setReplicatedBy(metadataCollectionId);

/*
* If an initial status is supplied then override the default value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@baseURL=https://localhost:9443
@adminUserId=garygeeke
@auditLogTopic=logging
@localMatadataCollectionId=3fe67e5a-28eb-42bb-910c-600c3a8d6fb2
@localMetadataCollectionId=3fe67e5a-28eb-42bb-910c-600c3a8d6fb2

###
# ---------------------------------------------
Expand Down Expand Up @@ -55,7 +55,7 @@ Content-Type: application/json
POST {{baseURL}}/open-metadata/admin-services/users/{{adminUserId}}/servers/postgres-metadata-store/local-repository/metadata-collection-id
Content-Type: text/plain

{{localMatadataCollectionId}}
{{localMetadataCollectionId}}


###
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@ public EntityDetail addEntity(String userId,
metadataCollectionId,
metadataCollectionName,
InstanceProvenanceType.LOCAL_COHORT,
null,
userId,
typeDef.getName(),
initialProperties,
Expand Down Expand Up @@ -1186,14 +1187,12 @@ public EntityDetail addExternalEntity(String userId,
externalSourceGUID,
externalSourceName,
InstanceProvenanceType.EXTERNAL_SOURCE,
metadataCollectionId,
userId,
typeDef.getName(),
initialProperties,
initialClassifications);

newEntity.setMetadataCollectionName(externalSourceName);
newEntity.setReplicatedBy(metadataCollectionId);

/*
* If an initial status is supplied then override the default value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ List<EntityDetail> findEntitiesByProperty(String entityTypeGU
QueryBuilder entityQueryBuilder = new QueryBuilder(repositoryHelper, repositoryName);

entityQueryBuilder.setTypeGUID(entityTypeGUID, entityTypeGUIDParameterName);
entityQueryBuilder.setMatchProperties(matchProperties, matchCriteria);
entityQueryBuilder.setMatchProperties(matchProperties, matchCriteria, RepositoryTable.ENTITY_ATTRIBUTE_VALUE.getTableName());
entityQueryBuilder.setLimitResultsByStatus(limitResultsByStatus);
entityQueryBuilder.setAsOfTime(asOfTime);
entityQueryBuilder.setSequencingOrder(sequencingOrder, sequencingProperty);
Expand Down Expand Up @@ -427,7 +427,7 @@ List<EntityDetail> findEntitiesByClassification(String entity
entityQueryBuilder.setPaging(fromEntityElement, pageSize);

classificationQueryBuilder.setLimitResultsByClassification(Collections.singletonList(classificationName));
classificationQueryBuilder.setMatchProperties(matchClassificationProperties, matchCriteria);
classificationQueryBuilder.setMatchProperties(matchClassificationProperties, matchCriteria, RepositoryTable.CLASSIFICATION_ATTRIBUTE_VALUE.getTableName());
classificationQueryBuilder.setAsOfTime(asOfTime);

DatabaseStore databaseStore = new DatabaseStore(jdbcResourceConnector, repositoryName, repositoryHelper);
Expand Down Expand Up @@ -700,7 +700,7 @@ List<Relationship> findRelationshipsByProperty(String relatio
QueryBuilder queryBuilder = new QueryBuilder(repositoryHelper, repositoryName);

queryBuilder.setTypeGUID(relationshipTypeGUID, relationshipTypeGUIDParameterName);
queryBuilder.setMatchProperties(matchProperties, matchCriteria);
queryBuilder.setMatchProperties(matchProperties, matchCriteria, RepositoryTable.RELATIONSHIP_ATTRIBUTE_VALUE.getTableName());
queryBuilder.setLimitResultsByStatus(limitResultsByStatus);
queryBuilder.setAsOfTime(asOfTime);
queryBuilder.setSequencingOrder(sequencingOrder, sequencingProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException;

import java.sql.SQLException;
import java.util.*;

/**
Expand Down Expand Up @@ -213,7 +212,7 @@ public List<ClassificationMapper> getHomeClassifications(String guid,

try
{
String whereClause = RepositoryColumn.INSTANCE_GUID.getColumnName() + " = '" + guid + "' and " + RepositoryColumn.METADATA_COLLECTION_GUID.getColumnName() + " = '" + localMetadataCollectionId + "' and " + this.getAsOfTimeClause(asOfTime) + ";";
String whereClause = RepositoryColumn.INSTANCE_GUID.getColumnName() + " = '" + guid + "' and " + RepositoryColumn.METADATA_COLLECTION_GUID.getColumnName() + " = '" + localMetadataCollectionId + "' " + this.getAsOfTimeClause(asOfTime) + ";";

List<Map<String, JDBCDataValue>> classifications = jdbcResourceConnector.getMatchingRows(RepositoryTable.CLASSIFICATION.getTableName(),
whereClause,
Expand All @@ -229,9 +228,10 @@ public List<ClassificationMapper> getHomeClassifications(String guid,
{
if (classificationRow != null)
{
Object classificationName = classificationRow.get(RepositoryColumn.CLASSIFICATION_NAME.getColumnName()).getDataValue();
String classificationName = baseMapper.getStringPropertyFromColumn(RepositoryColumn.CLASSIFICATION_NAME.getColumnName(), classificationRow, true);
long version = baseMapper.getLongPropertyFromColumn(RepositoryColumn.VERSION.getColumnName(), classificationRow, true);

String classificationWhereClause = RepositoryColumn.INSTANCE_GUID.getColumnName() + " = '" + guid + " and " + RepositoryColumn.CLASSIFICATION_NAME.getColumnName() + " = '" + classificationName + "' and " + this.getAsOfTimeClause(asOfTime);
String classificationWhereClause = RepositoryColumn.INSTANCE_GUID.getColumnName() + " = '" + guid + "' and " + RepositoryColumn.VERSION.getColumnName() + " = " + version + " and " + RepositoryColumn.CLASSIFICATION_NAME.getColumnName() + " = '" + classificationName + "';";

List<Map<String, JDBCDataValue>> classificationProperties = jdbcResourceConnector.getMatchingRows(RepositoryTable.CLASSIFICATION_ATTRIBUTE_VALUE.getTableName(),
classificationWhereClause,
Expand Down Expand Up @@ -348,7 +348,8 @@ public List<EntityMapper> retrieveEntitiesByProperties(QueryBuilder entityQueryB
final String methodName = "retrieveEntitiesByProperties";

String sqlEntityQuery = entityQueryBuilder.getPropertyJoinQuery(RepositoryTable.ENTITY.getTableName(),
RepositoryTable.ENTITY_ATTRIBUTE_VALUE.getTableName()) +
RepositoryTable.ENTITY_ATTRIBUTE_VALUE.getTableName(),
"*") +
" where " + entityQueryBuilder.getAsOfTimeWhereClause();

try
Expand All @@ -357,19 +358,20 @@ public List<EntityMapper> retrieveEntitiesByProperties(QueryBuilder entityQueryB

if (classificationQueryBuilder == null)
{
entityRows = jdbcResourceConnector.getMatchingRows(sqlEntityQuery + entityQueryBuilder.getSequenceAndPaging(),
entityRows = jdbcResourceConnector.getMatchingRows(sqlEntityQuery + entityQueryBuilder.getSequenceAndPaging(RepositoryTable.ENTITY.getTableName()),
RepositoryTable.ENTITY.getColumnNameTypeMap());
}
else
{
String sqlClassificationQuery = classificationQueryBuilder.getPropertyJoinQuery(RepositoryTable.CLASSIFICATION.getTableName(),
RepositoryTable.CLASSIFICATION_ATTRIBUTE_VALUE.getTableName()) +
RepositoryTable.CLASSIFICATION_ATTRIBUTE_VALUE.getTableName(),
RepositoryColumn.INSTANCE_GUID.getColumnName(RepositoryTable.CLASSIFICATION_ATTRIBUTE_VALUE.getTableName())) +
" where " + classificationQueryBuilder.getAsOfTimeWhereClause();

entityRows = jdbcResourceConnector.getMatchingRows(sqlEntityQuery + " and " +
RepositoryColumn.INSTANCE_GUID.getColumnName(RepositoryTable.ENTITY.getTableName()) +
" in (" + sqlClassificationQuery + ")" +
entityQueryBuilder.getSequenceAndPaging(),
entityQueryBuilder.getSequenceAndPaging(RepositoryTable.ENTITY.getTableName()),
RepositoryTable.ENTITY.getColumnNameTypeMap());
}

Expand Down Expand Up @@ -410,7 +412,7 @@ public List<RelationshipMapper> retrieveRelationships(QueryBuilder queryBuilder,
try
{
List<Map<String, JDBCDataValue>> relationshipRows = jdbcResourceConnector.getMatchingRows(RepositoryTable.RELATIONSHIP.getTableName(),
queryBuilder.getAsOfTimeWhereClause() + queryBuilder.getSequenceAndPaging(),
queryBuilder.getAsOfTimeWhereClause() + queryBuilder.getSequenceAndPaging(RepositoryTable.RELATIONSHIP.getTableName()),
RepositoryTable.RELATIONSHIP.getColumnNameTypeMap());

if (relationshipRows != null)
Expand Down Expand Up @@ -447,8 +449,9 @@ public List<RelationshipMapper> retrieveRelationshipsByProperties(QueryBuilder q
final String methodName = "retrieveRelationships";

String sqlQuery = queryBuilder.getPropertyJoinQuery(RepositoryTable.RELATIONSHIP.getTableName(),
RepositoryTable.RELATIONSHIP_ATTRIBUTE_VALUE.getTableName()) +
" where " + queryBuilder.getAsOfTimeWhereClause() + queryBuilder.getSequenceAndPaging();
RepositoryTable.RELATIONSHIP_ATTRIBUTE_VALUE.getTableName(),
"*") +
" where " + queryBuilder.getAsOfTimeWhereClause() + queryBuilder.getSequenceAndPaging(RepositoryTable.RELATIONSHIP.getTableName());


try
Expand Down Expand Up @@ -605,7 +608,7 @@ private Map<String, EntityMapper> getCompleteEntitiesFromGUIDs(List<String> enti
queryBuilder.setAsOfTime(asOfTime);

List<Map<String, JDBCDataValue>> entityRows = jdbcResourceConnector.getMatchingRows(RepositoryTable.ENTITY.getTableName(),
queryBuilder.getAsOfTimeWhereClause() + queryBuilder.getSequenceAndPaging(),
queryBuilder.getAsOfTimeWhereClause() + queryBuilder.getSequenceAndPaging(RepositoryTable.ENTITY.getTableName()),
RepositoryTable.ENTITY.getColumnNameTypeMap());

return this.getCompleteEntitiesFromStore(entityRows, asOfTime);
Expand Down Expand Up @@ -655,7 +658,7 @@ private Map<String, EntityMapper> getCompleteEntitiesFromStore(List<Map<String,
queryBuilder.setGUIDList(new ArrayList<>(databaseResultRowsMap.keySet()));
queryBuilder.setAsOfTime(asOfTime);

Map<String, List<ClassificationMapper>> classificationMappersForEntityGUIDs = getClassificationMappersForEntityGUIDs(queryBuilder.getAsOfTimeWhereClause() + queryBuilder.getSequenceAndPaging());
Map<String, List<ClassificationMapper>> classificationMappersForEntityGUIDs = getClassificationMappersForEntityGUIDs(queryBuilder.getAsOfTimeWhereClause() + queryBuilder.getSequenceAndPaging(RepositoryTable.CLASSIFICATION.getTableName()));

/*
* All of the information is assembled to build the entity mappers.
Expand Down
Loading

0 comments on commit 41b1461

Please sign in to comment.