Skip to content

Commit

Permalink
feat : add parameter to specify origin tech-by-design#745
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreeja jobin committed Jan 2, 2025
1 parent e0fedbc commit 6e7e43f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion hub-prime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>org.techbd</groupId>
<artifactId>hub-prime</artifactId>
<version>0.415.0</version>
<version>0.416.0</version>
<packaging>war</packaging>
<name>Tech by Design Hub (Prime)</name>
<description>Tech by Design Hub (Primary)</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -39,6 +40,7 @@ public CsvController(CsvService csvService) {
public Object handleCsvUpload(
@Parameter(description = "ZIP file containing CSV data. Must not be null.", required = true) @RequestPart("file") @Nonnull MultipartFile file,
@Parameter(description = "Tenant ID, a mandatory parameter.", required = true) @RequestHeader(value = Configuration.Servlet.HeaderName.Request.TENANT_ID) String tenantId,
@Parameter(description = "Parameter to specify origin of the request.", required = false) @RequestParam(value = "origin", required = false,defaultValue = "HTTP") String origin,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
Expand All @@ -63,7 +65,7 @@ public Object handleCsvUpload(
log.error("CsvController: handleCsvUpload:: Tenant ID is missing or empty");
throw new IllegalArgumentException("Tenant ID must be provided");
}
return csvService.validateCsvFile(file, request, response, tenantId);
return csvService.validateCsvFile(file, request, response, tenantId,origin);
}

@PostMapping(value = { "/flatfile/csv/Bundle", "/flatfile/csv/Bundle/" }, consumes = {
Expand All @@ -73,12 +75,13 @@ public Object handleCsvUpload(
public List<Object> handleCsvUploadAndConversion(
@Parameter(description = "ZIP file containing CSV data. Must not be null.", required = true) @RequestPart("file") @Nonnull MultipartFile file,
@Parameter(description = "Parameter to specify the Tenant ID. This is a <b>mandatory</b> parameter.", required = true) @RequestHeader(value = Configuration.Servlet.HeaderName.Request.TENANT_ID, required = true) String tenantId,
@Parameter(description = "Parameter to specify origin of the request.", required = false) @RequestParam(value = "origin", required = false,defaultValue = "HTTP") String origin,
HttpServletRequest request,
HttpServletResponse response) throws Exception {

if (tenantId == null || tenantId.trim().isEmpty()) {
throw new IllegalArgumentException("Tenant ID must be provided");
}
return csvService.processZipFile(file, request, response, tenantId);
return csvService.processZipFile(file, request, response, tenantId,origin);
}
}
13 changes: 7 additions & 6 deletions hub-prime/src/main/java/org/techbd/service/CsvService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.fasterxml.jackson.databind.JsonNode;

import io.micrometer.common.util.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@Service
Expand All @@ -45,12 +46,12 @@ public CsvService(final CsvOrchestrationEngine engine, final UdiPrimeJpaConfig u

public Object validateCsvFile(final MultipartFile file, final HttpServletRequest request,
final HttpServletResponse response,
final String tenantId) throws Exception {
final String tenantId,String origin) throws Exception {
CsvOrchestrationEngine.OrchestrationSession session = null;
try {
final var dslContext = udiPrimeJpaConfig.dsl();
final var jooqCfg = dslContext.configuration();
saveArchiveInteraction(jooqCfg, request, file, tenantId);
saveArchiveInteraction(jooqCfg, request, file, tenantId,origin);
session = engine.session()
.withMasterInteractionId(getBundleInteractionId(request))
.withSessionId(UUID.randomUUID().toString())
Expand All @@ -74,14 +75,14 @@ private String getBundleInteractionId(final HttpServletRequest request) {

private void saveArchiveInteraction(final org.jooq.Configuration jooqCfg, final HttpServletRequest request,
final MultipartFile file,
final String tenantId) {
final String tenantId,String origin) {
final var interactionId = getBundleInteractionId(request);
LOG.info("REGISTER State NONE : BEGIN for inteaction id : {} tenant id : {}",
interactionId, tenantId);
final var forwardedAt = OffsetDateTime.now();
final var initRIHR = new RegisterInteractionHttpRequest();
try {
initRIHR.setOrigin(Origin.HTTP.name());
initRIHR.setOrigin(StringUtils.isEmpty(origin) ? Origin.HTTP.name():origin);
initRIHR.setInteractionId(interactionId);
initRIHR.setInteractionKey(request.getRequestURI());
initRIHR.setNature((JsonNode) Configuration.objectMapper.valueToTree(
Expand Down Expand Up @@ -127,12 +128,12 @@ private void saveArchiveInteraction(final org.jooq.Configuration jooqCfg, final
* @throws Exception If an error occurs during processing the zip file or CSV
* parsing.
*/
public List<Object> processZipFile(final MultipartFile file,final HttpServletRequest request ,HttpServletResponse response ,final String tenantId) throws Exception {
public List<Object> processZipFile(final MultipartFile file,final HttpServletRequest request ,HttpServletResponse response ,final String tenantId,String origin) throws Exception {
CsvOrchestrationEngine.OrchestrationSession session = null;
try {
final var dslContext = udiPrimeJpaConfig.dsl();
final var jooqCfg = dslContext.configuration();
saveArchiveInteraction(jooqCfg, request, file, tenantId);
saveArchiveInteraction(jooqCfg, request, file, tenantId,origin);
final String masterInteractionId = getBundleInteractionId(request);
session = engine.session()
.withMasterInteractionId(masterInteractionId)
Expand Down

0 comments on commit 6e7e43f

Please sign in to comment.