SystemSetupAction.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;
import com.fa.sesa.i18n.Languages;
import com.mycim.framework.context.spring.SpringContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.server.security.service.SecurityService;
import com.mycim.server.system.service.SysService;
import com.mycim.valueobject.bas.NamedObject;
import com.mycim.valueobject.ems.AllowableEventSet;
import com.mycim.valueobject.ems.Event;
import com.mycim.valueobject.security.Menu;
import com.mycim.valueobject.security.Role;
import com.mycim.valueobject.security.SecurityClass;
import com.mycim.valueobject.security.TreeDetail;
import com.mycim.valueobject.sys.*;
import com.mycim.webapp.Constants;
import com.mycim.webapp.forms.RootForm;
import org.apache.commons.beanutils.PropertyUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* @author songp
*/
public abstract class SystemSetupAction extends AbstractAction {
protected SysService sysService = SpringContext.getBean(SysService.class);
protected SecurityService securityService = SpringContext.getBean(SecurityService.class);
@Override
protected NamedObject getInstance(NamedObject instance) {
NamedObject namedObject = null;
if (instance instanceof Field) {
namedObject = sysService.getField((Field) instance);
} else if (instance instanceof Facility) {
namedObject = sysService.getFacility((Facility) instance);
} else if (instance instanceof TreeDetail) {
namedObject = securityService.getTreeDetail((TreeDetail) instance);
} else if (instance instanceof Label) {
namedObject = sysService.getLabel((Label) instance);
} else if (instance instanceof Task) {
namedObject = sysService.getTask((Task) instance);
} else if (instance instanceof Message) {
namedObject = sysService.getMessage((Message) instance);
} else if (instance instanceof Role) {
namedObject = securityService.getRole((Role) instance);
} else if (instance instanceof Screen) {
namedObject = sysService.getScreen((Screen) instance);
} else if (instance instanceof ObjectAttribute) {
namedObject = sysService.getObjectAttribute((ObjectAttribute) instance);
} else if (instance instanceof ObjectAttributeField) {
namedObject = sysService.getObjectAttributeField((ObjectAttributeField) instance);
} else if (instance instanceof ObjectAttributeIndex) {
namedObject = sysService.getObjectAttributeIndexs((ObjectAttributeIndex) instance);
} else if (instance instanceof SecurityClass) {
namedObject = securityService.getSecurityClass((SecurityClass) instance);
} else if (instance instanceof Menu) {
namedObject = securityService.getMenu((Menu) instance);
} else if (instance instanceof Shift) {
namedObject = sysService.getShift((Shift) instance);
} else if (instance instanceof Event) {
namedObject = baseService.getEvent((Event) instance);
} else if (instance instanceof AllowableEventSet) {
namedObject = baseService.getAllowableEventSet((AllowableEventSet) instance);
} else {
namedObject = baseService.getNamedObject(instance);
}
// since value object retrieved from database will be null,
// if no data found. We restore the draft value object
if (namedObject != null) {
instance = namedObject;
}
return instance;
}
protected void process(NamedObject instance) {
String action = instance.getTransId();
if (action.equals(Constants.CREATE_KEY)) {
long instanceRrn = 0;
if (instance instanceof Field) {
instanceRrn = sysService.insertField((Field) instance);
} else if (instance instanceof Label) {
instanceRrn = sysService.insertLabel((Label) instance);
} else if (instance instanceof Task) {
instanceRrn = sysService.insertTask((Task) instance);
} else if (instance instanceof Message) {
instanceRrn = sysService.insertMessage((Message) instance);
} else if (instance instanceof Role) {
instanceRrn = securityService.insertRole((Role) instance);
} else if (instance instanceof Screen) {
instanceRrn = sysService.insertScreen((Screen) instance);
} else if (instance instanceof ObjectAttributeField) {
instanceRrn = sysService.insertObjectAttributeField((ObjectAttributeField) instance);
} else if (instance instanceof ObjectAttributeIndex) {
instanceRrn = sysService.insertObjectAttributeIndex((ObjectAttributeIndex) instance);
} else if (instance instanceof SecurityClass) {
instanceRrn = securityService.insertSecurityClass((SecurityClass) instance);
} else if (instance instanceof Menu) {
instanceRrn = securityService.insertMenu((Menu) instance);
} else if (instance instanceof TreeDetail) {
instanceRrn = securityService.insertTreeDetail((TreeDetail) instance);
} else if (instance instanceof Facility) {
instanceRrn = sysService.insertFacility((Facility) instance);
Facility facility = (Facility) instance;
facility.setInstanceRrn(instanceRrn);
sysService.copyNamedSpaceDef(facility.getCopyFacilityRrn(), instanceRrn);
} else if (instance instanceof Shift) {
instanceRrn = sysService.insertShift((Shift) instance);
} else if (instance instanceof Event) {
instanceRrn = baseService.insertEvent((Event) instance);
} else if (instance instanceof AllowableEventSet) {
instanceRrn = baseService.insertAllowableEventSet((AllowableEventSet) instance);
} else {
instanceRrn = baseService.insertNamedObject(instance);
}
instance.setInstanceRrn(instanceRrn);
} else if (action.equals(Constants.DELETE_KEY)) {
if (instance instanceof Field) {
sysService.deleteField((Field) instance);
} else if (instance instanceof Label) {
sysService.deleteLabel((Label) instance);
} else if (instance instanceof Task) {
sysService.deleteTask((Task) instance);
} else if (instance instanceof Message) {
sysService.deleteMessage((Message) instance);
} else if (instance instanceof Role) {
securityService.deleteRole((Role) instance);
} else if (instance instanceof Screen) {
sysService.deleteScreen((Screen) instance);
} else if (instance instanceof ObjectAttributeField) {
sysService.deleteObjectAttributeField((ObjectAttributeField) instance);
} else if (instance instanceof ObjectAttributeIndex) {
sysService.deleteObjectAttributeIndex((ObjectAttributeIndex) instance);
} else if (instance instanceof SecurityClass) {
sysService.deleteSecurityClass((SecurityClass) instance);
} else if (instance instanceof Menu) {
securityService.deleteMenu((Menu) instance);
} else if (instance instanceof TreeDetail) {
} else if (instance instanceof Facility) {
sysService.deleteFacility((Facility) instance);
} else if (instance instanceof Shift) {
sysService.deleteShift((Shift) instance);
} else if (instance instanceof Event) {
baseService.deleteEvent((Event) instance);
} else if (instance instanceof AllowableEventSet) {
baseService.deleteAllowableEventSet((AllowableEventSet) instance);
} else {
baseService.deleteNamedObject(instance);
}
} else if (action.equals(Constants.MODIFY_KEY)) {
if (instance instanceof Field) {
sysService.updateField((Field) instance);
} else if (instance instanceof Label) {
sysService.updateLabel((Label) instance);
} else if (instance instanceof Task) {
sysService.updateTask((Task) instance);
} else if (instance instanceof Message) {
sysService.updateMessage((Message) instance);
} else if (instance instanceof Role) {
securityService.updateRole((Role) instance);
} else if (instance instanceof Screen) {
sysService.updateScreen((Screen) instance);
} else if (instance instanceof ObjectAttributeField) {
sysService.updateObjectAttributeField((ObjectAttributeField) instance);
} else if (instance instanceof SecurityClass) {
securityService.updateSecurityClass((SecurityClass) instance);
} else if (instance instanceof Menu) {
securityService.updateMenu((Menu) instance);
} else if (instance instanceof TreeDetail) {
securityService.updateTreeDetail((TreeDetail) instance);
} else if (instance instanceof Facility) {
sysService.updateFacility((Facility) instance);
} else if (instance instanceof Shift) {
sysService.updateShift((Shift) instance);
} else if (instance instanceof Event) {
baseService.updateEvent((Event) instance);
} else if (instance instanceof AllowableEventSet) {
baseService.updateAllowableEventSet((AllowableEventSet) instance);
} else {
baseService.updateNamedObject(instance);
}
}
}
protected List<CheckRule> getCheckRules(Field field) {
return sysService.getCheckRules(field);
}
protected Collection getNamedSpaceDef(Facility facility) {
return sysService.getNamedSpaceDef(facility);
}
protected Collection getChilds(TreeDetail tree) {
return securityService.getTreeChilds(tree);
}
protected Collection getUserGroupsByRole(Role role) {
return securityService.getUserGroupsByRole(role);
}
protected Collection getLabelItems(Label label) {
Collection texts = new ArrayList();
texts = sysService.getLabelItems(label);
if (texts.isEmpty()) {
LabelItem labelItem = new LabelItem();
labelItem.setLanguage("EN");
texts.add(labelItem);
}
return texts;
}
protected List<Validator> getValidators(Screen screen) {
return sysService.getScreenValidators(screen);
}
protected Collection getSecurityScreens(SecurityClass securityClass) {
return securityService.getScreensBySecurityClass(securityClass);
}
protected Collection getSecurityGroups(SecurityClass securityClass) {
return securityService.getGroupsBySecurityClass(securityClass);
}
@Override
protected void doCopy(RootForm theform, NamedObject instance) throws Exception {
String origId = theform.getInstanceId();
instance = getInstance(instance);
// populate the new information thru the new instance id
PropertyUtils.copyProperties(theform, instance);
// and restore the original Id
theform.setInstanceId(origId);
}
protected Collection getObjectTransAttributeFields(ObjectTransAttribute objectTransAttribute) {
objectTransAttribute.setFieldRrn(null);
return sysService.getObjectTransAttributes(objectTransAttribute);
}
protected List<MessageDetail> getMessageDetails(Message message) {
List<MessageDetail> texts = sysService.getMessageItems(message);
if (texts.isEmpty()) {
MessageDetail messageDetail = new MessageDetail();
messageDetail.setLanguage("EN");
texts.add(messageDetail);
}
return texts;
} // end of getMessageDetails
protected List<Menu> getSubMenus(Menu menu) {
return securityService.getSubMenus(menu.getInstanceRrn());
}
protected Menu getParentMenu(Menu menu) {
return securityService.getParentMenu(menu.getInstanceRrn());
}
protected void processObjectTransAttribute(ObjectTransAttribute instance) {
String action = instance.getTransId();
if (action.equals(Constants.CREATE_KEY)) {
sysService.insertObjectTransAttribute(instance);
} else if (action.equals(Constants.DELETE_KEY)) {
sysService.deleteObjectTransAttribute(instance);
} else if (action.equals(Constants.MODIFY_KEY)) {
sysService.updateObjectTransAttribute(instance);
}
}
protected Collection getObjectAttributeValue(long instanceRrn, String namedSpace, String object, String group,
Languages language) {
if (StringUtils.isEmpty(group)) {
return sysService.getAllAttributes(instanceRrn, namedSpace, object, language);
} else {
return sysService.getAttributesByGroup(instanceRrn, namedSpace, object, language, group);
}
}
protected Collection getRolesByObjectType(String objectType) {
return securityService.getRolesByObjectType(objectType);
} // end of getRolesByObjectType
protected void processNamedSpaceDefOfFacility(Facility facility) {
String action = facility.getTransId();
if (action.equals(Constants.MODIFY_KEY)) {
sysService.updateNamedSpaceDefOfFacility(facility);
}
}
protected void maintainAttributeValue(Map value) throws Exception {
sysService.maintainAttribute(value);
}
}
/*
* Modification Log Log No : Name : Modified Date: Description :
*/