@Test void testToFetch() { EntityType entityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); when(attribute.getName()).thenReturn("test"); Attribute attributeXref = mock(Attribute.class); when(attributeXref.getName()).thenReturn("xref"); when(attributeXref.getDataType()).thenReturn(AttributeType.XREF); when(entityType.getAtomicAttributes()).thenReturn(Arrays.asList(attribute, attributeXref)); Selection expand = new Selection(Collections.singletonMap("xref", Selection.FULL_SELECTION)); Selection filter = Selection.FULL_SELECTION; Fetch expected = new Fetch().field("xref").field("test"); assertEquals(expected, fetchMapper.toFetch(entityType, filter, expand)); }
public @CheckForNull @Nullable Fetch toFetch( EntityType entityType, Selection filter, Selection expand) { if (!filter.hasItems()) { return null; } Fetch fetch = new Fetch(); Iterable<Attribute> attributes = entityType.getAtomicAttributes(); attributes.forEach( attribute -> { String attributeName = attribute.getName(); if (filter.hasItem(attributeName)) { Fetch subFetch; if (expand.hasItem(attributeName) && EntityTypeUtils.isReferenceType(attribute)) { Selection subFilter = filter.getSelection(attributeName).orElse(EMPTY_SELECTION); Selection subExpand = expand.getSelection(attributeName).orElse(EMPTY_SELECTION); subFetch = toFetch(attribute.getRefEntity(), subFilter, subExpand); } else { subFetch = null; } fetch.field(attributeName, subFetch); } }); return fetch; }
FetchMapper { public @CheckForNull @Nullable Fetch toFetch( EntityType entityType, Selection filter, Selection expand) { if (!filter.hasItems()) { return null; } Fetch fetch = new Fetch(); Iterable<Attribute> attributes = entityType.getAtomicAttributes(); attributes.forEach( attribute -> { String attributeName = attribute.getName(); if (filter.hasItem(attributeName)) { Fetch subFetch; if (expand.hasItem(attributeName) && EntityTypeUtils.isReferenceType(attribute)) { Selection subFilter = filter.getSelection(attributeName).orElse(EMPTY_SELECTION); Selection subExpand = expand.getSelection(attributeName).orElse(EMPTY_SELECTION); subFetch = toFetch(attribute.getRefEntity(), subFilter, subExpand); } else { subFetch = null; } fetch.field(attributeName, subFetch); } }); return fetch; } }
FetchMapper { public @CheckForNull @Nullable Fetch toFetch( EntityType entityType, Selection filter, Selection expand) { if (!filter.hasItems()) { return null; } Fetch fetch = new Fetch(); Iterable<Attribute> attributes = entityType.getAtomicAttributes(); attributes.forEach( attribute -> { String attributeName = attribute.getName(); if (filter.hasItem(attributeName)) { Fetch subFetch; if (expand.hasItem(attributeName) && EntityTypeUtils.isReferenceType(attribute)) { Selection subFilter = filter.getSelection(attributeName).orElse(EMPTY_SELECTION); Selection subExpand = expand.getSelection(attributeName).orElse(EMPTY_SELECTION); subFetch = toFetch(attribute.getRefEntity(), subFilter, subExpand); } else { subFetch = null; } fetch.field(attributeName, subFetch); } }); return fetch; }  }
FetchMapper { public @CheckForNull @Nullable Fetch toFetch( EntityType entityType, Selection filter, Selection expand) { if (!filter.hasItems()) { return null; } Fetch fetch = new Fetch(); Iterable<Attribute> attributes = entityType.getAtomicAttributes(); attributes.forEach( attribute -> { String attributeName = attribute.getName(); if (filter.hasItem(attributeName)) { Fetch subFetch; if (expand.hasItem(attributeName) && EntityTypeUtils.isReferenceType(attribute)) { Selection subFilter = filter.getSelection(attributeName).orElse(EMPTY_SELECTION); Selection subExpand = expand.getSelection(attributeName).orElse(EMPTY_SELECTION); subFetch = toFetch(attribute.getRefEntity(), subFilter, subExpand); } else { subFetch = null; } fetch.field(attributeName, subFetch); } }); return fetch; }  @CheckForNull @Nullable Fetch toFetch(
      EntityType entityType, Selection filter, Selection expand); }
FetchMapper { public @CheckForNull @Nullable Fetch toFetch( EntityType entityType, Selection filter, Selection expand) { if (!filter.hasItems()) { return null; } Fetch fetch = new Fetch(); Iterable<Attribute> attributes = entityType.getAtomicAttributes(); attributes.forEach( attribute -> { String attributeName = attribute.getName(); if (filter.hasItem(attributeName)) { Fetch subFetch; if (expand.hasItem(attributeName) && EntityTypeUtils.isReferenceType(attribute)) { Selection subFilter = filter.getSelection(attributeName).orElse(EMPTY_SELECTION); Selection subExpand = expand.getSelection(attributeName).orElse(EMPTY_SELECTION); subFetch = toFetch(attribute.getRefEntity(), subFilter, subExpand); } else { subFetch = null; } fetch.field(attributeName, subFetch); } }); return fetch; }  @CheckForNull @Nullable Fetch toFetch(
      EntityType entityType, Selection filter, Selection expand);  }