/** * Appends searchable links to resource's Href * * @param url to append to * @param resource to add links to * @param rel link ro add * @param flags used to specify different link options */ public static void addLink(BaseResource resource, String rel, LinkFlags flags) { addLink(resource.getHref(), resource, rel, flags); }
protected Object doList(List<T> collection, int limit) throws Exception { int i = 0, widestName = "Name".length(), widestId = "ID".length(), widestDescription = 0; for (T model : collection) { if (model.isSetName() && model.getName().length() > widestName) { widestName = model.getName().length(); if (model.isSetId() && model.getId().length() > widestId) { widestId = model.getId().length(); if (model.isSetDescription() && model.getDescription().length() > widestDescription) { widestDescription = model.getDescription().length(); System.out.print(model.getName() + " "); } else { if (i == 1) { + (widestDescription > 0 ? " Description" : "")); System.out.println(pad(model.getName(), widestName) + pad(model.getId(), widestId) + value(model.getDescription())); verbose(model);
public void setId(String id) { model.setId(id); }
protected void display(T model) { if (model != null) { StringBuffer print = new StringBuffer("Created ["); print.append(model.getName()).append("] ["); print.append(model.getId()).append("] "); print.append(model.isSetDescription() ? model.getDescription() : "").append("\n"); System.out.print(print.toString()); verbose(model); } }
protected R addStatus(UriInfo uriInfo, R model, String taskIds) { if (taskIds != null) { Link link = new Link(); link.setRel(CREATION_STATUS); link.setHref(LinkHelper.getUriBuilder(uriInfo, model).path(CREATION_STATUS).path(taskIds).build().toString()); model.getLinks().add(link); } return model; }
public String getId() { return model.getId(); }
protected <T extends BaseResource> T getResource(List<T> collection, String name) { // need to do better than linear search for large collections for (T resource : collection) { if (name.equals(resource.getName())) { return resource; } } if (collection.size() > 0) { System.err.println(name + " is unknown, use tab-completion to see a list of valid targets"); } return null; }
protected Link getLink(BaseResource resource, String rel) { Link ret = null; Collection<Link> links = resource.getActions().getLinks(); for (Link link : links) { if (rel.equals(link.getRel())) { ret = link; break; } } return ret; }
protected void display(T model) { if (model != null) { System.out.println(pad("Name", longer(model.getName(), "Name"), false) + pad("ID", longer(model.getId(), "ID"), false) + (model.isSetDescription() ? " Description" : "")); System.out.println(pad(model.getName(), longer(model.getName(), "Name")) + pad(model.getId(), longer(model.getId(), "ID")) + " " + value(model.getDescription())); verbose(model); } }
/** * Adds searchable links to resource * * @param url to append to and combine search dialect * @param resource to add links to * @param rel link ro add */ public static void addLink(String url, BaseResource resource, String rel) { Link link = new Link(); link.setRel(rel + SEARCH_RELATION); link.setHref(combine(url, rel) + SEARCH_TEMPLATE); resource.getLinks().add(link); }
public static <R extends BaseResource> R addLinks(UriInfo uriInfo, R model, Class<? extends BaseResource> suggestedParentType) { setHref(uriInfo, model, suggestedParentType); setActions(uriInfo, model, suggestedParentType); for (BaseResource inline : getInlineResources(model)) { if (inline.getId() != null) { setHref(uriInfo, inline); } for (BaseResource grandParent : getInlineResources(inline)) { unsetInlineResource(inline, grandParent.getClass()); } } return model; }
public <T extends BaseResource> T doAdd(T resource, Class<T> clz, String href, String localName) throws Exception { Response r = null; Exception failure = null; T ret = null; try { WebClient post = getClient(href); r = post.path("/").post(new JAXBElement<T>(new QName("", localName), clz, null, resource)); ret = unmarshall(r, clz); } catch (Exception e) { failure = e; } if (failure != null || r.getStatus() != 201) { diagnose("addition of " + resource.getName() + " failed with ", failure, r, 201); } return ret; }
/** * Appends searchable links to resource's Href * * @param url to append to and combine search dialect * @param resource to add links to * @param rel link ro add */ public static void addLink(BaseResource resource, String rel) { addLink(resource.getHref(), resource, rel); }
/** * Adds searchable links to resource * * @param url to append to and combine search dialect * @param resource to add links to * @param rel link ro add * @param params the URL params to append */ public static void addLink(String url, BaseResource resource, String rel, Map<String, String> params) { Link link = new Link(); link.setRel(rel + SEARCH_RELATION); link.setHref(combine(combine(url, rel) + SEARCH_TEMPLATE, params)); resource.getLinks().add(link); }
protected R getModel() { R parent = newModel(); parent.setId(getId()); return parent; }
return uriBuilder.path(model.getId());
public int complete(final String buffer, final int cursor, final List candidates) { StringsCompleter delegate = new StringsCompleter(); try { List<? extends BaseResource> collection = getCollection(); for (BaseResource resource : collection) { delegate.getStrings().add(resource.getName()); } } catch (Exception e) { // Substantive exceptions dealt within the BaseClient } return delegate.complete(buffer, cursor, candidates); }
protected <T extends BaseResource> void doRemove(List<T> collection, Class<T> clz, String name) throws Exception { T resource = getResource(collection, name); if (resource != null) { if (resource.getHref() != null) { client.doRemove(resource); } } else { System.err.println(name + " is unknown"); } } }
/** * Adds searchable links to resource * * @param url to append to * @param resource to add links to * @param rel link to add * @param flags used to specify different link options * @param params the URL params to append */ public static void addLink(String url, BaseResource resource, String rel, LinkFlags flags, Map<String, String> params) { Link link = new Link(); link.setRel(rel); link.setHref(combine(url, rel)); resource.getLinks().add(link); if (flags == LinkFlags.SEARCHABLE) { addLink(url, resource, rel, params); } }