LabelDetailSaveAction.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.beans.PropertyUtils;
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.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 LabelDetailSaveAction extends SystemSetupAction {
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
LabelInfoForm theform = (LabelInfoForm) form;
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
List<LabelItem> it = (List<LabelItem>) getLabelItems(label);
label.setLabelItems(it);
request.setAttribute(SessionNames.LABEL_KEY, label);
theform.setTransId(Constants.MODIFY_KEY);
return mapping.findForward("members");
}
@Override
public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
LabelInfoForm theform = (LabelInfoForm) form;
Label label = new Label(theform.getInstanceId(),
getNamedSpace(ObjectList.LABEL_KEY, LocalContext.getFacilityRrn()),
ObjectList.LABEL_KEY);
label = (Label) getInstance(label);
theform.setTransId(Constants.MODIFY_KEY);
label.setLabelItems(getLabelItems(label));
request.setAttribute(SessionNames.LABEL_KEY, label);
return (new ActionForward(mapping.getInput()));
}
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);
// constructs the relation object that stores from field to check rules
LabelItem labelItem = new LabelItem();
// populate the new information thru the new instance id
PropertyUtils.copyProperties(labelItem, theform);
// only modify permitted
processDetails(label.getInstanceRrn(), labelItem);
label.setLabelItems(getLabelItems(label));
// no matter user click whatever button: cancel, modify
// just return the input page
theform.setTransId(Constants.MODIFY_KEY);
request.setAttribute(SessionNames.LABEL_KEY, label);
return (new ActionForward(mapping.getInput()));
}
private void processDetails(long labelRrn, LabelItem labelItem) throws Exception {
sysService.updateLabelItem(labelRrn, labelItem);
}
}