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

📄 entityfacade.java

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

            list.add(new IntegratedRecord(fieldSet));
        }

        return new IntegratedRecordSet(pkeyFieldName, EntityViewHelper.getListFieldNameForEntity(entityName, ctx),
                list, metas, recordsRes, EntityViewHelper.getGridFields(entityName, entityType, false, ls, ctx));
    }

    private static Long getRowId(ResRecord rec, String pkeyFieldId) {
        Long ret = -1L;
        int pkeyIndex = -1;
        for(int i = 0; i < rec.getResFieldCount(); i++) {
            ResField field =  rec.getResField(i);
            if(field.getName().equalsIgnoreCase(pkeyFieldId)) {
                pkeyIndex = i;
            }
        }
        if(pkeyIndex >= 0) {
            String rowID = rec.getResField(pkeyIndex).getResFieldValue();
            ret = Long.parseLong(rowID);
        }
        return ret;
    }

    private static IntegratedRecordSet parseMultipleEntityResult(GetRecordsRes recordsRes, LogonSession ls, ActionContext ctx)
            throws CouldntGetEJBException, IncorrectEntityDescriptionException {
        Ress result = recordsRes.getRess();

        //parse result and fill up empty values with non-empty incoming data
        int rows = result.getRes().getResRecordCount();

        Map<String, Map<String, FieldMeta>> entitiesMap = new HashMap<String, Map<String, FieldMeta>>();

        List<IntegratedRecord> list = new ArrayList<IntegratedRecord>(rows);
        //create combined meta. Since we can have names collision we use key as "entityName" + "fieldName".
        Set<String> combinedGridFields = new LinkedHashSet<String>();
        Map<String, FieldMeta> combinedRecordMeta = new LinkedHashMap<String, FieldMeta>();
        
        //iterate result fields
        for(int r = 0; r < rows; r++) {
            ResRecord rec = result.getRes().getResRecord(r);//datasets result doesn't included into standart eql resultset

            int cols = rec.getResFieldCount();
            Map<String, FieldData> fieldSet = new LinkedHashMap<String, FieldData>(cols);
            for(int c = 0; c < cols; c++) {
                ResField fld = rec.getResField(c);
                String fieldName = fld.getName();
                String entityName = fld.getEntity();

                Map<String, FieldMeta> metas;
                if(entitiesMap.containsKey(entityName)) {
                    metas = entitiesMap.get(entityName);
                } else {
                    metas = EntityViewHelper.getMetaForEntity(entityName, EntityViewHelper.FieldsModificator.FORM, false, ls, ctx);
                    entitiesMap.put(entityName, metas);
                }
                if(metas.containsKey(fieldName)) {
                    try {
                        String key = EntityElement.getElementKey(entityName, fieldName);

                        FieldMeta fieldMeta = metas.get(fieldName);
                        fieldSet.put(key, EntitySerializeHelper.createFieldDataFromString(fld, fieldMeta, -1L, ls.getUser(), ctx));

                        combinedGridFields.add(key);
                        combinedRecordMeta.put(key, fieldMeta);
                    } catch (Exception e) {
                        logger.ERROR("Could not retrieve data for entity [" + entityName + "], field name [" + fieldName + "]. ", e);
                    }
                }
            }

            list.add(new IntegratedRecord(fieldSet));
        }

        return new IntegratedRecordSet("", "", list, combinedRecordMeta, recordsRes, combinedGridFields);
    }

    /**
     * Creates {@link com.queplix.core.client.app.vo.FieldData} element for the 3 types of datasets : multiselect, entitylink and
     * inform grid.
     *
     * @param descriptor dataset descriptor, that contains all the data, that describs dataset.
     * @param recordID   record id, for which this dataset should be get. (in old terms pkey value)
     * @param ls         logon session.
     * @param ctx        servlet context @return created field data object. Cannot be a null object.
     * @throws IllegalControlTypeException thrown if dataset descriptor points to not-dataset field.
     * @throws EQLException                thrown if some eql exception occured during procedure performing.
     * @throws CouldntGetEJBException      thrown if some ejb could not be get.
     * @throws IncorrectEntityDescriptionException
     *                                     thrown if some entity has incorrect description
     */
    private static FieldData createFieldDataForDataset(
            DatasetDescriptor descriptor,
            Long recordID,
            LogonSession ls,
            ActionContext ctx)
            throws EQLException {
        FieldData retData;
        DatasetType datasetType = descriptor.getType();
        switch(datasetType) {
            case ENYTITYLINK: {
                FieldData filter = new TextboxFieldData(descriptor.getBindingEntityFkeyFieldNameToLocation(), Long.toString(recordID));
                FieldData[] filters = new FieldData[]{filter};
                ArrayList<EntityData> filtersEntity = new ArrayList<EntityData>(1);
                EntityData entity = new EntityData(descriptor.getBindingEntity(), -1L, filters);
                filtersEntity.add(entity);
                Reqs request = buildReqsFromEntities(filtersEntity, null,
                        descriptor.getBindingEntity(),
                        new RequestProperties(), ls, ctx);
                IntegratedRecordSet result = performRequest(request, descriptor.getBindingEntity(), ls, ctx,
                        EntityViewHelper.FieldsModificator.CUSTOMIZED_GRID);
                String linkedPkeyValueFieldName = descriptor.getBindingEntityFkeyFieldNameToLinked();
                FieldMeta idFieldMeta = result.getRecordMeta().get(linkedPkeyValueFieldName);
                if(idFieldMeta == null) {//entity result doesn't contain required foreign key value.
                    throw new IncorrectEntityDescriptionException(descriptor.getBindingEntity(),
                            "Could not find field [" + linkedPkeyValueFieldName + "] in entity [" + descriptor.getBindingEntity()
                                    + "]. Check your entity description. ");
                } else {
                    ArrayList<Long> linkedPkeyValues = new ArrayList<Long>(result.getRowsCount());
                    for(IntegratedRecord record : result.getRecordSet()) {
                        FieldData idData = record.getFieldSet().get(linkedPkeyValueFieldName);
                        try {
                            Long linkedRecordID = Long.parseLong(EntitySerializeHelper.getValueStringRepresentation(idData, idFieldMeta));
                            linkedPkeyValues.add(linkedRecordID);
                        } catch (NumberFormatException e) {
                            logger.ERROR("Field [" + linkedPkeyValueFieldName + "] in entity [" + descriptor.getBindingEntity()
                                    + "] should be numeric and should not contain null or empty values. Because it is used as a foreign key to ["
                                    +
                                    descriptor.getLinkedEntity() + "] entity. ", e);
                        } catch (IllegalControlTypeException e) {
                            logger.ERROR("Field [" + linkedPkeyValueFieldName + "] in entity [" + descriptor.getBindingEntity()
                                    + "] could not be represented as a string. ", e);
                        }
                    }
                    retData = new EntityLinkFieldData(descriptor.getLocationEntityFieldName(), recordID, new HashSet<Long>(
                            linkedPkeyValues));
                }
                break;
            }
            case MULTISELECT: {
                //get selected entities in the binding table
                IntegratedRecordSet resp = getEntityByIDRequest(descriptor.getLinkedEntity(), descriptor.getLocationEntity(), recordID, ls,
                        ctx);

                String pkeyFieldName = EntityViewHelper.getPkeyID(descriptor.getLinkedEntity(), ctx);


                /* Core 2.6 implementation.
                // Getting records.
                Ress ress = resp.getInitialResultSet().getRess();

                String pkeyFieldName = null;
                ResHeaderField[] headers = ress.getResHeader().getResHeaderField();
                for(ResHeaderField header : headers) {
                    *//* in 2.6 version it was necessary to have both (header.getGrid() && header.getPkey()) on for linked entity (see see m2mform.xsl)
                     * but here due to the fact we only one pkey field in entity we change logic to header.getPkey() is enaught to indicate field
                     *//*
                    if(header.getPkey()) {
                        pkeyFieldName = header.getName();
                        break;
                    }
                }*/
                if(pkeyFieldName != null) {
                    //Retrieving the selected items.
                    ArrayList<Long> selectedItems = new ArrayList<Long>();

                    if(resp.getRowsCount() > 0) {
                        Map<String, FieldMeta> metaData = resp.getRecordMeta();
                        for(IntegratedRecord record : resp.getRecordSet()) {
                            FieldData recData = record.getFieldSet().get(pkeyFieldName);
                            try {
                                long l = Long.parseLong(EntitySerializeHelper.getValueStringRepresentation(recData, metaData.get(pkeyFieldName)));
                                selectedItems.add(l);
                            } catch (Exception e) {
                                logger.ERROR("Could not add selected value. ", e);
                            }
                        }
                    }
                    //convert ArrayLong to long[]
                    long[] ds = new long[selectedItems.size()];
                    for(int i = 0; i < selectedItems.size(); i++) {
                        ds[i] = selectedItems.get(i);
                    }
                    SubsetData selected = new SubsetData(ds);
                    retData = new MultiselectFieldData(descriptor.getLocationEntityFieldName(), selected);
                } else {
                    throw new IncorrectEntityDescriptionException(descriptor.getBindingEntity(),
                            "Could not find field pkey=\"true\" and grid=\"true\" in entity ["
                                    + descriptor.getLinkedEntity() + "]. ");
                }
                break;
            }
            case IN_FORM_GRID: {
                //check if all needed data is available
                String fieldName = descriptor.getLocationEntityFieldName();

                //build filters for current entity, and select linked entity with it.
                List<FieldData> filterFields = new LinkedList<FieldData>();
                filterFields.add(new TextboxFieldData(descriptor.getLocationPkeyFieldName(), String.valueOf(recordID)));

                Reqs request = buildReqsFromFields(filterFields,
                        descriptor.getLinkedEntity(),
                        descriptor.getLocationEntity(), null, new RequestProperties(),
                        ls, ctx);

                IntegratedRecordSet resp = performRequest(request,
                        descriptor.getLinkedEntity(), ls, ctx,
                        EntityViewHelper.FieldsModificator.GRID);

                RowData[] rows = EntityOperationsHelper.retrieveGridRowsDataFromResult(resp, ls, ctx);

                retData = new InFormGridFieldData(fieldName, new GridData(rows, descriptor.getLinkedEntity()));
                break;
            }
            default: {
                throw new IllegalControlTypeException("Couldn't create data for dataset of type [" + datasetType.toString() + "]."); 
            }
        }

        return retData;
    }

    private static List<DatasetDescriptor> getDatasetDescriptors(Map<String, FieldMeta> metas, String entityName,
                                                                 ActionContext ctx) throws CouldntGetEJBException {
        List<DatasetDescriptor> ret = new LinkedList<DatasetDescriptor>();
        Set<String> keys = metas.keySet();
        for(String key : keys) {
            int type = metas.get(key).getDataType();
            if(type == FieldMeta.MULTISELECT || type == FieldMeta.IN_FORM_GRID || type == FieldMeta.ENTITYLINK) {
                ret.add(EntityViewHelper.getDatasetMetadata(entityName, key, ctx));
            }
        }
        return ret;
    }

    /**
     * Delete records of the single entity.
     * This method doesn't take any filters from entity data, but just take its id. 
     * @param entityData data array of EntityData. All the entity datas should correspond to the single entity
     * @param ctx action context
     * @param ls logon session
     * @throws EQLException if some eql exception occured.
     */
    public static void deleteRecord(EntityData[] entityData, ActionContext ctx, LogonSession ls)
            throws EQLException {
        if(entityData.length == 0) {
            throw new IllegalArgumentException("No record(s) to delete");
        }

        // Let's assume that all entityData's corresponds to the single entity
        String entityName = entityData[0].getEntityID();
        String pkeyName = EntityViewHelper.getPkeyID(entityName, ctx);

⌨️ 快捷键说明

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