Skip to content

Commit

Permalink
chore: auto update client extensions samples
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 18, 2024
1 parent 182accb commit 753468a
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM liferay/jar-runner:latest

COPY *.jar /opt/liferay/jar-runner.jar

#ENV LIFERAY_JAR_RUNNER_JAVA_OPTS="-Xmx512m"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"cpu": 1,
"env": {
"LIFERAY_ROUTES_CLIENT_EXTENSION": "/etc/liferay/lxc/ext-init-metadata",
"LIFERAY_ROUTES_DXP": "/etc/liferay/lxc/dxp-metadata"
},
"environments": {
"infra": {
"deploy": false
}
},
"id": "__PROJECT_ID__",
"kind": "Deployment",
"livenessProbe": {
"httpGet": {
"path": "/ready",
"port": 58081
}
},
"loadBalancer": {
"targetPort": 58081
},
"memory": 512,
"readinessProbe": {
"httpGet": {
"path": "/ready",
"port": 58081
}
},
"scale": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

export default function CommerceCheckoutStep() {
const commerceCheckoutStepContainer = document.getElementById(
'commerceCheckoutStepContainer'
);

const newInput = document.createElement('input');

const inputName =
'_com_liferay_commerce_checkout_web_internal_portlet_CommerceCheckoutPortlet_pon';

newInput.setAttribute('id', inputName);
newInput.setAttribute('name', inputName);

newInput.setAttribute('placeholder', 'Purchase order number');
newInput.setAttribute('type', 'text');

commerceCheckoutStepContainer.appendChild(newInput);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins.defaults", version: "latest.release"
classpath group: "org.springframework.boot", name: "spring-boot-gradle-plugin", version: "2.7.18"
}

repositories {
maven {
url new File(rootProject.projectDir, "../../.m2-tmp")
}

maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
}

apply plugin: "com.liferay.source.formatter"
apply plugin: "java-library"
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: "5.3.4"
implementation group: "com.liferay", name: "org.apache.commons.logging", version: "1.2.LIFERAY-PATCHED-2"
implementation group: "org.json", name: "json", version: "20231013"
implementation group: "org.springframework.boot", name: "spring-boot-starter-oauth2-resource-server", version: "2.7.18"
implementation group: "org.springframework.boot", name: "spring-boot-starter-web", version: "2.7.18"
implementation group: "org.springframework.boot", name: "spring-boot-starter-webflux", version: "2.7.18"
}

repositories {
maven {
url new File(rootProject.projectDir, "../../.m2-tmp")
}

maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
assemble:
- from: assets
into: static
- fromTask: bootJar
liferay-sample-commerce-checkout-step:
active: true
checkoutStepLabel: liferay-sample-commerce-checkout-step-label
checkoutStepName: liferay-sample-commerce-checkout-step-name
checkoutStepOrder: 25
name: Liferay Sample Commerce Checkout Step
oAuth2ApplicationExternalReferenceCode: liferay-sample-commerce-checkout-step-oauth-application-user-agent
order: true
sennaDisabled: true
showControls: true
type: commerceCheckoutStep
visible: true
liferay-sample-commerce-checkout-step-oauth-application-user-agent:
.serviceAddress: localhost:58081
.serviceScheme: http
name: Liferay Sample Commerce Checkout Step OAuth Application User Agent
scopes:
- Liferay.Headless.Admin.Workflow.everything
type: oAuthApplicationUserAgent
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"dependencies": {
"react": "16.12.0",
"serve": "^14.2.0"
},
"description": "Liferay Sample Commerce Checkout Step",
"name": "liferay-sample-commerce-checkout-step",
"type": "module",
"version": "1.0.0",
"workspaces": [
"src/main/resources/assets/liferay-sample-commerce-checkout-step"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.sample;

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;
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
*/
@RequestMapping("/action")
@RestController
public class ActionRestController extends BaseRestController {

@PostMapping
public ResponseEntity<String> post(
@AuthenticationPrincipal Jwt jwt, @RequestBody String json) {

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(
new JSONObject(
).put(
"purchaseOrderNumber", jsonObject.getString("pon")
).toString()
).header(
HttpHeaders.AUTHORIZATION, "Bearer " + jwt.getTokenValue()
).retrieve(
).bodyToMono(
String.class
).block(),
HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.sample;

import java.util.Map;

import org.apache.commons.logging.Log;

import org.json.JSONObject;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.oauth2.jwt.Jwt;

/**
* @author Raymond Augé
* @author Gregory Amerson
* @author Brian Wing Shun Chan
*/
public abstract class BaseRestController {

protected void log(Jwt jwt, Log log) {
if (log.isInfoEnabled()) {
log.info("JWT Claims: " + jwt.getClaims());
log.info("JWT ID: " + jwt.getId());
log.info("JWT Subject: " + jwt.getSubject());
}
}

protected void log(Jwt jwt, Log log, Map<String, String> parameters) {
if (log.isInfoEnabled()) {
log.info("JWT Claims: " + jwt.getClaims());
log.info("JWT ID: " + jwt.getId());
log.info("JWT Subject: " + jwt.getSubject());
log.info("Parameters: " + parameters);
}
}

protected void log(Jwt jwt, Log log, String json) {
if (log.isInfoEnabled()) {
try {
JSONObject jsonObject = new JSONObject(json);

log.info("JSON: " + jsonObject.toString(4));
}
catch (Exception exception) {
log.error("JSON: " + json, exception);
}

log.info("JWT Claims: " + jwt.getClaims());
log.info("JWT ID: " + jwt.getId());
log.info("JWT Subject: " + jwt.getSubject());
}
}

@Value("${com.liferay.lxc.dxp.mainDomain}")
protected String lxcDXPMainDomain;

@Value("${com.liferay.lxc.dxp.server.protocol}")
protected String lxcDXPServerProtocol;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.sample;

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

/**
* @author Raymond Augé
* @author Gregory Amerson
* @author Brian Wing Shun Chan
*/
@RequestMapping("/ready")
@RestController
public class ReadyRestController extends BaseRestController {

@GetMapping
public String get() {
return "READY";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.sample;

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

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;

/**
* @author Raymond Augé
* @author Gregory Amerson
* @author Brian Wing Shun Chan
*/
@Import(ClientExtensionUtilSpringBootComponentScan.class)
@SpringBootApplication
public class SampleSpringBootApplication {

public static void main(String[] args) {
SpringApplication.run(SampleSpringBootApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# LXC
#

com.liferay.lxc.dxp.domains=localhost:8080
com.liferay.lxc.dxp.mainDomain=localhost:8080
com.liferay.lxc.dxp.server.protocol=http

#
# OAuth
#

liferay.oauth.application.external.reference.codes=liferay-sample-commerce-checkout-step-oauth-application-user-agent
liferay.oauth.urls.excludes=/ready

#
# Spring Boot
#

server.port=58081
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.config.import=\
classpath:/application-default.properties,\
optional:configtree:${LIFERAY_ROUTES_CLIENT_EXTENSION}/,\
optional:configtree:${LIFERAY_ROUTES_DXP}/
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.liferay.sample;

import java.util.UUID;

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

Expand Down Expand Up @@ -32,11 +34,14 @@ public ResponseEntity<String> post(

log(jwt, _log, json);

JSONObject jsonObject = new JSONObject();

jsonObject.put("paymentStatus", 2);

return new ResponseEntity<>(jsonObject.toString(), HttpStatus.OK);
return new ResponseEntity<>(
new JSONObject(
).put(
"paymentStatus", 2
).put(
"transactionCode", UUID.randomUUID()
).toString(),
HttpStatus.OK);
}

private static final Log _log = LogFactory.getLog(
Expand Down
Loading

0 comments on commit 753468a

Please sign in to comment.