diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-codec.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-codec.jar new file mode 100644 index 00000000..1d7417c4 Binary files /dev/null and b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-codec.jar differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-collections4.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-collections4.jar new file mode 100644 index 00000000..43a9413b Binary files /dev/null and b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-collections4.jar differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-logging.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-logging.jar similarity index 100% rename from liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-logging.jar rename to liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/commons-logging.jar diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/log4j.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/log4j.jar similarity index 100% rename from liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/log4j.jar rename to liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/log4j.jar diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/poi.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/poi.jar new file mode 100644 index 00000000..353ce765 Binary files /dev/null and b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/poi.jar differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-asm.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-asm.jar new file mode 100644 index 00000000..f0a1261a Binary files /dev/null and b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-asm.jar differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-beans.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-beans.jar new file mode 100644 index 00000000..5639dd47 Binary files /dev/null and b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-beans.jar differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-context.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-context.jar new file mode 100644 index 00000000..6b23efa8 Binary files /dev/null and b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-context.jar differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-core.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-core.jar new file mode 100644 index 00000000..b8e928c2 Binary files /dev/null and b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/spring-core.jar differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/util-bridges.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/util-bridges.jar similarity index 100% rename from liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/util-bridges.jar rename to liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/util-bridges.jar diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/util-taglib.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/util-taglib.jar similarity index 100% rename from liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/util-taglib.jar rename to liferay-plugins-sdk-6.2/portlets/portos-report-engine-portlet/docroot/WEB-INF/lib/util-taglib.jar diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-collections.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-collections.jar deleted file mode 100644 index fa5df82a..00000000 Binary files a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-collections.jar and /dev/null differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-io.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-io.jar deleted file mode 100644 index 00556b11..00000000 Binary files a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-io.jar and /dev/null differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-lang.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-lang.jar deleted file mode 100644 index 98467d3a..00000000 Binary files a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/commons-lang.jar and /dev/null differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/javassist.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/javassist.jar deleted file mode 100644 index 5af8eaeb..00000000 Binary files a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/javassist.jar and /dev/null differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-api.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-api.jar deleted file mode 100644 index 80a5737f..00000000 Binary files a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-api.jar and /dev/null differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-impl.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-impl.jar deleted file mode 100644 index e5a9342f..00000000 Binary files a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/jstl-impl.jar and /dev/null differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/velocity.jar b/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/velocity.jar deleted file mode 100644 index e7151c5c..00000000 Binary files a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/lib/velocity.jar and /dev/null differ diff --git a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/tld/c.tld b/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/tld/c.tld deleted file mode 100644 index 98efa6a6..00000000 --- a/liferay-plugins-sdk-6.2/portlets/portos-report-portlet/docroot/WEB-INF/tld/c.tld +++ /dev/null @@ -1,572 +0,0 @@ - - - - - JSTL 1.2 core library - JSTL core - 1.2 - c - http://java.sun.com/jsp/jstl/core - - - - Provides core validation features for JSTL tags. - - - org.apache.taglibs.standard.tlv.JstlCoreTLV - - - - - - Catches any Throwable that occurs in its body and optionally - exposes it. - - catch - org.apache.taglibs.standard.tag.common.core.CatchTag - JSP - - -Name of the exported scoped variable for the -exception thrown from a nested action. The type of the -scoped variable is the type of the exception thrown. - - var - false - false - - - - - - Simple conditional tag that establishes a context for - mutually exclusive conditional operations, marked by - <when> and <otherwise> - - choose - com.liferay.taglib.core.ChooseTag - JSP - - - - - Simple conditional tag, which evalutes its body if the - supplied condition is true and optionally exposes a Boolean - scripting variable representing the evaluation of this condition - - if - com.liferay.taglib.core.IfTag - JSP - - -The test condition that determines whether or -not the body content should be processed. - - test - true - true - boolean - - - -Name of the exported scoped variable for the -resulting value of the test condition. The type -of the scoped variable is Boolean. - - var - false - false - - - -Scope for var. - - scope - false - false - - - - - - Retrieves an absolute or relative URL and exposes its contents - to either the page, a String in 'var', or a Reader in 'varReader'. - - import - org.apache.taglibs.standard.tag.rt.core.ImportTag - org.apache.taglibs.standard.tei.ImportTEI - JSP - - -The URL of the resource to import. - - url - true - true - - - -Name of the exported scoped variable for the -resource's content. The type of the scoped -variable is String. - - var - false - false - - - -Scope for var. - - scope - false - false - - - -Name of the exported scoped variable for the -resource's content. The type of the scoped -variable is Reader. - - varReader - false - false - - - -Name of the context when accessing a relative -URL resource that belongs to a foreign -context. - - context - false - true - - - -Character encoding of the content at the input -resource. - - charEncoding - false - true - - - - - - The basic iteration tag, accepting many different - collection types and supporting subsetting and other - functionality - - forEach - org.apache.taglibs.standard.tag.rt.core.ForEachTag - org.apache.taglibs.standard.tei.ForEachTEI - JSP - - -Collection of items to iterate over. - - items - false - true - java.lang.Object - - java.lang.Object - - - - -If items specified: -Iteration begins at the item located at the -specified index. First item of the collection has -index 0. -If items not specified: -Iteration begins with index set at the value -specified. - - begin - false - true - int - - - -If items specified: -Iteration ends at the item located at the -specified index (inclusive). -If items not specified: -Iteration ends when index reaches the value -specified. - - end - false - true - int - - - -Iteration will only process every step items of -the collection, starting with the first one. - - step - false - true - int - - - -Name of the exported scoped variable for the -current item of the iteration. This scoped -variable has nested visibility. Its type depends -on the object of the underlying collection. - - var - false - false - - - -Name of the exported scoped variable for the -status of the iteration. Object exported is of type -javax.servlet.jsp.jstl.core.LoopTagStatus. This scoped variable has nested -visibility. - - varStatus - false - false - - - - - - Iterates over tokens, separated by the supplied delimeters - - forTokens - org.apache.taglibs.standard.tag.rt.core.ForTokensTag - JSP - - -String of tokens to iterate over. - - items - true - true - java.lang.String - - java.lang.String - - - - -The set of delimiters (the characters that -separate the tokens in the string). - - delims - true - true - java.lang.String - - - -Iteration begins at the token located at the -specified index. First token has index 0. - - begin - false - true - int - - - -Iteration ends at the token located at the -specified index (inclusive). - - end - false - true - int - - - -Iteration will only process every step tokens -of the string, starting with the first one. - - step - false - true - int - - - -Name of the exported scoped variable for the -current item of the iteration. This scoped -variable has nested visibility. - - var - false - false - - - -Name of the exported scoped variable for the -status of the iteration. Object exported is of -type -javax.servlet.jsp.jstl.core.LoopTag -Status. This scoped variable has nested -visibility. - - varStatus - false - false - - - - - - Like <%= ... >, but for expressions. - - out - org.apache.taglibs.standard.tag.rt.core.OutTag - JSP - - -Expression to be evaluated. - - value - true - true - - - -Default value if the resulting value is null. - - default - false - true - - - -Determines whether characters <,>,&,'," in the -resulting string should be converted to their -corresponding character entity codes. Default value is -true. - - escapeXml - false - true - - - - - - - Subtag of <choose> that follows <when> tags - and runs only if all of the prior conditions evaluated to - 'false' - - otherwise - com.liferay.taglib.core.OtherwiseTag - JSP - - - - - Adds a parameter to a containing 'import' tag's URL. - - param - org.apache.taglibs.standard.tag.rt.core.ParamTag - JSP - - -Name of the query string parameter. - - name - true - true - - - -Value of the parameter. - - value - false - true - - - - - - Redirects to a new URL. - - redirect - org.apache.taglibs.standard.tag.rt.core.RedirectTag - JSP - - -The URL of the resource to redirect to. - - url - false - true - - - -Name of the context when redirecting to a relative URL -resource that belongs to a foreign context. - - context - false - true - - - - - - Removes a scoped variable (from a particular scope, if specified). - - remove - org.apache.taglibs.standard.tag.common.core.RemoveTag - empty - - -Name of the scoped variable to be removed. - - var - true - false - - - -Scope for var. - - scope - false - false - - - - - - Sets the result of an expression evaluation in a 'scope' - - set - org.apache.taglibs.standard.tag.rt.core.SetTag - JSP - - -Name of the exported scoped variable to hold the value -specified in the action. The type of the scoped variable is -whatever type the value expression evaluates to. - - var - false - false - - - -Expression to be evaluated. - - value - false - true - - java.lang.Object - - - - -Target object whose property will be set. Must evaluate to -a JavaBeans object with setter property property, or to a -java.util.Map object. - - target - false - true - - - -Name of the property to be set in the target object. - - property - false - true - - - -Scope for var. - - scope - false - false - - - - - - Creates a URL with optional query parameters. - - url - org.apache.taglibs.standard.tag.rt.core.UrlTag - JSP - - -Name of the exported scoped variable for the -processed url. The type of the scoped variable is -String. - - var - false - false - - - -Scope for var. - - scope - false - false - - - -URL to be processed. - - value - false - true - - - -Name of the context when specifying a relative URL -resource that belongs to a foreign context. - - context - false - true - - - - - - Subtag of <choose> that includes its body if its - condition evalutes to 'true' - - when - com.liferay.taglib.core.WhenTag - JSP - - -The test condition that determines whether or not the -body content should be processed. - - test - true - true - boolean - - - - diff --git a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/AccessToken.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/AccessToken.java index e7b357b8..93a28a17 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/AccessToken.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/AccessToken.java @@ -52,11 +52,10 @@ public class AccessToken { token = Base64.encode(cipher.doFinal(payload.toString().getBytes()), 0); } - public AccessToken(String token) throws Exception { + public AccessToken(long companyId, String token) throws Exception { KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - // TODO companyId - String key = ApiSettingLocalServiceUtil.get(20155, ApiConstants.API_PUBLIC_KEY); + String key = ApiSettingLocalServiceUtil.get(companyId, ApiConstants.API_PUBLIC_KEY); X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(Base64.decode(key)); PublicKey publicKey = keyFactory.generatePublic(pubKeySpec); Cipher cipher = Cipher.getInstance("RSA"); 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 59ea660a..dfc50fb2 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 @@ -15,10 +15,11 @@ import it.tref.liferay.portos.bo.service.IntPraticaLocalServiceUtil; import it.tref.liferay.portos.bo.service.TerritorioLocalServiceUtil; import java.io.IOException; -import java.io.InputStreamReader; import java.io.Serializable; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; +import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,6 +27,8 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.io.IOUtils; + import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.json.JSONDeserializer; @@ -35,7 +38,10 @@ import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.servlet.HttpMethods; import com.liferay.portal.kernel.util.ContentTypes; import com.liferay.portal.kernel.util.MapUtil; +import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.Validator; +import com.liferay.portal.model.Company; +import com.liferay.portal.util.PortalUtil; public abstract class Command { @@ -52,19 +58,21 @@ public abstract class Command { protected Map parameters = null; protected Sportello sportello = null; - private String verb; - private List methods; - private String description; + private final String verb; + private final List methods; + private final String description; private AccessToken accessToken; + private long companyId = 0L; - private static final String[] defaultMethods = { HttpMethods.POST }; + private static final List DEFAULT_METHODS = Arrays.asList(HttpMethods.GET, HttpMethods.POST); private static final JSONDeserializer> deserializer = JSONFactoryUtil .createJSONDeserializer(); + private static final List BLACKLIST = Arrays.asList("password", "token", "username"); public Command(String description, String... methods) { this.verb = getCommandVerb(); - this.methods = Arrays.asList(methods.length > 0 ? methods : defaultMethods); + this.methods = methods.length > 0 ? Arrays.asList(methods) : DEFAULT_METHODS; this.description = description; } @@ -93,10 +101,22 @@ public abstract class Command { protected Map readParameters(HttpServletRequest request) throws IOException { parameters = new HashMap<>(); + String input = StringPool.BLANK; if (request.getMethod().equals(HttpMethods.POST)) { + input = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8); + } + Enumeration names = request.getParameterNames(); + while (names.hasMoreElements()) { + String name = names.nextElement(); + if (!BLACKLIST.contains(name)) { + parameters.put(name, request.getParameter(name)); + } + } + if (request.getMethod().equals(HttpMethods.POST) && !input.isEmpty()) { try { - parameters = deserializer.deserialize(new InputStreamReader(request.getInputStream())); + parameters.putAll(deserializer.deserialize(input)); } catch (Exception e) { + e.printStackTrace(); } } String token = request.getHeader(Parameters.X_AUTH_TOKEN); @@ -135,7 +155,7 @@ public abstract class Command { } else { try { try { - accessToken = new AccessToken(token); + accessToken = new AccessToken(getCompanyId(request), token); sportello = SportelloLocalServiceUtil.getSportello(accessToken.getSportelloId()); } catch (InvalidTokenException e) { Response.write(response, Status.INVALID_TOKEN); @@ -153,6 +173,19 @@ public abstract class Command { return false; } + protected long getCompanyId(HttpServletRequest request) throws PortalException, SystemException { + + if (0 == companyId) { + Company company = PortalUtil.getCompany(request); + if (Validator.isNull(company)) { + companyId = PortalUtil.getDefaultCompanyId(); + } else { + companyId = company.getCompanyId(); + } + } + return companyId; + } + protected Sportello getSportello() { if (null == sportello) { @@ -196,7 +229,7 @@ public abstract class Command { } } catch (PortalException | SystemException e) { additionalInfo.add("Errore del server durante il caricamento dell'istanza"); - Response.write(response, Status.INVALID_INPUT, additionalInfo); + Response.write(response, Status.SERVER_ERROR, additionalInfo); return null; } return intPratica; 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 6fab80d5..3d6f72cc 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 @@ -11,11 +11,11 @@ import it.mwg.sicilia.sue.api.v1.command.impl.ListAttachments; import it.mwg.sicilia.sue.api.v1.command.impl.ListFields; import it.mwg.sicilia.sue.api.v1.command.impl.ListValues; 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 it.mwg.sicilia.sue.api.v1.command.impl.SetFields; import it.mwg.sicilia.sue.api.v1.command.impl.UploadAttachment; +import it.mwg.sicilia.sue.api.v1.command.impl.VerifyApplication; import java.util.Collection; import java.util.LinkedHashMap; @@ -33,37 +33,31 @@ public class CommandList { private static final Set verbs = new TreeSet<>(); static { // Manuali - addCommand(new Manual("Restituisce la documentazione dell'API generata automaticamente", HttpMethods.GET, - HttpMethods.POST)); - addCommand(new ManualHtml("Restituisce la documentazione dell'API generata automaticamente in versione HTML", - HttpMethods.GET, HttpMethods.POST)); + addCommand(new ManualHtml("Restituisce la documentazione dell'API generata automaticamente in versione HTML")); // Login - addCommand(new Login("Esegue l'accesso con nome email e password e restituisce un token di accesso")); - // Elenchi - addCommand(new ListApplications("Elenco delle istanze presentabili sul portale", HttpMethods.GET, - HttpMethods.POST)); - addCommand(new ListAttachments("Elenco dei documenti riconosciuti dal portale", HttpMethods.GET, - HttpMethods.POST)); - addCommand(new ListFields("Elenco dei dati dell'istanza accettati dal portale", HttpMethods.GET, + addCommand(new Login("Esegue l'accesso con nome email e password e restituisce un token di accesso", HttpMethods.POST)); + // Elenchi + addCommand(new ListApplications("Elenco delle istanze presentabili sul portale")); + addCommand(new ListAttachments("Elenco dei documenti riconosciuti dal portale")); + addCommand(new ListFields("Elenco dei dati dell'istanza accettati dal portale")); addCommand(new ListValues("Elenca i valori ammissibili per un campo a selezione obbligata")); // Istanze addCommand(new AddApplication( "Crea una nuova istanza di endoprocedimento, crea l'utente se non esiste ancora sul portale")); - addCommand(new GetApplications("Elenca le istanze in lavorazione da questo SUE", HttpMethods.GET, - HttpMethods.POST)); + addCommand(new GetApplications("Elenca le istanze in lavorazione da questo SUE")); addCommand(new DeleteApplication("Elimina un'istanza")); + addCommand(new VerifyApplication("Verifica la completezza dell'istanza")); addCommand(new SetFields( "Imposta i valori dei dati dell'istanza, l'elenco dei campi valorizzabili è fornito dal comando " + Command.getCommandVerb(ListFields.class))); // Allegati - addCommand(new UploadAttachment("Allega un documento all'istanza")); + addCommand(new UploadAttachment("Allega un documento all'istanza", HttpMethods.POST)); addCommand(new GetAttachments("Elenca gli allegati dell'istanza")); addCommand(new DeleteAttachment("Elimina un allegato")); // Altro - addCommand(new Nop("NOP verifica la connettività senza eseguire operazioni", HttpMethods.GET, HttpMethods.POST)); - addCommand(new GetSourceCode("Scarica il codice sorgente generato per il client", HttpMethods.GET, - HttpMethods.POST)); + addCommand(new Nop("NOP verifica la connettività senza eseguire operazioni")); + addCommand(new GetSourceCode("Scarica il codice sorgente generato per il client")); } private static void addCommand(Command command) { 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/GetApplications.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetApplications.java index b74ab5bb..808df6f8 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetApplications.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetApplications.java @@ -25,6 +25,13 @@ import com.liferay.portal.kernel.dao.orm.QueryUtil; public class GetApplications extends Command { + @SuppressWarnings("serial") + private static final List INPUT_PARAMETERS = new ArrayList() { + { + add(new Parameter(Parameters.CODE, TYPES.STRING, "Codice del tipo di istanza", false)); + } + }; + private static final List OUTPUT_PARAMETERS = new ArrayList<>(); static { OUTPUT_PARAMETERS.addAll(BASE_OUTPUT_PARAMETERS); @@ -62,7 +69,7 @@ public class GetApplications extends Command { @Override public List getInputParameters() { - return EMPTY_PARAMETERS; + return INPUT_PARAMETERS; } @Override 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/GetSourceCode.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetSourceCode.java index 9fb588fd..f93fbb51 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetSourceCode.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/GetSourceCode.java @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.FileUtils; import com.liferay.portal.kernel.servlet.HttpHeaders; +import com.liferay.portal.kernel.servlet.HttpMethods; import com.liferay.portal.kernel.servlet.ServletResponseUtil; import com.liferay.portal.kernel.util.ContentTypes; import com.liferay.portal.kernel.util.StringPool; @@ -68,7 +69,7 @@ public class GetSourceCode extends Command { public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { ServletContext servletContext = request.getServletContext(); - String regex = "(\\s*)\\/\\/\\{\\{([^}]*)\\}\\}\\/\\/(.*)"; + String regex = "(\\s*)(.*?)\\/\\/\\{\\{([^}]*)\\}\\}\\/\\/(.*)"; Pattern pattern = Pattern.compile(regex); File sourcePath = new File(servletContext.getRealPath("/WEB-INF/src/resource/client/php")); URI sourceUri = sourcePath.toURI(); @@ -79,27 +80,30 @@ public class GetSourceCode extends Command { for (String line = reader.readLine(); null != line; line = reader.readLine()) { Matcher matcher = pattern.matcher(line); if (matcher.matches()) { - switch (matcher.group(2)) { + switch (matcher.group(3)) { case "CLIENT_FUNCTIONS": - line = line.replaceAll(regex, getClientFunctions(matcher.group(1)) + "$3"); + line = line.replaceAll(regex, getClientFunctions(matcher.group(1)) + "$4"); break; case "COMMANDS": - line = line.replaceAll(regex, getCommands(matcher.group(1)) + "$3"); + line = line.replaceAll(regex, getCommands(matcher.group(1)) + "$4"); + break; + case "ENDPOINT": + line = line.replace("//{{ENDPOINT}}//", ApiUtil.getBaseUrl(request)); break; case "HELP_ARRAY": - line = line.replaceAll(regex, getHelpArray(matcher.group(1)) + "$3"); + line = line.replaceAll(regex, getHelpArray(matcher.group(1)) + "$4"); break; case "METHODS": - line = line.replaceAll(regex, getMethods(matcher.group(1)) + "$3"); + line = line.replaceAll(regex, getMethods(matcher.group(1)) + "$4"); break; case "PARAMETERS": - line = line.replaceAll(regex, getParameters(matcher.group(1)) + "$3"); + line = line.replaceAll(regex, getParameters(matcher.group(1)) + "$4"); break; case "STATUSES": - line = line.replaceAll(regex, getStatuses(matcher.group(1)) + "$3"); + line = line.replaceAll(regex, getStatuses(matcher.group(1)) + "$4"); break; default: - System.out.println("################# Unknown match //{{" + matcher.group(2) + "}}//"); + System.out.println("################# Unknown match //{{" + matcher.group(3) + "}}//"); } } output.append(line).append(StringPool.NEW_LINE); @@ -133,7 +137,8 @@ public class GetSourceCode extends Command { sb.append(prefix).append(INDENT).append("if (\\$argc < ").append(nRequired + 2).append(") {\n"); sb.append(prefix).append(INDENT).append(INDENT) .append("echo(\"Numero di argomenti insufficiente.\\\\n\\\\n\");\n"); - sb.append(prefix).append(INDENT).append(INDENT).append("die(\\$api->getHelp(\\$argv[1]));\n"); + sb.append(prefix).append(INDENT).append(INDENT) + .append("die(\\$api->getHelp(\\$argv[0], \\$argv[1]));\n"); sb.append(prefix).append(INDENT).append("}\n"); } if (command.isSecure()) { @@ -197,7 +202,7 @@ public class GetSourceCode extends Command { if (!verb.equals("login")) { Command command = CommandList.get(verb); sb.append(prefix).append(StringPool.APOSTROPHE).append(verb).append("' => [\n"); - sb.append(prefix).append(INDENT).append("\"Uso: php {\\$argv[0]} ").append(verb); + sb.append(prefix).append(INDENT).append("\"Uso: php \\$application ").append(verb); for (Parameter parameter : command.getInputParameters()) { if (parameter.isRequired()) { sb.append(" <").append(parameter.getName()).append(StringPool.GREATER_THAN); @@ -216,8 +221,7 @@ public class GetSourceCode extends Command { boolean hasRequired = false; for (Parameter parameter : command.getInputParameters()) { if (parameter.isRequired()) { - sb.append(prefix).append(INDENT).append("'**").append(parameter.getName()) - .append(": ") + sb.append(prefix).append(INDENT).append("'**").append(parameter.getName()).append(": ") .append(parameter.getDescription().replace(StringPool.APOSTROPHE, "\\\\'")) .append("',\n"); hasRequired = true; @@ -290,7 +294,13 @@ public class GetSourceCode extends Command { } if (allRequired) { sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase()) - .append(", [\n"); + .append(StringPool.COMMA_AND_SPACE); + if (command.getMethods().size() > 1) { + sb.append("\\$this->config->getDefaultMethod() === 'POST'"); + } else { + sb.append(command.getMethods().get(0).equals(HttpMethods.POST)); + } + sb.append(", [\n"); for (Parameter parameter : parameters) { sb.append(prefix).append(INDENT).append(INDENT).append("Parameters::") .append(PARAMETER_NAMES.get(parameter.getName())).append(" => \\$") @@ -322,14 +332,26 @@ public class GetSourceCode extends Command { } } sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase()) - .append(", \\$data"); + .append(StringPool.COMMA_AND_SPACE); + if (command.getMethods().size() > 1) { + sb.append("\\$this->config->getDefaultMethod() === 'POST'"); + } else { + sb.append(command.getMethods().get(0).equals(HttpMethods.POST)); + } + sb.append(", \\$data"); if (!command.isSecure()) { sb.append(", false"); } sb.append(");\n"); } } else { - sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase()); + sb.append(prefix).append(INDENT).append("return \\$this->exec(Commands::").append(verb.toUpperCase()) + .append(StringPool.COMMA_AND_SPACE); + if (command.getMethods().size() > 1) { + sb.append("\\$this->config->getDefaultMethod() === 'POST'"); + } else { + sb.append(command.getMethods().get(0).equals(HttpMethods.POST)); + } if (!command.isSecure()) { sb.append(", null, false"); } 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/Login.java b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Login.java index a9d50456..8b3f4037 100644 --- a/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Login.java +++ b/liferay-plugins-sdk-6.2/portlets/sicilia-sue-connector-portlet/docroot/WEB-INF/src/it/mwg/sicilia/sue/api/v1/command/impl/Login.java @@ -48,14 +48,19 @@ public class Login extends Command { public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { readParameters(request); - String userName = (String) parameters.get(Parameters.USERNAME); + List additionalInfo = new ArrayList<>(); + String username = (String) parameters.get(Parameters.USERNAME); + if (null == username) { + additionalInfo.add("Parametro " + Parameters.USERNAME + " mancante"); + } String password = (String) parameters.get(Parameters.PASSWORD); - if ((null == userName) || (null == password)) { - response.sendError(HttpServletResponse.SC_BAD_REQUEST); - } else { + if (null == password) { + additionalInfo.add("Parametro " + Parameters.PASSWORD + " mancante"); + } + if (additionalInfo.isEmpty()) { Sportello sportello = null; try { - sportello = SportelloLocalServiceUtil.findByUserName(userName); + sportello = SportelloLocalServiceUtil.findByUserName(username); } catch (NoSuchSportelloException | SystemException e) { } if (Validator.isNull(sportello) || !sportello.checkPassword(password)) { @@ -67,6 +72,8 @@ public class Login extends Command { result.put(Parameters.TOKEN, new AccessToken(sportello).getToken()); Response.write(response, Status.OK, result); } + } else { + Response.write(response, Status.INVALID_INPUT, additionalInfo); } } 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 0fd271b5..68dbe983 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 @@ -2,11 +2,13 @@ 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 it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES; import java.io.Serializable; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; @@ -16,14 +18,10 @@ 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.Base64; -import com.liferay.portal.kernel.util.Http; import com.liferay.portal.kernel.util.StringPool; public class Manual extends Command { @@ -35,8 +33,6 @@ public class Manual extends Command { } }; - private static String baseUrl = null; - private static final JSONSerializer serializer = JSONFactoryUtil.createJSONSerializer(); public Manual(String description, String... methods) { @@ -45,68 +41,14 @@ public class Manual extends Command { @Override public void run(HttpServletRequest request, HttpServletResponse response) throws Exception { - - StringBuilder result = new StringBuilder(); - Iterator commands = CommandList.getList().iterator(); - while (commands.hasNext()) { - Command command = commands.next(); - result.append("Comando: /").append(command.getVerb()); - if (command.isSecure()) { - result.append(" [T]"); - } - result.append(StringPool.NEW_LINE); - result.append(command.getDescription()).append(StringPool.NEW_LINE); - result.append("Metodi: ").append(StringUtils.join(command.getMethods(), StringPool.COMMA_AND_SPACE)) - .append(StringPool.NEW_LINE); - result.append("Parametri:"); - List parameters = command.getInputParameters(); - if (parameters.isEmpty()) { - result.append(" Nessuno\n"); - } else { - result.append(StringPool.NEW_LINE); - for (Parameter parameter : parameters) { - result.append(StringPool.TAB).append(parameter.getName()); - if (parameter.isRequired()) { - result.append(StringPool.STAR); - } - result.append(" (").append(parameter.getType().toString()).append(") - ") - .append(parameter.getDescription()).append(StringPool.NEW_LINE); - } - } - parameters = command.getOutputParameters(); - if (!parameters.isEmpty()) { - result.append("Restituisce:\n"); - for (Parameter parameter : parameters) { - result.append(StringPool.TAB).append(parameter.getName()).append(" (") - .append(parameter.getType().toString()).append(") - ").append(parameter.getDescription()) - .append(StringPool.NEW_LINE); - if (parameter.getType().equals(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), StringPool.TAB)); - if (commands.hasNext()) { - result.append("================================================================================\n"); - } - } - 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"); - setTextPlain(response); - ServletResponseUtil.write(response, result.toString()); } - protected String getCurlExample(Command command, String baseUrl) { + protected String getCurlExample(Command command, String method, String baseUrl) { - return getCurlExample(command, baseUrl, StringPool.BLANK); + return getCurlExample(command, method, baseUrl, StringPool.BLANK); } - protected String getCurlExample(Command command, String baseUrl, String prefix) { + protected String getCurlExample(Command command, String method, String baseUrl, String prefix) { StringBuilder sb = new StringBuilder(); sb.append(prefix).append("curl "); @@ -114,33 +56,49 @@ public class Manual extends Command { sb.append("--header \"").append(Parameters.X_AUTH_TOKEN).append(": $TOKEN\"").append(" \\\n") .append(prefix).append(StringPool.TAB); } - if (command.getMethods().contains(HttpMethods.GET)) { - } else { - sb.append("--header \"Content-Type: application/json; charset=UTF-8\" \\\n").append(prefix) - .append(StringPool.TAB); - sb.append("--request POST \\\n").append(prefix).append(StringPool.TAB); - Map data = new LinkedHashMap<>(); - for (Parameter parameter : command.getInputParameters()) { - if (parameter.getType().equals(TYPES.ARRAY)) { - List> list = new ArrayList<>(); - for (int i = 1; i < 3; i++) { - Map item = new LinkedHashMap<>(); - for (Parameter subParameter : parameter.getSubParameters()) { - item.put(subParameter.getName(), getParameterSampleValue(subParameter, i)); - } - list.add(item); + Map data = new LinkedHashMap<>(); + for (Parameter parameter : command.getInputParameters()) { + if (parameter.getType().equals(TYPES.ARRAY)) { + List> list = new ArrayList<>(); + for (int i = 1; i < 3; i++) { + Map item = new LinkedHashMap<>(); + for (Parameter subParameter : parameter.getSubParameters()) { + item.put(subParameter.getName(), getParameterSampleValue(subParameter, i)); } - data.put(parameter.getName(), (Serializable) list); - } else { - data.put(parameter.getName(), getParameterSampleValue(parameter)); + list.add(item); } + data.put(parameter.getName(), (Serializable) list); + } else { + data.put(parameter.getName(), getParameterSampleValue(parameter)); } + } + if (method.equals(HttpMethods.POST)) { + sb.append("--request POST \\\n").append(prefix).append(StringPool.TAB); if (data.size() > 0) { + sb.append("--header \"Content-Type: application/json; charset=UTF-8\" \\\n").append(prefix) + .append(StringPool.TAB); sb.append("--data '").append(serializer.serializeDeep(data)).append("' \\\n").append(prefix) .append(StringPool.TAB); } } - sb.append(baseUrl).append(command.getVerb()).append(StringPool.NEW_LINE); + sb.append(baseUrl).append(command.getVerb()); + if (method.equals(HttpMethods.GET) && !data.isEmpty()) { + sb.append(StringPool.QUESTION); + Iterator names = data.keySet().iterator(); + while (names.hasNext()) { + String name = names.next(); + sb.append(name).append(StringPool.EQUAL); + try { + sb.append(URLEncoder.encode(data.get(name).toString(), StandardCharsets.UTF_8.toString())); + } catch (UnsupportedEncodingException e) { + sb.append(data.get(name).toString()); + } + if (names.hasNext()) { + sb.append(StringPool.AMPERSAND); + } + } + } + sb.append(StringPool.NEW_LINE); return sb.toString(); } @@ -170,22 +128,6 @@ public class Manual extends Command { return ret; } - protected 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; 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 index a74612ae..adf8f17a 100644 --- 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 @@ -5,6 +5,7 @@ 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 it.mwg.sicilia.sue.api.v1.parameter.Parameter.TYPES; +import it.mwg.sicilia.sue.api.v1.util.ApiUtil; import java.io.File; import java.util.ArrayList; @@ -35,13 +36,13 @@ public class ManualHtml extends Manual { String cssFile = "/css/api/v1/api.css"; String bootstrapFile = "/css/bootstrap.css"; StringBuilder result = new StringBuilder(); - result.append("").append("") + result.append("") .append("") - .append("Manual").append("Manual") .append("").append(""); + .append("\">"); result.append("
"); result.append("
"); result.append("
"); @@ -57,15 +58,15 @@ public class ManualHtml extends Manual { result.append(""); result.append("

").append(command.getDescription()) .append(".

"); - result.append("
"); - for (String cmd : command.getMethods()) { - result.append("").append(cmd).append(""); + for (String method : command.getMethods()) { + result.append("
"); + result.append("").append(method).append(""); + result.append("
"); + result.append("
");
+				result.append(getCurlExample(command, method, ApiUtil.getBaseUrl(request)));
+				result.append("
"); } - result.append("
"); - result.append("
");
-			result.append(getCurlExample(command, getBaseUrl(request)));
-			result.append("
"); List parameters = command.getInputParameters(); result.append("
"); 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); }