Migrated Query 3 - Using Parameterized query
This commit is contained in:
@@ -79,11 +79,9 @@
|
||||
<option value="-1" selected >SELECT PORTFOLIO</option>
|
||||
<c:choose>
|
||||
<c:when test="${not empty model}">
|
||||
<c:forEach items="${model.options}" var="port">
|
||||
<c:if test="${fn:startsWith(port.key, 'portfolio.')}">
|
||||
<option value="${fn:substringAfter(port.key, 'portfolio.')}"><c:out value="${port.value}" /></option>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
<c:forEach items="${model.options['portfolio.']}" var="port">
|
||||
<option value="${port.value}"><c:out value="${port.label}" /></option>
|
||||
</c:forEach>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<c:forEach items="${portlist}" var="port">
|
||||
|
||||
@@ -28,6 +28,7 @@ public class ModernDbConfiguration implements DisposableBean {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (installed != null) ModernDbExecutors.clear(installed);
|
||||
if (installed != null)
|
||||
ModernDbExecutors.clear(installed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package matrix.services.commons;
|
||||
|
||||
import com.cygnus.db.CygnusDbExecutor;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import lib.models.Option;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import matrix.nimble.model.Session;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@@ -15,6 +20,19 @@ public class CommonService {
|
||||
"SubmitMenuCommand\\(\\s*'([^']+)'\\s*,",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private final CygnusDbExecutor dbExecutor;
|
||||
|
||||
@Autowired
|
||||
public CommonService(CygnusDbExecutor dbExecutor) {
|
||||
this.dbExecutor = Objects.requireNonNull(dbExecutor, "dbExecutor");
|
||||
}
|
||||
|
||||
/* Used by the session-only unit tests. Production construction is handled
|
||||
by Spring through the CygnusDbExecutor constructor above. */
|
||||
public CommonService() {
|
||||
this.dbExecutor = null;
|
||||
}
|
||||
|
||||
public Session getSession(HttpSession httpSession) {
|
||||
if (httpSession == null) {
|
||||
return null;
|
||||
@@ -70,4 +88,15 @@ public class CommonService {
|
||||
int slash = normalized.lastIndexOf('/');
|
||||
return slash >= 0 ? normalized.substring(slash + 1) : normalized;
|
||||
}
|
||||
|
||||
public List<Option> getOptions(Integer queryId, Object[] queryParams) {
|
||||
if (queryId == null) {
|
||||
return List.of();
|
||||
}
|
||||
if (dbExecutor == null) {
|
||||
throw new IllegalStateException("CygnusDbExecutor is not configured");
|
||||
}
|
||||
Object[] parameters = queryParams == null ? new Object[0] : queryParams;
|
||||
return dbExecutor.query(queryId, parameters, Option.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import lib.models.CasePunching;
|
||||
import lib.models.ErrorDetails;
|
||||
import lib.models.Option;
|
||||
import lib.constants.ApplicationError;
|
||||
import matrix.nimble.edp.punching.model.PunchingHandler;
|
||||
import matrix.nimble.utilities.CommonFunctions;
|
||||
import matrix.nimble.utilities.GlobalClass;
|
||||
import matrix.services.commons.CommonService;
|
||||
|
||||
@Service
|
||||
public class PunchingService {
|
||||
@@ -25,18 +27,27 @@ public class PunchingService {
|
||||
private static final String APPLICATION_TYPE = "applicationType.";
|
||||
private static final String CATEGORY = "category.";
|
||||
|
||||
private final CommonService commonService;
|
||||
|
||||
public PunchingService(CommonService commonService) {
|
||||
this.commonService = commonService;
|
||||
}
|
||||
|
||||
public CasePunching init(
|
||||
String branchIds,
|
||||
String branchId,
|
||||
String userId,
|
||||
String verificationCaseId,
|
||||
String documentCaseId) {
|
||||
PunchingHandler punchingHandler = new PunchingHandler();
|
||||
punchingHandler.setErrCode("1001");
|
||||
punchingHandler.GetDDValues(3, branchIds.split(GlobalClass.ColDelim));
|
||||
|
||||
CasePunching casePunching = new CasePunching();
|
||||
Map<String, String> options = new LinkedHashMap<>();
|
||||
addOptions(options, PORTFOLIO, punchingHandler.getOptionvals());
|
||||
Map<String, List<Option>> options = new LinkedHashMap<>();
|
||||
Short databaseBranchId = Short.valueOf(branchId.trim());
|
||||
List<Option> portfolios = commonService.getOptions(
|
||||
3, new Object[] { databaseBranchId, Short.valueOf((short) 1) });
|
||||
|
||||
addOptions(options, PORTFOLIO, portfolios);
|
||||
casePunching.setOptions(Collections.unmodifiableMap(options));
|
||||
casePunching.setVisibleSections(List.of());
|
||||
casePunching.setPortfolioId(-1);
|
||||
@@ -120,7 +131,7 @@ public class PunchingService {
|
||||
addOptions(options, CATEGORY,
|
||||
commonFunctions.GetSubArray("CATEGORY", 2, portfolioOptions));
|
||||
}
|
||||
result.setOptions(Collections.unmodifiableMap(options));
|
||||
result.setOptionsl(Collections.unmodifiableMap(options));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -149,6 +160,24 @@ public class PunchingService {
|
||||
}
|
||||
}
|
||||
|
||||
private void addOptions(Map<String, List<Option>> options, String prefix, List<Option> values) {
|
||||
if (values == null || values.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Option> groupOptions = options.get(prefix);
|
||||
for (Option value : values) {
|
||||
if (value == null || value.getValue() == null) {
|
||||
continue;
|
||||
}
|
||||
if (groupOptions == null) {
|
||||
groupOptions = new java.util.ArrayList<>(values.size());
|
||||
options.put(prefix, groupOptions);
|
||||
}
|
||||
groupOptions.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> toVisibleSections(String sections) {
|
||||
if (sections == null || sections.isBlank()) {
|
||||
return List.of();
|
||||
|
||||
Reference in New Issue
Block a user