use of io.apiman.manager.api.rest.exceptions.InvalidParameterException in project apiman by apiman.
the class ApiService method updateApiVersion.
private ApiVersionBean updateApiVersion(ApiVersionBean avb, UpdateApiVersionBean update) throws ApiVersionNotFoundException {
if (avb.getStatus() == ApiStatus.Published) {
// If published and public API, then allow full modification (caveat emptor).
if (avb.isPublicAPI()) {
return updateApiVersionInternal(avb, update);
} else {
Set<UpdateApiPlanDto> updatePlans = Optional.ofNullable(update.getPlans()).orElse(Collections.emptySet());
// TODO refactor with HTTP PATCH?
if (updatePlans.size() != avb.getPlans().size()) {
throw new InvalidParameterException("Can not attach or remove plans from an API Version after it has been published");
}
// Collect just the ID and Versions (as these must be the same). Other fields can change freely.
Set<PlanIdVersion> existingPIV = avb.getPlans().stream().map(PlanIdVersion::new).collect(Collectors.toSet());
Set<PlanIdVersion> updatedPIV = updatePlans.stream().map(PlanIdVersion::new).collect(Collectors.toSet());
if (!existingPIV.equals(updatedPIV)) {
throw new InvalidParameterException("Plan IDs and versions must not change after publication");
}
// If published, then mapper copies across only fields that are safe for change after publication.
UpdateApiVersionBean afterPublishUpdate = ApiVersionMapper.INSTANCE.toPublishedUpdateBean(update);
return updateApiVersionInternal(avb, afterPublishUpdate);
}
} else {
return updateApiVersionInternal(avb, update);
}
}
Aggregations