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

com.manywho.sdk.services.controllers.AbstractController Maven / Gradle / Ivy

package com.manywho.sdk.services.controllers;

import com.manywho.sdk.entities.ConfigurationValuesAware;
import com.manywho.sdk.entities.run.elements.config.ServiceRequest;
import com.manywho.sdk.entities.security.AuthenticatedWho;
import com.manywho.sdk.services.PropertyCollectionParser;
import com.manywho.sdk.services.actions.ActionParser;
import com.manywho.sdk.services.annotations.Action;
import org.glassfish.jersey.server.ContainerRequest;

import javax.inject.Inject;
import javax.ws.rs.core.Context;

public abstract class AbstractController {
    @Context
    protected ContainerRequest request;

    @Inject
    protected ActionParser actionParser;

    @Inject
    protected PropertyCollectionParser propertyCollectionParser;

    public AuthenticatedWho getAuthenticatedWho() {
        return (AuthenticatedWho) this.request.getProperty("AuthenticatedWho");
    }

    protected  T parseConfigurationValues(ConfigurationValuesAware configurationValuesAware, Class tClass) throws Exception {
        return propertyCollectionParser.parse(configurationValuesAware.getConfigurationValues(), tClass);
    }

    protected  T parseInputs(ServiceRequest serviceRequest, Class tClass) throws Exception {
        // If the given class to populate is an @Action, then parse using ActionParser
        if (tClass.isAnnotationPresent(Action.class)) {
            return actionParser.parseInputs(serviceRequest.getInputs(), tClass);
        }

        // Otherwise use the old style way
        return propertyCollectionParser.parse(serviceRequest.getInputs(), tClass);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy