Skip to content

Commit

Permalink
chore: auto update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 11, 2024
1 parent a4e2d74 commit 29c6b0f
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@

package com.liferay.sample;

import com.liferay.petra.string.StringBundler;
import com.liferay.client.extension.util.spring.boot.BaseRestController;

import org.json.JSONObject;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;

/**
* @author Andrea Sbarra
Expand All @@ -35,27 +32,14 @@ public ResponseEntity<String> post(
JSONObject jsonObject = new JSONObject(json);

return new ResponseEntity<>(
WebClient.create(
StringBundler.concat(
lxcDXPServerProtocol, "://", lxcDXPMainDomain,
"/o/headless-commerce-delivery-cart/v1.0/carts/",
jsonObject.getLong("commerceOrderId"))
).patch(
).accept(
MediaType.APPLICATION_JSON
).contentType(
MediaType.APPLICATION_JSON
).bodyValue(
patch(
"Bearer " + jwt.getTokenValue(),
new JSONObject(
).put(
"purchaseOrderNumber", jsonObject.getString("pon")
).toString()
).header(
HttpHeaders.AUTHORIZATION, "Bearer " + jwt.getTokenValue()
).retrieve(
).bodyToMono(
String.class
).block(),
).toString(),
"/o/headless-commerce-delivery-cart/v1.0/carts/" +
jsonObject.getLong("commerceOrderId")),
HttpStatus.OK);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;
import com.liferay.petra.string.StringBundler;

import org.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;

import java.util.Objects;

import org.apache.commons.logging.Log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@

package com.liferay.sample;

import com.liferay.client.extension.util.spring.boot.BaseRestController;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.json.JSONObject;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;

import reactor.core.publisher.Mono;

/**
* @author Raymond Augé
Expand All @@ -41,48 +37,16 @@ public ResponseEntity<String> post(

log(jwt, _log, json);

WebClient.Builder builder = WebClient.builder();

WebClient webClient = builder.baseUrl(
lxcDXPServerProtocol + "://" + lxcDXPMainDomain
).defaultHeader(
HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE
).defaultHeader(
HttpHeaders.AUTHORIZATION, "Bearer " + jwt.getTokenValue()
).defaultHeader(
HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE
).build();

JSONObject jsonObject = new JSONObject(json);

webClient.post(
).uri(
jsonObject.getString("transitionURL")
).bodyValue(
"{\"transitionName\": \"approve\"}"
).exchangeToMono(
clientResponse -> {
HttpStatus httpStatus = clientResponse.statusCode();

if (httpStatus.is2xxSuccessful()) {
return clientResponse.bodyToMono(String.class);
}
else if (httpStatus.is4xxClientError()) {
return Mono.just(httpStatus.getReasonPhrase());
}

Mono<WebClientResponseException> mono =
clientResponse.createException();
String response = post(
"Bearer " + jwt.getTokenValue(),
"{\"transitionName\": \"approve\"}",
jsonObject.getString("transitionURL"));

return mono.flatMap(Mono::error);
}
).doOnNext(
output -> {
if (_log.isInfoEnabled()) {
_log.info("Output: " + output);
}
}
).subscribe();
if (_log.isInfoEnabled()) {
_log.info("Output: " + response);
}

return new ResponseEntity<>(json, HttpStatus.OK);
}
Expand Down
2 changes: 1 addition & 1 deletion liferay-sample-site-initializer/client-extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ liferay-sample-site-initializer:
liferay-sample-site-initializer-oauth-application-headless-server:
.serviceAddress: localhost:8080
.serviceScheme: http
name: Liferay Sample OAuth Application Headless Server
name: Liferay Sample Site Initializer OAuth Application Headless Server
scopes:
- Liferay.Headless.Site.everything
type: oAuthApplicationHeadlessServer

0 comments on commit 29c6b0f

Please sign in to comment.