📄 entityviewhelper.java
字号:
return ret;
}
/**
* Search efield in array.
* @param field field to search
* @param array array
* @return index in array
*/
private static int getIndexInArray(Efield field, Efield[] array) {
int ret = -1;
for(int i = 0; i < array.length; i++) {
String name = array[i].getName();
if(name != null && name.equalsIgnoreCase(field.getName())) {
ret = i;
break;
}
}
return ret;
}
private static BaseFieldMeta retrieveMetaForListbox(Efield field, String fieldID, String fieldCaption, ActionContext ctx,
LogonSession ls) throws EQLException, IncorrectEntityDescriptionException {
BaseFieldMeta ret;// Get listref entity data.
Listref listref = field.getListref();
if(listref != null) {
String lrEntityName = listref.getEntity();
LinkedList<SubsetItemMeta> options = getOptionsForSubsetMeta(lrEntityName, Collections.<FieldData>emptyList(),
null, ls, ctx
);
ret = new ListboxFieldMeta(fieldID, lrEntityName, fieldCaption, new SubsetMeta(options.toArray(
new SubsetItemMeta[options.size()])), field.getDynamic());
} else {
throw new IncorrectEntityDescriptionException(field.getEntityName(), "Control ["
+ field.getName() + "] has type ControlSType.SELECT_TYPE, but hasn't listref entity. ");
}
return ret;
}
/**
* Retrieve entity name on which #referencingFieldName in #entityName is referencing. If there is no such field
* returns null object, otherwise returns referencing entity name.
*
* @param entityName entity, where referencing field is located
* @param referencingFieldName field name in entity
* @param ctx servlet context
* @return referenced entity name
* @throws IncorrectEntityDescriptionException thrown if entity has unknown referencing entity.
*/
public static String getListRefEntityName(String entityName, String referencingFieldName, ActionContext ctx)
throws IncorrectEntityDescriptionException {
String referencedEntityName = null;
EntityViewConfigManagerLocal evcm = ctx.getEntityViewConfigManager();
try {
// Get Entity object
Entity entity = evcm.getEntityViewConfig(entityName);
Efield[] fields = entity.getEfield();
for(Efield field : fields) {
if(field.getName().equalsIgnoreCase(referencingFieldName)) {
referencedEntityName = field.getListref().getEntity();
break;
}
}
} catch (UnknownEntityException e) {
throw new IncorrectEntityDescriptionException(entityName, "Could not get entity list filed. ", e);
}
return referencedEntityName;
}
public static String getListFieldNameForEntity(String entityName, ActionContext ctx)
throws IncorrectEntityDescriptionException {
String listFieldName;
EntityViewConfigManagerLocal evcm = ctx.getEntityViewConfigManager();
try {
// Get Entity object
Entity entity = evcm.getEntityViewConfig(entityName);
listFieldName = entity.getListfield();
} catch (UnknownEntityException e) {
throw new IncorrectEntityDescriptionException(entityName, "Could not get entity list filed. ", e);
}
return listFieldName;
}
private static String getFieldCaption(String langID, String entityName, String fieldName, ActionContext ctx) {
String fieldCaption;
CaptionManagerLocal captionManager = null;
try {
captionManager = ctx.getCaptionManager();
} catch (Exception e) {
logger.ERROR("Could't get caption for field", e);
}
if(captionManager != null) {
fieldCaption = captionManager.getEfieldCaption(langID, entityName, fieldName);
} else {
fieldCaption = fieldName;
}
return fieldCaption;
}
public static void setFieldsForGrid(LogonSession ls, String entity, FieldMeta[] fields, ActionContext ctx)
{
List<String> fieldNames = new ArrayList<String>();
for(FieldMeta field : fields) {
fieldNames.add(field.getFieldID());
}
setFieldsForGrid(ls, entity, fieldNames.toArray(new String[0]), ctx);
}
public static void setFieldsForGrid(LogonSession ls, String entity, String[] fields, ActionContext ctx)
{
UserPropertyManagerLocal userPropManager = ctx.getUserPropertyManager();
userPropManager.setFieldsForGrid(ls.getUser(), entity, fields);
}
/**
* Retrieve entity pkey id. If there is no field with pkey = true in entity returns null.
*
* @param entityName entity to retrieve name
* @param ctx current servlet context
* @return pkey field name
* @throws IncorrectEntityDescriptionException if there is no pkey defined in entity
*/
public static String getPkeyID(String entityName, ActionContext ctx) throws IncorrectEntityDescriptionException {
String pkeyID = null;
EntityViewConfigManagerLocal evcm = ctx.getEntityViewConfigManager();
if(evcm != null) {
// Get Entity object
Entity entity;
try {
entity = evcm.getEntityViewConfig(entityName);
Efield pkeyField = searchPkeyField(entity);
if(pkeyField != null) {
pkeyID = pkeyField.getName();
} else {
throw new IncorrectEntityDescriptionException("Could not find pkey field in entity [" + entityName + "]. ");
}
} catch (UnknownEntityException e) {
logger.ERROR(e);
}
}
return pkeyID;
}
private static Efield searchPkeyField(Entity entity) {
Efield pkeyField = null;
Efield[] fields = entity.getEfield();
for(Efield field : fields) {
if(field.getPkey()) {
pkeyField = field;
break;
}
}
return pkeyField;
}
public static Map<String, FieldMeta> getMetaForEntity(String entityName, FieldsModificator entityType, boolean withCaptions,
LogonSession ls, ActionContext ctx) {
Map<String, FieldMeta> metas = new LinkedHashMap<String, FieldMeta>();
FieldMeta[] fieldsMeta = getMetaInfoForEntity(entityName, entityType, withCaptions, ls, ctx);
for(FieldMeta meta : fieldsMeta) {
metas.put(meta.getFieldID(), meta);
}
return metas;
}
public static FieldMeta getMetaForField(String entityName, String fieldName,
boolean withCaptions, LogonSession ls, ActionContext ctx) {
Map<String, FieldMeta> metas = getMetaForEntity(
entityName, FieldsModificator.FORM, withCaptions, ls, ctx);
return metas.get(fieldName);
}
/**
* Returns {@link DatasetDescriptor} for the given dataset for the given entity
*
* @param entityName entity name
* @param datasetName dataset name
* @param ctx servlet context
* @return {@link DatasetDescriptor} object if given dataset exists in entity null object
* if dataset doesn't exists.
* @ thrown if ejb config manager could not be retrieved.
*/
public static DatasetDescriptor getDatasetMetadata(String entityName, String datasetName, ActionContext ctx) {
DatasetDescriptor desc = null;
EntityViewConfigManagerLocal evcm = ctx.getEntityViewConfigManager();
if(evcm != null) {
// Get Entity object
try {
Entity entity = evcm.getEntityViewConfig(entityName);
Dataset[] datasets = entity.getDataset();
for(Dataset dataset : datasets) {
if(dataset.getName().equalsIgnoreCase(datasetName)) {
//retrieve binding and location information from fkeys parameters.
Fkeys fk = retriveFkColumnName(entityName, dataset.getEntity(), ctx);
String bindingEntityFkColumnToLocationEntity = null;
String locationEntityPkColumn = null;
if(fk != null) {
bindingEntityFkColumnToLocationEntity = fk.getFkColumn();
locationEntityPkColumn = fk.getPkColumn();
}
//retrieve binding and linked entities information from fkeys params
Fkeys secondfk = retriveFkColumnName(dataset.getLinkedEntity(), dataset.getEntity(), ctx);
String bindingEntityFkeyFieldNameToLinked = null;
String linkedEntityPkeyFieldName = null;
if(secondfk != null) {
bindingEntityFkeyFieldNameToLinked = secondfk.getFkColumn();
linkedEntityPkeyFieldName = secondfk.getPkColumn();
}
String linkedEntityFieldName = getDatasetName(dataset.getLinkedEntity(), dataset.getEntity(), ctx);
ControlSType type = dataset.getControl();
desc = new DatasetDescriptor(getDatasetType(type), entityName, locationEntityPkColumn,
datasetName, dataset.getEntity(),
bindingEntityFkColumnToLocationEntity,
bindingEntityFkeyFieldNameToLinked,
dataset.getLinkedEntity(),
linkedEntityPkeyFieldName,
linkedEntityFieldName,
true
);
break;//don't need to iterate entity if we already found field
}
}
} catch (UnknownEntityException e) {
logger.ERROR(e);
}
}
return desc;
}
private static DatasetType getDatasetType(ControlSType type) {
DatasetType retType = null;
switch(type.getType()) {
case ControlSType.GRID_TYPE: {
retType = DatasetType.IN_FORM_GRID;
break;
}
case ControlSType.LINK_TYPE: {
retType = DatasetType.ENYTITYLINK;
break;
}
case ControlSType.M2M_TYPE: {
retType = DatasetType.MULTISELECT;
break;
}
default: {
throw new IllegalControlTypeException("Couldn't process dataset with type: "
+ type.toString());
}
}
return retType;
}
private static String getDatasetName(String entityName, String pointedToEntityName, ActionContext ctx) {
String ret = null;
EntityViewConfigManagerLocal evcm = ctx.getEntityViewConfigManager();
if(evcm != null) {
// Get Entity object
Entity entity = evcm.getEntityViewConfig(entityName);
Dataset[] datasets = entity.getDataset();
for(Dataset dataset : datasets) {
if(dataset.getEntity().equalsIgnoreCase(pointedToEntityName)) {
ret = dataset.getName();
}
}
}
return ret;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -