use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceImpl method findById.
@Override
public QualityRuleEntity findById(String id) {
try {
LOGGER.debug("Find quality rule by id : {}", id);
Optional<QualityRule> qualityRule = qualityRuleRepository.findById(id);
if (qualityRule.isPresent()) {
return convert(qualityRule.get());
}
throw new QualityRuleNotFoundException(id);
} catch (TechnicalException ex) {
final String error = "An error occurs while trying to find a quality rule using its ID: " + id;
LOGGER.error(error, ex);
throw new TechnicalManagementException(error, ex);
}
}
use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceImpl method convert.
private QualityRule convert(final NewQualityRuleEntity qualityRuleEntity) {
final QualityRule qualityRule = new QualityRule();
qualityRule.setId(UuidString.generateRandom());
qualityRule.setName(qualityRuleEntity.getName());
qualityRule.setDescription(qualityRuleEntity.getDescription());
qualityRule.setWeight(qualityRuleEntity.getWeight());
final Date now = new Date();
qualityRule.setCreatedAt(now);
qualityRule.setUpdatedAt(now);
return qualityRule;
}
use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceImpl method convert.
private QualityRule convert(final UpdateQualityRuleEntity qualityRuleEntity, final QualityRule qr) {
final QualityRule qualityRule = new QualityRule();
qualityRule.setId(qualityRuleEntity.getId());
qualityRule.setName(qualityRuleEntity.getName());
qualityRule.setDescription(qualityRuleEntity.getDescription());
qualityRule.setWeight(qualityRuleEntity.getWeight());
qualityRule.setCreatedAt(qr.getCreatedAt());
qualityRule.setUpdatedAt(new Date());
return qualityRule;
}
use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceImpl method update.
@Override
public QualityRuleEntity update(UpdateQualityRuleEntity updateEntity) {
try {
final Optional<QualityRule> optionalQualityRule = qualityRuleRepository.findById(updateEntity.getId());
if (!optionalQualityRule.isPresent()) {
throw new QualityRuleNotFoundException(updateEntity.getId());
}
final QualityRule qualityRule = qualityRuleRepository.update(convert(updateEntity, optionalQualityRule.get()));
auditService.createEnvironmentAuditLog(singletonMap(QUALITY_RULE, qualityRule.getId()), QUALITY_RULE_UPDATED, qualityRule.getUpdatedAt(), optionalQualityRule.get(), qualityRule);
return convert(qualityRule);
} catch (TechnicalException e) {
LOGGER.error("An error occurs while trying to update quality rule {}", updateEntity, e);
throw new TechnicalManagementException("An error occurs while trying to update quality rule " + updateEntity, e);
}
}
use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceTest method shouldDelete.
@Test
public void shouldDelete() throws TechnicalException {
final QualityRule qualityRule = mock(QualityRule.class);
when(qualityRuleRepository.findById(QUALITY_RULE_ID)).thenReturn(of(qualityRule));
qualityRuleService.delete(QUALITY_RULE_ID);
verify(qualityRuleRepository, times(1)).delete(QUALITY_RULE_ID);
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(QUALITY_RULE, QUALITY_RULE_ID)), eq(QualityRule.AuditEvent.QUALITY_RULE_DELETED), any(Date.class), isNull(), eq(qualityRule));
verify(apiQualityRuleRepository, times(1)).deleteByQualityRule(QUALITY_RULE_ID);
}
Aggregations