use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessor method createModel.
private CustomCertificateModel createModel(CustomCertificateEntity entity) {
CustomCertificateModel customCertificateModel = new CustomCertificateModel(entity.getAlias(), entity.getCertificateContent(), DateUtils.formatDate(entity.getLastUpdated(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE));
customCertificateModel.setId(entity.getId());
return customCertificateModel;
}
use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class CertificateActions method updateWithoutChecks.
@Override
protected ActionResponse<CertificateModel> updateWithoutChecks(Long id, CertificateModel resource) {
try {
Optional<CustomCertificateModel> existingCertificate = certificateAccessor.getCertificate(id);
String logableId = escapeUtil.replaceWithUnderscore(resource.getId());
String loggableAlias = escapeUtil.replaceWithUnderscore(resource.getAlias());
logger.info("Updating certificate with id: {} and alias: {}", logableId, loggableAlias);
if (existingCertificate.isPresent()) {
CertificateModel certificateModel = importCertificate(resource);
return new ActionResponse<>(HttpStatus.NO_CONTENT, certificateModel);
}
logger.error("Certificate with id: {} missing.", logableId);
return new ActionResponse<>(HttpStatus.NOT_FOUND, "Certificate not found.");
} catch (AlertException ex) {
logger.error("Error occurred updating certificate", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class CertificateActions method deleteWithoutChecks.
@Override
protected ActionResponse<CertificateModel> deleteWithoutChecks(Long id) {
try {
Optional<CustomCertificateModel> certificate = certificateAccessor.getCertificate(id);
if (certificate.isPresent()) {
CustomCertificateModel certificateModel = certificate.get();
logger.info("Delete certificate with id: {} and alias: {}", certificateModel.getNullableId(), certificateModel.getAlias());
trustStoreService.removeCertificate(certificateModel);
certificateAccessor.deleteCertificate(id);
}
} catch (AlertException ex) {
logger.error("Error deleting certificate", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error deleting certificate: %s", ex.getMessage()));
}
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessorTest method deleteCertificateByIdTest.
@Test
public void deleteCertificateByIdTest() {
CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(alias, content, testDate);
DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository);
List<CustomCertificateModel> customCertificateModelList = customCertificateAccessor.getCertificates();
assertEquals(1, customCertificateModelList.size());
CustomCertificateModel customCertificateModel = customCertificateModelList.get(0);
testCustomCertificateModel(expectedCustomCertificateModel, customCertificateModel);
customCertificateAccessor.deleteCertificate(0L);
customCertificateModelList = customCertificateAccessor.getCertificates();
assertTrue(customCertificateModelList.isEmpty());
}
use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessorTest method deleteCertificateByAliasTest.
@Test
public void deleteCertificateByAliasTest() {
CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(alias, content, testDate);
DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository);
List<CustomCertificateModel> customCertificateModelList = customCertificateAccessor.getCertificates();
assertEquals(1, customCertificateModelList.size());
CustomCertificateModel customCertificateModel = customCertificateModelList.get(0);
testCustomCertificateModel(expectedCustomCertificateModel, customCertificateModel);
customCertificateAccessor.deleteCertificate(alias);
customCertificateModelList = customCertificateAccessor.getCertificates();
assertTrue(customCertificateModelList.isEmpty());
}
Aggregations