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

net.cpollet.maven.plugins.postman.EnvironmentsAdapter Maven / Gradle / Ivy

Go to download

A maven plugin to export JAX-RS annotated classes and methods to Postman collection

The newest version!
package net.cpollet.maven.plugins.postman;

import lombok.AllArgsConstructor;
import net.cpollet.maven.plugins.postman.frontend.api.Context;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@AllArgsConstructor
public class EnvironmentsAdapter {
    private final List environments;

    public Map contexts() throws DuplicateEnvironmentNameException {
        List duplicates = findDuplicates(extractNames());

        if (!duplicates.isEmpty()) {
            throw new DuplicateEnvironmentNameException(duplicates);
        }

        return environments.stream()
                .map(EnvironmentAdapter::new)
                .collect(Collectors.toMap(
                        EnvironmentAdapter::getName,
                        e -> Context.builder()
                                .baseUrl(e.getBaseUrl())
                                .username(e.getUsername())
                                .password(e.getPassword())
                                .build()
                ));
    }

    private List findDuplicates(List names) {
        return names.stream()
                .distinct()
                .filter(e -> Collections.frequency(names, e) > 1)
                .collect(Collectors.toList());
    }

    private List extractNames() {
        return environments.stream()
                .map(Environment::getName)
                .collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy