");
result.append("
Parametri
");
@@ -76,13 +77,13 @@ public class ManualHtml extends Manual {
result.append("
");
result.append("");
result.append("Campo | ");
- result.append("Obbligatorio | ");
+ result.append("Opzionale | ");
result.append("Tipo | ");
result.append("Descrizione | ");
result.append("
");
result.append("");
result.append("
");
- result.append(printTableParameters(parameters, 0, false));
+ result.append(printTableParameters(parameters, 0));
result.append("");
result.append("");
}
@@ -103,7 +104,7 @@ public class ManualHtml extends Manual {
result.append("");
result.append("");
result.append("
");
- result.append(printTableParameters(parameters, 0, true));
+ result.append(printTableParameters(parameters, 0));
result.append("");
result.append("");
}
@@ -114,8 +115,9 @@ public class ManualHtml extends Manual {
result.append("
");
result.append("
");
result.append("
");
- result.append("Note
[T] = Richiede token di autenticazione: header di richiesta \"");
- result.append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro JSON \"").append(Parameters.TOKEN);
+ result.append("Note
[T] = Richiede token di autenticazione: header di richiesta \"");
+ result.append(Parameters.X_AUTH_TOKEN).append("\" oppure per il metodo POST parametro JSON \"")
+ .append(Parameters.TOKEN);
result.append("\"
");
result.append("
");
result.append("
");
@@ -125,33 +127,20 @@ public class ManualHtml extends Manual {
ServletResponseUtil.write(response, result.toString());
}
- private String printTableParameters(List
parameters, int level, boolean output) {
+ private String printTableParameters(List parameters, int level) {
StringBuilder result = new StringBuilder();
for (Parameter parameter : parameters) {
- result.append("");
- result.append("")
- .append(parameter.getName()).append(" | ");
- result.append("");
- if (output) {
- if (parameter.isRequired()) {
- result.append("No");
- } else {
- result.append("Sì");
- }
- } else {
- if (parameter.isRequired()) {
- result.append("Sì");
- } else {
- result.append("No");
- }
+ result.append(" |
");
+ for (int i = 0; i < level; i++) {
+ result.append(">");
}
- result.append(" | ");
- result.append("").append(parameter.getType().toString()).append(" | ");
- result.append("").append(parameter.getDescription()).append(" | ");
- result.append("
");
+ result.append(StringPool.SPACE).append(parameter.getName()).append("")
+ .append(parameter.isRequired() ? "No" : "Sì").append(" | ")
+ .append(parameter.getType().toString()).append(" | ").append(parameter.getDescription())
+ .append(" | ");
if (parameter.getType().equals(TYPES.ARRAY)) {
- result.append(printTableParameters(parameter.getSubParameters(), level + 1, output));
+ result.append(printTableParameters(parameter.getSubParameters(), level + 1));
}
}
return result.toString();
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/VerifyApplication.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/VerifyApplication.java
new file mode 100644
index 00000000..8e1bbd7a
--- /dev/null
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/VerifyApplication.java
@@ -0,0 +1,62 @@
+package it.mwg.sicilia.sue.api.v1.command.impl;
+
+import it.mwg.sicilia.sue.api.v1.Parameters;
+import it.mwg.sicilia.sue.api.v1.Response;
+import it.mwg.sicilia.sue.api.v1.Status;
+import it.mwg.sicilia.sue.api.v1.command.Command;
+import it.mwg.sicilia.sue.api.v1.parameter.Parameter;
+import it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES;
+import it.tref.liferay.portos.bo.model.IntPratica;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.liferay.portal.kernel.util.Validator;
+
+public class VerifyApplication extends Command {
+
+ @SuppressWarnings("serial")
+ private static final List INPUT_PARAMETERS = new ArrayList() {
+ {
+ add(new Parameter(Parameters.APPLICATION_ID, TYPES.INT, "Id dell'istanza"));
+ }
+ };
+
+ @SuppressWarnings("serial")
+ private static final List OUTPUT_PARAMETERS = new ArrayList() {
+ {
+ addAll(BASE_OUTPUT_PARAMETERS);
+ add(new Parameter(Parameters.ADDITIONAL_INFO, TYPES.STRING,
+ "Eventuali informazioni aggiuntive sull'operazione o sugli errori incontrati", false));
+ }
+ };
+
+ public VerifyApplication(String description, String... methods) {
+ super(description, methods);
+ }
+
+ @Override
+ public void run(HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+ if (verifyAccessToken(request, response)) {
+ IntPratica intPratica = getSecureIntPratica(response);
+ if (Validator.isNotNull(intPratica)) {
+ Response.write(response, Status.OK);
+ }
+ }
+ }
+
+ @Override
+ public List getInputParameters() {
+ return INPUT_PARAMETERS;
+ }
+
+ @Override
+ public List getOutputParameters() {
+ return OUTPUT_PARAMETERS;
+ }
+
+}
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/ApiUtil.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/ApiUtil.java
index 25552287..af06e52a 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/ApiUtil.java
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/util/ApiUtil.java
@@ -5,10 +5,14 @@ import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
+import javax.servlet.http.HttpServletRequest;
+
import org.apache.commons.lang.StringUtils;
import com.itextpdf.text.pdf.PdfReader;
+import com.liferay.portal.kernel.util.Http;
import com.liferay.portal.kernel.util.PropsUtil;
+import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
public class ApiUtil {
@@ -34,6 +38,19 @@ public class ApiUtil {
return Validator.isNotNull(PropsUtil.get("mwg.test.display"));
}
+ public static String getBaseUrl(HttpServletRequest request) {
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(request.isSecure() ? Http.HTTPS_WITH_SLASH : Http.HTTP_WITH_SLASH);
+ sb.append(request.getServerName());
+ if ((request.isSecure() && (request.getServerPort() != Http.HTTPS_PORT))
+ || (!request.isSecure() && (request.getServerPort() != Http.HTTP_PORT))) {
+ sb.append(StringPool.COLON).append(request.getServerPort());
+ }
+ sb.append(request.getContextPath()).append(request.getServletPath()).append(StringPool.FORWARD_SLASH);
+ return sb.toString();
+ }
+
public static String underscoreToCamelCase(String underscore) {
StringBuilder sb = new StringBuilder();
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/startup/Startup.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/startup/Startup.java
index ed69380f..dada5ae9 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/startup/Startup.java
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/startup/Startup.java
@@ -29,7 +29,6 @@ public class Startup extends SimpleAction {
String secret = null;
try {
secret = ApiSettingLocalServiceUtil.get(companyId, ApiConstants.API_SECRET);
- _log.info("apiSetting = " + secret);
if (Validator.isNull(secret)) {
SecureRandom rnd = new SecureRandom();
byte[] bytes = new byte[32];
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/README.txt b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/README.txt
index be1fd1b0..4d92044c 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/README.txt
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/README.txt
@@ -1,5 +1,6 @@
Prima di operare aggiornare il file SueApi/v1/config/api.json con i corretti
-parametri di accesso.
+parametri di accesso, oppure utilizzare il comando:
+ php client.php username password
Compatibile con php 7.1+
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/functions.php b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/functions.php
index 2687bb12..f63d4e5f 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/functions.php
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/functions.php
@@ -1,5 +1,7 @@
getHelp($command);
+ echo "\nDigitare help per maggiori informazioni sul comando.\n";
+ echo "L'opzione --debug visualizza a schermo le comunicazioni con il server.\n";
+ echo " Es.: php client.php nop --debug\n";
+}
+
+function helpSetLogin(string $program)
+{
+ echo "Uso: php $program set_login \n";
+ echo "Salva le credenziali per l'accesso\n\n";
+ echo "**username: Nome utente\n";
+ echo "**password: Password\n\n";
+ echo "** = parametro obbligatorio\n";
+}
+
+function helpSetMethod(string $program)
+{
+ echo "Uso: php $program set_method \n";
+ echo " Imposta il metodo predefinito per le richieste (GET o POST)\n\n";
+ echo "**method: Il metodo predefinito (GET o POST)\n";
+ echo "** = parametro obbligatorio\n";
+}
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Client.php b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Client.php
index 04ddc9c0..8f0f40f2 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Client.php
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Client.php
@@ -16,7 +16,7 @@ class Client
public function login(?string $username = null, ?string $password = null)
{
- $response = $this->exec(Commands::LOGIN, [
+ $response = $this->exec(Commands::LOGIN, true, [
Parameters::USERNAME => $username ?? $this->config->getUsername(),
Parameters::PASSWORD => $password ?? $this->config->getPassword(),
]);
@@ -33,20 +33,25 @@ class Client
$this->config->save();
}
+ public function setMethod(string $method)
+ {
+ $this->config->setDefaultMethod(strtoupper($method));
+ $this->config->save();
+ }
+
//{{METHODS}}//
- public static function getHelp(string $command = '')
+ public static function getHelp(string $application, string $command = '')
{
- global $argv;
$help = [
//{{HELP_ARRAY}}//
][$command] ?? ["Nessun aiuto per $command"];
return implode("\n", $help) . "\n";
}
- private function exec(string $command, ?array $payload = null, bool $secure = true)
+ private function exec(string $command, bool $post = true, ?array $payload = null, bool $secure = true)
{
- $data = $this->curlExec($command, $payload, $secure);
+ $data = $this->curlExec($command, $post, $payload, $secure);
if (is_array($data)) {
if (!isset($data[Parameters::STATUS_CODE])) {
die("Risposta del server non corretta.\n$" . json_encode($data) . "\n");
@@ -59,22 +64,26 @@ class Client
return $data;
}
- private function curlExec(string $command, ?array $payload = null, bool $secure = true)
+ private function curlExec(string $command, bool $post = true, ?array $payload = null, bool $secure = true)
{
- $url = "{$this->config->getEndpoint()}/$command";
- $post = (null !== $payload);
- $curl = curl_init($url);
+ $url = "{$this->config->getEndpoint()}$command";
+ $curl = curl_init();
if ($post) {
- $json = json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
curl_setopt_array($curl, [
CURLOPT_HTTPHEADER => ['Content-Type:application/json; charset=UTF-8'],
CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => $json,
]);
+ if (null !== $payload) {
+ $json = json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
+ }
if (DEBUG) {
- echo "DEBUG: POST $url > $json\n";
+ echo "DEBUG: POST $url" . (isset($json) ? " > $json" : '') . "\n";
}
} else {
+ if (null != $payload) {
+ $url .= '?' . http_build_query($payload);
+ }
if (DEBUG) {
echo "DEBUG: GET $url\n";
}
@@ -82,7 +91,10 @@ class Client
if ($secure) {
curl_setopt($curl, CURLOPT_HTTPHEADER, [Parameters::X_AUTH_TOKEN . ': ' . $this->token]);
}
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt_array($curl, [
+ CURLOPT_URL => $url,
+ CURLOPT_RETURNTRANSFER => true,
+ ]);
$data = curl_exec($curl);
if (200 !== ($sc = curl_getinfo($curl, CURLINFO_HTTP_CODE))) {
if ('' != ($error = curl_error($curl))) {
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Config.php b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Config.php
index f46a6fb1..8a7340ee 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Config.php
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/Config.php
@@ -7,6 +7,7 @@ abstract class Config
protected $endpoint = null;
protected $username = null;
protected $password = null;
+ protected $defaultMethod = 'POST';
protected static $apiPath = null;
protected static $basePath = null;
@@ -19,11 +20,12 @@ abstract class Config
self::$configPath = self::$apiPath . 'config' . DIRECTORY_SEPARATOR;
}
- public function __construct(string $endpoint, string $username, string $password)
+ public function __construct(string $endpoint, string $username, string $password, string $defaultMethod)
{
$this->endpoint = $endpoint;
$this->username = $username;
$this->password = $password;
+ $this->defaultMethod = $defaultMethod;
}
public static function getConfigPath(string $configFile = ''): ?string
@@ -38,7 +40,7 @@ abstract class Config
public function setEndpoint(string $endpoint): void
{
- $this->endpoint = $endpoint;
+ $this->endpoint = rtrim($endpoint, '/') . '/';
}
public function getUsername(): ?string
@@ -61,5 +63,17 @@ abstract class Config
$this->password = $password;
}
+ public function getDefaultMethod(): string
+ {
+ return $this->defaultMethod;
+ }
+
+ public function setDefaultMethod(string $defaultMethod): void
+ {
+ if (in_array($defaultMethod, ['GET', 'POST'])) {
+ $this->defaultMethod = $defaultMethod;
+ }
+ }
+
abstract public function save();
}
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/FileConfig.php b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/FileConfig.php
index c4faf194..59d0c00c 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/FileConfig.php
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/FileConfig.php
@@ -10,7 +10,7 @@ class FileConfig extends Config
{
$this->fileName = $fileName;
$dati = json_decode(file_get_contents($this->getConfigPath($fileName)));
- parent::__construct($dati->endpoint, $dati->username, $dati->password);
+ parent::__construct($dati->endpoint, $dati->username, $dati->password, $dati->defaultMethod);
}
public function save()
@@ -19,6 +19,7 @@ class FileConfig extends Config
'endpoint' => $this->endpoint,
'username' => $this->username,
'password' => $this->password,
+ 'defaultMethod' => $this->defaultMethod,
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}
}
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/config/api.json b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/config/api.json
index 3db18616..cf5ee013 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/config/api.json
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/SueApi/v1/config/api.json
@@ -1,5 +1,6 @@
{
- "endpoint": "http://paesaggistica:8080/sicilia-sue-connector-portlet/api/v1",
+ "endpoint": "//{{ENDPOINT}}//",
"username": "",
- "password": ""
-}
\ No newline at end of file
+ "password": "",
+ "defaultMethod": "POST"
+}
diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/client.php b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/client.php
index ef98e5ea..88304c91 100644
--- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/client.php
+++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/resource/client/php/client.php
@@ -12,38 +12,31 @@ switch ($argv[1] ?? '') {
case 'set_login':
if ($argc < 4) {
echo ("Numero di argomenti insufficiente.\n\n");
- echo "Uso: php {$argv[0]} {$argv[2]} \n";
- echo "Salva le credenziali per l'accesso\n\n";
- echo "**username: Nome utente\n";
- echo "**password: Password\n\n";
- echo "** = parametro obbligatorio\n";
+ helpSetLogin($argv[0]);
die();
}
$api->setLogin($argv[2], $argv[3]);
echo "Impostazioni salvate\n";
break;
+ case 'set_method':
+ if ($argc < 3) {
+ echo ("Numero di argomenti insufficiente.\n\n");
+ helpSetMethod($argv[0]);
+ die();
+ }
+ $api->setMethod($argv[2]);
+ echo "Impostazioni salvate\n";
+ break;
case 'help':
switch ($argv[2] ?? '') {
case 'set_login':
- echo "Uso: php {$argv[0]} {$argv[2]} \n";
- echo "Salva le credenziali per l'accesso\n\n";
- echo "**username: Nome utente\n";
- echo "**password: Password\n\n";
- echo "** = parametro obbligatorio\n";
+ helpSetLogin($argv[0]);
break;
default:
- echo "set_login: Salva le credenziali per l'accesso\n";
- echo $api->getHelp($argv[2] ?? '');
- echo "\nDigitare help per maggiori informazioni sul comando.\n";
- echo "L'opzione --debug visualizza a schermo le comunicazioni con il server.\n";
- echo " Es.: php client.php nop --debug\n";
+ help($api, $argv[2]);
break;
}
break;
default:
- echo "set_login: Salva le credenziali per l'accesso\n";
- echo $api->getHelp();
- echo "\nDigitare help per maggiori informazioni sul comando.\n";
- echo "L'opzione --debug visualizza a schermo le comunicazioni con il server.\n";
- echo " Es.: php client.php nop --debug\n";
+ help($api);
}