<commit_before>package fedreg.core

class BootstrapController {
	def allowedMethods = [saveidp: 'POST', savesp: 'POST', saveorganization: 'POST']
	
	def IDPSSODescriptorService
	def SPSSODescriptorService
	def organizationService
	def grailsApplication
	
	def idp = {
		def identityProvider = new IDPSSODescriptor()
		[identityProvider: identityProvider, organizationList: Organization.findAllWhere(active:true, approved:true), attributeList: AttributeBase.list(), nameIDFormatList: SamlURI.findAllWhere(type:SamlURIType.NameIdentifierFormat)]
	}
	
	def saveidp = {
		def (created, ret) = IDPSSODescriptorService.create(params)
		
		if(created) {	
			log.info "Sucessfully registered ${ret.identityProvider} from public source"
			redirect (action: "idpregistered", id: ret.identityProvider.id)
		}
		else {
			flash.type="error"
			flash.message = message(code: 'fedreg.core.idpssoroledescriptor.register.validation.error')
			render (view:'idp', model:ret + [organizationList: Organization.findAllWhere(active:true, approved:true), attributeList: AttributeBase.list(), nameIDFormatList: SamlURI.findAllWhere(type:SamlURIType.NameIdentifierFormat)])
		}
	}
	
	def idpregistered = {
		if(!params.id) {
			log.warn "IDPSSODescriptor ID was not present"
			flash.type="error"
			flash.message = message(code: 'fedreg.controllers.namevalue.missing')
			redirect uri:"/"
			return
		}
		
		def identityProvider = IDPSSODescriptor.get(params.id)
		if (!identityProvider) {
			flash.type="error"
			flash.message = message(code: 'fedreg.core.idpssoroledescriptor.nonexistant')
			redirect uri:"/"
			return
		}
		
		[identityProvider: identityProvider]
	}
	
	def sp = {
		def serviceProvider = new SPSSODescriptor()
		[serviceProvider: serviceProvider, organizationList: Organization.findAllWhere(active:true, approved:true), attributeList: AttributeBase.list(), nameIDFormatList: SamlURI.findAllWhere(type:SamlURIType.NameIdentifierFormat)]
	}
	
	def savesp = {
		def (created, ret) = SPSSODescriptorService.create(params)
		
		if(created) {
			log.info "Sucessfully registered ${ret.serviceProvider} from public source"
			redirect (action: "spregistered", id: ret.serviceProvider.id)
		}
		else {
			flash.type="error"
			flash.message = message(code: 'fedreg.core.spssoroledescriptor.register.validation.error')
			render (view:'sp', model:ret + [organizationList: Organization.findAllWhere(active:true, approved:true), attributeList: AttributeBase.list(), nameIDFormatList: SamlURI.findAllWhere(type:SamlURIType.NameIdentifierFormat)])
		}
	}
	
	def spregistered = {
		if(!params.id) {
			log.warn "SPSSODescriptor ID was not present"
			flash.type="error"
			flash.message = message(code: 'fedreg.controllers.namevalue.missing')
			redirect uri:"/"
			return
		}
		
		def serviceProvider = SPSSODescriptor.get(params.id)
		if (!serviceProvider) {
			flash.type="error"
			flash.message = message(code: 'fedreg.core.spssoroledescriptor.nonexistant')
			redirect uri: "/"
			return
		}

		[serviceProvider: serviceProvider]
	}
	
	def organization = {
		def organization = new Organization()
		[organization:organization, organizationTypes: OrganizationType.list()]
	}
	
	def saveorganization = {
		def (created, organization, contact) = organizationService.create(params)
		<commit_msg>enforced attribute sort on bootstrap<commit_after>package fedreg.core

class BootstrapController {
	def allowedMethods = [saveidp: 'POST', savesp: 'POST', saveorganization: 'POST']
	
	def IDPSSODescriptorService
	def SPSSODescriptorService
	def organizationService
	def grailsApplication
	
	def idp = {
		def identityProvider = new IDPSSODescriptor()
		def c = AttributeBase.createCriteria()
		def attributeList = c.list {
			order("category", "asc")
			order("friendlyName", "asc")
		}
		[identityProvider: identityProvider, organizationList: Organization.findAllWhere(active:true, approved:true), attributeList: attributeList, nameIDFormatList: SamlURI.findAllWhere(type:SamlURIType.NameIdentifierFormat)]
	}
	
	def saveidp = {
		def (created, ret) = IDPSSODescriptorService.create(params)
		
		if(created) {	
			log.info "Sucessfully registered ${ret.identityProvider} from public source"
			redirect (action: "idpregistered", id: ret.identityProvider.id)
		}
		else {
			flash.type="error"
			flash.message = message(code: 'fedreg.core.idpssoroledescriptor.register.validation.error')
			def c = AttributeBase.createCriteria()
			def attributeList = c.list {
				order("category", "asc")
				order("friendlyName", "asc")
			}
			render (view:'idp', model:ret + [organizationList: Organization.findAllWhere(active:true, approved:true), attributeList: attributeList, nameIDFormatList: SamlURI.findAllWhere(type:SamlURIType.NameIdentifierFormat)])
		}
	}
	
	def idpregistered = {
		if(!params.id) {
			log.warn "IDPSSODescriptor ID was not present"
			flash.type="error"
			flash.message = message(code: 'fedreg.controllers.namevalue.missing')
			redirect uri:"/"
			return
		}
		
		def identityProvider = IDPSSODescriptor.get(params.id)
		if (!identityProvider) {
			flash.type="error"
			flash.message = message(code: 'fedreg.core.idpssoroledescriptor.nonexistant')
			redirect uri:"/"
			return
		}
		
		[identityProvider: identityProvider]
	}
	
	def sp = {
		def serviceProvider = new SPSSODescriptor()
		def c = AttributeBase.createCriteria()
		def attributeList = c.list {
			order("category", "asc")
			order("friendlyName", "asc")
		}
		[serviceProvider: serviceProvider, organizationList: Organization.findAllWhere(active:true, approved:true), attributeList: attributeList, nameIDFormatList: SamlURI.findAllWhere(type:SamlURIType.NameIdentifierFormat)]
	}
	
	def savesp = {
		def (created, ret) = SPSSODescriptorService.create(params)
		
		if(created) {
			log.info "Sucessfully registered ${ret.serviceProvider} from public source"
			redirect (action: "spregistered", id: ret.serviceProvider.id)
		}
		else {
			flash.type="error"
			flash.message = message(code: 'fedreg.core.spssoroledescriptor.register.validation.error')
			def c = AttributeBase.createCriteria()
			def attributeList = c.list {
				order("category", "asc")
				order("friendlyName", "asc")
			}
			render (view:'sp', model:ret + [organizationList: Organization.findAllWhere(active:true, approved:true), attributeList: attributeList, nameIDFormatList: SamlURI.findAllWhere(type:SamlURIType.NameIdentifierFormat)])
		}
	}
	
	def spregistered = {
		if(!params.id) {
			log.warn "SPSSODescriptor ID was not present"
			flash.type="error"
			flash.message = message(code: 'fedreg.controllers.namevalue.missing')
			redirect uri:"/"
			return
		}
		
		def serviceProvider = SPSSODescriptor.get(params.id)
		if (!serviceProvider) {
			flash.type="error"
			flash.message = message(code: 'fedreg.core.spssoroledescriptor.nonexistant')
			redirect uri: "/"
			return
		}

		[serviceProvider: serviceProvider]
	}
	
	def organization = {
		def organization = new Organization()
		[organization:organization, organizationTypes: OrganizationType.list()]
	}
	
	def saveorganization = {
		def (created, organization, contact) = organizationService.create(params)
		
{'fraction_non_alphanumeric': 0.11662217226359421, 'fraction_numerical': 0.0, 'mean_word_length': 5.047578589634664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2566141', 'n_tokens_mistral': 2441, 'n_tokens_neox': 2150, 'n_words': 432}