Implement Integration Service

Service Base

  • For each service there will be an abstract class Service Base generated in the SDK.

  • The Service Base provide access to integration entity builder and event producer.

  • The Service Base contains one abstract method named execute.

  • This execute method needs to be implemented in the generated implementaion file for the service.

Input & Output Entity

  • Service execute method will take modelled Input Entity as a paramter.

  • Service execute method will return 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

  • Its very common to inject generated API Providers for api dependency and use them to integrate with extenral / internal apis.

    //... other imports

    // Import CreditIscoreApiIScore api provider from *iscore* integraion 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 implemenation file.

    //... imports

    // Import CreditIscoreApiIScore api provider from *iscore* integraion namespace
    import de.knowis.cards.operations.sdk.integration.iscore.iscorecheck.provider.CreditIscoreApiIScore;

    // Import IscoreResult from Iscore integraion 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;
        }