Search in sources :

Example 1 with NewMetadataEntity

use of io.gravitee.rest.api.model.NewMetadataEntity in project gravitee-management-rest-api by gravitee-io.

the class MetadataServiceImpl method create.

@Override
public MetadataEntity create(final NewMetadataEntity metadataEntity) {
    // if no format defined, we just set String format
    if (metadataEntity.getFormat() == null) {
        metadataEntity.setFormat(MetadataFormat.STRING);
    }
    try {
        // First we prevent the duplicate metadata name
        final Optional<MetadataEntity> optionalMetadata = findAllDefault().stream().filter(metadata -> metadataEntity.getName().equalsIgnoreCase(metadata.getName())).findAny();
        if (optionalMetadata.isPresent()) {
            throw new DuplicateMetadataNameException(optionalMetadata.get().getName());
        }
        checkMetadataValue(metadataEntity.getValue());
        checkMetadataFormat(metadataEntity.getFormat(), metadataEntity.getValue());
        final Metadata metadata = convert(metadataEntity);
        final Date now = new Date();
        metadata.setCreatedAt(now);
        metadata.setUpdatedAt(now);
        metadataRepository.create(metadata);
        // Audit
        auditService.createEnvironmentAuditLog(singletonMap(METADATA, metadata.getKey()), METADATA_CREATED, metadata.getCreatedAt(), null, metadata);
        return convert(metadata);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurred while trying to create metadata {}", metadataEntity.getName(), ex);
        throw new TechnicalManagementException("An error occurred while trying to create metadata " + metadataEntity.getName(), ex);
    }
}
Also used : URL(java.net.URL) Date(java.util.Date) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) Autowired(org.springframework.beans.factory.annotation.Autowired) MetadataRepository(io.gravitee.repository.management.api.MetadataRepository) InternetAddress(javax.mail.internet.InternetAddress) IdGenerator(io.gravitee.common.utils.IdGenerator) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) NotificationTemplateService(io.gravitee.rest.api.service.notification.NotificationTemplateService) AuditEvent(io.gravitee.repository.management.model.Metadata.AuditEvent) UpdateMetadataEntity(io.gravitee.rest.api.model.UpdateMetadataEntity) MetadataService(io.gravitee.rest.api.service.MetadataService) Collections.singletonMap(java.util.Collections.singletonMap) METADATA(io.gravitee.repository.management.model.Audit.AuditProperties.METADATA) MetadataReferenceType(io.gravitee.repository.management.model.MetadataReferenceType) Logger(org.slf4j.Logger) NewMetadataEntity(io.gravitee.rest.api.model.NewMetadataEntity) AuditService(io.gravitee.rest.api.service.AuditService) MetadataFormat(io.gravitee.rest.api.model.MetadataFormat) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Metadata(io.gravitee.repository.management.model.Metadata) StringReader(java.io.StringReader) DuplicateMetadataNameException(io.gravitee.rest.api.service.exceptions.DuplicateMetadataNameException) Optional(java.util.Optional) MetadataEntity(io.gravitee.rest.api.model.MetadataEntity) UpdateMetadataEntity(io.gravitee.rest.api.model.UpdateMetadataEntity) NewMetadataEntity(io.gravitee.rest.api.model.NewMetadataEntity) MetadataEntity(io.gravitee.rest.api.model.MetadataEntity) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) DuplicateMetadataNameException(io.gravitee.rest.api.service.exceptions.DuplicateMetadataNameException) Metadata(io.gravitee.repository.management.model.Metadata) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with NewMetadataEntity

use of io.gravitee.rest.api.model.NewMetadataEntity in project gravitee-management-rest-api by gravitee-io.

the class DefaultMetadataUpgrader method upgrade.

@Override
public boolean upgrade() {
    // initialize default metadata
    final MetadataEntity defaultEmailSupportMetadata = metadataService.findDefaultByKey(METADATA_EMAIL_SUPPORT_KEY);
    if (defaultEmailSupportMetadata == null) {
        logger.info("    No default metadata for email support found. Add default one.");
        final NewMetadataEntity metadata = new NewMetadataEntity();
        metadata.setFormat(MetadataFormat.MAIL);
        metadata.setName("Email support");
        metadata.setValue(DEFAULT_METADATA_EMAIL_SUPPORT);
        final MetadataEntity metadataEntity = metadataService.create(metadata);
        logger.info("    Added default metadata for email support with success: {}", metadataEntity);
    }
    return true;
}
Also used : NewMetadataEntity(io.gravitee.rest.api.model.NewMetadataEntity) MetadataEntity(io.gravitee.rest.api.model.MetadataEntity) NewMetadataEntity(io.gravitee.rest.api.model.NewMetadataEntity)

Aggregations

MetadataEntity (io.gravitee.rest.api.model.MetadataEntity)2 NewMetadataEntity (io.gravitee.rest.api.model.NewMetadataEntity)2 IdGenerator (io.gravitee.common.utils.IdGenerator)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 AuditEvent (io.gravitee.repository.management.model.Metadata.AuditEvent)1 MetadataReferenceType (io.gravitee.repository.management.model.MetadataReferenceType)1 MetadataFormat (io.gravitee.rest.api.model.MetadataFormat)1 UpdateMetadataEntity (io.gravitee.rest.api.model.UpdateMetadataEntity)1 AuditService (io.gravitee.rest.api.service.AuditService)1 MetadataService (io.gravitee.rest.api.service.MetadataService)1 DuplicateMetadataNameException (io.gravitee.rest.api.service.exceptions.DuplicateMetadataNameException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 NotificationTemplateService (io.gravitee.rest.api.service.notification.NotificationTemplateService)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collections.singletonMap (java.util.Collections.singletonMap)1