Skip to content

Commit

Permalink
odpi#5399 fix only top test
Browse files Browse the repository at this point in the history
Signed-off-by: David Radley <david_radley@uk.ibm.com>
  • Loading branch information
davidradl committed Jul 26, 2021
1 parent 149eb34 commit cbf9e42
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;
import org.odpi.openmetadata.commonservices.generichandlers.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

Expand All @@ -30,7 +32,10 @@
* OMAS and retrieves entities and relationships through the OMRSRepositoryConnector.
*/
public class SubjectAreaGlossaryHandler extends SubjectAreaHandler {
private static final String className = SubjectAreaGlossaryHandler.class.getName();
private static Class<SubjectAreaGlossaryHandler> clazz = SubjectAreaGlossaryHandler.class;
String className = clazz.getName();
private static final Logger log = LoggerFactory.getLogger(clazz);


/**
* Construct the Subject Area Glossary Handler
Expand Down Expand Up @@ -485,6 +490,16 @@ public SubjectAreaOMASAPIResponse<Term> getTerms(String userId, String guid, Sub
*/
public SubjectAreaOMASAPIResponse<Category> getCategories(String userId, String guid, FindRequest findRequest, boolean exactValue, boolean ignoreCase, Boolean onlyTop, SubjectAreaCategoryHandler categoryHandler) {
final String methodName = "getCategories";
if (log.isDebugEnabled()) {
String searchCriteria = "not set";
int startingFrom = 0;
if (findRequest != null) {
searchCriteria = findRequest.getSearchCriteria();
startingFrom = findRequest.getStartingFrom();
}

log.debug("==> " + methodName + ",userId=" + userId + ",guid=" + guid +",searchCriteria="+searchCriteria+",startingFrom="+startingFrom);
}
SubjectAreaOMASAPIResponse<Category> response = new SubjectAreaOMASAPIResponse<>();
Integer pageSize = findRequest.getPageSize();
Integer requestedStartingFrom = findRequest.getStartingFrom();
Expand All @@ -498,6 +513,10 @@ public SubjectAreaOMASAPIResponse<Category> getCategories(String userId, String
SubjectAreaOMASAPIResponse<Glossary> thisGlossaryResponse = getGlossaryByGuid(userId, guid);
if (thisGlossaryResponse.getRelatedHTTPCode() == 200) {
try {
if (log.isDebugEnabled()) {
log.debug(methodName + ": got glossary guid " + guid );
}

Set<String> specificMatchPropertyNames = new HashSet();

specificMatchPropertyNames.add(OpenMetadataAPIMapper.DISPLAY_NAME_PROPERTY_NAME);
Expand All @@ -509,6 +528,9 @@ public SubjectAreaOMASAPIResponse<Category> getCategories(String userId, String
if (onlyTop) {
parentToCheckTypeGUID = OpenMetadataAPIMapper.CATEGORY_HIERARCHY_TYPE_GUID;
parentToCheckTypeName = OpenMetadataAPIMapper.CATEGORY_HIERARCHY_TYPE_NAME;
if (log.isDebugEnabled()) {
log.debug("parentToCheckTypeGUID="+parentToCheckTypeGUID+",parentToCheckTypeName=" + parentToCheckTypeName);
}
}


Expand All @@ -521,7 +543,7 @@ public SubjectAreaOMASAPIResponse<Category> getCategories(String userId, String
2, // get only the category end
parentToCheckTypeName, //set for onlyTop
parentToCheckTypeGUID, //set for onlyTop
false,
true, // CategoryHierarchyLink end1 is the parent.
specificMatchPropertyNames,
searchCriteria,
requestedStartingFrom,
Expand All @@ -530,17 +552,24 @@ public SubjectAreaOMASAPIResponse<Category> getCategories(String userId, String
pageSize,
methodName);
Set<Category> categories = new HashSet<>();
for (EntityDetail entity:entities) {
if(entities != null)
{
for (EntityDetail entity : entities)
{
SubjectAreaOMASAPIResponse<Category> categoryResponse = categoryHandler.getCategoryByGuid(userId, entity.getGUID());
if (categoryResponse.getRelatedHTTPCode() == 200) {
categories.add(categoryResponse.results().get(0));
} else {
if (categoryResponse.getRelatedHTTPCode() == 200)
{
categories.add(categoryResponse.results().get(0));
} else
{
response = categoryResponse;
break;
}
}
if( response.getRelatedHTTPCode() == 200) {
response.addAllResults(categories);
}
if (response.getRelatedHTTPCode() == 200)
{
response.addAllResults(categories);
}
}

} catch (PropertyServerException | UserNotAuthorizedException | InvalidParameterException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4220,7 +4220,10 @@ public List<EntityDetail> getAttachedEntities(String userId,
catch (InvalidParameterException | UserNotAuthorizedException | PropertyServerException inaccessibleEntity)
{
// skip entities that are not visible to this user
log.debug("Skipping inaccessible entity", inaccessibleEntity);
if (log.isDebugEnabled())
{
log.debug("Skipping inaccessible entity", inaccessibleEntity);
}
}
}
}
Expand Down Expand Up @@ -6573,7 +6576,10 @@ public List<String> getAttachedElementGUIDs(String userId,
catch (InvalidParameterException | UserNotAuthorizedException | PropertyServerException nonAccessibleEntity)
{
// skip entities that are not visible to this user
log.debug("Skipping entity", nonAccessibleEntity);
if (log.isDebugEnabled())
{
log.debug("Skipping entity", nonAccessibleEntity);
}
}
}
}
Expand Down Expand Up @@ -6752,7 +6758,10 @@ else if (selectionEnd == 2)
catch (InvalidParameterException | UserNotAuthorizedException | PropertyServerException nonAccessibleEntity)
{
// skip entities that are not visible to this user
log.debug("Skipping entity", nonAccessibleEntity);
if (log.isDebugEnabled())
{
log.debug("Skipping entity", nonAccessibleEntity);
}
}
}
}
Expand Down Expand Up @@ -7139,7 +7148,10 @@ public List<B> getAttachedElements(String userId,
catch (InvalidParameterException | UserNotAuthorizedException | PropertyServerException inaccessibleEntity)
{
// skip entities that are not visible to this user
log.debug("Skipping inaccessible entity", inaccessibleEntity);
if (log.isDebugEnabled())
{
log.debug("Skipping inaccessible entity", inaccessibleEntity);
}
}
}
}
Expand Down Expand Up @@ -7255,7 +7267,10 @@ public List<B> getAnchorsForAttachedElements(String userId,
catch (InvalidParameterException | UserNotAuthorizedException | PropertyServerException inaccessibleEntity)
{
// skip entities that are not visible to this user
log.debug("Skipping inaccessible entity", inaccessibleEntity);
if (log.isDebugEnabled())
{
log.debug("Skipping inaccessible entity", inaccessibleEntity);
}
}
}
}
Expand Down Expand Up @@ -7587,7 +7602,20 @@ public List<EntityDetail> getAttachedFilteredEntities(String userId,
while ((relatedEntityIterator.moreToReceive()) && ((queryPageSize == 0) || resultsToReturn.size() < queryPageSize))
{
EntityDetail relatedEntity = relatedEntityIterator.getNext();

if (log.isDebugEnabled())
{
String displayName = "";
String qualifiedName = "";
if (relatedEntity.getProperties() !=null && relatedEntity.getProperties().getInstanceProperties() != null ) {
if ( relatedEntity.getProperties().getInstanceProperties().get("displayName")!=null) {
displayName = relatedEntity.getProperties().getInstanceProperties().get("displayName").toString();
}
if ( relatedEntity.getProperties().getInstanceProperties().get("qualifiedName")!=null) {
qualifiedName = relatedEntity.getProperties().getInstanceProperties().get("qualifiedName").toString();
}
}
log.debug("getAttachedFilteredEntities - while relatedEntity guid="+relatedEntity.getGUID() + ",displayName=" + displayName + ",qualifiedName="+ qualifiedName);
}
if (relatedEntity != null)
{
Relationship parentRelationship = null;
Expand All @@ -7601,22 +7629,21 @@ public List<EntityDetail> getAttachedFilteredEntities(String userId,
attachedEntityFilterRelationshipTypeName,
attachedEntityParentAtEnd1,
methodName);

if (log.isDebugEnabled())
{
if (parentRelationship != null)
{
log.debug("getAttachedFilteredEntities - while found parent relationship parentRelationship" + parentRelationship.getGUID());
}
}
}
// if there is a parentRelationship - this should not be included.
if (parentRelationship == null &&
entityMatchSearchCriteria(relatedEntity, specificMatchPropertyNames, searchCriteria, !startsWith, ignoreCase))
{
entityMatchSearchCriteria(relatedEntity, specificMatchPropertyNames, searchCriteria, !startsWith, ignoreCase)) {
totalFilteredResults.add(relatedEntity);
if (totalFilteredResults.size() > startFrom) {
resultsToReturn.add(relatedEntity);
// TODO remove = here for debugging!!!!
repositoryHandler.getUniqueParentRelationshipByType(userId,
relatedEntity.getGUID(),
relatedEntity.getType().getTypeDefName(),
attachedEntityFilterRelationshipTypeGUID,
attachedEntityFilterRelationshipTypeName,
attachedEntityParentAtEnd1,
methodName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3671,8 +3671,25 @@ public Relationship getUniqueParentRelationshipByType(String userId,
relationshipTypeName,
methodName);



if (relationships != null)
{
if (log.isDebugEnabled())
{
log.debug("getUniqueParentRelationshipByType relationships");
for (Relationship relationship : relationships)
{
log.debug("relationship.getGUID()=" +
relationship.getGUID() +
"relationship.end1 guid=" +
relationship.getEntityOneProxy().getGUID() +
relationship.getEntityOneProxy().getUniqueProperties().getInstanceProperties().get("qualifiedName") +
"relationship.end2 guid " +
relationship.getEntityTwoProxy().getGUID() +
relationship.getEntityTwoProxy().getUniqueProperties().getInstanceProperties().get("qualifiedName"));
}
}
RepositoryRelationshipsIterator iterator = new RepositoryRelationshipsIterator(this,
userId,
startingEntityGUID,
Expand All @@ -3686,9 +3703,22 @@ public Relationship getUniqueParentRelationshipByType(String userId,
while (iterator.moreToReceive())
{
Relationship relationship = iterator.getNext();

if (relationship != null)
{
if (log.isDebugEnabled())
{
log.debug("getUniqueParentRelationshipByType while (iterator.moreToReceive()");
log.debug("relationship.getGUID()=" +
relationship.getGUID() +
", relationship.end1 guid=" +
relationship.getEntityOneProxy().getGUID() +
",qualified name=" +
relationship.getEntityOneProxy().getUniqueProperties().getInstanceProperties().get("qualifiedName") +
"relationship.end2 guid " +
relationship.getEntityTwoProxy().getGUID() +
",qualified name=" +
relationship.getEntityTwoProxy().getUniqueProperties().getInstanceProperties().get("qualifiedName"));
}
EntityProxy parentEntity;

if (parentAtEnd1)
Expand All @@ -3702,6 +3732,17 @@ public Relationship getUniqueParentRelationshipByType(String userId,

if ((parentEntity != null) && (! startingEntityGUID.equals(parentEntity.getGUID())))
{
if (log.isDebugEnabled()) {
log.debug("getUniqueParentRelationshipByType : returning relationship.getGUID()=" +
relationship.getGUID() +
"relationship.end1 guid=" +
relationship.getEntityOneProxy().getGUID() +
relationship.getEntityOneProxy().getUniqueProperties().getInstanceProperties().get("qualifiedName") +
"relationship.end2 guid " +
relationship.getEntityTwoProxy().getGUID() +
relationship.getEntityTwoProxy().getUniqueProperties().getInstanceProperties().get("qualifiedName"));

}
return relationship;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException;
import org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
Expand All @@ -24,6 +24,7 @@ public class RepositoryRelatedEntitiesIterator extends RepositoryIteratorForEnti
private String relationshipTypeGUID;
private String relationshipTypeName;
private int selectionEnd = 0;
private static final Logger log = LoggerFactory.getLogger(RepositoryRelatedEntitiesIterator.class);


/**
Expand Down Expand Up @@ -86,7 +87,10 @@ public RepositoryRelatedEntitiesIterator(RepositoryHandler repositoryHandler,
String methodName)
{
this(repositoryHandler, userId, startingEntityGUID, startingEntityTypeName, relationshipTypeGUID, relationshipTypeName, sequencingPropertyName, startingFrom, pageSize, methodName);

if (log.isDebugEnabled())
{
log.debug("RepositoryRelatedEntitiesIterator :startingFrom=" + startingFrom + ",startingEntityGUID=" + startingEntityGUID);
}
this.selectionEnd = selectionEnd;
}

Expand Down Expand Up @@ -135,7 +139,29 @@ public boolean moreToReceive() throws UserNotAuthorizedException,

if (entitiesCache != null)
{
if (log.isDebugEnabled())
{
log.debug("RepositoryRelatedEntitiesIterator : moreToReceive() entitiesCache not null");
for (EntityDetail entityDetail : entitiesCache)
{
String displayName = "";
String qualifiedName = "";
if (entityDetail.getProperties() != null && entityDetail.getProperties().getInstanceProperties() != null)
{
if ( entityDetail.getProperties().getInstanceProperties().get("displayName") !=null) {
displayName = entityDetail.getProperties().getInstanceProperties().get("displayName").toString();
}
if ( entityDetail.getProperties().getInstanceProperties().get("qualifiedName") !=null) {
qualifiedName = entityDetail.getProperties().getInstanceProperties().get("qualifiedName").toString();
}
}
log.debug("Cached entity " + entityDetail.getGUID() + ",displayName=" + displayName + ",qualifiedName=" +qualifiedName );
}
}
startingFrom = startingFrom + entitiesCache.size();
if (log.isDebugEnabled()) {
log.debug("StartingFrom=" + startingFrom);
}
}
}

Expand Down
Loading

0 comments on commit cbf9e42

Please sign in to comment.