Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.it.metasonic.ruspost.infopoint.actions;
- import java.lang.reflect.Field;
- import java.lang.reflect.ParameterizedType;
- import java.lang.reflect.Type;
- import java.rmi.RemoteException;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Set;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import ru.it.metasonic.ruspost.infopoint.utils.BOHelper;
- import ru.it.metasonic.ruspost.infopoint.utils.RusPostException;
- import ru.it.metasonic.ruspost.infopoint.utils.StorageAPI;
- import ru.it.metasonic.ruspost.infopoint.utils.StorageNames;
- import com.jcom1.api.constants.Constants;
- import com.jcom1.api.dto.interfaces.IGroupBean;
- import com.jcom1.api.dto.interfaces.IStorageInstanceBean;
- import com.jcom1.api.dto.interfaces.ISubjectInstanceBean;
- import com.jcom1.api.dto.interfaces.storages.IStorageInstanceItemBeanReducedToId;
- import com.jcom1.api.exceptions.InternalEngineException;
- import com.jcom1.api.exceptions.SubjectInstanceNotAvailableException;
- import com.jcom1.api.interfaces.IAuthorizationAdministrationApi;
- import com.jcom1.api.interfaces.IAuthorizationApi;
- import com.jcom1.api.interfaces.IBo20AccessApi;
- import com.jcom1.api.interfaces.ICommonApi;
- import com.jcom1.api.util.IViewStorageInstanceItemPair;
- import com.jcom1.api.util.interfaces.IIdNamePair;
- import de.metasonic.businessobjects.exceptions.ServerRuleExecutionException;
- import de.metasonic.businessobjects.model.context.ContextInformation;
- import de.metasonic.businessobjects.model.interfaces.IView;
- import de.metasonic.businessobjects.model.rules.AbstractServerAction;
- /**
- * Just implement your action methods here.
- */
- public class OperationPlanActions extends AbstractServerAction {
- @Autowired
- IBo20AccessApi boApi;
- @Autowired
- ICommonApi commonApi;
- @Autowired
- IBo20AccessApi accessApi;
- @Autowired
- IAuthorizationApi authApi;
- @Autowired
- IAuthorizationAdministrationApi administrationApi;
- private final static String REGION_GROUP = "region";
- private final static String REGION_CODE = "regionCode";
- private final static String GROUP_TYPE = "type";
- private final static String PARENT_ID = "parentId";
- private final static String CNT = "cnt";
- private final static Log log = LogFactory
- .getLog(OperationPlanActions.class);
- public void updateInnerPostamt() throws RusPostException, ServerRuleExecutionException {
- log.error(">>> updateInnerPostamt begin");
- IView iView = getBean();
- try {
- Object postamt = BOHelper.getAttribute(iView, "postamt");
- if (null == postamt) {
- log.error("bad postamt");
- }
- String postamtIndex = (String)BOHelper.getAttribute(postamt, "postamtPostamtIndex");
- String postamtName = (String)BOHelper.getAttribute(postamt, "postamtPostamtName");
- log.error("retrieved index/name:" + postamtIndex + " " + postamtName);
- Object operationList = BOHelper.getAttribute(iView, "operationList");
- if (null == operationList) {
- log.error("bad operationList");
- }
- IView innerMeta = (IView)BOHelper.getAttribute(operationList, "metaData");
- if (null == innerMeta) {
- Class<?> metaDataClass = BOHelper.getType(operationList, "metaData");
- log.error(metaDataClass);
- innerMeta = (IView) (metaDataClass.newInstance());
- log.error("err2");
- BOHelper.setAttribute(operationList, "metaData", innerMeta);
- log.error("meta retrieved and set");
- }
- if (null == innerMeta) {
- log.error("still bad");
- }
- /*
- IView selectedPostamt = (IView)BOHelper.getAttribute(iView, "metaData");
- if (null == selectedPostamt) {
- Class<?> metaDataClass = BOHelper.getType(iView, "metaData");
- selectedPostamt = (IView) (metaDataClass.newInstance());
- BOHelper.setAttribute(iView, "metaData", selectedPostamt);
- }
- if (null != postamtIndex && null != postamtName && null!= selectedPostamt) {
- BOHelper.setAttribute(selectedPostamt, "selectedPostamtIndex", postamtIndex);
- BOHelper.setAttribute(selectedPostamt, "selectedPostamtName", postamtName);
- log.error("meta data values set");
- }*/
- } catch (ServerRuleExecutionException ex) {
- throw ex;
- } catch (RusPostException ex) {
- throw ex;
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.error("<<< updateInnerPostamt end");
- }
- public void copyPostamtFromParent() throws RusPostException, ServerRuleExecutionException, SubjectInstanceNotAvailableException, RemoteException, InternalEngineException {
- log.error(">>> copyPostamtFromParent begin");
- IView operationList = getBean();
- ContextInformation context = getContextInformation();
- Long id = context.getSubjectInstanceId();
- ISubjectInstanceBean subjInstBean = commonApi.getSubjectInstanceBean(id.toString());
- try {
- StorageAPI storageAPI = new StorageAPI(boApi);
- Set<IStorageInstanceBean> storages = storageAPI.getStorages(subjInstBean);
- //prepare storage infrastructure for План мероприятий
- IStorageInstanceBean planStorage = storageAPI.findStorageByName(storages, StorageNames.OPERATION_PLAN_FOLDER);
- Set<IStorageInstanceItemBeanReducedToId> planStorageItems = boApi
- .getItems(subjInstBean, planStorage);
- int i = 0;
- while (planStorageItems.iterator().hasNext()) {
- IStorageInstanceItemBeanReducedToId tmpInst = planStorageItems.iterator().next();
- log.error("storage_items[" + i + "]:");
- log.error(tmpInst.toString());
- IViewStorageInstanceItemPair storageInstanceItem = boApi
- .getIViewAndItem(
- subjInstBean,
- tmpInst,
- Constants.Storage.BusinessObject20.Action.UPDATE);
- log.error(storageInstanceItem.toString());
- //IView operationPlanView = storageInstanceItem.getiView();
- }
- /*if (planStorageItems.iterator().hasNext()) {
- Object postamt = (Object) (BOHelper.getAttribute(operationPlanView,"postamt"));
- String postamtIndex = (String)(BOHelper.getAttribute(postamt, "postamtPostamtIndex"));
- String postamtName = (String)(BOHelper.getAttribute(postamt, "postamtPostamtName"));
- BOHelper.setAttribute(operationList, "postamtIndex", postamtIndex);
- BOHelper.setAttribute(operationList, "postamtName", postamtName);
- }*/
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.error("<<< copyPostamtFromParent end");
- }
- public void setPostamtIntoSearchMask() throws RusPostException, ServerRuleExecutionException, SubjectInstanceNotAvailableException, RemoteException, InternalEngineException {
- log.error(">>> setPostamtIntoSearchMask begin");
- IView postOfficeCard = getBean();
- ContextInformation context = getContextInformation();
- Long id = context.getSubjectInstanceId();
- ISubjectInstanceBean subjInstBean = commonApi.getSubjectInstanceBean(id.toString());
- try {
- StorageAPI storageAPI = new StorageAPI(boApi);
- Set<IStorageInstanceBean> storages = storageAPI.getStorages(subjInstBean);
- //prepare storage infrastructure for План мероприятий
- IStorageInstanceBean planStorage = storageAPI.findStorageByName(storages, StorageNames.OPERATION_PLAN_FOLDER);
- Set<IStorageInstanceItemBeanReducedToId> planStorageItems = boApi
- .getItems(subjInstBean, planStorage);
- if (planStorageItems.iterator().hasNext()) {
- IStorageInstanceItemBeanReducedToId tmpInst = planStorageItems.iterator().next();
- IViewStorageInstanceItemPair storageInstanceItem = boApi
- .getIViewAndItem(
- subjInstBean,
- tmpInst,
- Constants.Storage.BusinessObject20.Action.UPDATE);
- IView operationPlanView = storageInstanceItem.getiView();
- Object postamt = (Object) (BOHelper.getAttribute(operationPlanView,"postamt"));
- String postamtIndex = (String)(BOHelper.getAttribute(postamt, "postamtPostamtIndex"));
- String postamtName = (String)(BOHelper.getAttribute(postamt, "postamtPostamtName"));
- BOHelper.setAttribute(postOfficeCard, "postamtIndex", postamtIndex);
- BOHelper.setAttribute(postOfficeCard, "postamtName", postamtName);
- /*Object operationList = (Object) (BOHelper.getAttribute(operationPlanView, "operationList"));
- if (null == operationList) {
- log.error("bad list");
- }*/
- /* Collection<Object> collection;
- try {
- collection = (Collection<Object>) (BOHelper.getAttribute(operationPlanView, "operationList"));
- if(collection == null){
- collection = new ArrayList<Object>();
- BOHelper.setAttribute(operationPlanView, "operationList", collection);
- }
- //create new OperationOPSResult
- Field officeListField = BOHelper.getField(operationCardView, "officeList");
- Type generic = officeListField.getGenericType();
- final ParameterizedType ptype = (ParameterizedType) generic;
- final Class<?> genericType = (Class<?>) ptype
- .getActualTypeArguments()[0];
- log.debug("genericType: " + genericType);
- IView operationOPSResultImpl = (IView) (genericType.newInstance());
- BOHelper.setAttribute(operationOPSResultImpl, "indexOPS", opsIndex);
- //add to collection
- collection.add(operationOPSResultImpl);*/
- }
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.error("<<< setPostamtIntoSearchMask end");
- }
- public void updateOuterUfps() throws RusPostException, ServerRuleExecutionException {
- log.debug("updateOuterUfps begin");
- IView iView = getBean();
- try {
- IView metaData = (IView)BOHelper.getAttribute(iView, "metaData");
- if (null == metaData) {
- //explicitly get inline BO because it can be not initialized yet
- Class<?> metaDataClass = BOHelper.getType(iView, "metaData");
- metaData = (IView) (metaDataClass.newInstance());
- BOHelper.setAttribute(iView, "metaData", metaData);
- }
- ContextInformation context = getContextInformation();
- String userId = context.getEditorId();
- if (null == userId || userId.isEmpty()) {
- userId = context.getAgentId();
- }
- String ufpsIndex = "dummy id";
- String ufpsName = "dummy name";
- ufpsIndex = getRegionGroupId(userId);
- ufpsName = getRegionGroupName(userId);
- log.debug("current user ufpsGroupId/Name: " + ufpsIndex + " " + ufpsName);
- BOHelper.setAttribute(metaData, "regionGroupIndex", ufpsIndex);
- BOHelper.setAttribute(metaData, "regionGroupName", ufpsName);
- } catch (ServerRuleExecutionException ex) {
- throw ex;
- } catch (RusPostException ex) {
- throw ex;
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.debug("updateOuterUfps end");
- }
- public void updateOuterPostamt() throws RusPostException, ServerRuleExecutionException {
- log.debug("updateOuterPostamt begin");
- IView iView = getBean();
- try {
- Object postamt = BOHelper.getAttribute(iView, "postamt");
- if (null == postamt) {
- log.debug("bad postamt");
- }
- String postamtIndex = (String)BOHelper.getAttribute(postamt, "postamtPostamtIndex");
- String postamtName = (String)BOHelper.getAttribute(postamt, "postamtPostamtName");
- log.debug("index/name:" + postamtIndex + " " + postamtName);
- IView selectedPostamt = (IView)BOHelper.getAttribute(iView, "metaData");
- if (null == selectedPostamt) {
- Class<?> metaDataClass = BOHelper.getType(iView, "metaData");
- selectedPostamt = (IView) (metaDataClass.newInstance());
- BOHelper.setAttribute(iView, "metaData", selectedPostamt);
- }
- if (null != postamtIndex && null != postamtName && null!= selectedPostamt) {
- BOHelper.setAttribute(selectedPostamt, "postamtIndex", postamtIndex);
- BOHelper.setAttribute(selectedPostamt, "postamtName", postamtName);
- log.debug("meta data values set");
- }
- } catch (ServerRuleExecutionException ex) {
- throw ex;
- } catch (RusPostException ex) {
- throw ex;
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.debug("updateOuterPostamt end");
- }
- private String getRegionGroupId(String userId) throws RusPostException {
- try {
- IGroupBean[] groupsOfUser = administrationApi
- .getGroupsOfUser(userId);
- if (groupsOfUser == null)
- return null;
- String groupType = null;
- // searching for postamt group that contains parent id of ufps group
- for (IGroupBean iGroupBean : groupsOfUser) {
- IIdNamePair[] attributes = iGroupBean.getAttributes();
- if (attributes == null)
- continue;
- groupType = getAttributeByKey(attributes, GROUP_TYPE);
- if (groupType == null)
- continue;
- if (groupType.equals(REGION_GROUP)) {
- return iGroupBean.getId();
- }
- }
- log.debug("region group with parent id attribute wasn't found for user with id : "
- + userId);
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- return null;
- }
- /**
- * Get name of a region group that current user belongs to
- * @param userId
- * @return ufps id or null if there are no groups with attributes type=Region and ParentId=N
- * @throws RusPostException
- */
- private String getRegionGroupName(String userId) throws RusPostException {
- try {
- IGroupBean[] groupsOfUser = administrationApi
- .getGroupsOfUser(userId);
- if (groupsOfUser == null)
- return null;
- String groupType = null;
- // searching for postamt group that contains parent id of ufps group
- for (IGroupBean iGroupBean : groupsOfUser) {
- IIdNamePair[] attributes = iGroupBean.getAttributes();
- if (attributes == null)
- continue;
- groupType = getAttributeByKey(attributes, GROUP_TYPE);
- if (groupType == null)
- continue;
- if (groupType.equals(REGION_GROUP)) {
- return iGroupBean.getName();
- }
- }
- log.debug("region group with parent id attribute wasn't found for user with id : "
- + userId);
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- return null;
- }
- private static String getAttributeByKey(IIdNamePair[] attributes, String key) {
- for (IIdNamePair attribute : attributes) {
- if (attribute.getId().equals(key)) {
- return attribute.getName();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment