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

fix(dvs-client): missing fields in callback 3 #177

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading