Skip to content

Commit

Permalink
Merge pull request #78 from logoutdhaval/GOV-360
Browse files Browse the repository at this point in the history
GOV-360
  • Loading branch information
fynmanoj authored Nov 8, 2023
2 parents a544fdc + a953149 commit 1340e81
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/main/java/hu/dpc/phee/operator/importer/VariableParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import static hu.dpc.phee.operator.OperatorUtils.strip;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext;
import hu.dpc.phee.operator.OperatorUtils;
import hu.dpc.phee.operator.entity.batch.Batch;
import hu.dpc.phee.operator.entity.batch.BatchRepository;
import hu.dpc.phee.operator.entity.outboundmessages.OutboudMessages;
import hu.dpc.phee.operator.entity.transactionrequest.TransactionRequest;
import hu.dpc.phee.operator.entity.transactionrequest.TransactionRequestState;
Expand All @@ -13,11 +16,15 @@
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import javax.transaction.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Component;
Expand All @@ -30,7 +37,8 @@ public class VariableParser {

@Value("${bpmn.outgoing-direction}")
private String outgoingDirection;

@Autowired
private BatchRepository batchRepository;
private final Logger logger = LoggerFactory.getLogger(VariableParser.class);
private final Map<String, Consumer<Pair<Transfer, String>>> transferParsers = new HashMap<>();
private final Map<String, Consumer<Pair<TransactionRequest, String>>> transactionRequestParsers = new HashMap<>();
Expand Down Expand Up @@ -99,6 +107,13 @@ public VariableParser() {
batchParsers.put("registeringInstituteId", pair -> pair.getFirst().setRegisteringInstitutionId(pair.getSecond()));
batchParsers.put("payerIdentifier", pair -> pair.getFirst().setPayerFsp(pair.getSecond()));
batchParsers.put("clientCorrelationId", pair -> pair.getFirst().setCorrelationId(pair.getSecond()));
batchParsers.put("subBatchDetails", pair -> {
try {
parseSubBatchDetails(pair.getSecond());
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
});

outboundMessageParsers.put("tenantId", pair -> pair.getFirst().setTenantId(Long.parseLong(pair.getSecond())));
outboundMessageParsers.put("externalId", pair -> pair.getFirst().setExternalId(strip(pair.getSecond())));
Expand All @@ -111,6 +126,15 @@ public VariableParser() {
outboundMessageParsers.put("bridgeId", pair -> pair.getFirst().setBridgeId(Long.parseLong(pair.getSecond())));
}

@Transactional
public void parseSubBatchDetails(String jsonString) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
List<Batch> batches = Arrays.asList(objectMapper.readValue(jsonString, Batch[].class));
for (Batch bt : batches) {
batchRepository.save(bt);
}
}

public Map<String, Consumer<Pair<Transfer, String>>> getTransferParsers() {
return transferParsers;
}
Expand Down

0 comments on commit 1340e81

Please sign in to comment.