Search in sources :

Example 1 with CustomCertificateEntity

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);
}
Also used : CustomCertificateEntity(com.synopsys.integration.alert.database.certificates.CustomCertificateEntity) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Aggregations

AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 CustomCertificateEntity (com.synopsys.integration.alert.database.certificates.CustomCertificateEntity)1