Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.it.metasonic.ruspost.infopoint.actions;
- 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.AttributeHelper;
- import ru.it.metasonic.ruspost.infopoint.utils.BOHelper;
- import ru.it.metasonic.ruspost.infopoint.utils.RusPostException;
- import com.jcom1.api.dto.interfaces.ISubjectInstanceBean;
- 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 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
- ICommonApi commonApi;
- @Autowired
- IBo20AccessApi accessApi;
- @Autowired
- IAuthorizationApi authApi;
- @Autowired
- private IAuthorizationAdministrationApi administrationApi;
- private final static Log log = LogFactory.getLog(OperationPlanActions.class);
- /*public void myServerAction() throws ServerRuleExecutionException {
- log.error("myServerAction begin");
- IView iView = getBean();
- try {
- } catch (ServerRuleExecutionException ex) {
- throw ex;
- } catch (RusPostException ex) {
- throw ex;
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.error("myServerAction end");
- }*/
- public void setPlanNumber() throws ServerRuleExecutionException, RusPostException {
- log.debug("setPlanNumber begin");
- IView iView = getBean();
- ContextInformation context = getContextInformation();
- try {
- Object commonInfo = BOHelper.getAttribute(iView, "commonInfo");
- if (null == commonInfo) {
- commonInfo = BOHelper.getType(iView, "commonInfo").newInstance();
- BOHelper.setAttribute(iView, "commonInfo", commonInfo);
- }
- String userId = context.getEditorId();
- if (null == userId || userId.isEmpty()) {
- userId = context.getAgentId();
- }
- if (null == userId) {
- log.debug("There is no editor-user id. Retrieving potentialOwner as user-editor");
- ISubjectInstanceBean subjectInstanceBean = commonApi.getSubjectInstanceBean(
- String.valueOf(context.getSubjectInstanceId()));
- if (0 != subjectInstanceBean.getPotentialOwners().length) {
- userId = subjectInstanceBean.getPotentialOwners()[0];
- log.error("userId:" + userId);
- } else {
- log.error("no potential owners were found");
- }
- }
- String planNumber = new AttributeHelper(administrationApi).generateNumber(userId, this);
- if (null != planNumber) {
- BOHelper.setAttribute(commonInfo, "planNumber", planNumber);
- } else {
- log.error("failed to compose planNumber");
- }
- } catch (ServerRuleExecutionException ex) {
- throw ex;
- } catch (RusPostException ex) {
- throw ex;
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.debug("setPlanNumber end");
- }
- public void updateProcessTitle() throws ServerRuleExecutionException, RusPostException {
- log.debug("updateProcessTitle begin");
- IView iView = getBean();
- try {
- Object commonInfo = BOHelper.getAttribute(iView, "commonInfo");
- if (null == commonInfo) {
- commonInfo = BOHelper.getType(iView, "commonInfo").newInstance();
- BOHelper.setAttribute(iView, "commonInfo", commonInfo);
- }
- String planNumber = (String) BOHelper.getAttribute(commonInfo, "planNumber");
- if (null != planNumber) {
- commonApi.setProcessInstanceTitle(
- (int)getContextInformation().getProcessInstanceId(), planNumber);
- } else {
- log.error("failed to update process title (no planNumber)");
- }
- } catch (ServerRuleExecutionException ex) {
- throw ex;
- } catch (RusPostException ex) {
- throw ex;
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.debug("updateProcessTitle end");
- }
- public void updateOuterUfps() throws RusPostException, ServerRuleExecutionException {
- log.error("updateOuterUfps begin");
- IView iView = getBean();
- ContextInformation context = getContextInformation();
- 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");
- log.debug("mdataType: " + metaDataClass);
- metaData = (IView) (metaDataClass.newInstance());
- BOHelper.setAttribute(iView, "metaData", metaData);
- }
- String userId = context.getEditorId();
- if (null == userId || userId.isEmpty()) {
- userId = context.getAgentId();
- }
- if (null == userId) {
- log.debug("There is no editor-user id. Retrieving potentialOwner as user-editor");
- ISubjectInstanceBean subjectInstanceBean = commonApi.getSubjectInstanceBean(
- String.valueOf(context.getSubjectInstanceId()));
- if (0 != subjectInstanceBean.getPotentialOwners().length) {
- userId = subjectInstanceBean.getPotentialOwners()[0];
- log.error("userId:" + userId);
- } else {
- log.error("no potential owners were found");
- }
- }
- String ufpsIndex = "dummy id";
- String ufpsName = "dummy name";
- AttributeHelper ah = new AttributeHelper(administrationApi);
- ufpsIndex = ah.getRegionGroupId(userId);
- ufpsName = ah.getRegionGroupName(userId);
- log.debug("current user's regionGroupId/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.error("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");
- }
- public void finilizeOperationPlan() throws RusPostException {
- log.debug("begin finilizeOperationPlan ");
- IView iView = getBean();
- try {
- ContextInformation context = getContextInformation();
- Object postamt = BOHelper.getAttribute(iView, "postamt");
- String postamtName =(String) BOHelper.getAttribute(postamt, "postamtPostamtName");
- String postamtIndex =(String) BOHelper.getAttribute(postamt, "postamtPostamtIndex");
- //set postamt data
- Object planCommonInfo = (Object) (BOHelper.getAttribute(
- iView, "commonInfo"));
- BOHelper.setAttribute(planCommonInfo, "postamtIndex", postamtIndex);
- BOHelper.setAttribute(planCommonInfo, "postamtName", postamtName);
- } catch (Throwable th) {
- throw new RusPostException(th);
- }
- log.debug("end finilizeOperationPlan");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment