git-svn-id: https://serverad.studio-ml.local/svn/repo/projects/IntegryManagmentSystem/trunk@1659 7169d44f-50de-5945-979c-d5cbc11e8a2d
This commit is contained in:
@@ -9,7 +9,8 @@ public class Constants {
|
||||
private static final String PATH = "/";
|
||||
public static final String PATH_PROCESS_ENTITY = PATH + "processEntity";
|
||||
public static final String PATH_PROCESS_ENTITY_IMPORT = PATH + "processEntityImport";
|
||||
|
||||
public static final String PATH_SYNC_OFFLINE = PATH + "syncOffline";
|
||||
|
||||
public final static String TypeDbAny = "ANY";
|
||||
public final static String TypeDbMSSQL = "MSSQL";
|
||||
public final static String TypeDbMYSQL = "MYS";
|
||||
@@ -18,5 +19,5 @@ public class Constants {
|
||||
public static final String FORMAT_IMPORT = "format";
|
||||
|
||||
public static final String FILE_PROPS_NAME = "ems";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,19 @@ import it.integry.ems.util.EmsProperties;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -30,6 +40,11 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
@RestController
|
||||
@Scope(value="request")
|
||||
@SuppressWarnings("finally")
|
||||
@@ -48,6 +63,141 @@ public class EmsController {
|
||||
@Autowired
|
||||
private SetupGest setupGest;
|
||||
|
||||
@RequestMapping(value = Constants.PATH_SYNC_OFFLINE, method = RequestMethod.POST)
|
||||
public @ResponseBody Object syncOffile(HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
|
||||
@RequestParam(value = "publicationID") String publicationID,
|
||||
@RequestParam(value = "publicators") String publicators){
|
||||
ServiceRestResponse response = null;
|
||||
DataSource ds = new DataSource();
|
||||
Connection conn=null;
|
||||
Client client = null;
|
||||
PreparedStatement ps = null;
|
||||
PreparedStatement psUpdate = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
ds.initialize(configuration, properties.getGlobalConnectionIniPath());
|
||||
conn = ds.getConnection();
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
if("".equals(publicators)) {
|
||||
String sql = "select user_name from stb_subscriptions_user "
|
||||
+ "where publication_id = '"+publicationID+"'";
|
||||
ps = conn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
list.add(rs.getString("user_name"));
|
||||
}
|
||||
ps.close();
|
||||
rs.close();
|
||||
} else if(publicators.contains("|")) {
|
||||
list = Arrays.asList(publicators.split("|"));
|
||||
} else {
|
||||
list.add(publicators);
|
||||
}
|
||||
|
||||
for(String username : list){
|
||||
|
||||
String userSubSql = "select * from stb_subscriptions_user "
|
||||
+ "where publication_id='"+publicationID+"' and user_name='"+username+"'";
|
||||
ps = conn.prepareStatement(userSubSql);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
String transactID = rs.getString("last_transaction_id");
|
||||
String endpointUrl = "http://localhost:8080";//rs.getString("endpoint_url");
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
String tLogSql = "select * from stb_transaction_log_db "
|
||||
+ "where transaction_id > " + transactID + " order by transaction_id";
|
||||
ps = conn.prepareStatement(tLogSql);
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
String json = rs.getString("transaction_json");
|
||||
String currTransactID = rs.getString("transaction_id");
|
||||
if(json!=null){
|
||||
JsonArray array=null;
|
||||
JsonObject object=null;
|
||||
JsonParser jsonParser=new JsonParser();
|
||||
JsonElement element=jsonParser.parse(json);
|
||||
if(element.isJsonObject()){
|
||||
object = (JsonObject) element;
|
||||
}else if(element.isJsonArray()){
|
||||
array = (JsonArray) element;
|
||||
}
|
||||
|
||||
client = ClientBuilder.newClient();
|
||||
final WebTarget resource = client.target(endpointUrl)
|
||||
.path("/ems-api/processEntity");
|
||||
Response respEndpoint = resource.queryParam(CommonConstants.PROFILE_DB, username)
|
||||
.queryParam("isSync", "false").request()
|
||||
.post(Entity.json(json));
|
||||
String value = respEndpoint.readEntity(String.class);
|
||||
logger.info(respEndpoint.getStatus() + " - " + value);
|
||||
|
||||
respEndpoint.close();
|
||||
client.close();
|
||||
|
||||
JsonObject objResponse = (JsonObject) jsonParser.parse(value);
|
||||
String esito = objResponse.get("esito").getAsString();
|
||||
if("KO".equals(esito)){
|
||||
|
||||
String errorMessage = objResponse.get("errorMessage").getAsString();
|
||||
String execDate = objResponse.get("execDate").getAsString();
|
||||
|
||||
psUpdate = conn.prepareStatement("UPDATE stb_transaction_log_db "
|
||||
+ "SET esito = '"+esito+"', error_msg='"+errorMessage+"', "
|
||||
+ "exec_date = '"+execDate+"' WHERE transaction_id="+currTransactID);
|
||||
psUpdate.execute();
|
||||
conn.commit();
|
||||
conn.close();
|
||||
|
||||
psUpdate.close();
|
||||
rs.close();
|
||||
ps.close();
|
||||
return respEndpoint;
|
||||
} else if("OK".equals(esito)) {
|
||||
String execDate = objResponse.get("execDate").getAsString();
|
||||
|
||||
psUpdate = conn.prepareStatement("UPDATE stb_transaction_log_db "
|
||||
+ "SET esito = '"+esito+"', exec_date = '"+execDate +"' "
|
||||
+ "WHERE transaction_id="+currTransactID);
|
||||
psUpdate.execute();
|
||||
conn.commit();
|
||||
psUpdate.close();
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
//AGGIORNAMENTO ULTIMA TRANSAZIONE
|
||||
psUpdate = conn.prepareStatement("UPDATE stb_subscriptions_user SET last_transaction_id = last_transaction_id + 1");
|
||||
psUpdate.execute();
|
||||
psUpdate.close();
|
||||
conn.commit();
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
}
|
||||
response = new ServiceRestResponse(EsitoType.OK, null, configuration);
|
||||
ds.close();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString());
|
||||
e.printStackTrace();
|
||||
try {
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.rollback();
|
||||
conn.close();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
client.close();
|
||||
response = new ServiceRestResponse(EsitoType.KO, e.getLocalizedMessage(), null, entityProcessor.isSyncActive());
|
||||
} finally {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = Constants.PATH_PROCESS_ENTITY, method = RequestMethod.POST)
|
||||
public @ResponseBody Object processEntity(HttpServletRequest request,
|
||||
|
||||
@@ -45,105 +45,6 @@ public class OffLineSyncJob extends QuartzJobBean {
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext arg0)
|
||||
throws JobExecutionException {
|
||||
DataSource ds = new DataSource();
|
||||
Connection conn=null;
|
||||
Client client = null;
|
||||
PreparedStatement ps = null;
|
||||
PreparedStatement psUpdate = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
ds.initialize("", emsProperties.getGlobalConnectionIniPath());
|
||||
conn = ds.getConnection();
|
||||
|
||||
String username = "CEDI";
|
||||
String userSubSql = "select * from stb_subscriptions_user where user_name='"+username+"'";
|
||||
ps = conn.prepareStatement(userSubSql);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
String transactID = rs.getString("last_transaction_id");
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
String tLogSql = "select * from stb_transaction_log_db where transaction_id > " + transactID + " order by transaction_id";
|
||||
ps = conn.prepareStatement(tLogSql);
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
String json = rs.getString("transaction_json");
|
||||
String currTransactID = rs.getString("transaction_id");
|
||||
|
||||
JsonArray array=null;
|
||||
JsonObject object=null;
|
||||
JsonParser jsonParser=new JsonParser();
|
||||
JsonElement element=jsonParser.parse(json);
|
||||
if(element.isJsonObject()){
|
||||
object = (JsonObject) element;
|
||||
}else if(element.isJsonArray()){
|
||||
array = (JsonArray) element;
|
||||
}
|
||||
|
||||
client = ClientBuilder.newClient();
|
||||
final WebTarget resource = client.target("http://localhost:8080")
|
||||
.path("/ems-api/processEntity");
|
||||
Response response = resource.queryParam(CommonConstants.PROFILE_DB, username)
|
||||
.queryParam("isSync", "false").request()
|
||||
.post(Entity.text(json));
|
||||
String value = response.readEntity(String.class);
|
||||
logger.info(response.getStatus() + " - " + value);
|
||||
|
||||
response.close();
|
||||
client.close();
|
||||
|
||||
JsonObject objResponse = (JsonObject) jsonParser.parse(value);
|
||||
String esito = objResponse.get("esito").getAsString();
|
||||
if("KO".equals(esito)){
|
||||
|
||||
String errorMessage = objResponse.get("errorMessage").getAsString();
|
||||
String execDate = objResponse.get("execDate").getAsString();
|
||||
|
||||
psUpdate = conn.prepareStatement("UPDATE stb_transaction_log_db "
|
||||
+ "SET esito = '"+esito+"', error_msg='"+errorMessage+"', "
|
||||
+ "exec_date = '"+execDate+"' WHERE transaction_id="+currTransactID);
|
||||
psUpdate.execute();
|
||||
conn.commit();
|
||||
conn.close();
|
||||
|
||||
psUpdate.close();
|
||||
rs.close();
|
||||
ps.close();
|
||||
return;
|
||||
} else if("OK".equals(esito)) {
|
||||
String execDate = objResponse.get("execDate").getAsString();
|
||||
|
||||
psUpdate = conn.prepareStatement("UPDATE stb_transaction_log_db "
|
||||
+ "SET esito = '"+esito+"', exec_date = '"+execDate +"' "
|
||||
+ "WHERE transaction_id="+currTransactID);
|
||||
psUpdate.execute();
|
||||
conn.commit();
|
||||
psUpdate.close();
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
//AGGIORNAMENTO ULTIMA TRANSAZIONE
|
||||
psUpdate = conn.prepareStatement("UPDATE stb_subscriptions_user SET last_transaction_id = last_transaction_id + 1");
|
||||
psUpdate.execute();
|
||||
psUpdate.close();
|
||||
conn.commit();
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString());
|
||||
e.printStackTrace();
|
||||
try {
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.rollback();
|
||||
conn.close();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user