📄 wftemplatemgrbean.java
字号:
package com.coshare.joyteam.projectMgr.sessionFacade;
import java.util.Collection;
import java.util.List;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.RemoveException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.NamingException;
import com.coshare.joyteam.projectMgr.dto.ActivityDTO;
import com.coshare.joyteam.projectMgr.dto.ActivityRelDTO;
import com.coshare.joyteam.projectMgr.dto.AssignmentDTO;
import com.coshare.joyteam.projectMgr.dto.TemplateDTO;
import com.coshare.joyteam.projectMgr.dto.TplResourceDocDTO;
import com.coshare.joyteam.projectMgr.dto.TplResourceOrgDTO;
import com.coshare.joyteam.util.ID;
import com.coshare.joyteam.projectMgr.dao.*;
import com.coshare.joyteam.projectMgr.entitybean.template.*;
import com.coshare.joyteam.projectMgr.entitybean.activity.*;
import com.coshare.joyteam.projectMgr.entitybean.activityRel.*;
import com.coshare.joyteam.projectMgr.entitybean.tplResourceDoc.*;
import com.coshare.joyteam.projectMgr.entitybean.tplResourceOrg.*;
/**
* @ejb.bean name="WFTemplateMgr"
* jndi-name="WFTemplateMgrBean"
* type="Stateful"
*
**/
public class WFTemplateMgrBean implements SessionBean
{
private static final long serialVersionUID = 3906654111096060213L;
private SessionContext context;
private TemplateDAO templateDAO;
private ActivityDAO activityDAO;
private ActivityRelDAO activityRelDAO;
public void ejbCreate()
{
DAOFactory factory = DAOFactory.newInstance();
templateDAO = factory.getTemplateDAO();
activityDAO = factory.getActivityDAO();
activityRelDAO = factory.getActivityRelDAO();
}
public void ejbActivate()
{
//System.out.println("ejbActivate()");
}
public void ejbPassivate()
{
//System.out.println("ejbPassivate()");
}
public void setSessionContext(javax.ejb.SessionContext context)
{
//System.out.println("setSessionContext(javax.ejb.SessionContext ctx) ");
this.context = context;
}
public void unsetSessionContext()
{
//System.out.println("unsetSessionContext()");
this.context = null;
}
public void ejbRemove()
{
this.templateDAO.close();
this.activityDAO.close();
this.activityRelDAO.close();
}
/**
* @ejb.interface-method
* view-type="both"
**/
public int addTemplate(TemplateDTO template)
{
int rt = 0;
try {
TemplateLocalHome templateLocalHome = TemplateUtil.getLocalHome();
templateLocalHome.create(template);
rt = 1;
} catch (NamingException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
}
return rt;
}
/**
* @ejb.interface-method
* view-type="both"
**/
public int delTemplate(String templateName, int version)
{
int rt = 0;
try {
TemplateLocalHome templateLocalHome = TemplateUtil.getLocalHome();
TemplatePK pk = new TemplatePK(templateName, version);
templateLocalHome.remove(pk);
rt = 1;
} catch (NamingException e) {
e.printStackTrace();
} catch (EJBException e) {
e.printStackTrace();
} catch (RemoveException e) {
e.printStackTrace();
}
return rt;
}
/**
*
* @ejb.interface-method
* view-type="both"
**/
public Collection getALLTemplates() {
try {
return this.templateDAO.getTemplates();
} catch (DAOException e) {
e.printStackTrace();
return null;
}
}
/**
* @ejb.interface-method
* view-type="both"
**/
public Collection getTemplates(String templateName)
{
try {
return this.templateDAO.getTemplates(templateName);
} catch (DAOException e) {
e.printStackTrace();
return null;
}
}
public TemplateDTO getTemplate(ID templateId) {
try {
return this.templateDAO.getTemplate(templateId);
} catch (DAOException e) {
e.printStackTrace();
return null;
}
}
/**
* @ejb.interface-method
* view-type="both"
**/
public TemplateDTO getTemplate(String templateName, int version)
{
try {
return this.templateDAO.getTemplate(templateName, version);
} catch (DAOException e) {
e.printStackTrace();
return null;
}
}
/**
* @ejb.interface-method
* view-type="both"
**/
public int addActivity(ActivityDTO activity)
{
int rt = 0;
try {
ActivityLocalHome activityLocalHome = ActivityUtil.getLocalHome();
activityLocalHome.create(activity);
rt = 1;
} catch (NamingException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
}
return rt;
}
/**
* @ejb.interface-method
* view-type="both"
**/
public int delActivity(
ID templateId,
String activityName,
int activityType)
{
int rt = 0;
try {
ActivityLocalHome activityLocalHome = ActivityUtil.getLocalHome();
ActivityPK pk = new ActivityPK(templateId, activityName, activityType);
activityLocalHome.remove(pk);
rt = 1;
} catch (NamingException e) {
e.printStackTrace();
} catch (EJBException e) {
e.printStackTrace();
} catch (RemoveException e) {
e.printStackTrace();
}
return rt;
}
/**
* @ejb.interface-method
* view-type="both"
**/
public int addActivityRel(ID preActId, ID sucActId)
{
int rt = 0;
try {
ActivityRelLocalHome activityRelLocalHome = ActivityRelUtil.getLocalHome();
activityRelLocalHome.create(new ActivityRelDTO(sucActId, preActId));
rt = 1;
} catch (NamingException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
}
return rt;
}
/**
* @ejb.interface-method
* view-type="both"
**/
public int delActivityRel(ID preActId, ID sucActId)
{
int rt = 0;
try {
ActivityRelLocalHome activityRelLocalHome = ActivityRelUtil.getLocalHome();
ActivityRelPK pk = new ActivityRelPK(sucActId, preActId);
activityRelLocalHome.remove(pk);
rt = 1;
} catch (NamingException e) {
e.printStackTrace();
} catch (EJBException e) {
e.printStackTrace();
} catch (RemoveException e) {
e.printStackTrace();
}
return rt;
}
/**
* @ejb.interface-method
* view-type="both"
**/
public Collection getActivitiesOfT(ID templateId)
{
try {
return this.activityDAO.getActivities(templateId);
} catch (DAOException e) {
e.printStackTrace();
return null;
}
}
/**
* @ejb.interface-method
* view-type="both"
**/
public ActivityDTO getActivity(ID activityId)
{
try {
return this.activityDAO.getActivity(activityId);
} catch (DAOException e) {
e.printStackTrace();
return null;
}
}
/**
* @ejb.interface-method
* view-type="both"
**/
public ActivityDTO getActivity(
ID templateId,
String activityName,
int activityType)
{
try {
return this.activityDAO.getActivity(templateId, activityName, activityType);
} catch (DAOException e) {
e.printStackTrace();
return null;
}
}
/**
* @ejb.interface-method
* view-type="both"
**/
public ActivityRelDTO getActivityRel(ID activityId_1, ID activityId_2)
{
try {
return this.activityRelDAO.getActivityRel(activityId_2, activityId_1);
} catch (DAOException e) {
e.printStackTrace();
return null;
}
}
/**
* @ejb.interface-method
* view-type="both"
**/
public int addAssignment(AssignmentDTO assignment)
{
ID holderId = assignment.getHolderId();
int rt = 0;
if (holderId.getType() == ID.TYPE_WfTemplate || holderId.getType() == ID.TYPE_WfActivity) {
try {
TplResourceDocLocalHome docLH = TplResourceDocUtil.getLocalHome();
TplResourceOrgLocalHome orgLH = TplResourceOrgUtil.getLocalHome();
ID templateId = null;
ID activityId = null;
if (holderId.getType() == ID.TYPE_WfTemplate) {
TemplateDTO template = this.getTemplate(holderId);
if (template == null) {
throw new EJBException("holder not found");
}
templateId = template.getTemplateId();
activityId = ActivityDTO.intToID(0);
}
else {
ActivityDTO activity = this.getActivity(holderId);
if (activity == null) {
throw new EJBException("holder not found");
}
templateId = activity.getTemplateId();
activityId = activity.getActivityId();
}
List doclist = assignment.getDocResources();
List orglist = assignment.getOrgResources();
for (int i = 0; i < doclist.size(); i++) {
TplResourceDocDTO dto = (TplResourceDocDTO)doclist.get(i);
dto.setTemplateId(templateId);
dto.setActivityId(activityId);
try{
docLH.create(dto);
rt++;
} catch (CreateException e) {
e.printStackTrace();
}
}
for (int i = 0; i < doclist.size(); i++) {
TplResourceOrgDTO dto = (TplResourceOrgDTO)doclist.get(i);
dto.setTemplateId(templateId);
dto.setActivityId(activityId);
try{
orgLH.create(dto);
rt++;
} catch (CreateException e) {
e.printStackTrace();
}
}
} catch (NamingException e) {
e.printStackTrace();
}
}
return rt;
}
/**
* @ejb.interface-method
* view-type="both"
**/
public int delAssignment(AssignmentDTO assignment)
{
ID holderId = assignment.getHolderId();
int rt = 0;
if (holderId.getType() == ID.TYPE_WfTemplate || holderId.getType() == ID.TYPE_WfActivity) {
try {
TplResourceDocLocalHome docLH = TplResourceDocUtil.getLocalHome();
TplResourceOrgLocalHome orgLH = TplResourceOrgUtil.getLocalHome();
List doclist = assignment.getDocResources();
List orglist = assignment.getOrgResources();
for (int i = 0; i < doclist.size(); i++) {
TplResourceDocDTO dto = (TplResourceDocDTO)doclist.get(i);
TplResourceDocPK pk = new TplResourceDocPK(dto.getTemplateId(), dto.getActivityId(), dto.getResId(), dto.getResType());
try{
docLH.remove(pk);
rt++;
} catch (EJBException e) {
e.printStackTrace();
} catch (RemoveException e) {
e.printStackTrace();
}
}
for (int i = 0; i < doclist.size(); i++) {
TplResourceOrgDTO dto = (TplResourceOrgDTO)doclist.get(i);
TplResourceOrgPK pk = new TplResourceOrgPK(dto.getTemplateId(), dto.getActivityId(), dto.getResId(), dto.getType());
try{
orgLH.remove(pk);
rt++;
} catch (EJBException e) {
e.printStackTrace();
} catch (RemoveException e) {
e.printStackTrace();
}
}
} catch (NamingException e) {
e.printStackTrace();
}
}
return rt;
}
/**
* @ejb.interface-method
* view-type="both"
**/
public AssignmentDTO getAssignment(ID holderId)
{
AssignmentDTO dto = new AssignmentDTO(holderId);
TplResourceOrgDAO orgdao = DAOFactory.newInstance().getTplResourceOrgDAO();
TplResourceDocDAO docdao = DAOFactory.newInstance().getTplResourceDocDAO();
try {
List doclist = null;
if (holderId.getType() == ID.TYPE_WfTemplate) {
doclist = docdao.getTplResourceDocs(holderId);
}
else if (holderId.getType() == ID.TYPE_WfActivity) {
doclist = docdao.getActResourceDocs(holderId);
}
if (doclist != null) {
for (int i = 0; i < doclist.size(); i++) {
dto.addDocResource((TplResourceDocDTO)doclist.get(i));
}
}
} catch (DAOException e) {
e.printStackTrace();
}
try {
List orglist = null;
if (holderId.getType() == ID.TYPE_WfTemplate) {
orglist = orgdao.getTplResourceOrgs(holderId);
}
else if (holderId.getType() == ID.TYPE_WfActivity) {
orglist = orgdao.getActResourceOrgs(holderId);
}
if (orglist != null) {
for (int i = 0; i < orglist.size(); i++) {
dto.addOrgResource((TplResourceOrgDTO)orglist.get(i));
}
}
} catch (DAOException e) {
e.printStackTrace();
}
orgdao.close();
docdao.close();
return dto;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -