|
|
@ -35,65 +35,127 @@ public class ManualHtml extends Manual { |
|
|
|
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
String cssFile = "/css/api/v1/api.css"; |
|
|
|
String cssFile = "/css/api/v1/api.css"; |
|
|
|
|
|
|
|
String bootstrapFile = "/css/bootstrap.css"; |
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
result.append("<!doctype html>").append("<meta charset=\"utf-8\">") |
|
|
|
result.append("<!doctype html>").append("<meta charset=\"utf-8\">") |
|
|
|
.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">") |
|
|
|
.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">") |
|
|
|
.append("<head><title>Manual</title>").append("<link rel=\"stylesheet\" href=\"") |
|
|
|
.append("<head><title>Manual</title>").append("<link rel=\"stylesheet\" href=\"") |
|
|
|
.append(request.getContextPath()).append(cssFile).append("?v=") |
|
|
|
.append(request.getContextPath()).append(cssFile).append("?v=") |
|
|
|
.append(new File(request.getServletContext().getRealPath(cssFile)).lastModified()).append("\">") |
|
|
|
.append(new File(request.getServletContext().getRealPath(cssFile)).lastModified()).append("\">") |
|
|
|
.append("</head><body>"); |
|
|
|
.append("<link rel=\"stylesheet\" href=\"").append(request.getContextPath()) |
|
|
|
|
|
|
|
.append(bootstrapFile).append("\">") |
|
|
|
|
|
|
|
.append("</head><body class=''>"); |
|
|
|
|
|
|
|
result.append("<div class='container'>"); |
|
|
|
|
|
|
|
result.append("<div class='row'>"); |
|
|
|
|
|
|
|
result.append("<div class='col-12 pt-4'>"); |
|
|
|
|
|
|
|
result.append("<h1>Sicilia SUE API v1</h1>"); |
|
|
|
|
|
|
|
result.append("</div>"); |
|
|
|
|
|
|
|
result.append("</div>"); |
|
|
|
for (Command command : CommandList.getList()) { |
|
|
|
for (Command command : CommandList.getList()) { |
|
|
|
result.append("<div class=\"command\">Comando: <b>/").append(command.getVerb()).append("</b>"); |
|
|
|
result.append("<div class='row'>"); |
|
|
|
if (command.isSecure()) { |
|
|
|
result.append("<div class='col-12 mb-5'>"); |
|
|
|
result.append(" [T]"); |
|
|
|
result.append("<h2 class='mb-3 mt-2'>/").append(command.getVerb()); |
|
|
|
|
|
|
|
if (command.isSecure()) |
|
|
|
|
|
|
|
result.append(" <small>[T]</small>"); |
|
|
|
|
|
|
|
result.append("</h2>"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.append("<p class='description text-secondary mb-3'>").append(command.getDescription()).append(".</p>"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.append("<div class='w-100 mb-2'>"); |
|
|
|
|
|
|
|
for(String cmd : command.getMethods() ){ |
|
|
|
|
|
|
|
result.append("<span class='badge badge-success mr-2 py-1 px-2' data-type='" + cmd.toLowerCase() + "'>"+cmd+"</span>"); |
|
|
|
} |
|
|
|
} |
|
|
|
result.append("<div class=\"description\">").append(command.getDescription()).append(".</div>"); |
|
|
|
result.append("</div>"); |
|
|
|
result.append("<div class=\"methods\">Metodi: ") |
|
|
|
|
|
|
|
.append(StringUtils.join(command.getMethods(), StringPool.COMMA_AND_SPACE)).append("</div>"); |
|
|
|
result.append("<div class='d-flex w-100 mb-3'><kbd class='container-fluid py-2'>"); |
|
|
|
result.append("<div class=\"parameters\">Parametri:"); |
|
|
|
result.append(getCurlExample(command, getBaseUrl(request))); |
|
|
|
|
|
|
|
result.append("</kbd></div>"); |
|
|
|
|
|
|
|
|
|
|
|
List<Parameter> parameters = command.getInputParameters(); |
|
|
|
List<Parameter> parameters = command.getInputParameters(); |
|
|
|
|
|
|
|
result.append("<div class='w-100 mb-3 mt-4'>"); |
|
|
|
|
|
|
|
result.append("<h4 class='w-100'>Parametri</h4>"); |
|
|
|
if (parameters.isEmpty()) { |
|
|
|
if (parameters.isEmpty()) { |
|
|
|
result.append(" Nessuno</div>"); |
|
|
|
result.append("<p>Nessuno</p>"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (Parameter parameter : parameters) { |
|
|
|
result.append("<table class='table table-sm table-bordered'>"); |
|
|
|
result.append("<div class=\"parameter\">").append(parameter.getName()); |
|
|
|
result.append("<thead class='thead-light font-weight-bold'>"); |
|
|
|
if (parameter.isRequired()) { |
|
|
|
result.append("<tr>"); |
|
|
|
result.append(StringPool.STAR); |
|
|
|
result.append("<th>Campo</th>"); |
|
|
|
} |
|
|
|
result.append("<th>Obbligatorio</th>"); |
|
|
|
result.append(" (").append(parameter.getType().toString()).append(") - ") |
|
|
|
result.append("<th>Tipo</th>"); |
|
|
|
.append(parameter.getDescription()).append("</div>"); |
|
|
|
result.append("<th>Descrizione</th>"); |
|
|
|
|
|
|
|
result.append("</tr>"); |
|
|
|
|
|
|
|
result.append("</thead>"); |
|
|
|
|
|
|
|
result.append("<tbody>"); |
|
|
|
|
|
|
|
result.append(printTableParameters(parameters, 1)); |
|
|
|
|
|
|
|
result.append("</tbody>"); |
|
|
|
|
|
|
|
result.append("</table>"); |
|
|
|
} |
|
|
|
} |
|
|
|
result.append("</div>"); |
|
|
|
result.append("</div>"); |
|
|
|
} |
|
|
|
|
|
|
|
parameters = command.getOutputParameters(); |
|
|
|
parameters = command.getOutputParameters(); |
|
|
|
if (!parameters.isEmpty()) { |
|
|
|
result.append("<div class='w-100 mb-3 mt-4'>"); |
|
|
|
result.append("<div class=\"returns\">Restituisce:"); |
|
|
|
result.append("<h4 clsas='w-100'>Risposta</h4>"); |
|
|
|
for (Parameter parameter : parameters) { |
|
|
|
if (parameters.isEmpty()) { |
|
|
|
result.append("<div class=\"parameter\">").append(parameter.getName()).append(" (") |
|
|
|
result.append("<p>Nessuno</p>"); |
|
|
|
.append(parameter.getType().toString()).append(") - ").append(parameter.getDescription()); |
|
|
|
} else { |
|
|
|
if (parameter.getType().equals(TYPES.ARRAY)) { |
|
|
|
result.append("<table class='table table-sm table-bordered'>"); |
|
|
|
for (Parameter subParameter : parameter.getSubParameters()) { |
|
|
|
result.append("<thead class='thead-light font-weight-bold'>"); |
|
|
|
result.append("<div class=\"parameter\">").append(subParameter.getName()).append(" (") |
|
|
|
result.append("<tr>"); |
|
|
|
.append(subParameter.getType().toString()).append(") - ") |
|
|
|
result.append("<th>Campo</th>"); |
|
|
|
.append(subParameter.getDescription()).append("</div>"); |
|
|
|
result.append("<th>Obbligatorio</th>"); |
|
|
|
} |
|
|
|
result.append("<th>Tipo</th>"); |
|
|
|
|
|
|
|
result.append("<th>Descrizione</th>"); |
|
|
|
|
|
|
|
result.append("</tr>"); |
|
|
|
|
|
|
|
result.append("</thead>"); |
|
|
|
|
|
|
|
result.append("<tbody>"); |
|
|
|
|
|
|
|
result.append(printTableParameters(parameters, 1)); |
|
|
|
|
|
|
|
result.append("</tbody>"); |
|
|
|
|
|
|
|
result.append("</table>"); |
|
|
|
} |
|
|
|
} |
|
|
|
result.append("</div>"); |
|
|
|
result.append("</div>"); |
|
|
|
} |
|
|
|
result.append("</div>"); |
|
|
|
result.append("</div>"); |
|
|
|
result.append("</div>"); |
|
|
|
} |
|
|
|
} |
|
|
|
result.append("<div class=\"example\">Esempio:<pre>").append(getCurlExample(command, getBaseUrl(request))) |
|
|
|
result.append("<div class='row'>"); |
|
|
|
.append("</pre></div>"); |
|
|
|
result.append("<div class='col-12 pt-4'>"); |
|
|
|
result.append("</div>"); // class="command"
|
|
|
|
result.append("<p>"); |
|
|
|
} |
|
|
|
result.append("<b>Note</b><br>[T] = Richiede token di autenticazione: header di richiesta \""); |
|
|
|
result.append("<div class=\"notes\">Note:<br>[T] = Richiede token di autenticazione: header di richiesta \"") |
|
|
|
result.append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro \"").append(Parameters.TOKEN); |
|
|
|
.append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro \"").append(Parameters.TOKEN) |
|
|
|
result.append("\"</p>"); |
|
|
|
.append("\"<br>* = Parametro obbligatorio</div>"); |
|
|
|
result.append("</div>"); |
|
|
|
|
|
|
|
result.append("</div>"); |
|
|
|
|
|
|
|
result.append("</div>"); |
|
|
|
result.append("</body></html>"); |
|
|
|
result.append("</body></html>"); |
|
|
|
setTextHtml(response); |
|
|
|
setTextHtml(response); |
|
|
|
ServletResponseUtil.write(response, result.toString()); |
|
|
|
ServletResponseUtil.write(response, result.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String printTableParameters(List<Parameter> parameters, int level){ |
|
|
|
|
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Parameter parameter : parameters) { |
|
|
|
|
|
|
|
result.append("<tr>"); |
|
|
|
|
|
|
|
result.append("<td style='padding-left:" + (0.75 * level) + "rem'>" + parameter.getName() + "</td>"); |
|
|
|
|
|
|
|
result.append("<td>"); |
|
|
|
|
|
|
|
if (parameter.isRequired()) |
|
|
|
|
|
|
|
result.append("Sì"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
result.append("No"); |
|
|
|
|
|
|
|
result.append("</td>"); |
|
|
|
|
|
|
|
result.append("<td>" + parameter.getType().toString() + "</td>"); |
|
|
|
|
|
|
|
result.append("<td>" + parameter.getDescription() + "</td>"); |
|
|
|
|
|
|
|
result.append("</tr>"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parameter.getType().equals(TYPES.ARRAY)) { |
|
|
|
|
|
|
|
printTableParameters(parameter.getSubParameters(), level++); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result.toString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<Parameter> getOutputParameters() { |
|
|
|
public List<Parameter> getOutputParameters() { |
|
|
|
return OUTPUT_PARAMETERS; |
|
|
|
return OUTPUT_PARAMETERS; |
|
|
|