Skip to content

Commit

Permalink
refactor: Private active check method
Browse files Browse the repository at this point in the history
Moved logic for checking active ruleset to private method within controller
  • Loading branch information
Jack-Golding committed Oct 17, 2024
1 parent c65dcf7 commit d2b2183
Showing 1 changed file with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class SerialRulesetController extends OkapiTenantAwareController<SerialRuleset>
respond result
}

//Check to see if new ruleset is active, if it is, additionally set the current active ruleset to deprecated
private void activeRulesetCheck(SerialRuleset ruleset) {
if(ruleset?.rulesetStatus?.value == 'active'){
String activeRulesetId = serialRulesetService.findActive(ruleset?.owner?.id)
if(activeRulesetId){
serialRulesetService.updateRulesetStatus(activeRulesetId, 'deprecated')
}
}
}

@Transactional
def replaceAndDelete() {
SerialRuleset.withTransaction {
Expand All @@ -78,13 +88,8 @@ class SerialRulesetController extends OkapiTenantAwareController<SerialRuleset>
}
// New ruleset
SerialRuleset ruleset = new SerialRuleset(data)
//Check to see if new ruleset is active, if it is, additionally set the current active ruleset to deprecated
if(ruleset?.rulesetStatus?.value == 'active'){
String activeRulesetId = serialRulesetService.findActive(ruleset?.owner?.id)
if(activeRulesetId){
serialRulesetService.updateRulesetStatus(activeRulesetId, 'deprecated')
}
}
activeRulesetCheck(ruleset)

ruleset.save(failOnError: true)
if(ruleset.hasErrors()) {
transactionStatus.setRollbackOnly()
Expand Down Expand Up @@ -112,12 +117,8 @@ class SerialRulesetController extends OkapiTenantAwareController<SerialRuleset>
// New ruleset
SerialRuleset ruleset = new SerialRuleset(data)
//Check to see if new ruleset is active, if it is, additionally set the current active ruleset to deprecated
if(ruleset?.rulesetStatus?.value == 'active'){
String activeRulesetId = serialRulesetService.findActive(ruleset?.owner?.id)
if(activeRulesetId){
serialRulesetService.updateRulesetStatus(activeRulesetId, 'deprecated')
}
}
activeRulesetCheck(ruleset)

ruleset.save(failOnError: true)
if(ruleset.hasErrors()) {
transactionStatus.setRollbackOnly()
Expand All @@ -134,12 +135,8 @@ class SerialRulesetController extends OkapiTenantAwareController<SerialRuleset>
SerialRuleset.withTransaction {
def data = getObjectToBind()
SerialRuleset ruleset = new SerialRuleset(data)
if(ruleset?.rulesetStatus?.value == 'active'){
String activeRulesetId = serialRulesetService.findActive(ruleset?.owner?.id)
if(activeRulesetId){
serialRulesetService.updateRulesetStatus(activeRulesetId, 'deprecated')
}
}
activeRulesetCheck(ruleset)

ruleset.save(failOnError: true)
if(ruleset.hasErrors()) {
transactionStatus.setRollbackOnly()
Expand Down

0 comments on commit d2b2183

Please sign in to comment.