Skip to content

Commit

Permalink
fix(dvs-client): missing fields in callback 3
Browse files Browse the repository at this point in the history
  • Loading branch information
vincejv committed Aug 28, 2023
1 parent a9568c9 commit a48ee67
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
@BsonDiscriminator
@MongoEntity(collection = "rewards_leak")
public class DVSCallback extends AbsMongoItem {

@BsonProperty(value = "transactionId")
private Long dtOneId;

Expand Down Expand Up @@ -92,4 +93,5 @@ public class DVSCallback extends AbsMongoItem {
private List<Benefit> benefits;

private String loadProvider;

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.dtone.dvs.dto.Product;
import com.dtone.dvs.dto.Promotion;
import com.dtone.dvs.dto.Rates;
import com.dtone.dvs.dto.StatementIdentifier;
import com.dtone.dvs.dto.Status;
import com.dtone.dvs.dto.Values;
import io.quarkus.runtime.annotations.RegisterForReflection;
Expand All @@ -44,24 +45,49 @@
@NoArgsConstructor
@BsonDiscriminator
public class DVSResp extends AbsMongoField {

private Long dtOneId;

private String externalId;

private LocalDateTime creationDate;

private LocalDateTime confirmationExpirationDate;

private LocalDateTime confirmationDate;

private Status status;

private String operatorReference;

private Pin pin;

private Product product;

private Prices prices;

private Rates rates;
private List<Benefit> benefits;

private List<Promotion> promotions;

private Values requestedValues;

private Values adjustedValues;

private Party sender;

private Party beneficiary;

private PartyIdentifier debitPartyIdentifier;

private PartyIdentifier creditPartyIdentifier;

private StatementIdentifier statementIdentifier;

private String callbackUrl;

private List<Benefit> benefits;

private String loadProvider;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

import com.abavilla.fpi.fw.mapper.IMapper;
import com.abavilla.fpi.load.dto.load.dtone.DVSCallbackDto;
Expand All @@ -31,11 +32,16 @@
import com.abavilla.fpi.load.entity.dtone.DVSResp;
import com.abavilla.fpi.load.util.LoadConst;
import com.dtone.dvs.dto.Transaction;
import com.dtone.dvs.dto.TransactionFixed;
import com.dtone.dvs.dto.TransactionRanged;
import com.dtone.dvs.dto.TransactionRequest;
import org.apache.commons.lang3.ObjectUtils;
import org.mapstruct.AfterMapping;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = MappingConstants.ComponentModel.CDI,
injectionStrategy = InjectionStrategy.CONSTRUCTOR)
Expand All @@ -46,12 +52,34 @@ public interface DTOneMapper extends IMapper {
@Mapping(target = "dtOneId", source = "id")
DVSResp copyTransactionRespToDVSResp(Transaction dto);

@AfterMapping
default void postCopyTransactionRespToDVSResp(Transaction dvsCallbackTransaction, @MappingTarget DVSResp dvsResp) {
if (dvsCallbackTransaction instanceof TransactionFixed fixed && ObjectUtils.isNotEmpty(fixed.getBenefits())) {
dvsResp.setBenefits(new ArrayList<>(fixed.getBenefits().size()));
dvsResp.getBenefits().addAll(fixed.getBenefits());
} else if (dvsCallbackTransaction instanceof TransactionRanged ranged && ObjectUtils.isNotEmpty(ranged.getBenefits())) {
dvsResp.setBenefits(new ArrayList<>(ranged.getBenefits().size()));
dvsResp.getBenefits().addAll(ranged.getBenefits());
}
}

@Mapping(target = "loadProvider", constant = LoadConst.PROV_DTONE)
DVSCallback mapDTOneRespToEntity(DVSCallbackDto dto);

@Mapping(target = "dtOneId", source = "id")
DVSCallbackDto mapDTOneTransactionToCallbackDto(Transaction dto);

@AfterMapping
default void postMapDTOneTransactionToCallbackDto(Transaction dvsCallbackTransaction, @MappingTarget DVSCallbackDto dvsCallbackDto) {
if (dvsCallbackTransaction instanceof TransactionFixed fixed && ObjectUtils.isNotEmpty(fixed.getBenefits())) {
dvsCallbackDto.setBenefits(new ArrayList<>(fixed.getBenefits().size()));
dvsCallbackDto.getBenefits().addAll(fixed.getBenefits());
} else if (dvsCallbackTransaction instanceof TransactionRanged ranged && ObjectUtils.isNotEmpty(ranged.getBenefits())) {
dvsCallbackDto.setBenefits(new ArrayList<>(ranged.getBenefits().size()));
dvsCallbackDto.getBenefits().addAll(ranged.getBenefits());
}
}

default String dtLdtToStr(LocalDateTime ldtTimestamp) {
if (ldtTimestamp != null) {
var formatter = DateTimeFormatter.ISO_DATE_TIME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.function.Function;

import com.abavilla.fpi.fw.entity.mongo.AbsMongoItem;
Expand All @@ -47,15 +46,12 @@
import com.abavilla.fpi.sms.ext.rest.SmsApi;
import com.abavilla.fpi.telco.ext.enums.ApiStatus;
import com.dtone.dvs.dto.Transaction;
import com.dtone.dvs.dto.TransactionFixed;
import com.dtone.dvs.dto.TransactionRanged;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.rest.client.inject.RestClient;

Expand Down Expand Up @@ -104,13 +100,6 @@ public Uni<Void> storeCallback(GLRewardsCallbackDto callbackDto) {

public Uni<Void> storeCallback(Transaction dvsCallbackTransaction) {
var dvsCallbackDto = dtOneMapper.mapDTOneTransactionToCallbackDto(dvsCallbackTransaction);
if (dvsCallbackTransaction instanceof TransactionFixed fixed && ObjectUtils.isNotEmpty(fixed.getBenefits())) {
dvsCallbackDto.setBenefits(new ArrayList<>(fixed.getBenefits().size()));
dvsCallbackDto.getBenefits().addAll(fixed.getBenefits());
} else if (dvsCallbackTransaction instanceof TransactionRanged ranged && ObjectUtils.isNotEmpty(ranged.getBenefits())) {
dvsCallbackDto.setBenefits(new ArrayList<>(ranged.getBenefits().size()));
dvsCallbackDto.getBenefits().addAll(ranged.getBenefits());
}
return storeCallback(
dtOneMapper.mapDTOneRespToEntity(dvsCallbackDto),
ApiStatus.fromDtOne(dvsCallbackDto.getStatus().getId()),
Expand Down Expand Up @@ -244,7 +233,7 @@ private Uni<?> sendFPIAckMsg(RewardsTransStatus rewardsTransStatus, AbsMongoItem
}

private String retrievePinFromCallBack(RewardsTransStatus rewardsTransStatus, AbsMongoItem callbackResponse) {
String pin = StringUtils.EMPTY;
var pin = StringUtils.EMPTY;
if (StringUtils.equals(rewardsTransStatus.getLoadProvider(), LoadConst.PROV_DTONE)) {
var dvsCallback = (DVSCallback) callbackResponse;
if (dvsCallback.getPin() != null && StringUtils.isNotBlank(dvsCallback.getPin().getCode())) {
Expand Down

0 comments on commit a48ee67

Please sign in to comment.