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

io.polyapi.plugin.model.generation.ResolvedContext Maven / Gradle / Ivy

There is a newer version: 0.15.3
Show newest version
package io.polyapi.plugin.model.generation;

import io.polyapi.plugin.model.specification.resolved.*;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;

@Getter
public class ResolvedContext implements Generable {
    private final String name;
    private final String packageName;
    private final Set imports;
    private final String className;
    private final List subcontexts;
    private final List specifications;

    public ResolvedContext(String name, String packageName, Set imports, String className, List subcontexts, List specifications) {
        this.packageName = packageName;
        this.imports = imports;
        this.name = name;
        this.className = className;
        this.subcontexts = new ArrayList<>();
        Optional.ofNullable(subcontexts).ifPresent(this.subcontexts::addAll);
        this.specifications = new ArrayList<>();
        Optional.ofNullable(specifications).ifPresent(this.specifications::addAll);
    }

    public List getServerFunctionSpecifications() {
        return filterSpecifications(ResolvedServerFunctionSpecification.class);
    }

    public List getCustomFunctionSpecifications() {
        return filterSpecifications(ResolvedCustomFunctionSpecification.class);
    }

    public List getApiFunctionSpecifications() {
        return filterSpecifications(ResolvedApiFunctionSpecification.class);
    }

    public List getAuthFunctionSpecification() {
        return filterSpecifications(ResolvedAuthFunctionSpecification.class);
    }

    public List getSubresourceAuthFunctionSpecifications() {
        return filterSpecifications(ResolvedSubresourceAuthFunctionSpecification.class);
    }

    public List getStandardAuthFunctionSpecifications() {
        return filterSpecifications(ResolvedStandardAuthFunctionSpecification.class);
    }

    public List getServerVariableSpecifications() {
        return filterSpecifications(ResolvedServerVariableSpecification.class);
    }

    public List getWebhookHandlerSpecifications() {
        return filterSpecifications(ResolvedWebhookHandleSpecification.class);
    }

    public List getFunctionSpecifications() {
        return filterSpecifications(ResolvedDefaultFunctionSpecification.class);
    }

    private  List filterSpecifications(Class resolvedSpecificationClass) {
        return specifications.stream().filter(resolvedSpecificationClass::isInstance).map(resolvedSpecificationClass::cast).toList();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy