Git Product home page Git Product logo

osgi-vat-checker's Introduction

License Build Status codecov Quality Gate Status

OSGi VIES VAT number validation

About

The project contains two OSGi bundles that provide online EU VAT number validation with VAT Information Exchange System (VIES).

  1. vat-checker-api.jar - Java model for VIES API
  2. vat-checker-service.jar - service client that uses classes generated from WSDL published by VIES

API

Bundle offers simple Java service interface:

package org.synus.vies.api;
public interface VatChecker {
    VatCheckerResult checkVat(Country country, String vatNumber);

The implementation catches all exceptions (logs them with slf4j) and always returns a result instance of type:

// ...
public class VatCheckerResult {

    private final Country country;
    private final String vatNumber;
    private final Optional<LocalDateTime> requestDate;
    private final boolean valid;
    private final Optional<String> name;
    private final Optional<String> address;
    private final Optional<VatCheckerError> error;
// ...

Result and error handling

Returned VatCheckerResult instance can be in following states:

  1. VAT valid: valid=true
  2. VAT invalid: valid=false and error is empty
  3. VAT checker error: valid=false and error has enum value
    public enum VatCheckerError {
        INVALID_INPUT,
        INVALID_REQUESTER_INFO,
        SERVICE_UNAVAILABLE,
        MS_UNAVAILABLE,
        TIMEOUT,
        VAT_BLOCKED,
        IP_BLOCKED,
        GLOBAL_MAX_CONCURRENT_REQ,
        GLOBAL_MAX_CONCURRENT_REQ_TIME,
        MS_MAX_CONCURRENT_REQ,
        MS_MAX_CONCURRENT_REQ_TIME,
        UNEXPECTED,
    }

Installation

Build and install both api and implementation jars on your osgi container.

$ ./gradlew build # to build both jars jar
$ cp vat-checker-api/build/libs/vat-checker-api-1.0.0.jar $MY_OSGI_CONTAINER
$ cp vat-checker-service/build/libs/vat-checker-service-1.0.0.jar $MY_OSGI_CONTAINER

Usage

Gradle project

build.gradle:

dependencies {
    compileOnly 'org.synus.vies:vat-checker-api:1.0.0'
}

Example: Liferay's gogo shell command

@Component(
        property = {"osgi.command.function=checkvat", "osgi.command.scope=blade"},
        service = Object.class
)
public class ExampleCommand {

    @Reference
    private volatile VatChecker vatChecker;

    public void checkvat(String country, String vatNumber) {
        System.out.println(vatChecker.checkVat(Country.valueOf(country), vatNumber).isValid());
    }

}
$ telnet localhost 11311
Welcome to Apache Felix Gogo

g! checkvat "SK" "2020216748"
true

Contributing

Want to hack on vat-checker? See CONTRIBUTING.md for information on building, testing and contributing changes.

They are probably not perfect, please let me know if anything feels wrong or incomplete.

License

The contents of this repository are made available to the public under the terms of the Apache License, Version 2.0. Bundles may depend on non Apache Licensed code.


osgi-vat-checker's People

Contributors

ktor avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

ivanf7

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.