Implementati servizi di import delle transazioni partendo da una subscription
This commit is contained in:
@@ -359,7 +359,7 @@ public class WooCommerceArticoliDataManager {
|
||||
" where cod_mdep = dbo.getGestSetup('WOOCOMMERCE','SETUP','COD_MDEP')";
|
||||
|
||||
if (codMarts != null && codMarts.size() > 0) {
|
||||
sql += " AND lisv.cod_mart IN (" + UtilityQuery.concatFieldsWithSeparator(codMarts, ",") + ")";
|
||||
sql += " AND lisv.cod_mart IN (" + UtilityQuery.concatStringFieldsWithSeparator(codMarts, ",") + ")";
|
||||
}
|
||||
|
||||
PreparedStatement info = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package it.integry.ems.async.controller;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.async.service.AsyncServiceNew;
|
||||
import it.integry.ems.controller.EmsController;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.response.StatusResponse;
|
||||
import it.integry.ems.status.ServiceChecker;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Scope("request")
|
||||
@RequestMapping(EmsRestConstants.PATH_ASYNC_BASE_ROUTE)
|
||||
public class AsyncControllerNew {
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
|
||||
@Autowired
|
||||
private ServiceChecker serviceChecker;
|
||||
|
||||
@Autowired
|
||||
private AsyncServiceNew asyncServiceNew;
|
||||
|
||||
@RequestMapping(value = "/status", method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
List<StatusResponse> status(HttpServletRequest request) {
|
||||
Method[] methods = EmsController.class.getDeclaredMethods();
|
||||
return serviceChecker.getServiceStatus(methods, EmsController.class);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_ASYNC_START, method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse start(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
|
||||
@RequestParam String subscriptionName
|
||||
) throws Exception {
|
||||
asyncServiceNew.startSync(subscriptionName);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_ASYNC_RETRIEVE_TRANSACTIONS, method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse retrieveTransactions(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
|
||||
@RequestParam(value = "limit", required = false, defaultValue = "1") Integer limit
|
||||
) throws Exception {
|
||||
return ServiceRestResponse.createPositiveResponse(asyncServiceNew.retrieveTransactions(limit));
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_ASYNC_UPDATE_TRANSACTION_IMPORT_ID, method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse updateTransactionImportID(HttpServletRequest request,
|
||||
@RequestParam Integer transactionImportID,
|
||||
@RequestParam String sender,
|
||||
@RequestParam String publicationID) throws Exception {
|
||||
|
||||
asyncServiceNew.updateTransactionImportCounterInDB(transactionImportID, publicationID, sender);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package it.integry.ems.async.dto;
|
||||
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
|
||||
public class SubscriptionDTO {
|
||||
|
||||
private String publicationId;
|
||||
private int lastTransactionIDImport = 0;
|
||||
private String entityName = null;
|
||||
private String whereCond = null;
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
|
||||
public String getPublicationId() {
|
||||
return publicationId;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setPublicationId(String publicationId) {
|
||||
this.publicationId = publicationId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getLastTransactionIDImport() {
|
||||
return lastTransactionIDImport;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setLastTransactionIDImport(int lastTransactionIDImport) {
|
||||
this.lastTransactionIDImport = lastTransactionIDImport;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
return entityName;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setEntityName(String entityName) {
|
||||
this.entityName = entityName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getWhereCond() {
|
||||
return whereCond;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setWhereCond(String whereCond) {
|
||||
this.whereCond = whereCond;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiDBTransactionManager getMultiDBTransactionManager() {
|
||||
return multiDBTransactionManager;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setMultiDBTransactionManager(MultiDBTransactionManager multiDBTransactionManager) {
|
||||
this.multiDBTransactionManager = multiDBTransactionManager;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package it.integry.ems.async.dto;
|
||||
|
||||
public class SyncConfigDTO
|
||||
{
|
||||
private String endpoint;
|
||||
private String profileDb;
|
||||
private String username;
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
public SyncConfigDTO setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getProfileDb() {
|
||||
return profileDb;
|
||||
}
|
||||
|
||||
public SyncConfigDTO setProfileDb(String profileDb) {
|
||||
this.profileDb = profileDb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public SyncConfigDTO setUsername(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,340 +0,0 @@
|
||||
package it.integry.ems.async.service;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.async.dto.SubscriptionDTO;
|
||||
import it.integry.ems.async.dto.SyncConfigDTO;
|
||||
import it.integry.ems.async.dto.TransactionDTO;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.json.JSONObjectMapper;
|
||||
import it.integry.ems.response.EsitoType;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.HttpRestWrapper;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
import it.integry.ems_model.resolver.EntitySubTypeHolder;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityHashMap;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.josql.Query;
|
||||
import org.josql.QueryResults;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Scope("request")
|
||||
public class AsyncServiceNew {
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
|
||||
@Autowired
|
||||
private JSONObjectMapper jsonObjectMapper;
|
||||
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
|
||||
@Autowired
|
||||
private EntityProcessor entityProcessor;
|
||||
|
||||
@Autowired
|
||||
private RequestDataDTO requestData;
|
||||
|
||||
|
||||
@Autowired
|
||||
private SetupGest setupGest;
|
||||
|
||||
|
||||
|
||||
|
||||
public void startSync(String subscriptionName) throws Exception {
|
||||
|
||||
String jsonConfigurationString = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "SINCRONIZZAZIONI_OFFLINE", "SETUP", subscriptionName);
|
||||
|
||||
if(UtilityString.isNullOrEmpty(jsonConfigurationString))
|
||||
throw new Exception("Nessuna configurazione trovata per la sincronizzazione: " + subscriptionName);
|
||||
|
||||
final List<SyncConfigDTO> syncConfigs = jsonObjectMapper.readValue(jsonConfigurationString, new TypeReference<List<SyncConfigDTO>>() {
|
||||
});
|
||||
|
||||
for (SyncConfigDTO syncConfig : syncConfigs) {
|
||||
String wsUrlEndpoint = syncConfig.getEndpoint() + EmsRestConstants.PATH_ASYNC_BASE_ROUTE + EmsRestConstants.PATH_ASYNC_RETRIEVE_TRANSACTIONS;
|
||||
|
||||
HashMap<String, String> queryParams = new HashMap<>();
|
||||
queryParams.put("profileDb", syncConfig.getProfileDb());
|
||||
|
||||
boolean shouldStop = false;
|
||||
|
||||
int importedTransactionsCounter = 0;
|
||||
|
||||
do {
|
||||
|
||||
StringBuilder responseBody = new StringBuilder();
|
||||
int status = HttpRestWrapper.callGenericGet(wsUrlEndpoint, syncConfig.getUsername(), syncConfig.getUsername(), responseBody, queryParams);
|
||||
|
||||
if (status != 200)
|
||||
throw new Exception("La richiesta \"" + wsUrlEndpoint + "\" ha generato status code: " + status + "<br />Body: " + responseBody);
|
||||
|
||||
ServiceRestResponse response = jsonObjectMapper.readValue(responseBody.toString(), ServiceRestResponse.class);
|
||||
|
||||
if (response.getEsito() == EsitoType.OK) {
|
||||
StringWriter writer = new StringWriter();
|
||||
jsonObjectMapper.writeValue(writer, response.getJsonObject());
|
||||
String dtoJson = writer.toString();
|
||||
|
||||
List<List<TransactionDTO>> transactions = jsonObjectMapper.readValue(dtoJson, new TypeReference<List<List<TransactionDTO>>>() {
|
||||
});
|
||||
|
||||
if (transactions.isEmpty() || transactions.get(0).isEmpty()) {
|
||||
if (importedTransactionsCounter == 0) logger.debug("Nessuna entity da sincronizzare");
|
||||
else logger.debug("Sincronizzazione OFFLINE terminata");
|
||||
shouldStop = true;
|
||||
} else {
|
||||
importedTransactionsCounter +=
|
||||
importTransactions(syncConfig.getEndpoint(), syncConfig.getProfileDb(), syncConfig.getUsername(), transactions);
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Exception("La richiesta \"" + wsUrlEndpoint + "\" ha generato un ESITO KO<br />Body: " + responseBody);
|
||||
}
|
||||
|
||||
} while (!shouldStop);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private int importTransactions(@NotNull String hostEndpoint, @NotNull String profileDb, @NotNull String username, @NotNull List<List<TransactionDTO>> transactionList) throws Exception {
|
||||
|
||||
int importedEntityCounter = 0;
|
||||
|
||||
|
||||
for (List<TransactionDTO> transactionDTOS : transactionList) {
|
||||
final List<Integer> transactionsIDGroups = new ArrayList<>();
|
||||
|
||||
for (TransactionDTO dto : transactionDTOS) {
|
||||
if (!transactionsIDGroups.contains(dto.getTransactionGroupId()))
|
||||
transactionsIDGroups.add(dto.getTransactionGroupId());
|
||||
}
|
||||
|
||||
//Per ogni transaction group trovato mi prendo tutte le transactions
|
||||
for (int j = 0; j < transactionsIDGroups.size(); j++) {
|
||||
final int finalJ = j;
|
||||
List<TransactionDTO> transactionsToImport = Stream.of(transactionDTOS)
|
||||
.filter(transactionDTO -> transactionDTO.getTransactionGroupId() == transactionsIDGroups.get(finalJ))
|
||||
.toList();
|
||||
|
||||
List<EntityBase> entitiesToImport = new ArrayList<EntityBase>();
|
||||
|
||||
for (TransactionDTO transaction : transactionsToImport) {
|
||||
EntityBase entity = jsonObjectMapper.readValue(transaction.getTransactionJson(), EntityBase.class);
|
||||
entitiesToImport.add(entity);
|
||||
}
|
||||
|
||||
|
||||
entityProcessor.processEntityList(null, false, true, false, entitiesToImport);
|
||||
|
||||
for (EntityBase importedEntity : entitiesToImport) {
|
||||
if (importedEntity.getException() != null) {
|
||||
throw importedEntity.getException();
|
||||
}
|
||||
}
|
||||
|
||||
importedEntityCounter += entitiesToImport.size();
|
||||
|
||||
updateTransactionImportCounterInRemote(hostEndpoint, profileDb, username, transactionsToImport);
|
||||
}
|
||||
}
|
||||
|
||||
return importedEntityCounter;
|
||||
|
||||
}
|
||||
|
||||
public List<List<TransactionDTO>> retrieveTransactions(int limit) throws Exception {
|
||||
String username = requestData.getUsername();
|
||||
|
||||
String sqlCheckActiveSubscriptions = "SELECT * " +
|
||||
" FROM stb_subscriptions_user " +
|
||||
" LEFT OUTER JOIN stb_subscriptions_user_detail ssud" +
|
||||
" on stb_subscriptions_user.publication_id = ssud.publication_id and" +
|
||||
" stb_subscriptions_user.user_name = ssud.user_name" +
|
||||
" WHERE stb_subscriptions_user.user_name = " + UtilityDB.valueToString(username) +
|
||||
" AND flag_attivo = 'S'";
|
||||
|
||||
|
||||
List<SubscriptionDTO> activeSubscriptions = new ArrayList<>();
|
||||
|
||||
//Lettura di tutte le sottoscrizioni attive (di tutte le entity)
|
||||
List<HashMap<String, Object>> result = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sqlCheckActiveSubscriptions);
|
||||
|
||||
if (!result.isEmpty()) {
|
||||
for (HashMap<String, Object> stringObjectHashMap : result) {
|
||||
activeSubscriptions.add(new SubscriptionDTO()
|
||||
.setPublicationId(UtilityHashMap.<String>getValueIfExists(stringObjectHashMap, "publication_id"))
|
||||
.setLastTransactionIDImport(UtilityHashMap.<Integer>getValueIfExists(stringObjectHashMap, "last_transaction_id_import"))
|
||||
.setEntityName(UtilityHashMap.<String>getValueIfExists(stringObjectHashMap, "entity_name"))
|
||||
.setWhereCond(UtilityHashMap.<String>getValueIfExists(stringObjectHashMap, "where_cond_sql")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Estraggo le transazione in base alle sottoscrizioni attive
|
||||
return getTransactionsFromSubscriptions(activeSubscriptions, limit);
|
||||
}
|
||||
|
||||
private List<List<TransactionDTO>> getTransactionsFromSubscriptions(List<SubscriptionDTO> subscriptionList, int limit) throws Exception {
|
||||
List<List<TransactionDTO>> groupOfTransactionsToBeExecuted = new ArrayList<>();
|
||||
|
||||
int totalTransactionsCounter = 0;
|
||||
|
||||
for (SubscriptionDTO subscriptionDTO : subscriptionList) {
|
||||
if (totalTransactionsCounter >= limit) break;
|
||||
|
||||
String sqlToRetrieveMaxGroupTransactionId = "SELECT min(transaction_group_id) as min_group, max(transaction_group_id) as max_group " +
|
||||
"FROM stb_transaction_log_db " +
|
||||
"WHERE transaction_id > " + UtilityDB.valueToString(subscriptionDTO.getLastTransactionIDImport()) + " AND " +
|
||||
"entity_name_list = " + UtilityDB.valueToString(subscriptionDTO.getEntityName());
|
||||
|
||||
HashMap<String, Object> transactionGroupsResult = UtilityDB.executeSimpleQueryOnlyFirstRow(multiDBTransactionManager.getPrimaryConnection(), sqlToRetrieveMaxGroupTransactionId);
|
||||
|
||||
if (transactionGroupsResult == null) continue;
|
||||
|
||||
Integer minTransactionGroupId = UtilityHashMap.getValueIfExists(transactionGroupsResult, "min_group");
|
||||
Integer maxTransactionGroupId = UtilityHashMap.getValueIfExists(transactionGroupsResult, "max_group");
|
||||
|
||||
if (minTransactionGroupId == null || maxTransactionGroupId == null) continue;
|
||||
|
||||
List<TransactionDTO> transactionsToBeProcessed = new ArrayList<>();
|
||||
|
||||
for (int i = minTransactionGroupId; i <= maxTransactionGroupId; i++) {
|
||||
if (totalTransactionsCounter >= limit) break;
|
||||
|
||||
String sqlToRetrieveTransactions = "SELECT * " +
|
||||
"FROM stb_transaction_log_db " +
|
||||
"WHERE transaction_group_id = " + UtilityDB.valueToString(i) + " AND " +
|
||||
"entity_name_list = " + UtilityDB.valueToString(subscriptionDTO.getEntityName()) + " " +
|
||||
"ORDER BY transaction_id";
|
||||
|
||||
List<HashMap<String, Object>> results = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sqlToRetrieveTransactions);
|
||||
|
||||
boolean shouldAdd = true;
|
||||
|
||||
for (HashMap<String, Object> result : results) {
|
||||
TransactionDTO transaction = new TransactionDTO()
|
||||
.setPublicationId(subscriptionDTO.getPublicationId())
|
||||
.setEntityName(UtilityHashMap.<String>getValueIfExists(result, "entity_name_list"))
|
||||
//.setErrorMsg(UtilityHashMap.<String>getValueIfExists(result, "error_msg"))
|
||||
//.setEsito(UtilityHashMap.<String>getValueIfExists(result, "esito"))
|
||||
//.setExecDate(UtilityHashMap.<Date>getValueIfExists(result, "exec_date"))
|
||||
.setTransactionDate(UtilityHashMap.<Date>getValueIfExists(result, "transaction_date"))
|
||||
.setTransactionGroupId(UtilityHashMap.<Integer>getValueIfExists(result, "transaction_group_id"))
|
||||
.setTransactionId(UtilityHashMap.<Integer>getValueIfExists(result, "transaction_id"))
|
||||
.setTransactionJson(UtilityHashMap.<String>getValueIfExists(result, "transaction_json"))
|
||||
.setUsername(UtilityHashMap.<String>getValueIfExists(result, "user_name"));
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(subscriptionDTO.getWhereCond())) {
|
||||
Class<? extends EntityBase> entityClass = UtilityHashMap.getValueIfExists(EntitySubTypeHolder.getMapType(), subscriptionDTO.getEntityName().toLowerCase());
|
||||
|
||||
EntityBase entity = jsonObjectMapper.readValue(transaction.getTransactionJson(), EntityBase.class);
|
||||
|
||||
List<EntityBase> tmpList = new ArrayList<>();
|
||||
tmpList.add(entity);
|
||||
|
||||
String selectSql = "SELECT * FROM " + entityClass.getCanonicalName() + " WHERE " + subscriptionDTO.getWhereCond();
|
||||
|
||||
// Create a new Query.
|
||||
Query q = new Query();
|
||||
q.parse(selectSql);
|
||||
|
||||
QueryResults qr = q.execute(tmpList);
|
||||
tmpList = qr.getResults();
|
||||
|
||||
if (tmpList.size() == 0) {
|
||||
shouldAdd = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldAdd) {
|
||||
transactionsToBeProcessed.add(transaction);
|
||||
totalTransactionsCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (transactionsToBeProcessed.size() > 0) groupOfTransactionsToBeExecuted.add(transactionsToBeProcessed);
|
||||
|
||||
}
|
||||
|
||||
return groupOfTransactionsToBeExecuted;
|
||||
}
|
||||
|
||||
|
||||
public void updateTransactionImportCounterInDB(int lastTransactionId, String publicationID, String username) throws Exception {
|
||||
String sql = "UPDATE stb_subscriptions_user " +
|
||||
"SET last_transaction_id_import = " + lastTransactionId + " " +
|
||||
"WHERE publication_id = " + UtilityDB.valueToString(publicationID) + " " +
|
||||
"AND user_name = " + UtilityDB.valueToString(username);
|
||||
|
||||
PreparedStatement psUpdate = multiDBTransactionManager.prepareStatement(sql);
|
||||
psUpdate.executeUpdate();
|
||||
multiDBTransactionManager.commitAll();
|
||||
psUpdate.close();
|
||||
}
|
||||
|
||||
private void updateTransactionImportCounterInRemote(String hostEndpoint, String profileDb, String username, List<TransactionDTO> importedTransactions) throws Exception {
|
||||
StringBuilder responseBody;
|
||||
String wsUrlEndpoint = hostEndpoint + EmsRestConstants.PATH_ASYNC_BASE_ROUTE + EmsRestConstants.PATH_ASYNC_UPDATE_TRANSACTION_IMPORT_ID;
|
||||
|
||||
List<String> publicationIDs = Stream.of(importedTransactions)
|
||||
.map(transactionDTO -> transactionDTO.getPublicationId())
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
|
||||
List<TransactionDTO> maxOfTransactionsIDList = new ArrayList<>();
|
||||
for (final String publicationId : publicationIDs) {
|
||||
maxOfTransactionsIDList.add(Stream.of(importedTransactions)
|
||||
.filter(transactionDTO -> transactionDTO.getPublicationId().equalsIgnoreCase(publicationId))
|
||||
.max((o1, o2) -> o1.getTransactionId() - o2.getTransactionId()).get());
|
||||
}
|
||||
|
||||
for (TransactionDTO transactionDTO : maxOfTransactionsIDList) {
|
||||
int status;
|
||||
int retryCounter = 0;
|
||||
do {
|
||||
HashMap<String, String> queryParams = new HashMap<>();
|
||||
queryParams.put(CommonConstants.PROFILE_DB, profileDb);
|
||||
queryParams.put("publicationID", transactionDTO.getPublicationId());
|
||||
queryParams.put("sender", username);
|
||||
queryParams.put("transactionImportID", "" + transactionDTO.getTransactionId());
|
||||
|
||||
responseBody = new StringBuilder();
|
||||
status = HttpRestWrapper.callGenericGet(wsUrlEndpoint, username, username, responseBody, queryParams);
|
||||
|
||||
retryCounter++;
|
||||
} while (status != 200 && retryCounter < 4);
|
||||
|
||||
if (retryCounter == 4) {
|
||||
throw new Exception("La richiesta \"" + wsUrlEndpoint + "\" ha generato un ESITO KO<br />Body: " + responseBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20240228160024 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
dropTable(advancedDataSource.getConnection(), "stb_subscriptions_user_detail");
|
||||
dropTable(advancedDataSource.getConnection(), "stb_subscriptions_user");
|
||||
|
||||
executeStatement(advancedDataSource.getConnection(),
|
||||
|
||||
"CREATE TABLE dbo.stb_remote_subscription\n" +
|
||||
"(\n" +
|
||||
" id BIGINT IDENTITY\n" +
|
||||
" CONSTRAINT stb_remote_subscription_pk\n" +
|
||||
" PRIMARY KEY,\n" +
|
||||
" publication_id BIGINT NOT NULL,\n" +
|
||||
" publication_description VARCHAR(MAX),\n" +
|
||||
" endpoint_protocol VARCHAR(5) DEFAULT 'HTTP' NOT NULL,\n" +
|
||||
" endpoint_host VARCHAR(MAX) NOT NULL,\n" +
|
||||
" endpoint_port INT DEFAULT 80 NOT NULL,\n" +
|
||||
" username VARCHAR(MAX) NOT NULL,\n" +
|
||||
" password VARCHAR(MAX) NOT NULL,\n" +
|
||||
" profile_db VARCHAR(MAX) NOT NULL,\n" +
|
||||
" last_transaction_id BIGINT,\n" +
|
||||
" last_transaction_id_imported BIGINT,\n" +
|
||||
" active BIT DEFAULT 0 NOT NULL\n" +
|
||||
")",
|
||||
|
||||
"EXEC sp_addextendedproperty 'MS_Description', 'HTTP or HTTPS', 'SCHEMA', 'dbo', 'TABLE', 'stb_remote_subscription',\n" +
|
||||
" 'COLUMN', 'endpoint_protocol'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class EntityProcessor {
|
||||
username = requestDataDTO.getUsername();
|
||||
}
|
||||
|
||||
return (T) processEntity(entity, true, false, username, multiDBTransactionManager, true);
|
||||
return (T) processEntity(entity, true, false, username, multiDBTransactionManager, true, false);
|
||||
}
|
||||
|
||||
public EntityBase processEntity(EntityInterface entity, boolean skipCommit, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||
@@ -101,13 +101,20 @@ public class EntityProcessor {
|
||||
username = requestDataDTO.getUsername();
|
||||
}
|
||||
|
||||
return (EntityBase) processEntity(entity, true, skipCommit, username, multiDBTransactionManager, true);
|
||||
return (EntityBase) processEntity(entity, true, skipCommit, username, multiDBTransactionManager, true, false);
|
||||
}
|
||||
|
||||
public EntityBase processEntity(EntityInterface entity, Boolean isSync,
|
||||
boolean skipCommit, String username,
|
||||
MultiDBTransactionManager mdb) throws Exception {
|
||||
return (EntityBase) processEntity(entity, true, skipCommit, username, mdb, true);
|
||||
return (EntityBase) processEntity(entity, isSync, skipCommit, username, mdb, true, false);
|
||||
}
|
||||
|
||||
public Object processEntity(EntityInterface entity, Boolean isSync,
|
||||
boolean skipCommit, String username,
|
||||
MultiDBTransactionManager mdb,
|
||||
boolean completeEntity) throws Exception {
|
||||
return processEntity(entity, isSync, skipCommit, username, mdb, completeEntity, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +132,7 @@ public class EntityProcessor {
|
||||
public Object processEntity(EntityInterface entity, Boolean isSync,
|
||||
boolean skipCommit, String username,
|
||||
MultiDBTransactionManager mdb,
|
||||
boolean completeEntity) throws Exception {
|
||||
boolean completeEntity, boolean overrideEntityChildCheck) throws Exception {
|
||||
|
||||
try {
|
||||
entity.setEntityHolder(entityPropertyHolder);
|
||||
@@ -137,7 +144,7 @@ public class EntityProcessor {
|
||||
entity.setOperation(OperationType.NO_OP);
|
||||
}
|
||||
|
||||
this.checkEntityChildsUsage(entity, mdb);
|
||||
if (!overrideEntityChildCheck) this.checkEntityChildsUsage(entity, mdb);
|
||||
|
||||
if (settingsModel.isEnablePermissionCheck() && !checkUserPermissions(entity))
|
||||
throw new InvalidPermissionsException();
|
||||
@@ -453,26 +460,21 @@ public class EntityProcessor {
|
||||
|
||||
|
||||
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, boolean singleTransaction) throws Exception {
|
||||
return processEntityList(null, true, singleTransaction, false, entities);
|
||||
return processEntityList(entities, null, true, singleTransaction, false, mDbTransactManager, true, false);
|
||||
}
|
||||
|
||||
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, MultiDBTransactionManager multiDBTransactionManager, boolean singleTransaction) throws Exception {
|
||||
return processEntityList(null, true, singleTransaction, false, entities, multiDBTransactionManager);
|
||||
return processEntityList(entities, null, true, singleTransaction, false, multiDBTransactionManager, true, false);
|
||||
}
|
||||
|
||||
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, boolean isSync, boolean singleTransaction, boolean ordinaSuPriorita) throws Exception {
|
||||
return processEntityList(null, isSync, singleTransaction, ordinaSuPriorita, entities);
|
||||
return processEntityList(entities, null, isSync, singleTransaction, ordinaSuPriorita, mDbTransactManager, true, false);
|
||||
}
|
||||
|
||||
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, String username, boolean isSync, boolean singleTransaction, boolean ordinaSuPriorita) throws Exception {
|
||||
return processEntityList(username, isSync, singleTransaction, ordinaSuPriorita, entities);
|
||||
return processEntityList(entities, username, isSync, singleTransaction, ordinaSuPriorita, mDbTransactManager, true, false);
|
||||
}
|
||||
|
||||
public List<EntityBase> processEntityList(String username, boolean isSync, boolean singleTransaction, boolean ordinaSuPriorita, List<? extends EntityBase> entities) throws Exception {
|
||||
return processEntityList(username, isSync, singleTransaction, ordinaSuPriorita, entities, mDbTransactManager);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Entity List Processor
|
||||
*
|
||||
@@ -485,7 +487,12 @@ public class EntityProcessor {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<EntityBase> processEntityList(String username, boolean isSync, boolean singleTransaction, boolean ordinaSuPriorita, List<? extends EntityBase> entities, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, String username,
|
||||
boolean isSync,
|
||||
boolean singleTransaction,
|
||||
boolean ordinaSuPriorita,
|
||||
MultiDBTransactionManager multiDBTransactionManager,
|
||||
boolean completeEntity, boolean overrideEntityChildCheck) throws Exception {
|
||||
|
||||
if (UtilityString.isNullOrEmpty(username) && requestDataDTO != null && requestDataDTO.isValidUsername()) {
|
||||
username = requestDataDTO.getUsername();
|
||||
@@ -504,7 +511,7 @@ public class EntityProcessor {
|
||||
EntityBase entity = entities.get(i);
|
||||
entity.setTransactionGroupId(prevTransactionGroupId);
|
||||
try {
|
||||
EntityBase entityResult = (EntityBase) this.processEntity(entity, isSync, singleTransaction, username, multiDBTransactionManager, true);
|
||||
EntityBase entityResult = (EntityBase) this.processEntity(entity, isSync, singleTransaction, username, multiDBTransactionManager, completeEntity, overrideEntityChildCheck);
|
||||
prevTransactionGroupId = entity.getTransactionGroupId();
|
||||
if (entityResult != null) {
|
||||
entityList.add(entityResult);
|
||||
|
||||
@@ -28,4 +28,12 @@ public class RemoteSynchronizationController {
|
||||
return ServiceRestResponse.createPositiveResponse(remoteSynchronizationService.getPublicationStatus());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "subscription/{subscriptionId}/run", method = RequestMethod.GET)
|
||||
public ServiceRestResponse runSubscription(@PathVariable long subscriptionId) throws Exception {
|
||||
remoteSynchronizationService.runSubscription(subscriptionId);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package it.integry.ems.sync.controller;
|
||||
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.sync.dto.InsertPublicationGroupRequestDTO;
|
||||
import it.integry.ems.sync.dto.InsertPublicationItemResponseDTO;
|
||||
import it.integry.ems.sync.dto.PublicationDTO;
|
||||
import it.integry.ems.sync.dto.*;
|
||||
import it.integry.ems.sync.service.RemoteSynchronizationSetupService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -62,4 +60,14 @@ public class RemoteSynchronizationSetupController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "subscriptions/insert", method = RequestMethod.POST)
|
||||
public ServiceRestResponse insertSubscription(@RequestBody SubscriptionDTO subscriptionToInsert) throws Exception {
|
||||
InsertSubscriptionResponseDTO response = new InsertSubscriptionResponseDTO()
|
||||
.setId(remoteSynchronizationSetupService.addSubscription(subscriptionToInsert));
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package it.integry.ems.sync.controller;
|
||||
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.sync.service.RemoteSynchronizationTransactionsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@Scope("request")
|
||||
@RequestMapping("system/remote-transaction")
|
||||
public class RemoteSynchronizationTransactionsController {
|
||||
|
||||
@Autowired
|
||||
private RemoteSynchronizationTransactionsService remoteSynchronizationTransactionsService;
|
||||
|
||||
|
||||
@RequestMapping(value = "{publicationId}/retrieve", method = RequestMethod.GET)
|
||||
public ServiceRestResponse retrieve(@PathVariable long publicationId,
|
||||
@RequestParam(required = false) Long lastRetrievedTransactionId,
|
||||
@RequestParam(required = false, defaultValue = "-1") int limit) throws Exception {
|
||||
return ServiceRestResponse.createPositiveResponse(
|
||||
remoteSynchronizationTransactionsService.retrieveTransactions(publicationId, lastRetrievedTransactionId, limit));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package it.integry.ems.sync.dto;
|
||||
|
||||
public class InsertSubscriptionResponseDTO {
|
||||
|
||||
private long id;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public InsertSubscriptionResponseDTO setId(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package it.integry.ems.sync.dto;
|
||||
|
||||
import it.integry.ems_model.entity.StbRemoteSubscription;
|
||||
|
||||
public class SubscriptionDTO {
|
||||
|
||||
private Long id;
|
||||
private long publicationId;
|
||||
private String publicationDescription;
|
||||
private String endpointProtocol;
|
||||
private String endpointHost;
|
||||
private int endpointPort;
|
||||
private String username;
|
||||
private String password;
|
||||
private String profileDb;
|
||||
private boolean active;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setId(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getPublicationId() {
|
||||
return publicationId;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setPublicationId(long publicationId) {
|
||||
this.publicationId = publicationId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPublicationDescription() {
|
||||
return publicationDescription;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setPublicationDescription(String publicationDescription) {
|
||||
this.publicationDescription = publicationDescription;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEndpointProtocol() {
|
||||
return endpointProtocol;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setEndpointProtocol(String endpointProtocol) {
|
||||
this.endpointProtocol = endpointProtocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEndpointHost() {
|
||||
return endpointHost;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setEndpointHost(String endpointHost) {
|
||||
this.endpointHost = endpointHost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getEndpointPort() {
|
||||
return endpointPort;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setEndpointPort(int endpointPort) {
|
||||
this.endpointPort = endpointPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setUsername(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setPassword(String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getProfileDb() {
|
||||
return profileDb;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setProfileDb(String profileDb) {
|
||||
this.profileDb = profileDb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public SubscriptionDTO setActive(boolean active) {
|
||||
this.active = active;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getEndpointUrl() {
|
||||
return endpointProtocol.toLowerCase() + "://" + endpointHost + ":" + endpointPort;
|
||||
}
|
||||
|
||||
|
||||
public static SubscriptionDTO fromEntity(StbRemoteSubscription stbRemoteSubscription) {
|
||||
return new SubscriptionDTO()
|
||||
.setId(stbRemoteSubscription.getId())
|
||||
.setPublicationId(stbRemoteSubscription.getPublicationId())
|
||||
.setPublicationDescription(stbRemoteSubscription.getPublicationDescription())
|
||||
.setEndpointProtocol(stbRemoteSubscription.getEndpointProtocol())
|
||||
.setEndpointHost(stbRemoteSubscription.getEndpointHost())
|
||||
.setEndpointPort(stbRemoteSubscription.getEndpointPort())
|
||||
.setUsername(stbRemoteSubscription.getUsername())
|
||||
.setPassword(stbRemoteSubscription.getPassword())
|
||||
.setProfileDb(stbRemoteSubscription.getProfileDb())
|
||||
.setActive(stbRemoteSubscription.isActive());
|
||||
}
|
||||
|
||||
public StbRemoteSubscription toEntity() {
|
||||
return new StbRemoteSubscription()
|
||||
.setPublicationId(getPublicationId())
|
||||
.setPublicationDescription(getPublicationDescription())
|
||||
.setEndpointProtocol(getEndpointProtocol())
|
||||
.setEndpointHost(getEndpointHost())
|
||||
.setEndpointPort(getEndpointPort())
|
||||
.setProfileDb(getProfileDb())
|
||||
.setUsernameField(getUsername())
|
||||
.setPassword(getPassword())
|
||||
.setActive(isActive());
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,39 @@
|
||||
package it.integry.ems.async.dto;
|
||||
package it.integry.ems.sync.dto;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class TransactionDTO {
|
||||
|
||||
private String publicationId;
|
||||
private int transactionId;
|
||||
private Date transactionDate;
|
||||
private long publicationId;
|
||||
private long transactionId;
|
||||
private LocalDateTime transactionDate;
|
||||
private String username;
|
||||
private String entityName;
|
||||
private String transactionJson;
|
||||
private int transactionGroupId;
|
||||
|
||||
public String getPublicationId() {
|
||||
public long getPublicationId() {
|
||||
return publicationId;
|
||||
}
|
||||
|
||||
public TransactionDTO setPublicationId(String publicationId) {
|
||||
public TransactionDTO setPublicationId(long publicationId) {
|
||||
this.publicationId = publicationId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getTransactionId() {
|
||||
public long getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
public TransactionDTO setTransactionId(int transactionId) {
|
||||
public TransactionDTO setTransactionId(long transactionId) {
|
||||
this.transactionId = transactionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getTransactionDate() {
|
||||
public LocalDateTime getTransactionDate() {
|
||||
return transactionDate;
|
||||
}
|
||||
|
||||
public TransactionDTO setTransactionDate(Date transactionDate) {
|
||||
public TransactionDTO setTransactionDate(LocalDateTime transactionDate) {
|
||||
this.transactionDate = transactionDate;
|
||||
return this;
|
||||
}
|
||||
@@ -65,13 +64,4 @@ public class TransactionDTO {
|
||||
this.transactionJson = transactionJson;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getTransactionGroupId() {
|
||||
return transactionGroupId;
|
||||
}
|
||||
|
||||
public TransactionDTO setTransactionGroupId(int transactionGroupId) {
|
||||
this.transactionGroupId = transactionGroupId;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package it.integry.ems.sync.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TransactionGroupDTO {
|
||||
|
||||
private long id;
|
||||
|
||||
private List<TransactionDTO> items;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public TransactionGroupDTO setId(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<TransactionDTO> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public TransactionGroupDTO setItems(List<TransactionDTO> items) {
|
||||
this.items = items;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,23 @@
|
||||
package it.integry.ems.sync.service;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import it.integry.ems.json.JSONObjectMapper;
|
||||
import it.integry.ems.response.EsitoType;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.HttpRestWrapper;
|
||||
import it.integry.ems.sync.AsyncHistoryManager;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.sync.dto.ExportHistoryStatusDTO;
|
||||
import it.integry.ems.sync.dto.PublicationDTO;
|
||||
import it.integry.ems.sync.dto.TransactionDTO;
|
||||
import it.integry.ems.sync.dto.TransactionGroupDTO;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EntityPropertyHolder;
|
||||
import it.integry.ems_model.entity.StbPublicationsDetail;
|
||||
import it.integry.ems_model.entity.StbRemoteSubscription;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -15,6 +26,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -35,12 +48,15 @@ public class RemoteSynchronizationService {
|
||||
@Autowired
|
||||
private EntityProcessor entityProcessor;
|
||||
|
||||
@Autowired
|
||||
private JSONObjectMapper jsonObjectMapper;
|
||||
|
||||
public void startPublication(long groupId) throws Exception {
|
||||
String sql = Query.format("SELECT * FROM " + StbPublicationsDetail.ENTITY + " WHERE stb_publication_id = %s AND export_history = %s AND ready_to_transmit = 0", groupId, 1);
|
||||
|
||||
final List<StbPublicationsDetail> stbPublicationsDetails = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, StbPublicationsDetail.class);
|
||||
|
||||
if(stbPublicationsDetails == null)
|
||||
if (stbPublicationsDetails == null)
|
||||
throw new Exception("Non è stata trovata alcuna pubblicazione da poter avviare (ID: " + groupId + ")");
|
||||
|
||||
for (StbPublicationsDetail stbPublicationsDetail : stbPublicationsDetails) {
|
||||
@@ -51,17 +67,98 @@ public class RemoteSynchronizationService {
|
||||
}
|
||||
|
||||
public List<ExportHistoryStatusDTO> getPublicationStatus() {
|
||||
// int totalCount = new Random().nextInt(1000000);
|
||||
// int currentCount = new Random().nextInt(totalCount);
|
||||
//
|
||||
// return Collections.singletonList(new ExportHistoryStatusDTO()
|
||||
// .setPublicationGroupId(1)
|
||||
// .setProcessedCount(currentCount)
|
||||
// .setTotalCount(totalCount)
|
||||
// .setStartedAt(UtilityLocalDate.getNowTime().minusMinutes(10))
|
||||
// .setEstimatedEnd(UtilityLocalDate.getNowTime().plusMinutes(15))
|
||||
// .setSpeedPerMinute(500));
|
||||
|
||||
return asyncHistoryManager.getStatus();
|
||||
}
|
||||
|
||||
public void runSubscription(long subscriptionId) throws Exception {
|
||||
String sql = Query.format("SELECT * FROM " + StbRemoteSubscription.ENTITY +
|
||||
" WHERE id = %s AND active = 1", subscriptionId);
|
||||
|
||||
final StbRemoteSubscription stbRemoteSubscription =
|
||||
UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, StbRemoteSubscription.class);
|
||||
|
||||
if (stbRemoteSubscription == null)
|
||||
throw new Exception("Non è stata trovata alcuna sottoscrizione da poter avviare con l'ID " + subscriptionId);
|
||||
|
||||
internalSubscriptionRun(stbRemoteSubscription);
|
||||
}
|
||||
|
||||
|
||||
private void internalSubscriptionRun(StbRemoteSubscription subscription) throws Exception {
|
||||
boolean shouldStop = false;
|
||||
|
||||
while (!shouldStop) {
|
||||
List<TransactionGroupDTO> downloadedTransactions = downloadTransactions(subscription);
|
||||
|
||||
if (downloadedTransactions == null || downloadedTransactions.isEmpty()) {
|
||||
shouldStop = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
long lastImportedId = importTransactions(subscription, downloadedTransactions);
|
||||
subscription.setLastTransactionIdImported(lastImportedId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<TransactionGroupDTO> downloadTransactions(StbRemoteSubscription subscription) throws Exception {
|
||||
String endpoint = subscription.getEndpointUrl();
|
||||
HashMap<String, String> queryParams = new HashMap<String, String>() {{
|
||||
put("profileDb", subscription.getProfileDb());
|
||||
put("lastRetrievedTransactionId", subscription.getLastTransactionIdImported() == null ? null : String.valueOf(subscription.getLastTransactionIdImported()));
|
||||
put("limit", String.valueOf(50));
|
||||
}};
|
||||
|
||||
String retrieveTransactionsUrl = endpoint + "/ems-api/system/remote-transaction/" + subscription.getPublicationId() + "/retrieve";
|
||||
|
||||
StringBuilder responseBody = new StringBuilder();
|
||||
int status = HttpRestWrapper.callGenericGet(retrieveTransactionsUrl, subscription.getUsername(), subscription.getPassword(), responseBody, queryParams);
|
||||
|
||||
if (status != 200)
|
||||
throw new Exception("Errore durante l'aggiornamento della subscription \"" + subscription.getPublicationDescription() + "\"," +
|
||||
" l'endpoint " + endpoint + " ha generato lo status code " + status);
|
||||
|
||||
ServiceRestResponse response = jsonObjectMapper.readValue(responseBody.toString(), ServiceRestResponse.class);
|
||||
|
||||
if (response.getEsito() != EsitoType.OK)
|
||||
throw new Exception("Errore durante l'aggiornamento della subscription \"" + subscription.getPublicationDescription() + "\"." +
|
||||
" L'endpoint " + endpoint + " ha generato esito KO con il seguente messaggio: " + response.getErrorMessage());
|
||||
|
||||
|
||||
return response.getDTO(new TypeReference<List<TransactionGroupDTO>>() {
|
||||
});
|
||||
}
|
||||
|
||||
private long importTransactions(StbRemoteSubscription subscription, List<TransactionGroupDTO> transactions) throws Exception {
|
||||
|
||||
StbRemoteSubscription cloneSubscriptionItem = (StbRemoteSubscription) subscription.deepClone();
|
||||
|
||||
for (TransactionGroupDTO transactionGroup : transactions) {
|
||||
List<EntityBase> entities = new ArrayList<>();
|
||||
|
||||
for (TransactionDTO transaction : transactionGroup.getItems()) {
|
||||
final EntityBase entityBase = jsonObjectMapper.readValue(transaction.getTransactionJson(), EntityBase.class);
|
||||
entityBase.setOperation(OperationType.INSERT);
|
||||
entityBase.setUsername(transaction.getUsername());
|
||||
entities.add(entityBase);
|
||||
}
|
||||
|
||||
cloneSubscriptionItem.setLastTransactionIdImported(
|
||||
transactionGroup.getItems().stream()
|
||||
.map(TransactionDTO::getTransactionId)
|
||||
.max(Long::compare).get());
|
||||
|
||||
cloneSubscriptionItem.setOperation(OperationType.UPDATE);
|
||||
entities.add(cloneSubscriptionItem);
|
||||
|
||||
entities = entityProcessor.processEntityList(entities,
|
||||
null, false, true,
|
||||
false, multiDBTransactionManager,
|
||||
false, true);
|
||||
|
||||
UtilityEntity.throwEntitiesException(entities);
|
||||
}
|
||||
|
||||
return cloneSubscriptionItem.getLastTransactionIdImported();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
package it.integry.ems.sync.service;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
import it.integry.ems.json.JSONObjectMapper;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.HttpRestWrapper;
|
||||
import it.integry.ems.sync.AsyncHistoryManager;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.sync.dto.ExportHistoryStatusDTO;
|
||||
import it.integry.ems.sync.dto.PublicationDTO;
|
||||
import it.integry.ems.sync.dto.PublicationGroupDTO;
|
||||
import it.integry.ems.sync.dto.SubscriptionDTO;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.entity.StbPublications;
|
||||
import it.integry.ems_model.entity.StbPublicationsDetail;
|
||||
import it.integry.ems_model.entity.StbRemoteSubscription;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityQuery;
|
||||
@@ -47,15 +53,14 @@ public class RemoteSynchronizationSetupService {
|
||||
@Autowired
|
||||
private AsyncHistoryManager asyncHistoryManager;
|
||||
|
||||
@Autowired
|
||||
private JSONObjectMapper jsonObjectMapper;
|
||||
|
||||
public List<PublicationGroupDTO> retrievePublications() throws Exception {
|
||||
|
||||
StbPublications tmpStbPublications = new StbPublications();
|
||||
tmpStbPublications.setOperation(OperationType.SELECT);
|
||||
tmpStbPublications.setOnlyPkMaster(false);
|
||||
|
||||
List<EntityBase> selectedEntities = entityProcessor.processEntity(tmpStbPublications, multiDBTransactionManager);
|
||||
if (selectedEntities == null) return null;
|
||||
List<StbPublications> stbPublicationsToRetrieve = UtilityEntity.toCustomEntity(selectedEntities);
|
||||
List<StbPublications> stbPublicationsToRetrieve = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||
"SELECT * FROM " + StbPublications.ENTITY, StbPublications.class);
|
||||
if (stbPublicationsToRetrieve == null) return null;
|
||||
|
||||
List<StbPublicationsDetail> stbPublicationsDetails =
|
||||
UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||
@@ -241,4 +246,39 @@ public class RemoteSynchronizationSetupService {
|
||||
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
}
|
||||
|
||||
public long addSubscription(SubscriptionDTO subscriptionToInsert) throws Exception {
|
||||
|
||||
String endpointRetrieve = subscriptionToInsert.getEndpointUrl() + "/ems-api/system/remote-sync/setup/publications/retrieve";
|
||||
HashMap<String, String> queryParams = new HashMap<String, String>() {{
|
||||
put("profileDb", subscriptionToInsert.getProfileDb());
|
||||
}};
|
||||
|
||||
StringBuilder responseString = new StringBuilder();
|
||||
int retrieveStatus = HttpRestWrapper.callGenericGet(endpointRetrieve,
|
||||
subscriptionToInsert.getUsername(), subscriptionToInsert.getPassword(), responseString, queryParams);
|
||||
|
||||
if(retrieveStatus != 200)
|
||||
throw new Exception("Impossibile stabilire una connessione con l'endpoint " + subscriptionToInsert.getEndpointUrl() + ". [STATUS CODE: " + retrieveStatus + "]");
|
||||
|
||||
final ServiceRestResponse publicationResponse = jsonObjectMapper.readValue(responseString.toString(), ServiceRestResponse.class);
|
||||
final List<PublicationGroupDTO> availablePublications = publicationResponse.getDTO(new TypeReference<List<PublicationGroupDTO>>() {
|
||||
});
|
||||
|
||||
final PublicationGroupDTO publicationGroupDTO = availablePublications.stream().filter(x -> x.getId() == subscriptionToInsert.getPublicationId())
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if(publicationGroupDTO == null)
|
||||
throw new Exception("Non è stata trovata alcuna pubblicazione con ID " + subscriptionToInsert.getPublicationId() + " sull'endpoint " + subscriptionToInsert.getEndpointUrl());
|
||||
|
||||
subscriptionToInsert.setPublicationDescription(publicationGroupDTO.getDescription());
|
||||
|
||||
final StbRemoteSubscription stbRemoteSubscription = subscriptionToInsert.toEntity();
|
||||
stbRemoteSubscription.setOperation(OperationType.INSERT);
|
||||
|
||||
entityProcessor.processEntity(stbRemoteSubscription, multiDBTransactionManager);
|
||||
|
||||
return stbRemoteSubscription.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package it.integry.ems.sync.service;
|
||||
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.sync.dto.TransactionDTO;
|
||||
import it.integry.ems.sync.dto.TransactionGroupDTO;
|
||||
import it.integry.ems_model.entity.StbPublicationsDetail;
|
||||
import it.integry.ems_model.entity.StbTransactionLog;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
@Service
|
||||
@Scope("request")
|
||||
public class RemoteSynchronizationTransactionsService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
|
||||
public List<TransactionGroupDTO> retrieveTransactions(long publicationId, Long lastRetrievedTransactionId, int limit) throws Exception {
|
||||
|
||||
String sql = Query.format("SELECT * FROM " + StbPublicationsDetail.ENTITY + " WHERE stb_publication_id = %s AND ready_to_transmit = 1", publicationId);
|
||||
final StbPublicationsDetail stbPublicationsDetails = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, StbPublicationsDetail.class);
|
||||
|
||||
if(stbPublicationsDetails == null)
|
||||
return null;
|
||||
|
||||
List<Long> availableGroupIds = UtilityDB.executeSimpleQueryOnlyFirstColumn(multiDBTransactionManager.getPrimaryConnection(),
|
||||
"SELECT DISTINCT group_id\n" +
|
||||
"FROM " + StbTransactionLog.ENTITY + "\n" +
|
||||
"WHERE publication_group_id = " + UtilityDB.valueToString(publicationId) + "\n" +
|
||||
(lastRetrievedTransactionId != null ? "AND id > " + UtilityDB.valueToString(lastRetrievedTransactionId) + "\n" : "") +
|
||||
"ORDER BY group_id");
|
||||
|
||||
if (availableGroupIds == null || availableGroupIds.isEmpty())
|
||||
return null;
|
||||
|
||||
availableGroupIds = availableGroupIds.subList(0, Math.min(limit > 0 ? limit : 100, availableGroupIds.size()));
|
||||
|
||||
List<StbTransactionLog> transactions = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||
"SELECT * FROM " + StbTransactionLog.ENTITY + "\n" +
|
||||
"WHERE group_id IN (" + UtilityQuery.concatLongFieldsWithSeparator(availableGroupIds, ",") + ")\n" +
|
||||
"ORDER BY id",
|
||||
StbTransactionLog.class);
|
||||
|
||||
|
||||
if (transactions == null || transactions.isEmpty())
|
||||
return null;
|
||||
|
||||
final Map<Long, List<StbTransactionLog>> collect = transactions.stream().collect(groupingBy(StbTransactionLog::getGroupId));
|
||||
final List<TransactionGroupDTO> transactionGroups = new ArrayList<>();
|
||||
|
||||
for(Long groupId : collect.keySet().stream().sorted().collect(Collectors.toList())) {
|
||||
transactionGroups.add(new TransactionGroupDTO()
|
||||
.setId(groupId)
|
||||
.setItems(collect.get(groupId).stream()
|
||||
.sorted(Comparator.comparingLong(StbTransactionLog::getId))
|
||||
.map(x -> new TransactionDTO()
|
||||
.setTransactionId(x.getId())
|
||||
.setPublicationId(x.getPublicationGroupId())
|
||||
.setTransactionDate(x.getCreatedAt())
|
||||
.setEntityName(x.getEntities())
|
||||
.setTransactionJson(x.getEntitiesJson())
|
||||
.setUsername(x.getUserName()))
|
||||
.collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
return transactionGroups;
|
||||
}
|
||||
}
|
||||
@@ -150,10 +150,6 @@ public class EmsRestConstants {
|
||||
public static final String PATH_EXPORT_PRODOTTI_CQ = PATH + "exportProdottiCQ";
|
||||
public static final String PATH_IMPORT_ORDINI_CQ = PATH + "importOrdiniCQ";
|
||||
public static final String PATH_SELECT_RAW_DATA = PATH + "selectRawData";
|
||||
public static final String PATH_ASYNC_BASE_ROUTE = PATH + "async_v2";
|
||||
public static final String PATH_ASYNC_START = PATH + "start";
|
||||
public static final String PATH_ASYNC_RETRIEVE_TRANSACTIONS = PATH + "retrieveTransactions";
|
||||
public static final String PATH_ASYNC_UPDATE_TRANSACTION_IMPORT_ID = PATH + "updateTransactionImportID";
|
||||
public static final String PATH_ACCETTAZIONE = PATH + "accettazione";
|
||||
public static final String PATH_PICKING = PATH + "picking";
|
||||
public static final String PATH_PICKING_ORDINE = PATH + "pickingOrdine";
|
||||
|
||||
@@ -21,7 +21,7 @@ public class StbPublications extends EntityBase {
|
||||
@PK
|
||||
@Identity
|
||||
@SqlField(value = "id", nullable = false)
|
||||
private long id;
|
||||
private Long id;
|
||||
|
||||
@SqlField(value = "publication_description")
|
||||
private String publicationDescription;
|
||||
@@ -30,11 +30,11 @@ public class StbPublications extends EntityBase {
|
||||
private List<StbPublicationsDetail> stbPublicationsDetails = new ArrayList<>();
|
||||
|
||||
|
||||
public long getId() {
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public StbPublications setId(long id) {
|
||||
public StbPublications setId(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
package it.integry.ems_model.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import it.integry.ems_model.annotation.*;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@Table(StbRemoteSubscription.ENTITY)
|
||||
@JsonTypeName(StbRemoteSubscription.ENTITY)
|
||||
public class StbRemoteSubscription extends EntityBase {
|
||||
|
||||
public static final String ENTITY = "stb_remote_subscription";
|
||||
|
||||
private static final long serialVerionUID = 1L;
|
||||
|
||||
@PK
|
||||
@Identity
|
||||
@SqlField(value = "id", nullable = false)
|
||||
private Long id;
|
||||
|
||||
@SqlField(value = "publication_id", nullable = false)
|
||||
private Long publicationId;
|
||||
|
||||
@SqlField(value = "publication_description")
|
||||
private String publicationDescription;
|
||||
|
||||
@SqlField(value = "endpoint_protocol", nullable = false, defaultObjectValue = "HTTP")
|
||||
private String endpointProtocol;
|
||||
|
||||
@SqlField(value = "endpoint_host", nullable = false)
|
||||
private String endpointHost;
|
||||
|
||||
@SqlField(value = "endpoint_port", nullable = false, defaultObjectValue = "80")
|
||||
private int endpointPort;
|
||||
|
||||
@SqlField(value = "username", nullable = false)
|
||||
private String username;
|
||||
|
||||
@SqlField(value = "password", nullable = false)
|
||||
private String password;
|
||||
|
||||
@SqlField(value = "profile_db", nullable = false)
|
||||
private String profileDb;
|
||||
|
||||
@SqlField(value = "last_transaction_id")
|
||||
private Long lastTransactionId;
|
||||
|
||||
@SqlField(value = "last_transaction_id_imported")
|
||||
private Long lastTransactionIdImported;
|
||||
|
||||
@SqlField(value = "active", nullable = false, defaultObjectValue = "0")
|
||||
private boolean active;
|
||||
|
||||
|
||||
public String getEndpointUrl() {
|
||||
return endpointProtocol.toLowerCase() + "://" + endpointHost + ":" + endpointPort;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setId(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long getPublicationId() {
|
||||
return publicationId;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setPublicationId(Long publicationId) {
|
||||
this.publicationId = publicationId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPublicationDescription() {
|
||||
return publicationDescription;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setPublicationDescription(String publicationDescription) {
|
||||
this.publicationDescription = publicationDescription;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEndpointProtocol() {
|
||||
return endpointProtocol;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setEndpointProtocol(String endpointProtocol) {
|
||||
this.endpointProtocol = endpointProtocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getEndpointHost() {
|
||||
return endpointHost;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setEndpointHost(String endpointHost) {
|
||||
this.endpointHost = endpointHost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getEndpointPort() {
|
||||
return endpointPort;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setEndpointPort(int endpointPort) {
|
||||
this.endpointPort = endpointPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUsernameField() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setUsernameField(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setPassword(String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getProfileDb() {
|
||||
return profileDb;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setProfileDb(String profileDb) {
|
||||
this.profileDb = profileDb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long getLastTransactionId() {
|
||||
return lastTransactionId;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setLastTransactionId(Long lastTransactionId) {
|
||||
this.lastTransactionId = lastTransactionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long getLastTransactionIdImported() {
|
||||
return lastTransactionIdImported;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setLastTransactionIdImported(Long lastTransactionIdImported) {
|
||||
this.lastTransactionIdImported = lastTransactionIdImported;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public StbRemoteSubscription setActive(boolean active) {
|
||||
this.active = active;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,11 @@ public class UtilityQuery {
|
||||
return sbWhereCond.toString();
|
||||
}
|
||||
|
||||
public static String concatFieldsWithSeparator(List<String> inputData, String separator) {
|
||||
public static String concatStringFieldsWithSeparator(List<String> inputData, String separator) {
|
||||
return UtilityQuery.concatObjectFieldsWithSeparator(Stream.of(inputData).map(x -> (Object) x).toList(), separator);
|
||||
}
|
||||
|
||||
public static String concatLongFieldsWithSeparator(List<Long> inputData, String separator) {
|
||||
return UtilityQuery.concatObjectFieldsWithSeparator(Stream.of(inputData).map(x -> (Object) x).toList(), separator);
|
||||
}
|
||||
|
||||
|
||||
@@ -1621,7 +1621,7 @@ public class DocumentService {
|
||||
throw new Exception("Data storico da, data storico a richiesti in creaBudget.");
|
||||
}
|
||||
|
||||
String inClienti = UtilityQuery.concatFieldsWithSeparator(creaBudgetDTO.getClienti(), ",");
|
||||
String inClienti = UtilityQuery.concatStringFieldsWithSeparator(creaBudgetDTO.getClienti(), ",");
|
||||
String codAnagAltri = setupGest.getSetup("PVM", "ANALISI_BUDGET", "COD_ANAG_ALTRI");
|
||||
|
||||
String sql =
|
||||
|
||||
@@ -185,7 +185,7 @@ public class ImportAnagListiniService {
|
||||
String selectMtbAarts = "SELECT maa.cod_mart, maa.id_art_equi, maa.unt_mis, vaa.cod_vart, vaa.id_riga " +
|
||||
" FROM " + MtbAart.ENTITY + " maa" +
|
||||
" LEFT OUTER JOIN vtb_arti_acc vaa on maa.cod_mart = vaa.cod_mart " +
|
||||
" WHERE maa.cod_mart IN (" + UtilityQuery.concatFieldsWithSeparator(dbCodMarts, ",") + ")";
|
||||
" WHERE maa.cod_mart IN (" + UtilityQuery.concatStringFieldsWithSeparator(dbCodMarts, ",") + ")";
|
||||
|
||||
List<HashMap<String, Object>> dbArtsData = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), selectMtbAarts);
|
||||
List<String> dbCodMartsData = Stream.of(dbArtsData)
|
||||
@@ -204,7 +204,7 @@ public class ImportAnagListiniService {
|
||||
sql =
|
||||
"SELECT * " +
|
||||
" FROM " + MtbAartEqui.ENTITY +
|
||||
" WHERE id_art_equi IN (" + UtilityQuery.concatFieldsWithSeparator(dbCodMartEqui, ",") + ")";
|
||||
" WHERE id_art_equi IN (" + UtilityQuery.concatStringFieldsWithSeparator(dbCodMartEqui, ",") + ")";
|
||||
mtbAartEquiList = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbAartEqui.class);
|
||||
}
|
||||
List<EntityBase> entitiesToSave = new ArrayList<>();
|
||||
|
||||
@@ -227,7 +227,7 @@ public class ProductServices {
|
||||
String query =
|
||||
"SELECT DISTINCT mtb_aart.*"
|
||||
+ " FROM mtb_aart "
|
||||
+ " WHERE cod_mart IN (" + UtilityQuery.concatFieldsWithSeparator(codMarts, ",") + ")";
|
||||
+ " WHERE cod_mart IN (" + UtilityQuery.concatStringFieldsWithSeparator(codMarts, ",") + ")";
|
||||
|
||||
|
||||
List<MtbAart> listMtbAart = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), query, MtbAart.class);
|
||||
@@ -260,7 +260,7 @@ public class ProductServices {
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
String queryUntMis = "SELECT * FROM mtb_unt_mis WHERE unt_mis IN (" + UtilityQuery.concatFieldsWithSeparator(untMisStrings, ",") + ")";
|
||||
String queryUntMis = "SELECT * FROM mtb_unt_mis WHERE unt_mis IN (" + UtilityQuery.concatStringFieldsWithSeparator(untMisStrings, ",") + ")";
|
||||
final List<MtbUntMis> mtbUntMis = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), queryUntMis, MtbUntMis.class);
|
||||
return mtbUntMis != null ? mtbUntMis : new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -231,10 +231,10 @@ public class AgribookOrderService {
|
||||
.toList();
|
||||
|
||||
List<MtbDepo> mtbDepoList = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||
"SELECT * FROM mtb_depo WHERE cod_mdep IN (" + UtilityQuery.concatFieldsWithSeparator(mtbDepoSearchList, ", ") + ")", MtbDepo.class);
|
||||
"SELECT * FROM mtb_depo WHERE cod_mdep IN (" + UtilityQuery.concatStringFieldsWithSeparator(mtbDepoSearchList, ", ") + ")", MtbDepo.class);
|
||||
|
||||
List<MtbDepoPosizioni> mtbDepoPosizioniList = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||
"SELECT * FROM " + MtbDepoPosizioni.ENTITY + " WHERE cod_mdep IN (" + UtilityQuery.concatFieldsWithSeparator(mtbDepoSearchList, ", ") + ")", MtbDepoPosizioni.class);
|
||||
"SELECT * FROM " + MtbDepoPosizioni.ENTITY + " WHERE cod_mdep IN (" + UtilityQuery.concatStringFieldsWithSeparator(mtbDepoSearchList, ", ") + ")", MtbDepoPosizioni.class);
|
||||
|
||||
if (mtbDepoPosizioniList == null) mtbDepoPosizioniList = new ArrayList<>();
|
||||
|
||||
@@ -625,7 +625,7 @@ public class AgribookOrderService {
|
||||
}
|
||||
|
||||
if (entityList.size() > 0) {
|
||||
List<EntityBase> entityRet = entityProcessor.processEntityList("dba", true, true, false, entityList);
|
||||
List<EntityBase> entityRet = entityProcessor.processEntityList(entityList, "dba", true, true, false);
|
||||
|
||||
UtilityEntity.throwEntitiesException(entityRet);
|
||||
|
||||
@@ -759,7 +759,7 @@ public class AgribookOrderService {
|
||||
}
|
||||
|
||||
if (entityList.size() > 0) {
|
||||
List<EntityBase> entityRet = entityProcessor.processEntityList("dba", true, true, false, entityList);
|
||||
List<EntityBase> entityRet = entityProcessor.processEntityList(entityList, "dba", true, true, false);
|
||||
|
||||
UtilityEntity.throwEntitiesException(entityRet);
|
||||
|
||||
|
||||
@@ -3556,7 +3556,7 @@ public class PvmService {
|
||||
whereCond += " AND filtro is not null";
|
||||
|
||||
if (depositi != null && !depositi.isEmpty()) {
|
||||
whereCond += String.format(" AND cod_mdep IN (%s)", UtilityQuery.concatFieldsWithSeparator(depositi, ", "));
|
||||
whereCond += String.format(" AND cod_mdep IN (%s)", UtilityQuery.concatStringFieldsWithSeparator(depositi, ", "));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1935,7 +1935,7 @@ public class SystemService {
|
||||
|
||||
|
||||
public List<LicenseStatusDTO> retrieveLicenseStatus(List<String> partIvaList) throws Exception {
|
||||
String partIvaWhereCond = UtilityQuery.concatFieldsWithSeparator(partIvaList, ",");
|
||||
String partIvaWhereCond = UtilityQuery.concatStringFieldsWithSeparator(partIvaList, ",");
|
||||
if (UtilityString.isNullOrEmpty(partIvaWhereCond)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user