}
/**
- * Template rules do not exists in the rule repository, only in database, but have to be updated from their parent rule.
+ * Template rules do not exists in rule repositories, only in database, they have to be updated from their parent.
*/
private List<Rule> registerTemplateRules(List<Rule> registeredRules, RulesByRepository existingRules, DatabaseSession session) {
List<Rule> templateRules = newArrayList();
if (parent != null && registeredRules.contains(parent)) {
persistedRule.setRepositoryKey(parent.getRepositoryKey());
persistedRule.setLanguage(parent.getLanguage());
- persistedRule.setStatus(parent.getStatus());
+ persistedRule.setStatus(Objects.firstNonNull(persistedRule.getStatus(), Rule.STATUS_READY));
+ persistedRule.setCreatedAt(Objects.firstNonNull(persistedRule.getCreatedAt(), new Date()));
persistedRule.setUpdatedAt(new Date());
session.saveWithoutFlush(persistedRule);
def self.up
Rule.reset_column_information
Rule.update_all({:status => 'READY', :created_at => Time.now}, ['enabled=?', true])
- Rule.update_all({:status => 'REMOVED', :updated_at => Time.now}, ['enabled=?', false])
+ Rule.update_all({:status => 'REMOVED', :created_at => Time.now, :updated_at => Time.now}, ['enabled=?', false])
end
end
rule = getSession().getSingleResult(Rule.class, "id", 4);
assertThat(rule.getRepositoryKey(), is("fake"));
assertThat(rule.getLanguage(), is("java"));
- // Status was READY in db, but parent status is now DEPRECATED
- assertThat(rule.getStatus(), is(Rule.STATUS_DEPRECATED));
+ // parent status is now DEPRECATED but template should not be changed
+ assertThat(rule.getStatus(), is(Rule.STATUS_READY));
}
@Test
}
@Test
- public void should_reactivate_disabled_template_rules() {
+ public void should_not_reactivate_disabled_template_rules() {
setupData("should_reactivate_disabled_template_rules");
task.start();
Rule rule = getSession().getSingleResult(Rule.class, "id", 2);
- assertThat(rule.getStatus(), is(Rule.STATUS_READY));
+ assertThat(rule.getStatus(), is(Rule.STATUS_REMOVED));
assertThat(rule.getUpdatedAt(), notNullValue());
}