use of com.synopsys.integration.alert.database.certificates.CustomCertificateEntity in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessor method storeCertificate.
@Override
public CustomCertificateModel storeCertificate(CustomCertificateModel certificateModel) throws AlertConfigurationException {
String alias = certificateModel.getAlias();
String certificateContent = certificateModel.getCertificateContent();
CustomCertificateEntity entityToSave = new CustomCertificateEntity(alias, certificateContent, DateUtils.createCurrentDateTimestamp());
Long id = certificateModel.getNullableId();
if (null == id) {
// Mimic keystore functionality
id = customCertificateRepository.findByAlias(alias).map(CustomCertificateEntity::getId).orElse(null);
} else if (!customCertificateRepository.existsById(id)) {
throw new AlertConfigurationException("A custom certificate with that id did not exist");
}
entityToSave.setId(id);
CustomCertificateEntity updatedEntity = customCertificateRepository.save(entityToSave);
return createModel(updatedEntity);
}
Aggregations