PersistentResource implements com.yahoo.elide.security.PersistentResource<T> { protected Map<String, Object> getAttributes() { final Map<String, Object> attributes = new LinkedHashMap<>(); final Set<String> attrFields = filterFields(dictionary.getAttributes(obj)); for (String field : attrFields) { Object val = getAttribute(field); attributes.put(field, val); } return attributes; } PersistentResource(@NonNull T obj, PersistentResource parent, String id, @NonNull RequestScope scope); @Override String toString(); static PersistentResource<T> createObject(
            PersistentResource<?> parent,
            Class<T> entityClass,
            RequestScope requestScope,
            Optional<String> uuid); @Override boolean matchesId(String checkId); @SuppressWarnings("resource") @NonNull static PersistentResource<T> loadRecord(
            Class<T> loadClass, String id, RequestScope requestScope); static Set<PersistentResource> loadRecords(
            Class<?> loadClass,
            List<String> ids,
            Optional<FilterExpression> filter,
            Optional<Sorting> sorting,
            Optional<Pagination> pagination,
            RequestScope requestScope); boolean updateAttribute(String fieldName, Object newVal); boolean updateRelation(String fieldName, Set<PersistentResource> resourceIdentifiers); boolean clearRelation(String relationName); void removeRelation(String fieldName, PersistentResource removeResource); boolean relationshipAlreadyExists(String fieldName, PersistentResource toAdd); void addRelation(String fieldName, PersistentResource newRelation); void deleteResource(); @Override String getId(); void setId(String id); boolean isIdGenerated(); @Override Optional<String> getUUID(); PersistentResource getRelation(String relation, String id); Set<PersistentResource> getRelation(String relation,
            List<String> ids,
            Optional<FilterExpression> filter,
            Optional<Sorting> sorting,
            Optional<Pagination> pagination); Set<PersistentResource> getRelationCheckedFiltered(String relationName,
            Optional<FilterExpression> filterExpression,
            Optional<Sorting> sorting,
            Optional<Pagination> pagination); RelationshipType getRelationshipType(String relation); Object getAttribute(String attr); @Override T getObject(); void setObject(T obj); @Override @JsonIgnore Class<T> getResourceClass(); @Override String getType(); @Override int hashCode(); @Override boolean equals(Object obj); ResourceLineage getLineage(); EntityDictionary getDictionary(); @Override RequestScope getRequestScope(); Resource toResource(); Resource toResourceWithSortingAndPagination(); Resource toResource(final Supplier<Map<String, Relationship>> relationshipSupplier,
                               final Supplier<Map<String, Object>> attributeSupplier); static Object getValue(Object target, String fieldName, RequestScope requestScope);  }
@Test public void testGetAttributes() { FunWithPermissions fun = new FunWithPermissions(); fun.setField3("Foobar"); fun.setField1("blah"); fun.setField2(null); fun.setField4("bar"); PersistentResource<FunWithPermissions> funResource = new PersistentResource<>(fun, null, "3", goodUserScope); Map<String, Object> attributes = funResource.getAttributes(); assertEquals(6, attributes.size(), "A valid user should have access to all attributes that are readable." ); assertTrue(attributes.containsKey("field2"), "Readable attributes should include field2"); assertTrue(attributes.containsKey("field3"), "Readable attributes should include field3"); assertTrue(attributes.containsKey("field4"), "Readable attributes should include field4"); assertTrue(attributes.containsKey("field5"), "Readable attributes should include field5"); assertTrue(attributes.containsKey("field6"), "Readable attributes should include field6"); assertTrue(attributes.containsKey("field8"), "Readable attributes should include field8"); assertNull(attributes.get("field2"), "field2 should be set to original value."); assertEquals(attributes.get("field3"), "Foobar", "field3 should be set to original value."); assertEquals(attributes.get("field4"), "bar", "field4 should be set to original value."); PersistentResource<FunWithPermissions> funResourceBad = new PersistentResource<>(fun, null, "3", badUserScope); attributes = funResourceBad.getAttributes(); assertEquals(3, attributes.size(), "An invalid user should have access to a subset of attributes."); assertTrue(attributes.containsKey("field2"), "Readable attributes should include field2"); assertTrue(attributes.containsKey("field4"), "Readable attributes should include field4"); assertTrue(attributes.containsKey("field5"), "Readable attributes should include field5"); assertNull(attributes.get("field2"), "field2 should be set to original value."); assertEquals(attributes.get("field4"), "bar", "field4 should be set to original value."); }