|
|
|
@ -33,156 +33,162 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
public class FirmaServlet extends HttpServlet { |
|
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
|
|
|
|
|
|
private static final String GET_CONFIGURATION = "get-configuration"; // get
|
|
|
|
|
private static final String GET_FILE_LIST = "get-file-list"; // post
|
|
|
|
|
private static final String GET_FILE = "get-file"; // post
|
|
|
|
|
private static final String GET_TYPE = "get-type"; // get
|
|
|
|
|
private static final String GET_TYPE_VERBALE = "get-type-verbale"; // get
|
|
|
|
|
private static final String LOGIN = "login"; // get
|
|
|
|
|
private static final String OPEN_PRATICA = "open-pratica"; // post
|
|
|
|
|
private static final String RIFIUTA = "rifiuta"; // post
|
|
|
|
|
private static final String SET_FILE = "set-file"; // post
|
|
|
|
|
private static final String VERSION = "version"; // get
|
|
|
|
|
private static final String GET_STILE = "get-stile"; // get
|
|
|
|
|
|
|
|
|
|
private static final Log _log = LogFactoryUtil.getLog(FirmaServlet.class); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @see HttpServlet#HttpServlet() |
|
|
|
|
*/ |
|
|
|
|
public FirmaServlet() { |
|
|
|
|
|
|
|
|
|
super(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
|
|
|
|
|
|
|
|
|
String pathInfo = request.getPathInfo().substring(1); |
|
|
|
|
String[] pathArray = StringUtil.split(pathInfo, "/"); |
|
|
|
|
FirmaGetUtil firmaGetUtil = new FirmaGetUtil(); |
|
|
|
|
String metodo = pathArray[0]; |
|
|
|
|
Risposta<?> risposta = new Risposta<>(); |
|
|
|
|
|
|
|
|
|
switch (metodo) { |
|
|
|
|
case GET_CONFIGURATION: |
|
|
|
|
risposta = firmaGetUtil.getConfiguration(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case GET_TYPE: |
|
|
|
|
risposta = firmaGetUtil.getType(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case GET_TYPE_VERBALE: |
|
|
|
|
risposta = firmaGetUtil.getTypeVerbale(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case LOGIN: |
|
|
|
|
if (pathArray.length == 2) { |
|
|
|
|
String codiceFiscale = pathArray[1]; |
|
|
|
|
risposta = firmaGetUtil.loginCodiceFiscale(codiceFiscale); |
|
|
|
|
} |
|
|
|
|
if (pathArray.length == 3) { |
|
|
|
|
String nome = pathArray[1]; |
|
|
|
|
String cognome = pathArray[2]; |
|
|
|
|
risposta = firmaGetUtil.loginNomeCognome(nome, cognome); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case VERSION: |
|
|
|
|
risposta = firmaGetUtil.version(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case GET_STILE: |
|
|
|
|
risposta = firmaGetUtil.getStile(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
JSONSerializer jsonSerializer = JSONFactoryUtil.createJSONSerializer(); |
|
|
|
|
jsonSerializer.exclude("*.class"); |
|
|
|
|
String jsonResponse = jsonSerializer.serializeDeep(risposta); |
|
|
|
|
|
|
|
|
|
response.setContentType("application/json; charset=UTF-8"); |
|
|
|
|
ServletResponseUtil.write(response, jsonResponse); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
|
|
|
|
|
|
|
|
|
String pathInfo = request.getPathInfo().substring(1); |
|
|
|
|
String[] pathArray = StringUtil.split(pathInfo, "/"); |
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
StreamUtil.transfer(request.getInputStream(), outputStream); |
|
|
|
|
String token = new String(outputStream.toByteArray(), StandardCharsets.UTF_8); |
|
|
|
|
|
|
|
|
|
FirmaPostUtil firmaPostUtil = new FirmaPostUtil(); |
|
|
|
|
String metodo = pathArray[0]; |
|
|
|
|
Risposta<?> risposta = new Risposta<>(); |
|
|
|
|
|
|
|
|
|
switch (metodo) { |
|
|
|
|
case GET_FILE: |
|
|
|
|
if (pathArray.length == 3) { |
|
|
|
|
String tipo = pathArray[1]; |
|
|
|
|
String id = pathArray[2]; |
|
|
|
|
risposta = firmaPostUtil.getFile(token, tipo, id); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case GET_FILE_LIST: |
|
|
|
|
risposta = firmaPostUtil.getFileList(token); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case OPEN_PRATICA: |
|
|
|
|
if (pathArray.length == 2) { |
|
|
|
|
String idFile = pathArray[1]; |
|
|
|
|
risposta = firmaPostUtil.openPratica(token, idFile); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case RIFIUTA: |
|
|
|
|
if (pathArray.length == 5) { |
|
|
|
|
String idFile = pathArray[1]; |
|
|
|
|
String messaggio = pathArray[2]; |
|
|
|
|
String cambiaFase = pathArray[3]; |
|
|
|
|
String assegna = pathArray[4]; |
|
|
|
|
risposta = firmaPostUtil.rifiuta(token, idFile, messaggio, cambiaFase, assegna); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case SET_FILE: |
|
|
|
|
if (pathArray.length == 3) { |
|
|
|
|
String tipo = pathArray[1]; |
|
|
|
|
String idFile = pathArray[2]; |
|
|
|
|
JSONDeserializer<Map<String, String>> jsonDeserializer = JSONFactoryUtil.createJSONDeserializer(); |
|
|
|
|
Map<String, String> map = jsonDeserializer.deserialize(token); |
|
|
|
|
|
|
|
|
|
ServiceContext serviceContext = null; |
|
|
|
|
try { |
|
|
|
|
serviceContext = ServiceContextFactory.getInstance(request); |
|
|
|
|
} catch (PortalException | SystemException e) { |
|
|
|
|
_log.error(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
risposta = firmaPostUtil.setFile(map.get("token"), map.get("file"), tipo, idFile, serviceContext); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSONSerializer jsonSerializer = JSONFactoryUtil.createJSONSerializer(); |
|
|
|
|
jsonSerializer.exclude("*.class"); |
|
|
|
|
String jsonResponse = jsonSerializer.serialize(risposta); |
|
|
|
|
|
|
|
|
|
response.setContentType("application/json; charset=UTF-8"); |
|
|
|
|
ServletResponseUtil.write(response, jsonResponse); |
|
|
|
|
} |
|
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
|
|
|
|
|
|
private static final String GET_CONFIGURATION = "get-configuration"; // get
|
|
|
|
|
private static final String GET_FILE_LIST = "get-file-list"; // post
|
|
|
|
|
private static final String GET_FILE = "get-file"; // post
|
|
|
|
|
private static final String GET_TYPE = "get-type"; // get
|
|
|
|
|
private static final String GET_TYPE_VERBALE = "get-type-verbale"; // get
|
|
|
|
|
private static final String LOGIN = "login"; // get
|
|
|
|
|
private static final String OPEN_PRATICA = "open-pratica"; // post
|
|
|
|
|
private static final String RIFIUTA = "rifiuta"; // post
|
|
|
|
|
private static final String SET_FILE = "set-file"; // post
|
|
|
|
|
private static final String VERSION = "version"; // get
|
|
|
|
|
private static final String GET_STILE = "get-stile"; // get
|
|
|
|
|
|
|
|
|
|
private static final Log _log = LogFactoryUtil.getLog(FirmaServlet.class); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @see HttpServlet#HttpServlet() |
|
|
|
|
*/ |
|
|
|
|
public FirmaServlet() { |
|
|
|
|
|
|
|
|
|
super(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse |
|
|
|
|
* response) |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, |
|
|
|
|
IOException { |
|
|
|
|
|
|
|
|
|
String pathInfo = request.getPathInfo().substring(1); |
|
|
|
|
String[] pathArray = StringUtil.split(pathInfo, "/"); |
|
|
|
|
FirmaGetUtil firmaGetUtil = new FirmaGetUtil(); |
|
|
|
|
String metodo = pathArray[0]; |
|
|
|
|
Risposta<?> risposta = new Risposta<>(); |
|
|
|
|
|
|
|
|
|
switch (metodo) { |
|
|
|
|
case GET_CONFIGURATION: |
|
|
|
|
risposta = firmaGetUtil.getConfiguration(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case GET_TYPE: |
|
|
|
|
risposta = firmaGetUtil.getType(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case GET_TYPE_VERBALE: |
|
|
|
|
risposta = firmaGetUtil.getTypeVerbale(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case LOGIN: |
|
|
|
|
if (pathArray.length == 2) { |
|
|
|
|
String codiceFiscale = pathArray[1]; |
|
|
|
|
risposta = firmaGetUtil.loginCodiceFiscale(codiceFiscale); |
|
|
|
|
} |
|
|
|
|
if (pathArray.length == 3) { |
|
|
|
|
String nome = pathArray[1]; |
|
|
|
|
String cognome = pathArray[2]; |
|
|
|
|
risposta = firmaGetUtil.loginNomeCognome(nome, cognome); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case VERSION: |
|
|
|
|
risposta = firmaGetUtil.version(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case GET_STILE: |
|
|
|
|
risposta = firmaGetUtil.getStile(); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
JSONSerializer jsonSerializer = JSONFactoryUtil.createJSONSerializer(); |
|
|
|
|
jsonSerializer.exclude("*.class"); |
|
|
|
|
String jsonResponse = jsonSerializer.serializeDeep(risposta); |
|
|
|
|
|
|
|
|
|
response.setContentType("application/json; charset=UTF-8"); |
|
|
|
|
ServletResponseUtil.write(response, jsonResponse); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse |
|
|
|
|
* response) |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, |
|
|
|
|
IOException { |
|
|
|
|
|
|
|
|
|
String pathInfo = request.getPathInfo().substring(1); |
|
|
|
|
String[] pathArray = StringUtil.split(pathInfo, "/"); |
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
StreamUtil.transfer(request.getInputStream(), outputStream); |
|
|
|
|
String token = new String(outputStream.toByteArray(), StandardCharsets.UTF_8); |
|
|
|
|
|
|
|
|
|
FirmaPostUtil firmaPostUtil = new FirmaPostUtil(); |
|
|
|
|
String metodo = pathArray[0]; |
|
|
|
|
Risposta<?> risposta = new Risposta<>(); |
|
|
|
|
|
|
|
|
|
switch (metodo) { |
|
|
|
|
case GET_FILE: |
|
|
|
|
if (pathArray.length == 3) { |
|
|
|
|
String tipo = pathArray[1]; |
|
|
|
|
String id = pathArray[2]; |
|
|
|
|
risposta = firmaPostUtil.getFile(token, tipo, id); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case GET_FILE_LIST: |
|
|
|
|
risposta = firmaPostUtil.getFileList(token); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case OPEN_PRATICA: |
|
|
|
|
if (pathArray.length == 2) { |
|
|
|
|
String idFile = pathArray[1]; |
|
|
|
|
risposta = firmaPostUtil.openPratica(token, idFile); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case RIFIUTA: |
|
|
|
|
if (pathArray.length == 5) { |
|
|
|
|
String idFile = pathArray[1]; |
|
|
|
|
String messaggio = pathArray[2]; |
|
|
|
|
String cambiaFase = pathArray[3]; |
|
|
|
|
String assegna = pathArray[4]; |
|
|
|
|
risposta = firmaPostUtil.rifiuta(token, idFile, messaggio, cambiaFase, assegna); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case SET_FILE: |
|
|
|
|
if (pathArray.length == 3) { |
|
|
|
|
String tipo = pathArray[1]; |
|
|
|
|
String idFile = pathArray[2]; |
|
|
|
|
JSONDeserializer<Map<String, String>> jsonDeserializer = JSONFactoryUtil |
|
|
|
|
.createJSONDeserializer(); |
|
|
|
|
Map<String, String> map = jsonDeserializer.deserialize(token); |
|
|
|
|
|
|
|
|
|
ServiceContext serviceContext = null; |
|
|
|
|
try { |
|
|
|
|
serviceContext = ServiceContextFactory.getInstance(request); |
|
|
|
|
} catch (PortalException | SystemException e) { |
|
|
|
|
_log.error(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
risposta = firmaPostUtil.setFile(map.get("token"), map.get("file"), tipo, idFile, |
|
|
|
|
serviceContext); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSONSerializer jsonSerializer = JSONFactoryUtil.createJSONSerializer(); |
|
|
|
|
jsonSerializer.exclude("*.class"); |
|
|
|
|
String jsonResponse = jsonSerializer.serialize(risposta); |
|
|
|
|
|
|
|
|
|
response.setContentType("application/json; charset=UTF-8"); |
|
|
|
|
ServletResponseUtil.write(response, jsonResponse); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|