Пример #1
0
    def create_TS_CommonService(entityDto, transDto, ts_name):
        '''
        This method is used to create the CommonService TSHandler 
        '''
        #path constant
        fileconstant = File_constant()
        tsconstant = TS_constant()
        proj_path = transDto.get_projectpath()

        # get the main table interface name
        controller_dto = entityDto.get_dataControllerDTO()
        business_entity_name = entityDto.get_businessentityname()
        # get the parent package name
        parent_pack = Java_processor.analysis_dataController_package_name(
            controller_dto.get_class_package())

        # get the generated constant full path
        commsev_filefullpath = proj_path + fileconstant.RESOURCE_TS_MAIN_PATH + parent_pack + '\\' + business_entity_name.lower(
        ) + '\\' + ts_name

        # create the header for constant file
        temp_lines = []
        additional_reference = []
        import_list = []

        # ------------------------------------------------------- #
        # ----- Prepare the imports -----
        # ------------------------------------------------------- #
        import_list.append(tsconstant.TS_TAB +
                           tsconstant.TS_FIN_COMMONSERVICE_IMPORT)

        # DTO import
        #tempStr = tsconstant.TS_DTO_IMPORT_TEMP % (dsName,parent_pack,business_entity_name.lower(),business_entity_name,)
        #import_list.append(tsconstant.TS_TAB + tempStr)

        # ------------------------------------------------------- #
        # ----- Create the file -----
        # ------------------------------------------------------- #
        if not File_processor.verify_dir_existing(commsev_filefullpath):
            # create file
            Path(commsev_filefullpath).touch()

        # ------------------------------------------------------- #
        # ----- open the observable object file -----
        # ------------------------------------------------------- #
        file = open(commsev_filefullpath, 'w')

        # ------------------------------------------------------- #
        # ----- write the common references -----
        # ------------------------------------------------------- #
        for temp_ref in tsconstant.TS_REFERENCE_COMMON_REFERENCES:
            file.write(temp_ref)
            file.write('\n')

        for temp_ref in tsconstant.TS_REFERENCE_UTIL_REFERENCES:
            file.write(temp_ref)
            file.write('\n')

        # ------------------------------------------------------- #
        # ----- write the common references -----
        # ------------------------------------------------------- #
        for temp_ref in additional_reference:
            file.write(temp_ref)
            file.write('\n')

        file.write('\n')

        # ------------------------------------------------------- #
        # ----- write the observable object header -----
        # ------------------------------------------------------- #
        temp_header = tsconstant.TS_COMMONSERVICE_HEADER % (
            parent_pack, business_entity_name.lower())
        file.write(temp_header)
        file.write('\n')

        # ------------------------------------------------------- #
        # ----- write the imports -----
        # ------------------------------------------------------- #
        for temp_ref in import_list:
            file.write(temp_ref)
            file.write('\n')

        file.write('\n')

        # ------------------------------------------------------- #
        # ----- write the observable object content -----
        # ------------------------------------------------------- #
        for sub_line in temp_lines:
            file.write(sub_line)

        file.write(tsconstant.TS_RIGHT_BRACE)

        file.close()

        return True, None
Пример #2
0
    def create_TS_ObserObj(entityDto, transDto, filename):
        '''
        create Observable Object
        '''
        #path constant
        fileconstant = File_constant()
        tsconstant = TS_constant()
        business_entity_name = entityDto.get_businessentityname()
        proj_path = transDto.get_projectpath()
        controller_dto = entityDto.get_dataControllerDTO()

        # get the parent package name
        parent_pack = Java_processor.analysis_dataController_package_name(
            controller_dto.get_class_package())
        # get the file full path
        filefullpath = proj_path + fileconstant.RESOURCE_TS_MAIN_PATH + fileconstant.RESOURCE_TS_DTO_UI_FOLDER + filename
        # additional references
        additional_reference = []
        # imports
        import_list = []
        # temp lines
        temp_lines = []

        # ------------------------------------------------------- #
        # ----- preparation -----
        # TODO: grid obj
        # ------------------------------------------------------- #
        for ajaxMtd in controller_dto.get_class_methods():
            # skip the method without parameters
            if len(ajaxMtd.get_method_ajax_resp()) == 0:
                continue

            # get the response parameters
            ajax_temp = ''
            for ajaxResp in ajaxMtd.get_method_ajax_resp():
                # convert the java type to TS type
                ajax_para_type_temp = TS_processor.convertJavaTypeToTSType(
                    ajaxResp.get_parameter_type())
                # verify and convert container type
                if ajax_para_type_temp.endswith(
                        fileconstant.JAVA_CONTAINER_SUFFIX):
                    # add import
                    import_name = ajax_para_type_temp[:-9]
                    import_prefix_part = ''
                    import_cells = ajaxResp.get_parameter_import().split(
                        tsconstant.TS_DOT_MARK)
                    idx = 0
                    while idx < len(import_cells):
                        if idx != len(import_cells) - 1:
                            import_prefix_part = import_prefix_part + import_cells[
                                idx] + tsconstant.TS_DOT_MARK
                        idx = idx + 1

                    import_temp = tsconstant.TS_OBSERVABLE_OBJ_NAMESPACE_TEMP % (
                        import_name, import_prefix_part, business_entity_name,
                        import_name + 's')
                    import_list.append(tsconstant.TS_TAB + import_temp)

                    # add additional references
                    reference_temp = tsconstant.TS_OBSERVABLE_OBJ_REFERENCE_TEMP % (
                        'bl', import_name)
                    additional_reference.append(reference_temp)

                    # convert the Container type to import name
                    ajax_para_type_temp = import_name

                ajax_temp = ajax_temp + '\n' + tsconstant.TS_TAB + tsconstant.TS_TAB + ajaxResp.get_parameter_name(
                ) + ': ' + ajax_para_type_temp + tsconstant.TS_END_MARK

            ajaxMtd_name = ajaxMtd.get_method_name()
            ajaxMtd_name = ajaxMtd_name[:1].upper() + ajaxMtd_name[1:]
            line = tsconstant.TS_TAB + tsconstant.TS_OBSERVABLE_OBJ_RESPONSE_TEMPLATE % (
                ajaxMtd_name, ajax_temp)

            temp_lines.append(line)
            temp_lines.append('\n')

        if not File_processor.verify_dir_existing(filefullpath):
            # create file
            Path(filefullpath).touch()

        # ------------------------------------------------------- #
        # ----- open the observable object file -----
        # ------------------------------------------------------- #
        file = open(filefullpath, 'w')

        # ------------------------------------------------------- #
        # ----- write the common references -----
        # ------------------------------------------------------- #
        for temp_ref in tsconstant.TS_REFERENCE_COMMON_REFERENCES:
            file.write(temp_ref)
            file.write('\n')

        # ------------------------------------------------------- #
        # ----- write the common references -----
        # ------------------------------------------------------- #
        for temp_ref in additional_reference:
            file.write(temp_ref)
            file.write('\n')

        file.write('\n')

        # ------------------------------------------------------- #
        # ----- write the observable object header -----
        # ------------------------------------------------------- #
        temp_header = tsconstant.TS_OBSERVABLE_OBJ_HEADER % (
            parent_pack, business_entity_name.lower(), business_entity_name)
        file.write(temp_header)
        file.write('\n')

        # ------------------------------------------------------- #
        # ----- write the imports -----
        # ------------------------------------------------------- #
        for temp_ref in import_list:
            file.write(temp_ref)
            file.write('\n')

        file.write('\n')

        # ------------------------------------------------------- #
        # ----- write the observable object content -----
        # ------------------------------------------------------- #
        for sub_line in temp_lines:
            file.write(sub_line)

        file.write(tsconstant.TS_RIGHT_BRACE)

        file.close()

        return True, None
Пример #3
0
    def create_TS_Constant(entityDto, transDto, tsConstant_name):
        '''
        create TS Constant
        '''
        #path constant
        fileconstant = File_constant()
        tsconstant = TS_constant()
        proj_path = transDto.get_projectpath()

        # get the main table interface name
        controller_dto = entityDto.get_dataControllerDTO()
        business_entity_name = entityDto.get_businessentityname()
        # get the parent package name
        parent_pack = Java_processor.analysis_dataController_package_name(
            controller_dto.get_class_package())

        # get the generated constant full path
        const_filefullpath = proj_path + fileconstant.RESOURCE_TS_MAIN_PATH + parent_pack + '\\' + business_entity_name.lower(
        ) + '\\' + tsConstant_name

        # create the header for constant file
        tempLines = []
        fieldLines = []
        gridLines = []
        gridfieldLines = {}

        tempStr = tsconstant.TS_CONSTANT_HEADER % (
            parent_pack, business_entity_name.lower())
        tempLines.append(tempStr)
        tempLines.append('\n')

        viewMetaDataDTO = entityDto.get_viewDTO()

        if not viewMetaDataDTO:
            return False, 'The View Metadata has not been analyzed, please do it first.'

        # ------------------------------------------------------- #
        # ----- prepare the field & labels -----
        # ------------------------------------------------------- #
        for datafield in viewMetaDataDTO.get_datafields():
            if datafield.get_name():
                tempName = datafield.get_name()
                constName = TS_processor.convertConstName(tempName)

                # add fields into const file
                fieldLines.append(tsconstant.TS_CONSTANT_FIELD_LINE_TEMP %
                                  (constName, tempName))

        for datalabels in viewMetaDataDTO.get_datalabels():
            if datalabels.get_name():
                tempName = datalabels.get_name()
                constName = TS_processor.convertConstName(tempName)

                # add fields into const file
                fieldLines.append(tsconstant.TS_CONSTANT_FIELD_LINE_TEMP %
                                  (constName, tempName))

        # create field&label constant
        if len(fieldLines) > 0:
            fieldContent = ''
            for fieldLine in fieldLines:
                fieldContent = fieldContent + fieldLine

            tempLines.append(tsconstant.TS_CONSTANT_FIELDS_TEMP %
                             (business_entity_name, fieldContent))

        # ------------------------------------------------------- #
        # ----- prepare the grids -----
        # ------------------------------------------------------- #
        for datagrids in viewMetaDataDTO.get_datagrids():
            if datagrids.get_name():
                tempGridName = datagrids.get_name()
                constGridName = TS_processor.convertConstName(tempGridName)

                # add fields into const file
                gridLines.append(tsconstant.TS_CONSTANT_FIELD_LINE_TEMP %
                                 (constGridName, tempGridName))

                # ------------------------------------------------------- #
                # ----- prepare the grid fields -----
                # ------------------------------------------------------- #
                if datagrids.get_datagridtable(
                ) and datagrids.get_datagridtable().get_datagridfields(
                ) and len(datagrids.get_datagridtable().get_datagridfields()
                          ) > 0:

                    tempGridFieldList = []

                    for datagridfield in datagrids.get_datagridtable(
                    ).get_datagridfields():
                        if datagridfield.get_fieldname():
                            tempFieldName = datagridfield.get_fieldname()
                            constFieldName = TS_processor.convertConstName(
                                tempFieldName)

                            # add grid fields into const file
                            tempGridFieldList.append(
                                tsconstant.TS_CONSTANT_FIELD_LINE_TEMP %
                                (constFieldName, tempFieldName))

                    gridfieldLines[tempGridName] = tempGridFieldList

        # create grid constant
        if len(gridLines) > 0:
            gridContent = ''
            for gridLine in gridLines:
                gridContent = gridContent + gridLine

            tempLines.append(tsconstant.TS_CONSTANT_GRIDS_TEMP %
                             (business_entity_name, gridContent))

        # create gridfield constant
        for key, value in gridfieldLines.items():
            gridFieldContent = ''
            for gridFieldLine in value:
                gridFieldContent = gridFieldContent + gridFieldLine

            tempLines.append(tsconstant.TS_CONSTANT_GRIDFIELD_TEMP %
                             (key, gridFieldContent))

        # write the constant file
        if not File_processor.verify_dir_existing(const_filefullpath):
            # create file
            Path(const_filefullpath).touch()

        # ------------------------------------------------------- #
        # ----- open the constant file -----
        # ------------------------------------------------------- #
        newfile = open(const_filefullpath, 'w')

        for line in tempLines:
            newfile.write(line)

        newfile.write(tsconstant.TS_RIGHT_BRACE)

        newfile.close()

        return True, None
Пример #4
0
    def before_next(self):
        '''
        overwrite the function in super class
        verify the input directory
        generating the next frames according to the selections
        '''
        # verify the connection name
        if not self.__input01.get(
        ) and self.__maintain_mode == MATAIN_MODE_NEW:
            showerror('Error', 'Please provide the connection name!')
            return False

        # verify the input value
        if not self.__input02.get() or not self.__input03.get(
        ) or not self.__input04.get() or not self.__input05.get():
            showerror('Error', 'Please provide the complete info!')
            return False

        # setup the connection file path into workspace folder
        fileconstant = File_constant()
        workspacepath = self.get_trans().get_workspacepath()
        cassandra_conection_folder = workspacepath + fileconstant.CASSANDRA_CONFIG_FOLDER

        if not File_processor.verify_dir_existing(cassandra_conection_folder):
            File_processor.create_folder(cassandra_conection_folder)

        cassandra_conection_file = cassandra_conection_folder + fileconstant.CASSANDRA_CONNECTION_FILE

        # combine the connection parameter
        # TODO: this should be implemented as toString() in Cassandra_connection_dto
        if self.__maintain_mode == MATAIN_MODE_NEW:
            connection_name = self.__input01.get()
            connection_param = self.__input01.get(
            ) + ':' + 'host=' + self.__input02.get(
            ) + ',port=' + self.__input03.get(
            ) + ',username='******',password='******':' + 'host=' + self.__input02.get(
            ) + ',port=' + self.__input03.get(
            ) + ',username='******',password='******'Warning',
                        'The connection name is existing, do you confirm to overwrite?'
                ):
                    return False
            Database_connection_file_processor.update_connection_file(
                cassandra_conection_file, connection_name, connection_param)

        return True
Пример #5
0
    def create_MockDTO(entityDto, transDto, mock_ds_name, isCopy):
        '''
        create Observable Object
        @param copyFromBlDto: if the mock DTO is copied from the generated one
        '''
        #path constant
        fileconstant = File_constant()
        tsconstant = TS_constant()
        proj_path = transDto.get_projectpath()

        # get the main table interface name
        main_tb_name = entityDto.get_maintableInterDTO().get_class_name()

        # copy from the generated ds
        if isCopy == 1:
            # get the generated ds name
            gene_ds_name = fileconstant.TS_DATASET_PREFIX + main_tb_name + fileconstant.TS_SUFFIX

            # get the generated ds full path
            gene_ds_filefullpath = proj_path + fileconstant.RESOURCE_TS_MAIN_PATH + fileconstant.RESOURCE_TS_DTO_BL_FOLDER + gene_ds_name
            # get the mock ds full path
            mock_ds_filefullpath = proj_path + fileconstant.RESOURCE_TS_MAIN_PATH + fileconstant.RESOURCE_TS_DTO_UI_FOLDER + mock_ds_name

            if not File_processor.verify_dir_existing(gene_ds_filefullpath):
                # throw error
                return False, 'The DTO %s does not generated in bl folder, please check.' % gene_ds_name

            # buffer the content of generated ds
            with open(gene_ds_filefullpath, 'r') as file:
                lines = file.readlines()

            # write the mock ds
            if not File_processor.verify_dir_existing(mock_ds_filefullpath):
                # create file
                Path(mock_ds_filefullpath).touch()

            # ------------------------------------------------------- #
            # ----- open the mock ds file -----
            # ------------------------------------------------------- #
            newfile = open(mock_ds_filefullpath, 'w')

            comment_flag = False
            for line in lines:
                if tsconstant.TS_LEFT_COMMENT in line:
                    comment_flag = True
                elif tsconstant.TS_RIGHT_COMMENT in line:
                    comment_flag = False

                if line[:6] == tsconstant.TS_KEYWORD_MODULE:
                    line = line.replace(tsconstant.TS_DTO_MODULE,
                                        tsconstant.TS_DTO_UI_MODULE)

                if not comment_flag and tsconstant.TS_COLON in line:
                    line = line.replace(
                        tsconstant.TS_COLON,
                        tsconstant.TS_QUESTION_MARK + tsconstant.TS_COLON)

                newfile.write(line)

            newfile.close()

        return True, None
Пример #6
0
    def write_entity_map(dir_path, urn, urn_type, object_name, pan_domain):
        '''
        write the entityMap.xml file
        @param dir_path: the full path of entityMap.xml
        @param urn: the new urn
        @param urn_type: the new urn_type
        @param object_name: the new object_name
        @param pan_domain: the new pan_domain
        @return: return status
        @return: message if validation failed
        '''
        # verify if file is existing
        if not File_processor.verify_dir_existing(dir_path):
            return False, None, 'The entityMap.xml is not exist, please check.'

        #get the root of entityMap
        linecontents = []
        entityuri_start, entityuri_end, file_end = -1, -1, -1

        with open(dir_path, "r", encoding="utf-8") as f:
            for cur_line_number, line in enumerate(f):
                linecontents.append(line)
                if '<EntityMap>' in line:
                    entityuri_start = cur_line_number
                if '</EntityMap>' in line and cur_line_number >= entityuri_start:
                    entityuri_end = cur_line_number
                if '</EntityMaps>' in line:
                    file_end = cur_line_number
        f.close()

        if entityuri_start == -1 or entityuri_end == -1:
            return False, 'The file format of entityMap.xml is incorrect, cannot find \'EntityMap\''

        try:
            # --- add a blank line
            linecontents.insert(file_end, '\n')
            # --- get the prefix from the last EntityMap node
            linepre = linecontents[
                entityuri_start][:linecontents[entityuri_start].
                                 index('<EntityMap>')]
            # --- add new EntityMap node
            linecontents.insert(file_end + 1, linepre + '<EntityMap>\n')
            linecontents.insert(file_end + 2,
                                linepre + '\t<urn>' + urn + '</urn>\n')
            linecontents.insert(file_end + 3,
                                linepre + '\t<type>' + urn_type + '</type>\n')
            linecontents.insert(
                file_end + 4,
                linepre + '\t<objectName>' + object_name + '</objectName>\n')
            linecontents.insert(
                file_end + 5,
                linepre + '\t<panDomain>' + pan_domain + '</panDomain>\n')
            linecontents.insert(file_end + 6, linepre + '</EntityMap>\n')
        except ValueError as e:
            return False, e

        newfile = ''.join(linecontents)
        f = open(dir_path, "w", encoding="utf-8")
        try:
            f.write(newfile)

        except PermissionError as e:
            return False, e
        finally:
            f.close()

        del linecontents[:]
        return True, None
Пример #7
0
    def write_beans_app_context(dir_path, value):
        '''
        write the beans-app-context.xml file
        @param dir_path: the full path of beans-app-context.xml
        @param value: append value
        @return: return status
        @return: message if validation failed
        '''
        # verify if file is existing
        if not File_processor.verify_dir_existing(dir_path):
            return False, 'The beans-app-context is not exist, please check.'

        #get the root of resource metadata
        linecontents = []
        entityuri_start, entityuri_end, value_start = -1, -1, -1

        with open(dir_path, "r", encoding="utf-8") as f:
            for cur_line_number, line in enumerate(f):
                linecontents.append(line)
                if 'name=\"entityUriMapString\"' in line:
                    entityuri_start = cur_line_number
                if 'value=' in line and entityuri_start > -1 and value_start == -1 and cur_line_number >= entityuri_start:
                    value_start = cur_line_number
                if '\"/>' in line and entityuri_start > -1 and entityuri_end == -1 and cur_line_number >= entityuri_start:
                    entityuri_end = cur_line_number
        f.close()

        if entityuri_start == -1 or entityuri_end == -1:
            return False, 'The file format of beans-app-context.xml is incorrect, cannot find \'entityUriMapString\''

        try:
            # --- the node in a single line
            if entityuri_start == entityuri_end or value_start == entityuri_end:
                idxarr = linecontents[entityuri_end].index('\"/>')
                linecontents[entityuri_end] = linecontents[
                    entityuri_end][:idxarr].rstrip(
                        ' '
                    ) + ';' + value + linecontents[entityuri_end][idxarr:]
            else:
                strtrim = linecontents[entityuri_end].replace(
                    '\"/>', '').replace('\t', '').replace('\n', '').strip(' ')
                # --- the end flag in a single line
                if strtrim == '':
                    # --- add ';' in previous line
                    idxarr = linecontents[entityuri_end - 1].index('\n')
                    linecontents[entityuri_end - 1] = linecontents[
                        entityuri_end - 1][:idxarr].rstrip(' ') + ';\n'
                    # --- clone the tab format in previous line
                    tabpre = ''
                    if (entityuri_end - 1 != value_start):
                        tabpre = linecontents[entityuri_end -
                                              1][:linecontents[entityuri_end -
                                                               1].index('urn')]
                    # --- insert new line
                    value = tabpre + value + '\n'
                    linecontents.insert(entityuri_end, value)
                else:
                    idxarr = linecontents[entityuri_end].index('\"/>')
                    linesuf = linecontents[entityuri_end][idxarr:]
                    # --- only one uri in the last line
                    if len(linecontents[entityuri_end].split(';')) == 1:
                        linecontents[entityuri_end] = linecontents[
                            entityuri_end][:idxarr].rstrip(' ') + ';\n'
                        # --- clone the tab format in current line
                        tabpre = linecontents[
                            entityuri_end][:linecontents[entityuri_end].
                                           index('urn')]
                        # --- insert new line
                        value = tabpre + value + linesuf
                        linecontents.insert(entityuri_end + 1, value)
                    else:
                        # --- add the new uri at the end of this line
                        linecontents[entityuri_end] = linecontents[
                            entityuri_end][:idxarr].rstrip(
                                ' ') + ';' + value + linecontents[
                                    entityuri_end][idxarr:]
        except ValueError as e:
            return False, e

        newfile = ''.join(linecontents)
        f = open(dir_path, "w", encoding="utf-8")
        try:
            f.write(newfile)

        except PermissionError as e:
            return False, e
        finally:
            f.close()

        del linecontents[:]
        return True, None
Пример #8
0
    def read_resource_metadata(dir_path, file_dto):
        '''
        read the target resource metadata xml file by dom, and load the details into ResourceMetadataDTO
        @param dir_path: the full path of resource metadata
        @return: return status
        @return: message if validation failed
        '''
        # verify if file is existing
        if not File_processor.verify_dir_existing(dir_path):
            return False, "The resource metadata is not exist, please check."

        #get the root of resource metadata
        dom = xml.dom.minidom.parse(dir_path)
        root = dom.documentElement
        #elements=root.getElementsByTagName('element')

        #create new resource dto
        resDto = ResourceMetadataDTO()

        #root node information
        if root.nodeName == 'ViewResourceMetadata':
            prim_uri = root.getAttribute('PrimarySecureUri')
            if prim_uri.index(resDto.ENTITY_TYPE_BE) >= 0:
                entity_type = 'BE'
            elif prim_uri.index(resDto.ENTITY_TYPE_SERVICE) >= 0:
                entity_type = 'Service'
            else:
                entity_type = None

            resDto.update_header(root.getAttribute('MetaUri'),
                                 root.getAttribute('ViewUri'),
                                 root.getAttribute('NameStringCode'),
                                 root.getAttribute('IsEligibleForMenu'),
                                 root.getAttribute('IsSecure'), prim_uri,
                                 entity_type)

            # --- HybridBrowseView ---

            # --- BrowseView ---

            # --- MaintView ---

            # --- ViewParameters ---
            tempViewDto = ViewParametersDTO()
            views = dom.getElementsByTagName("ViewParameters")
            for view in views:
                if len(view.getElementsByTagName(
                        "EntityModule")) > 0 and view.getElementsByTagName(
                            "EntityModule")[0].firstChild:
                    tempViewDto.set_entity_module(
                        view.getElementsByTagName("EntityModule")
                        [0].firstChild.data)
                if len(view.getElementsByTagName(
                        "StoredViewKey")) > 0 and view.getElementsByTagName(
                            "StoredViewKey")[0].firstChild:
                    tempViewDto.set_stored_view_key(
                        view.getElementsByTagName("StoredViewKey")
                        [0].firstChild.data)
                if len(view.getElementsByTagName(
                        "UsesDomain")) > 0 and view.getElementsByTagName(
                            "UsesDomain")[0].firstChild:
                    tempViewDto.set_uses_domain(
                        view.getElementsByTagName("UsesDomain")
                        [0].firstChild.data)
                if len(view.getElementsByTagName("ResourceUrlPrefix")
                       ) > 0 and view.getElementsByTagName(
                           "ResourceUrlPrefix")[0].firstChild:
                    tempViewDto.set_resource_url_prefix(
                        view.getElementsByTagName("ResourceUrlPrefix")
                        [0].firstChild.data)
                if len(view.getElementsByTagName(
                        "DataResource")) > 0 and view.getElementsByTagName(
                            "DataResource")[0].firstChild:
                    tempViewDto.set_data_resource(
                        view.getElementsByTagName("DataResource")
                        [0].firstChild.data)
                if len(
                        view.getElementsByTagName("Table")
                ) > 0 and view.getElementsByTagName("Table")[0].firstChild:
                    tempViewDto.set_table(
                        view.getElementsByTagName("Table")[0].firstChild.data)
                    print(tempViewDto.get_table())
                if len(view.getElementsByTagName("KeyFields")) > 0:
                    firstkeys = view.getElementsByTagName("KeyFields")[0]
                    for subkey in firstkeys.getElementsByTagName("KeyField"):
                        keyDto = KeyField()
                        if len(subkey.getElementsByTagName("BrowseKeyField")
                               ) > 0 and subkey.getElementsByTagName(
                                   "BrowseKeyField")[0].firstChild:
                            keyDto.set_browse_key_field(
                                subkey.getElementsByTagName("BrowseKeyField")
                                [0].firstChild.data)
                        if len(subkey.getElementsByTagName("EntityKeyField")
                               ) > 0 and subkey.getElementsByTagName(
                                   "EntityKeyField")[0].firstChild:
                            keyDto.set_entity_key_field(
                                subkey.getElementsByTagName("EntityKeyField")
                                [0].firstChild.data)
                        if len(
                                subkey.getElementsByTagName(
                                    "IsParentForeignKey")
                        ) > 0 and subkey.getElementsByTagName(
                                "IsParentForeignKey")[0].firstChild:
                            keyDto.set_is_parent_foreign_key(
                                subkey.getElementsByTagName(
                                    "IsParentForeignKey")[0].firstChild.data)

                        tempViewDto.push_key_field(keyDto)

            resDto.set_view_parameters(tempViewDto)

        else:
            return False, 'This is not a valid resource metadata, please check.'

        #print(root.childNodes)

        #update the ResourceMetadataDTO in FileDTOSet
        if file_dto:
            file_dto.set_resourceDTO(resDto)

        return True, None
Пример #9
0
    def read_view_metadata(file_dto):
        '''
        read the target view metadata xml file by dom, and load the details into ViewMetadataDTO
        @param dir_path: the full path of view metadata
        @return: return status
        @return: message if validation failed
        '''
        Xmlconstant = Xml_constant()

        # verify if file is existing
        if not File_processor.verify_dir_existing(file_dto.get_viewfullpath()):
            return False, "The view metadata is not exist, please check."

        #get the root of view metadata
        dom = xml.dom.minidom.parse(file_dto.get_viewfullpath())

        #create new resource dto
        viewDto = ViewMetadataDTO()

        # add field node into ViewMetadata DTO
        fields = dom.getElementsByTagName(Xmlconstant.XML_NODE_FIELD)
        for field in fields:
            dtField = Datafield()

            if field.getAttribute(Xmlconstant.XML_NODE_PROP_NAME):
                dtField.set_name(
                    field.getAttribute(Xmlconstant.XML_NODE_PROP_NAME))

            if field.getAttribute(Xmlconstant.XML_NODE_PROP_TABLENAME):
                dtField.set_tablename(
                    field.getAttribute(Xmlconstant.XML_NODE_PROP_TABLENAME))

            viewDto.push_datafields(dtField)

        # add label node into ViewMetadata DTO
        labels = dom.getElementsByTagName(Xmlconstant.XML_NODE_LABEL)
        for label in labels:
            dtLabel = Datalabel()

            if label.getAttribute(Xmlconstant.XML_NODE_PROP_NAME):
                dtLabel.set_name(
                    label.getAttribute(Xmlconstant.XML_NODE_PROP_NAME))

            viewDto.push_datalabels(dtLabel)

        # add label node into ViewMetadata DTO
        datagrids = dom.getElementsByTagName(Xmlconstant.XML_NODE_DATAGRID)
        for datagrid in datagrids:
            dtGrid = Datagrid()

            if datagrid.getAttribute(Xmlconstant.XML_NODE_PROP_NAME):
                dtGrid.set_name(
                    datagrid.getAttribute(Xmlconstant.XML_NODE_PROP_NAME))

            if datagrid.getAttribute(Xmlconstant.XML_NODE_PROP_TABLENAME):
                dtGrid.set_tablename(
                    datagrid.getAttribute(Xmlconstant.XML_NODE_PROP_TABLENAME))

            # add DataGridTable into DataTable node
            datagridtables = datagrid.getElementsByTagName(
                Xmlconstant.XML_NODE_DATAGRIDTABLE)
            if len(datagridtables) == 0:
                return False, 'The DataGrid structure is incorrect without table!'

            dtGridTable = Datagridtable()

            if datagridtables[0].getAttribute(Xmlconstant.XML_NODE_PROP_NAME):
                dtGridTable.set_name(datagridtables[0].getAttribute(
                    Xmlconstant.XML_NODE_PROP_NAME))

            # add DataGridField into DataGridTable
            datagridfields = datagridtables[0].getElementsByTagName(
                Xmlconstant.XML_NODE_DATAGRIDFIELD)
            for datagridfield in datagridfields:

                dtGridfield = Datagridfield()

                if datagridfield.getAttribute(
                        Xmlconstant.XML_NODE_PROP_FIELDNAME):
                    dtGridfield.set_fieldname(
                        datagridfield.getAttribute(
                            Xmlconstant.XML_NODE_PROP_FIELDNAME))

                if datagridfield.getAttribute(
                        Xmlconstant.XML_NODE_PROP_READONLY):
                    dtGridfield.set_readonly(
                        datagridfield.getAttribute(
                            Xmlconstant.XML_NODE_PROP_READONLY))

                dtGridTable.push_datagridfield(dtGridfield)

            dtGrid.set_datagridtable(dtGridTable)
            viewDto.push_datagrids(dtGrid)

        #update the ViewMetadataDTO in FileDTOSet
        if file_dto:
            file_dto.set_viewDTO(viewDto)

        return True, None
Пример #10
0
    def verify_proj_files(self):
        '''
        verify the project fiels
        '''
        #path constant
        fileconstant = File_constant()
        entity_name = self.get_dtos().get_entityname()
        proj_path = self.get_trans().get_projectpath()

        #verify view metadata
        view_exist = False
        viewfullpath = self.get_dtos().get_viewfullpath()
        if not viewfullpath and entity_name:
            viewfullpath = proj_path + fileconstant.VIEW_METADATA_PATH + entity_name + fileconstant.XML_SUFFIX
            view_exist, self.__message = Xmlfile_processor.veriy_view_metadata(
                viewfullpath)
        elif viewfullpath:
            view_exist = True
        if view_exist:
            newlabel01 = "< passed >"
            self.__label04.config(text=newlabel01, fg='blue')
            self.get_dtos().set_viewfullpath(viewfullpath)
            self.__checkstatus['ViewMetadata'] = [True, self.__checkval01]
        else:
            newlabel01 = "< failed >"
            self.__label04.config(text=newlabel01, fg='red')
            btnlabel = 'Correct'
            self.__button01.config(text=btnlabel)
            self.__checkstatus['ViewMetadata'] = [False, self.__checkval01]
        self.__checkval01.set(1)
        #bind button click event
        self.__button01.bind(
            '<Button-1>',
            self.event_adapter(self.detal_button_click,
                               iscorrect=self.__checkstatus['ViewMetadata'][0],
                               filename=entity_name + fileconstant.XML_SUFFIX,
                               filetype='ViewMetadata',
                               filepath=viewfullpath))

        #verify source metadata
        resource_exist = False
        resourcefullpath = self.get_dtos().get_resourcefullpath()
        if not resourcefullpath and entity_name:
            resourcefullpath = proj_path + fileconstant.RESOURCE_METADATA_PATH + entity_name + fileconstant.RESOURCE_METADATA_SUFFIX
            resource_exist, self.__message = Xmlfile_processor.veriy_resource_metadata(
                resourcefullpath)
        if resource_exist:
            newlabel = "< passed >"
            self.__label06.config(text=newlabel, fg='blue')
            self.get_dtos().set_resourcefullpath(resourcefullpath)
            self.__checkstatus['ResourceMetadata'] = [True, self.__checkval02]
        else:
            newlabel = "< failed >"
            self.__label06.config(text=newlabel, fg='red')
            btnlabel = 'Correct'
            self.__button02.config(text=btnlabel)
            self.__checkstatus['ResourceMetadata'] = [False, self.__checkval02]
        self.__checkval02.set(1)
        self.__button02.bind(
            '<Button-1>',
            self.event_adapter(
                self.detal_button_click,
                iscorrect=self.__checkstatus['ResourceMetadata'][0],
                filename=entity_name + fileconstant.RESOURCE_METADATA_SUFFIX,
                filetype='ResourceMetadata',
                filepath=resourcefullpath))

        #verify pom
        result, self.__message = Xmlfile_processor.verify_pom(
            proj_path + fileconstant.POM_PATH)
        if result:
            #read the pom
            result, pomDto, self.__message = Xmlfile_processor.read_pom(
                proj_path + fileconstant.POM_PATH)
            newlabel = "< passed >"
            self.__label08.config(text=newlabel, fg='blue')
            self.get_trans().set_pomDto(pomDto)
            self.__checkstatus['Pom'] = [True, self.__checkval03]
        else:
            newlabel = "< failed >"
            self.__label08.config(text=newlabel, fg='red')
            btnlabel = 'Correct'
            self.__button03.config(text=btnlabel)
            self.__checkstatus['Pom'] = [False, self.__checkval03]
        self.__checkval03.set(1)
        self.__button03.bind(
            '<Button-1>',
            self.event_adapter(self.detal_button_click,
                               iscorrect=self.__checkstatus['Pom'][0],
                               filename='pom.xml',
                               filetype='POM',
                               filepath=proj_path + fileconstant.POM_PATH))

        #verify beans-app-context
        result, self.__message = Xmlfile_processor.verify_beans_app_context(
            proj_path + fileconstant.BEAN_APP_CONTEXT_PATH)
        if result:
            newlabel = "< passed >"
            self.__label10.config(text=newlabel, fg='blue')
            self.get_trans().set_pomDto(pomDto)
            self.__checkstatus['beans-app-context'] = [True, self.__checkval04]
        else:
            newlabel = "< failed >"
            self.__label10.config(text=newlabel, fg='red')
            btnlabel = 'Correct'
            self.__button04.config(text=btnlabel)
            self.__checkstatus['beans-app-context'] = [
                False, self.__checkval04
            ]
        self.__checkval04.set(1)
        self.__button04.bind(
            '<Button-1>',
            self.event_adapter(
                self.detal_button_click,
                iscorrect=self.__checkstatus['beans-app-context'][0],
                filename='beans-app-server.xml',
                filetype='beans',
                filepath=proj_path + fileconstant.BEAN_APP_CONTEXT_PATH))

        #verify entityMap
        result, self.__message = Xmlfile_processor.verify_entity_map(
            proj_path + fileconstant.ENTITY_MAP_PATH)
        if result:
            newlabel = "< passed >"
            self.__label12.config(text=newlabel, fg='blue')
            self.get_trans().set_pomDto(pomDto)
            self.__checkstatus['entityMap'] = [True, self.__checkval05]
        else:
            newlabel = "< failed >"
            self.__label12.config(text=newlabel, fg='red')
            btnlabel = 'Correct'
            self.__button05.config(text=btnlabel)
            self.__checkstatus['entityMap'] = [False, self.__checkval05]
        self.__checkval05.set(1)
        self.__button05.bind(
            '<Button-1>',
            self.event_adapter(self.detal_button_click,
                               iscorrect=self.__checkstatus['entityMap'][0],
                               filename='entityMap.xml',
                               filetype='entityMap',
                               filepath=proj_path +
                               fileconstant.ENTITY_MAP_PATH))

        #verify jar
        result = False
        jarname = None
        implJarfullpath = self.get_trans().get_finImplJarPath()
        apiJarfullpath = self.get_trans().get_finApiJarPath()
        #verify if jar is existing at the Maven's default repository
        #impl jar
        if not implJarfullpath:
            userhomepath = File_processor.get_user_home(
            ) + fileconstant.IMPL_JAR_LIB_PATH
            #jar name and full path
            implJarfullpath = userhomepath + pomDto.get_financials_api_version(
            ) + '\\' + fileconstant.FIN_IMPL_JAR_PREFIX + pomDto.get_financials_api_version(
            ) + fileconstant.JAR_SUFFIX
            jarname = fileconstant.FIN_IMPL_JAR_PREFIX + pomDto.get_financials_api_version(
            ) + fileconstant.JAR_SUFFIX

            result, self.__message = Java_processor.verify_jar_type(
                implJarfullpath)

            if result:
                newlabel = "< passed >"
                self.__label92.config(text=newlabel, fg='blue')
                self.get_trans().set_finImplJarPath(implJarfullpath)
                self.__checkstatus['ImplJAR'] = [True, self.__checkval91]
            else:
                newlabel = "< failed >"
                self.__label92.config(text=newlabel, fg='red')
                btnlabel = 'Correct'
                self.__button91.config(text=btnlabel)
                self.__checkstatus['ImplJAR'] = [False, self.__checkval91]
        else:
            newlabel = "< passed >"
            self.__label92.config(text=newlabel, fg='blue')
            self.__checkstatus['ImplJAR'] = [True, self.__checkval91]
            #jar name
            jarname = File_processor.get_file_name(
                self.get_trans().get_finImplJarPath())

        self.__checkval91.set(1)
        self.__button91.bind(
            '<Button-1>',
            self.event_adapter(self.detal_button_click,
                               iscorrect=self.__checkstatus['ImplJAR'][0],
                               filename=jarname,
                               filetype='ImplJAR',
                               filepath=implJarfullpath))
        # api jar
        if not apiJarfullpath:
            userhomepath = File_processor.get_user_home(
            ) + fileconstant.API_JAR_LIB_PATH
            #jar name and full path
            apiJarfullpath = userhomepath + pomDto.get_financials_api_version(
            ) + '\\' + fileconstant.FIN_API_JAR_PREFIX + pomDto.get_financials_api_version(
            ) + fileconstant.JAR_SUFFIX
            jarname = fileconstant.FIN_IMPL_JAR_PREFIX + pomDto.get_financials_api_version(
            ) + fileconstant.JAR_SUFFIX

            result, self.__message = Java_processor.verify_jar_type(
                apiJarfullpath)

            if result:
                newlabel = "< passed >"
                self.__label94.config(text=newlabel, fg='blue')
                self.get_trans().set_finApiJarPath(apiJarfullpath)
                self.__checkstatus['ApiJAR'] = [True, self.__checkval92]
            else:
                newlabel = "< failed >"
                self.__label94.config(text=newlabel, fg='red')
                btnlabel = 'Correct'
                self.__button92.config(text=btnlabel)
                self.__checkstatus['ApiJAR'] = [False, self.__checkval92]
        else:
            newlabel = "< passed >"
            self.__label94.config(text=newlabel, fg='blue')
            self.__checkstatus['ApiJAR'] = [True, self.__checkval92]
            #jar name
            jarname = File_processor.get_file_name(
                self.get_trans().get_finImplJarPath())

        self.__checkval92.set(1)
        self.__button92.bind(
            '<Button-1>',
            self.event_adapter(self.detal_button_click,
                               iscorrect=self.__checkstatus['ApiJAR'][0],
                               filename=jarname,
                               filetype='ApiJAR',
                               filepath=apiJarfullpath))