We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for simple resource views, which allow you to generate a sub-set of the resource in question.
public class ResourceView { private List<String> names; private List<String> matches; public ResourceView() { this.names = new ArrayList<String>(); this.matches = new ArrayList<String>(); } public ResourceView extract(String fieldName) { names.add(fieldName); return this; } public ResourceView extractMatching(String match) { matches.add(match); return this; } public ReadableResource fromResource(ReadableResource oReadableResource) { ResourceFactory resourceFactory = new ResourceFactory(); Resource extractedResource = resourceFactory.newResource(oReadableResource.getResourceLink().getHref()); for (String fieldName : names) { if (oReadableResource.get(fieldName).isPresent()) { extractedResource.withProperty(fieldName, oReadableResource.get(fieldName).get()); } } for (String matcher : matches) { final Map<String,Object> properties = oReadableResource.getProperties(); for (String name : properties.keySet()) { if (name.startsWith(matcher)) { final String newKeyField = name.substring(matcher.length()); if (newKeyField == null || "".equals(newKeyField)) { throw new IllegalArgumentException("Illegal match pattern of " + matcher + " generates empty key for " + name); } if (oReadableResource.get(name).isPresent()) { extractedResource.withProperty(newKeyField, oReadableResource.get(name).get()); } } } } return extractedResource; } }
This should probably also extract links/embedded resources as well.
Suggest adding this method on the {{ResourceFactory}} class.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Add support for simple resource views, which allow you to generate a sub-set of the resource in question.
This should probably also extract links/embedded resources as well.
Suggest adding this method on the {{ResourceFactory}} class.
The text was updated successfully, but these errors were encountered: