Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify dataset #9

Merged
merged 9 commits into from
Jan 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.inqwise.opinion.infrastructure.systemFramework.DateConverter;
import com.inqwise.opinion.infrastructure.systemFramework.JSONHelper;
import com.inqwise.opinion.library.common.IProduct;
import com.inqwise.opinion.library.common.accounts.AccountModel;
import com.inqwise.opinion.library.common.accounts.AccountOperationsReferenceType;
import com.inqwise.opinion.library.common.accounts.AccountsOperationsType;
import com.inqwise.opinion.library.common.accounts.IAccount;
Expand Down Expand Up @@ -76,19 +77,20 @@ public JSONObject getAccounts(JSONObject input) throws JSONException, CDataGridE
Date fromDate = JSONHelper.optDate(input, "fromDate");
Date toDate = JSONHelper.optDate(input, "toDate");

CDataCacheContainer dsAccounts = AccountsManager.getAccounts(userId, productId, top, includeNonActive, fromDate, toDate, null);
CDataRowSet rowSet = dsAccounts.getAll();
if(rowSet.size() > 0){
List<AccountModel> accountList = AccountsManager.getAccounts(userId, productId, top, includeNonActive, fromDate, toDate, null);
JSONArray ja = new JSONArray();

if(accountList.size() > 0){
output = new JSONObject();
JSONArray list = new JSONArray();
while(rowSet.next()){
for(var accountModel : accountList){
JSONObject item = new JSONObject();
item.put(IAccount.JsonNames.ACCOUNT_ID, rowSet.getLong(IAccount.ResultSetNames.ACCOUNT_ID));
item.put(IAccount.JsonNames.SERVICE_PACKAGE_NAME, rowSet.getString(IAccount.ResultSetNames.SERVICE_PACKAGE_NAME));
item.put(IAccount.JsonNames.ACCOUNT_NAME, rowSet.getString(IAccount.ResultSetNames.ACCOUNT_NAME));
item.put(IAccount.JsonNames.OWNER_ID, rowSet.getLong(IAccount.ResultSetNames.OWNER_ID));
item.put(IAccount.JsonNames.INSERT_DATE, mdyhmsFormatter.format(rowSet.getDate(IAccount.ResultSetNames.INSERT_DATE)));
item.put(IAccount.JsonNames.IS_ACTIVE, rowSet.getBoolean(IAccount.ResultSetNames.IS_ACTIVE));
item.put(IAccount.JsonNames.ACCOUNT_ID, accountModel.getAccountId());
item.put(IAccount.JsonNames.SERVICE_PACKAGE_NAME, accountModel.getServicePackageName());
item.put(IAccount.JsonNames.ACCOUNT_NAME, accountModel.getAccountName());
item.put(IAccount.JsonNames.OWNER_ID, accountModel.getOwnerId());
item.put(IAccount.JsonNames.INSERT_DATE, mdyhmsFormatter.format(accountModel.getInsertDate()));
item.put(IAccount.JsonNames.IS_ACTIVE, accountModel.getIsActive());

list.put(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,39 @@
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import net.casper.data.model.CDataCacheContainer;
import net.casper.data.model.CDataGridException;
import net.casper.data.model.CDataRowSet;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.inqwise.opinion.common.IPostmasterContext;
import com.inqwise.opinion.common.SurveyStatistics;
import com.inqwise.opinion.common.collectors.CollectorModel;
import com.inqwise.opinion.common.collectors.CollectorSourceType;
import com.inqwise.opinion.common.collectors.CollectorStatus;
import com.inqwise.opinion.common.collectors.ICollector;
import com.inqwise.opinion.common.opinions.IOpinion;
import com.inqwise.opinion.common.opinions.ISurvey;
import com.inqwise.opinion.infrastructure.systemFramework.ApplicationLog;
import com.inqwise.opinion.infrastructure.systemFramework.JSONHelper;
import com.inqwise.opinion.library.common.IProduct;
import com.inqwise.opinion.library.common.accounts.AccountModel;
import com.inqwise.opinion.library.common.accounts.IAccount;
import com.inqwise.opinion.library.common.accounts.IAccountView;
import com.inqwise.opinion.library.common.errorHandle.BaseOperationResult;
import com.inqwise.opinion.library.common.errorHandle.ErrorCode;
import com.inqwise.opinion.library.common.errorHandle.OperationResult;
import com.inqwise.opinion.library.common.pay.ChargeReferenceType;
import com.inqwise.opinion.library.managers.AccountsManager;
import com.inqwise.opinion.library.managers.ChargesManager;
import com.inqwise.opinion.library.systemFramework.ApplicationConfiguration;
import com.inqwise.opinion.opinion.common.IPostmasterContext;
import com.inqwise.opinion.opinion.common.SurveyStatistics;
import com.inqwise.opinion.opinion.common.collectors.CollectorSourceType;
import com.inqwise.opinion.opinion.common.collectors.CollectorStatus;
import com.inqwise.opinion.opinion.common.collectors.ICollector;
import com.inqwise.opinion.opinion.common.collectors.ICollector.IMessagesExtension;
import com.inqwise.opinion.opinion.common.collectors.ICollector.JsonNames;
import com.inqwise.opinion.opinion.common.collectors.ICollector.ResultSetNames;
import com.inqwise.opinion.opinion.common.opinions.IOpinion;
import com.inqwise.opinion.opinion.common.opinions.ISurvey;
import com.inqwise.opinion.opinion.managers.CollectorsManager;
import com.inqwise.opinion.opinion.managers.OpinionsManager;
import com.inqwise.opinion.library.managers.ProductsManager;
import com.inqwise.opinion.library.systemFramework.ApplicationConfiguration;
import com.inqwise.opinion.managers.CollectorsManager;
import com.inqwise.opinion.managers.OpinionsManager;

import net.casper.data.model.CDataCacheContainer;
import net.casper.data.model.CDataGridException;
import net.casper.data.model.CDataRowSet;

public class CollectorsEntry extends Entry {

Expand All @@ -64,51 +61,47 @@ public JSONObject getCollectors(JSONObject input) throws CDataGridException, JSO
collectorsByAccountId = new LinkedHashMap<>();
}

CDataCacheContainer ds = CollectorsManager.getMeny(opinionId, accountId, includeExpired, top, fromDate, toDate, null, ICollector.ResultSetNames.LAST_START_DATE);
List<CollectorModel> list = CollectorsManager.getMeny(opinionId, accountId, includeExpired, top, fromDate, toDate, null, ICollector.ResultSetNames.LAST_START_DATE);
JSONArray ja = new JSONArray();



//int accountsResult = AccountsManager.getAccounts(null, null, null, true, null, null, )

CDataRowSet rowSet = ds.getAll();


Format formatter = new SimpleDateFormat(
"MMM dd, yyyy HH:mm:ss");
while(rowSet.next()){
for(var collectorModel : list) {
JSONObject jo = new JSONObject();
jo.put(ICollector.JsonNames.COLLECTOR_ID, rowSet.getLong(ICollector.ResultSetNames.COLLECTOR_ID));
jo.put(ICollector.JsonNames.OPINION_ID, rowSet.getLong(ICollector.ResultSetNames.OPINION_ID));
Long actualAccountId = rowSet.getLong(ICollector.ResultSetNames.ACCOUNT_ID);
jo.put(ICollector.JsonNames.ACCOUNT_ID, actualAccountId);
jo.put(ICollector.JsonNames.COLLECTOR_UUID, rowSet.getString(ICollector.ResultSetNames.COLLECTOR_UUID));
jo.put(ICollector.JsonNames.MODIFY_DATE, mdyhFormatter.format(rowSet.getDate(ICollector.ResultSetNames.MODIFY_DATE)));
jo.put(ICollector.JsonNames.CREATE_DATE, mdyhFormatter.format(rowSet.getDate(ICollector.ResultSetNames.CREATE_DATE)));
if(null != rowSet.getDate(ICollector.ResultSetNames.EXPIRATION_DATE)){
jo.put(ICollector.JsonNames.EXPIRATION_DATE, mdyhFormatter.format(rowSet.getDate(ICollector.ResultSetNames.EXPIRATION_DATE)));
jo.put(ICollector.JsonNames.COLLECTOR_ID, collectorModel.getId());
jo.put(ICollector.JsonNames.OPINION_ID, collectorModel.getOpinionId());
Long actualAccountId = collectorModel.getAccountId();
jo.put(ICollector.JsonNames.ACCOUNT_ID, collectorModel.getAccountId());
jo.put(ICollector.JsonNames.COLLECTOR_UUID, collectorModel.getCollectorUuid());
jo.put(ICollector.JsonNames.MODIFY_DATE, mdyhFormatter.format(collectorModel.getModifyDate()));
jo.put(ICollector.JsonNames.CREATE_DATE, mdyhFormatter.format(collectorModel.getCreateDate()));
if(null != collectorModel.getExpirationDate()){
jo.put(ICollector.JsonNames.EXPIRATION_DATE, mdyhFormatter.format(collectorModel.getExpirationDate()));
}
jo.put(ICollector.JsonNames.NAME, rowSet.getString(ICollector.ResultSetNames.COLLECTOR_NAME));
jo.put(ICollector.JsonNames.NAME, collectorModel.getCollectorName());

String opinionName = rowSet.getString(ICollector.ResultSetNames.OPINION_NAME);
String opinionName = collectorModel.getOpinionName();
String opinionShortName = (opinionName.length() > 20 ? opinionName.substring(0, 18) + ".." : opinionName);
jo.put(ICollector.JsonNames.OPINION_NAME, opinionName);
jo.put("opinionShortName", opinionShortName);
jo.put(ICollector.JsonNames.OPINION_TYPE_NAME, rowSet.getString(ICollector.ResultSetNames.OPINION_TYPE_NAME));
jo.put(ICollector.JsonNames.STATUS_ID, rowSet.getInt(ICollector.ResultSetNames.COLLECTOR_STATUS_ID));
jo.put(ICollector.JsonNames.SOURCE_ID, rowSet.getInt(ICollector.ResultSetNames.COLLECTOR_SOURCE_ID));
jo.put(ICollector.JsonNames.SOURCE_NAME, rowSet.getString(ICollector.ResultSetNames.COLLECTOR_SOURCE_NAME));
jo.put(ICollector.JsonNames.SOURCE_TYPE_ID, rowSet.getInt(ICollector.ResultSetNames.COLLECTOR_SOURCE_TYPE_ID));
long cntStarted = rowSet.getLong(ResultSetNames.CNT_STARTED_OPINIONS);
long cntCompleted = rowSet.getLong(ResultSetNames.CNT_FINISHED_OPINIONS);
jo.put(JsonNames.STARTED_RESPONSES, cntStarted);
jo.put(JsonNames.FINISHED_RESPONSES, cntCompleted);
jo.put(JsonNames.PARTIAL_RESPONSES, cntStarted - cntCompleted);
jo.put(JsonNames.COMPLETION_RATE, (cntStarted > 0 ? Math.round((cntCompleted * 1d / cntStarted * 1d) * 100.0) : 0));
if(null != rowSet.getDate(ICollector.ResultSetNames.LAST_START_DATE)){
jo.put(ICollector.JsonNames.LAST_RESPONSE_DATE, formatter.format(rowSet.getDate(ICollector.ResultSetNames.LAST_START_DATE)));
jo.put(ICollector.JsonNames.OPINION_TYPE_NAME, collectorModel.getOpinionTypeName());
jo.put(ICollector.JsonNames.STATUS_ID, collectorModel.getCollectorStatusId());
jo.put(ICollector.JsonNames.SOURCE_ID, collectorModel.getCollectorSourceId());
jo.put(ICollector.JsonNames.SOURCE_NAME, collectorModel.getCollectorSourceName());
jo.put(ICollector.JsonNames.SOURCE_TYPE_ID, collectorModel.getCollectorSourceTypeId());
long cntStarted = collectorModel.getCntStartedOpinions();
long cntCompleted = collectorModel.getCntFinishedOpinions();
jo.put(ICollector.JsonNames.STARTED_RESPONSES, cntStarted);
jo.put(ICollector.JsonNames.FINISHED_RESPONSES, cntCompleted);
jo.put(ICollector.JsonNames.PARTIAL_RESPONSES, cntStarted - cntCompleted);
jo.put(ICollector.JsonNames.COMPLETION_RATE, (cntStarted > 0 ? Math.round((cntCompleted * 1d / cntStarted * 1d) * 100.0) : 0));
if(null != collectorModel.getLastStartDate()){
jo.put(ICollector.JsonNames.LAST_RESPONSE_DATE, formatter.format(collectorModel.getLastStartDate()));
}
if(null != rowSet.getDouble(ICollector.ResultSetNames.AVG_TIME_TAKEN_SEC)){
jo.put(ICollector.JsonNames.TIME_TAKEN, JSONHelper.getTimeSpanSec(Math.round(rowSet.getDouble(ICollector.ResultSetNames.AVG_TIME_TAKEN_SEC))));
if(null != collectorModel.getAvgTimeTakenSec()){
jo.put(ICollector.JsonNames.TIME_TAKEN, JSONHelper.getTimeSpanSec(Math.round(collectorModel.getAvgTimeTakenSec())));
}
ja.put(jo);

Expand All @@ -129,9 +122,9 @@ public JSONObject getCollectors(JSONObject input) throws CDataGridException, JSO
if(null == accountId){
accountIds = getArrayFromKeys(collectorsByAccountId);
IProduct product = ProductsManager.getProductByGuid(ApplicationConfiguration.Opinion.getProductGuid()).getValue();
CDataCacheContainer dsAccounts = AccountsManager.getAccounts(null, product.getId(), top, true, null, null, accountIds);
if(dsAccounts.size() > 0){
fillAccountDetails(dsAccounts, collectorsByAccountId);
List<AccountModel> accountList = AccountsManager.getAccounts(null, product.getId(), top, true, null, null, accountIds);
if(accountList.size() > 0){
fillAccountDetails(accountList, collectorsByAccountId);
}
}

Expand All @@ -141,13 +134,12 @@ public JSONObject getCollectors(JSONObject input) throws CDataGridException, JSO
return output;
}

private void fillAccountDetails(CDataCacheContainer dsAccounts,
LinkedHashMap<Long, List<JSONObject>> collectorsByAccountId) throws JSONException, CDataGridException {
CDataRowSet rowSet = dsAccounts.getAll();
while(rowSet.next()){
List<JSONObject> joList = collectorsByAccountId.get(rowSet.getLong(IAccount.ResultSetNames.ACCOUNT_ID));
private void fillAccountDetails(List<AccountModel> list,
LinkedHashMap<Long, List<JSONObject>> collectorsByAccountId) throws JSONException {
for(var accountModel : list){
List<JSONObject> joList = collectorsByAccountId.get(accountModel.getAccountId());
for (JSONObject jo : joList) {
jo.put(ICollector.JsonNames.ACCOUNT_NAME, rowSet.getString(IAccount.ResultSetNames.ACCOUNT_NAME));
jo.put(ICollector.JsonNames.ACCOUNT_NAME, accountModel.getAccountName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.inqwise.opinion.infrastructure.systemFramework.ApplicationLog;
import com.inqwise.opinion.infrastructure.systemFramework.JSONHelper;
import com.inqwise.opinion.library.common.IProduct;
import com.inqwise.opinion.library.common.accounts.AccountModel;
import com.inqwise.opinion.library.common.accounts.IAccount;
import com.inqwise.opinion.library.common.accounts.IAccountView;
import com.inqwise.opinion.library.common.errorHandle.BaseOperationResult;
Expand Down Expand Up @@ -108,9 +109,9 @@ public JSONObject getList(JSONObject input) throws JSONException, CDataGridExcep
if(null == accountId){
accountIds = getArrayFromKeys(surveysByAccountId);
IProduct product = ProductsManager.getProductByGuid(ApplicationConfiguration.Opinion.getProductGuid()).getValue();
CDataCacheContainer dsAccounts = AccountsManager.getAccounts(null, product.getId(), top, true, null, null, accountIds);
if(dsAccounts.size() > 0){
fillAccountDetails(dsAccounts, surveysByAccountId);
List<AccountModel> accountList = AccountsManager.getAccounts(null, product.getId(), top, true, null, null, accountIds);
if(accountList.size() > 0){
fillAccountDetails(accountList, surveysByAccountId);
}
}

Expand All @@ -119,13 +120,12 @@ public JSONObject getList(JSONObject input) throws JSONException, CDataGridExcep
return output;
}

private void fillAccountDetails(CDataCacheContainer dsAccounts,
LinkedHashMap<Long, List<JSONObject>> collectorsByAccountId) throws JSONException, CDataGridException {
CDataRowSet rowSet = dsAccounts.getAll();
while(rowSet.next()){
List<JSONObject> joList = collectorsByAccountId.get(rowSet.getLong(IAccount.ResultSetNames.ACCOUNT_ID));
private void fillAccountDetails(List<AccountModel> accountList,
LinkedHashMap<Long, List<JSONObject>> collectorsByAccountId) throws JSONException {
for(AccountModel model : accountList){
List<JSONObject> joList = collectorsByAccountId.get(model.getAccountId());
for (JSONObject jo : joList) {
jo.put(IOpinion.JsonNames.ACCOUNT_NAME, rowSet.getString(IAccount.ResultSetNames.ACCOUNT_NAME));
jo.put(IOpinion.JsonNames.ACCOUNT_NAME, model.getAccountName());
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion opinion-infrastructure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@
<groupId>com.maxmind.db</groupId>
<artifactId>maxmind-db</artifactId>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.inqwise.opinion.infrastructure.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.List;

import org.jooq.impl.DSL;
import org.json.JSONArray;
import org.json.JSONObject;

public class ResultSets {

public static JSONArray parse(Connection connection, ResultSet resultSet){


List<JSONObject> list = DSL.using(connection)
.fetch(resultSet)
.map(r -> {
JSONObject obj = new JSONObject();

for(var field : r.fields()) {
obj.put(field.getName(), r.getValue(field));
}
return obj;
});

return new JSONArray(list);

}


//JSONArray result = ResultSets.parse(connection, resultSet);


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
package com.inqwise.opinion.infrastructure.dao;

public class Resultsets {
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.List;

import org.jooq.impl.DSL;
import org.json.JSONArray;
import org.json.JSONObject;

public class ResultSets {

public static JSONArray parse(Connection connection, ResultSet resultSet){


List<JSONObject> list = DSL.using(connection)
.fetch(resultSet)
.map(r -> {
JSONObject obj = new JSONObject();

for(var field : r.fields()) {
obj.put(field.getName(), r.getValue(field));
}
return obj;
});

return new JSONArray(list);

}


//JSONArray result = ResultSets.parse(connection, resultSet);


}
5 changes: 1 addition & 4 deletions opinion-library-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
<artifactId>opinion-payments</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Loading
Loading