@Test void testGetQueryRuleAttributeNestedUnknown() { String refAttrName = "refAttr"; String attrName = "unknownAttr"; String queryRuleField = refAttrName + '.' + attrName; QueryRule queryRule = mock(QueryRule.class); when(queryRule.getField()).thenReturn(queryRuleField); EntityType entityType = mock(EntityType.class); Attribute refAttr = mock(Attribute.class); EntityType refEntity = mock(EntityType.class); when(refEntity.getAttribute(attrName)).thenReturn(null); when(refAttr.getRefEntity()).thenReturn(refEntity); when(entityType.getAttribute(refAttrName)).thenReturn(refAttr); assertThrows( UnknownAttributeException.class, () -> QueryUtils.getQueryRuleAttribute(queryRule, entityType)); }
public static Attribute getQueryRuleAttribute(QueryRule queryRule, EntityType entityType) { String queryRuleField = queryRule.getField(); if (queryRuleField == null) { return null; } Attribute attr = null; String[] queryRuleFieldTokens = StringUtils.split(queryRuleField, NESTED_ATTRIBUTE_SEPARATOR); EntityType entityTypeAtCurrentDepth = entityType; for (int depth = 0; depth < queryRuleFieldTokens.length; ++depth) { String attrName = queryRuleFieldTokens[depth]; attr = entityTypeAtCurrentDepth.getAttribute(attrName); if (attr == null) { throw new UnknownAttributeException(entityTypeAtCurrentDepth, attrName); } if (depth + 1 < queryRuleFieldTokens.length) { entityTypeAtCurrentDepth = attr.getRefEntity(); } } return attr; }
QueryUtils { public static Attribute getQueryRuleAttribute(QueryRule queryRule, EntityType entityType) { String queryRuleField = queryRule.getField(); if (queryRuleField == null) { return null; } Attribute attr = null; String[] queryRuleFieldTokens = StringUtils.split(queryRuleField, NESTED_ATTRIBUTE_SEPARATOR); EntityType entityTypeAtCurrentDepth = entityType; for (int depth = 0; depth < queryRuleFieldTokens.length; ++depth) { String attrName = queryRuleFieldTokens[depth]; attr = entityTypeAtCurrentDepth.getAttribute(attrName); if (attr == null) { throw new UnknownAttributeException(entityTypeAtCurrentDepth, attrName); } if (depth + 1 < queryRuleFieldTokens.length) { entityTypeAtCurrentDepth = attr.getRefEntity(); } } return attr; } }
QueryUtils { public static Attribute getQueryRuleAttribute(QueryRule queryRule, EntityType entityType) { String queryRuleField = queryRule.getField(); if (queryRuleField == null) { return null; } Attribute attr = null; String[] queryRuleFieldTokens = StringUtils.split(queryRuleField, NESTED_ATTRIBUTE_SEPARATOR); EntityType entityTypeAtCurrentDepth = entityType; for (int depth = 0; depth < queryRuleFieldTokens.length; ++depth) { String attrName = queryRuleFieldTokens[depth]; attr = entityTypeAtCurrentDepth.getAttribute(attrName); if (attr == null) { throw new UnknownAttributeException(entityTypeAtCurrentDepth, attrName); } if (depth + 1 < queryRuleFieldTokens.length) { entityTypeAtCurrentDepth = attr.getRefEntity(); } } return attr; } private  QueryUtils(); }
QueryUtils { public static Attribute getQueryRuleAttribute(QueryRule queryRule, EntityType entityType) { String queryRuleField = queryRule.getField(); if (queryRuleField == null) { return null; } Attribute attr = null; String[] queryRuleFieldTokens = StringUtils.split(queryRuleField, NESTED_ATTRIBUTE_SEPARATOR); EntityType entityTypeAtCurrentDepth = entityType; for (int depth = 0; depth < queryRuleFieldTokens.length; ++depth) { String attrName = queryRuleFieldTokens[depth]; attr = entityTypeAtCurrentDepth.getAttribute(attrName); if (attr == null) { throw new UnknownAttributeException(entityTypeAtCurrentDepth, attrName); } if (depth + 1 < queryRuleFieldTokens.length) { entityTypeAtCurrentDepth = attr.getRefEntity(); } } return attr; } private  QueryUtils(); static boolean containsOperator(Query<Entity> q, Operator operator); static boolean containsAnyOperator(Query<Entity> q, Set<Operator> operators); static boolean containsAnyOperator(List<QueryRule> rules, Set<Operator> operators); static boolean containsComputedAttribute(Query<Entity> query, EntityType entityType); static boolean containsComputedAttribute(Sort sort, EntityType entityType); static boolean containsComputedAttribute(
      Iterable<QueryRule> rules, EntityType entityType); static boolean containsNestedQueryRuleField(Query<Entity> q); static Attribute getQueryRuleAttribute(QueryRule queryRule, EntityType entityType); static List<Attribute> getAttributePath(String queryRuleField, EntityType entityType); static List<Attribute> getAttributePathExpanded(
      String queryRuleField, EntityType entityType); static List<Attribute> getAttributePathExpanded(
      String queryRuleField, EntityType entityType, boolean expandLabelInsteadOfId); static boolean isTaggedType(Attribute attribute, IRI typeIRI); }
QueryUtils { public static Attribute getQueryRuleAttribute(QueryRule queryRule, EntityType entityType) { String queryRuleField = queryRule.getField(); if (queryRuleField == null) { return null; } Attribute attr = null; String[] queryRuleFieldTokens = StringUtils.split(queryRuleField, NESTED_ATTRIBUTE_SEPARATOR); EntityType entityTypeAtCurrentDepth = entityType; for (int depth = 0; depth < queryRuleFieldTokens.length; ++depth) { String attrName = queryRuleFieldTokens[depth]; attr = entityTypeAtCurrentDepth.getAttribute(attrName); if (attr == null) { throw new UnknownAttributeException(entityTypeAtCurrentDepth, attrName); } if (depth + 1 < queryRuleFieldTokens.length) { entityTypeAtCurrentDepth = attr.getRefEntity(); } } return attr; } private  QueryUtils(); static boolean containsOperator(Query<Entity> q, Operator operator); static boolean containsAnyOperator(Query<Entity> q, Set<Operator> operators); static boolean containsAnyOperator(List<QueryRule> rules, Set<Operator> operators); static boolean containsComputedAttribute(Query<Entity> query, EntityType entityType); static boolean containsComputedAttribute(Sort sort, EntityType entityType); static boolean containsComputedAttribute(
      Iterable<QueryRule> rules, EntityType entityType); static boolean containsNestedQueryRuleField(Query<Entity> q); static Attribute getQueryRuleAttribute(QueryRule queryRule, EntityType entityType); static List<Attribute> getAttributePath(String queryRuleField, EntityType entityType); static List<Attribute> getAttributePathExpanded(
      String queryRuleField, EntityType entityType); static List<Attribute> getAttributePathExpanded(
      String queryRuleField, EntityType entityType, boolean expandLabelInsteadOfId); static boolean isTaggedType(Attribute attribute, IRI typeIRI);  }