Salvatore La Manna 3 anni fa
parent
commit
dcfcd829f6
  1. 7
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/Command.java
  2. 4
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/CommandList.java
  3. 10
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Applications.java
  4. 10
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Documents.java
  5. 21
      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. 165
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/ManualHtml.java
  7. 18
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/parameter/Parameter.java
  8. 70
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/css/api/v1/api.css
  9. 2
      liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/html/administration/edit_sportello.jsp

7
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);

4
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,

10
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<Parameter> OUTPUT_PARAMETERS = new ArrayList<Parameter>();
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<Parameter> getOutputParameters() {
return EMPTY_PARAMETERS;
return OUTPUT_PARAMETERS;
}
}

10
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<Parameter> OUTPUT_PARAMETERS = new ArrayList<Parameter>();
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<Parameter> getOutputParameters() {
return EMPTY_PARAMETERS;
return OUTPUT_PARAMETERS;
}
}

21
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<Parameter> OUTPUT_PARAMETERS = new ArrayList<Parameter>() {
{
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<Parameter> getOutputParameters() {
return EMPTY_PARAMETERS;
return OUTPUT_PARAMETERS;
}
}

165
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<Parameter> OUTPUT_PARAMETERS = new ArrayList<Parameter>() {
{
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("<!doctype html>").append("<meta charset=\"utf-8\">")
.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">")
.append("<head><title>Manual</title>").append("<link rel=\"stylesheet\" href=\"")
.append(request.getContextPath()).append(cssFile).append("?v=")
.append(new File(request.getServletContext().getRealPath(cssFile)).lastModified()).append("\">")
.append("</head><body>");
for (Command command : CommandList.getList()) {
result.append("<div class=\"command\">Comando: <b>/").append(command.getVerb()).append("</b>");
if (command.isSecure()) {
result.append(" [T]");
}
result.append("<div class=\"description\">").append(command.getDescription()).append("</div>");
result.append("<div class=\"methods\">Metodi: ")
.append(StringUtils.join(command.getMethods(), StringPool.COMMA_AND_SPACE)).append("</div>");
result.append("<div class=\"parameters\">Parametri:");
List<Parameter> parameters = command.getInputParameters();
if (parameters.isEmpty()) {
result.append(" Nessuno</div>");
} else {
for (Parameter parameter : parameters) {
result.append("<div class=\"parameter\">").append(parameter.getName());
if (parameter.isRequired()) {
result.append(StringPool.STAR);
}
result.append(" (").append(parameter.getType().toString()).append(") - ")
.append(parameter.getDescription()).append("</div>");
}
result.append("</div>");
}
parameters = command.getOutputParameters();
if (!parameters.isEmpty()) {
result.append("<div class=\"returns\">Restituisce:");
for (Parameter parameter : parameters) {
result.append("<div class=\"parameter\">").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("<div class=\"parameter\">").append(subParameter.getName()).append(" (")
.append(subParameter.getType().toString()).append(") - ")
.append(subParameter.getDescription()).append("</div>");
}
}
result.append("</div>");
}
}
result.append("</div>");
result.append("<div class=\"example\">Esempio:<pre>").append(getCurlExample(command, getBaseUrl(request)))
.append("</pre></div>");
result.append("</div>"); // class="command"
}
result.append("<div class=\"notes\">Note:<br>[T] = Richiede token di autenticazione: header di richiesta \"")
.append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro \"").append(Parameters.TOKEN)
.append("\"<br>* = Parametro obbligatorio</div>");
result.append("</body></html>");
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<String, Serializable> 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<Parameter> getInputParameters() {
return EMPTY_PARAMETERS;
}
@Override
public List<Parameter> getOutputParameters() {
return OUTPUT_PARAMETERS;
}
}

18
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<Parameter> 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<Parameter> getSubParameters() {
return subParameters;
}
public static enum TYPES {
ARRAY, BOOLEAN, STRING
ARRAY, BOOLEAN, STRING, TEXT_HTML, TEXT_PLAIN
}
}

70
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;
}

2
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
</aui:col>
<aui:col width="70">
<aui:input name="userName" id="userName" cssClass="span10"
value="<%= Validator.isNull(sportello) ? sportello.getNomeComune() : sportello.getUserName() %>">
value="<%= Validator.isNull(sportello) ? StringPool.BLANK : sportello.getUserName() %>">
<aui:validator name="required" />
</aui:input>
<aui:input name="email" id="email" label="email" cssClass="span10"

Caricamento…
Annulla
Salva