@Override public Links index() { return new LinksBuilder(module) .addLink( "Page1", "page1") .addLink( "Page2", "page2") .addLink( "Page3", "page3") .newLinks(); } }
public static Function<Link, String> toRel() { return link -> link.rel().get(); } }
public T addLink( String description, String id, String rel, String href, String classes ) { linkBuilder.prototype().text().set( description ); linkBuilder.prototype().id().set( id ); linkBuilder.prototype().rel().set( rel ); linkBuilder.prototype().href().set( href ); linkBuilder.prototype().classes().set( classes ); addLink( linkBuilder.newInstance() ); return (T) this; }
HandlerCommand command( Link link, Object commandRequest, ResponseHandler handler, ResponseHandler processingErrorHandler ) { if (handler == null) handler = commandHandlers.get( link.rel().get() ); if (processingErrorHandler == null) processingErrorHandler = processingErrorHandlers.get( link.rel().get() ); // Check if we should do POST or PUT Method method; if( LinksUtil.withClass( "idempotent" ).test( link ) ) { method = Method.PUT; } else { method = Method.POST; } Reference ref = new Reference( reference.toUri().toString() + link.href().get() ); return invokeCommand( ref, method, commandRequest, handler, processingErrorHandler ); }
@Override public Link command( String relation ) { return commands().get().stream().filter( LinksUtil.withRel( relation ) ).collect( single() ); }
public synchronized ContextResourceClient newClient( Link link ) { if( link == null ) { throw new NullPointerException( "No link specified" ); } return newClient( link.href().get() ); }
public static Predicate<Link> withClass(final String clazz) { return link -> { String classes = link.classes().get(); return classes != null && classes.contains( clazz ); }; }
public static Predicate<Link> withId(final String id) { return link -> link.id().get().equals( id); }
public static Predicate<Link> withText(final String text) { return link -> link.text().get().equals( text); }
@Override public HandlerCommand handleResult( Links result, ContextResourceClient client ) { Link link = LinksUtil.withId( "any", result ); return command( link ); } } ).onCommand( "runbuild", new ResponseHandler()
public T addLink( Link link ) { linksBuilder.prototype().links().get().add( link ); linkBuilder = vbf.newValueBuilderWithPrototype( link ); return (T) this; }
public T addLink( String description, String id ) { try { linkBuilder.prototype().text().set( description ); linkBuilder.prototype().id().set( id ); if( command != null ) { linkBuilder.prototype().href().set( command + "?entity=" + id ); } else { linkBuilder.prototype() .href() .set( ( path == null ? "" : path + "/" ) + URLEncoder.encode( id, "UTF-8" ) + "/" ); } linkBuilder.prototype().rel().set( rel ); linkBuilder.prototype().classes().set( classes ); addLink( linkBuilder.newInstance() ); return (T) this; } catch( UnsupportedEncodingException e ) { e.printStackTrace(); return (T) this; } }
public Links commandwithvalue() { return new LinksBuilder(module). command( "commandwithvalue" ). addLink( "Command ABC","right" ). addLink( "Command XYZ", "wrong" ).newLinks(); }
public static Predicate<Link> withRel(final String rel) { return link -> link.rel().get().equals( rel); }
@Override public Link query( String relation ) { return queries().get().stream().filter( LinksUtil.withRel( relation ) ).collect( single() ); }
@Override public HandlerCommand handleResult( Links result, ContextResourceClient client ) { Link link = LinksUtil.withId( "right", result ); return command( link ); } } ).onCommand( "commandwithvalue", new ResponseHandler()
@Override public Link resource( String relation ) { return resources().get().stream().filter( LinksUtil.withRel( relation ) ).collect( single() ); } }