Search in sources :

Example 1 with ApiMetadataNotFoundException

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);
    }
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) ApiService(io.gravitee.management.service.ApiService) DuplicateMetadataNameException(io.gravitee.management.service.exceptions.DuplicateMetadataNameException) ApiMetadataService(io.gravitee.management.service.ApiMetadataService) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Autowired(org.springframework.beans.factory.annotation.Autowired) AuditService(io.gravitee.management.service.AuditService) MetadataRepository(io.gravitee.repository.management.api.MetadataRepository) ApiMetadataNotFoundException(io.gravitee.management.service.exceptions.ApiMetadataNotFoundException) METADATA_UPDATED(io.gravitee.repository.management.model.Metadata.AuditEvent.METADATA_UPDATED) MetadataService(io.gravitee.management.service.MetadataService) IdGenerator(io.gravitee.common.utils.IdGenerator) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) METADATA_DELETED(io.gravitee.repository.management.model.Metadata.AuditEvent.METADATA_DELETED) Metadata(io.gravitee.repository.management.model.Metadata) io.gravitee.management.model(io.gravitee.management.model) METADATA_CREATED(io.gravitee.repository.management.model.Metadata.AuditEvent.METADATA_CREATED) MetadataReferenceType(io.gravitee.repository.management.model.MetadataReferenceType) METADATA(io.gravitee.repository.management.model.Audit.AuditProperties.METADATA) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Metadata(io.gravitee.repository.management.model.Metadata) ApiMetadataNotFoundException(io.gravitee.management.service.exceptions.ApiMetadataNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

IdGenerator (io.gravitee.common.utils.IdGenerator)1 io.gravitee.management.model (io.gravitee.management.model)1 ApiMetadataService (io.gravitee.management.service.ApiMetadataService)1 ApiService (io.gravitee.management.service.ApiService)1 AuditService (io.gravitee.management.service.AuditService)1 MetadataService (io.gravitee.management.service.MetadataService)1 ApiMetadataNotFoundException (io.gravitee.management.service.exceptions.ApiMetadataNotFoundException)1 DuplicateMetadataNameException (io.gravitee.management.service.exceptions.DuplicateMetadataNameException)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 MetadataRepository (io.gravitee.repository.management.api.MetadataRepository)1 METADATA (io.gravitee.repository.management.model.Audit.AuditProperties.METADATA)1 Metadata (io.gravitee.repository.management.model.Metadata)1 METADATA_CREATED (io.gravitee.repository.management.model.Metadata.AuditEvent.METADATA_CREATED)1 METADATA_DELETED (io.gravitee.repository.management.model.Metadata.AuditEvent.METADATA_DELETED)1 METADATA_UPDATED (io.gravitee.repository.management.model.Metadata.AuditEvent.METADATA_UPDATED)1 MetadataReferenceType (io.gravitee.repository.management.model.MetadataReferenceType)1 java.util (java.util)1 Collectors.toList (java.util.stream.Collectors.toList)1 Logger (org.slf4j.Logger)1