List of usage examples for com.google.common.collect Multimap putAll
boolean putAll(@Nullable K key, Iterable<? extends V> values);
From source file:com.github.yongchristophertang.engine.web.request.RequestProxy.java
@Override @SuppressWarnings("unchecked") public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // if the method is a default method, process with the default implementation if (method.isDefault()) { return LOOKUP_CONSTRUCTOR.newInstance(method.getDeclaringClass(), MethodHandles.Lookup.PRIVATE) .unreflectSpecial(method, method.getDeclaringClass()).bindTo(proxy).invokeWithArguments(args); }/* www. jav a2 s . c o m*/ Multimap<String, String> queryParams = ArrayListMultimap.create(); Multimap<String, String> bodyParams = ArrayListMultimap.create(); Map<String, String> pathParams = new HashMap<>(); Multimap<String, String> fileParams = ArrayListMultimap.create(); Map<String, String> headerParams = new HashMap<>(); /* Handle the class level annotations: Host and Path */ // The url will be the URL path for the request String url = getHost(method.getDeclaringClass().getAnnotation(Host.class)); /* Handle the method level annotations: Path, HTTPMethod, Produce and Consume */ url += getPath(method.getDeclaringClass().getAnnotation(Path.class)) + getPath(method.getAnnotation(Path.class)); /* Fill out the api's description */ String description = Optional.ofNullable(method.getAnnotation(Description.class)).map(Description::value) .orElse(method.getName()); // Handle Produce and Consume String contentType = Optional.ofNullable(method.getAnnotation(Produce.class)).map(Produce::value) .orElse(null); String accept = Optional.ofNullable(method.getAnnotation(Consume.class)).map(Consume::value).orElse(null); // Handle HTTPMethod, only ONE HTTPMethod can be annotated with one method List<HTTPMethod> httpMethods = Arrays.asList(method.getAnnotations()).stream() .map(a -> a.annotationType().getAnnotation(HTTPMethod.class)).filter(m -> m != null) .collect(Collectors.toList()); if (httpMethods.size() != 1) { throw new IllegalArgumentException("HTTPMethod annotation must be annotated once, no more and no less"); } notNull(httpMethods.get(0).value(), "Http Method is not defined"); HttpMethod httpMethod = HttpMethod.valueOf(httpMethods.get(0).value()); /* Handle the field level annotations: PathParam, BodyParam, QueryParam and HeaderParam. Noted that only the first annotation will be processed. */ Field[] fields = method.getDeclaringClass().getFields(); try { for (Field f : fields) { Object value = f.get(null); if (value != null) { Class<? extends Annotation> annotationType = f.getAnnotations()[0].annotationType(); if (annotationType == PathParam.class) { PathParam a = f.getAnnotation(PathParam.class); pathParams.put(a.value(), a.converter().newInstance().convert(value)); } else if (annotationType == BodyParam.class) { BodyParam a = f.getAnnotation(BodyParam.class); if (value instanceof Collection) { bodyParams.putAll(a.value(), (Iterable<? extends String>) ((Collection) value).stream().map( v -> Try.of(() -> a.converter().newInstance().convert(v)).orElse("")) .collect(Collectors.toList())); } else if (value instanceof Map) { ((Map<String, Object>) value).entrySet().parallelStream() .forEach(e -> bodyParams.put(e.getKey(), e.getValue().toString())); } else { bodyParams.put(a.value(), a.converter().newInstance().convert(value)); } } else if (annotationType == QueryParam.class) { QueryParam a = f.getAnnotation(QueryParam.class); if (value instanceof Collection) { queryParams.putAll(a.value(), (Iterable<? extends String>) ((Collection) value).stream().map( v -> Try.of(() -> a.converter().newInstance().convert(v)).orElse("")) .collect(Collectors.toList())); } else { queryParams.put(a.value(), a.converter().newInstance().convert(value)); } } else if (annotationType == HeaderParam.class) { HeaderParam a = f.getAnnotation(HeaderParam.class); headerParams.put(a.value(), a.converter().newInstance().convert(value)); } } } } catch (Exception e) { LOGGER.error("Cannot process filed level annotations"); } // Stream.of(method.getDeclaringClass().getFields()).filter(f -> Try.of(() -> Optional.of(f.get(null)).isPresent()).orElse(false)).forEach(f -> // Optional.ofNullable(f.getAnnotations()[0]).map(Match.as(String.class) // .whenType(PathParam.class).then(anno -> Try.of(() -> anno.converter().newInstance().convert(f.get(null))) // .onSuccess(p -> pathParams.put(anno.value(), p)).orElse("")) // .whenType(BodyParam.class).then(anno -> Try.of(() -> { // Object object = f.get(null); // if (object instanceof Collection) { // return ((Collection) object).stream().map(e -> Try.of(() -> anno.converter().newInstance().convert(e)).orElse("")).collect(Collectors.toList()); // } else { // return anno.converter().newInstance().convert(object); // } // }).onSuccess(p -> { // if (p instanceof Collection) { // bodyParams.putAll(anno.value(), (Iterable<String>) p); // } else { // bodyParams.put(anno.value(), String.valueOf(p)); // } // }).orElse("")) // .whenType(QueryParam.class).then(anno -> Try.of(() -> anno.converter().newInstance().convert(f.get(null))) // .onSuccess(p -> queryParams.put(anno.value(), p)).orElse("")) // .whenType(HeaderParam.class).then(anno -> Try.of(() -> anno.converter().newInstance().convert(f.get(null))) // .onSuccess(p -> headerParams.put(anno.value(), p)).orElse("")))); /* Handle the method parameter level annotations: PathParam, BodyParam, QueryParam, HeaderParam and FileParam. Noted that only the first annotation will be processed. */ Parameter[] parameters = method.getParameters(); try { for (int i = 0; i < args.length; i++) { if (args[i] != null && parameters[i].getAnnotations() != null) { Class<? extends Annotation> annotationType = parameters[i].getAnnotations()[0].annotationType(); if (annotationType == PathParam.class) { PathParam a = parameters[i].getAnnotation(PathParam.class); pathParams.put(a.value(), a.converter().newInstance().convert(args[i])); } else if (annotationType == BodyParam.class) { BodyParam a = parameters[i].getAnnotation(BodyParam.class); if (args[i] instanceof Collection) { bodyParams.putAll(a.value(), (Iterable<? extends String>) ((Collection) args[i]).stream().map( v -> Try.of(() -> a.converter().newInstance().convert(v)).orElse("")) .collect(Collectors.toList())); } else if (args[i] instanceof Map) { ((Map<String, Object>) args[i]).entrySet().parallelStream() .forEach(e -> bodyParams.put(e.getKey(), e.getValue().toString())); } else { bodyParams.put(a.value(), a.converter().newInstance().convert(args[i])); } } else if (annotationType == QueryParam.class) { QueryParam a = parameters[i].getAnnotation(QueryParam.class); if (args[i] instanceof Collection) { queryParams.putAll(a.value(), (Iterable<? extends String>) ((Collection) args[i]).stream().map( v -> Try.of(() -> a.converter().newInstance().convert(v)).orElse("")) .collect(Collectors.toList())); } else if (args[i] instanceof Map) { ((Map<String, Object>) args[i]).entrySet().parallelStream() .forEach(e -> queryParams.put(e.getKey(), e.getValue().toString())); } else { queryParams.put(a.value(), a.converter().newInstance().convert(args[i])); } } else if (annotationType == HeaderParam.class) { HeaderParam a = parameters[i].getAnnotation(HeaderParam.class); headerParams.put(a.value(), a.converter().newInstance().convert(args[i])); } else if (annotationType == FileParam.class) { FileParam a = parameters[i].getAnnotation(FileParam.class); fileParams.put(a.value(), args[i].toString()); } } } } catch (Exception e) { LOGGER.error("Cannot process parameter level annotations"); } // Stream.range(0, parameters.length).filter( // i -> args[i] != null & parameters[i].getAnnotations() != null).map( // i -> new Tuple2<>(parameters[i].getAnnotations()[0], args[i])).forEach(t -> Option.of(t._1).map(Match.as(String.class) // .whenType(PathParam.class).then(p -> Try.of(() -> p.converter().newInstance().convert(t._2)) // .onSuccess(v -> pathParams.put(p.value(), v)).orElse("")) // .whenType(BodyParam.class).then(p -> Try.of(() -> p.converter().newInstance().convert(t._2)) // .onSuccess(v -> bodyParams.put(p.value(), v)).orElse("")) // .whenType(QueryParam.class).then(p -> Try.of(() -> p.converter().newInstance().convert(t._2)) // .onSuccess(v -> queryParams.put(p.value(), v)).orElse("")) // .whenType(HeaderParam.class).then(p -> Try.of(() -> p.converter().newInstance().convert(t._2)) // .onSuccess(v -> headerParams.put(p.value(), v)).orElse("")) // .whenType(FileParam.class).then(p -> String.valueOf(fileParams.put(p.value(), t._2.toString())) // ))); /** * Local inner class for creating a {@link HttpRequestBuilders} or {@link HttpMultipartRequestBuilders}. * This class provides a {@code build} method to construct the target {@code builders}. */ abstract class RequestBuilderConstructor { HttpRequestBuilders builders; /** * Build path parameters. */ void pathBuild() { pathParams.keySet().stream().forEach(key -> builders.path(key, pathParams.get(key))); } /** * Build query string parameters. */ void queryBuild() { queryParams.keySet().stream().forEach(key -> builders.param(key, queryParams.get(key))); } /** * Build ordinary header parameters. */ void headerBuild() { headerParams.keySet().stream().forEach(key -> builders.header(key, headerParams.get(key))); } /** * Build a special header parameter, ContentType. * The method behaviour varies with different request types.. */ abstract void contentTypeBuild(); /** * Build a special header parameter, Accept. */ void acceptBuild() { Optional.ofNullable(accept).ifPresent(builders::accept); } /** * Build body form parameters. * The method behaviour varies with different request types. */ abstract void bodyBuild(); /** * Attach files with requests. * This method is only valid for multipart request type. */ abstract void fileBuild(); /** * Post processors for returning {@code builders} */ abstract void postProcessor(); /** * Return a {@link HttpRequestBuilders}. */ final HttpRequestBuilders build() { pathBuild(); queryBuild(); headerBuild(); contentTypeBuild(); acceptBuild(); bodyBuild(); fileBuild(); postProcessor(); return builders; } } /** * Local inner class for creating a {@link HttpMultipartRequestBuilders}. */ class MultipartConstructor extends RequestBuilderConstructor { MultipartBodyFormBuilder multipartBodyFormBuilder = MultipartBodyFormBuilder.create(); MultipartConstructor(HttpMultipartRequestBuilders builders) { this.builders = builders; } @Override void contentTypeBuild() { } @Override void bodyBuild() { bodyParams.keySet().stream() .forEach(key -> multipartBodyFormBuilder.param(key, bodyParams.get(key))); } @Override void fileBuild() { fileParams.keySet().stream().forEach(key -> fileParams.get(key).stream().forEach(value -> { if (value.contains(",")) { for (String file : value.split(",")) { multipartBodyFormBuilder.file(key, file); } } else if (!value.isEmpty()) { multipartBodyFormBuilder.file(key, value); } })); } @Override void postProcessor() { HttpMultipartRequestBuilders.class.cast(builders).body(multipartBodyFormBuilder); } } /** * Local inner class for creating a {@link HttpRequestBuilders}. */ class RequestConstructor extends RequestBuilderConstructor { RequestConstructor(HttpRequestBuilders builders) { this.builders = builders; } @Override void contentTypeBuild() { Optional.ofNullable(contentType).ifPresent(builders::contentType); } @Override void bodyBuild() { bodyParams.keySet().stream().forEach(key -> { if (key.equals("")) { // if use a raw string to set up body, then we only add the first value, igonor the further builders.body(bodyParams.get(key).iterator().next()); } else { builders.body(key, bodyParams.get(key)); } }); } @Override void fileBuild() { } @Override void postProcessor() { } } return fileParams.isEmpty() ? new RequestConstructor(new HttpRequestBuilders(httpMethod.getHttpRequest(), url, description)) .build() : new MultipartConstructor( new HttpMultipartRequestBuilders(httpMethod.getHttpRequest(), url, description)).build(); }
From source file:org.eclipse.papyrus.uml.diagram.activity.activitygroup.GroupRequestAdvisor.java
protected Multimap<EReference, IGroupNotifier> fillReqestWithReferendedElement(IGroupRequest request, boolean lookingForParent, boolean onlyContainment) { final Rectangle newBounds = getInitalTargetRequestNewBounds(request); final Multimap<EReference, IGroupNotifier> result = ArrayListMultimap.create(); if (request.getNodeDescpitor() == null) { return result; }/*from www. j a v a 2s. c om*/ List<EReference> references = null; if (lookingForParent) { references = request.getNodeDescpitor().getParentReferences(); } else { references = request.getNodeDescpitor().getChildrenReferences(); } final Multimap<EReference, IGroupNotifier> auxResult = ArrayListMultimap.create(); final Multimap<EReference, Element> eReferenceLookedForMap = ArrayListMultimap.create(); getReferenceElements(request, newBounds, references, eReferenceLookedForMap, auxResult, lookingForParent, onlyContainment, lookingForParent ? request.getNodeDescpitor().getParentEOppositeReferences() : null); /* * Filter ancestors */ for (EReference ref : eReferenceLookedForMap.keySet()) { /* * Filter descendant * Example : * 1 - ActPart1 include in Act1 then Act1 disappear * 2 - ActPart1 include in ActPart2 then ActPart1 disappear */ Object adapter = request.getTargetElement().getAdapter(EObject.class); if (adapter instanceof Element) { Element element = (Element) adapter; Predicate<Element> composedPredicate = Predicates.and(new SameContainerFilter(element), lookingForParent ? new DescendantsFilter(eReferenceLookedForMap.values()) : new AncestorFilter(eReferenceLookedForMap.values())); Collection<Element> filteredCollection = Collections2.filter(eReferenceLookedForMap.get(ref), composedPredicate); if (lookingForParent) { request.getParentEReferenceMap().putAll(ref, filteredCollection); } else { request.getChildrenEReferenceMap().putAll(ref, filteredCollection); } } } for (EReference ref : auxResult.keySet()) { /* * Filter descendant * Example : * 1 - ActPart1 include in Act1 then Act1 disappear * 2 - ActPart1 include in ActPart2 then ActPart1 disappear */ Iterable<IGroupNotifier> resultCollection = Iterables.filter(auxResult.get(ref), new DescendantsFilterIGroupNotifier(auxResult.values())); result.putAll(ref, resultCollection); } return result; }
From source file:org.sosy_lab.cpachecker.cpa.predicate.persistence.PredicateAbstractionsStorage.java
private void parseAbstractionTree() throws IOException, PredicateParsingFailedException { Multimap<Integer, Integer> resultTree = LinkedHashMultimap.create(); Map<Integer, AbstractionNode> resultAbstractions = Maps.newTreeMap(); Set<Integer> abstractionsWithParents = Sets.newTreeSet(); String source = abstractionsFile.getName(); try (BufferedReader reader = abstractionsFile.asCharSource(StandardCharsets.US_ASCII) .openBufferedStream()) {/*from w w w . j av a2 s .co m*/ // first, read first section with initial set of function definitions Pair<Integer, String> defParsingResult = PredicatePersistenceUtils.parseCommonDefinitions(reader, abstractionsFile.toString()); int lineNo = defParsingResult.getFirst(); String commonDefinitions = defParsingResult.getSecond(); String currentLine; int currentAbstractionId = -1; Optional<Integer> currentLocationId = Optional.absent(); Set<Integer> currentSuccessors = Sets.newTreeSet(); AbstractionsParserState parserState = AbstractionsParserState.EXPECT_NODE_DECLARATION; while ((currentLine = reader.readLine()) != null) { lineNo++; currentLine = currentLine.trim(); if (currentLine.isEmpty()) { // blank lines separates sections continue; } if (currentLine.startsWith("//")) { // comment continue; } if (parserState == AbstractionsParserState.EXPECT_NODE_DECLARATION) { // we expect a new section header if (!currentLine.endsWith(":")) { throw new PredicateParsingFailedException( currentLine + " is not a valid abstraction header", source, lineNo); } currentLine = currentLine.substring(0, currentLine.length() - 1).trim(); // strip off ":" if (currentLine.isEmpty()) { throw new PredicateParsingFailedException("empty header is not allowed", source, lineNo); } if (!NODE_DECLARATION_PATTERN.matcher(currentLine).matches()) { throw new PredicateParsingFailedException( currentLine + " is not a valid abstraction header", source, lineNo); } currentLocationId = null; StringTokenizer declarationTokenizer = new StringTokenizer(currentLine, " (,):"); currentAbstractionId = Integer.parseInt(declarationTokenizer.nextToken()); while (declarationTokenizer.hasMoreTokens()) { String token = declarationTokenizer.nextToken().trim(); if (token.length() > 0) { if (token.startsWith("@")) { currentLocationId = Optional.of(Integer.parseInt(token.substring(1))); } else { int successorId = Integer.parseInt(token); currentSuccessors.add(successorId); } } } parserState = AbstractionsParserState.EXPECT_NODE_ABSTRACTION; } else if (parserState == AbstractionsParserState.EXPECT_NODE_ABSTRACTION) { if (!currentLine.startsWith("(assert ") && currentLine.endsWith(")")) { throw new PredicateParsingFailedException("unexpected line " + currentLine, source, lineNo); } BooleanFormula f; try { f = fmgr.parse(commonDefinitions + currentLine); } catch (IllegalArgumentException e) { throw new PredicateParsingFailedException(e, "Formula parsing", lineNo); } AbstractionNode abstractionNode = new AbstractionNode(currentAbstractionId, f, currentLocationId); resultAbstractions.put(currentAbstractionId, abstractionNode); resultTree.putAll(currentAbstractionId, currentSuccessors); abstractionsWithParents.addAll(currentSuccessors); currentAbstractionId = -1; currentSuccessors.clear(); parserState = AbstractionsParserState.EXPECT_NODE_DECLARATION; } } } // Determine root node Set<Integer> nodesWithNoParents = Sets.difference(resultAbstractions.keySet(), abstractionsWithParents); assert nodesWithNoParents.size() <= 1; if (!nodesWithNoParents.isEmpty()) { this.rootAbstractionId = nodesWithNoParents.iterator().next(); } else { this.rootAbstractionId = null; } // Set results this.abstractions = ImmutableMap.copyOf(resultAbstractions); this.abstractionTree = ImmutableMultimap.copyOf(resultTree); }
From source file:org.killbill.billing.client.KillBillClient.java
public Payment completePayment(final PaymentTransaction paymentTransaction, @Nullable final List<String> controlPluginNames, final Map<String, String> pluginProperties, final RequestOptions inputOptions) throws KillBillClientException { Preconditions.checkState(/*from w ww . jav a 2 s . c o m*/ paymentTransaction.getPaymentId() != null || paymentTransaction.getPaymentExternalKey() != null, "PaymentTransaction#paymentId or PaymentTransaction#paymentExternalKey cannot be null"); final String uri = (paymentTransaction.getPaymentId() != null) ? JaxrsResource.PAYMENTS_PATH + "/" + paymentTransaction.getPaymentId() : JaxrsResource.PAYMENTS_PATH; final Multimap<String, String> params = HashMultimap.create(inputOptions.getQueryParams()); if (controlPluginNames != null) { params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, controlPluginNames); } storePluginPropertiesAsParams(pluginProperties, params); final Boolean followLocation = MoreObjects.firstNonNull(inputOptions.getFollowLocation(), Boolean.TRUE); final RequestOptions requestOptions = inputOptions.extend().withQueryParams(params) .withFollowLocation(followLocation).build(); return httpClient.doPut(uri, paymentTransaction, Payment.class, requestOptions); }
From source file:org.killbill.billing.client.KillBillClient.java
public HostedPaymentPageFormDescriptor buildFormDescriptor(final ComboHostedPaymentPage comboHostedPaymentPage, @Nullable final List<String> controlPluginNames, final Map<String, String> pluginProperties, final RequestOptions inputOptions) throws KillBillClientException { final String uri = JaxrsResource.PAYMENT_GATEWAYS_PATH + "/" + JaxrsResource.HOSTED + "/" + JaxrsResource.FORM;/*from w ww . j a va2s . co m*/ final Multimap<String, String> params = LinkedListMultimap.create(inputOptions.getQueryParams()); if (controlPluginNames != null) { params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, controlPluginNames); } storePluginPropertiesAsParams(pluginProperties, params); final RequestOptions requestOptions = inputOptions.extend().withQueryParams(params) .withFollowLocation(false).build(); return httpClient.doPost(uri, comboHostedPaymentPage, HostedPaymentPageFormDescriptor.class, requestOptions); }
From source file:org.killbill.billing.client.KillBillClient.java
public Payment createPayment(final ComboPaymentTransaction comboPaymentTransaction, @Nullable final List<String> controlPluginNames, final Map<String, String> pluginProperties, final RequestOptions inputOptions) throws KillBillClientException { final String uri = JaxrsResource.PAYMENTS_PATH + "/" + JaxrsResource.COMBO; final Multimap<String, String> queryParams = LinkedListMultimap.create(inputOptions.getQueryParams()); if (controlPluginNames != null) { queryParams.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, controlPluginNames); }//from ww w . ja v a2s . c o m storePluginPropertiesAsParams(pluginProperties, queryParams); final Boolean followLocation = MoreObjects.firstNonNull(inputOptions.getFollowLocation(), Boolean.TRUE); final RequestOptions requestOptions = inputOptions.extend().withQueryParams(queryParams) .withFollowLocation(followLocation).build(); return httpClient.doPost(uri, comboPaymentTransaction, Payment.class, requestOptions); }
From source file:org.killbill.billing.client.KillBillClient.java
public HostedPaymentPageFormDescriptor buildFormDescriptor(final HostedPaymentPageFields fields, final UUID kbAccountId, @Nullable final UUID kbPaymentMethodId, @Nullable final List<String> controlPluginNames, final Map<String, String> pluginProperties, final RequestOptions inputOptions) throws KillBillClientException { final String uri = JaxrsResource.PAYMENT_GATEWAYS_PATH + "/" + JaxrsResource.HOSTED + "/" + JaxrsResource.FORM + "/" + kbAccountId; final Multimap<String, String> params = LinkedListMultimap.create(inputOptions.getQueryParams()); storePluginPropertiesAsParams(pluginProperties, params); if (controlPluginNames != null) { params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, controlPluginNames); }/*w w w. j a v a2s .co m*/ if (kbPaymentMethodId != null) { params.put(JaxrsResource.QUERY_PAYMENT_METHOD_ID, kbPaymentMethodId.toString()); } final RequestOptions requestOptions = inputOptions.extend().withQueryParams(params) .withFollowLocation(false).build(); return httpClient.doPost(uri, fields, HostedPaymentPageFormDescriptor.class, requestOptions); }
From source file:org.killbill.billing.client.KillBillClient.java
public Payment chargebackPayment(final PaymentTransaction paymentTransaction, @Nullable final List<String> controlPluginNames, final Map<String, String> pluginProperties, final RequestOptions inputOptions) throws KillBillClientException { Preconditions.checkState(//from w ww. j a v a2s. c o m paymentTransaction.getPaymentId() != null || paymentTransaction.getPaymentExternalKey() != null, "PaymentTransaction#paymentId or PaymentTransaction#paymentExternalKey cannot be null"); Preconditions.checkNotNull(paymentTransaction.getAmount(), "PaymentTransaction#amount cannot be null"); final String uri = (paymentTransaction.getPaymentId() != null) ? JaxrsResource.PAYMENTS_PATH + "/" + paymentTransaction.getPaymentId() + "/" + JaxrsResource.CHARGEBACKS : JaxrsResource.PAYMENTS_PATH + "/" + JaxrsResource.CHARGEBACKS; final Multimap<String, String> params = LinkedListMultimap.create(inputOptions.getQueryParams()); storePluginPropertiesAsParams(pluginProperties, params); if (controlPluginNames != null) { params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, controlPluginNames); } final Boolean followLocation = MoreObjects.firstNonNull(inputOptions.getFollowLocation(), Boolean.TRUE); final RequestOptions requestOptions = inputOptions.extend().withQueryParams(params) .withFollowLocation(followLocation).build(); return httpClient.doPost(uri, paymentTransaction, Payment.class, requestOptions); }
From source file:org.killbill.billing.client.KillBillClient.java
public Payment captureAuthorization(final PaymentTransaction paymentTransaction, @Nullable final List<String> controlPluginNames, final Map<String, String> pluginProperties, final RequestOptions inputOptions) throws KillBillClientException { Preconditions.checkState(// w ww . j a v a2 s . c o m paymentTransaction.getPaymentId() != null || paymentTransaction.getPaymentExternalKey() != null, "PaymentTransaction#paymentId or PaymentTransaction#paymentExternalKey cannot be null"); Preconditions.checkNotNull(paymentTransaction.getAmount(), "PaymentTransaction#amount cannot be null"); final String uri = (paymentTransaction.getPaymentId() != null) ? JaxrsResource.PAYMENTS_PATH + "/" + paymentTransaction.getPaymentId() : JaxrsResource.PAYMENTS_PATH; final Multimap<String, String> params = LinkedListMultimap.create(inputOptions.getQueryParams()); storePluginPropertiesAsParams(pluginProperties, params); if (controlPluginNames != null) { params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, controlPluginNames); } final Boolean followLocation = MoreObjects.firstNonNull(inputOptions.getFollowLocation(), Boolean.TRUE); final RequestOptions requestOptions = inputOptions.extend().withQueryParams(params) .withFollowLocation(followLocation).build(); return httpClient.doPost(uri, paymentTransaction, Payment.class, requestOptions); }
From source file:org.killbill.billing.client.KillBillClient.java
public Payment refundPayment(final PaymentTransaction paymentTransaction, @Nullable final List<String> controlPluginNames, final Map<String, String> pluginProperties, final RequestOptions inputOptions) throws KillBillClientException { Preconditions.checkState(//from w w w. j a v a2 s.c o m paymentTransaction.getPaymentId() != null || paymentTransaction.getPaymentExternalKey() != null, "PaymentTransaction#paymentId or PaymentTransaction#paymentExternalKey cannot be null"); Preconditions.checkNotNull(paymentTransaction.getAmount(), "PaymentTransaction#amount cannot be null"); final String uri = (paymentTransaction.getPaymentId() != null) ? JaxrsResource.PAYMENTS_PATH + "/" + paymentTransaction.getPaymentId() + "/" + JaxrsResource.REFUNDS : JaxrsResource.PAYMENTS_PATH + "/" + JaxrsResource.REFUNDS; final Multimap<String, String> params = LinkedListMultimap.create(inputOptions.getQueryParams()); storePluginPropertiesAsParams(pluginProperties, params); if (controlPluginNames != null) { params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, controlPluginNames); } final Boolean followLocation = MoreObjects.firstNonNull(inputOptions.getFollowLocation(), Boolean.TRUE); final RequestOptions requestOptions = inputOptions.extend().withQueryParams(params) .withFollowLocation(followLocation).build(); return httpClient.doPost(uri, paymentTransaction, Payment.class, requestOptions); }