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

📄 entityfacade.java

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

                constractDatasetUpdateStructure(dataSet, descriptor, convSelectedIDs, convOldIDs, recordID);
                break;
            }
            case FieldMeta.ENTITYLINK: {
                EntityLinkFieldData elData = (EntityLinkFieldData) data;
                EntityLinkFieldData elOldData = (EntityLinkFieldData) oldData;

                constractDatasetUpdateStructure(dataSet, descriptor, elData.getLinkedEntityIDs(), elOldData.getLinkedEntityIDs(),
                        elData.getCurrentEntityID());
                break;
            }
            case FieldMeta.IN_FORM_GRID: {
                InFormGridFieldData inGridData = (InFormGridFieldData) data;
                InFormGridFieldData inGridOldData = (InFormGridFieldData) oldData;

                RowData[] rows = inGridData.getGridData().getRows();
                RowData[] oldRows = inGridOldData.getGridData().getRows();

                Set<Long> linkedIDs = new HashSet<Long>(rows.length);
                Set<Long> oldIDs = new HashSet<Long>(oldRows.length);

                for(RowData row : rows) {
                    Long id = row.getId();
                    if(id != null) {
                        linkedIDs.add(id);
                    }
                }

                for(RowData row : oldRows) {
                    Long id = row.getId();
                    if(id != null) {
                        oldIDs.add(id);
                    }
                }

                constractDatasetUpdateStructure(dataSet, descriptor, linkedIDs,
                        oldIDs, recordID);
                break;
            }
            default:
                throw new IllegalControlTypeException("Unsupported control type [" + meta.getDataType() + "]");
        }
        if(dataSet.getSreqRecordCount() > 0) {
            updateDatasets.add(dataSet);
        }
    }

    /**
     * This method add appropriate parameters to dataSet update object. It compares old and selected id's and insert
     * appropriate fields to update object.
     * DB doesn't allow to insert incorrect keys, because it uses foreign keys for that purpose. (it is checking by tools).
     *
     * @param dataSet              dataset object that should be filled up with insert and delete object.
     * @param descriptor           dataset descriptor
     * @param selectedLinkedIDs    id's that was selected by user (id for the linked entity)
     * @param oldLinkedIDs         id's that stored in db (id for the linked entity)
     * @param locationReferencedID current (id for the location entity)
     */
    private static void constractDatasetUpdateStructure(SreqDataset dataSet, DatasetDescriptor descriptor,
                                                        Set<Long> selectedLinkedIDs, Set<Long> oldLinkedIDs, Long locationReferencedID) {
        //parse what should be deleted, and what should be inserted
        List<Long> toDelete = new ArrayList<Long>();
        List<Long> toInsert = new ArrayList<Long>();
        for(Long oldID : oldLinkedIDs) {
            if(!selectedLinkedIDs.contains(oldID)) {
                toDelete.add(oldID);
            }
        }

        for(Long id : selectedLinkedIDs) {
            if(!oldLinkedIDs.contains(id)) {
                toInsert.add(id);
            }
        }

        //build update request object for dataset. can add filters only
        for(long idToDelete : toDelete) {
            SreqRecord record = new SreqRecord();
            record.setTodo(TodoSType.DELETE);

            SreqField field = new SreqField();
            field.setName(descriptor.getBindingEntityFkeyFieldNameToLinked());
            field.setSreqFieldValue(Long.toString(idToDelete));
            record.addSreqField(field);

            SreqField field2 = new SreqField();
            field2.setName(descriptor.getBindingEntityFkeyFieldNameToLocation());
            field2.setSreqFieldValue(Long.toString(locationReferencedID));
            record.addSreqField(field2);

            dataSet.addSreqRecord(record);
        }

        for(long idToInsert : toInsert) {
            SreqRecord record = new SreqRecord();
            record.setTodo(TodoSType.INSERT);

            SreqField field = new SreqField();
            field.setName(descriptor.getBindingEntityFkeyFieldNameToLinked());
            field.setSreqFieldValue(Long.toString(idToInsert));
            record.addSreqField(field);

            SreqField field2 = new SreqField();
            field2.setName(descriptor.getBindingEntityFkeyFieldNameToLocation());
            field2.setSreqFieldValue(Long.toString(locationReferencedID));
            record.addSreqField(field2);

            dataSet.addSreqRecord(record);
        }
    }

    private static void addUpdatingField(FieldData data, FieldMeta meta, boolean toBeInserted, FieldData oldData,
                                         LinkedList<SreqField> updateFields) throws IllegalControlTypeException {
        SreqField field = new SreqField();
        field.setName(data.getFieldID());
        String newValue = getValue(data, meta);
        String newText = getText(data, meta);
        field.setSreqFieldValue(newValue);
        field.setSreqFieldText(newText);
        if(!toBeInserted) {
            String oldValue = getValue(oldData, meta);
            String oldText = getText(oldData, meta);
            field.setSreqFieldOldValue(oldValue);
            field.setSreqFieldOldText(oldText);
            field.setHasChanged(!StringUtil.isStringsEquals(newValue, oldValue));
        } else {
            field.setHasChanged(true);
        }
        updateFields.add(field);
    }

    /**
     * Retrieve text string representation. If representation is empty string, then returns null.
     * That method might be needed for the controls, where text make sense too.
     * @param data field data
     * @param meta field meta
     * @return field text string representation
     */
    private static String getText(FieldData data, FieldMeta meta) {
        String newText = EntitySerializeHelper.getTextStringRepresentation(data, meta);
        if("".equalsIgnoreCase(newText.trim())) {
            newText = null;
        }
        return newText;
    }

    /**
     * Retrieve value string representation. If representation is empty string, then returns null.
     * @param data field data
     * @param meta field meta
     * @return field value string representation
     */
    private static String getValue(FieldData data, FieldMeta meta) {
        String newValue = EntitySerializeHelper.getValueStringRepresentation(data, meta);
        if("".equalsIgnoreCase(newValue.trim())) {
            newValue = null;
        }
        return newValue;
    }

    public static IntegratedRecordSet searchEntity(List<EntityData> filterEntities, String requestedEntityName, RequestProperties props,
                                                   LogonSession ls, ActionContext ctx)
            throws EQLException, IncorrectEntityDescriptionException, CouldntGetEJBException {

        Reqs request = buildReqsFromEntities(filterEntities, null, requestedEntityName, props, ls, ctx);
        return performRequest(request, requestedEntityName, ls, ctx, EntityViewHelper.FieldsModificator.CUSTOMIZED_GRID);
    }

    /**
     * Build request for the given entity with filters for this entity.
     *
     * @param filterFields        filter fields for entity
     * @param requestedEntityName requested entity
     * @param eqlFilters
     * @param props
     * @param ls
     * @param ctx
     * @return
     * @throws EQLException
     */
    public static Reqs buildReqsFromThisEntityFields(
            List<FieldData> filterFields, String requestedEntityName,
            String eqlFilters, RequestProperties props, LogonSession ls,
            ActionContext ctx) throws EQLException {
        return buildReqsFromFields(filterFields, requestedEntityName, requestedEntityName,
                eqlFilters, props, ls, ctx);
    }

    /**
     * Build request for the given requested entity with the filter for the another entity. Note this two entities should be linked with each other.
     *
     * @param filterFields        filtering field for the filtering entity
     * @param requestedEntityName requested entity
     * @param filteringEntityName filtering entity
     * @param eqlFilters
     * @param props
     * @param ls
     * @param ctx
     * @return
     * @throws EQLException
     */
    public static Reqs buildReqsFromFields(Collection<FieldData> filterFields,
                                           String requestedEntityName,
                                           String filteringEntityName,
                                           String eqlFilters,
                                           RequestProperties props,
                                           LogonSession ls, ActionContext ctx) throws EQLException {
        FieldData[] data = filterFields.toArray(new FieldData[filterFields.size()]);
        return buildReqsFromEntity(new EntityData(filteringEntityName, -1L, data), requestedEntityName, eqlFilters, props, ls, ctx);
    }

    /**
     * Build the request for the #requestedEntityName entity with the filters for the #filterEntity.
     *
     * @param filterEntity        entity and filters for this entity.
     * @param requestedEntityName requested entity name
     * @param props
     * @param ls
     * @param ctx
     * @return
     * @throws EQLException
     */
    public static Reqs buildReqsFromEntity(EntityData filterEntity,
                                           String requestedEntityName,
                                           String eqlFilters,
                                           RequestProperties props,
                                           LogonSession ls,
                                           ActionContext ctx) throws EQLException {
        ArrayList<EntityData> datas = new ArrayList<EntityData>();
        datas.add(filterEntity);
        return buildReqsFromEntities(datas, eqlFilters, requestedEntityName, props, ls, ctx);
    }

    /**
     * Create request for #requestedEntityName entity, with the given constraints for another linked to requested entity entities.
     *
     * @param filterEntities      constrainst
     * @param eqlFilters      additional eql filter
     * @param requestedEntityName requested entity name
     * @param props
     * @param ls
     * @param ctx
     * @return castor request object
     * @throws EQLException
     */
    public static Reqs buildReqsFromEntities(List<EntityData> filterEntities,
                                             String eqlFilters,
                                             String requestedEntityName,
                                             RequestProperties props,
                                             LogonSession ls, ActionContext ctx
    )
            throws EQLException {

⌨️ 快捷键说明

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