package gw.api.rating uses com.guidewire.pl.domain.persistence.core.impl.BundleInternal uses gw.api.locale.DisplayKey uses gw.api.rating.ParallelRatingInfo.ThreadInfo uses org.slf4j.Logger /** * Parallel Rater that works with EffDated objects */ class ParallelRater extends AbstractParallelRater { construct(description: String, logger: Logger) { super(description, logger) } protected override function getThreadInfo(bean: T): ThreadInfo { return new ThreadInfo("" + bean.ID + " " + bean.IntrinsicType, _logger) } override property get ThreadInfos(): List { return super.ThreadInfos } function rateInChildThread(bean: T, doRating(item: T): void) { /* * We need to get the bean we want to rate in this child thread's bundle. So first get the current thread, * which is a child of the main thread. */ var childThreadBundle = getChildThreadBundle() var initialState = saveInitialState(childThreadBundle) var beanInChildThreadBundle = getBeanInChildThreadBundle(bean, childThreadBundle) rate(beanInChildThreadBundle, doRating) validateBundleState(initialState, childThreadBundle) } private function getChildThreadBundle(): BundleInternal { var childThread = Thread.currentThread() as ParallelRatingThread return childThread.Bundle } /** * Store the initial state of the bundle associated with the first entry in this array so that we can check that * the bundle has not been modified. This check should only be done during development or testing. * There shouldn't be any modification to the child threads' bundles by the time the code is in production. */ private function saveInitialState(bundle: BundleInternal): BundleState { return ParallelRatingHelper.recordBundleState(bundle) } /** * Validate the final state of this child thread's bundle against the initial bundle. */ private function validateBundleState(initialState: BundleState, bundle: BundleInternal) { if (initialState != null) { initialState.validate(bundle) } } private function getBeanInChildThreadBundle(bean: T, bundle: BundleInternal): T { var beanInChildThreadBundle = ParallelRatingHelper.getBeanInBundle(bean, bundle) as T if (beanInChildThreadBundle == null) { throw new IllegalStateException(DisplayKey.get("BundleState.Error.EffDatedBeanNotFound")) } return beanInChildThreadBundle } }