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

📄 entityfacade.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * Copyright 2006-2007 Queplix Corp.
 *
 * Licensed under the Queplix Public License, Version 1.1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.queplix.core.integrator.entity;

import com.queplix.core.client.app.vo.EntityData;
import com.queplix.core.client.app.vo.EntityElement;
import com.queplix.core.client.app.vo.EntityLinkFieldData;
import com.queplix.core.client.app.vo.FieldData;
import com.queplix.core.client.app.vo.FieldMeta;
import com.queplix.core.client.app.vo.GridData;
import com.queplix.core.client.app.vo.InFormGridFieldData;
import com.queplix.core.client.app.vo.MultiselectFieldData;
import com.queplix.core.client.app.vo.RowData;
import com.queplix.core.client.app.vo.SortField;
import com.queplix.core.client.app.vo.SubsetData;
import com.queplix.core.client.app.vo.TextboxFieldData;
import com.queplix.core.client.common.CollectionsHelper;
import com.queplix.core.client.common.StringUtil;
import com.queplix.core.integrator.ActionContext;
import com.queplix.core.integrator.security.LogonSession;
import com.queplix.core.modules.eql.error.EQLException;
import com.queplix.core.modules.eqlext.GetRecordsRes;
import com.queplix.core.modules.eqlext.ejb.SetRecordsLocal;
import com.queplix.core.modules.eqlext.jxb.gr.Req;
import com.queplix.core.modules.eqlext.jxb.gr.ReqEntity;
import com.queplix.core.modules.eqlext.jxb.gr.ReqField;
import com.queplix.core.modules.eqlext.jxb.gr.ReqFilter;
import com.queplix.core.modules.eqlext.jxb.gr.ReqFilters;
import com.queplix.core.modules.eqlext.jxb.gr.ReqFiltersTypeItem;
import com.queplix.core.modules.eqlext.jxb.gr.Reqs;
import com.queplix.core.modules.eqlext.jxb.gr.ResField;
import com.queplix.core.modules.eqlext.jxb.gr.ResRecord;
import com.queplix.core.modules.eqlext.jxb.gr.Ress;
import com.queplix.core.modules.eqlext.jxb.gr.types.ConditionSType;
import com.queplix.core.modules.eqlext.jxb.gr.types.OrderDirectionSType;
import com.queplix.core.modules.eqlext.jxb.sr.Sreq;
import com.queplix.core.modules.eqlext.jxb.sr.SreqDataset;
import com.queplix.core.modules.eqlext.jxb.sr.SreqField;
import com.queplix.core.modules.eqlext.jxb.sr.SreqRecord;
import com.queplix.core.modules.eqlext.jxb.sr.types.TodoSType;
import com.queplix.core.utils.StringHelper;
import com.queplix.core.utils.log.AbstractLogger;
import com.queplix.core.utils.log.Log;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Class is facade for the core2.6 entity described in xml files.
 * This class incapsulate from us details of it's interface representation.
 *
 * @author Sergey Kozmin
 * @since 21.11.2006, 18:26:44
 */
public class EntityFacade {
    private static final AbstractLogger logger = Log.getLog(EntityFacade.class);

    public static IntegratedRecordSet createEmptyEntityRequest(String entityName, LogonSession ls, ActionContext ctx)
            throws EQLException, CouldntGetEJBException, IncorrectEntityDescriptionException, IllegalControlTypeException {
        Reqs castorRequest = createRequest(entityName, new RequestProperties(), true);
        return performRequest(castorRequest, entityName, ls, ctx, EntityViewHelper.FieldsModificator.CUSTOMIZED_GRID);
    }

    public static IntegratedRecordSet getEntityByIDRequest(String entityName, Long rowID, LogonSession ls, ActionContext ctx)
            throws EQLException, CouldntGetEJBException, IncorrectEntityDescriptionException, IllegalControlTypeException {

        return getEntityByIDRequest(entityName, entityName, rowID, ls, ctx);
    }

    /**
     * Search requiredEntity with id filter for the filteringEntity. Entities should be bound. See dataschema binging.
     *
     * @param requiredEntity    entity which will be searched
     * @param filteringEntity   entity for filters
     * @param filteringEntityID id for the filteringEntity
     * @param ls                logon session
     * @param ctx               ActionContext
     * @return integrated result set with for the requiredEntity
     * @throws EQLException                thrown if eql excetpion occured
     * @throws CouldntGetEJBException      thrown if error occured during a ejb instantiation
     * @throws IncorrectEntityDescriptionException
     *                                     throw if entities have incorrect description
     * @throws IllegalControlTypeException if illegal control type was found.
     */
    public static IntegratedRecordSet getEntityByIDRequest(String requiredEntity, String filteringEntity, Long filteringEntityID,
                                                           LogonSession ls, ActionContext ctx)
            throws EQLException, CouldntGetEJBException, IncorrectEntityDescriptionException, IllegalControlTypeException {

        FieldData pkeyDataField = getPkeyFilter(filteringEntity, filteringEntityID, ctx);
        FieldData[] filters = new FieldData[]{pkeyDataField};
        ArrayList<EntityData> filtersEntity = new ArrayList<EntityData>(1);
        EntityData entity = new EntityData(filteringEntity, filteringEntityID, filters);
        filtersEntity.add(entity);
        Reqs request = buildReqsFromEntities(filtersEntity, null, requiredEntity, new RequestProperties(), ls, ctx);
        return performRequest(request, requiredEntity, ls, ctx, EntityViewHelper.FieldsModificator.CUSTOMIZED_GRID);
    }

    /**
     * Method returns found records for the given entity. Result is filtered by entityFilters
     *
     * @param entityFilters filters for request
     * @param entityName    requested entity
     * @param props         request property
     * @param requestType   type of the request
     * @param ls            logon session
     * @param ctx           servlet context
     * @return found records for selected entity
     * @throws EQLException
     * @throws IncorrectEntityDescriptionException
     *
     * @throws CouldntGetEJBException
     */
    public static IntegratedRecordSet getResultByEntitiesFilters(List<EntityData> entityFilters, String entityName,
                                                                 RequestProperties props,
                                                                 EntityViewHelper.FieldsModificator requestType,
                                                                 LogonSession ls, ActionContext ctx)
            throws EQLException {
        Reqs castorRequest = buildReqsFromEntities(entityFilters, null,
                entityName, props, ls, ctx
        );
        return performRequest(castorRequest, entityName, ls, ctx, requestType);
    }

    public static IntegratedRecordSet getCombinedEntitiesResult(List<EntityElement> requestingEntities,
                                                                Collection<EntityData> entityFilters,
                                                                RequestProperties props,
                                                                LogonSession ls, ActionContext ctx)
            throws EQLException {

        Reqs reqs = EntityFacade.createRequest(props);
        reqs.getReq().setReqField(getReqFields(requestingEntities, props));
        reqs.setReqFilters(EntityFacade.getReqFilters(entityFilters, ls, ctx));

        GetRecordsRes recordsRes = ctx.getRecordsManager().process(reqs, ls);

        return parseMultipleEntityResult(recordsRes, ls, ctx);
    }

    public static ReqField[] getReqFields(List<EntityElement> fields, RequestProperties props) {
        ReqField[] rf = new ReqField[fields.size()];
        SortField sortField = props.getSortField();
        for(int i = 0; i < fields.size(); i++) {
            EntityElement t = fields.get(i);
            rf[i] = new ReqField();
            rf[i].setEntity(EntityOperationsHelper.getEntityNameFromFormID(t.getFormId()));
            rf[i].setName(t.getElementId());
            rf[i].setCaption(t.getElementCaption());
            if(sortField != null && t.getElementKey().equalsIgnoreCase(sortField.getFieldID())
                    && sortField.getSortOrder() != null) {
                rf[i].setSortdir(sortField.getSortOrder() ? OrderDirectionSType.ASC : OrderDirectionSType.DESC);
                rf[i].setSort(true);
            }
        }
        return rf;
    }

    /**
     * Perform request to DB, integrated result will include datasets in it. It simply wrap result set with FieldData objects.
     * Initial eql result is attached to integrated result set.
     *
     * @param castorRequest 2.6 core request
     * @param entityName    request entity name
     * @param ls            logon session
     * @param ctx           servlet context
     * @param entityType
     * @return integrated result set
     * @throws EQLException           if eql exception occured
     * @throws CouldntGetEJBException thrown if could not get ejb exception
     * @throws IncorrectEntityDescriptionException
     *                                thrown if entity has incorrect description
     */
    public static IntegratedRecordSet performRequest(Reqs castorRequest, String entityName, LogonSession ls,
                                                     ActionContext ctx, EntityViewHelper.FieldsModificator entityType)
            throws EQLException {
        GetRecordsRes recordsRes = ctx.getRecordsManager().process(castorRequest, ls);
        return parseSingleEntityResult(recordsRes, entityName, entityType, ls, ctx);
    }

    /**
     * Parse resultset and perform additional requests if needed for datasets. Returned metadata is defined by the #entityType parameter
     *
     * @param recordsRes
     * @param entityName
     * @param entityType
     * @param ls
     * @param ctx
     * @return
     * @throws CouldntGetEJBException
     * @throws IncorrectEntityDescriptionException
     *
     */
    private static IntegratedRecordSet parseSingleEntityResult(GetRecordsRes recordsRes, String entityName,
                                                   EntityViewHelper.FieldsModificator entityType,
                                                   LogonSession ls, ActionContext ctx)
            throws CouldntGetEJBException, IncorrectEntityDescriptionException {
        Ress result = recordsRes.getRess();

        Map<String, FieldMeta> metas = EntityViewHelper.getMetaForEntity(entityName, EntityViewHelper.FieldsModificator.FORM, false,
                ls, ctx);
        String pkeyFieldName = EntityViewHelper.getPkeyID(entityName, ctx);

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

        List<IntegratedRecord> list = new ArrayList<IntegratedRecord>(rows);
        List<DatasetDescriptor> datasetsInEntity = getDatasetDescriptors(metas, entityName, ctx);

        for(int r = 0; r < rows; r++) {
            ResRecord rec = result.getRes().getResRecord(r);//datasets result doesn't included into standart eql resultset
            Long recordID = getRowId(rec, pkeyFieldName);

            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 key = fld.getName();
                if(metas.containsKey(key)) {
                    try {
                        fieldSet.put(key, EntitySerializeHelper.createFieldDataFromString(fld, metas.get(key), recordID, ls.getUser(), ctx));
                    } catch (Exception e) {
                        logger.ERROR("Could not retrieve data for entity [" + entityName + "], field name [" + key + "]. ", e);
                    }
                }
            }

            for(DatasetDescriptor descriptor : datasetsInEntity) {
                String fieldName = descriptor.getLocationEntityFieldName();
                try {
                    fieldSet.put(fieldName, createFieldDataForDataset(descriptor, recordID, ls, ctx));
                } catch (Exception e) {
                    logger.ERROR("Could not retrieve data for entity [" + entityName + "], field name [" + fieldName + "]. ", e);

⌨️ 快捷键说明

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