ObjectAttributeSaveAction.java
package com.mycim.webapp.actions.setting.system.objectAttribute;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.MiscUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.sys.ObjectAttribute;
import com.mycim.valueobject.sys.ObjectAttributeField;
import com.mycim.valueobject.sys.ObjectAttributeIndex;
import com.mycim.webapp.Constants;
import com.mycim.webapp.actions.SystemSetupAction;
import com.mycim.webapp.forms.system.ObjectAttributeInfoForm;
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.Collection;
/**
* 对象属性定义
*
* @author yanbing.chen
* @date 2019/8/19
* @since 1.8
**/
public class ObjectAttributeSaveAction extends SystemSetupAction {
private static final String IS_TRUE = "Y";
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ObjectAttributeInfoForm theform = (ObjectAttributeInfoForm) form;
String id = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
String flag = "N";
if (theform.getVersionFlag() != null) {
if (theform.getVersionFlag().equalsIgnoreCase(IS_TRUE)) {
theform.setVersionFlagLable("For Version");
flag = "Y";
} else {
theform.setVersionFlagLable("For Object");
}
} else {
theform.setVersionFlag("Y");
theform.setVersionFlagLable("For Object");
}
ObjectAttribute objectAttribute = new ObjectAttribute(id, getNamedSpace(id, LocalContext.getFacilityRrn()));
objectAttribute.setVersionFlag(flag);
// According to the instance of object, retrieve the value object
objectAttribute = (ObjectAttribute) getInstance(objectAttribute);
// set new Value into form Bean
PropertyUtils.copyProperties(theform, objectAttribute);
request.setAttribute(SessionNames.OBJECTATTRIBUTE_KEY, objectAttribute);
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 {
ObjectAttributeInfoForm theform = (ObjectAttributeInfoForm) form;
String id = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
String versionId = StringUtils.trimToUpperCase(theform.getVersionFlag());
// if user click the Cancel button
if (mapping.getAttribute() != null) {
request.removeAttribute(mapping.getAttribute());
}
request.removeAttribute(SessionNames.OBJECTATTRIBUTE_KEY);
return mapping.findForward(Constants.CREATE_KEY);
}
public ActionForward modify(ActionMapping mapping, ObjectAttributeInfoForm theform,
HttpServletRequest request) throws Exception {
String id = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
String versionId = StringUtils.trimToUpperCase(theform.getVersionFlag());
ObjectAttributeField objectAttributeField = new ObjectAttributeField(id, getNamedSpace(id, LocalContext
.getFacilityRrn()), versionId);
if (request.getParameter(Constants.ITEM_KEY) != null) {
Long fieldRrn = new Long(request.getParameter(Constants.ITEM_KEY));
objectAttributeField.setFieldRrn(fieldRrn);
objectAttributeField = (ObjectAttributeField) getInstance(objectAttributeField);
PropertyUtils.copyProperties(theform, objectAttributeField);
theform.setModifiableFlag(MiscUtils.unparseCheckBox(objectAttributeField.getModifiableFlag()));
theform.setSystemUse(MiscUtils.unparseCheckBox(objectAttributeField.getSystemUse()));
theform.setAttributeGroup(objectAttributeField.getAttributeGroup());
String fieldId = getInstanceId(Long.parseLong(request.getParameter(Constants.ITEM_KEY)));
theform.setFieldId(fieldId);
request.setAttribute(SessionNames.OBJECTATTRIBUTEFIELD_KEY, objectAttributeField);
theform.setTransId(Constants.MODIFY_KEY);
return mapping.findForward(Constants.MEMBERS_KEY);
} else {
theform.setTransId(Constants.CREATE_KEY);
request.setAttribute(SessionNames.OBJECTATTRIBUTEFIELD_KEY, objectAttributeField);
return mapping.findForward(Constants.MEMBERS_KEY);
}
}
public ActionForward delete(ActionMapping mapping, ObjectAttributeInfoForm theform,
HttpServletRequest request) throws Exception {
String id = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
String versionId = StringUtils.trimToUpperCase(theform.getVersionFlag());
ObjectAttributeField objectAttributeField = new ObjectAttributeField(id, getNamedSpace(id, LocalContext
.getFacilityRrn()), versionId);
if (request.getParameter(Constants.ITEM_KEY) != null) {
Long fieldRrn = new Long(request.getParameter(Constants.ITEM_KEY));
objectAttributeField.setFieldRrn(fieldRrn);
objectAttributeField = (ObjectAttributeField) getInstance(objectAttributeField);
PropertyUtils.copyProperties(theform, objectAttributeField);
theform.setModifiableFlag(MiscUtils.unparseCheckBox(objectAttributeField.getModifiableFlag()));
theform.setSystemUse(MiscUtils.unparseCheckBox(objectAttributeField.getSystemUse()));
theform.setAttributeGroup(objectAttributeField.getAttributeGroup());
objectAttributeField.setTransId(Constants.DELETE_KEY);
process(objectAttributeField);
ObjectAttribute objectAttribute = new ObjectAttribute(theform.getObjectAttributeObject(),
getNamedSpace(id, LocalContext.getFacilityRrn()));
objectAttribute.setVersionFlag(theform.getVersionFlag());
// According to the instance of object, retrieve the value object
objectAttribute = (ObjectAttribute) getInstance(objectAttribute);
request.setAttribute(SessionNames.OBJECTATTRIBUTE_KEY, objectAttribute);
}
return mapping.findForward(Constants.MODIFY_KEY);
}
public ActionForward attribute(ActionMapping mapping, ObjectAttributeInfoForm theform,
HttpServletRequest request) throws Exception {
String id = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
ObjectAttributeIndex objectAttributeIndex = new ObjectAttributeIndex(id, getNamedSpace(id, LocalContext
.getFacilityRrn()));
objectAttributeIndex = (ObjectAttributeIndex) getInstance(objectAttributeIndex);
ObjectAttribute objectAttribute = (ObjectAttribute) request.getAttribute(SessionNames.OBJECTATTRIBUTE_KEY);
Collection attibuteFields = objectAttribute.getObjectAttributeFields();
request.setAttribute(SessionNames.OBJECTATTRIBUTEFIELDS_KEY, attibuteFields);
request.setAttribute(SessionNames.OBJECTATTRIBUTEINDEX_KEY, objectAttributeIndex);
return mapping.findForward("attribute");
}
}