📄 entityviewhelper.java
字号:
/*
* 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.BaseFieldMeta;
import com.queplix.core.client.app.vo.CheckBoxMeta;
import com.queplix.core.client.app.vo.DateFieldMeta;
import com.queplix.core.client.app.vo.EntityLinkFieldMeta;
import com.queplix.core.client.app.vo.EntityMeta;
import com.queplix.core.client.app.vo.EntityReferenceMeta;
import com.queplix.core.client.app.vo.FieldData;
import com.queplix.core.client.app.vo.FieldMeta;
import com.queplix.core.client.app.vo.FormMeta;
import com.queplix.core.client.app.vo.GridMeta;
import com.queplix.core.client.app.vo.HistoryFieldMeta;
import com.queplix.core.client.app.vo.InFormGridFieldMeta;
import com.queplix.core.client.app.vo.ListboxFieldMeta;
import com.queplix.core.client.app.vo.MemoFieldMeta;
import com.queplix.core.client.app.vo.MultiselectFieldMeta;
import com.queplix.core.client.app.vo.SubsetItemMeta;
import com.queplix.core.client.app.vo.SubsetMeta;
import com.queplix.core.client.app.vo.TextBoxFieldMeta;
import com.queplix.core.client.app.vo.TextareaFieldMeta;
import com.queplix.core.client.common.StringUtil;
import com.queplix.core.integrator.ActionContext;
import com.queplix.core.integrator.security.LogonSession;
import com.queplix.core.jxb.entity.Dataset;
import com.queplix.core.jxb.entity.Efield;
import com.queplix.core.jxb.entity.Entity;
import com.queplix.core.jxb.entity.Fkeys;
import com.queplix.core.jxb.entity.Listref;
import com.queplix.core.jxb.entity.types.ControlSType;
import com.queplix.core.modules.config.ejb.CaptionManagerLocal;
import com.queplix.core.modules.config.ejb.EntityViewConfigManagerLocal;
import com.queplix.core.modules.config.ejb.UserPropertyManagerLocal;
import com.queplix.core.modules.config.error.UnknownEntityException;
import com.queplix.core.modules.eql.error.EQLException;
import com.queplix.core.modules.eqlext.jxb.gr.Reqs;
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.Collections;
import java.util.HashMap;
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 helps to get entity view config
*
* @author Sergey Kozmin
* @since 25.10.2006, 17:21:17
*/
public class EntityViewHelper {
/**
* Describes what fields should be used when performing an operation with entities.
*/
public static enum FieldsModificator {
/**
* All fields should be included to entity except of hidden ones.
*/
FORM,
/**
* Fields, that marked <code>grid="true"</code> to be included.
*/
GRID,
/**
* Fields, that marked <code>grid="true"</code> and choosen by user in customizer tool to be included.
*/
CUSTOMIZED_GRID
}
private static final AbstractLogger logger = Log.getLog(EntityViewHelper.class);
private static final String FIELD_AND_ENTITY_SEPARATOR = ".";
private static final EntityViewHelper instance = new EntityViewHelper();
/**
* Cache of the objects, that is to be cleared when entity metadata updates.
* Here we assume that client code, that will clear that cache when entity meta updates will be loaded on the same
* JVM (classloader). Same assumption exists with other caches in the system. For instance:
* <code>Cache cache = ConfigPropertyFactory.getInstance().getViewObjectsCache();</code>
*/
private static final Map<String, FieldMeta> fieldsMetaCache = Collections.synchronizedMap(new HashMap<String, FieldMeta>());
// final Lock lock = new ReentrantLock();
private EntityViewHelper() {
}
public void putFieldMeta(String key, FieldMeta meta) {
fieldsMetaCache.put(key, meta);
}
public void clearCache(String key) {
fieldsMetaCache.remove(key);
}
public void clearCache() {
fieldsMetaCache.clear();
}
public FieldMeta getFieldMeta(String key) {
//todo upgrade it. no need to sync users, that need just to get field, if nothing updating now. updating is very rare operation.
return fieldsMetaCache.get(key);
}
public static EntityViewHelper getInstance() {
return instance;
}
/**
* Retrieve array of FieldMeta for the given entity.
* @param entityName entity name
* @param entityType the purpose of requesting.
* @param withCaptions should captions be included to meta information.
* @param ls logon session
* @param ctx action context
* @return array of FieldMeta
* @see com.queplix.core.integrator.entity.EntityViewHelper.FieldsModificator
*/
public static FieldMeta[] getMetaInfoForEntity(String entityName, FieldsModificator entityType,
boolean withCaptions, LogonSession ls, ActionContext ctx) {
EntityViewConfigManagerLocal entityManager = ctx.getEntityViewConfigManager();
// Get Entity object
List<FieldMeta> listOfMeta = new LinkedList<FieldMeta>();
Entity entity;
try {
entity = entityManager.getEntityViewConfig(entityName);
Efield[] fields = getFieldsToBeProcessessed(entity.getEfield(), entityName, entityType, ls, ctx);
Efield pkeyField = searchPkeyField(entity);
for(Efield field : fields) {
try {
String key = entityName + FIELD_AND_ENTITY_SEPARATOR + field.getName();
FieldMeta meta = getInstance().getFieldMeta(key);
if(meta == null) {
meta = createFieldMetaFromEfield(field, pkeyField, withCaptions, ls, ctx);
getInstance().putFieldMeta(key, meta);
}
listOfMeta.add(meta);
} catch (IllegalControlTypeException e) {
logger.WARN(e);
} catch (EQLException e) {
logger.WARN(e);
} catch (IncorrectEntityDescriptionException e) {
logger.WARN(e);
}
}
if(entityType == FieldsModificator.FORM) {
Dataset[] datasets = entity.getDataset();
for(Dataset dataset : datasets) {
try {
String key = entityName + FIELD_AND_ENTITY_SEPARATOR + dataset.getName();
FieldMeta meta = getInstance().getFieldMeta(key);
if(meta == null) {
meta = createFieldMetaFromDataset(dataset, entityName, withCaptions, ls, ctx);
getInstance().putFieldMeta(key, meta);
}
listOfMeta.add(meta);
} catch (IllegalControlTypeException e) {
logger.ERROR(e);
} catch (EQLException e) {
logger.ERROR(e);
} catch (IncorrectEntityDescriptionException e) {
logger.ERROR(e);
}
}
}
} catch (UnknownEntityException e) {
logger.ERROR(e);
}
return listOfMeta.toArray(new FieldMeta[listOfMeta.size()]);
}
private static Efield[] getFieldsToBeProcessessed(Efield[] initialEfields, String entityName,
FieldsModificator entityType, LogonSession ls, ActionContext ctx) {
Efield[] fieldsToBeProcesses;
switch(entityType) {
case FORM: {
fieldsToBeProcesses = initialEfields;
break;
}
case GRID: {
ArrayList<Efield> resList = new ArrayList<Efield>();
for(Efield initialEfield : initialEfields) {
if(initialEfield.getGrid()) {
resList.add(initialEfield);
}
}
fieldsToBeProcesses = resList.toArray(new Efield[resList.size()]);
break;
}
case CUSTOMIZED_GRID: {
UserPropertyManagerLocal userPropManager = ctx.getUserPropertyManager();
String[] fieldNames = userPropManager.getFieldsForGrid(ls.getUser(), entityName);
if(fieldNames != null) {
Map<String, Efield> efields = new HashMap<String, Efield>();
for(Efield efield : initialEfields) {
efields.put(efield.getName(), efield);
}
ArrayList<Efield> resList = new ArrayList<Efield>();
for(String fieldName : fieldNames) {
resList.add(efields.get(fieldName));
}
fieldsToBeProcesses = resList.toArray(new Efield[resList.size()]);
} else {//take simple grid set
ArrayList<Efield> resList = new ArrayList<Efield>();
for(Efield initialEfield : initialEfields) {
if(initialEfield.getGrid()) {
resList.add(initialEfield);
}
}
fieldsToBeProcesses = resList.toArray(new Efield[resList.size()]);
}
break;
}
default: {
fieldsToBeProcesses = initialEfields;
}
}
return fieldsToBeProcesses;
}
public static Set<String> getGridFields(String entityName, FieldsModificator entityType, boolean withCaptions, LogonSession ls,
ActionContext ctx) {
FieldMeta[] meta = getMetaInfoForEntity(entityName, entityType, withCaptions, ls, ctx);
LinkedHashSet<String> ret = new LinkedHashSet<String>(meta.length);
for(FieldMeta fieldMeta : meta) {
ret.add(fieldMeta.getFieldID());
}
return ret;
}
private static FieldMeta createFieldMetaFromDataset(Dataset dataset, String entityName, boolean withCaptions, LogonSession ls,
ActionContext ctx)
throws IllegalControlTypeException, EQLException, IncorrectEntityDescriptionException {
BaseFieldMeta ret;
if(dataset == null) {
throw new IllegalControlTypeException("Couldn't fill field meta data, because field objectis null");
} else {
ControlSType type = dataset.getControl();
String datasetID = dataset.getName();//field name is field id within entity
String datasetCaption;
if(withCaptions) {
datasetCaption = getFieldCaption(ls.getUser().getLangID(), dataset.getEntityName(), dataset.getName(), ctx);
} else {
datasetCaption = "";
}
String linkedEntityName = dataset.getLinkedEntity();
if(type == null) {
throw new IncorrectEntityDescriptionException(dataset.getEntityName(), "Could not find \"control\" attribute. ");
} else {
switch(type.getType()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -