Implement integration service
Service Base
For each service there will be an abstract class Service Base generated in the SDK.
The Service Base provides access to the integration entity builder and the event producer.
The Service Base contains one abstract method named execute.
This execute method needs to be implemented in the generated implementation file for the service.
Input & output entity
Service execute method will take a modelled Input Entity as a parameter.
Service execute method will return a modelled Output Entity as a return type.
Business errors
If service is modelled with Business Errors, it will be added as
throws
declaration to service execute method.
Injecting an API provider
It's very common to inject generated API Providers for an API Dependency and use them to integrate with external / internal apis.
//... other imports
// Import CreditIscoreApiIScore API provider from *iscore* integration namespace
import de.knowis.cards.operations.sdk.integration.iscore.iscorecheck.provider.CreditIscoreApiIScore;
// Declare integration API provider
private final CreditIscoreApiIScore iscoreApi;
// Adjust your generated integration service implemenation constructor
// to inject Iscore integration namespace API provider
public CheckIscoreService(IntegrationEntityBuilder entityBuilder, EventProducerService eventProducer CreditIscoreApiIScore iscoreApi) {
super(entityBuilder, eventProducer);
this.iscoreApi = iscoreApi;
}
Implementation example
Example of CheckIscore service implementation file.
//... imports
// Import CreditIscoreApiIScore api provider from *iscore* integration namespace
import de.knowis.cards.operations.sdk.integration.iscore.iscorecheck.provider.CreditIscoreApiIScore;
// Import IscoreResult from Iscore integration namespace API provider
import de.knowis.cards.operations.sdk.integration.iscore.iscorecheck.model.IscoreResult;
@Service
public class CheckIscoreService extends CheckIscoreServiceBase {
private static Logger log = LoggerFactory.getLogger(CheckIscoreService.class);
private final CreditIscoreApiIScore iscoreApi;
// Adjust your generated integration service constructor to inject Iscore API provider
public CheckIscoreService(IntegrationEntityBuilder entityBuilder,
EventProducerService eventProducer,
CreditIscoreApiIScore iscoreApi) {
super(entityBuilder, eventProducer);
this.iscoreApi = iscoreApi;
}
// Example of a service implemenation logic
@NewSpan
@Override
public IscoreCheck execute(Account accountDetails) throws IscoreCheckError {
log.info("CheckIscoreService.execute()");
try {
ResponseEntity<IscoreResult> iscoreResult =
iscoreApi.checkIscore(accountDetails.getAccountNumer);
} catch(Exception e) {
String errorMessage = String.format("Iscore check failed %s" ,e.getMessage());
throw new IscoreCheckError(errorMessage);
}
IscoreCheck iscoreCheck = this.entityBuilder.getIscore().getIscoreCheck().build();
iscoreCheck.setScore(iscoreResult.getScore());
iscoreCheck.setScoreComment(iscoreResult.getScoreComment());
return iscoreCheck;
}