All Downloads are FREE. Search and download functionalities are using the official Maven repository.

yakworks.rally.orgs.repo.OrgMemberRepo.groovy Maven / Gradle / Ivy

There is a newer version: 7.3.76
Show newest version
/*
* Copyright 2021 Yak.Works - Licensed under the Apache License, Version 2.0 (the "License")
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
package yakworks.rally.orgs.repo


import groovy.transform.CompileStatic

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.validation.Errors

import gorm.tools.repository.GormRepo
import gorm.tools.repository.GormRepository
import gorm.tools.repository.events.RepoListener
import gorm.tools.validation.Rejector
import yakworks.rally.orgs.OrgDimensionService
import yakworks.rally.orgs.model.OrgMember
import yakworks.rally.orgs.model.OrgType

@GormRepository
@CompileStatic
class OrgMemberRepo implements GormRepo {

    @Autowired(required = false)
    OrgDimensionService orgDimensionService

    @RepoListener
    void beforeValidate(OrgMember orgMember, Errors errors) {
        validateMembers(orgMember, errors)
    }

    void validateMembers(OrgMember orgMember, Errors errors){
        // For OrgMember, All parents levels for the given orgtype is required
        OrgType memOrgType = orgMember.org.type
        List parents = orgDimensionService.getParentLevels(memOrgType)

        for(OrgType orgtype : parents){
            String propName = orgtype.propertyName

            //these fields wont be in the member so continue if its one of them
            List excludeTypes = ['customer', 'custAccount', 'company']
            if(excludeTypes.contains(propName)) continue

            if(orgMember[propName] == null){
                Rejector.of(orgMember, errors).withNotNullError(propName)
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy