/
ObjectValidationRule1RestController.java
52 lines (39 loc) · 1.49 KB
/
ObjectValidationRule1RestController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* SPDX-FileCopyrightText: (c) 2023 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.Objects;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.springframework.http.HttpStatus;
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;
/**
* @author Mateus Santana
*/
@RequestMapping("/object/validation/rule/1")
@RestController
public class ObjectValidationRule1RestController extends BaseRestController {
@PostMapping
public ResponseEntity<String> post(
@AuthenticationPrincipal Jwt jwt, @RequestBody String json) {
log(jwt, _log, json);
JSONObject jsonObject = new JSONObject(json);
if (Objects.equals(jsonObject.get("name"), "Invalid Name")) {
jsonObject.put("validationCriteriaMet", false);
}
else {
jsonObject.put("validationCriteriaMet", true);
}
return new ResponseEntity<>(jsonObject.toString(), HttpStatus.OK);
}
private static final Log _log = LogFactory.getLog(
ObjectValidationRule1RestController.class);
}