Hi Isomorphic,
I got a problem about my project.
This problem happens sometimes.
Before today, everything works fine, But it happens today .
When this problem happens , the client broswer just has no response no matter what i click , then wait for a long time, it gives me a window msg "operation timeout".
I can do nothing, but restart my tomcat,or refresh the page then login in again, then it works fine again.
I don't know what causes this problem .
this is my .ds.xml code
manualTree.java
tomcat log :
client code:
I got a problem about my project.
Code:
=== 2014-04-25 09:50:20,173 [88-3] DEBUG AppBase - [builtinApplication.manualTre
e_fetch] No public zero-argument method named '_manualTree_fetch' found, performing generic datasource operation
Before today, everything works fine, But it happens today .
When this problem happens , the client broswer just has no response no matter what i click , then wait for a long time, it gives me a window msg "operation timeout".
I can do nothing, but restart my tomcat,or refresh the page then login in again, then it works fine again.
I don't know what causes this problem .
this is my .ds.xml code
Code:
<DataSource
ID="manualTree"
serverConstructor="com.atoz.technicalreport.server.datasource.ManualTreeDS">
<fields>
<field name="id" type="integer" />
<field name="nodeId" type="text" primaryKey="true" />
<field name="parentId" type="text" foreignKey="manualTree.nodeId" />
<field name="name" type="text" title="名称" length="100" />
<field name="sortId" type="integer"/>
<field name="isOpen" type="boolean"/>
<field name="isFolder" type="boolean"/>
<field name="status" title="状态" type="integer" width="10%">
<valueMap>
<!-- 以下是章节的状态,在原有状态下加2得到 -->
<value id="2">创建</value>
<value id="3">检入</value>
<!-- 以下是手册的状态 -->
<value id="0">待审核</value>
<value id="1">已发布</value>
<value id="-1">未通过</value>
<value id="-2">未发布</value>
</valueMap>
</field>
<field name="secrecy" title="密级" type="integer" width="5%" >
<valueMap>
<value id="3">机密</value>
<value id="2">秘密</value>
<value id="1">非密</value>
</valueMap>
</field>
<field name="remark" title="备注" type="text" width="10%" hidden="true"/>
<field name="number" title="版本" type="integer" length="10" width="20%"/>
<field name="creator" title="创建人" width="10%" foreignKey="user.userId" valueXPath="creator/userFullName"/>
<field name="createTime" title="创建时间" type="datetime" width="13%" />
<field name="updator" title="更新人" width="10%" foreignKey="user.userId" valueXPath="updator/userFullName"/>
<field name="updateTime" title="更新时间" type="datetime" width="13%" />
<field name="icon" title="图标" type="text" />
<field name="contentId" title="内容编号" type="integer" />
<field name="contentName" title="内容名称" type="text" />
<field name="isSelected" title="是否选中" type="boolean" />
<field name="msg" type="text" hidden="true"/>
</fields>
<operationBindings>
<operationBinding operationType="fetch" operationId="getManualList">
<serverObject className="com.atoz.technicalreport.server.DMI.ManualManageDMI"
methodName="getManualList"/>
</operationBinding>
<operationBinding operationType="fetch" operationId="getLinkedManual">
<serverObject className="com.atoz.technicalreport.server.DMI.ManualManageDMI"
methodName="getLinkedManual"/>
</operationBinding>
<operationBinding operationType="add" operationId="linkManual">
<serverObject className="com.atoz.technicalreport.server.DMI.ManualManageDMI"
methodName="linkManual"/>
</operationBinding>
<operationBinding operationType="add" operationId="linkContent">
<serverObject className="com.atoz.technicalreport.server.DMI.ManualManageDMI"
methodName="linkContent"/>
</operationBinding>
<operationBinding operationType="fetch" operationId="getReportReleaseList">
<serverObject className="com.atoz.technicalreport.server.DMI.ManualManageDMI"
methodName="getReportReleaseList"/>
</operationBinding>
<operationBinding operationType="add" operationId="linkChapter">
<serverObject className="com.atoz.technicalreport.server.DMI.ManualManageDMI"
methodName="linkChapter"/>
</operationBinding>
<operationBinding operationType="update" operationId="publishPreManual">
<serverObject className="com.atoz.technicalreport.server.DMI.ManualReleaseManageDMI"
methodName="publishManual"/>
</operationBinding>
</operationBindings>
</DataSource>
Code:
package com.atoz.technicalreport.server.datasource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.atoz.technicalreport.server.service.ManualManageService;
import com.atoz.technicalreport.server.service.ModelManageService;
import com.atoz.technicalreport.server.service.ReportMS;
import com.atoz.technicalreport.server.service.ServiceException;
import com.atoz.technicalreport.server.service.UserManageService;
import com.atoz.technicalreport.server.servlet.util.ImageUtil;
import com.atoz.technicalreport.server.servlet.util.PropertiesUtil;
import com.atoz.technicalreport.server.servlet.util.StringUtil;
import com.atoz.technicalreport.shared.Chapter;
import com.atoz.technicalreport.shared.Manual;
import com.atoz.technicalreport.shared.ManualFolder;
import com.atoz.technicalreport.shared.ManualNode;
import com.atoz.technicalreport.shared.ManualVersion;
import com.atoz.technicalreport.shared.Model;
import com.atoz.technicalreport.shared.Report;
import com.atoz.technicalreport.shared.ReportRelease;
import com.atoz.technicalreport.shared.User;
import com.isomorphic.datasource.BasicDataSource;
import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DSResponse;
@SuppressWarnings("serial")
public class ManualTreeDS extends BasicDataSource{
ManualManageService mams = new ManualManageService();
UserManageService ums = new UserManageService();
ReportMS rms = new ReportMS();
/**
* 添加
*/
public DSResponse executeAdd(DSRequest dsRequest) throws Exception {
Map map = dsRequest.getValues();
String nodeId = (String)map.get("nodeId");
ManualNode node = null;
if(nodeId.startsWith("O")){
return addOrUpdateManual(dsRequest);
}else if(nodeId.startsWith("F")&&"chapter".equals(dsRequest.getOperationId())){
String name = StringUtil.ObjectToStringTrim(map.get("name"));
if(StringUtil.isNullOrEmpty(name)){
return StringUtil.getDSResponse("name", "必填字段.");
}
Long contentId = (Long)map.get("contentId");
Long secrecy = (Long)map.get("secrecy");
Long userId = (Long)map.get("userId");
String remark = StringUtil.ObjectToStringTrim(map.get("remark"));
Chapter c = new Chapter();
c.setName(name);
c.setRemark(remark);
c.setSecrecy(secrecy);
Date date = new Date();
c.setCreateTime(date);
c.setUpdateTime(date);
User user = ums.getUserByUserID(userId.intValue());
c.setCreator(user);
c.setUpdator(user);
c.setBelongManualFolder(mams.getManualFolderById(Long.parseLong(nodeId.substring(1))));
ReportRelease rr = null;
if(!StringUtil.isNullOrEmpty(contentId)){
rr = rms.getReportRelease(contentId);
}
if(rr!=null){
c.setStatus(1);
c.setReport(rr.getReport());
}else{
c.setStatus(0);
}
Chapter c2 = mams.addChapter(c);
node = copyChapter(c2,null);
}else{
Long userId = (Long)map.get("userId");
Long manualId = (Long)map.get("manualId");
String folderName = StringUtil.ObjectToStringTrim(map.get("name"));
if(StringUtil.isNullOrEmpty(folderName)){
// throw new ServiceException("型号名称不能为空!", "modelName", "型号名称不能为空!");
return StringUtil.getDSResponse("name", "必填字段");
}
ManualFolder mf = new ManualFolder();
mf.setFolderName(folderName);
Date date = new Date();
mf.setCreateTime(date);
mf.setUpdateTime(date);
User user = ums.getUserByUserID(userId.intValue());
mf.setCreator(user);
mf.setUpdator(user);
Long parentId = Long.parseLong(nodeId.substring(1));
mf.setParentId(parentId);
mf.setBelongManual(mams.getManualById(manualId));
ManualFolder mf2 = mams.addManualFolder(mf);
node = copyFolder(mf2);
}
return new DSResponse(node);
}
/**
* 更新
*/
public DSResponse executeUpdate(DSRequest dsRequest) throws Exception {
Map map = dsRequest.getValues();
String nodeId = (String)map.get("nodeId");
ManualNode node = null;
if(nodeId.startsWith("F")){
String folderName = StringUtil.ObjectToStringTrim(map.get("name"));
if(StringUtil.isNullOrEmpty(folderName)){
return StringUtil.getDSResponse("name", "必填字段.");
}
Long userId = (Long)map.get("userId");
ManualFolder mf = mams.modifyManualFolder(Long.parseLong(nodeId.substring(1)),userId.intValue(),folderName);
node = copyFolder(mf);
}else if(nodeId.startsWith("M")){
return addOrUpdateManual(dsRequest);
}else if(nodeId.startsWith("C")){
String name = StringUtil.ObjectToStringTrim(map.get("name"));
if(StringUtil.isNullOrEmpty(name)){
return StringUtil.getDSResponse("name", "必填字段.");
}
String description = StringUtil.ObjectToStringTrim(map.get("remark"));
Long contentId = (Long)map.get("contentId");
Long secrecy = (Long)map.get("secrecy");
Long userId = (Long)map.get("userId");
Chapter c = mams.getChapterById(Long.parseLong(nodeId.substring(1)));
ReportRelease rr = null;
if(!StringUtil.isNullOrEmpty(contentId)){
rr = rms.getReportRelease(contentId);
}
c.setName(name);
c.setSecrecy(secrecy);
c.setRemark(description);
if(rr!=null){
c.setStatus(1);
c.setReport(rr.getReport());
}else{
c.setStatus(0);
}
Date date = new Date();
c.setUpdateTime(date);
User user = ums.getUserByUserID(userId.intValue());
c.setUpdator(user);
Chapter c2 = mams.updateChapter(c);
node = copyChapter(c2,null);
}
return new DSResponse(node);
}
/**
* 删除
*/
public DSResponse executeRemove(DSRequest dsRequest) throws Exception {
Map map = dsRequest.getCriteria();
String nodeId = (String)map.get("nodeId");
if(nodeId.startsWith("F")){
mams.removeFolder(Long.parseLong(nodeId.substring(1)));
}else if(nodeId.startsWith("M")){
mams.removeManual(-Long.parseLong(nodeId.substring(1)));
}else if(nodeId.startsWith("C")){
mams.removeChapter(Long.parseLong(nodeId.substring(1)));
}
return new DSResponse();
}
/**
* fetch
*/
public DSResponse executeFetch(DSRequest dsRequest) throws Exception {
Map map = dsRequest.getCriteria();
// Object nodeId = map.get("nodeId");
String parentId = (String)map.get("parentId");
String reportNodeId = (String)map.get("reportNodeId");
List<ManualNode> lstNodes = new ArrayList<ManualNode>();
if(parentId == null){
Long modelId = (Long)map.get("modelId");
ModelManageService moms = new ModelManageService();
Model mo = moms.getModelById(modelId);
ManualNode rootma = new ManualNode();
rootma.setNodeId("O"+mo.getId());
rootma.setId(0);
rootma.setName(mo.getModelName());
rootma.setIcon("nuaa/manual/model.png");
// rootma.setIsOpen(true);
rootma.setIsFolder(true);
if(StringUtil.isNullOrEmpty(modelId)){
throw new ServiceException("获取模型编号失败!");
}
List<Manual> lstMs = mams.getManualList(modelId);
for (Manual m : lstMs) {
lstNodes.add(copyManual(m));
}
//添加关联的手册
// for (Manual m : mo.getManuals()) {
// lstNodes.add(copyManual(m));
// }
lstNodes.add(rootma);//最后才能添加根节点
}else if(!StringUtil.isNullOrEmpty(parentId)&&parentId.toString().startsWith("M")){
Long mId = Long.parseLong(parentId.toString().substring(1));
List<ManualFolder> lstFolder = mams.getManualFolders(mId);
for(ManualFolder mf : lstFolder){
lstNodes.add(copyFolder(mf));
}
}else if(!StringUtil.isNullOrEmpty(parentId)&&parentId.toString().startsWith("F")){
Long mId = Long.parseLong(parentId.toString().substring(1));
List<ManualFolder> lstFolder = mams.getManualFolders(mId);
for(ManualFolder mf : lstFolder){
lstNodes.add(copyFolder(mf));
}
List<Chapter> lstChapter = mams.getChapterByFolderId(mId);
Report report = null;
if(!StringUtil.isNullOrEmpty(reportNodeId)){
report = rms.getReport(Long.parseLong(reportNodeId.substring(1)));
}
for(Chapter c : lstChapter){
lstNodes.add(copyChapter(c,report));
}
}
// else if(!StringUtil.isNullOrEmpty(parentId)&& parentId.toString().startsWith("O")){
// Long modelId = (Long)map.get("modelId");
// List<Manual> lstMs = mams.getManualList(modelId);
// for (Manual m : lstMs) {
// lstNodes.add(copyManual(m));
// }
// }
return new DSResponse(lstNodes);
}
private ManualNode copyManual(Manual m){
ManualNode node = new ManualNode();
node.setId(m.getId());
node.setManualId(m.getId());
node.setParentId("O"+m.getBelongModel().getId());
node.setNodeId("M"+(-m.getId()));
node.setName(m.getName());
node.setIcon("nuaa/manual/book.png");
// node.setSecrecy(m.getSecrecy());
// node.setIsOpen(true);
node.setIsFolder(true);
ManualVersion mv = m.getCurrentVersion();
if(mv!=null&&mv.getCurrentRelease()!=null){
node.setStatus(mv.getCurrentRelease().getStatus());
}else{
node.setStatus(m.getStatus());
}
node.setCreateTime(m.getCreateTime());
node.setCreator(m.getCreator());
node.setUpdateTime(m.getUpdateTime());
node.setUpdator(m.getUpdator());
node.setRemark(m.getRemark());
// node.setSecrecy(m.getSecrecy());
return node;
}
private ManualNode copyFolder(ManualFolder mf){
ManualNode node = new ManualNode();
node.setId(mf.getFolderId());
node.setManualId(mf.getBelongManual().getId());
if(mf.getParentId()>0){
node.setParentId("F"+mf.getParentId());
}else{
node.setParentId("M"+mf.getParentId());
}
node.setNodeId("F"+mf.getFolderId());
node.setName(mf.getFolderName());
node.setIcon("nuaa/manual/content.png");
// node.setIsOpen(true);
node.setIsFolder(true);
return node;
}
private ManualNode copyChapter(Chapter c,Report report){
ManualNode node = new ManualNode();
ManualFolder mf = c.getBelongManualFolder();
Report rr = c.getReport();
if(mf!=null&&mf.getBelongManual()!=null){
node.setManualId(mf.getBelongManual().getId());
}
node.setId(c.getId());
node.setName(c.getName());
node.setParentId("F"+mf.getFolderId());
node.setNodeId("C"+c.getId());
if(c.getStatus()==1){
node.setIcon("nuaa/manual/chapter_linked.png");
}else{
node.setIcon("nuaa/manual/chapter.png");
}
node.setIsOpen(false);
node.setIsFolder(false);
node.setStatus(c.getStatus()+2);
node.setCreateTime(c.getCreateTime());
node.setCreator(c.getCreator());
node.setUpdateTime(c.getUpdateTime());
node.setUpdator(c.getUpdator());
node.setRemark(c.getRemark());
node.setChapterId(c.getId());
node.setSecrecy(c.getSecrecy());
if(report!=null&&c.getReport()!=null){
node.setIsSelected(report.getId()==c.getReport().getId());
}
if(rr!=null){
node.setContentId(rr.getId());
node.setContentName(rr.getReportName());
}
return node;
}
/**
* 添加或更新手册
* @param dsRequest
* @return
* @throws Exception
*/
private DSResponse addOrUpdateManual(DSRequest dsRequest) throws Exception{
Map map = dsRequest.getValues();
ModelManageService moms = new ModelManageService();
//获取参数
String nodeId = (String)map.get("nodeId");
Long userId = (Long)map.get("userId");
String name = StringUtil.ObjectToStringTrim(map.get("name"));
if(StringUtil.isNullOrEmpty(name)){
return StringUtil.getDSResponse("name", "必填字段.");
}
String strIds = (String)map.get("strIds");
Map<String, String> msgsMap = PropertiesUtil.getMsgsMap();
String SEP = File.separator;
String dir = msgsMap.get("storehouse_path") + SEP + msgsMap.get("manual_home") + SEP +"tempManual" +SEP+userId+SEP;
String fileStr = (String)map.get("file");
boolean isEmpty = StringUtil.isNullOrEmpty(fileStr);
String type = "";
String filename="";
String fullFileName = "";
if(!isEmpty){
File file = new File(fileStr);
filename = file.getName();
type = StringUtil.getFileType(filename);
boolean isSupport = false;
for(String str : StringUtil.COVERTYPES){
if(str.equals(type)){
isSupport = true;
}
}
if(!isSupport){
return StringUtil.getDSResponse("file", "不支持的文件格式!");
}
fullFileName = dir + filename;
//获取路径
File fullDirF = new File(dir);
if(!fullDirF.exists()){
fullDirF.mkdirs();
}
// else {
// File[] tempFiles = fullDirF.listFiles();
// for (File tempFile : tempFiles) {
// tempFile.delete();
// }
// }
//写入文件
InputStream in = dsRequest.getUploadedFileStream("file");
FileOutputStream out = new FileOutputStream(fullFileName);
byte[] bt = new byte[1024];
int count;
while ((count = in.read(bt)) > 0) {
out.write(bt, 0, count);
}
in.close();
out.close();
}
Manual m ;
boolean isAdd = nodeId.startsWith("O");
Date date = new Date();
User user = ums.getUserByUserID(userId.intValue());
if(isAdd){
m = new Manual();
m.setCreator(user);
m.setCreateTime(date);
Long modelId = Long.parseLong(nodeId.substring(1));
Model model = moms.getModelById(modelId);
m.setBelongModel(model);
m.setStatus(-2);//未发布
}else{
m = mams.getManualById(-Long.parseLong(nodeId.substring(1)));
// modelId=Long.parseLong(reportsTo.substring(1));
}
Set<Model> lstMs = new HashSet<Model>();
if(!StringUtil.isNullOrEmpty(strIds)){
String[] ids = strIds.split(",");
if(ids!=null&&ids.length>0){
for(String id : ids){
lstMs.add(moms.getModelById(Long.parseLong(id)));
}
}
}
m.setName(name);
m.setModels(lstMs);
m.setUpdator(user);
m.setUpdateTime(date);
if(isAdd){
if(!isEmpty){
m.setCoverPath(type);
}
mams.addManual(m);
}else{
if(!isEmpty){
m.setCoverPath(m.getId()+"."+type);
}
mams.updateManual(m);
}
// 移动文件
if(!isEmpty){
String dstDir = msgsMap.get("storehouse_path") + SEP + msgsMap.get("manual_home") + SEP + m.getId() +SEP;
String newName = m.getId() + "." + type;
try {
File file = new File(fullFileName);
if(file.exists()){
//移动
// FileUtil.moveFile(fullFileName, dstDir+newName);
//制作缩略图并删除源图
ImageUtil.saveImageAsJpg(fullFileName, dstDir+newName, 100, 130, true);
file.delete();
}
} catch (Exception e1) {
System.out.println("--------------------移动文件出错...-----------------------");
e1.printStackTrace();
}
}
return new DSResponse(copyManual(m));
}
}
Code:
=== 2014-04-25 11:11:31,259 [8-17] DEBUG IDACall - Header Name:Value pair: cooki
e:JSESSIONID=63FC10D14A3E67F10F91AB0D47BE4F7E; ASP.NET_SessionId=xkioqhnmmsjo40d
crsoxscpu
=== 2014-04-25 11:11:31,259 [8-17] DEBUG IDACall - session exists: 63FC10D14A3E6
7F10F91AB0D47BE4F7E
=== 2014-04-25 11:11:31,259 [8-17] DEBUG IDACall - remote user: null
=== 2014-04-25 11:11:31,259 [8-17] INFO RequestContext - URL: '/dreams/techrepo
rtsys/sc/IDACall', User-Agent: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6
.1; WOW64; Trident/6.0)': MSIE with Accept-Encoding header, ready for compressed
JS
=== 2014-04-25 11:11:31,275 [8-17] DEBUG XML - Parsed XML from (in memory stream
): 0ms
=== 2014-04-25 11:11:31,275 [8-17] DEBUG RPCManager - Processing 1 requests.
=== 2014-04-25 11:11:31,275 [8-17] DEBUG DSRequest - Caching instance 9276 of DS
manualTree from DSRequest.getDataSource()
=== 2014-04-25 11:11:31,275 [8-17] DEBUG RPCManager - Request #1 (DSRequest) pay
load: {
criteria:{
modelId:2886,
parentId:null
},
operationConfig:{
dataSource:"manualTree",
operationType:"fetch",
textMatchStyle:"exact"
},
componentId:"isc_TreeGrid_2",
appID:"builtinApplication",
operation:"manualTree_fetch",
oldValues:{
modelId:2886,
parentId:null
}
}
=== 2014-04-25 11:11:31,275 [8-17] INFO IDACall - Performing 1 operation(s)
=== 2014-04-25 11:11:31,275 [8-17] DEBUG DeclarativeSecurity - Processing securi
ty checks for DataSource null, field null
=== 2014-04-25 11:11:31,275 [8-17] DEBUG DeclarativeSecurity - DataSource manual
Tree is not in the pre-checked list, processing...
=== 2014-04-25 11:11:31,275 [8-17] DEBUG AppBase - [builtinApplication.manualTre
e_fetch] No userTypes defined, allowing anyone access to all operations for this
application
=== 2014-04-25 11:11:31,275 [8-17] DEBUG AppBase - [builtinApplication.manualTre
e_fetch] No public zero-argument method named '_manualTree_fetch' found, perform
ing generic datasource operation
Code:
folderTreeGrid = new TreeGrid();
folderTreeGrid.setWidth100();
folderTreeGrid.setHeight100();
folderTreeGrid.setDataSource(manualTreeDS);
folderTreeGrid.setAutoFetchData(false);
folderTreeGrid.setShowOpenIcons(false);
folderTreeGrid.setShowOpenIcons(false);
folderTreeGrid.setSelectionAppearance(SelectionAppearance.ROW_STYLE);
folderTreeGrid.setSelectionType(SelectionStyle.SINGLE);
Tree tree = new Tree();
tree.setModelType(TreeModelType.PARENT);
tree.setParentIdField("parentId");
tree.setIsFolderProperty("isFolder");
// tree.setOpenProperty("isOpen");
tree.setAutoOpenRoot(true);
folderTreeGrid.setDataProperties(tree);
folderTreeGrid.setCanReorderRecords(true);//0
folderTreeGrid.setCanAcceptDroppedRecords(true);//1
folderTreeGrid.setCanDragRecordsOut(true);//2
folderTreeGrid.setCanReparentNodes(true);//3
folderTreeGrid.setSeparateFolders(true);
folderTreeGrid.setSortFoldersBeforeLeaves(true);