⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 activitiesservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                input.put("actualCompletionDate", communicationEvent.getTimestamp("datetimeEnded"));                input.put("workEffortName", communicationEvent.getString("subject"));                input.put("workEffortPurposeTypeId", "WEPT_TASK_EMAIL");                serviceResults = dispatcher.runSync("createWorkEffort", input);                if (ServiceUtil.isError(serviceResults)) {                    Debug.logError(ServiceUtil.getErrorMessage(serviceResults), module);                    throw new GenericServiceException(ServiceUtil.getErrorMessage(serviceResults));                }                                //get the work effort ID from the serviceResults                String workEffortId = (String) serviceResults.get("workEffortId");                                //create an association between the task and comm event                input = UtilMisc.toMap("userLogin", userLogin, "communicationEventId", communicationEventId, "workEffortId", workEffortId);                serviceResults = dispatcher.runSync("createCommunicationEventWorkEff", input);                if (ServiceUtil.isError(serviceResults)) {                    Debug.logError(ServiceUtil.getErrorMessage(serviceResults), module);                    throw new GenericServiceException(ServiceUtil.getErrorMessage(serviceResults));                }                                //create an association between the WorkEffort and the CommunicationEvent using the partyIdFrom field                context.put("internalPartyId", communicationEvent.getString("partyIdFrom"));                createWorkEffortPartyAssociations(dctx, context, workEffortId, "CrmErrorProcessIncomingEmailFail", false);                input = UtilMisc.toMap("partyId", partyIdTo, "workEffortId", workEffortId, "roleTypeId", roleTypeId, "statusId", "PRTYASGN_ASSIGNED", "userLogin", userLogin);                serviceResults = dispatcher.runSync("assignPartyToWorkEffort", input);                    if (ServiceUtil.isError(serviceResults)) {                    Debug.logError(ServiceUtil.getErrorMessage(serviceResults), module);                    throw new GenericServiceException(ServiceUtil.getErrorMessage(serviceResults));                }            } else {                Debug.logWarning("No valid team member roles found for partyId [" + partyIdTo + "], so no activities will be created for it", module);            }        }    }        /**     * Calls the storeIncomingEmail service to process incoming emails      */    public static Map processIncomingEmail(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        MimeMessageWrapper wrapper = (MimeMessageWrapper) context.get("messageWrapper");        Map serviceResults = null;         Map input = null;        try {            //Call storeIncomingEmail service        	input = UtilMisc.toMap("messageWrapper", wrapper, "userLogin", userLogin);        			serviceResults = dispatcher.runSync("storeIncomingEmail", input);			if (ServiceUtil.isError(serviceResults)) {	            return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorProcessIncomingEmailFail", locale, module);	        }						//Get communicationEventId			String communicationEventId = (String) serviceResults.get("communicationEventId");						//Find CommunicationEvent from its Id			GenericValue communicationEvent = delegator.findByPrimaryKey("CommunicationEvent", UtilMisc.toMap("communicationEventId", communicationEventId));                        String partyIdTo = communicationEvent.getString("partyIdTo");                        //Associate partyIdTo of CommunicationEvent            associateCommunicationEventWorkEffortAndParty(partyIdTo, communicationEvent, delegator, dispatcher, userLogin, locale, dctx, context);						//Associate partyIds of CommunicationEventRoles associated with the CommunicationEvent            List commEventRoles = delegator.findByAnd("CommunicationEventRole", UtilMisc.toMap("communicationEventId", communicationEventId));            Iterator itr = commEventRoles.iterator();                        while (itr.hasNext()) {                GenericValue commEventRole = (GenericValue) itr.next();                                associateCommunicationEventWorkEffortAndParty(commEventRole.getString("partyId"), communicationEvent, delegator, dispatcher, userLogin, locale, dctx, context);            }        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorProcessIncomingEmailFail", locale, module);        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorProcessIncomingEmailFail", locale, module);        }                return ServiceUtil.returnSuccess();    }    /*************************************************************************/    /*                     Create/Update Activities                          */    /*************************************************************************/        public static Map createActivity(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        try {            // get the estimated completion date from the duration            Timestamp estimatedStartDate = (Timestamp) context.get("estimatedStartDate");            Timestamp estimatedCompletionDate = UtilCommon.getEndTimestamp(estimatedStartDate, (String) context.get("duration"), locale);            // check for conflicts            String forceIfConflicts = (String) context.get("forceIfConflicts");            if (forceIfConflicts == null || forceIfConflicts.equals("N")) {                List events = UtilActivity.getActivityConflicts(userLogin, estimatedStartDate, estimatedCompletionDate);                if (events.size() > 0) {                    StringBuffer msg = new StringBuffer("You have one or more conflicting events during the specified time. ");                    msg.append("<a class=\"messageLink\" href=\"/crmsfa/control/myHome?calendarView=day&start=");                    msg.append(UtilDateTime.getDayStart(estimatedStartDate).getTime());                    msg.append("\">Click here to view them.</a>");                    return UtilCommon.createAndLogServiceError(msg.toString(), "CrmErrorCreateActivityFail", locale, module);                }            }            // validate the associations            Map serviceResults = validateWorkEffortAssociations(dctx, context);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateActivityFail", locale, module);            }            // create the workeffort from the context data, which results in a workEffortId            ModelService service = dctx.getModelService("createWorkEffort");            Map input = service.makeValid(context, "IN");            input.put("estimatedCompletionDate", estimatedCompletionDate);            serviceResults = dispatcher.runSync("createWorkEffort", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateActivityFail", locale, module);            }            String workEffortId = (String) serviceResults.get("workEffortId");            // create the associations and finish            serviceResults = createWorkEffortPartyAssociations(dctx, context, workEffortId, "CrmErrorCreateActivityFail", true);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateActivityFail", locale, module);            }            Map results = ServiceUtil.returnSuccess();            results.put("workEffortId", workEffortId);            return results;        } catch (IllegalArgumentException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateActivityFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateActivityFail", locale, module);        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateActivityFail", locale, module);        }    }    public static Map updateActivity(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        String workEffortId = (String) context.get("workEffortId");        try {            // check if userlogin can update this work effort            if (!CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, workEffortId)) {                return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);            }            // get the estimated completion date from the duration            Timestamp estimatedStartDate = (Timestamp) context.get("estimatedStartDate");            Timestamp estimatedCompletionDate = UtilCommon.getEndTimestamp(estimatedStartDate, (String) context.get("duration"), locale);            // check for conflicts            String forceIfConflicts = (String) context.get("forceIfConflicts");            if (forceIfConflicts == null || forceIfConflicts.equals("N")) {                List events = UtilActivity.getActivityConflicts(userLogin, estimatedStartDate, estimatedCompletionDate, workEffortId);                if (events.size() > 0) {                    StringBuffer msg = new StringBuffer("You have one or more conflicting events during the specified time. ");                    msg.append("<a class=\"messageLink\" href=\"/crmsfa/control/myHome?calendarView=day&start=");                    msg.append(UtilDateTime.getDayStart(estimatedStartDate).getTime());                    msg.append("\">Click here to view them.</a>");                    return UtilCommon.createAndLogServiceError(msg.toString(), "CrmErrorCreateActivityFail", locale, module);                }            }            // validate the associations            Map serviceResults = validateWorkEffortAssociations(dctx, context);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateActivityFail", locale, module);            }            // update the workeffort from the context data            ModelService service = dctx.getModelService("updateWorkEffort");            Map input = service.makeValid(context, "IN");            input.put("estimatedCompletionDate", estimatedCompletionDate);            serviceResults = dispatcher.runSync("updateWorkEffort", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateActivityFail", locale, module);            }            // delete existing associations            UtilActivity.removeAllAssociationsForWorkEffort(workEffortId, delegator);            // create the associations and finish            return createWorkEffortPartyAssociations(dctx, context, workEffortId, "CrmErrorUpdateActivityFail", false);        } catch (IllegalArgumentException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateActivityFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityFail", locale, module);        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityFail", locale, module);        }    }    public static Map updateActivityWithoutAssoc(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        String workEffortId = (String) context.get("workEffortId");        try {            // check if userlogin can update this work effort            if (!CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, workEffortId)) {                return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);            }                        // update the workeffort from the context data            ModelService service = dctx.getModelService("updateWorkEffort");            Map input = service.makeValid(context, "IN");            Map serviceResults = dispatcher.runSync("updateWorkEffort", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateActivityFail", locale, module);            }                        return ServiceUtil.returnSuccess();        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityFail", locale, module);        }    }        /*     * Updates the status of the CommunicationEvents associated with a WorkEffort     * If WorkEffort status is started then change the status of related CommunicationEvents from entered to pending.     * If WorkEffort status is completed then change the status of related CommunicationEvents from pending to completed.      */    public static Map updateActivityCommEvent(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        String workEffortId = (String) context.get("workEffortId");        Map input = null;        Map serviceResults = null;        try {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -