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

📄 integratorgetrecords.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                //lock the record, and after we lock it, get it, because it can be changed, before we lock the record.
                locker.unlock(eqleRes, ls, eqleRes.getRecord(0));
            } else {
                IntegratorHelper.throwException("System could not find the record you are trying to unlock. " +
                        "Probably, the record was deleted, update your data. ");
            }
        } catch (EQLException e) {
            IntegratorHelper.throwException("Eql exception occured. Caused by :" + e.getMessage() + ". ", e);
        } catch (RuntimeException th) {
            IntegratorHelper.reThrowException(th);
        }

        AccumulatedEntityDataResponse entityData = null;
        try {
            BoundFormsOperationsHelper.ResultFormStructure boundResultSet =
                    BoundFormsOperationsHelper.getClearBoundFormResult(formID, ls, servletCacheActionContext);
            List<EntityData> fields = boundResultSet.getFieldDatas();
            EntityData[] ed = new EntityData[0];
            entityData = new AccumulatedEntityDataResponse(ed, fields.toArray(new EntityData[fields.size()]), null);
        } catch (RuntimeException th) {
            IntegratorHelper.reThrowException(th);
        }
        return entityData;
}

    private static String getFocusIDFromFormID(String formID) {
        return formID.substring(0, formID.indexOf("__"));
    }

    public static EntityUpdateResponseObject insertRecord(EntityUpdateRequestObject updateRequest, HttpServletRequest request)
            throws DisplayableException {
        return changeRecord(request, updateRequest, true);
    }

    public static EntityUpdateResponseObject updateRecord(EntityUpdateRequestObject updateRequest, HttpServletRequest request)
            throws DisplayableException {
        return changeRecord(request, updateRequest, false);
    }

    private static EntityUpdateResponseObject changeRecord(HttpServletRequest request, EntityUpdateRequestObject updateRequest, boolean toBeInsterted)
            throws DisplayableException {
        ServletContext ctx = request.getSession().getServletContext();
        EntityUpdateResponseObject resp = null;

        LogonSession ls = WebLoginManager.getLogonSession(request);
        String entityName = EntityOperationsHelper.getEntityNameFromFormID(updateRequest.getFormID());
        Long rowID = updateRequest.getRowID();

        try {
            Collection<FieldData> col = (Collection<FieldData>) updateRequest.getFieldsFilterData();
            //initial entity that contains the proposed to update result
            EntityData entityData = new EntityData(entityName, rowID, col.toArray(new FieldData[col.size()]));
            //entity, that is returned after update
            ActionContext actx = IntegratorHelper.getActionContext(ctx);
            if (toBeInsterted) {
                EntityFacade.insertRecord(entityData, actx, ls);
            } else {
                EntityFacade.updateRecord(entityData, actx, ls);
            }
            IntegratedRecordSet integrResp = EntityFacade.getEntityByIDRequest(entityName, rowID, ls, actx);
            if(integrResp.getRowsCount() > 0) {
                //retrieve updating record and fill up result grid row.
                ArrayList<String> columnValues = new ArrayList<String>();
                Set<String> gridMetas = integrResp.getGridFields();
                IntegratedRecord rec = integrResp.getRecordSet().get(0);
                Map<String, FieldData> fieldDataFields = rec.getFieldSet();

                for (String fieldName : gridMetas) {
                    String gridValue = EntitySerializeHelper.getStringRepresentationForGrid(
                            fieldDataFields.get(fieldName),
                            integrResp.getRecordMeta().get(fieldName),
                            ls, actx);
                    columnValues.add(gridValue);
                }
                String key = integrResp.getPkeyFieldName();
                Long newRowID = Long.parseLong(EntitySerializeHelper.getValueStringRepresentation(fieldDataFields.get(key), integrResp.getRecordMeta().get(key)));
                RowData rowdata = new RowData(newRowID, columnValues.toArray(new String[columnValues.size()]));

                //get bound result to fill up all the forms, bound with updating one.
                BoundFormsOperationsHelper.ResultFormStructure boundResultSet =
                        BoundFormsOperationsHelper.getBoundFormResult(updateRequest.getFormID(), rowID, ls, actx);
                List<EntityData> entities = boundResultSet.getEntityDatas();
                List<EntityData> fields = boundResultSet.getFieldDatas();
                resp = new EntityUpdateResponseObject(entities.toArray(new EntityData[entities.size()]),
                        fields.toArray(new EntityData[fields.size()]), rowdata);
            } else {
                IntegratorHelper.throwException("Could not select the updated record, probably it wasn't updated properly. ");
            }
        } catch (EQLException e) {
            IntegratorHelper.throwException(e, ls.getUser().getLangID(), ctx);
        } catch (RecordDoesntExistsException e) {
            IntegratorHelper.throwException(e.getMessage(), e);
        } catch (RuntimeException th) {
            IntegratorHelper.reThrowException(th);
        }
        return resp;
    }

    public static EntityDataResponseObject createEntity(NewEntityRequestObject newEntityObjectRequest, HttpServletRequest request)
            throws DisplayableException {
        ServletContext ctx = request.getSession().getServletContext();
        EntityDataResponseObject resp = null;

        try {
            LogonSession ls = WebLoginManager.getLogonSession(request);
            String formID = newEntityObjectRequest.getFormID();
            String entityName = EntityOperationsHelper.getEntityNameFromFormID(formID);
            Collection<FieldData> prototypeDataList = (Collection<FieldData>) newEntityObjectRequest.getFieldsFilterData();

            EntityData entityData = EntityFacade.createEntityPrototype(entityName, prototypeDataList, ls, IntegratorHelper.getActionContext(ctx));
            resp = new EntityDataResponseObject(entityData);
        } catch (UserQueryParseException ex) {
            IntegratorHelper.throwException("Incorrect value: " + ex.getValue() + ". Entity: " + ex.getEntityName() + ". Field: " +
                    ex.getFieldCaption(), ex);
        } catch (EQLSystemException ex) {
            IntegratorHelper.throwException("EQL System Exception. " + ex.getMessage(), ex);
        } catch (EQLException ex) {
            IntegratorHelper.throwException("EQL Exception. " + ex.getMessage(), ex);
        } catch (RecordDoesntExistsException e) {
            IntegratorHelper.reThrowException(e);
        } catch (RuntimeException th) {
            IntegratorHelper.reThrowException(th);
        }
        return resp;
    }

    public static MoreDataResponseObject getMoreData(FieldDataRequest elementRequest, HttpServletRequest request)
            throws DisplayableException {
        MoreDataResponseObject resp = null;

        try {
            LogonSession ls = WebLoginManager.getLogonSession(request);

            resp = getMoreData(elementRequest, ls, IntegratorHelper.getActionContext(request));
        } catch (UserQueryParseException ex) {
            IntegratorHelper.throwException("Incorrect value: " + ex.getValue() + ". Entity: " + ex.getEntityName() + ". Field: " +
                    ex.getFieldCaption(), ex);
        } catch (EQLSystemException ex) {
            IntegratorHelper.throwException("EQL System Exception. " + ex.getMessage(), ex);
        } catch (EQLException ex) {
            IntegratorHelper.throwException("EQL Exception. " + ex.getMessage(), ex);
        } catch (RuntimeException th) {
            IntegratorHelper.reThrowException(th);
        }
        return resp;
    }

    private static MoreDataResponseObject getMoreData(
            FieldDataRequest elementRequest, LogonSession ls,
            ActionContext ctx)
            throws EQLException, DisplayableException {
        MoreDataResponseObject resp = null;
        switch (elementRequest.getRequestType()) {
            case FieldType.ENTITYREFERENCE: {
                EntityReferenceDataRequest req
                        = (EntityReferenceDataRequest) elementRequest;
                FieldOnDemandData onDemandData = getMoreDataForEntityReference(
                        req, ls, ctx);
                resp = new MoreDataResponseObject(onDemandData);
                break;
            }
            case FieldType.LISTBOX: {
                ListboxDataRequest req = (ListboxDataRequest) elementRequest;
                SubsetMeta availableChoises = getAvailableChoises(req.getEntityName(), req.getAdditionalFilters(),
                        req.getEqlFilter(), ls, ctx
                );
                resp = new MoreDataResponseObject(new ListBoxOnDemandData(req.getElementID(), availableChoises));
                break;
            }
            case FieldType.MULTISELECT: {
                MultiselectDataRequest req = (MultiselectDataRequest) elementRequest;
                SubsetMeta availableChoises = getAvailableChoises(req.getEntityName(), req.getAdditionalFilters(),
                        req.getEqlFilter(), ls, ctx
                );
                resp = new MoreDataResponseObject(new MultiselectOnDemandData(req.getElementID(), availableChoises));
                break;
            }
            case FieldType.HISTORY: {
                HistoryDataRequest req = (HistoryDataRequest) elementRequest;
                resp = new MoreDataResponseObject(loadHistory(req, ls, ctx));
                break;
            }
            case FieldType.IN_FORM_GRID: {
                FieldOnDemandData onDemandData = getMoreDataForInFormGrid((InFormDataRequest) elementRequest, ls, ctx);
                resp = new MoreDataResponseObject(onDemandData);
                break;
            }
            default: {
                IntegratorHelper.throwException("Could not find 'more data' functionality for control of type:"
                        + elementRequest.getRequestType() + ". ");
            }
        }
        return resp;
    }

    private static FieldOnDemandData getMoreDataForInFormGrid(
            InFormDataRequest inFormDataRequest, LogonSession ls,
            ActionContext ctx) throws DisplayableException {
        InFormGridOnDemandData data = null;
        try {
            int type = inFormDataRequest.getInformGridRequestType();
            switch(type) {
                case InFormGridType.SEARCH_TYPE: {
                    RequestProperties props = new RequestProperties();
                    props.setIgnoreSendOnRequest(false);

                    String entityName = inFormDataRequest.getRequestingEntity();
                    SearchInformRequest req
                            = (SearchInformRequest) inFormDataRequest;

                    RequestBuilder requestBuilder = RequestBuilderFactory.createRequestBuilder(
                            entityName, entityName,
                            (Collection<FieldData>) req.getFieldsFilters(), props, ls,
                            ctx);
                    SearchGridRecordsResponseObject result = IntegratorHelper
                            .getNotEmptyResult(0, requestBuilder,
                                    entityName,
                                    EntityViewHelper.FieldsModificator.CUSTOMIZED_GRID,
                                    ls, ctx);
                    data = new SearchInformOnDemandData(
                            inFormDataRequest.getElementID(),
                            new ArrayList<RowData>(Arrays.asList( result.getGridData().getRows())));

                    break;
                }
                case InFormGridType.GET_CONTROL_DATA_TYPE: {
                    GetControlDataInformRequest req
                            = (GetControlDataInformRequest) inFormDataRequest;
                    data = new GetControlInformOnDemandData(req.getElementID(),
                            getMoreData(req.getRequest(), ls,
                                    ctx).getFieldData());
                    break;
                }
                case InFormGridType.GET_RECORDS_DATA_TYPE: {
                    GetRecordsDataInformRequest req = (GetRecordsDataInformRequest) inFormDataRequest;
                    String entityName = req.getRequestingEntity();
                    RecordFilter filter = req.getFilter();

                    List<RowData> rows;
                    if(filter.isRecordsFilter()) {
                        RequestBuilder requestBuilder = RequestBuilderFactory
                                .createRequestBuilder(entityName,
                                        filter.getRecordIds(),
                                        new RequestProperties(), ls, ctx);

⌨️ 快捷键说明

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