use of io.gravitee.management.service.exceptions.ApiMetadataNotFoundException in project gravitee-management-rest-api by gravitee-io.
the class ApiMetadataServiceImpl method findByIdAndApi.
@Override
public ApiMetadataEntity findByIdAndApi(final String metadataId, final String apiId) {
LOGGER.debug("Find metadata by id {} and api {}", metadataId, apiId);
try {
final List<MetadataEntity> defaultMedatata = metadataService.findAllDefault();
final Optional<Metadata> optMetadata = metadataRepository.findById(metadataId, apiId, MetadataReferenceType.API);
if (optMetadata.isPresent()) {
final Metadata metadata = optMetadata.get();
final Optional<MetadataEntity> optDefaultMetadata = defaultMedatata.stream().filter(metadataEntity -> metadata.getKey().equals(metadataEntity.getKey())).findAny();
final ApiMetadataEntity apiMetadataEntity = convert(metadata, apiId);
optDefaultMetadata.ifPresent(defMetadata -> apiMetadataEntity.setDefaultValue(defMetadata.getValue()));
return apiMetadataEntity;
}
throw new ApiMetadataNotFoundException(apiId, metadataId);
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to find metadata by id and API", ex);
throw new TechnicalManagementException("An error occurred while trying to find metadata by id and API", ex);
}
}
Aggregations