mirror of
https://github.com/valitydev/cashreg-adapter-orangedata.git
synced 2024-11-06 02:15:16 +00:00
parent
09438c1d12
commit
bc9325d211
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/build_utils" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
1
Jenkinsfile
vendored
1
Jenkinsfile
vendored
@ -12,5 +12,6 @@ build('cashreg-adapter-orangedata', 'java-maven') {
|
||||
def mvnArgs = '-DjvmArgs="-Xmx256m"'
|
||||
def useJava11 = true
|
||||
|
||||
env.skipSonar = 'true'
|
||||
javaServicePipeline(serviceName, useJava11, mvnArgs)
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e89b885839df8013df804d48ff24dff10c9c451e
|
||||
Subproject commit f42e059d9ec93826ba4ad23232eed8ce67bd5486
|
34
pom.xml
34
pom.xml
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.2.RELEASE</version>
|
||||
<version>2.3.4.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
@ -19,15 +19,13 @@
|
||||
<description>Application to interact with adapters kkt</description>
|
||||
|
||||
<properties>
|
||||
<sonar.jacoco.reportPath>target/sites/jacoco/jacoco.exec</sonar.jacoco.reportPath>
|
||||
<sonar.cobertura.reportPath>target/site/cobertura/coverage.xml</sonar.cobertura.reportPath>
|
||||
<java.version>11</java.version>
|
||||
<server.port>8022</server.port>
|
||||
<stage>dev</stage>
|
||||
<exposed.ports>${server.port}</exposed.ports>
|
||||
<project.maintainer>Anatoly Cherkasov <a.cherkasov@rbkmoney.com></project.maintainer>
|
||||
<dockerfile.Template>GENERATED DOCKER FILE</dockerfile.Template>
|
||||
<dockerfile.base.service.tag>bc95d0d6dc13c693acd2b274531a7d604b877bf3</dockerfile.base.service.tag>
|
||||
<dockerfile.registry>dr2.rbkmoney.com</dockerfile.registry>
|
||||
<dockerfile.base.service.tag>57e26d8ee999d7b0b50248c22afc63e6f926d276</dockerfile.base.service.tag>
|
||||
<dockerfile.registry>${env.REGISTRY}</dockerfile.registry>
|
||||
<shared.resources.version>0.3.8</shared.resources.version>
|
||||
<logstash-logback-encoder.version>5.2</logstash-logback-encoder.version>
|
||||
<woody.version>[1.1.21,)</woody.version>
|
||||
@ -36,8 +34,7 @@
|
||||
<error-mapping.version>1.0.6</error-mapping.version>
|
||||
<cashreg-proto.version>1.15-f4f228b</cashreg-proto.version>
|
||||
<adapter-common-lib.version>0.0.26</adapter-common-lib.version>
|
||||
<testcontainers.version>1.10.2</testcontainers.version>
|
||||
<adapter-cashreg-spring-boot-starter.version>1.0.2</adapter-cashreg-spring-boot-starter.version>
|
||||
<adapter-cashreg-spring-boot-starter.version>1.0.3</adapter-cashreg-spring-boot-starter.version>
|
||||
<spring-boot-starter-metrics-statsd.version>1.1.2</spring-boot-starter-metrics-statsd.version>
|
||||
<hibernate-validator.version>6.1.5.Final</hibernate-validator.version>
|
||||
<ipaddress.version>5.0.1</ipaddress.version>
|
||||
@ -188,12 +185,12 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-remote-resources-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<version>1.6.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>maven-filtering</artifactId>
|
||||
<version>1.3</version>
|
||||
<version>3.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
@ -220,23 +217,6 @@
|
||||
</nonFilteredFileExtensions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.2</version>
|
||||
<configuration>
|
||||
<destFile>${sonar.jacoco.reportPath}</destFile>
|
||||
<append>true</append>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>agent</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.rbkmoney.adapter.orangedata.configuration;
|
||||
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.config.properties.TimerProperties;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.service.IntentService;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.service.IntentServiceImpl;
|
||||
import com.rbkmoney.error.mapping.ErrorMapping;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ServiceConfiguration {
|
||||
|
||||
@Bean
|
||||
public IntentService intentService(ErrorMapping errorMapping, TimerProperties timerProperties) {
|
||||
return new IntentServiceImpl(errorMapping, timerProperties);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +1,45 @@
|
||||
package com.rbkmoney.adapter.orangedata.converter.exit;
|
||||
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.config.properties.TimerProperties;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.AdapterState;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.EntryStateModel;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.ExitStateModel;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.Step;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.service.IntentService;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.state.serializer.AdapterSerializer;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.utils.creators.CashregAdapterCreators;
|
||||
import com.rbkmoney.adapter.common.model.PollingInfo;
|
||||
import com.rbkmoney.damsel.cashreg.adapter.CashregResult;
|
||||
import com.rbkmoney.damsel.cashreg.adapter.Intent;
|
||||
import com.rbkmoney.damsel.domain.Failure;
|
||||
import com.rbkmoney.error.mapping.ErrorMapping;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.rbkmoney.adapter.cashreg.spring.boot.starter.utils.extractors.OptionsExtractors.extractMaxTimePolling;
|
||||
import static com.rbkmoney.adapter.cashreg.spring.boot.starter.utils.extractors.OptionsExtractors.extractPollingDelay;
|
||||
import static java.time.temporal.ChronoUnit.MINUTES;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ExitModelToProxyResultConverter implements Converter<ExitStateModel, CashregResult> {
|
||||
|
||||
private final ErrorMapping errorMapping;
|
||||
private final TimerProperties timerProperties;
|
||||
private final IntentService intentService;
|
||||
private final AdapterSerializer serializer;
|
||||
|
||||
@Override
|
||||
public CashregResult convert(ExitStateModel exitStateModel) {
|
||||
EntryStateModel entryStateModel = exitStateModel.getEntryStateModel();
|
||||
AdapterState adapterState = entryStateModel.getState().getAdapterContext();
|
||||
if (adapterState.getMaxDateTimePolling() == null) {
|
||||
int timerMaxTimePolling = extractMaxTimePolling(entryStateModel.getOptions(), timerProperties.getMaxTimePolling());
|
||||
Instant maxDateTime = Instant.now().plus(timerMaxTimePolling, MINUTES);
|
||||
adapterState.setMaxDateTimePolling(maxDateTime);
|
||||
|
||||
PollingInfo pollingInfo = new PollingInfo();
|
||||
if (adapterState.getPollingInfo() == null) {
|
||||
pollingInfo.setStartDateTimePolling(Instant.now());
|
||||
pollingInfo.setMaxDateTimePolling(intentService.extractMaxDateTimeInstant(entryStateModel));
|
||||
adapterState.setPollingInfo(pollingInfo);
|
||||
}
|
||||
|
||||
if (Step.CREATE == adapterState.getNextStep()) {
|
||||
adapterState.setNextStep(Step.CHECK_STATUS);
|
||||
}
|
||||
|
||||
Intent intent = prepareIntent(exitStateModel, entryStateModel);
|
||||
Intent intent = prepareIntent(exitStateModel);
|
||||
CashregResult cashRegResult = new CashregResult()
|
||||
.setIntent(intent)
|
||||
.setState(serializer.writeByte(adapterState));
|
||||
@ -56,13 +51,11 @@ public class ExitModelToProxyResultConverter implements Converter<ExitStateModel
|
||||
return cashRegResult;
|
||||
}
|
||||
|
||||
private Intent prepareIntent(ExitStateModel exitStateModel, EntryStateModel entryStateModel) {
|
||||
private Intent prepareIntent(ExitStateModel exitStateModel) {
|
||||
if (exitStateModel.getErrorCode() != null) {
|
||||
Failure failure = errorMapping.mapFailure(exitStateModel.getErrorCode(), exitStateModel.getErrorMessage());
|
||||
return CashregAdapterCreators.createFinishIntentFailure(failure);
|
||||
return intentService.getFailureByCodeAndDesc(exitStateModel);
|
||||
} else if (exitStateModel.getInfo() == null) {
|
||||
Map<String, String> options = entryStateModel.getOptions();
|
||||
return CashregAdapterCreators.createIntentWithSleepIntent(extractPollingDelay(options, timerProperties.getPollingDelay()));
|
||||
return intentService.getSleep(exitStateModel);
|
||||
} else {
|
||||
return CashregAdapterCreators.createFinishIntentSuccess();
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class ErrorProcessor implements Processor<ExitStateModel, EntryStateModel
|
||||
if (ErrorUtils.hasError(responseEntity)) {
|
||||
exitStateModel.setErrorCode(responseEntity.getStatusCode().toString());
|
||||
exitStateModel.setErrorMessage(responseEntity.getStatusCode().getReasonPhrase());
|
||||
} else if (adapterState.getMaxDateTimePolling().getEpochSecond() < currentTime.getEpochSecond()) {
|
||||
} else if (adapterState.getPollingInfo().getMaxDateTimePolling().getEpochSecond() < currentTime.getEpochSecond()) {
|
||||
log.error("Sleep Timeout for response: {}!", responseEntity);
|
||||
exitStateModel.setErrorCode(SLEEP_TIMEOUT.getCode());
|
||||
exitStateModel.setErrorMessage(SLEEP_TIMEOUT.getMessage());
|
||||
|
@ -36,9 +36,10 @@ restTemplate:
|
||||
adapter-cashreg:
|
||||
url: "https://apip.orangedata.ru:2443/api/v2/"
|
||||
---
|
||||
timer:
|
||||
maxTimePolling: 600
|
||||
pollingDelay: 600
|
||||
time:
|
||||
config:
|
||||
maxTimePolling: 600
|
||||
pollingDelay: 600
|
||||
---
|
||||
error-mapping:
|
||||
file: classpath:fixture/errors.json
|
||||
|
@ -3,6 +3,7 @@ package com.rbkmoney.adapter.orangedata.converter.exit;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.AdapterState;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.EntryStateModel;
|
||||
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.ExitStateModel;
|
||||
import com.rbkmoney.adapter.common.model.PollingInfo;
|
||||
import com.rbkmoney.adapter.orangedata.AbstractIntegrationTest;
|
||||
import com.rbkmoney.adapter.orangedata.TestData;
|
||||
import com.rbkmoney.adapter.orangedata.converter.entry.CtxToEntryModelConverter;
|
||||
@ -13,6 +14,9 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
@ -28,8 +32,15 @@ public class ExitModelToProxyResultConverterTest extends AbstractIntegrationTest
|
||||
@Test
|
||||
public void testExitModelToProxyResultConverter() {
|
||||
EntryStateModel entryStateModel = ctxConverter.convert(makeCashRegContext(Type.debit(new Debit())));
|
||||
AdapterState adapterState = new AdapterState();
|
||||
|
||||
PollingInfo pollingInfo = new PollingInfo();
|
||||
pollingInfo.setStartDateTimePolling(Instant.now());
|
||||
pollingInfo.setMaxDateTimePolling(Instant.now().plus(2, ChronoUnit.HOURS));
|
||||
adapterState.setPollingInfo(pollingInfo);
|
||||
|
||||
ExitStateModel exitStateModel = ExitStateModel.builder()
|
||||
.adapterContext(new AdapterState())
|
||||
.adapterContext(adapterState)
|
||||
.receiptId(TestData.CASHREG_ID)
|
||||
.entryStateModel(entryStateModel)
|
||||
.build();
|
||||
|
Loading…
Reference in New Issue
Block a user