package gw.exportimport uses gw.api.database.IQueryBeanResult uses gw.api.database.Query uses gw.api.effdate.EffDatedFinderUtil @ReadOnly class PublicIdEntityFinder { /** * Finds a bean with given public id or creates a new bean. * Will throw if trying to find a bean with an invalid PublicID or if trying to create a new * non-EffDated bean * @return The found or created {@link KeyableBean} */ static function findBean(period : PolicyPeriod, id : String, beanType : Type) : KeyableBean { var beans = Query.make(beanType).compare("PublicID", Equals, id).withFindTemporaryBranches(true).select() if (beans.Empty) { return null } var bean = beans.single() if (bean typeis EffDated) { if (bean.BranchUntyped.ID != period.ID) { var beanQuery = Query.make(beanType) .withFindTemporaryBranches(true) .compare("BranchValue", Equals, period.ID) .compare("Fixed", Equals, bean.FixedId) EffDatedFinderUtil.addRestrictionsForEffectiveOnDate(beanQuery, period.EditEffectiveDate) var periodBeans = beanQuery.select() as IQueryBeanResult if (periodBeans.Empty) { return null } bean = periodBeans.single() } bean = bean.getSliceUntyped(period.EditEffectiveDate) } bean = period.Bundle.add(bean) return bean } }