⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applicationmetadatahelper.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

                            famgSet.get(entityName).add(famgMeta);
                        }
                    }
                }
            }
        }
        Set<String> entityNames = famgSet.keySet();
        for(String e1 : entityNames) {
            for(String e2 : entityNames) {
                if(e1.equals(e2)) {
                    continue;
                }

                if(canJoinEntities(e1, e2, ctx)) {
                    setJoinableForms(metaData, famgSet.get(e1), famgSet.get(e2));
                    setJoinableForms(metaData, famgSet.get(e2), famgSet.get(e1));
                }
            }
        }
    }

    private static void setJoinableForms(MetaData metaData, Set<FamgMeta> targetFamgs, Set<FamgMeta> joinableFamgs) {
        Set<FamgMeta.Index> joinableForms = new HashSet<FamgMeta.Index>();
        for(FamgMeta joinableFamg : joinableFamgs) {
            joinableForms.add(getFamgIndex(metaData, joinableFamg.getFormID()));
        }
        for(FamgMeta targetFamg : targetFamgs) {
            FormMeta targetForm = targetFamg.getForm();
            Set oldJoinableForms = targetForm.getJoinableForms();
            if(oldJoinableForms != null && oldJoinableForms.size() > 0) {
                joinableForms.addAll(oldJoinableForms);
            }
            targetForm.setJoinableForms(joinableForms);
//            targetForm.setJoinableForms(new ArrayList<FamgMeta.Index>(joinableForms));
        }
    }

    private static boolean canJoinEntities(String e1, String e2, ServletContext ctx) {
        EntityViewConfigManagerLocal manager = IntegratorHelper.getActionContext(ctx).getEntityViewConfigManager();
        Entity entity1 = manager.getEntityViewConfig(e1);
        ChainTable chain = EntityHelper.getChainTable(e2, entity1);
        if(chain == null) {
            return false;
        }

        Chainref chainRef = chain.getChainref();
        if(chainRef != null) {
            String e3 = chainRef.getEntity();
            if(!canJoinEntities(e1, e3, ctx)) {
                return false;
            }

            if(!canJoinEntities(e2, e3, ctx)) {
                return false;
            }
        }

        return true;
    }

    private static void fillExternalFormIndexes(MetaData metaData, Collection<Focus> focuses) {
        for(FocusMeta focusMeta : metaData.getFocuses()) {
            String focusName = focusMeta.getFocusName();
            Focus focus = getFocusByName(focusName, focuses);

            for(SubFocusMeta subFocusMeta : focusMeta.getSubFocuses()) {
                String subfocusName = focusName + EntityHelper.FORM_NAME_SEPARATOR + subFocusMeta.getSubFocusName();
                SubFocus subfocus = (SubFocus) focus.getObject(subfocusName);

                for(TabMeta tabMeta : subFocusMeta.getTabs()) {
                    String tabName = subfocusName + EntityHelper.FORM_NAME_SEPARATOR + tabMeta.getTabName();
                    Tab tab = (Tab) subfocus.getObject(tabName);

                    for(FamgMeta famgMeta : tabMeta.getFamgs()) {
                        if(famgMeta.getFormID() != null) {
                            Form theForm = (Form) tab.getObject(famgMeta.getFormID());
                            if(theForm != null) {
                                ExternalForm[] externalForms = theForm.getExternalForm();
                                for(ExternalForm externalForm : externalForms) {
                                    FormMeta formMeta = famgMeta.getForm();
                                    FamgMeta.Index index = getFamgIndex(metaData, externalForm.getName());
                                    if(index != null) {
                                        formMeta.addExternalForms(index);
                                    } else {
                                        logger.WARN("Couldn't find form index for form:" + externalForm.getName());
                                    }
                                }
                            } else {
                                logger.WARN("FocusManager couldn't find form for formID :" + famgMeta.getFormID());
                            }
                        } else {
                            logger.ERROR("Form id wasn't filled up for tab:" + famgMeta.getIndex().serialize());
                        }
                    }
                }
            }
        }
    }

    private static Focus getFocusByName(String focusName, Collection<Focus> focuses) {
        for(Focus focus : focuses) {
            if(focus.getName().equalsIgnoreCase(focusName)) {
                return focus;
            }
        }
        return null;
    }

    private static FamgMeta.Index getFamgIndex(MetaData metaData, String formID) {
        try {
            String entityName = EntityHelper.getFormEntityName(formID);
            String tmpID = EntityHelper.getParentTabName(formID);
            String tabID = getShortName(tmpID);
            tmpID = EntityHelper.getParentSubFocusName(tmpID);
            String subFocusID = getShortName(tmpID);
            String focusID = EntityHelper.getParentFocusName(tmpID);
            return metaData.getFormIndex(focusID, subFocusID, tabID, entityName);
        } catch(Exception e) {
            logger.ERROR(MessageFormat.format("Cannot find Index for form by name \"{0}\".", formID));
            return null;
        }
    }

    private static String getShortName(String compoundName) {
        int pos = compoundName.lastIndexOf(EntityHelper.FORM_NAME_SEPARATOR);
        if(pos < 0) {
            return compoundName;
        } else {
            return compoundName.substring(pos + EntityHelper.FORM_NAME_SEPARATOR.length());
        }
    }

    private static SubFocusMeta[] getSubFocusMeta(Focus focus, PermissionSet permissions, Map<String, DialogSetting> dialogSettings,
                                                  Map<String, GridSetting> gridSettings, LogonSession ls, ServletContext ctx) {
        List<SubFocusMeta> metaList = new ArrayList<SubFocusMeta>();
        for(int i = 0; i < focus.getSubFocusCount(); i++) {
            SubFocus subFocus = focus.getSubFocus(i);
            Permission permissionForObject = permissions.getPermissionObject(PermissionObjectType.SUB_FOCUS, subFocus.getName());
            if(permissionForObject != null) {//if user has some of rights, it means user can read.
                metaList.add(new SubFocusMeta(subFocus.getCaption(), subFocus.getIcon(),
                        getShortName(subFocus.getName()), getTabMeta(subFocus, permissions, dialogSettings, gridSettings, ls, ctx)));
            }
        }
        return metaList.toArray(new SubFocusMeta[metaList.size()]);
    }

    private static TabMeta[] getTabMeta(SubFocus subFocus, PermissionSet permissions, Map<String, DialogSetting> dialogSettings,
                                        Map<String, GridSetting> gridSettings, LogonSession ls, ServletContext ctx) {
        List<TabMeta> metaList = new ArrayList<TabMeta>();
        for(int i = 0; i < subFocus.getTabCount(); i++) {
            Tab tab = subFocus.getTab(i);
            Permission permissionForObject = permissions.getPermissionObject(PermissionObjectType.TAB, tab.getName());
            if(permissionForObject != null) {//if user has some of rights, it means user can read.
                TabMeta tabMeta = new TabMeta(tab.getCaption(), getShortName(tab.getName()),
                        getFamgMeta(tab, permissions, dialogSettings, gridSettings, ls, ctx));
                tabMeta.setInFrameLinks(tab.getInframelinks());
                tabMeta.setHaveGrid(tab.getGrid());
                tabMeta.setHelpLink(tab.getHelplink());
                metaList.add(tabMeta);
            }
        }
        return metaList.toArray(new TabMeta[metaList.size()]);
    }

    private static FamgMeta[] getFamgMeta(Tab tab, PermissionSet permissions, Map<String, DialogSetting> dialogSettings,
                                          Map<String, GridSetting> gridSettings, LogonSession ls, ServletContext ctx) {
        Form[] forms = tab.getForm();
        List<FamgMeta> famgMetas = new LinkedList<FamgMeta>();
        ActionContext actx = IntegratorHelper.getActionContext(ctx);

        for(Form form : forms) {
            Permission permissionForObject = permissions.getPermissionObject(PermissionObjectType.FORM, form.getName());
            if(permissionForObject != null) {//if user has some of rights, it means user can read.
                String langID = ls.getUser().getLangID();

                FieldMeta[] fields = EntityViewHelper.getMetaInfoForEntity(form.getEntity(),
                        EntityViewHelper.FieldsModificator.FORM,
                        true, ls, actx);
/*
                //get metadata for form
                Set<String> formFields = getAllFormFields(form);
                FieldMeta[] fields = EntityViewHelper.getMetaInfoForEntity(form.getEntity(),
                        EntityViewHelper.FieldsModificator.FORM,
                        true, ls, actx);
                // Search all entity fields that lay on form
                ArrayList<FieldMeta> entityFormFields = new ArrayList<FieldMeta>();
                for (FieldMeta field : fields) {
                    if (formFields.contains(field.getFieldID())) {
                        entityFormFields.add(field);
                    }
                }
                FieldMeta[] availableFormFields = entityFormFields.toArray(new FieldMeta[entityFormFields.size()]);*/
                addDialogSettings(dialogSettings, fields, form.getName());
                EntityMeta entityMeta = new EntityMeta(form.getEntity(), fields);
                FormMeta formMeta = new FormMeta(entityMeta, form.getCaption(), getContextMenuMeta(form, permissions, langID, ctx),
                        EntityViewHelper.getPkeyID(form.getEntity(), actx));
                FormLayoutMeta layoutMeta = createLayoutMetaFromLayout(form,
                        permissionForObject);
                formMeta.setLayoutMeta(layoutMeta);
                formMeta.setButtons(createButtonsMeta(EntityHelper.FormHelper.getFormButtons(form), permissionForObject));
                formMeta.setLinks(createLinksMeta(EntityHelper.FormHelper.getFormLinks(form)));
                formMeta.setLabelsOrientation(form.getLabelsOrientation().getType());
                formMeta.setInMyQueWeb(form.getMyqueweb());
                formMeta.setDescription(form.getDescription());
                formMeta.setAutoSearch(form.getAutosearch());

                // htmlelements
                Htmlelements htmlElements = form.getHtmlelements();
                if(htmlElements != null){
                    List<FormHtmlElementMeta> htmlElementMetas = new ArrayList<FormHtmlElementMeta>();
                    for (Htmlelement htmlElement : htmlElements.getHtmlelement()) {
                        htmlElementMetas.add(new FormHtmlElementMeta(
                                htmlElement.getName(), htmlElement.getHtmlcontent()));
                    }
                    formMeta.setHtmlElements(htmlElementMetas.toArray(new FormHtmlElementMeta[0]));
                }

                //get metadata for grid
                long[] selectedIDs = EntityViewHelper.getSelectedIndexes(form.getEntity(),
                        EntityViewHelper.FieldsModificator.CUSTOMIZED_GRID, actx, ls);

                GridMeta gridMeta = new GridMeta(fields, selectedIDs, getGridSetting(gridSettings, form.getName()));

                famgMetas.add(new FamgMeta(formMeta, gridMeta, form.getName()));
            }
        }
        return famgMetas.toArray(new FamgMeta[famgMetas.size()]);
    }

    private static GridUISettings getGridSetting(Map<String, GridSetting> gridSettings, String name) {
        GridUISettings ret = null;
        if(gridSettings.containsKey(name)) {
            GridSetting setts = gridSettings.get(name);
            ret = new GridUISettings(setts.isCounterOn(), setts.getPageSize(), setts.getColumnWidths());
        }
        return ret;
    }

    private static String getKey(String formId, String fieldId) {
        return formId + FORM_AND_FIELD_DIV + fieldId;
    }

    private static void addDialogSettings(Map<String, DialogSetting> dialogSettings, FieldMeta[] fields, String formName) {
        for(FieldMeta field : fields) {
            DialogSetting setting = dialogSettings.get(getKey(formName, field.getFieldID()));
            if(setting != null) {
                field.setUISettings(new DialogUISettings(setting.getLeft(), setting.getTop(), setting.getWidth(),
                        setting.getHeight()));
            }
        }
    }

    private static FormButtonMeta[] createButtonsMeta(Button[] buttons, Permission formPermissions) {
        List<FormButtonMeta> metaButtons = new LinkedList<FormButtonMeta>();
        for(Button button : buttons) {
            if(AccessRightsManager.canUserPerformAction(formPermissions.getLevel(), getActionForButton(button))) {
                metaButtons.add(new FormButtonMeta(button.getName(), button.getCaption()));
            }
        }
        return metaButtons.toArray(new FormButtonMeta[metaButtons.size()]);
    }

    private static CommonActionTypes getActionForButton(Button button) {
        String buttonName = button.getName();
        if ("FORM_NEW_BUTTON".equalsIgnoreCase(buttonName)) {
            return CommonActionTypes.WRITE;
        } else if ("FORM_CHANGE_BUTTON".equalsIgnoreCase(buttonName)) {
            return CommonActionTypes.WRITE;
        } else if ("FORM_UPDATE_BUTTON".equalsIgnoreCase(buttonName)) {
            return CommonActionTypes.WRITE;
        } else if ("FORM_CHANGE_OR_UPDATE_BUTTON".equalsIgnoreCase(buttonName)) {
            return CommonActionTypes.WRITE;
        }
        PermissionsType permission = button.getPermission();
        if (permission != null) {
            AccessLevel level = AccessLevel.getByLevelConstant(permission.getType());
            if (level == AccessLevel.READ) {
                return CommonActionTypes.READ;
            } else if (level == AccessLevel.WRITE) {
                return CommonActionTypes.WRITE;
            } else if (level == AccessLevel.OWNER) {
                return CommonActionTypes.DELETE_OWNED_RECORDS;
            } else if (level == AccessLevel.FULL_CONTROL) {
                return CommonActionTypes.DELETE_ANY_RECORD;
            }
        }
        return CommonActionTypes.READ; //if button has custom, or search, clear names it means user should at least has read access to see that.
    }

    private static FormLinkMeta[] createLinksMeta(Link[] links) {
        FormLinkMeta[] metaLinks = new FormLinkMeta[links.length];
        for (int i = 0; i < links.length; i++) {
            metaLinks[i] = new FormLinkMeta(links[i].getField(), links[i].getForm());
        }
        return metaLinks;
    }

    private static FormLayoutMeta createLayoutMetaFromLayout(Form form, Permission formPermissions) {
        Row[] rows = EntityHelper.FormHelper.getLayoutRows(form);
        if(rows.length > 0) {
            //convert headers
            Header[] headers = EntityHelper.FormHelper.getLayoutHeaders(form);
            FormLayoutMeta.ColumnHeader[] metaHeaders = new FormLayoutMeta.ColumnHeader[headers.length];
            for(int i = 0; i < headers.length; i++) {
                metaHeaders[i] = new FormLayoutMeta.ColumnHeader(headers[i].getClientwidth());
            }
            //convert rows
            FormLayoutMeta.Row[] metaRows = new FormLayoutMeta.Row[rows.length];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -