|
|
|
@ -35,65 +35,127 @@ public class ManualHtml extends Manual {
|
|
|
|
|
public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
|
|
|
|
|
|
String cssFile = "/css/api/v1/api.css"; |
|
|
|
|
String bootstrapFile = "/css/bootstrap.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>"); |
|
|
|
|
} |
|
|
|
|
.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>"); |
|
|
|
|
} |
|
|
|
|
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(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>"); |
|
|
|
|
for (Command command : CommandList.getList()) { |
|
|
|
|
result.append("<div class='row'>"); |
|
|
|
|
result.append("<div class='col-12 mb-5'>"); |
|
|
|
|
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>"); |
|
|
|
|
|
|
|
|
|
result.append("<div class='d-flex w-100 mb-3'><kbd class='container-fluid py-2'>"); |
|
|
|
|
result.append(getCurlExample(command, getBaseUrl(request))); |
|
|
|
|
result.append("</kbd></div>"); |
|
|
|
|
|
|
|
|
|
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()) { |
|
|
|
|
result.append("<p>Nessuno</p>"); |
|
|
|
|
} else { |
|
|
|
|
result.append("<table class='table table-sm table-bordered'>"); |
|
|
|
|
result.append("<thead class='thead-light font-weight-bold'>"); |
|
|
|
|
result.append("<tr>"); |
|
|
|
|
result.append("<th>Campo</th>"); |
|
|
|
|
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>"); |
|
|
|
|
|
|
|
|
|
parameters = command.getOutputParameters(); |
|
|
|
|
result.append("<div class='w-100 mb-3 mt-4'>"); |
|
|
|
|
result.append("<h4 clsas='w-100'>Risposta</h4>"); |
|
|
|
|
if (parameters.isEmpty()) { |
|
|
|
|
result.append("<p>Nessuno</p>"); |
|
|
|
|
} else { |
|
|
|
|
result.append("<table class='table table-sm table-bordered'>"); |
|
|
|
|
result.append("<thead class='thead-light font-weight-bold'>"); |
|
|
|
|
result.append("<tr>"); |
|
|
|
|
result.append("<th>Campo</th>"); |
|
|
|
|
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 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("<div class='row'>"); |
|
|
|
|
result.append("<div class='col-12 pt-4'>"); |
|
|
|
|
result.append("<p>"); |
|
|
|
|
result.append("<b>Note</b><br>[T] = Richiede token di autenticazione: header di richiesta \""); |
|
|
|
|
result.append(Parameters.X_AUTH_TOKEN).append("\" oppure parametro \"").append(Parameters.TOKEN); |
|
|
|
|
result.append("\"</p>"); |
|
|
|
|
result.append("</div>"); |
|
|
|
|
result.append("</div>"); |
|
|
|
|
result.append("</div>"); |
|
|
|
|
result.append("</body></html>"); |
|
|
|
|
setTextHtml(response); |
|
|
|
|
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 |
|
|
|
|
public List<Parameter> getOutputParameters() { |
|
|
|
|
return OUTPUT_PARAMETERS; |
|
|
|
|