package gw.beantransfer uses com.google.common.base.Preconditions uses com.guidewire.pl.system.bundle.EntityBundleImpl uses gw.api.beantransfer.BeanTransferException uses gw.api.locale.DisplayKey uses gw.entity.IEntityType uses gw.pl.persistence.core.Key uses gw.pl.persistence.core.Bean /** * This interface defines a handler (or observer) methods for importing a KeyableBean. */ interface BeanImportHandler { /** * Callback for bean import. It is used to retrieve an existing entity instance. If this method returns a non-null, * no new instance will be created. This callback is called before setIdOnBean(KeyableBean, String). * * @param entityType the entityType it is to find * @param publicId the public ID it is to find * @return */ function findEntityById(entityType : IEntityType, publicId : String) : KeyableBean { return null } /** * Callback for bean import. It is used to set the ID's of the bean. This method is called after each bean instance * is either newly created or retrieved from somewhere, but before any of its properties is set. It is called after * findEntityById(IEntityType, String). * * This callback does not get called for referenced beans. Since referenced beans should already exist in the * destination system, there's no need to set the ID's on these beans. * * @param bean the KeyableBean to be imported * @param dbId the DB ID defined in the bean XML. */ function setIdOnBean(bean : KeyableBean, dbId : String) {} /** * Callback for bean import. This method is called after all the beans have been created and added to the bundle. * The EffDated beans in the bundle are unsliced. It is used to perform any post processing of the bean(s) related to * this handler. */ function handlePostImport(info : Set) {} /** * Extracts a unique inserted (new) bean of given type from the bean transfer import bundle * * @param type type of bean to extract * @param info set of transfer rootinfo * @param acceptMultipleRoots if false then an exception is thrown if info set contains multiple rootinfos * @return unique inserted (new) bean of given type in bundle, null if none found * @throws BeanTransferException if multiple beans of given type are found * @throws BeanTransferException if acceptMultipleRoots is false and info set contains multiple elements * @throws BeanTransferException if multiple bundles found linked to the info set * @throws IllegalArgumentException if info is empty */ reified function extractUniqueImportedBeanFromRootBundle(type : Class, info : Set, acceptMultipleRoots : boolean = false) : T { var beansInBundle = extractImportedBeansFromRootBundle(type,info,acceptMultipleRoots) if (beansInBundle.Count > 1) { throw new BeanTransferException(DisplayKey.get("BeanTransfer.BeanImportHandler.Error.BeanNotUnique",type)) } else if (beansInBundle.Count == 0) { return null } return beansInBundle.single() } /** * Extracts all inserted (new) beans of given type from the bean transfer import bundle * * @param type type of bean to extract * @param info set of transfer rootinfo * @param acceptMultipleRoots if false then an exception is thrown if info set contains multiple rootinfos * @return all inserted (new) beans of given type in bundle * @throws BeanTransferException if acceptMultipleRoots is false and info set contains multiple elements * @throws BeanTransferException if multiple bundles found linked to the info set * @throws IllegalArgumentException if info is empty */ reified function extractImportedBeansFromRootBundle(type : Class, info : Set, acceptMultipleRoots : boolean = false) : List { Preconditions.checkNotNull(type) Preconditions.checkNotNull(info) if (info.Count == 0) { throw new IllegalArgumentException("Set of rootInfo cannot be empty") } else if (!acceptMultipleRoots && info.Count > 1) { throw new BeanTransferException(DisplayKey.get("BeanTransfer.BeanImportHandler.Error.MultipleRoots")) } var bundles = info*.Bundle.toSet() if (bundles.Count > 1) { throw new BeanTransferException(DisplayKey.get("BeanTransfer.BeanImportHandler.MultipleBundlesNotSupported")) } return bundles.single().InsertedBeans.whereTypeIs(type) } }