LabelSaveAction.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.setting.system.label;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.sys.Label;
import com.mycim.valueobject.sys.LabelItem;
import com.mycim.webapp.Constants;
import com.mycim.webapp.actions.SystemSetupAction;
import com.mycim.webapp.forms.system.LabelInfoForm;
import org.apache.commons.beanutils.PropertyUtils;
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;
import java.util.List;
/**
* 卷标定义
*
* @author yanbing.chen
* @date 2019/8/19
* @since 1.8
**/
public class LabelSaveAction extends SystemSetupAction {
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
LabelInfoForm theform = (LabelInfoForm) form;
// Populate the new valid format id
String id = "";
String formId = theform.getInstanceId();
if(StringUtils.isNotEmptyTrim(formId)){
id = theform.getInstanceId().trim().toUpperCase();
}
String flag = request.getParameter("flag");
String type = request.getParameter("type");
if(StringUtils.isNotEmptyTrim(flag)){
request.setAttribute("flag",flag);
}
if(StringUtils.isNotEmptyTrim(type)){
request.setAttribute("type",type);
}
// Construct a new value object that stores the id,
// named space(implicit, derived)
// object(hard coded)
Label label = new Label(id, getNamedSpace(ObjectList.LABEL_KEY, LocalContext.getFacilityRrn()),
ObjectList.LABEL_KEY);
label = (Label) getInstance(label);
// Copy value object properties to form bean.
PropertyUtils.copyProperties(theform, label);
request.setAttribute(SessionNames.LABEL_KEY, label);
// if a value object does not exist, its instanceRrn will be set to 0
if (label.getInstanceRrn() == 0) {
theform.setTransId(Constants.CREATE_KEY);
return mapping.findForward(Constants.MODIFY_KEY);
}
label.setLabelItems(getLabelItems(label));
theform.setTransId(Constants.MODIFY_KEY);
return (mapping.findForward(Constants.MODIFY_KEY));
}
@Override
public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
LabelInfoForm theform = (LabelInfoForm) form;
request.removeAttribute(SessionNames.LABEL_KEY);
theform.setInstanceId("");
return (mapping.findForward(Constants.SETUP_KEY));
}
public ActionForward members(ActionMapping mapping, LabelInfoForm theform,
HttpServletRequest request) throws Exception {
Label label = new Label(theform.getInstanceId(),
getNamedSpace(ObjectList.LABEL_KEY, LocalContext.getFacilityRrn()),
ObjectList.LABEL_KEY);
label = (Label) getInstance(label);
// who operate this object?
label.setTransPerformedby(LocalContext.getUserId());
// member of action, when there is a one2many function
theform.setTransId(Constants.CREATE_KEY);
if (request.getParameter(Constants.ITEM_KEY) != null) {
String language = request.getParameter(Constants.ITEM_KEY);
List<LabelItem> it = (List<LabelItem>) getLabelItems(label);
for (LabelItem item : it) {
if (item.getLanguage().equals(language)) {
theform.setLanguage(item.getLanguage());
theform.setFullLanguage(item.getFullLanguage());
theform.setText(item.getText());
theform.setFullText(item.getFullText());
theform.setExtendedDesc(item.getExtendedDesc());
}
}
label.setLabelItems(it);
request.setAttribute(SessionNames.LABEL_KEY, label);
theform.setTransId(Constants.MODIFY_KEY);
}
return mapping.findForward(Constants.MEMBERS_KEY);
}
public ActionForward create(ActionMapping mapping, LabelInfoForm theform,
HttpServletRequest request) throws Exception {
Label label = new Label(theform.getInstanceId(),
getNamedSpace(ObjectList.LABEL_KEY, LocalContext.getFacilityRrn()),
ObjectList.LABEL_KEY);
label = (Label) getInstance(label);
// who operate this object?
label.setTransPerformedby(LocalContext.getUserId());
PropertyUtils.copyProperties(label, theform);
label.setTransId(Constants.CREATE_KEY);
// no matter add or modify, they all execute the same function
process(label);
// differet from other one2many model, label has fixed items
label.setLabelItems(getLabelItems(label));
// just for logic equals tag
theform.setTransId(Constants.MODIFY_KEY);
request.setAttribute(SessionNames.LABEL_KEY, label);
return mapping.findForward(Constants.MODIFY_KEY);
}
public ActionForward modify(ActionMapping mapping, LabelInfoForm theform,
HttpServletRequest request) throws Exception {
Label label = new Label(theform.getInstanceId(),
getNamedSpace(ObjectList.LABEL_KEY, LocalContext.getFacilityRrn()),
ObjectList.LABEL_KEY);
label = (Label) getInstance(label);
// who operate this object?
label.setTransPerformedby(LocalContext.getUserId());
PropertyUtils.copyProperties(label, theform);
label.setTransId(Constants.MODIFY_KEY);
// no matter add or modify, they all execute the same function
process(label);
// differet from other one2many model, label has fixed items
label.setLabelItems(getLabelItems(label));
// just for logic equals tag
theform.setTransId(Constants.MODIFY_KEY);
request.setAttribute(SessionNames.LABEL_KEY, label);
return mapping.findForward(Constants.MODIFY_KEY);
}
public ActionForward delete(ActionMapping mapping, LabelInfoForm theform,
HttpServletRequest request) throws Exception {
Label label = new Label(theform.getInstanceId(),
getNamedSpace(ObjectList.LABEL_KEY, LocalContext.getFacilityRrn()),
ObjectList.LABEL_KEY);
label = (Label) getInstance(label);
// who operate this object?
label.setTransPerformedby(LocalContext.getUserId());
PropertyUtils.copyProperties(label, theform);
label.setTransId(Constants.DELETE_KEY);
theform.setInstanceId("");
// no matter add or modify, they all execute the same function
process(label);
// differet from other one2many model, label has fixed items
label.setLabelItems(getLabelItems(label));
// just for logic equals tag
theform.setTransId(Constants.MODIFY_KEY);
request.setAttribute(SessionNames.LABEL_KEY, label);
return mapping.findForward(Constants.SETUP_KEY);
}
public ActionForward copy(ActionMapping mapping, LabelInfoForm theform,
HttpServletRequest request) throws Exception {
Label label = new Label(theform.getInstanceId(),
getNamedSpace(ObjectList.LABEL_KEY, LocalContext.getFacilityRrn()),
ObjectList.LABEL_KEY);
label = (Label) getInstance(label);
// who operate this object?
label.setTransPerformedby(LocalContext.getUserId());
// copy function is a special function other than adding, deleting or updating
// the new Id is stored in the burl COPY key
String id = request.getParameter(Constants.COPY_KEY);
label.setInstanceId(id);
doCopy(theform, label);
// for logic equal tag, copy is the same action as create
theform.setTransId(Constants.CREATE_KEY);
return mapping.findForward(Constants.MODIFY_KEY);
}
}