ContextValueSave.java
/*
* @ Copyright 2001 FA Software;
* All right reserved. No part of this program may be reproduced or
* transmitted in any form or by any means, electronic or
* mechanical, including photocopying, recording, or by any
* information storage or retrieval system without written
* permission from FA Software, except for inclusion of brief
* quotations in a review.
*/
package com.mycim.webapp.actions.contextvalue;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.beans.PropertyUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.prp.Context;
import com.mycim.valueobject.prp.ContextValue;
import com.mycim.valueobject.prp.Ecn;
import com.mycim.webapp.Constants;
import com.mycim.webapp.actions.CtxAction;
import com.mycim.webapp.forms.ContextInfoForm;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 配置列表定义 配置列表页
*
* @author yanbing.chen
* @date 2019/8/20
* @since 1.8
**/
public class ContextValueSave extends CtxAction {
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ContextInfoForm theform = (ContextInfoForm) form;
Context context = new Context(theform.getInstanceId(), theform.getNamedSpace(), ObjectList.CONTEXT_KEY);
context = (Context) getInstance(context);
context.setTransPerformedby(LocalContext.getUserId());
// Copy value object properties to form bean.
PropertyUtils.copyProperties(context, theform);
theform.setTransId(Constants.MODIFY_KEY);
request.setAttribute(SessionNames.CONTEXT_KEY, context);
return (mapping.findForward(Constants.VALUES_KEY));
}
@Override
public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ContextInfoForm theform = (ContextInfoForm) form;
theform.setEcnFlag(getEcnFlag());
Context context = new Context(theform.getInstanceId(), theform.getNamedSpace(), ObjectList.CONTEXT_KEY);
context = (Context) getInstance(context);
context.setTransPerformedby(LocalContext.getUserId());
// Copy value object properties to form bean.
PropertyUtils.copyProperties(theform, context);
// if user click the Cancel button
theform.setTransId(Constants.MODIFY_KEY);
request.setAttribute(SessionNames.CONTEXT_KEY, context);
return (new ActionForward(mapping.getInput()));
}
public ActionForward edit(ActionMapping mapping, ContextInfoForm theform,
HttpServletRequest request) throws Exception {
theform.setEcnFlag(getEcnFlag());
Context context = new Context(theform.getInstanceId(), theform.getNamedSpace(), ObjectList.CONTEXT_KEY);
context = (Context) getInstance(context);
context.setTransPerformedby(LocalContext.getUserId());
// Copy value object properties to form bean.
PropertyUtils.copyProperties(theform, context);
ContextValue contextValue = new ContextValue();
PropertyUtils.copyProperties(contextValue, theform);
contextValue.setContextRrn(context.getInstanceRrn());
ContextValue currentContext = ctxService.getContextValue(contextValue, LocalContext.getFacilityRrn());
if (currentContext == null) {
theform.setTransId(Constants.CREATE_KEY);
theform.setStatus(null);
} else {
if (currentContext.getEcnRrn() != null) {
Ecn ecn = new Ecn();
ecn.setInstanceRrn(currentContext.getEcnRrn());
ecn = (Ecn) this.getInstance(ecn);
theform.setEcnId(ecn.getInstanceId());
PropertyUtils.copyProperties(theform, currentContext);
theform.setTransId(Constants.MODIFY_KEY);
}
}
request.setAttribute(SessionNames.CONTEXT_KEY, context);
return (mapping.findForward(Constants.EDIT_KEY));
}
public ActionForward quary(ActionMapping mapping, ContextInfoForm theform,
HttpServletRequest request) throws Exception {
theform.setEcnFlag(getEcnFlag());
Context context = new Context(theform.getInstanceId(), theform.getNamedSpace(), ObjectList.CONTEXT_KEY);
context = (Context) getInstance(context);
context.setTransPerformedby(LocalContext.getUserId());
// Copy value object properties to form bean.
PropertyUtils.copyProperties(theform, context);
ContextValue contextValue = new ContextValue();
PropertyUtils.copyProperties(contextValue, theform);
contextValue.setContextRrn(context.getInstanceRrn());
theform.setTransId("quary");
request.setAttribute(SessionNames.CONTEXT_QUARY_CONDITION_KEY, contextValue);
context.setValues(ctxService.getContextValues(contextValue, LocalContext.getFacilityRrn()));
request.setAttribute(SessionNames.CONTEXT_KEY, context);
return (mapping.findForward("quary"));
}
public ActionForward simulate(ActionMapping mapping, ContextInfoForm theform,
HttpServletRequest request) throws Exception {
theform.setEcnFlag(getEcnFlag());
Context context = new Context(theform.getInstanceId(), theform.getNamedSpace(), ObjectList.CONTEXT_KEY);
context = (Context) getInstance(context);
context.setTransPerformedby(LocalContext.getUserId());
// Copy value object properties to form bean.
PropertyUtils.copyProperties(theform, context);
ContextValue contextValue = new ContextValue();
PropertyUtils.copyProperties(contextValue, theform);
contextValue.setContextRrn(context.getInstanceRrn());
theform.setTransId("simulate");
context.setValues(ctxService.simulateFilterContextValues(contextValue, LocalContext.getFacilityRrn()));
request.setAttribute(SessionNames.CONTEXT_KEY, context);
return (mapping.findForward("simulate"));
}
}