|
|
@ -1,5 +1,6 @@ |
|
|
|
package it.tref.liferay.portos.bo.util; |
|
|
|
package it.tref.liferay.portos.bo.util; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import it.mwg.sismica.bo.util.HttpPostUtil; |
|
|
|
import it.tref.liferay.portos.bo.model.Avviso; |
|
|
|
import it.tref.liferay.portos.bo.model.Avviso; |
|
|
|
import it.tref.liferay.portos.bo.model.Collaudo; |
|
|
|
import it.tref.liferay.portos.bo.model.Collaudo; |
|
|
|
import it.tref.liferay.portos.bo.model.DettPratica; |
|
|
|
import it.tref.liferay.portos.bo.model.DettPratica; |
|
|
@ -34,19 +35,20 @@ import org.apache.commons.codec.digest.DigestUtils; |
|
|
|
import org.apache.commons.csv.CSVFormat; |
|
|
|
import org.apache.commons.csv.CSVFormat; |
|
|
|
import org.apache.commons.csv.CSVRecord; |
|
|
|
import org.apache.commons.csv.CSVRecord; |
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
|
|
|
|
import org.apache.http.HttpResponse; |
|
|
|
|
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
|
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
|
|
|
|
import org.apache.http.impl.client.HttpClientBuilder; |
|
|
|
|
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
|
|
|
|
|
|
|
|
import com.liferay.portal.kernel.exception.PortalException; |
|
|
|
import com.liferay.portal.kernel.exception.PortalException; |
|
|
|
import com.liferay.portal.kernel.exception.SystemException; |
|
|
|
import com.liferay.portal.kernel.exception.SystemException; |
|
|
|
import com.liferay.portal.kernel.json.JSONFactoryUtil; |
|
|
|
import com.liferay.portal.kernel.json.JSONFactoryUtil; |
|
|
|
import com.liferay.portal.kernel.json.JSONObject; |
|
|
|
import com.liferay.portal.kernel.json.JSONObject; |
|
|
|
import com.liferay.portal.kernel.log.Log; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.repository.model.FileEntry; |
|
|
|
import com.liferay.portal.kernel.repository.model.FileEntry; |
|
|
|
import com.liferay.portal.kernel.util.ContentTypes; |
|
|
|
import com.liferay.portal.kernel.util.ContentTypes; |
|
|
|
import com.liferay.portal.kernel.util.GetterUtil; |
|
|
|
import com.liferay.portal.kernel.util.GetterUtil; |
|
|
|
import com.liferay.portal.kernel.util.Http.Body; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.Http.Options; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.HttpUtil; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.ParamUtil; |
|
|
|
import com.liferay.portal.kernel.util.ParamUtil; |
|
|
|
import com.liferay.portal.kernel.util.StreamUtil; |
|
|
|
import com.liferay.portal.kernel.util.StreamUtil; |
|
|
|
import com.liferay.portal.kernel.util.StringPool; |
|
|
|
import com.liferay.portal.kernel.util.StringPool; |
|
|
@ -59,15 +61,6 @@ import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil; |
|
|
|
|
|
|
|
|
|
|
|
public class ProtocollazioneUtil { |
|
|
|
public class ProtocollazioneUtil { |
|
|
|
|
|
|
|
|
|
|
|
private static final Log _log = LogFactoryUtil.getLog(ProtocollazioneUtil.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public static String protocollaPartenza(DettPratica dettPratica, Avviso
|
|
|
|
|
|
|
|
// avviso) throws
|
|
|
|
|
|
|
|
// Exception {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return protocollaPartenza(dettPratica, avviso, null);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String protocollaPartenza(Avviso avviso, Long fileEntryId) throws Exception { |
|
|
|
public static String protocollaPartenza(Avviso avviso, Long fileEntryId) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
String protocollo = null; |
|
|
|
String protocollo = null; |
|
|
@ -80,7 +73,6 @@ public class ProtocollazioneUtil { |
|
|
|
|
|
|
|
|
|
|
|
File allegato = new File(); |
|
|
|
File allegato = new File(); |
|
|
|
if (Validator.isNotNull(fileEntryId)) { |
|
|
|
if (Validator.isNotNull(fileEntryId)) { |
|
|
|
|
|
|
|
|
|
|
|
FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId); |
|
|
|
FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId); |
|
|
|
|
|
|
|
|
|
|
|
inputStream = DLFileEntryLocalServiceUtil.getFileAsStream(fileEntry.getFileEntryId(), |
|
|
|
inputStream = DLFileEntryLocalServiceUtil.getFileAsStream(fileEntry.getFileEntryId(), |
|
|
@ -91,7 +83,6 @@ public class ProtocollazioneUtil { |
|
|
|
allegato.setFileSha256(sha256); |
|
|
|
allegato.setFileSha256(sha256); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
String doc = String.valueOf(avviso.getAvvisoId()); |
|
|
|
String doc = String.valueOf(avviso.getAvvisoId()); |
|
|
|
|
|
|
|
|
|
|
|
String sha256 = DigestUtils.sha256Hex(doc); |
|
|
|
String sha256 = DigestUtils.sha256Hex(doc); |
|
|
@ -100,11 +91,10 @@ public class ProtocollazioneUtil { |
|
|
|
allegato.setFileSha256(sha256); |
|
|
|
allegato.setFileSha256(sha256); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// utilizzato anche come discriminate tra la 1a e la 2a chiamata
|
|
|
|
// utilizzato anche come discriminate tra la 1a e la 2a chiamata 1a
|
|
|
|
// 1a recupero numero protocollo -> 1 allegato finto
|
|
|
|
// recupero numero protocollo -> 1 allegato finto 2a aggiorno dati
|
|
|
|
// 2a aggiorno dati del documento prodotto -> 2 allegati, il 1o
|
|
|
|
// del documento prodotto -> 2 allegati, il 1o giusto e il 2o per
|
|
|
|
// giusto e il 2o per recupero
|
|
|
|
// recupero num protocollo
|
|
|
|
// num protocollo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Protocollo protocolloBean = new Protocollo(); |
|
|
|
Protocollo protocolloBean = new Protocollo(); |
|
|
|
protocolloBean.setOggetto(generaOggettoProtocollo(avviso.getClassName(), avviso.getAvvisoId())); |
|
|
|
protocolloBean.setOggetto(generaOggettoProtocollo(avviso.getClassName(), avviso.getAvvisoId())); |
|
|
@ -114,17 +104,8 @@ public class ProtocollazioneUtil { |
|
|
|
protocolloBean.setUfficioId(String.valueOf(groupId)); |
|
|
|
protocolloBean.setUfficioId(String.valueOf(groupId)); |
|
|
|
protocolloBean.setPraticaId(String.valueOf(avviso.getClassPk())); |
|
|
|
protocolloBean.setPraticaId(String.valueOf(avviso.getClassPk())); |
|
|
|
protocolloBean.setFiles(Collections.singletonList(allegato)); |
|
|
|
protocolloBean.setFiles(Collections.singletonList(allegato)); |
|
|
|
Options options = createCall(avviso.getCompanyId(), protocolloBean, true); |
|
|
|
JSONObject risposta = HttpPostUtil.postProtocolloBean(avviso.getCompanyId(), protocolloBean); |
|
|
|
|
|
|
|
protocollo = call(avviso.getCompanyId(), protocolloBean); |
|
|
|
String responseBody = HttpUtil.URLtoString(options); |
|
|
|
|
|
|
|
if (options.getResponse().getResponseCode() == HttpServletResponse.SC_OK |
|
|
|
|
|
|
|
|| options.getResponse().getResponseCode() == HttpServletResponse.SC_CREATED) { |
|
|
|
|
|
|
|
JSONObject risposta = JSONFactoryUtil.createJSONObject(responseBody); |
|
|
|
|
|
|
|
protocollo = risposta.getString("anno") + String.format("%07d", risposta.getInt("numero")); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
throw new Exception(options.getResponse().getResponseCode() + StringPool.SPACE + responseBody); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
StreamUtil.cleanUp(inputStream); |
|
|
|
StreamUtil.cleanUp(inputStream); |
|
|
|
} |
|
|
|
} |
|
|
@ -134,8 +115,6 @@ public class ProtocollazioneUtil { |
|
|
|
|
|
|
|
|
|
|
|
public static String protocollaArrivo(Object praticaInstance, String title) throws Exception { |
|
|
|
public static String protocollaArrivo(Object praticaInstance, String title) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
String protocollo = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long groupId = 0l; |
|
|
|
long groupId = 0l; |
|
|
|
long praticaId = 0l; |
|
|
|
long praticaId = 0l; |
|
|
|
long companyId = 0l; |
|
|
|
long companyId = 0l; |
|
|
@ -202,25 +181,12 @@ public class ProtocollazioneUtil { |
|
|
|
protocolloBean.setPraticaId(String.valueOf(praticaId)); |
|
|
|
protocolloBean.setPraticaId(String.valueOf(praticaId)); |
|
|
|
|
|
|
|
|
|
|
|
protocolloBean.setFiles(allegati); |
|
|
|
protocolloBean.setFiles(allegati); |
|
|
|
Options options = createCall(companyId, protocolloBean, true); |
|
|
|
return call(companyId, protocolloBean); |
|
|
|
|
|
|
|
|
|
|
|
String responseBody = HttpUtil.URLtoString(options); |
|
|
|
|
|
|
|
if (options.getResponse().getResponseCode() == HttpServletResponse.SC_OK |
|
|
|
|
|
|
|
|| options.getResponse().getResponseCode() == HttpServletResponse.SC_CREATED) { |
|
|
|
|
|
|
|
JSONObject risposta = JSONFactoryUtil.createJSONObject(responseBody); |
|
|
|
|
|
|
|
protocollo = risposta.getString("anno") + String.format("%07d", risposta.getInt("numero")); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
throw new Exception(options.getResponse().getResponseCode() + StringPool.SPACE + responseBody); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return protocollo; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String protocollaArrivoAccessoAtti(long groupId, long companyId, String userName, |
|
|
|
public static String protocollaArrivoAccessoAtti(long groupId, long companyId, String userName, |
|
|
|
long accessoAttiId, String className) throws Exception { |
|
|
|
long accessoAttiId, String className) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
String protocollo = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<File> allegati = new ArrayList<File>(); |
|
|
|
List<File> allegati = new ArrayList<File>(); |
|
|
|
File allegato = new File(); |
|
|
|
File allegato = new File(); |
|
|
|
String doc = String.valueOf(accessoAttiId); |
|
|
|
String doc = String.valueOf(accessoAttiId); |
|
|
@ -238,18 +204,7 @@ public class ProtocollazioneUtil { |
|
|
|
protocolloBean.setPraticaId(String.valueOf(accessoAttiId)); |
|
|
|
protocolloBean.setPraticaId(String.valueOf(accessoAttiId)); |
|
|
|
|
|
|
|
|
|
|
|
protocolloBean.setFiles(allegati); |
|
|
|
protocolloBean.setFiles(allegati); |
|
|
|
Options options = createCall(companyId, protocolloBean, true); |
|
|
|
return call(companyId, protocolloBean); |
|
|
|
|
|
|
|
|
|
|
|
String responseBody = HttpUtil.URLtoString(options); |
|
|
|
|
|
|
|
if (options.getResponse().getResponseCode() == HttpServletResponse.SC_OK |
|
|
|
|
|
|
|
|| options.getResponse().getResponseCode() == HttpServletResponse.SC_CREATED) { |
|
|
|
|
|
|
|
JSONObject risposta = JSONFactoryUtil.createJSONObject(responseBody); |
|
|
|
|
|
|
|
protocollo = risposta.getString("anno") + String.format("%07d", risposta.getInt("numero")); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
throw new Exception(options.getResponse().getResponseCode() + StringPool.SPACE + responseBody); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return protocollo; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String generaOggettoProtocollo(String className, long classPk) { |
|
|
|
public static String generaOggettoProtocollo(String className, long classPk) { |
|
|
@ -266,73 +221,6 @@ public class ProtocollazioneUtil { |
|
|
|
return "Oggetto: " + className + " " + classPk; |
|
|
|
return "Oggetto: " + className + " " + classPk; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void test() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String url = "http://172.16.20.148:8080/portos-protocollazione-service/v1/api-rest/genera-protocollo"; |
|
|
|
|
|
|
|
// String url =
|
|
|
|
|
|
|
|
// "http://10.159.51.84:8080/portos-protocollazione-service/v1/api-rest/genera-protocollo";
|
|
|
|
|
|
|
|
Options options = new Options(); |
|
|
|
|
|
|
|
options.setLocation(url); |
|
|
|
|
|
|
|
options.setPost(true); |
|
|
|
|
|
|
|
flexjson.JSONSerializer serialize = new flexjson.JSONSerializer(); |
|
|
|
|
|
|
|
// JSONSerializer jsonSerializer =
|
|
|
|
|
|
|
|
// JSONFactoryUtil.createJSONSerializer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
serialize.exclude("*.class"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Protocollo protocolloBean = new Protocollo(); |
|
|
|
|
|
|
|
protocolloBean.setOggetto("oggetto"); |
|
|
|
|
|
|
|
protocolloBean.setChiuso(false); |
|
|
|
|
|
|
|
protocolloBean.setTipo(TipoProtocollo.INGRESSO); |
|
|
|
|
|
|
|
protocolloBean.setUtenteId("SSSS"); |
|
|
|
|
|
|
|
protocolloBean.setUfficioId("genio"); |
|
|
|
|
|
|
|
String protocollo = serialize.serialize(protocolloBean); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Body body = new Body(protocollo, ContentTypes.APPLICATION_JSON, "UTF-8"); |
|
|
|
|
|
|
|
options.setBody(body); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
String responseBody = HttpUtil.URLtoString(options); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (options.getResponse().getResponseCode() == HttpServletResponse.SC_OK |
|
|
|
|
|
|
|
|| options.getResponse().getResponseCode() == HttpServletResponse.SC_CREATED) { |
|
|
|
|
|
|
|
System.out.println("ok " + responseBody); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
System.out.println("error " + responseBody); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void createCall(Protocollo protocollo) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Options createCall2(long companyId, Protocollo protocolloBean, boolean post) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String url = |
|
|
|
|
|
|
|
ConfigurazioneLocalServiceUtil.findByC_ChiaveString(companyId, |
|
|
|
|
|
|
|
ConfigurazioneConstants.PROTOCOLLAZIONE_SERVICE_URL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Options options = new Options(); |
|
|
|
|
|
|
|
options.setLocation(url); |
|
|
|
|
|
|
|
options.setPost(post); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flexjson.JSONSerializer serialize = new flexjson.JSONSerializer(); |
|
|
|
|
|
|
|
serialize.exclude("*.class"); |
|
|
|
|
|
|
|
String protocollo = serialize.serialize(protocolloBean); |
|
|
|
|
|
|
|
Body body = new Body(protocollo, ContentTypes.APPLICATION_JSON, "UTF-8"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options.setBody(body); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return options; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<OggettoProtocollo> csvToOggettoProtocollo(java.io.File file) |
|
|
|
public static List<OggettoProtocollo> csvToOggettoProtocollo(java.io.File file) |
|
|
|
throws FileNotFoundException, IOException, ParseException { |
|
|
|
throws FileNotFoundException, IOException, ParseException { |
|
|
|
|
|
|
|
|
|
|
|