Exemplo n.º 1
0
 /** Checks if the given party with role is assigned to the user login. */
 public static boolean isAssignedToUserLogin(
     String partyId, String roleTypeId, GenericValue userLogin) throws GenericEntityException {
   Delegator delegator = userLogin.getDelegator();
   String roleTypeIdTo =
       getFirstValidTeamMemberRoleTypeId(userLogin.getString("partyId"), delegator);
   if (roleTypeIdTo == null) {
     return false;
   }
   List<GenericValue> activeRelationships =
       EntityUtil.filterByDate(
           delegator.findByAnd(
               "PartyRelationship",
               UtilMisc.toMap(
                   "partyIdFrom",
                   partyId,
                   "roleTypeIdFrom",
                   roleTypeId,
                   "partyIdTo",
                   userLogin.get("partyId"),
                   "roleTypeIdTo",
                   roleTypeIdTo,
                   "partyRelationshipTypeId",
                   "ASSIGNED_TO")));
   return activeRelationships.size() > 0;
 }
Exemplo n.º 2
0
  public static String getPartyName(GenericValue partyObject, boolean lastNameFirst) {
    if (partyObject == null) {
      return "";
    }
    if ("PartyGroup".equals(partyObject.getEntityName())
        || "Person".equals(partyObject.getEntityName())) {
      return formatPartyNameObject(partyObject, lastNameFirst);
    } else {
      String partyId = null;
      try {
        partyId = partyObject.getString("partyId");
      } catch (IllegalArgumentException e) {
        Debug.logError(e, "Party object does not contain a party ID", module);
      }

      if (partyId == null) {
        Debug.logWarning(
            "No party ID found; cannot get name based on entity: " + partyObject.getEntityName(),
            module);
        return "";
      } else {
        return getPartyName(partyObject.getDelegator(), partyId, lastNameFirst);
      }
    }
  }
  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);
    binder = new AnnotateDataBinder(comp);
    employeeRequestGroupBox = (Groupbox) comp;

    GenericValue userLogin =
        (GenericValue) Executions.getCurrent().getDesktop().getSession().getAttribute("userLogin");

    GenericDelegator delegator = (GenericDelegator) userLogin.getDelegator();
    String partyId = (String) userLogin.getString("partyId");
    this.assignedRequestTypeList = getAssignedRequsetType(delegator, partyId);

    binder.loadAttribute(requestTypeViewListbox, "model");
  }
 public static long categoryMemberCount(GenericValue category) {
   if (category == null) return 0;
   Delegator delegator = category.getDelegator();
   long count = 0;
   try {
     count =
         delegator.findCountByCondition(
             "ProductCategoryMember",
             buildCountCondition("productCategoryId", category.getString("productCategoryId")),
             null,
             null);
   } catch (GenericEntityException e) {
     Debug.logError(e, module);
   }
   return count;
 }
Exemplo n.º 5
0
 /**
  * Method to return the total amount of a payment which is applied to a payment
  *
  * @param payment GenericValue object of the Payment
  * @param actual false for currency of the payment, true for the actual currency
  * @return the applied total as BigDecimal in the currency of the payment
  */
 public static BigDecimal getPaymentApplied(GenericValue payment, Boolean actual) {
   BigDecimal paymentApplied = BigDecimal.ZERO;
   List<GenericValue> paymentApplications = null;
   try {
     List<EntityExpr> cond =
         UtilMisc.toList(
             EntityCondition.makeCondition(
                 "paymentId", EntityOperator.EQUALS, payment.getString("paymentId")),
             EntityCondition.makeCondition(
                 "toPaymentId", EntityOperator.EQUALS, payment.getString("paymentId")));
     EntityCondition partyCond = EntityCondition.makeCondition(cond, EntityOperator.OR);
     paymentApplications =
         payment
             .getDelegator()
             .findList(
                 "PaymentApplication",
                 partyCond,
                 null,
                 UtilMisc.toList("invoiceId", "billingAccountId"),
                 null,
                 false);
     if (UtilValidate.isNotEmpty(paymentApplications)) {
       for (GenericValue paymentApplication : paymentApplications) {
         BigDecimal amountApplied = paymentApplication.getBigDecimal("amountApplied");
         // check currency invoice and if different convert amount applied for display
         if (actual.equals(Boolean.FALSE)
             && paymentApplication.get("invoiceId") != null
             && payment.get("actualCurrencyAmount") != null
             && payment.get("actualCurrencyUomId") != null) {
           GenericValue invoice = paymentApplication.getRelatedOne("Invoice");
           if (payment
               .getString("actualCurrencyUomId")
               .equals(invoice.getString("currencyUomId"))) {
             amountApplied =
                 amountApplied
                     .multiply(payment.getBigDecimal("amount"))
                     .divide(payment.getBigDecimal("actualCurrencyAmount"), new MathContext(100));
           }
         }
         paymentApplied = paymentApplied.add(amountApplied).setScale(decimals, rounding);
       }
     }
   } catch (GenericEntityException e) {
     Debug.logError(e, "Trouble getting entities", module);
   }
   return paymentApplied;
 }
  @Override
  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);

    GenericValue userLogin =
        (GenericValue) comp.getDesktop().getSession().getAttribute("userLogin");

    GenericDelegator delegator = (GenericDelegator) userLogin.getDelegator();
    if (delegator == null) GenericDelegator.getGenericDelegator("default");

    GenericValue person = userLogin.getRelatedOne("Person");

    Map<String, Object> allFields = person.getAllFields();

    int count = 0;

    Collection<Component> leftHalf = new LinkedList<Component>();
    Collection<Component> rightHalf = new LinkedList<Component>();
    Label label = null;
    Label labelDesc = null;
    for (String key : allFields.keySet()) {

      Object obj = allFields.get(key);
      label = new Label();
      labelDesc = new Label();
      labelDesc.setValue(key);
      label.setValue(obj != null ? obj.toString() : "");
      Hbox hbox = new Hbox(new Component[] {labelDesc, label});
      if (count % 2 == 0) {
        leftHalf.add(hbox);
      } else {
        rightHalf.add(hbox);
      }
      count++;
    }

    Vbox vbox_1 = new org.zkoss.zul.Vbox(leftHalf.toArray(new Component[leftHalf.size()]));
    Vbox vbox_2 = new org.zkoss.zul.Vbox(rightHalf.toArray(new Component[rightHalf.size()]));
    comp.appendChild(vbox_1);
    comp.appendChild(vbox_2);
  }
 public void onEvent(Event event) {
   try {
     GenericValue userLogin =
         (GenericValue)
             Executions.getCurrent().getDesktop().getSession().getAttribute("userLogin");
     Component EditSalaryHeadWindow = event.getTarget();
     GenericDelegator delegator = (GenericDelegator) userLogin.getDelegator();
     String hrName = ((Textbox) EditSalaryHeadWindow.getFellow("applyHrName")).getValue();
     String geoId =
         (String)
             ((com.ndz.zkoss.CountryBox) EditSalaryHeadWindow.getFellow("countrybandbox"))
                 .getSelectedItem()
                 .getValue();
     Listitem isCreditInput =
         ((Listbox) EditSalaryHeadWindow.getFellow("applyCredit")).getSelectedItem();
     String isCredit = (String) isCreditInput.getValue();
     Listitem salaryHeadTypeInput =
         ((Listbox) EditSalaryHeadWindow.getFellow("applySalaryHeadType")).getSelectedItem();
     String salaryHeadType = (String) salaryHeadTypeInput.getValue();
     Listitem isTaxableInput =
         ((Listbox) EditSalaryHeadWindow.getFellow("applyTaxable")).getSelectedItem();
     String isTaxable = (String) isTaxableInput.getValue();
     Listitem isMandatoryInput =
         ((Listbox) EditSalaryHeadWindow.getFellow("applyMandatory")).getSelectedItem();
     String isMandatory = (String) isMandatoryInput.getValue();
     Listitem currencyUomIdInput =
         ((Listbox) EditSalaryHeadWindow.getFellow("applyCurrencyUomId")).getSelectedItem();
     String currencyUomId = (String) currencyUomIdInput.getValue();
     Listitem salaryComputationTypeIdInput =
         ((Listbox) EditSalaryHeadWindow.getFellow("applyComputationType")).getSelectedItem();
     String salaryComputationTypeId = (String) salaryComputationTypeIdInput.getValue();
     Map<String, Object> context =
         UtilMisc.toMap(
             "salaryHeadId",
             delegator.getNextSeqId("salaryHeadId"),
             "hrName",
             hrName,
             "isCr",
             isCredit,
             "salaryHeadTypeId",
             salaryHeadType,
             "isTaxable",
             isTaxable,
             "isMandatory",
             isMandatory,
             "geoId",
             geoId,
             "currencyUomId",
             currencyUomId,
             "salaryComputationTypeId",
             salaryComputationTypeId);
     delegator.create(delegator.makeValue("SalaryHead", context));
     Component searchPanelComponent = EditSalaryHeadWindow.getPage().getFellowIfAny("searchPanel");
     if (searchPanelComponent != null)
       Events.postEvent("onClick$searchButton", searchPanelComponent, null);
     Messagebox.show("Created successfully", "Success", 1, null);
     EditSalaryHeadWindow.detach();
   } catch (Exception e) {
     try {
       Messagebox.show("Created unsuccessfully", "Error", 1, null);
     } catch (Exception e1) {
       e1.printStackTrace();
     }
     e.printStackTrace();
   }
 }
Exemplo n.º 8
0
  public void sessionDestroyed(HttpSessionEvent event) {
    HttpSession session = event.getSession();

    // Finalize the Visit
    boolean beganTransaction = false;
    try {
      beganTransaction = TransactionUtil.begin();

      // instead of using this message, get directly from session attribute so it won't create a new
      // one: GenericValue visit = VisitHandler.getVisit(session);
      GenericValue visit = (GenericValue) session.getAttribute("visit");
      if (visit != null) {
        visit.set("thruDate", new Timestamp(session.getLastAccessedTime()));
        visit.store();
      } else {
        Debug.logWarning(
            "Could not find visit value object in session ["
                + session.getId()
                + "] that is being destroyed",
            module);
      }

      // Store the UserLoginSession
      String userLoginSessionString = getUserLoginSession(session);
      GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
      if (userLogin != null && userLoginSessionString != null) {
        GenericValue userLoginSession = null;
        userLoginSession = userLogin.getRelatedOne("UserLoginSession");

        if (userLoginSession == null) {
          userLoginSession =
              userLogin
                  .getDelegator()
                  .makeValue(
                      "UserLoginSession",
                      UtilMisc.toMap("userLoginId", userLogin.getString("userLoginId")));
          userLogin.getDelegator().create(userLoginSession);
        }
        userLoginSession.set("savedDate", UtilDateTime.nowTimestamp());
        userLoginSession.set("sessionData", userLoginSessionString);
        userLoginSession.store();
      }

      countDestroySession();
      Debug.logInfo("Destroying session: " + session.getId(), module);
      this.logStats(session, visit);
    } catch (GenericEntityException e) {
      try {
        // only rollback the transaction if we started one...
        TransactionUtil.rollback(
            beganTransaction, "Error saving information about closed HttpSession", e);
      } catch (GenericEntityException e2) {
        Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), module);
      }

      Debug.logError(e, "Error in session destuction information persistence", module);
    } finally {
      // only commit the transaction if we started one... this will throw an exception if it fails
      try {
        TransactionUtil.commit(beganTransaction);
      } catch (GenericEntityException e) {
        Debug.logError(
            e, "Could not commit transaction for update visit for session destuction", module);
      }
    }
  }
 protected Process(EntityPersistentMgr mgr, GenericValue process) {
   super(mgr, process.getDelegator());
   this.process = process;
 }
 public AssignmentEventAudit(EntityAuditMgr mgr, GenericValue assignmentEventAudit) {
   super(mgr, assignmentEventAudit.getDelegator(), assignmentEventAudit.getString("eventAuditId"));
   this.assignmentEventAudit = assignmentEventAudit;
 }
Exemplo n.º 11
0
  public static void indexKeywords(GenericValue product, boolean doAll)
      throws GenericEntityException {
    if (product == null) return;
    Timestamp nowTimestamp = UtilDateTime.nowTimestamp();

    if (!doAll) {
      if ("N".equals(product.getString("autoCreateKeywords"))) {
        return;
      }
      if ("Y".equals(product.getString("isVariant"))
          && "true"
              .equals(UtilProperties.getPropertyValue("prodsearch", "index.ignore.variants"))) {
        return;
      }
      Timestamp salesDiscontinuationDate = product.getTimestamp("salesDiscontinuationDate");
      if (salesDiscontinuationDate != null
          && salesDiscontinuationDate.before(nowTimestamp)
          && "true"
              .equals(
                  UtilProperties.getPropertyValue(
                      "prodsearch", "index.ignore.discontinued.sales"))) {
        return;
      }
    }

    Delegator delegator = product.getDelegator();
    if (delegator == null) return;
    String productId = product.getString("productId");

    // get these in advance just once since they will be used many times for the multiple strings to
    // index
    String separators = KeywordSearchUtil.getSeparators();
    String stopWordBagOr = KeywordSearchUtil.getStopWordBagOr();
    String stopWordBagAnd = KeywordSearchUtil.getStopWordBagAnd();
    boolean removeStems = KeywordSearchUtil.getRemoveStems();
    Set<String> stemSet = KeywordSearchUtil.getStemSet();

    Map<String, Long> keywords = new TreeMap<String, Long>();
    List<String> strings = FastList.newInstance();

    int pidWeight = 1;
    try {
      pidWeight =
          Integer.parseInt(
              UtilProperties.getPropertyValue("prodsearch", "index.weight.Product.productId", "0"));
    } catch (Exception e) {
      Debug.logWarning("Could not parse weight number: " + e.toString(), module);
    }
    keywords.put(product.getString("productId").toLowerCase(), Long.valueOf(pidWeight));

    // Product fields - default is 0 if not found in the properties file
    if (!"0"
        .equals(
            UtilProperties.getPropertyValue(
                "prodsearch", "index.weight.Product.productName", "0"))) {
      addWeightedKeywordSourceString(product, "productName", strings);
    }
    if (!"0"
        .equals(
            UtilProperties.getPropertyValue(
                "prodsearch", "index.weight.Product.internalName", "0"))) {
      addWeightedKeywordSourceString(product, "internalName", strings);
    }
    if (!"0"
        .equals(
            UtilProperties.getPropertyValue("prodsearch", "index.weight.Product.brandName", "0"))) {
      addWeightedKeywordSourceString(product, "brandName", strings);
    }
    if (!"0"
        .equals(
            UtilProperties.getPropertyValue(
                "prodsearch", "index.weight.Product.description", "0"))) {
      addWeightedKeywordSourceString(product, "description", strings);
    }
    if (!"0"
        .equals(
            UtilProperties.getPropertyValue(
                "prodsearch", "index.weight.Product.longDescription", "0"))) {
      addWeightedKeywordSourceString(product, "longDescription", strings);
    }

    // ProductFeatureAppl
    if (!"0"
            .equals(
                UtilProperties.getPropertyValue(
                    "prodsearch", "index.weight.ProductFeatureAndAppl.description", "0"))
        || !"0"
            .equals(
                UtilProperties.getPropertyValue(
                    "prodsearch", "index.weight.ProductFeatureAndAppl.abbrev", "0"))
        || !"0"
            .equals(
                UtilProperties.getPropertyValue(
                    "prodsearch", "index.weight.ProductFeatureAndAppl.idCode", "0"))) {
      // get strings from attributes and features
      List<GenericValue> productFeatureAndAppls =
          delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId));
      for (GenericValue productFeatureAndAppl : productFeatureAndAppls) {
        addWeightedKeywordSourceString(productFeatureAndAppl, "description", strings);
        addWeightedKeywordSourceString(productFeatureAndAppl, "abbrev", strings);
        addWeightedKeywordSourceString(productFeatureAndAppl, "idCode", strings);
      }
    }

    // ProductAttribute
    if (!"0"
            .equals(
                UtilProperties.getPropertyValue(
                    "prodsearch", "index.weight.ProductAttribute.attrName", "0"))
        || !"0"
            .equals(
                UtilProperties.getPropertyValue(
                    "prodsearch", "index.weight.ProductAttribute.attrValue", "0"))) {
      List<GenericValue> productAttributes =
          delegator.findByAnd("ProductAttribute", UtilMisc.toMap("productId", productId));
      for (GenericValue productAttribute : productAttributes) {
        addWeightedKeywordSourceString(productAttribute, "attrName", strings);
        addWeightedKeywordSourceString(productAttribute, "attrValue", strings);
      }
    }

    // GoodIdentification
    if (!"0"
        .equals(
            UtilProperties.getPropertyValue(
                "prodsearch", "index.weight.GoodIdentification.idValue", "0"))) {
      List<GenericValue> goodIdentifications =
          delegator.findByAnd("GoodIdentification", UtilMisc.toMap("productId", productId));
      for (GenericValue goodIdentification : goodIdentifications) {
        addWeightedKeywordSourceString(goodIdentification, "idValue", strings);
      }
    }

    // Variant Product IDs
    if ("Y".equals(product.getString("isVirtual"))) {
      if (!"0"
          .equals(
              UtilProperties.getPropertyValue(
                  "prodsearch", "index.weight.Variant.Product.productId", "0"))) {
        List<GenericValue> variantProductAssocs =
            delegator.findByAnd(
                "ProductAssoc",
                UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"));
        variantProductAssocs = EntityUtil.filterByDate(variantProductAssocs);
        for (GenericValue variantProductAssoc : variantProductAssocs) {
          int weight = 1;
          try {
            weight =
                Integer.parseInt(
                    UtilProperties.getPropertyValue(
                        "prodsearch", "index.weight.Variant.Product.productId", "0"));
          } catch (Exception e) {
            Debug.logWarning("Could not parse weight number: " + e.toString(), module);
          }
          for (int i = 0; i < weight; i++) {
            strings.add(variantProductAssoc.getString("productIdTo"));
          }
        }
      }
    }

    String productContentTypes =
        UtilProperties.getPropertyValue("prodsearch", "index.include.ProductContentTypes");
    for (String productContentTypeId : productContentTypes.split(",")) {
      int weight = 1;
      try {
        // this is defaulting to a weight of 1 because you specified you wanted to index this type
        weight =
            Integer.parseInt(
                UtilProperties.getPropertyValue(
                    "prodsearch", "index.weight.ProductContent." + productContentTypeId, "1"));
      } catch (Exception e) {
        Debug.logWarning("Could not parse weight number: " + e.toString(), module);
      }

      List<GenericValue> productContentAndInfos =
          delegator.findByAnd(
              "ProductContentAndInfo",
              UtilMisc.toMap("productId", productId, "productContentTypeId", productContentTypeId),
              null);
      for (GenericValue productContentAndInfo : productContentAndInfos) {
        addWeightedDataResourceString(productContentAndInfo, weight, strings, delegator, product);

        List<GenericValue> alternateViews =
            productContentAndInfo.getRelated(
                "ContentAssocDataResourceViewTo",
                UtilMisc.toMap("caContentAssocTypeId", "ALTERNATE_LOCALE"),
                UtilMisc.toList("-caFromDate"));
        alternateViews =
            EntityUtil.filterByDate(
                alternateViews, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true);
        for (GenericValue thisView : alternateViews) {
          addWeightedDataResourceString(thisView, weight, strings, delegator, product);
        }
      }
    }
    if (UtilValidate.isNotEmpty(strings)) {
      for (String str : strings) {
        // call process keywords method here
        KeywordSearchUtil.processKeywordsForIndex(
            str, keywords, separators, stopWordBagAnd, stopWordBagOr, removeStems, stemSet);
      }
    }

    List<GenericValue> toBeStored = FastList.newInstance();
    int keywordMaxLength =
        Integer.parseInt(
            UtilProperties.getPropertyValue("prodsearch", "product.keyword.max.length"));
    for (Map.Entry<String, Long> entry : keywords.entrySet()) {
      if (entry.getKey().length() <= keywordMaxLength) {
        GenericValue productKeyword =
            delegator.makeValue(
                "ProductKeyword",
                UtilMisc.toMap(
                    "productId",
                    product.getString("productId"),
                    "keyword",
                    entry.getKey(),
                    "keywordTypeId",
                    "KWT_KEYWORD",
                    "relevancyWeight",
                    entry.getValue()));
        toBeStored.add(productKeyword);
      }
    }
    if (toBeStored.size() > 0) {
      if (Debug.verboseOn())
        Debug.logVerbose(
            "[KeywordIndex.indexKeywords] Storing "
                + toBeStored.size()
                + " keywords for productId "
                + product.getString("productId"),
            module);

      if ("true"
          .equals(
              UtilProperties.getPropertyValue("prodsearch", "index.delete.on_index", "false"))) {
        // delete all keywords if the properties file says to
        delegator.removeByAnd(
            "ProductKeyword", UtilMisc.toMap("productId", product.getString("productId")));
      }

      delegator.storeAll(toBeStored);
    }
  }