From 30c23a090f44fef6295695877186f821926b7fe7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 29 Aug 2024 01:09:23 +0000 Subject: [PATCH] chore: auto update samples --- liferay-sample-etc-spring-boot/build.gradle | 1 + .../client-extension.yaml | 1 + .../sample/ObjectAction2RestController.java | 45 ++++++++++++++++--- .../resources/application-default.properties | 8 ++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/liferay-sample-etc-spring-boot/build.gradle b/liferay-sample-etc-spring-boot/build.gradle index 2fe3930..1275ac7 100644 --- a/liferay-sample-etc-spring-boot/build.gradle +++ b/liferay-sample-etc-spring-boot/build.gradle @@ -21,6 +21,7 @@ apply plugin: "org.springframework.boot" dependencies { implementation group: "com.liferay", name: "com.liferay.client.extension.util.spring.boot", version: "latest.release" + implementation group: "com.liferay", name: "com.liferay.petra.string", version: "latest.release" implementation group: "com.liferay", name: "org.apache.commons.logging", version: "1.2.LIFERAY-PATCHED-2" implementation group: "net.datafaker", name: "datafaker", version: "1.9.0" implementation group: "org.json", name: "json", version: "20231013" diff --git a/liferay-sample-etc-spring-boot/client-extension.yaml b/liferay-sample-etc-spring-boot/client-extension.yaml index 0f1603a..33888a8 100644 --- a/liferay-sample-etc-spring-boot/client-extension.yaml +++ b/liferay-sample-etc-spring-boot/client-extension.yaml @@ -10,6 +10,7 @@ liferay-sample-etc-spring-boot-oauth-application-user-agent: .serviceScheme: http name: Liferay Sample Etc Spring Boot OAuth Application User Agent scopes: + - Liferay.Headless.Admin.User.everything - Liferay.Headless.Admin.Workflow.everything type: oAuthApplicationUserAgent liferay-sample-etc-spring-boot-object-action-1: diff --git a/liferay-sample-etc-spring-boot/src/main/java/com/liferay/sample/ObjectAction2RestController.java b/liferay-sample-etc-spring-boot/src/main/java/com/liferay/sample/ObjectAction2RestController.java index 6ac7f85..8136e5a 100644 --- a/liferay-sample-etc-spring-boot/src/main/java/com/liferay/sample/ObjectAction2RestController.java +++ b/liferay-sample-etc-spring-boot/src/main/java/com/liferay/sample/ObjectAction2RestController.java @@ -5,10 +5,13 @@ package com.liferay.sample; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import com.liferay.petra.string.StringBundler; +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; @@ -16,6 +19,7 @@ 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 Raymond Augé @@ -30,12 +34,39 @@ public class ObjectAction2RestController extends BaseRestController { public ResponseEntity post( @AuthenticationPrincipal Jwt jwt, @RequestBody String json) { - log(jwt, _log, json); + JSONObject jsonObject = new JSONObject(json); - return new ResponseEntity<>(json, HttpStatus.OK); - } + JSONObject modelDTOAccountJSONObject = jsonObject.getJSONObject( + "modelDTOAccount"); - private static final Log _log = LogFactory.getLog( - ObjectAction2RestController.class); + if (modelDTOAccountJSONObject == null) { + return new ResponseEntity<>(json, HttpStatus.OK); + } + + return new ResponseEntity<>( + WebClient.create( + StringBundler.concat( + lxcDXPServerProtocol, "://", lxcDXPMainDomain, + "/o/headless-admin-user/v1.0/user-accounts/", + modelDTOAccountJSONObject.getLong("id")) + ).patch( + ).accept( + MediaType.APPLICATION_JSON + ).contentType( + MediaType.APPLICATION_JSON + ).bodyValue( + new JSONObject( + ).put( + "alternateName", + modelDTOAccountJSONObject.getString("givenName") + ).toString() + ).header( + HttpHeaders.AUTHORIZATION, "Bearer " + jwt.getTokenValue() + ).retrieve( + ).bodyToMono( + String.class + ).block(), + HttpStatus.OK); + } } \ No newline at end of file diff --git a/liferay-sample-etc-spring-boot/src/main/resources/application-default.properties b/liferay-sample-etc-spring-boot/src/main/resources/application-default.properties index 0742e16..27622cb 100644 --- a/liferay-sample-etc-spring-boot/src/main/resources/application-default.properties +++ b/liferay-sample-etc-spring-boot/src/main/resources/application-default.properties @@ -1,3 +1,11 @@ +# +# LXC +# + +com.liferay.lxc.dxp.domains=localhost:8080 +com.liferay.lxc.dxp.mainDomain=localhost:8080 +com.liferay.lxc.dxp.server.protocol=http + # # OAuth #