diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..994a4c4
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..b00bcce
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ livecareclient
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/launch4jconf.xml b/launch4jconf.xml
new file mode 100644
index 0000000..195722c
--- /dev/null
+++ b/launch4jconf.xml
@@ -0,0 +1,24 @@
+
+
+ false
+ gui
+ A:\gdrive\_PROGETTI ALTRO\POLO\LIVECARE CLIENT API\pi_livecare_client.jar
+ A:\gdrive\_PROGETTI ALTRO\POLO\LIVECARE CLIENT API\pi_livecare_client.exe
+
+
+ .
+ normal
+
+
+ false
+ false
+
+
+
+ %JAVA_HOME%;%PATH%
+ false
+ false
+
+
+
+
\ No newline at end of file
diff --git a/manifest b/manifest
new file mode 100644
index 0000000..4af1b34
--- /dev/null
+++ b/manifest
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.poloinformatico.livecareclient.PILCClienct
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..8c6d56d
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,51 @@
+
+ 4.0.0
+ pi
+ livecareclient
+ 0.0.1-SNAPSHOT
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.1.0
+
+
+
+ true
+ lib/
+ com.poloinformatico.livecareclient.PILCClienct
+
+
+
+
+
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.12.4
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.13
+
+
+
+ com.microsoft.sqlserver
+ mssql-jdbc
+ 9.2.1.jre8
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/poloinformatico/livecareclient/Db.java b/src/main/java/com/poloinformatico/livecareclient/Db.java
new file mode 100644
index 0000000..385e2d2
--- /dev/null
+++ b/src/main/java/com/poloinformatico/livecareclient/Db.java
@@ -0,0 +1,15 @@
+package com.poloinformatico.livecareclient;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class Db {
+ public static Connection getConnection() throws SQLException {
+ String url = "jdbc:sqlserver://localhost:1433;databaseName=AHR_PI;";
+ String username = "sa";
+ String password = "p0l01nf.";
+
+ return DriverManager.getConnection(url, username, password);
+ }
+}
diff --git a/src/main/java/com/poloinformatico/livecareclient/PILCClienct.java b/src/main/java/com/poloinformatico/livecareclient/PILCClienct.java
new file mode 100644
index 0000000..d503590
--- /dev/null
+++ b/src/main/java/com/poloinformatico/livecareclient/PILCClienct.java
@@ -0,0 +1,166 @@
+package com.poloinformatico.livecareclient;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Timestamp;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.poloinformatico.livecareclient.objs.Company;
+
+public class PILCClienct {
+
+ private static Connection _conn;
+
+ private static int _datediff = 0;
+
+ private static String _fileout = "pi_livecareclient.log";
+
+ private static BufferedWriter _writer;
+
+ private static Timestamp _timestamp;
+
+ public static void main(String[] args) throws Exception {
+
+ try {
+ _datediff = Integer.parseInt(args[0]) * -1;
+ } catch (Exception e) {
+ _datediff = 0;
+ }
+
+ try {
+
+ _writer = new BufferedWriter(new FileWriter(_fileout, true));
+
+ _conn = Db.getConnection();
+
+ _timestamp = new Timestamp(System.currentTimeMillis());
+
+ _writer.append(System.lineSeparator() +"______________ "+ _timestamp.toString() + " " + _datediff);
+
+ callApi();
+
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ _writer.append(e.getMessage());
+ } finally {
+ _writer.flush();
+ _writer.close();
+ if (!_conn.isClosed()) {
+ _conn.close();
+ }
+ }
+ }
+
+ public static synchronized void callApi() throws Exception {
+
+ String sql = "select ANPARIVA,AN_EMAIL,ANDESCRI,ANCODICE,case when anclacl3 like '%BM%' or anclacl3 like '%BZ%' or "
+ + "anclacl3 like '%99%' or anclacl3 like '%CONC%' or anclacl3 like '%VISUR%' or anclacl3 like '%1SL%' or "
+ + "anclacl3 like '%2SL%' or anclacl3 like '%BL%' or anclacl3 like '%CAUSA%' or anclacl3 like '%DI%' "
+ + "or anclacl3 like '%ESEC%' or anclacl3 like '%LEG%' or anclacl3 like '%PDR%' or anclacl3 like '%BV%' "
+ + "then 1 else 0 end as blocco " + "from POLOICONTI where ANTIPCON='C' and GETDATE() <= DATEDIFF(DAY,"
+ + _datediff + ",UTDV) or GETDATE() <= DATEDIFF(DAY," + _datediff + ",UTDC)";
+
+ PreparedStatement stmt = _conn.prepareStatement(sql);
+ ResultSet rs = stmt.executeQuery();
+
+ while (rs.next()) {
+
+ Company comp;
+
+ String id = rs.getString("ANCODICE").trim();
+
+ // CALL
+ HttpClient httpclient = HttpClients.createDefault();
+ HttpGet httpget = new HttpGet("https://api.livecare.net/lsws10/company/?external_id=" + id);
+ httpget.addHeader("Authorization", "Basic MTcyMjc6ZjVkNjdhYzdkOTM0N2ZkMjZiMDkzNzE3MTBkZTNk");
+
+ HttpEntity entity = httpclient.execute(httpget).getEntity();
+ String response = EntityUtils.toString(entity);
+
+ // Parse JSON
+ ObjectMapper mapper = new ObjectMapper();
+
+ JsonNode jsonNode = mapper.readTree(response);
+
+ boolean update = false;
+
+ try {
+ String stato = jsonNode.get("result_msg").asText();
+ if (stato.equals("Company not found")) {
+ update = false;
+ } else {
+ update = true;
+ }
+ } catch (Exception e) {
+ update = true;
+ }
+
+ if (update) {
+ comp = mapper.readValue(response, Company.class);
+ } else {
+ comp = new Company();
+ comp.setExternal_id(id);
+ comp.setContract_type(1);
+ }
+
+ comp.setContract_blocked(rs.getInt("blocco"));
+ comp.setCompany(rs.getString("ANDESCRI").trim());
+ comp.setEmail(rs.getString("AN_EMAIL").trim());
+ comp.setVat(rs.getString("ANPARIVA").trim());
+
+ System.out.println(comp.getCompany());
+ _writer.append(System.lineSeparator() + comp.getCompany()+" "+id);
+
+ // UPDATE/INSERT
+ try {
+ String json = mapper.writeValueAsString(comp);
+ StringEntity params = new StringEntity(json);
+
+ HttpPost post;
+ HttpPut put;
+ HttpResponse resp;
+
+ if (update) {
+ post = new HttpPost("https://api.livecare.net/lsws10/company/");
+ post.addHeader("Authorization", "Basic MTcyMjc6ZjVkNjdhYzdkOTM0N2ZkMjZiMDkzNzE3MTBkZTNk");
+ post.addHeader("content-type", "application/json");
+ post.setEntity(params);
+ resp = httpclient.execute(post);
+ } else {
+ put = new HttpPut("https://api.livecare.net/lsws10/company/");
+ put.addHeader("Authorization", "Basic MTcyMjc6ZjVkNjdhYzdkOTM0N2ZkMjZiMDkzNzE3MTBkZTNk");
+ put.addHeader("content-type", "application/json");
+ put.setEntity(params);
+ resp = httpclient.execute(put);
+ }
+
+ System.out.println(resp.getStatusLine());
+ _writer.append(System.lineSeparator() + resp.getStatusLine().toString());
+
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ _writer.append(System.lineSeparator() + e.getMessage());
+ }
+ }
+
+ // Clean up resources
+ rs.close();
+ stmt.close();
+
+ }
+}
diff --git a/src/main/java/com/poloinformatico/livecareclient/objs/Company.java b/src/main/java/com/poloinformatico/livecareclient/objs/Company.java
new file mode 100644
index 0000000..077361e
--- /dev/null
+++ b/src/main/java/com/poloinformatico/livecareclient/objs/Company.java
@@ -0,0 +1,92 @@
+package com.poloinformatico.livecareclient.objs;
+
+
+public class Company {
+
+ public Company() {
+ super();
+ }
+
+ private String external_id="";
+
+ private String company="";
+
+ private String email="";
+
+ private String vat="";
+
+ private String contract_expiration="";
+
+ private String contract_code="";
+
+ private int contract_type=0;
+
+ private int contract_blocked=0;
+
+
+ public String getExternal_id() {
+ return external_id;
+ }
+
+ public void setExternal_id(String external_id) {
+ this.external_id = external_id;
+ }
+
+ public String getCompany() {
+ return company;
+ }
+
+ public void setCompany(String company) {
+ this.company = company;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getVat() {
+ return vat;
+ }
+
+ public void setVat(String vat) {
+ this.vat = vat;
+ }
+
+ public String getContract_expiration() {
+ return contract_expiration;
+ }
+
+ public void setContract_expiration(String contract_expiration) {
+ this.contract_expiration = contract_expiration;
+ }
+
+ public String getContract_code() {
+ return contract_code;
+ }
+
+ public void setContract_code(String contract_code) {
+ this.contract_code = contract_code;
+ }
+
+ public int getContract_type() {
+ return contract_type;
+ }
+
+ public void setContract_type(int contract_type) {
+ this.contract_type = contract_type;
+ }
+
+ public int getContract_blocked() {
+ return contract_blocked;
+ }
+
+ public void setContract_blocked(int contract_blocked) {
+ this.contract_blocked = contract_blocked;
+ }
+
+
+}