net.cpollet.maven.plugins.postman.EnvironmentsAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of postman-maven-plugin Show documentation
Show all versions of postman-maven-plugin Show documentation
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());
}
}