use of io.gravitee.management.model.UpdateMetadataEntity 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());
}
checkMetadataFormat(metadataEntity.getFormat(), metadataEntity.getValue());
final Metadata metadata = convert(metadataEntity);
final Date now = new Date();
metadata.setUpdatedAt(now);
metadataRepository.update(metadata);
// Audit
auditService.createPortalAuditLog(Collections.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);
}
}
Aggregations