package gw.exportimport uses gw.api.database.Query uses gw.api.database.QuerySelectColumns uses gw.api.path.Paths uses java.lang.IllegalArgumentException uses java.util.Collections uses java.util.List /** * Defines an entity flow mask that masks out identified attributes in the flow * either on input or output. */ @ReadOnly class EntityFlowMask { static public var Registry : EntityInfoRegistry = EntityInfo.Registry /** * The name of this mask. */ var _name : String as readonly Name /** * The base EntityInfo (flow) for this mask. */ var _entityInfo : EntityInfo /** * A list of identifiers used to remove columns from an EntityInfo. */ var _maskIdentifiers : String[] as readonly MaskIdentifiers construct(data : EntityFlowMaskData) { if ( data.EntityTypeName != EntityType.Name ) { throw new IllegalArgumentException("Data Entity Type Name <${data.EntityType}> does not match Flow Type <${EntityType}>!") } _name = data.Name _maskIdentifiers = data.MaskIdentifiers } construct(theName : String) { this(theName, {}) } internal construct(theName : String, mask : String[]) { _name = theName _maskIdentifiers = mask } function createMaskedEntityInfo() : EntityInfo { return createMaskedEntityInfo(getEntityInfo()) } internal function createMaskedEntityInfo(entityInfo : EntityInfo) : EntityInfo { var includedColumnInfos : List if ( ( this.MaskIdentifiers == null ) or this.MaskIdentifiers.IsEmpty ) { includedColumnInfos = entityInfo.Columns } else { includedColumnInfos = {} for ( colInfo in entityInfo.Columns ) { if ( colInfo.RequiredForImport or colInfo.FlagsEntityId or not MaskIdentifiers.contains(colInfo.ColumnIdentifier) ) { var requiredDependentOns = ( colInfo.DependentOn == null ) ? Collections.EMPTY_SET : MaskIdentifiers.intersect(colInfo.DependentOn.Values*.ColumnIdentifier) if ( requiredDependentOns.Count > 0 ) { // force add masked out DependentOn ColumnInfo's... for ( depOnName in requiredDependentOns ) { var depOnColInfo = entityInfo.Columns.singleWhere(\ eCinfo -> eCinfo.ColumnIdentifier == depOnName.toString()) includedColumnInfos.add(depOnColInfo) } } includedColumnInfos.add(colInfo) } } } return new EntityInfo(includedColumnInfos, entityInfo.ParentEntityType) } /** * The type of this entity. */ property get EntityType() : Type { return T } /** * The entity flow meta-data. */ protected final function getEntityInfo() : EntityInfo { if ( _entityInfo == null ) { _entityInfo = Registry.findEntityInfo(T) } return _entityInfo } /** * Return a result of EntityFlowMaskData's for the specified Type. */ static function getEntityFlowMaskData(entityType : Type) : List { var query = Query.make(EntityFlowMaskData) query.compare(EntityFlowMaskData#EntityTypeName, Equals, entityType.Name) return query.select().orderByDescending(QuerySelectColumns.path(Paths.make(EntityFlowMaskData#Default, EntityFlowMaskDefault#ID))).toList() } }