public void setChildDescription(String name, String description) { NamedDescription found = findNamedDescription(name, children); if (found != null) { found.setDescription(description); childDescriptionsSet = true; } }
public NamedDescription getChildDescription(String childName) { return findNamedDescription(childName, children); }
private NamedDescription findNamedDescription(String name, List<NamedDescription> namedDescriptions) { for (NamedDescription nd : namedDescriptions) { if (name.equals(nd.getName())) return nd; } return null; } }
json.object().key("description").value(model.getDescription()); json.key("children").array(); for (String child : model.getChildren()) NamedDescription nd = model.getChildDescription(child); if (nd != null) json.key("description").value(nd.getDescription()); for (NamedDescription nd : model.getOperations()) json.object().key("operation-name").value(nd.getName()).key("operation-description").value(nd.getDescription()).endObject();
public Resource(UriInfo uriInfo, ReadResourceModel readResource) this.description = readResource.getDescription(); UriBuilder uriBuilder = uriInfo.getRequestUriBuilder(); if (readResource.getOperations() != null) List<Operation> operations = new ArrayList<Operation>(readResource.getOperations().size()); for (NamedDescription operationDescribed : readResource.getOperations()) Operation operation = new Operation(operationDescribed.getName(), operationDescribed.getDescription(), null); operations.add(operation); if (operationDescribed.getName().equals(OperationNames.READ_RESOURCE)) else if (operationDescribed.getName().equals(OperationNames.EXPORT_RESOURCE)) else if (operationDescribed.getName().equals(OperationNames.IMPORT_RESOURCE)) .rel("operation").replaceQueryParam("op", operationDescribed.getName()).build(); Set<Child> children = new LinkedHashSet<Child>(readResource.getChildDescriptions().size()); for (NamedDescription childDescribed : readResource.getChildDescriptions()) Link link = new LinkBuilder(uriBuilder).rel("child").path(childDescribed.getName()).build(); children.add(new Child(childDescribed.getName(), childDescribed.getDescription(), link));
if (!readResource.isChildDescriptionsSet()) if (readResource.getOperations().isEmpty()) readResource.addOperation(new NamedDescription(desc.getKey(), desc.getValue().getDescription()));
@Override public ReadResourceModel execute(OperationContext operationContext) { ManagedResource resource = operationContext.getManagedResource(); PathAddress address = operationContext.getAddress(); Set<String> children = resource.getSubResourceNames(address); ReadResourceModel readResourceModel = new ReadResourceModel("Available operations and children (sub-resources).", children); // Set children descriptions for (String child : children) { ManagedDescription desc = resource.getResourceDescription(address.append(child)); readResourceModel.setChildDescription(child, desc.getDescription()); } // Set operation descriptions Map<String, ManagedDescription> descriptions = resource.getOperationDescriptions(address); for (Map.Entry<String, ManagedDescription> desc : descriptions.entrySet()) { readResourceModel.addOperation(new NamedDescription(desc.getKey(), desc.getValue().getDescription())); } return readResourceModel; }
/** * Result of a successful read-resource operation. * * @param description description of the result of a read-resource operation. * @param childNames the children (if any) of the managed resource. * */ public ReadResourceModel(String description, Set<String> childNames) { if (description == null) throw new IllegalArgumentException("description was null"); if (childNames == null) throw new IllegalArgumentException("childNames was null"); this.description = description; this.children = new ArrayList<NamedDescription>(childNames.size()); for (String childName : childNames) { // Core implementation will add the descriptions after so 'dynamic' extensions don't have to. children.add(new NamedDescription(childName, null)); } childDescriptionsSet = false; }
private void populateChildDescriptions(ManagedResource root, PathAddress address, ReadResourceModel readResource) { ManagedResource currentResource = root.getSubResource(address); Set<String> subResourceNames = currentResource.getSubResourceNames(PathAddress.empty()); // We have children but no sub resources which typically means that the same resource serves multiple paths like a navigation URI. if (!readResource.getChildren().isEmpty() && subResourceNames.isEmpty()) { for (String childName : readResource.getChildren()) { readResource.setChildDescription(childName, currentResource.getResourceDescription(PathAddress.empty()).getDescription()); } } else { // Set children descriptions for (String subResourceName : subResourceNames) { ManagedResource subResource = currentResource.getSubResource(subResourceName); for (String childName : readResource.getChildren()) { ManagedResource mr = root.getSubResource(address.append(childName)); if (mr == subResource || mr == currentResource) { readResource.setChildDescription(childName, mr.getResourceDescription(PathAddress.empty()).getDescription()); } } } } }
for (ExportResourceModel model : exportResultHandler.getResults()) tasks.addAll(model.getTasks()); return new ExportResourceModel(tasks);
for (String child : ((ReadResourceModel) model).getChildren())
public Set<String> getChildren() { Set<String> childNames = new LinkedHashSet<String>(children.size()); for (NamedDescription nd : children) { childNames.add(nd.getName()); } return Collections.unmodifiableSet(childNames); }