24 package org.lightjason.agentspeak.action.builtin.web.graphql;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.apache.http.client.methods.HttpPost;
28 import org.apache.http.entity.StringEntity;
38 import javax.annotation.Nonnull;
39 import java.io.IOException;
40 import java.io.UncheckedIOException;
41 import java.text.MessageFormat;
42 import java.util.List;
44 import java.util.stream.Collectors;
45 import java.util.stream.Stream;
56 protected static final ObjectMapper
JSONMAPPER =
new ObjectMapper();
87 protected static Stream<ITerm>
sendquery( @Nonnull
final String p_url, @Nonnull
final String p_query )
throws IOException
89 final HttpPost l_post =
httppost( p_url );
90 l_post.setHeader(
"Content-Type",
"application/json" );
91 l_post.setEntity(
new StringEntity( p_query ) );
99 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return )
101 final List<ITerm> l_argument =
CCommon.
flatten( p_argument ).collect( Collectors.toList() );
102 if ( l_argument.size() < 3 )
108 p_argument.size() == 3
109 ?
CLiteral.
from( l_argument.get( l_argument.size() - 1 ).<String>raw(),
sendquery( l_argument.get( 0 ).raw(), this.
query( l_argument.get( 1 ) ) ) )
111 l_argument.stream().skip( 2 ).map(
ITerm::<String>raw ),
112 sendquery( l_argument.get( 0 ).raw(), this.
query( l_argument.get( 1 ) ) )
116 catch (
final IOException l_exception )
118 throw new UncheckedIOException( l_exception );
134 return MessageFormat.format(
135 "'{'\"query\" : \"{0}\"'}'",
abstract String argumentquery( @Nonnull final ITerm p_argument)
convert argument into graphql query
static Stream< ITerm > flatterm( @Nullable final Object p_object)
converts an object into a term stream
final int minimalArgumentNumber()
minimum number of arguments
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
static String httppostexecute( @Nonnull final HttpPost p_post)
execute http-post request
String query( @Nonnull final ITerm p_argument)
converts a term argument to a graphql query
static Stream< ITerm > sendquery( @Nonnull final String p_url, @Nonnull final String p_query)
executes graphql query and returns a stream of terms of the result
static ITerm baseliteral( @Nonnull final Stream< String > p_functor, @Nonnull final Stream< ITerm > p_values)
creates a literal structure from a stream of string elements, the string stream will be build in a tr...
IBaseGraphQL(final int p_length)
ctor
execution context with local data
static Stream< ITerm > flatten( @Nonnull final Collection<? extends ITerm > p_terms)
flat term-in-term collection into a straight term list
static HttpPost httppost( @Nonnull final String p_url)
returns a http-post connection
static final ObjectMapper JSONMAPPER
json mapper
result for an immutable fuzzy value
default generic literal class for agent beliefs a literal consists of a functor, an optional list of ...
static ILiteral from( @Nonnull final String p_functor, @Nullable final ITerm... p_values)
factory
static final long serialVersionUID
serial id
base class to read data from the restful service
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation