/**
   * Creates a PartyRelationshipType
   *
   * @param ctx The DispatchContext that this service is operating in
   * @param context Map containing the input parameters
   * @return Map with the result of the service, the output parameters
   */
  public static Map<String, Object> createPartyRelationshipType(
      DispatchContext ctx, Map<String, ? extends Object> context) {
    Map<String, Object> result = FastMap.newInstance();
    Delegator delegator = ctx.getDelegator();
    Security security = ctx.getSecurity();
    GenericValue userLogin = (GenericValue) context.get("userLogin");

    ServiceUtil.getPartyIdCheckSecurity(
        userLogin, security, context, result, "PARTYMGR", "_CREATE");

    if (result.size() > 0) return result;

    GenericValue partyRelationshipType =
        delegator.makeValue(
            "PartyRelationshipType",
            UtilMisc.toMap("partyRelationshipTypeId", context.get("partyRelationshipTypeId")));

    partyRelationshipType.set("parentTypeId", context.get("parentTypeId"), true);
    partyRelationshipType.set("hasTable", context.get("hasTable"), true);
    partyRelationshipType.set("roleTypeIdValidFrom", context.get("roleTypeIdValidFrom"), true);
    partyRelationshipType.set("roleTypeIdValidTo", context.get("roleTypeIdValidTo"), false);
    partyRelationshipType.set("description", context.get("description"), true);
    partyRelationshipType.set("partyRelationshipName", context.get("partyRelationshipName"), true);

    try {
      if (delegator.findOne(
              partyRelationshipType.getEntityName(), partyRelationshipType.getPrimaryKey(), false)
          != null) {
        return ServiceUtil.returnError("Could not create party relationship type: already exists");
      }
    } catch (GenericEntityException e) {
      Debug.logWarning(e, module);
      return ServiceUtil.returnError(
          "Could not create party relationship type (read failure): " + e.getMessage());
    }

    try {
      partyRelationshipType.create();
    } catch (GenericEntityException e) {
      Debug.logWarning(e.getMessage(), module);
      return ServiceUtil.returnError(
          "Could not create party relationship type (write failure): " + e.getMessage());
    }

    result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
    return result;
  }
예제 #2
0
  public static String receiveAppletRequest(
      HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    String sessionId = request.getParameter("sessionId");
    String visitId = request.getParameter("visitId");
    sessionId = sessionId.trim();
    visitId = visitId.trim();

    String responseString = "ERROR";

    GenericValue visit = null;
    try {
      visit = delegator.findOne("Visit", false, "visitId", visitId);
    } catch (GenericEntityException e) {
      Debug.logError(e, "Cannot Visit Object", module);
    }

    if (visit.getString("sessionId").equals(sessionId)) {
      String currentPage = request.getParameter("currentPage");
      if (appletSessions.containsKey(sessionId)) {
        Map<String, String> sessionMap = appletSessions.get(sessionId);
        String followers = sessionMap.get("followers");
        List<String> folList = StringUtil.split(followers, ",");
        for (String follower : folList) {
          Map<String, String> folSesMap = UtilMisc.toMap("followPage", currentPage);
          appletSessions.put(follower, folSesMap);
        }
      }
      responseString = "OK";
    }

    try {
      PrintWriter out = response.getWriter();
      response.setContentType("text/plain");
      out.println(responseString);
      out.close();
    } catch (IOException e) {
      Debug.logError(e, "Problems writing servlet output!", module);
    }

    return "success";
  }
예제 #3
0
  public static boolean isProductInCategory(
      Delegator delegator, String productId, String productCategoryId)
      throws GenericEntityException {
    if (productCategoryId == null) return false;
    if (UtilValidate.isEmpty(productId)) return false;

    List<GenericValue> productCategoryMembers =
        EntityUtil.filterByDate(
            delegator.findByAnd(
                "ProductCategoryMember",
                UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId),
                null,
                true),
            true);
    if (UtilValidate.isEmpty(productCategoryMembers)) {
      // before giving up see if this is a variant product, and if so look up the virtual product
      // and check it...
      GenericValue product =
          delegator.findOne("Product", UtilMisc.toMap("productId", productId), true);
      List<GenericValue> productAssocs = ProductWorker.getVariantVirtualAssocs(product);
      // this does take into account that a product could be a variant of multiple products, but
      // this shouldn't ever really happen...
      if (productAssocs != null) {
        for (GenericValue productAssoc : productAssocs) {
          if (isProductInCategory(
              delegator, productAssoc.getString("productId"), productCategoryId)) {
            return true;
          }
        }
      }

      return false;
    } else {
      return true;
    }
  }
예제 #4
0
  public static String checkAppletRequest(
      HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    String sessionId = request.getParameter("sessionId");
    String visitId = request.getParameter("visitId");
    sessionId = sessionId.trim();
    visitId = visitId.trim();

    String responseString = "";

    GenericValue visit = null;
    try {
      visit = delegator.findOne("Visit", false, "visitId", visitId);
    } catch (GenericEntityException e) {
      Debug.logError(e, "Cannot Visit Object", module);
    }

    if (visit != null
        && visit.getString("sessionId").equals(sessionId)
        && appletSessions.containsKey(sessionId)) {
      Map<String, String> sessionMap = appletSessions.get(sessionId);
      if (sessionMap != null && sessionMap.containsKey("followPage"))
        responseString = sessionMap.remove("followPage");
    }

    try {
      PrintWriter out = response.getWriter();
      response.setContentType("text/plain");
      out.println(responseString);
      out.close();
    } catch (IOException e) {
      Debug.logError(e, "Problems writing servlet output!", module);
    }

    return "success";
  }
예제 #5
0
  /**
   * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Delegator delegator = (Delegator) getServletContext().getAttribute("delegator");

    String pathInfo = request.getPathInfo();
    List<String> pathElements = StringUtil.split(pathInfo, "/");

    // look for productId
    String productId = null;
    try {
      String lastPathElement = pathElements.get(pathElements.size() - 1);
      if (lastPathElement.startsWith("p_")
          || delegator.findOne("Product", UtilMisc.toMap("productId", lastPathElement), true)
              != null) {
        if (lastPathElement.startsWith("p_")) {
          productId = lastPathElement.substring(2);
        } else {
          productId = lastPathElement;
        }
        pathElements.remove(pathElements.size() - 1);
      }
    } catch (GenericEntityException e) {
      Debug.logError(
          e,
          "Error looking up product info for ProductUrl with path info ["
              + pathInfo
              + "]: "
              + e.toString(),
          module);
    }

    // get category info going with the IDs that remain
    String categoryId = null;
    if (pathElements.size() == 1) {
      CategoryWorker.setTrail(request, pathElements.get(0), null);
      categoryId = pathElements.get(0);
    } else if (pathElements.size() == 2) {
      CategoryWorker.setTrail(request, pathElements.get(1), pathElements.get(0));
      categoryId = pathElements.get(1);
    } else if (pathElements.size() > 2) {
      List<String> trail = CategoryWorker.getTrail(request);
      if (trail == null) {
        trail = FastList.newInstance();
      }

      if (trail.contains(pathElements.get(0))) {
        // first category is in the trail, so remove it everything after that and fill it in with
        // the list from the pathInfo
        int firstElementIndex = trail.indexOf(pathElements.get(0));
        while (trail.size() > firstElementIndex) {
          trail.remove(firstElementIndex);
        }
        trail.addAll(pathElements);
      } else {
        // first category is NOT in the trail, so clear out the trail and use the pathElements list
        trail.clear();
        trail.addAll(pathElements);
      }
      CategoryWorker.setTrail(request, trail);
      categoryId = pathElements.get(pathElements.size() - 1);
    }
    if (categoryId != null) {
      request.setAttribute("productCategoryId", categoryId);
    }

    String rootCategoryId = null;
    if (pathElements.size() >= 1) {
      rootCategoryId = pathElements.get(0);
    }
    if (rootCategoryId != null) {
      request.setAttribute("rootCategoryId", rootCategoryId);
    }

    if (productId != null) {
      request.setAttribute("product_id", productId);
      request.setAttribute("productId", productId);
    }

    RequestDispatcher rd =
        request.getRequestDispatcher(
            "/"
                + CONTROL_MOUNT_POINT
                + "/"
                + (productId != null ? PRODUCT_REQUEST : CATEGORY_REQUEST));
    rd.forward(request, response);
  }
  /**
   * Creates and updates a PartyRelationship creating related PartyRoles if needed. A side of the
   * relationship is checked to maintain history
   *
   * @param ctx The DispatchContext that this service is operating in
   * @param context Map containing the input parameters
   * @return Map with the result of the service, the output parameters
   */
  public static Map<String, Object> createUpdatePartyRelationshipAndRoles(
      DispatchContext ctx, Map<String, ? extends Object> context) {
    Map<String, Object> result = FastMap.newInstance();
    Delegator delegator = ctx.getDelegator();
    LocalDispatcher dispatcher = ctx.getDispatcher();

    try {
      List<GenericValue> partyRelationShipList =
          PartyRelationshipHelper.getActivePartyRelationships(delegator, context);
      if (UtilValidate.isEmpty(
          partyRelationShipList)) { // If already exists and active nothing to do: keep the current
                                    // one
        String partyId = (String) context.get("partyId");
        String partyIdFrom = (String) context.get("partyIdFrom");
        String partyIdTo = (String) context.get("partyIdTo");
        String roleTypeIdFrom = (String) context.get("roleTypeIdFrom");
        String roleTypeIdTo = (String) context.get("roleTypeIdTo");
        String partyRelationshipTypeId = (String) context.get("partyRelationshipTypeId");

        // Before creating the partyRelationShip, create the partyRoles if they don't exist
        GenericValue partyToRole = null;
        partyToRole =
            delegator.findOne(
                "PartyRole",
                UtilMisc.toMap("partyId", partyIdTo, "roleTypeId", roleTypeIdTo),
                false);
        if (partyToRole == null) {
          partyToRole =
              delegator.makeValue(
                  "PartyRole", UtilMisc.toMap("partyId", partyIdTo, "roleTypeId", roleTypeIdTo));
          partyToRole.create();
        }

        GenericValue partyFromRole = null;
        partyFromRole =
            delegator.findOne(
                "PartyRole",
                UtilMisc.toMap("partyId", partyIdFrom, "roleTypeId", roleTypeIdFrom),
                false);
        if (partyFromRole == null) {
          partyFromRole =
              delegator.makeValue(
                  "PartyRole",
                  UtilMisc.toMap("partyId", partyIdFrom, "roleTypeId", roleTypeIdFrom));
          partyFromRole.create();
        }

        // Check if there is already a partyRelationship of that type with another party from the
        // side indicated
        String sideChecked = partyIdFrom.equals(partyId) ? "partyIdFrom" : "partyIdTo";
        partyRelationShipList =
            delegator.findByAnd(
                "PartyRelationship",
                UtilMisc.toMap(
                    sideChecked,
                    partyId,
                    "roleTypeIdFrom",
                    roleTypeIdFrom,
                    "roleTypeIdTo",
                    roleTypeIdTo,
                    "partyRelationshipTypeId",
                    partyRelationshipTypeId));
        // We consider the last one (in time) as sole active (we try to maintain a unique
        // relationship and keep changes history)
        partyRelationShipList = EntityUtil.filterByDate(partyRelationShipList);
        GenericValue oldPartyRelationShip = EntityUtil.getFirst(partyRelationShipList);
        if (UtilValidate.isNotEmpty(oldPartyRelationShip)) {
          oldPartyRelationShip.setFields(
              UtilMisc.toMap("thruDate", UtilDateTime.nowTimestamp())); // Current becomes inactive
          oldPartyRelationShip.store();
        }
        try {
          dispatcher.runSync("createPartyRelationship", context); // Create new one
        } catch (GenericServiceException e) {
          Debug.logWarning(e.getMessage(), module);
          return ServiceUtil.returnError(
              "Could not create party relationship (write failure): " + e.getMessage());
        }
      }
    } catch (GenericEntityException e) {
      Debug.logWarning(e.getMessage(), module);
      return ServiceUtil.returnError(
          "Could not create party relationship (write failure): " + e.getMessage());
    }
    result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
    return result;
  }