From 38aa0c7eccf82fbf30e7618366f9f28878dd397d Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Thu, 28 Nov 2024 11:49:09 +0000 Subject: [PATCH] fix: Remove special Org transaction handling as it causes int tests to crash (Perf seems to be fine enough without it) --- .../olf/DependentModuleProxyService.groovy | 127 ++++++++---------- 1 file changed, 59 insertions(+), 68 deletions(-) diff --git a/service/grails-app/services/org/olf/DependentModuleProxyService.groovy b/service/grails-app/services/org/olf/DependentModuleProxyService.groovy index 0e90f36b..b1488793 100644 --- a/service/grails-app/services/org/olf/DependentModuleProxyService.groovy +++ b/service/grails-app/services/org/olf/DependentModuleProxyService.groovy @@ -21,76 +21,67 @@ public class DependentModuleProxyService { OkapiClient okapiClient public Org coordinateOrg(String orgName) { - Org.withSession { currentSess -> - Org.withTransaction { - Org.withNewSession { newSess -> - Org.withTransaction { - // Simply call the verb method on the client (get, post, put, delete). The client itself should take care of everything else. - // Get and Delete take the uri with optional params map for the query string. - // Post, Put and Patch take in the uri, data that can be converted to json (String or map) and optional params map for the query string. - Org org = Org.findByName(orgName) // This cannot be swapped for executeQuery SELECT -- possibly due to the bindUsingWhenRef - - if (!org) { - log.debug "No local org for ${orgName}. Check vendors." - - def mod_vendor_lookup_result = null; - if ( grailsApplication.config.getProperty('useModVendors', boolean) ) { - // This fetches a max of 2 (we should decide how to handle multiple matches) vendors with an exact name match. - mod_vendor_lookup_result = okapiClient.get("/vendor", [ - limit: 2, - query: ('(name=="' + orgName + '")') // CQL - ]) - } - else { - // Disable mod_vendor lookup - mod_vendor_lookup_result = [ total_records: 0 ] - } - - // Resp is a lazy map representation of the JSON returned by the module. - /* - { - "vendors" : [ ... ], - "total_records" : 0, - "first" : 0, - "last" : 0 - } - */ - - switch (mod_vendor_lookup_result.total_records) { - case 1: - // Exact match - def result = mod_vendor_lookup_result.vendors[0] - - org = new Org( - name: result.name, - orgsUuid: result.id, - sourceURI: "/vendor/${result.id}" - ).save( failOnError:true ) - break - - case 0: - // No match - // We should add in an option to create vendors if users configure that - if ( grailsApplication.config.getProperty('createMissingVendors', boolean) ) { - throw new RuntimeException("Not yet implemented"); - } - - // Create a new local one. - log.debug "No vendor found. Adding local org for ${orgName}" - org = (new Org(name:orgName)).save( failOnError:true ) - break - - default: - // Multiples. - log.debug "Multiple matches for vendor with name ${orgName}" - } - } - - return org - } - newSess.clear() + // Simply call the verb method on the client (get, post, put, delete). The client itself should take care of everything else. + // Get and Delete take the uri with optional params map for the query string. + // Post, Put and Patch take in the uri, data that can be converted to json (String or map) and optional params map for the query string. + Org org = Org.findByName(orgName) // This cannot be swapped for executeQuery SELECT -- possibly due to the bindUsingWhenRef + + if (!org) { + log.debug "No local org for ${orgName}. Check vendors." + + def mod_vendor_lookup_result = null; + if ( grailsApplication.config.getProperty('useModVendors', boolean) ) { + // This fetches a max of 2 (we should decide how to handle multiple matches) vendors with an exact name match. + mod_vendor_lookup_result = okapiClient.get("/vendor", [ + limit: 2, + query: ('(name=="' + orgName + '")') // CQL + ]) + } + else { + // Disable mod_vendor lookup + mod_vendor_lookup_result = [ total_records: 0 ] + } + + // Resp is a lazy map representation of the JSON returned by the module. + /* + { + "vendors" : [ ... ], + "total_records" : 0, + "first" : 0, + "last" : 0 } + */ + + switch (mod_vendor_lookup_result.total_records) { + case 1: + // Exact match + def result = mod_vendor_lookup_result.vendors[0] + + org = new Org( + name: result.name, + orgsUuid: result.id, + sourceURI: "/vendor/${result.id}" + ).save( failOnError:true ) + break + + case 0: + // No match + // We should add in an option to create vendors if users configure that + if ( grailsApplication.config.getProperty('createMissingVendors', boolean) ) { + throw new RuntimeException("Not yet implemented"); + } + + // Create a new local one. + log.debug "No vendor found. Adding local org for ${orgName}" + org = (new Org(name:orgName)).save( failOnError:true ) + break + + default: + // Multiples. + log.debug "Multiple matches for vendor with name ${orgName}" } } + + return org } }