Code Monkey home page Code Monkey logo

plugit-core-apex's Introduction

Plugit : A Module Framework For Apex

Ever wondered if the apex software blocks can be easily installed and plugged in into each other ?

  • Plugit tries to solve above problem by providing a base framework to design services which can be combined together using a keyword driven approach.
  • Implements Fluent Interface

Installation

Key Features

  • Develop modular and interoperable apex services called as plugits
  • Supports extensible service factory to add custom service factory
  • Service factory can be extended to hide implementation details of the service / plugit , i.e. the name of the service can be mapped to a local class or a remote service through the factory.
  • Without changing the consumer code we can swap the service implementation from local class to an external service. (eg AWS Lambda)
  • All default methods can be overriden to extend the framework
  • Use pipe keyword to easily chain multiple plugits like below

typical usage example

// load QueryAccounts plugit and pipe its output to next plugit and so on

Pluggable resultPlug = plugin('QueryAccounts')
    .exec( seedData)
    .pipe('ProcessActiveAccounts')
    .pipe('NotifyInActiveAccountOwners')
    .pass('HandleAccountSuccess')
    .fail('SendEmailToAdmin') //invoked if any of the plugit fails
    .fail('LogDebugToFile');

if( resultPlug.hasErrors() ){
    //access resultPlug.errors();
} else {
   Object result  = resultPlug.result();
}

Complete Sample Usage

Extend Plug base class

public class Calculator extends Plug {
	
    public override Object execute(Object data) {
        
        Pluggable addService = plugin('AdditionService')
            .exec( data )
            .pass( 'AdditionServicePassed' )
            .fail( 'AdditionServiceFailed' );

        Object resultValue = addService.result();

        if(  resultValue == null ){
        	System.debug( 'Errors In The Service '+addService.errors());
        }

        return resultValue;
    }
}

public class AdditionService extends Plug {
    public override Object execute(Object data) {

        Map<String,Decimal> dataMap = (Map<String,Decimal>)data;

        try {
            no1 = Integer.valueOf(dataMap.get('no1'));
            no2 = Integer.valueOf(dataMap.get('no2'));

            output('result',no1+no2);
            
            return no1+no2;

        } catch (Exception exp){
            //sets error state
            error('AdditionServiceException',exp);
        }
        
        return null;
    }
}

public class AdditionServicePassed extends Plug {

	public override Object execute(Object data) {

        System.debug(' outputResult ='+Decimal.valueOf(data));

        return data;
    }
}


public class AdditionServiceFailed extends Plug {

	public override Object execute(Object data) {

        //handle errors errors
        for( String errorKey : this.errors().keySet() ) {
        	System.debug(errorKey +' : '+ ((Exception)errors.get(errorKey)) );
            //handle errors here
        }

        return null;
    }
}

Invoke from a normal Apex class or from another Plugit

Normal Class :

Object result = Plug.plugin('CalculatorNanoService')
                    .exec(new Map<String,Decimal>{
                        'no1' => 1,
                        'no2' => 50
                    });

Another Plugit :

plugin('CalculatorNanoService')
      .exec(new Map<String,Decimal>{
	    'no1' => 1,
	    'no2' => null
      });

References

plugit-core-apex's People

Contributors

swapnilshrikhande avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

skolakan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.