public static boolean isAggregate(String fqcn) { return fromType(fqcn).isPresent(); }
public static Optional<AggregateType> fromType(String fqcn) { for(AggregateType aggregateType : values()){ if(aggregateType.isApplicableTo(fqcn)) { return Optional.of(aggregateType); } } return Optional.absent(); }
@Override public <T> T mapRequest( EndpointParamDef endpointParamDef, RestxRequest request, RestxRequestMatch match, EndpointParameterKind parameterKind) { List<String> values = parameterKind.extractQueryParamStringedValuesFor(endpointParamDef, request, match); if(values == null) { return null; } final Optional<AggregateType> aggregateType = AggregateType.fromType(endpointParamDef.getRawType().getCanonicalName()); if(!aggregateType.isPresent()) { throw new IllegalStateException("Called mapRequest() on base type aggregate whereas it is not considered as an aggregate !"); } final Class aggregatedType = AggregateType.aggregatedTypeOf(endpointParamDef.getType()); List convertedValues = FluentIterable.from(values).transform(new Function<String, Object>() { @Override public Object apply(String requestValue) { return baseTypeEndpointParameterMapper.convertRequestParamValue(Optional.fromNullable(requestValue), aggregatedType, aggregatedType); } }).toList(); return (T) aggregateType.get().createFrom(convertedValues, aggregatedType); }
public static ParameterExpressionBuilder createFromMapQueryObjectFromRequest( RestxAnnotationProcessor.ResourceMethodParameter parameter, EndpointParameterKind kind){ // We should check if target type is an iterable interface : in that case, we should // instantiate an empty iterable instead of null value if data is missing in request Optional<AggregateType> aggregateType = AggregateType.fromType(parameter.type); String emptySupplierParam = ""; if(aggregateType.isPresent()) { Function<String, String> fqcnToEmptyAggregateTransformer = EMPTY_AGGREGATE_FUNCTIONS.get(aggregateType.get()); if(fqcnToEmptyAggregateTransformer == null) { throw new IllegalStateException("Missing EMPTY_AGGREGATE_FUNCTIONS entry for aggregate type "+aggregateType.get().name()); } emptySupplierParam = ", "+fqcnToEmptyAggregateTransformer.apply(parameter.type); } return new ParameterExpressionBuilder(String.format( "%smapQueryObjectFromRequest(%s.class, \"%s\", request, match, EndpointParameterKind.%s%s)", TypeHelper.isParameterizedType(parameter.type)?"("+parameter.type+")":"", TypeHelper.rawTypeFrom(parameter.type), parameter.reqParamName, kind.name(), emptySupplierParam ), kind.name()); } }
public boolean isBaseTypeAggregateParam(EndpointParamDef endpointParamDef) { return AggregateType.isAggregate(endpointParamDef.getRawType().getCanonicalName()); } }
@Override public <T> T mapRequest( EndpointParamDef endpointParamDef, RestxRequest request, RestxRequestMatch match, EndpointParameterKind parameterKind) { List<String> values = parameterKind.extractQueryParamStringedValuesFor(endpointParamDef, request, match); if(values == null) { return null; } final Optional<AggregateType> aggregateType = AggregateType.fromType(endpointParamDef.getRawType().getCanonicalName()); if(!aggregateType.isPresent()) { throw new IllegalStateException("Called mapRequest() on base type aggregate whereas it is not considered as an aggregate !"); } final Class aggregatedType = AggregateType.aggregatedTypeOf(endpointParamDef.getType()); List convertedValues = FluentIterable.from(values).transform(new Function<String, Object>() { @Override public Object apply(String requestValue) { return baseTypeEndpointParameterMapper.convertRequestParamValue(Optional.fromNullable(requestValue), aggregatedType, aggregatedType); } }).toList(); return (T) aggregateType.get().createFrom(convertedValues, aggregatedType); }
public boolean isBaseTypeAggregateParam(EndpointParamDef endpointParamDef) { return AggregateType.isAggregate(endpointParamDef.getRawType().getCanonicalName()); } }
public static boolean isAggregate(String fqcn) { return fromType(fqcn).isPresent(); }
if(AggregateType.isAggregate(parameter.type)) { } else {
public static Optional<AggregateType> fromType(String fqcn) { for(AggregateType aggregateType : values()){ if(aggregateType.isApplicableTo(fqcn)) { return Optional.of(aggregateType); } } return Optional.absent(); }