📄 impdocument.java
字号:
package cn.myapps.core.expimp.imp.ejb;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.beanutils.DynaBean;
import cn.myapps.core.deploy.application.ejb.ApplicationProcess;
import cn.myapps.core.deploy.application.ejb.ApplicationVO;
import cn.myapps.core.deploy.module.ejb.ModuleProcess;
import cn.myapps.core.deploy.module.ejb.ModuleVO;
import cn.myapps.core.dynaform.form.ejb.Form;
import cn.myapps.core.dynaform.form.ejb.FormProcess;
import cn.myapps.util.ProcessFactory;
public class ImpDocument extends ImpElement {
public final static String COLUMN_FORMNAME = "FORMNAME";
public ImpDocument(String appId, String modId) {
super(appId, modId);
}
public String getNewFormName(String oldFormName) throws Exception {
String rtn = "";
ApplicationProcess ap = (ApplicationProcess) ProcessFactory
.createProcess(ApplicationProcess.class);
ApplicationVO appVO = (ApplicationVO) ap.doView(applicationid);
if (appVO != null) {
rtn += appVO.getName();
ModuleProcess mp = (ModuleProcess) ProcessFactory
.createProcess(ModuleProcess.class);
ModuleVO modVO = (ModuleVO) mp.doView(moduleid);
if (modVO != null) {
rtn += "/" + modVO.getName();
}
int lastIndex = oldFormName.lastIndexOf("/");
String formname = oldFormName.substring(lastIndex + 1, oldFormName
.length());
rtn += "/" + formname;
}
return rtn;
}
public final static String NAME = "T_DOCUMENT";
public final static String DISPLAY_NAME = "document";
public final static String FOREINGKEY_COLUMN_STATE = "STATE";
public final static String FOREINGKEY_COLUMN_FORMID = "FORMID";
public final static String FOREINGKEY_COLUMN_PARENT = "PARENT";
public Map getImportDatas(Collection dynaBeans, String[] ids)
throws Exception {
Map rtn = new LinkedHashMap();
Collection beans = getBeansOfTable(dynaBeans, getTableName());
for (Iterator iter = beans.iterator(); iter.hasNext();) {
DynaBean bean = (DynaBean) iter.next();
String id = (String) bean.get(IMPOBJECT_ID); // old id
for (int i = 0; i < ids.length; i++) {
if (id.equals(ids[i])) {
String parentId = (String) bean
.get(FOREINGKEY_COLUMN_PARENT);
Map pdoc = new ImpDocument(applicationid, moduleid)
.getImportDatas(dynaBeans,
new String[] { parentId });
rtn.putAll(pdoc);
String oldFormName = (String) bean.get(COLUMN_FORMNAME);
if (oldFormName != null && oldFormName.trim().length() > 0) {
String newFormName = getNewFormName(oldFormName);
changeFormName(bean, newFormName);
}
setForeignKeyValue(bean);
rtn.put(id, bean);
// 相关联的Items
String[] itemIds = getIdsByForeignKeyValue(dynaBeans,
ImpItem.FOREINGKEY_COLUMN_DOCID, id);
Map impItems = new ImpItem(applicationid, moduleid)
.getImportDatas(dynaBeans, itemIds);
rtn.putAll(impItems);
}
}
}
return rtn;
}
public String getTableName() {
return NAME;
}
public String getDisplayName() {
return DISPLAY_NAME;
}
public String getErrorMessage(DynaBean bean) throws Exception {
StringBuffer rtn = new StringBuffer();
String value = (String) bean.get(IMPOBJECT_NAME);
FormProcess fp = (FormProcess) ProcessFactory
.createProcess(FormProcess.class);
String formid = (String) bean.get(FOREINGKEY_COLUMN_FORMID);
rtn.append(getDisplayName() + ":" + value);
rtn.append(" from");
if (formid != null && formid.trim().length() > 0) {
Form form = (Form) fp.doView(formid);
rtn.append(" form:" + form.getName());
}
rtn.append(" is duplicate, please delete it before import.");
return rtn.toString();
}
private void changeFormName(DynaBean bean, String newfn) {
bean.set(COLUMN_FORMNAME, newfn);
}
public void setForeignKeyValue(DynaBean bean) {
resetPrimaryKey(bean);
resetForeignKey(bean, FOREINGKEY_COLUMN_PARENT);
bean.set(FOREIGNKEY_COLUMN_APPLICATION, applicationid);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -