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

org.leandreck.endpoints.processor.model.EndpointNode Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
/**
 * Copyright © 2016 Mathias Kowalzik ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.leandreck.endpoints.processor.model;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;

/**
 * Created by Mathias Kowalzik ([email protected]) on 27.08.2016.
 */
public class EndpointNode {

    private final String serviceName;
    private final String serviceURL;
    private final String template;
    private final List methods;
    private final List getMethods;
    private final List headMethods;
    private final List postMethods;
    private final List putMethods;
    private final List patchMethods;
    private final List deleteMethods;
    private final List optionsMethods;
    private final List traceMethods;
    private final Set types;

    public EndpointNode(final String serviceName, final String serviceURL, String template, final List methods) {
        this.serviceName = serviceName;
        this.serviceURL = serviceURL;
        this.template = template;
        this.methods = methods;

        this.getMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("get")).collect(toList());
        this.headMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("head")).collect(toList());
        this.postMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("post")).collect(toList());
        this.putMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("put")).collect(toList());
        this.patchMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("patch")).collect(toList());
        this.deleteMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("delete")).collect(toList());
        this.optionsMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("options")).collect(toList());
        this.traceMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("trace")).collect(toList());

        this.types = this.getMethods().stream()
                .map(MethodNode::getReturnType)
                .map(EndpointNode::flatten)
                .flatMap(Collection::stream)
                .filter(c -> !c.isMappedType())
                .filter(c -> TypeNodeKind.SIMPLE.equals(c.getKind()))
                .collect(toSet());
    }

    public String getServiceName() {
        return serviceName;
    }

    public String getServiceURL() {
        return serviceURL;
    }

    public List getMethods() {
        return methods;
    }

    public String getTemplate() {
        return template;
    }

    public Set getTypes() {
        return types;
    }

    private static Collection flatten(TypeNode root) {
        final Set typeSet = root.getChildren().stream()
                .map(EndpointNode::flatten)
                .flatMap(Collection::stream)
                .filter(c -> !c.isMappedType())
                .collect(toSet());
        typeSet.add(root);
        return typeSet;
    }

    public List getGetMethods() {
        return getMethods;
    }

    public List getHeadMethods() {
        return headMethods;
    }

    public List getPostMethods() {
        return postMethods;
    }

    public List getTraceMethods() {
        return traceMethods;
    }

    public List getOptionsMethods() {
        return optionsMethods;
    }

    public List getDeleteMethods() {
        return deleteMethods;
    }

    public List getPatchMethods() {
        return patchMethods;
    }

    public List getPutMethods() {
        return putMethods;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy