All Downloads are FREE. Search and download functionalities are using the official Maven repository.

core.dynamic.resources.ApiFactory Maven / Gradle / Ivy

Go to download

Epikos is a Rest Serivce framework which can be extend to develop any other Rest API/Services. For more detail please checkout github (https://github.com/epikosrest/epikos.git)

There is a newer version: 0.0.7.8.1
Show newest version
package core.dynamic.resources;

import core.exception.EpikosException;
import core.lib.Utility;

/**
 * Created by nitina on 1/14/17.
 */
public class ApiFactory {

    public static Api constructApiByType(Api api) throws EpikosException{

        Api returnApi = api;

        switch (api.getMethod()){
            case "GET":
                returnApi = new GetApi();
                copyProperties(api,returnApi);
                break;
            case "POST":
                returnApi = new PostApi();
                copyProperties(api,returnApi);
                break;
            case "DELETE":
                returnApi = new DeleteApi();
                copyProperties(api,returnApi);
                break;
            case "PUT":
                returnApi = new PutApi();
                copyProperties(api,returnApi);
                break;
            case "PATCH":
                returnApi = new PatchApi();
                copyProperties(api,returnApi);
                break;
            default:
                if(!Utility.hasResourceTypeImplementInterfaceListed(api.getMethod(),IMethod.class.getTypeName())) {
                    throw new EpikosException(String.format("Invalid method type %s", api.getMethod()));
                }

        }
        return returnApi;
    }


    private static void copyProperties(Api sourceApi, Api destinationApi){
        destinationApi.setConsume(sourceApi.getConsume());
        destinationApi.setController(sourceApi.getController());
        destinationApi.setMethod(sourceApi.getMethod());
        destinationApi.setPath(sourceApi.getPath());
        destinationApi.setProduce(sourceApi.getProduce());
        destinationApi.setRequest(sourceApi.getRequest());
        destinationApi.setResponse(sourceApi.getResponse());
        destinationApi.setResponseSpoof(sourceApi.getResponseSpoof());
        destinationApi.setServiceMode(sourceApi.getServiceMode());
        destinationApi.setStatus(sourceApi.getStatus());
        destinationApi.setResponseList(sourceApi.getResponseList());
        destinationApi.setApiParamList(sourceApi.getApiParamList());

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy