diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java index 06c9e9d5..d7e8e59b 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java @@ -96,11 +96,14 @@ public abstract class Command { response.setCharacterEncoding(StringPool.UTF8); } - protected void setPlainText(HttpServletResponse response) { - + protected void setTextPlain(HttpServletResponse response) { response.setContentType(ContentTypes.TEXT_PLAIN_UTF8); } + protected void setTextHtml(HttpServletResponse response) { + response.setContentType(ContentTypes.TEXT_HTML_UTF8); + } + protected boolean verifyAccessToken(HttpServletRequest request, HttpServletResponse response) throws IOException { setJson(response); diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/CommandList.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/CommandList.java index 6e819873..ebb58d62 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/CommandList.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/CommandList.java @@ -4,6 +4,7 @@ import it.mwg.sicilia.sue.api.v1.command.impl.Applications; import it.mwg.sicilia.sue.api.v1.command.impl.Documents; import it.mwg.sicilia.sue.api.v1.command.impl.Login; import it.mwg.sicilia.sue.api.v1.command.impl.Manual; +import it.mwg.sicilia.sue.api.v1.command.impl.ManualHtml; import it.mwg.sicilia.sue.api.v1.command.impl.Nop; import java.util.Collection; @@ -19,6 +20,9 @@ public class CommandList { static { addCommand(new Manual("manual", "Restituisce la documentazione dell'API generata automaticamente", HttpMethods.GET, HttpMethods.POST)); + addCommand(new ManualHtml("manual_html", + "Restituisce la documentazione dell'API generata automaticamente in versione HTML", HttpMethods.GET, + HttpMethods.POST)); addCommand(new Login("login", "Esegue l'accesso con nome email e password e restituisce un token di accesso")); addCommand(new Applications("applications", "Riceve l'elenco delle istanze valide contenenti codice e descrizione", HttpMethods.GET, 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/Applications.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Applications.java index 41f78de7..3c1adb17 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Applications.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Applications.java @@ -23,6 +23,14 @@ import com.liferay.portal.kernel.util.StringPool; public class Applications extends Command { + private static final List OUTPUT_PARAMETERS = new ArrayList(); + static { + Parameter p = new Parameter(Parameters.DOCUMENTS, Parameter.TYPES.ARRAY, "elenco di istanze presentabili"); + p.addSubParameter(new Parameter(Parameters.CODE, Parameter.TYPES.STRING, "codice dell'istanza")); + p.addSubParameter(new Parameter(Parameters.DESCRIPTION, Parameter.TYPES.STRING, "descrizione dell'istanza")); + OUTPUT_PARAMETERS.add(p); + }; + public Applications(String verb, String description, String... methods) { super(verb, description, methods); @@ -51,6 +59,6 @@ public class Applications extends Command { @Override public List getOutputParameters() { - return EMPTY_PARAMETERS; + 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/command/impl/Documents.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Documents.java index 039868b7..801998d8 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Documents.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Documents.java @@ -23,6 +23,14 @@ import com.liferay.portal.kernel.util.StringPool; public class Documents extends Command { + private static final List OUTPUT_PARAMETERS = new ArrayList(); + static { + Parameter p = new Parameter(Parameters.DOCUMENTS, Parameter.TYPES.ARRAY, "elenco di documenti"); + p.addSubParameter(new Parameter(Parameters.CODE, Parameter.TYPES.STRING, "codice del documento")); + p.addSubParameter(new Parameter(Parameters.DESCRIPTION, Parameter.TYPES.STRING, "descrizione del documento")); + OUTPUT_PARAMETERS.add(p); + }; + public Documents(String verb, String description, String... methods) { super(verb, description, methods); } @@ -50,6 +58,6 @@ public class Documents extends Command { @Override public List getOutputParameters() { - return EMPTY_PARAMETERS; + 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/command/impl/Manual.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Manual.java index ef04cad7..93053927 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Manual.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Manual.java @@ -6,6 +6,7 @@ import it.mwg.sicilia.sue.api.v1.command.CommandList; import it.mwg.sicilia.sue.api.v1.parameter.Parameter; import java.io.Serializable; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -25,6 +26,13 @@ import com.liferay.portal.kernel.util.StringPool; public class Manual extends Command { + @SuppressWarnings("serial") + private static final List OUTPUT_PARAMETERS = new ArrayList() { + { + add(new Parameter(StringPool.BLANK, Parameter.TYPES.TEXT_PLAIN, "Il testo del manuale (questa pagina)")); + } + }; + private static String baseUrl = null; private static final JSONSerializer serializer = JSONFactoryUtil.createJSONSerializer(); @@ -70,6 +78,13 @@ public class Manual extends Command { result.append(StringPool.TAB).append(parameter.getName()).append(" (") .append(parameter.getType().toString()).append(") - ").append(parameter.getDescription()) .append(StringPool.NEW_LINE); + if (parameter.getType().equals(Parameter.TYPES.ARRAY)) { + for (Parameter subParameter : parameter.getSubParameters()) { + result.append(StringPool.TAB).append(StringPool.TAB).append(subParameter.getName()) + .append(" (").append(subParameter.getType().toString()).append(") - ") + .append(subParameter.getDescription()).append(StringPool.NEW_LINE); + } + } } } result.append("Esempio:\n").append(getCurlExample(command, getBaseUrl(request))); @@ -77,10 +92,10 @@ public class Manual extends Command { result.append("================================================================================\n"); } } - result.append("\n[Note]\n[T] = Richiede token di autenticazione: header di richiesta \"") + result.append("\nNote:\n[T] = Richiede token di autenticazione: header di richiesta \"") .append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro \"").append(Parameters.TOKEN) .append("\"\n * = Parametro obbligatorio\n"); - setPlainText(response); + setTextPlain(response); ServletResponseUtil.write(response, result.toString()); } @@ -140,6 +155,6 @@ public class Manual extends Command { @Override public List getOutputParameters() { - return EMPTY_PARAMETERS; + 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/command/impl/ManualHtml.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ManualHtml.java new file mode 100644 index 00000000..84909437 --- /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/ManualHtml.java @@ -0,0 +1,165 @@ +package it.mwg.sicilia.sue.api.v1.command.impl; + +import it.mwg.sicilia.sue.api.v1.Parameters; +import it.mwg.sicilia.sue.api.v1.command.Command; +import it.mwg.sicilia.sue.api.v1.command.CommandList; +import it.mwg.sicilia.sue.api.v1.parameter.Parameter; + +import java.io.File; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; + +import com.liferay.portal.kernel.json.JSONFactoryUtil; +import com.liferay.portal.kernel.json.JSONSerializer; +import com.liferay.portal.kernel.servlet.HttpMethods; +import com.liferay.portal.kernel.servlet.ServletResponseUtil; +import com.liferay.portal.kernel.util.Http; +import com.liferay.portal.kernel.util.StringPool; + +public class ManualHtml extends Command { + + @SuppressWarnings("serial") + private static final List OUTPUT_PARAMETERS = new ArrayList() { + { + add(new Parameter(StringPool.BLANK, Parameter.TYPES.TEXT_HTML, "Il testo del manuale (questa pagina)")); + } + }; + + private static String baseUrl = null; + + private static final JSONSerializer serializer = JSONFactoryUtil.createJSONSerializer(); + + public ManualHtml(String verb, String description, String... methods) { + super(verb, description, methods); + } + + @Override + public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { + + String cssFile = "/css/api/v1/api.css"; + StringBuilder result = new StringBuilder(); + result.append("").append("") + .append("") + .append("Manual").append("") + .append(""); + for (Command command : CommandList.getList()) { + result.append("
Comando: /").append(command.getVerb()).append(""); + if (command.isSecure()) { + result.append(" [T]"); + } + result.append("
").append(command.getDescription()).append("
"); + result.append("
Metodi: ") + .append(StringUtils.join(command.getMethods(), StringPool.COMMA_AND_SPACE)).append("
"); + result.append("
Parametri:"); + List parameters = command.getInputParameters(); + if (parameters.isEmpty()) { + result.append(" Nessuno
"); + } else { + for (Parameter parameter : parameters) { + result.append("
").append(parameter.getName()); + if (parameter.isRequired()) { + result.append(StringPool.STAR); + } + result.append(" (").append(parameter.getType().toString()).append(") - ") + .append(parameter.getDescription()).append("
"); + } + result.append("
"); + } + parameters = command.getOutputParameters(); + if (!parameters.isEmpty()) { + result.append("
Restituisce:"); + for (Parameter parameter : parameters) { + result.append("
").append(parameter.getName()).append(" (") + .append(parameter.getType().toString()).append(") - ").append(parameter.getDescription()); + if (parameter.getType().equals(Parameter.TYPES.ARRAY)) { + for (Parameter subParameter : parameter.getSubParameters()) { + result.append("
").append(subParameter.getName()).append(" (") + .append(subParameter.getType().toString()).append(") - ") + .append(subParameter.getDescription()).append("
"); + } + } + result.append("
"); + } + } + result.append("
"); + result.append("
Esempio:
").append(getCurlExample(command, getBaseUrl(request)))
+					.append("
"); + result.append(""); // class="command" + } + result.append("
Note:
[T] = Richiede token di autenticazione: header di richiesta \"") + .append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro \"").append(Parameters.TOKEN) + .append("\"
* = Parametro obbligatorio
"); + result.append(""); + setTextHtml(response); + ServletResponseUtil.write(response, result.toString()); + } + + private String getCurlExample(Command command, String baseUrl) { + + StringBuilder sb = new StringBuilder(); + sb.append("curl "); + if (command.isSecure()) { + sb.append("--header \"").append(Parameters.X_AUTH_TOKEN).append(": $TOKEN\"").append(" \\\n\t"); + } + if (command.getMethods().contains(HttpMethods.GET)) { + } else { + sb.append("--header \"Content-Type: application/json; charset=UTF-8\" \\\n\t"); + sb.append("--request POST \\\n\t"); + Map data = new LinkedHashMap<>(); + for (Parameter parameter : command.getInputParameters()) { + if (parameter.isRequired()) { + if (parameter.getType().equals(Parameter.TYPES.STRING)) { + data.put(parameter.getName(), parameter.getName()); + } + } + } + if (data.size() > 0) { + sb.append("--data '").append(serializer.serialize(data)).append("' \\\n\t"); + } + } + sb.append(StringPool.APOSTROPHE).append(baseUrl).append(command.getVerb()).append(StringPool.APOSTROPHE) + .append(StringPool.NEW_LINE); + return sb.toString(); + } + + private String getBaseUrl(HttpServletRequest request) { + + if (null == baseUrl) { + 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); + baseUrl = sb.toString(); + } + return baseUrl; + } + + @Override + public boolean isSecure() { + return false; + } + + @Override + public List getInputParameters() { + return EMPTY_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/parameter/Parameter.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/parameter/Parameter.java index 3c85c421..8c88fd1f 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/parameter/Parameter.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/parameter/Parameter.java @@ -1,11 +1,15 @@ package it.mwg.sicilia.sue.api.v1.parameter; +import java.util.ArrayList; +import java.util.List; + public class Parameter { private String name; private TYPES type; private String description; private boolean required; + private List subParameters = null; public Parameter(String name, TYPES type, String description, boolean required) { @@ -39,7 +43,19 @@ public class Parameter { return required; } + public void addSubParameter(Parameter parameter) { + + if (null == subParameters) { + subParameters = new ArrayList<>(); + } + subParameters.add(parameter); + } + + public List getSubParameters() { + return subParameters; + } + public static enum TYPES { - ARRAY, BOOLEAN, STRING + ARRAY, BOOLEAN, STRING, TEXT_HTML, TEXT_PLAIN } } diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/css/api/v1/api.css b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/css/api/v1/api.css new file mode 100644 index 00000000..52a7226e --- /dev/null +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/css/api/v1/api.css @@ -0,0 +1,70 @@ +/* http://meyerweb.com/eric/tools/css/reset/ + v2.0 | 20110126 + License: none (public domain) */ +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; +} +/* End reset.css */ +body { + margin: 10px; + font-family: sans-serif; +} +div { + margin-bottom: 5px; +} +b { + font-weight: bold; +} +pre { + background-color: #ccc; + width: fit-content; + padding: 10px; + border: 1px solid #999; +} +.command { + border-bottom: 1px solid #999; + padding: 10px 0; +} +.parameter { + margin-left: 40px; +} diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/html/administration/edit_sportello.jsp b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/html/administration/edit_sportello.jsp index 49d0d3b9..bb7bf10a 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/html/administration/edit_sportello.jsp +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/html/administration/edit_sportello.jsp @@ -23,7 +23,7 @@ Sportello sportello = sportelloId == 0 ? null : SportelloLocalServiceUtil.getSpo + value="<%= Validator.isNull(sportello) ? StringPool.BLANK : sportello.getUserName() %>">