RESULT compare(final Map.Entry<String, ? extends AbstractParam> abstractParamPair, final Template template) { Preconditions.checkNotNull(abstractParamPair); Preconditions.checkNotNull(template); final AbstractParam paramAsHeader = template.getHeaders().get(abstractParamPair.getKey()); final AbstractParam paramAsQueryParam = template.getQueryParameters().get(abstractParamPair.getKey()); if (paramAsHeader == null && paramAsQueryParam == null) { return RESULT.NOT_FOUND; } final boolean isHeaderCompatible = compare(paramAsHeader, abstractParamPair.getValue()); final boolean isQueryParamCompatible = compare(paramAsQueryParam, abstractParamPair.getValue()); return isHeaderCompatible || isQueryParamCompatible ? RESULT.MATCHES : RESULT.NOT_MATCHES; }
private ParameterGroup transformTemplate(final Context context, final String templateName, final Template template, final TransformationContext ctx) { final Map<String, Template> currentTrait = Collections.singletonMap(templateName, template); final ParameterGroupBuilder builder = ParameterGroup.builder()// .qualifier(templateName)// .name(template.getDisplayName())// .description(template.getDescription())// .parameters(headerTransformer.transform(context, template.getHeaders(), ctx.getNamespace(), currentTrait))// .parameters(queryTransformer.transform(context, template.getQueryParameters(), ctx.getNamespace(), currentTrait))// .namespace(ctx.getNamespace()); return builder.build(); } }
private void decorateWithGroup(final ParameterBuilder builder, final Map.Entry<String, Template> matchingTemplate, final APINamespace namespace) { if (matchingTemplate != null) { final ParameterGroup.ParameterGroupBuilder groupBuilder = ParameterGroup.builder(); groupBuilder.description(matchingTemplate.getValue().getDescription()); groupBuilder.name("Group of parameters for trait : " + matchingTemplate.getKey()); groupBuilder.qualifier(matchingTemplate.getKey()); groupBuilder.namespace(namespace); decorateGroupWithBeanAnnotation(groupBuilder); decorateGroupWithValidAnnotation(groupBuilder); builder.group(groupBuilder.build()); } }
/** * Retrieves matching map of (traitName, Trait) pairs for the given list of traits applicable for given * AbstractParam. * The list of applicable traits is ordered from the least to the most specific. * * @param abstractParamPair a given AbstractParam pair (paramName, AbstractParam) to look for match * @param templates a map of (traitName, Trait) to look for the match with * @return the order matching pairs of (traitName, Trait) */ public Map<String, Template> matches(final Map.Entry<String, ? extends AbstractParam> abstractParamPair, final Map<String, Template> templates) { final Map<String, Template> result = new LinkedHashMap<>(); if (templates == null) { return result; } for (final Map.Entry<String, Template> template : Lists.reverse(new ArrayList<>(templates.entrySet()))) { final AbstractParam paramAsHeader = template.getValue().getHeaders().get(abstractParamPair.getKey()); final AbstractParam paramAsQueryParam = template.getValue().getQueryParameters().get(abstractParamPair.getKey()); if (paramAsHeader != null || paramAsQueryParam != null) { result.put(template.getKey(), template.getValue()); } } return result; }