use of io.gravitee.rest.api.model.MetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class MetadataServiceImpl method update.
@Override
public MetadataEntity update(final UpdateMetadataEntity metadataEntity) {
try {
// First we prevent the duplicate metadata name
final Optional<Metadata> optionalMetadata = metadataRepository.findByReferenceType(MetadataReferenceType.DEFAULT).stream().filter(metadata -> !metadataEntity.getKey().equals(metadata.getKey()) && 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.setUpdatedAt(now);
metadataRepository.update(metadata);
// Audit
auditService.createEnvironmentAuditLog(singletonMap(METADATA, metadata.getKey()), METADATA_UPDATED, metadata.getCreatedAt(), null, metadata);
return convert(metadata);
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to update metadata {}", metadataEntity.getName(), ex);
throw new TechnicalManagementException("An error occurred while trying to update metadata " + metadataEntity.getName(), ex);
}
}
use of io.gravitee.rest.api.model.MetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class MetadataServiceImpl method convert.
private MetadataEntity convert(final Metadata metadata) {
final MetadataEntity metadataEntity = new MetadataEntity();
metadataEntity.setKey(metadata.getKey());
metadataEntity.setName(metadata.getName());
metadataEntity.setValue(metadata.getValue());
metadataEntity.setFormat(MetadataFormat.valueOf(metadata.getFormat().name()));
return metadataEntity;
}
use of io.gravitee.rest.api.model.MetadataEntity 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);
}
}
use of io.gravitee.rest.api.model.MetadataEntity 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;
}
Aggregations