<commit_before>/**
 * Copyright 2005-2013 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.rice.scripts.beans

import groovy.util.logging.Log
import org.apache.commons.lang.StringUtils

/**
 * This class transforms maintenance document entry beans and its properties/children beans into their uif equivalent
 *
 * @author Kuali Rice Team (<EMAIL>)
 */
@Log
class MaintenanceDocumentEntryBeanTransformer extends SpringBeanTransformer {

    String maintenanceDefinitionBeanType = "MaintenanceDocumentEntry";
    String maintenanceDocEntryBeanType = "uifMaintenanceDocumentEntry"
    String maintenanceViewBeanType = "Uif-MaintenanceView";

    // MDE Conversion Components
    def mdeCopyProperties = ["businessObjectClass", "maintainableClass", "documentTypeName", "documentAuthorizerClass",
            "lockingKeys", "allowsRecordDeletion", "preserveLockingKeysOnCopy","allowsNewOrCopy","documentClass"];
    def mdeRenameProperties = [:]
    def mdeIgnoreOnCarryoverProperties = []
    def mdeIgnoreOnCarryoverAttributes = []

    // UMV Conversion Components - include
    def umvCopyProperties = ["businessObjectClass", "maintainableClass", "documentTypeName", "documentAuthorizerClass", "lockingKeys"]
    def umvRenameProperties = ["title": "headerText", "businessObjectClass": "dataObjectClassName", "dataObjectClass": "dataObjectClassName"]
    def umvIgnoreOnCarryoverProperties = ["title", "maintainableSections"]
    def umvIgnoreOnCarryoverAttributes = []


    /**
     * Transforms maintenance document entry which results in an updated document entry
     * and a maintenance View
     *
     * @param beanNode
     * @return
     */
    def transformMaintenanceDocumentEntryBean(Node beanNode) {
        def maintDocParentBeanNode = beanNode;

        def mdeBeanAttributes = convertBeanAttributes(beanNode, maintenanceDefinitionBeanType, maintenanceDocEntryBeanType, mdeIgnoreOnCarryoverAttributes);
        def mdeCarryoverProperties = findCarryoverProperties(beanNode, mdeCopyProperties, mdeRenameProperties.keySet(), mdeIgnoreOnCarryoverProperties);

        def umvBeanAttributes = convertBeanAttributes(beanNode, maintenanceDefinitionBeanType, maintenanceViewBeanType, umvIgnoreOnCarryoverAttributes);
        def umvCarryoverProperties = findCarryoverProperties(beanNode, umvCopyProperties, umvRenameProperties.keySet(), umvIgnoreOnCarryoverProperties);


        log.finer "transform bean node for maintenance document entry"
        if (isPlaceholder(beanNode)) {
            addCommentIfNotExists(beanNode.parent(), "Maintenance View");
            beanNode.attributes().putAll(mdeBeanAttributes);
            addCommentIfNotExists(beanNode.parent(), "Maintenance Document Entry");
            beanNode.plus{ bean(umvBeanAttributes) }
        } else {
            beanNode.replaceNode {
                addCommentIfNotExists(beanNode.parent(), "Maintenance View")
                bean(umvBeanAttributes) {
                    copyProperties(delegate, beanNode, umvCopyProperties + umvCarryoverProperties)
                    renameProperties(delegate, maintDocParentBeanNode, umvRenameProperties)
                    transformTitleProperty(delegate, beanNode);
                    transformMaintainableSectionsProperty(delegate, beanNode)
                }
                addCommentIfNotExists(beanNode.parent(), "Maintenance Document Entry")
                bean(mdeBeanAttributes) {
                    copyProperties(delegate, beanNode, mdeCopyProperties + mdeCarryoverProperties)
                }
            }
        }

        return beanNode;
    }

    def findCarryoverProperties(Node beanNode, def copyPropertiesList, def renamePropertiesList, def ignorePropertiesList) {
        def carryoverPropertiesList = []
        if (carryoverProperties) {
            carryoverPropertiesList = beanNode.property.collect { it.@name };
            carryoverPropertiesList.removeAll(copyPropertiesList);
            carryoverPropertiesList.removeAll(renamePropertiesList);
            carryoverPropertiesList.removeAll(ignorePropertiesList);
        }

        return carryoverPropertiesList;
    }

    /**
     *
     *
     * @param beanNode
     * @return
     */
    private String getMaintenanceDocumentObjectName(Node beanNode) {
        return beanNode.@id.toString().replaceFirst("-parentBean", "").replaceFirst("MaintenanceDocument", "");
    }

    def transformMaintainableSectionDefinitionBean(Node beanNode) {
        if ("MaintainableSectionDefinition".equals(beanNode.@parent)) {
            beanNode.replaceNode {
                transformMaintainableSectionDefinitionBean(delegate, beanNode);
            }
        }
    }

    def transformMaintainableSectionDefinitionBean(NodeBuilder builder, Node beanNode) {
        if (!beanNode.property.list.bean.find { "MaintainableCollectionDefinition".equals(it.@parent) }) {
            def beanAttributes = [parent: 'Uif-MaintenanceGridSection']
            if (beanNode.@id) {
                beanAttributes.put("id", beanNode.@id)
            }
            builder.bean(beanAttributes) {
                copyProperties(delegate, beanNode, ["title", "collectionObjectClass", "propertyName"])
                transformMaintainableItemsProperty(delegate, beanNode);
            }
        } else {
            transformMaintainableSectionDefinitionBeanWithCollection(builder, beanNode);
        }
    }

    /**
     * Generates a vertical box section with all collection and non-collection elements as items of the vertical box
     *
     *
     * @param builder
     * @param beanNode
     * @return
     */
    def transformMaintainableSectionDefinitionBeanWithCollection(NodeBuilder builder, Node beanNode) {
        // used to build up the list as its processes through the non-collection items
        def itemsList = [];
        def beanAttrs = [parent: "Uif-VerticalBoxSection"];
        if (beanNode.@id) {
            beanAttrs.put("id", beanNode.@id);
        }
        builder.bean(beanAttrs) {
            copyProperties(delegate, beanNode, ["title"]);
            property(name: "items") {
                list {
                    beanNode.property.find { it.@name == "maintainableItems" }.list.bean.each { beanItem ->
                        if (!"MaintainableCollectionDefinition".equals(beanItem.@parent)) {
                            itemsList.add(gatherNameAttribute(beanItem));
                        } else {
                            if (itemsList.size() > 0) {
                                builder.bean(parent: 'Uif-MaintenanceGridSection') {
                                    copyProperties(delegate, beanNode, ["title", "collectionObjectClass", "propertyName"])
                                    property(name: "items") {
                                        list {
                                            itemsList.each { attributes ->
                                                attributes.put("parent", "Uif-InputField");
                                                genericBeanTransform(builder, attributes);
                                            }
                                        }
                                    }
                                }
                            }

                            itemsList = [];
                            builder.bean(parent: 'Uif-MaintenanceStackedCollectionSection') {
                                copyProperties(delegate, beanNode, ["title", "collectionObjectClass", "propertyName"]);
                                renameProperties(delegate, beanNode, ["title": "headerText", "businessObjectClass": "collectionObjectClass"]);
                                transformMaintainableFieldsProperty(delegate, beanItem);
                                transformSummaryFieldsProperty(delegate, beanNode);

                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * Converts title property to view name property
     *
     * @param builder
     * @param beanNode
     * @return
     */
    def transformTitleProperty(NodeBuilder builder, Node beanNode) {
        if(beanNode?.property?.findAll { "title".equals(it.@name) }?.size > 0) {
            def modifiedViewName = beanNode?.property?.find { it.@name == "title" }?.@value;
            if (StringUtils.isNotBlank(modifiedViewName)) {
                modifiedViewName = OUTPUT_CONV_FILE_PREFIX + modifiedViewName;
            }

            createProperty(builder, "viewName", modifiedViewName)
        }

    }


    /**
     *
     *
     * @param builder
     * @param beanNode
     * @return
     */
    def transformMaintainableSectionsProperty(NodeBuilder builder, Node beanNode) {
        def maintainableSectionsProperty = beanNode.property.find { it.@name == "maintainableSections" }
        if (maintainableSectionsProperty != null) {
            builder.property(name: "items") {
                list {
                    maintainableSectionsProperty.list.'*'.each { beanOrRefNode ->
                        if ("bean".equals(beanOrRefNode.name()?.localPart) && "MaintainableSectionDefinition".equals(beanOrRefNode.@parent)) {
                            transformMaintainableSectionDefinitionBean(builder, beanOrRefNode); // replace with grid or stack collection
                        } else if ("ref".equals(beanOrRefNode.name()?.localPart)) {
                            ref(bean: beanOrRefNode.@bean)
                        } // copy ref over; let it be converted in bean conversions
                    }
                }
            }
        }
    }

    def transformMaintainableItemsProperty(NodeBuilder builder, Node beanNode) {
        transformPropertyBeanList(builder, beanNode, ["maintainableItems": "items"], gatherNameAttribute, inputFieldBeanTransform);
    }

    /**
     * Maintainable fields returned as an items property list
     *
     *
     * @param builder - data output is appended to the builder
     * @param beanNode - generally a collection definition bean
     * @return
     */
    def transformMaintainableFieldsProperty(NodeBuilder builder, Node beanNode) {
        def maintainableFieldsProperty = beanNode.property.find { "maintainableFields".equals(it.@name) };
        if (maintainableFieldsProperty) {
            builder.property(name: "items") {
                list {
                    maintainableFieldsProperty?.list?.bean.each { maintainableItem -> inputFieldBeanTransform(builder, gatherNameAttribute(maintainableItem)); }
                }
            }
        }
    }

}
<commit_msg>KULRICE-11222: Adding properties to mde carryover<commit_after>/**
 * Copyright 2005-2013 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.rice.scripts.beans

import groovy.util.logging.Log
import org.apache.commons.lang.StringUtils

/**
 * This class transforms maintenance document entry beans and its properties/children beans into their uif equivalent
 *
 * @author Kuali Rice Team (<EMAIL>)
 */
@Log
class MaintenanceDocumentEntryBeanTransformer extends SpringBeanTransformer {

    String maintenanceDefinitionBeanType = "MaintenanceDocumentEntry";
    String maintenanceDocEntryBeanType = "uifMaintenanceDocumentEntry"
    String maintenanceViewBeanType = "Uif-MaintenanceView";

    // MDE Conversion Components
    def mdeCopyProperties = ["businessObjectClass", "businessRulesClass", "maintainableClass", "documentTypeName",
            "documentAuthorizerClass", "lockingKeys", "allowsRecordDeletion", "preserveLockingKeysOnCopy","allowsNewOrCopy","documentClass"];
    def mdeRenameProperties = [:]
    def mdeIgnoreOnCarryoverProperties = []
    def mdeIgnoreOnCarryoverAttributes = []

    // UMV Conversion Components - include
    def umvCopyProperties = ["businessObjectClass", "maintainableClass", "documentTypeName", "documentAuthorizerClass", "lockingKeys"]
    def umvRenameProperties = ["title": "headerText", "businessObjectClass": "dataObjectClassName", "dataObjectClass": "dataObjectClassName"]
    def umvIgnoreOnCarryoverProperties = ["title", "maintainableSections"]
    def umvIgnoreOnCarryoverAttributes = []


    /**
     * Transforms maintenance document entry which results in an updated document entry
     * and a maintenance View
     *
     * @param beanNode
     * @return
     */
    def transformMaintenanceDocumentEntryBean(Node beanNode) {
        def maintDocParentBeanNode = beanNode;

        def mdeBeanAttributes = convertBeanAttributes(beanNode, maintenanceDefinitionBeanType, maintenanceDocEntryBeanType, mdeIgnoreOnCarryoverAttributes);
        def mdeCarryoverProperties = findCarryoverProperties(beanNode, mdeCopyProperties, mdeRenameProperties.keySet(), mdeIgnoreOnCarryoverProperties);

        def umvBeanAttributes = convertBeanAttributes(beanNode, maintenanceDefinitionBeanType, maintenanceViewBeanType, umvIgnoreOnCarryoverAttributes);
        def umvCarryoverProperties = findCarryoverProperties(beanNode, umvCopyProperties, umvRenameProperties.keySet(), umvIgnoreOnCarryoverProperties);


        log.finer "transform bean node for maintenance document entry"
        if (isPlaceholder(beanNode)) {
            addCommentIfNotExists(beanNode.parent(), "Maintenance View");
            beanNode.attributes().putAll(mdeBeanAttributes);
            addCommentIfNotExists(beanNode.parent(), "Maintenance Document Entry");
            beanNode.plus{ bean(umvBeanAttributes) }
        } else {
            beanNode.replaceNode {
                addCommentIfNotExists(beanNode.parent(), "Maintenance View")
                bean(umvBeanAttributes) {
                    copyProperties(delegate, beanNode, umvCopyProperties + umvCarryoverProperties)
                    renameProperties(delegate, maintDocParentBeanNode, umvRenameProperties)
                    transformTitleProperty(delegate, beanNode);
                    transformMaintainableSectionsProperty(delegate, beanNode)
                }
                addCommentIfNotExists(beanNode.parent(), "Maintenance Document Entry")
                bean(mdeBeanAttributes) {
                    copyProperties(delegate, beanNode, mdeCopyProperties + mdeCarryoverProperties)
                }
            }
        }

        return beanNode;
    }

    def findCarryoverProperties(Node beanNode, def copyPropertiesList, def renamePropertiesList, def ignorePropertiesList) {
        def carryoverPropertiesList = []
        if (carryoverProperties) {
            carryoverPropertiesList = beanNode.property.collect { it.@name };
            carryoverPropertiesList.removeAll(copyPropertiesList);
            carryoverPropertiesList.removeAll(renamePropertiesList);
            carryoverPropertiesList.removeAll(ignorePropertiesList);
        }

        return carryoverPropertiesList;
    }

    /**
     *
     *
     * @param beanNode
     * @return
     */
    private String getMaintenanceDocumentObjectName(Node beanNode) {
        return beanNode.@id.toString().replaceFirst("-parentBean", "").replaceFirst("MaintenanceDocument", "");
    }

    def transformMaintainableSectionDefinitionBean(Node beanNode) {
        if ("MaintainableSectionDefinition".equals(beanNode.@parent)) {
            beanNode.replaceNode {
                transformMaintainableSectionDefinitionBean(delegate, beanNode);
            }
        }
    }

    def transformMaintainableSectionDefinitionBean(NodeBuilder builder, Node beanNode) {
        if (!beanNode.property.list.bean.find { "MaintainableCollectionDefinition".equals(it.@parent) }) {
            def beanAttributes = [parent: 'Uif-MaintenanceGridSection']
            if (beanNode.@id) {
                beanAttributes.put("id", beanNode.@id)
            }
            builder.bean(beanAttributes) {
                copyProperties(delegate, beanNode, ["title", "collectionObjectClass", "propertyName"])
                transformMaintainableItemsProperty(delegate, beanNode);
            }
        } else {
            transformMaintainableSectionDefinitionBeanWithCollection(builder, beanNode);
        }
    }

    /**
     * Generates a vertical box section with all collection and non-collection elements as items of the vertical box
     *
     *
     * @param builder
     * @param beanNode
     * @return
     */
    def transformMaintainableSectionDefinitionBeanWithCollection(NodeBuilder builder, Node beanNode) {
        // used to build up the list as its processes through the non-collection items
        def itemsList = [];
        def beanAttrs = [parent: "Uif-VerticalBoxSection"];
        if (beanNode.@id) {
            beanAttrs.put("id", beanNode.@id);
        }
        builder.bean(beanAttrs) {
            copyProperties(delegate, beanNode, ["title"]);
            property(name: "items") {
                list {
                    beanNode.property.find { it.@name == "maintainableItems" }.list.bean.each { beanItem ->
                        if (!"MaintainableCollectionDefinition".equals(beanItem.@parent)) {
                            itemsList.add(gatherNameAttribute(beanItem));
                        } else {
                            if (itemsList.size() > 0) {
                                builder.bean(parent: 'Uif-MaintenanceGridSection') {
                                    copyProperties(delegate, beanNode, ["title", "collectionObjectClass", "propertyName"])
                                    property(name: "items") {
                                        list {
                                            itemsList.each { attributes ->
                                                attributes.put("parent", "Uif-InputField");
                                                genericBeanTransform(builder, attributes);
                                            }
                                        }
                                    }
                                }
                            }

                            itemsList = [];
                            builder.bean(parent: 'Uif-MaintenanceStackedCollectionSection') {
                                copyProperties(delegate, beanNode, ["title", "collectionObjectClass", "propertyName"]);
                                renameProperties(delegate, beanNode, ["title": "headerText", "businessObjectClass": "collectionObjectClass"]);
                                transformMaintainableFieldsProperty(delegate, beanItem);
                                transformSummaryFieldsProperty(delegate, beanNode);

                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * Converts title property to view name property
     *
     * @param builder
     * @param beanNode
     * @return
     */
    def transformTitleProperty(NodeBuilder builder, Node beanNode) {
        if(beanNode?.property?.findAll { "title".equals(it.@name) }?.size > 0) {
            def modifiedViewName = beanNode?.property?.find { it.@name == "title" }?.@value;
            if (StringUtils.isNotBlank(modifiedViewName)) {
                modifiedViewName = OUTPUT_CONV_FILE_PREFIX + modifiedViewName;
            }

            createProperty(builder, "viewName", modifiedViewName)
        }

    }


    /**
     *
     *
     * @param builder
     * @param beanNode
     * @return
     */
    def transformMaintainableSectionsProperty(NodeBuilder builder, Node beanNode) {
        def maintainableSectionsProperty = beanNode.property.find { it.@name == "maintainableSections" }
        if (maintainableSectionsProperty != null) {
            builder.property(name: "items") {
                list {
                    maintainableSectionsProperty.list.'*'.each { beanOrRefNode ->
                        if ("bean".equals(beanOrRefNode.name()?.localPart) && "MaintainableSectionDefinition".equals(beanOrRefNode.@parent)) {
                            transformMaintainableSectionDefinitionBean(builder, beanOrRefNode); // replace with grid or stack collection
                        } else if ("ref".equals(beanOrRefNode.name()?.localPart)) {
                            ref(bean: beanOrRefNode.@bean)
                        } // copy ref over; let it be converted in bean conversions
                    }
                }
            }
        }
    }

    def transformMaintainableItemsProperty(NodeBuilder builder, Node beanNode) {
        transformPropertyBeanList(builder, beanNode, ["maintainableItems": "items"], gatherNameAttribute, inputFieldBeanTransform);
    }

    /**
     * Maintainable fields returned as an items property list
     *
     *
     * @param builder - data output is appended to the builder
     * @param beanNode - generally a collection definition bean
     * @return
     */
    def transformMaintainableFieldsProperty(NodeBuilder builder, Node beanNode) {
        def maintainableFieldsProperty = beanNode.property.find { "maintainableFields".equals(it.@name) };
        if (maintainableFieldsProperty) {
            builder.property(name: "items") {
                list {
                    maintainableFieldsProperty?.list?.bean.each { maintainableItem -> inputFieldBeanTransform(builder, gatherNameAttribute(maintainableItem)); }
                }
            }
        }
    }

}

{'fraction_non_alphanumeric': 0.08683811054558442, 'fraction_numerical': 0.0013840521475131707, 'mean_word_length': 2.290099882491187, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7255913', 'n_tokens_mistral': 5498, 'n_tokens_neox': 5305, 'n_words': 1148}