ObjectAttributeValueDetail.java
package com.mycim.webapp.actions.setting.system.objectAttribute;
import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.i18n.I18nUtils;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.logging.Logger;
import com.mycim.framework.logging.LoggerFactory;
import com.mycim.framework.utils.MiscUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.bas.NamedObject;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.webapp.Constants;
import com.mycim.webapp.actions.SystemSetupAction;
import com.mycim.webapp.forms.system.ObjectAttributeInfoForm;
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;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class ObjectAttributeValueDetail extends SystemSetupAction {
private static final Logger log = LoggerFactory.getLogger(ObjectAttributeValueDetail.class);
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ObjectAttributeInfoForm theform = (ObjectAttributeInfoForm) form;
String id = StringUtils.trimToUpperCase(theform.getInstanceId());
String object = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
String namedSpace = theform.getObjectAttributeNamedSpace();
Map instance = new HashMap();
instance.put("object", object);
instance.put("id", id);
instance.put("namedSpace", namedSpace);
NamedObject namedObject = new NamedObject(id, getNamedSpace(object, LocalContext.getFacilityRrn()), object);
long instanceRrn = baseService.getNamedObjectRrn(namedObject);
Assert.isFalse(instanceRrn <= 0, Errors.create().key(MessageIdList.OBJECTATTRIBUTE_MISSING_INSTANCERRN)
.content("没有找到instanceRrn!").build());
instance.put("instanceRrn", instanceRrn);
Collection collection = this
.getObjectAttributeValue(instanceRrn, namedSpace, object, theform.getAttributeGroup(),
I18nUtils.getCurrentLanguage());
request.setAttribute("group", theform.getAttributeGroup());
Long fieldRrn = new Long(request.getParameter(Constants.ITEM_KEY));
Map value = getValueFromCollectionByFieldRrn(collection, fieldRrn);
if (MapUtils.isNotEmpty(value)) {
theform.setModifiableFlag(MiscUtils.unparseCheckBox(MapUtils.getString(value, "MODIFIABLEFLAG")));
theform.setSystemUse(MiscUtils.unparseCheckBox(MapUtils.getString(value, "SYSTEMUSE")));
theform.setAttributeGroup(MapUtils.getString(value, "ATTRIBUTEGROUP"));
theform.setAttributeValue(MapUtils.getString(value, "ATTRIBUTEVALUE"));
theform.setNamedSpace(MapUtils.getString(value, "NAMEDSPACE"));
}
log.info("group = " + theform.getAttributeGroup());
String fieldId = getInstanceId(fieldRrn.longValue());
theform.setFieldId(fieldId);
request.setAttribute(SessionNames.ITEM_KEY, value);
return mapping.findForward(Constants.MEMBERS_KEY);
}
@Override
public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ObjectAttributeInfoForm theform = (ObjectAttributeInfoForm) form;
String id = StringUtils.trimToUpperCase(theform.getInstanceId());
String object = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
String namedSpace = theform.getObjectAttributeNamedSpace();
Map instance = new HashMap();
instance.put("object", object);
instance.put("id", id);
instance.put("namedSpace", namedSpace);
NamedObject namedObject = new NamedObject(id, getNamedSpace(object, LocalContext.getFacilityRrn()), object);
long instanceRrn = baseService.getNamedObjectRrn(namedObject);
Assert.isFalse(instanceRrn <= 0, Errors.create().key(MessageIdList.OBJECTATTRIBUTE_MISSING_INSTANCERRN)
.content("没有找到instanceRrn!").build());
instance.put("instanceRrn", instanceRrn);
Collection collection = this.getObjectAttributeValue(((Long) instance.get("instanceRrn")).longValue(),
(String) instance.get("namedSpace"),
(String) instance.get("object"),
theform.getAttributeGroup(),
I18nUtils.getCurrentLanguage());
long fieldRrn = getInstanceRrn(theform.getFieldId(),
getNamedSpace(ObjectList.FIELD_KEY, LocalContext.getFacilityRrn()),
ObjectList.FIELD_KEY);
Assert.isFalse(fieldRrn <= 0,
Errors.create().key(MessageIdList.FIELD_MISSING_FIELD).content("没有找到这个字段!").build());
Map value = getValueFromCollectionByFieldRrn(collection, fieldRrn);
value.put("instanceRrn", "" + instance.get("instanceRrn"));
value.put("instanceVersion", "1");
request.setAttribute(SessionNames.COLLECTION_KEY, collection);
request.setAttribute(SessionNames.OBJECT_KEY, instance);
return mapping.findForward(Constants.MODIFY_KEY);
}
public ActionForward modify(ActionMapping mapping, ObjectAttributeInfoForm theform,
HttpServletRequest request) throws Exception {
String id = StringUtils.trimToUpperCase(theform.getInstanceId());
String object = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
String namedSpace = theform.getObjectAttributeNamedSpace();
Map instance = new HashMap();
instance.put("object", object);
instance.put("id", id);
instance.put("namedSpace", namedSpace);
NamedObject namedObject = new NamedObject(id, getNamedSpace(object, LocalContext.getFacilityRrn()), object);
long instanceRrn = baseService.getNamedObjectRrn(namedObject);
Assert.isFalse(instanceRrn <= 0, Errors.create().key(MessageIdList.OBJECTATTRIBUTE_MISSING_INSTANCERRN)
.content("没有找到instanceRrn!").build());
instance.put("instanceRrn", instanceRrn);
Collection collection = this.getObjectAttributeValue(((Long) instance.get("instanceRrn")).longValue(),
(String) instance.get("namedSpace"),
(String) instance.get("object"),
theform.getAttributeGroup(),
I18nUtils.getCurrentLanguage());
long fieldRrn = getInstanceRrn(theform.getFieldId(),
getNamedSpace(ObjectList.FIELD_KEY, LocalContext.getFacilityRrn()),
ObjectList.FIELD_KEY);
Assert.isFalse(fieldRrn <= 0,
Errors.create().key(MessageIdList.FIELD_MISSING_FIELD).content("没有找到这个字段!").build());
Map value = getValueFromCollectionByFieldRrn(collection, fieldRrn);
value.put("instanceRrn", "" + instance.get("instanceRrn"));
value.put("instanceVersion", "1");
log.info("request.getParameter------------------------------------------------>" +
request.getParameter("savedAsRrn"));
if (request.getParameter(Constants.MODIFY_KEY) != null) {
if (!"on".equalsIgnoreCase(request.getParameter("savedAsRrn"))) {
value.put("attributeValue", theform.getAttributeValue());
} else {
long rrn = this.getInstanceRrn(theform.getAttributeValue(), this.getNamedSpace(theform.getValuetype(),
LocalContext
.getFacilityRrn()),
theform.getValuetype());
Assert.isTrue(rrn > 0, Errors.create().content(theform.getValuetype()).build());
value.put("attributeValue", "" + rrn);
}
this.maintainAttributeValue(value);
}
collection = this.getObjectAttributeValue(((Long) instance.get("instanceRrn")).longValue(),
(String) instance.get("namedSpace"), (String) instance.get("object"),
theform.getAttributeGroup(), I18nUtils.getCurrentLanguage());
request.setAttribute(SessionNames.COLLECTION_KEY, collection);
request.setAttribute(SessionNames.OBJECT_KEY, instance);
return mapping.findForward(Constants.MODIFY_KEY);
}
public ActionForward delete(ActionMapping mapping, ObjectAttributeInfoForm theform,
HttpServletRequest request) throws Exception {
String id = StringUtils.trimToUpperCase(theform.getInstanceId());
String object = StringUtils.trimToUpperCase(theform.getObjectAttributeObject());
String namedSpace = theform.getObjectAttributeNamedSpace();
Map instance = new HashMap();
instance.put("object", object);
instance.put("id", id);
instance.put("namedSpace", namedSpace);
NamedObject namedObject = new NamedObject(id, getNamedSpace(object, LocalContext.getFacilityRrn()), object);
long instanceRrn = baseService.getNamedObjectRrn(namedObject);
Assert.isFalse(instanceRrn <= 0, Errors.create().key(MessageIdList.OBJECTATTRIBUTE_MISSING_INSTANCERRN)
.content("没有找到instanceRrn!").build());
instance.put("instanceRrn", instanceRrn);
Collection collection = this.getObjectAttributeValue(((Long) instance.get("instanceRrn")).longValue(),
(String) instance.get("namedSpace"),
(String) instance.get("object"),
theform.getAttributeGroup(),
I18nUtils.getCurrentLanguage());
long fieldRrn = getInstanceRrn(theform.getFieldId(),
getNamedSpace(ObjectList.FIELD_KEY, LocalContext.getFacilityRrn()),
ObjectList.FIELD_KEY);
Assert.isFalse(fieldRrn <= 0,
Errors.create().key(MessageIdList.FIELD_MISSING_FIELD).content("没有找到这个字段!").build());
Map value = getValueFromCollectionByFieldRrn(collection, fieldRrn);
value.put("instanceRrn", "" + instance.get("instanceRrn"));
value.put("instanceVersion", "1");
log.info("request.getParameter------------------------------------------------>" +
request.getParameter("savedAsRrn"));
value.put("attributeValue", "");
this.maintainAttributeValue(value);
collection = this.getObjectAttributeValue(((Long) instance.get("instanceRrn")).longValue(),
(String) instance.get("namedSpace"), (String) instance.get("object"),
theform.getAttributeGroup(), I18nUtils.getCurrentLanguage());
request.setAttribute(SessionNames.COLLECTION_KEY, collection);
request.setAttribute(SessionNames.OBJECT_KEY, instance);
return mapping.findForward(Constants.MODIFY_KEY);
}
private Map getValueFromCollectionByFieldRrn(Collection collection, Long fieldRrn) {
Iterator it = collection.iterator();
while (it.hasNext()) {
Map item = (Map) it.next();
Long rrn = MapUtils.getLong(item, "FIELD_RRN");
if (rrn.equals(fieldRrn)) {
return item;
}
}
return null;
}
}