예제 #1
0
 public static String setFollowerPage(HttpServletRequest request, HttpServletResponse response) {
   Security security = (Security) request.getAttribute("security");
   GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
   String visitId = request.getParameter("visitId");
   if (visitId != null) request.setAttribute("visitId", visitId);
   if (security.hasPermission("SEND_CONTROL_APPLET", userLogin)) {
     String followerSessionId = request.getParameter("followerSid");
     String pageUrl = request.getParameter("pageUrl");
     Map<String, String> follow = appletSessions.get(followerSessionId);
     if (follow == null) follow = FastMap.newInstance();
     follow.put("followPage", pageUrl);
     appletSessions.put(followerSessionId, follow);
   }
   return "success";
 }
예제 #2
0
  public static Map<String, Object> createContact(
      DispatchContext dctx, Map<String, Object> context) {
    Delegator delegator = dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Security security = dctx.getSecurity();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    Locale locale = UtilCommon.getLocale(context);

    if (!security.hasPermission("CRMSFA_CONTACT_CREATE", userLogin)) {
      return UtilMessage.createAndLogServiceError("CrmErrorPermissionDenied", locale, MODULE);
    }

    // the net result of creating an contact is the generation of a Contact partyId
    String contactPartyId = (String) context.get("partyId");
    try {
      // make sure user has the right crmsfa roles defined.  otherwise the contact will be created
      // as deactivated.
      if (UtilValidate.isEmpty(
          PartyHelper.getFirstValidTeamMemberRoleTypeId(
              userLogin.getString("partyId"), delegator))) {
        return UtilMessage.createAndLogServiceError(
            "CrmError_NoRoleForCreateParty",
            UtilMisc.toMap(
                "userPartyName",
                org.ofbiz.party.party.PartyHelper.getPartyName(
                    delegator, userLogin.getString("partyId"), false),
                "requiredRoleTypes",
                PartyHelper.TEAM_MEMBER_ROLES),
            locale,
            MODULE);
      }

      // if we're given the partyId to create, then verify it is free to use
      if (contactPartyId != null) {
        Map<String, Object> findMap = UtilMisc.<String, Object>toMap("partyId", contactPartyId);
        GenericValue party = delegator.findByPrimaryKey("Party", findMap);
        if (party != null) {
          return UtilMessage.createAndLogServiceError(
              "person.create.person_exists", findMap, locale, MODULE);
        }
      }

      // create the Party and Person, which results in a partyId
      Map<String, Object> input =
          UtilMisc.<String, Object>toMap(
              "firstName", context.get("firstName"), "lastName", context.get("lastName"));
      if (contactPartyId != null) {
        input.put("partyId", contactPartyId);
      }
      input.put("firstNameLocal", context.get("firstNameLocal"));
      input.put("lastNameLocal", context.get("lastNameLocal"));
      input.put("personalTitle", context.get("personalTitle"));
      input.put("preferredCurrencyUomId", context.get("preferredCurrencyUomId"));
      input.put("description", context.get("description"));
      input.put("birthDate", context.get("birthDate"));
      Map<String, Object> serviceResults = dispatcher.runSync("createPerson", input);
      if (ServiceUtil.isError(serviceResults)) {
        return UtilMessage.createAndLogServiceError(
            serviceResults, "CrmErrorCreateContactFail", locale, MODULE);
      }
      contactPartyId = (String) serviceResults.get("partyId");

      // create a PartyRole for the resulting Contact partyId with roleTypeId = CONTACT
      serviceResults =
          dispatcher.runSync(
              "createPartyRole",
              UtilMisc.toMap(
                  "partyId", contactPartyId, "roleTypeId", "CONTACT", "userLogin", userLogin));
      if (ServiceUtil.isError(serviceResults)) {
        return UtilMessage.createAndLogServiceError(
            serviceResults, "CrmErrorCreateContactFail", locale, MODULE);
      }

      // create PartySupplementalData
      GenericValue partyData =
          delegator.makeValue("PartySupplementalData", UtilMisc.toMap("partyId", contactPartyId));
      partyData.setNonPKFields(context);
      partyData.create();

      // create a party relationship between the userLogin and the Contact with
      // partyRelationshipTypeId RESPONSIBLE_FOR
      createResponsibleContactRelationshipForParty(
          userLogin.getString("partyId"), contactPartyId, userLogin, delegator, dispatcher);

      // if initial marketing campaign is provided, add it
      String marketingCampaignId = (String) context.get("marketingCampaignId");
      if (marketingCampaignId != null) {
        serviceResults =
            dispatcher.runSync(
                "crmsfa.addContactMarketingCampaign",
                UtilMisc.toMap(
                    "partyId",
                    contactPartyId,
                    "marketingCampaignId",
                    marketingCampaignId,
                    "userLogin",
                    userLogin));
        if (ServiceUtil.isError(serviceResults)) {
          return UtilMessage.createAndLogServiceError(
              serviceResults, "CrmErrorCreateContactFail", locale, MODULE);
        }
      }

      // create basic contact info
      ModelService service = dctx.getModelService("crmsfa.createBasicContactInfoForParty");
      input = service.makeValid(context, "IN");
      input.put("partyId", contactPartyId);
      serviceResults = dispatcher.runSync(service.name, input);
      if (ServiceUtil.isError(serviceResults)) {
        return UtilMessage.createAndLogServiceError(
            serviceResults, "CrmErrorCreateContactFail", locale, MODULE);
      }

      // Sumit:  priority of warehouse for the specified party..
      String priorityOne = (String) context.get("warehousePriorityOne");
      String priorityTwo = (String) context.get("warehousePriorityTwo");
      String priorityThree = (String) context.get("warehousePriorityThree");
      String priorityFour = (String) context.get("warehousePriorityFour");

      if (UtilValidate.isNotEmpty(priorityOne)
          && UtilValidate.isNotEmpty(priorityTwo)
          && UtilValidate.isNotEmpty(priorityThree)
          && UtilValidate.isNotEmpty(priorityFour)) {
        Set<String> priorityList = new LinkedHashSet<String>();
        priorityList.add(priorityOne);
        priorityList.add(priorityTwo);
        priorityList.add(priorityThree);
        priorityList.add(priorityFour);
        List<GenericValue> warehousePriority = new ArrayList<GenericValue>();

        GenericValue facilityPriorityOne = delegator.makeValue("FacilityPartyPriority");
        Long count = 0L;
        for (String priority : priorityList) {
          count++;
          facilityPriorityOne.set("facilityId", priority);
          facilityPriorityOne.set("partyId", contactPartyId);
          facilityPriorityOne.set("priority", count);
          facilityPriorityOne.set("thruDate", UtilDateTime.nowTimestamp());
          warehousePriority.add(facilityPriorityOne);
        }
        delegator.storeAll(warehousePriority);
      }

    } catch (GenericServiceException e) {
      return UtilMessage.createAndLogServiceError(e, "CrmErrorCreateContactFail", locale, MODULE);
    } catch (GenericEntityException e) {
      return UtilMessage.createAndLogServiceError(e, "CrmErrorCreateContactFail", locale, MODULE);
    }

    // return the partyId of the newly created Contact
    Map<String, Object> results = ServiceUtil.returnSuccess();
    results.put("partyId", contactPartyId);
    results.put("contactPartyId", contactPartyId);
    return results;
  }