Exemplo n.º 1
0
  public Object executeTask(Object object) throws Exception {
    StringBuffer query = new StringBuffer();
    Object result = null;
    Map incomingRequest = (Map) object;
    try {

      DBSession dbs = (DBSession) incomingRequest.get("dbsession");
      BrowseObject b = (BrowseObject) incomingRequest.get("browseObject");
      String organizationId = (String) incomingRequest.get("organizationId");
      String userTimeZone = (String) incomingRequest.get("userTimeZone");
      String userDateFormat = (String) incomingRequest.get("userDateFormat");
      String sqlWhere = (String) incomingRequest.get("sqlWhere");
      List dateArguments = new ArrayList();

      if (Utility.isEmpty(userDateFormat)) {
        userDateFormat =
            PropertiesManager.getInstance(organizationId)
                .getProperty("MISC", "DATEFORMAT", "MM-dd-yyyy");
      }

      sqlWhere =
          ReportDates.dateWhereClauseDecoder(
              sqlWhere, dateArguments, organizationId, userTimeZone, userDateFormat);

      if (Utility.isEmpty(sqlWhere)) {
        sqlWhere = "";
      }
      String sqlSelect = b.getSqlSelect();

      query.append(sqlSelect);
      query.append(" from " + b.getSqlFrom());
      query.append(" " + sqlWhere);
      Log.debug(this, incomingRequest.get("userId") + " - query: " + query.toString());

      long start = System.currentTimeMillis();
      System.out.println("Report Query: " + query.toString());
      List list = dbs.query(query.toString(), dateArguments.toArray(), b.getMaxRows());
      long end = System.currentTimeMillis();
      Log.error(
          this,
          "It took "
              + ((end - start) / 1000)
              + " seconds to execute the query: "
              + query.toString());
      Log.debug(this, incomingRequest.get("userId") + " - dbs.query COMPLETE.");

      result = list;

      this.setStatus(dbs.getStatus());
    } catch (Exception e) {
      incomingRequest.put("failed", Boolean.TRUE);
      Log.error(
          this,
          "Error executing Report Query: " + query.toString() + " -Exception: " + e.getMessage());
      e.printStackTrace();

      this.setStatus(Status.FAILED);
    }
    return result;
  }
Exemplo n.º 2
0
  public boolean isMaxLockExpired() {
    String sTimeOutPeriod =
        PropertiesManager.getInstance(this.getOrganizationId())
            .getProperty("budgetservice", "lockingPeriod", "30");
    long timeOut = 2000L * (Long.parseLong(sTimeOutPeriod));
    Calendar now = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    long diff = now.getTimeInMillis() - this.getLockingStart().getTimeInMillis();

    if (diff > timeOut) {
      Log.info(this, "Lock Max Expired. Will be Timed out. ");
      return true;
    }
    return false;
  }
Exemplo n.º 3
0
  public Object executeTask(Object object) throws Exception {
    Map incomingRequest = (Map) object;
    Object result = null;

    try {
      String organizationId = (String) incomingRequest.get("organizationId");
      String userTimeZone = (String) incomingRequest.get("userTimeZone");
      String userDateFormat = (String) incomingRequest.get("userDateFormat");

      PropertiesManager propertiesManager = PropertiesManager.getInstance(organizationId);

      if (Utility.isEmpty(userDateFormat)) {
        userDateFormat = propertiesManager.getProperty("MISC", "DateFormat", "");
      }

      String today = Dates.today(userDateFormat, userTimeZone);

      incomingRequest.put("AssetService_tagNumber", "");
      incomingRequest.put("AssetService_sequenceNo", "0");
      incomingRequest.put("AssetService_serviceCallDate", today);
      incomingRequest.put("AssetService_callInitiatedBy", "");
      incomingRequest.put("AssetService_dateInitiated", today);
      incomingRequest.put("AssetService_responseDate", today);
      incomingRequest.put("AssetService_completionDate", today);
      incomingRequest.put("AssetService_serviceAction", "");
      incomingRequest.put("AssetService_serviceCost", "0");
      incomingRequest.put("AssetService_lastChgBy", "");
      incomingRequest.put("AssetService_dateChanged", today);

      this.status = Status.SUCCEEDED;
    } catch (Exception e) {
      this.status = Status.FAILED;
      throw e;
    }
    return result;
  }
  /* (non-Javadoc)
   * @see com.tsagate.puridiom.process.ITask#executeTask(java.lang.Object)
   */
  public Object executeTask(Object object) throws Exception {

    Map incomingRequest = (Map) object;
    Object result = null;

    try {
      String organizationId = (String) incomingRequest.get("organizationId");
      String userTimeZone = (String) incomingRequest.get("userTimeZone");
      String userDateFormat = (String) incomingRequest.get("userDateFormat");

      if (HiltonUtility.isEmpty(userDateFormat)) {
        userDateFormat =
            PropertiesManager.getInstance(organizationId)
                .getProperty("MISC", "DATEFORMAT", "MM-dd-yyyy");
      }

      String today = Dates.today(userDateFormat, userTimeZone);

      if (incomingRequest.containsKey("PoLine_catalogId")
          && incomingRequest.containsKey("PoLine_itemNumber")) {
        String catalogId = (String) incomingRequest.get("PoLine_catalogId");
        String itemNumber = (String) incomingRequest.get("PoLine_itemNumber");
        if (!HiltonUtility.isEmpty(catalogId) && !HiltonUtility.isEmpty(itemNumber)) {
          BigDecimal leadDays =
              CatalogItemManager.getInstance().getLeadDays(organizationId, catalogId, itemNumber);
          incomingRequest.put("PoLine_poPromised", Dates.add(today, leadDays.intValue()));
        }
      }

      this.setStatus(Status.SUCCEEDED);
    } catch (Exception e) {
      Log.debug(this, e.getMessage());
      e.printStackTrace();
      throw e;
    }

    return result;
  }
  public Object executeTask(Object object) throws Exception {
    Map incomingRequest = (Map) object;
    Object result = null;

    try {
      String organizationId = (String) incomingRequest.get("organizationId");
      String userId = (String) incomingRequest.get("userId");
      PropertiesManager propertiesManager = PropertiesManager.getInstance(organizationId);
      incomingRequest.put(
          "ResponseValue_icQuestion",
          propertiesManager.getProperty("RESPONSEVALUE DEFAULTS", "icQuestion", ""));
      incomingRequest.put(
          "ResponseValue_responseValue",
          propertiesManager.getProperty("RESPONSEVALUE DEFAULTS", "responseValue", ""));
      incomingRequest.put(
          "ResponseValue_responseText",
          propertiesManager.getProperty("RESPONSEVALUE DEFAULTS", "responseText", ""));
      incomingRequest.put(
          "ResponseValue_weight",
          propertiesManager.getProperty("RESPONSEVALUE DEFAULTS", "weight", ""));
      incomingRequest.put(
          "ResponseValue_rating",
          propertiesManager.getProperty("RESPONSEVALUE DEFAULTS", "rating", ""));

      ResponseValueAdd addTask = new ResponseValueAdd();
      ResponseValue responseValue = (ResponseValue) addTask.executeTask(incomingRequest);
      this.setStatus(addTask.getStatus());

      result = responseValue;
      this.status = Status.SUCCEEDED;
    } catch (Exception e) {
      this.status = Status.FAILED;
      throw e;
    }
    return result;
  }
  public Object executeTask(Object object) throws Exception {
    try {

      Map incomingRequest = (Map) object;
      String assignTo = (String) incomingRequest.get("assignTo");

      if (Utility.isEmpty(assignTo)) {
        // Notification cannot be sent
        throw new Exception(
            "The notification cannot be sent because the assigned buyer user id was not specified (assignTo).");
      }

      if (assignTo.equalsIgnoreCase("AUTORELEASE")) {
        // Notification should not be sent
        this.setStatus(Status.SUCCEEDED);
        return null;
      }

      if (assignTo.equalsIgnoreCase("UNASSIGNED")) {
        assignTo = "PURCHASING";
      }

      String userId = (String) incomingRequest.get("userId");
      String organizationId = (String) incomingRequest.get("organizationId");
      RequisitionHeader requisitionHeader =
          (RequisitionHeader) incomingRequest.get("requisitionHeader");
      List requisitionLineList = (List) incomingRequest.get("requisitionLineList");
      String assignType = (String) incomingRequest.get("assignType");
      if (assignType == null) {
        assignType = "MANUAL";
      }
      UserProfile assignedBuyer = UserManager.getInstance().getUser(organizationId, assignTo);
      UserProfile requisitioner =
          UserManager.getInstance()
              .getUser(organizationId, requisitionHeader.getRequisitionerCode());
      UserProfile owner =
          UserManager.getInstance().getUser(organizationId, requisitionHeader.getOwner());
      StringBuffer message = new StringBuffer();
      StringBuffer sendTo = new StringBuffer();
      String sendFrom = UserManager.getInstance().getUser(organizationId, userId).getMailId();

      if (Utility.isEmpty(sendFrom)) {
        sendFrom =
            PropertiesManager.getInstance(organizationId)
                .getProperty("MAILEVENTS", "AdminEmailAddr", "");
      }
      if (!Utility.isEmpty(assignedBuyer.getMailId())) {
        sendTo.append(assignedBuyer.getMailId());
      }
      if (!Utility.isEmpty(requisitioner.getMailId()) && assignType.equals("MANUAL")) {
        if (sendTo.length() > 0) {
          sendTo.append(";" + requisitioner.getMailId());
        } else {
          sendTo.append(requisitioner.getMailId());
        }
      }
      if (!Utility.isEmpty(owner.getMailId())) {
        if (sendTo.length() > 0) {
          sendTo.append(";" + owner.getMailId());
        } else {
          sendTo.append(owner.getMailId());
        }
      }

      if (!Utility.isEmpty(assignedBuyer.getMailId())) {
        message.append(
            "Request "
                + requisitionHeader.getRequisitionNumber()
                + " was assigned to "
                + assignedBuyer.getDisplayName()
                + " on "
                + HiltonUtility.getFormattedDate(
                    requisitionHeader.getAssignedDate(), organizationId)
                + ".");
        message.append("\r");
        message.append("\r");
        message.append("This request contains the following items:");
        message.append("\r");

        for (int il = 0; il < requisitionLineList.size(); il++) {
          RequisitionLine requisitionLine = (RequisitionLine) requisitionLineList.get(il);
          message.append(requisitionLine.getLineNumber() + "." + "  ");
          if (!Utility.isEmpty(requisitionLine.getItemNumber())) {
            message.append(requisitionLine.getItemNumber() + " - ");
          }
          message.append(requisitionLine.getDescription());
          message.append("\r");
        }

        incomingRequest.put(
            "SendQueue_subject",
            "Assignment Notification: Requisition " + requisitionHeader.getRequisitionNumber());
        incomingRequest.put("SendQueue_sendfromtype", "E");
        incomingRequest.put("SendQueue_sendfrom", sendFrom);
        incomingRequest.put("SendQueue_sendtotype", "E");
        incomingRequest.put("SendQueue_action", "EN");
        incomingRequest.put("SendQueue_messagetext", message.toString());
        incomingRequest.put("SendQueue_owner", userId);
        incomingRequest.put("SendQueue_doctype", "REQ");
        incomingRequest.put("SendQueue_docic", String.valueOf(requisitionHeader.getIcReqHeader()));
        incomingRequest.put("SendQueue_sendto", sendTo.toString());

        PuridiomProcessLoader processLoader = new PuridiomProcessLoader();
        PuridiomProcess process = processLoader.loadProcess("sendqueue-add.xml");
        process.executeProcess(incomingRequest);
        this.status = process.getStatus();

        if (this.getStatus() != Status.SUCCEEDED) {
          throw new Exception("The email record could not be written to the queue.");
        }
      }

      this.status = Status.SUCCEEDED;
    } catch (Exception e) {
      this.status = Status.FAILED;
      throw e;
    }

    return null;
  }
  public Object executeTask(Object object) throws Exception {
    List result;
    try {
      Map incomingRequest = (Map) object;
      DBSession dbs = (DBSession) incomingRequest.get("dbsession");
      String o = (String) incomingRequest.get("organizationId");
      String userId = (String) incomingRequest.get("userId");
      String userDateFormat = (String) incomingRequest.get("userDateFormat");
      BrowseObject b = (BrowseObject) incomingRequest.get("browseObject");
      List groupFilters = b.getGroupFilters();
      List groupFilterOptions = new ArrayList();
      List commodities = new ArrayList();
      // boolean unspscCommodities = PropertiesManager.getInstance(o).getProperty("MISC",
      // "CommodityType", "").equalsIgnoreCase("UNSPSC");
      boolean unspscCommodities = false;
      boolean commoditySet = false;

      PropertiesManager propertiesManager = PropertiesManager.getInstance(o);

      if (Utility.isEmpty(userDateFormat)) {
        userDateFormat = propertiesManager.getProperty("MISC", "DateFormat", "MM-dd-yyyy");
      }

      for (int ix = 0; ix < groupFilters.size(); ix++) {
        BrowseGroupFilter gf = (BrowseGroupFilter) groupFilters.get(ix);
        StringBuffer query = new StringBuffer();
        StringBuffer queryFilter = new StringBuffer();

        if (!Utility.isEmpty(gf.getType()) && gf.getType().equals("CostRange")) {
          incomingRequest.put("CostRange_itemType", incomingRequest.get("as_item_type"));
        }

        List dateArguments = new ArrayList();

        if (Utility.isEmpty(gf.getType()) || !gf.getType().equals("Keywords")) {
          query.append(gf.getSqlSelect() + " from " + gf.getSqlFrom() + " where 1 = 1");

          if (Utility.ckNull(gf.getSqlWhere()).length() > 0) {
            query.append(" and ( " + gf.getSqlWhere() + ")");
          }
          if (Utility.ckNull(b.getSqlWhere()).length() > 0) {
            String sqlWhere = b.getSqlWhere();
            sqlWhere = sqlWhere.replaceAll(":as_userid", "'" + userId + "'");
            if (sqlWhere.indexOf(":as_today") > 0) {
              dateArguments.add(
                  Dates.getDate(
                      Dates.today(userDateFormat, (String) incomingRequest.get("userTimeZone"))));
            }
            sqlWhere = sqlWhere.replaceAll(":as_today", "?");

            query.append(" and ( " + sqlWhere + ")");
          }

          List filters = b.getBrowseFilters();
          if (filters != null) {
            for (int i = 0; i < filters.size(); i++) {
              BrowseFilter filter = (BrowseFilter) filters.get(i);
              String key = filter.getColumnName();

              if (!b.validateColumn(key)) {
                // skip this filter
                continue;
              }

              String value = encoder.encodeForSQL(new OracleCodec(), filter.getValue());

              String operator = filter.getOperator();
              String logicalOperator = filter.getLogicalOperator();

              if (!BrowseValidationUtility.permissibleOperators.contains(operator)) {
                operator = "=";
              }

              if (!BrowseValidationUtility.permissibleLogicalOperators.contains(logicalOperator)) {
                logicalOperator = "AND";
              }

              String type = filter.getType();

              if (!Utility.isEmpty(value)) {
                if (Utility.isEmpty(operator)) {
                  operator = "=";
                }
                if (Utility.isEmpty(logicalOperator)) {
                  logicalOperator = "AND";
                }
                if (Utility.isEmpty(type)) {
                  type = "STRING";
                }

                if (queryFilter.length() > 0) {
                  queryFilter.append(" " + logicalOperator + " ");
                }

                if (type.equalsIgnoreCase("DATE")) {
                  dateArguments.add(Dates.getDate(userDateFormat, value));
                  queryFilter.append(" " + key + " " + operator + " ?");
                } else if (operator.equalsIgnoreCase("LIKE")) {
                  queryFilter.append(" UPPER(" + key + ") " + operator + " '" + value + "'");
                } else {
                  queryFilter.append(" " + key + " " + operator + " '" + value + "'");
                }

                if (key.indexOf(".commodity") > 0) {
                  if (!Utility.isEmpty(value)) {
                    commoditySet = true;
                    if (value.indexOf("%") > 0) {
                      String commodity = "00000000";
                      for (int iv = 0; iv < value.length(); iv++) {
                        char temp = value.charAt(iv);
                        if (temp != '%') {
                          if (iv == 0) {
                            commodity = temp + commodity.substring(iv + 1);
                          } else if (commodity.length() >= (iv + 1)) {
                            commodity =
                                commodity.substring(0, iv) + temp + commodity.substring(iv + 1);
                          } else {
                            commodity = commodity.substring(0, iv) + temp;
                          }
                        }
                      }
                      if (!commodities.contains(commodity)) {
                        commodities.add(commodity);
                      }
                    }
                  }
                }
              }
            }
          }

          if (queryFilter.length() > 0) {
            query.append("AND (" + queryFilter + " )");
          }

          if (gf.getType().equalsIgnoreCase("Commodity") && unspscCommodities) {
            String originalQueryString = query.toString();
            List commodityList = null;
            CommodityGetUNSPSCWhereClause commodityWhere = new CommodityGetUNSPSCWhereClause();

            int attempts = 0;
            while ((commodityList == null || commodityList.size() == 0) && attempts <= 3) {
              query = new StringBuffer(originalQueryString);

              String commodityArray[] = new String[commodities.size()];
              commodities.toArray(commodityArray);
              incomingRequest.put("Commodity_commodity", commodityArray);
              incomingRequest.put("retrieveAllCodes", "N");

              if (attempts > 0) {
                incomingRequest.put("retrieveAllFamilies", "Y");
                if (attempts > 1) {
                  incomingRequest.put("retrieveAllGroups", "Y");
                  if (attempts > 2) {
                    incomingRequest.put("retrieveAllCommodities", "Y");
                  }
                }
              }

              String unspscWhere = (String) commodityWhere.executeTask(incomingRequest);
              if (!Utility.isEmpty(unspscWhere)) {
                query.append(" AND (" + unspscWhere + ")");
              }

              if (!Utility.isEmpty(gf.getSqlGroupBy())) {
                query.append(" group by " + gf.getSqlGroupBy());
              }
              if (!Utility.isEmpty(gf.getSqlOrderBy())) {
                query.append(" order by " + gf.getSqlOrderBy());
              }

              Log.debug(this, "group filter query: " + query.toString());

              Object arguments[] = new Object[dateArguments.size()];
              for (int i = 0; i < dateArguments.size(); i++) {
                arguments[i] = dateArguments.get(i);
              }
              commodityList = dbs.query(query.toString(), arguments);

              attempts++;
            }

            gf.setSelectionValues(commodityList);
          } else {
            if (!Utility.isEmpty(gf.getSqlGroupBy())) {
              query.append(" group by " + gf.getSqlGroupBy());
            }
            if (!Utility.isEmpty(gf.getSqlOrderBy())) {
              query.append(" order by " + gf.getSqlOrderBy());
            }

            Log.debug(this, "group filter query: " + query.toString());

            Object arguments[] = new Object[dateArguments.size()];
            for (int i = 0; i < dateArguments.size(); i++) {
              arguments[i] = dateArguments.get(i);
            }
            List list = dbs.query(query.toString(), arguments);

            gf.setSelectionValues(list);
          }
        }
      }

      result = groupFilters;

      this.setStatus(dbs.getStatus());
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
    return result;
  }
  /* (non-Javadoc)
   * @see com.tsagate.puridiom.process.ITask#executeTask(java.lang.Object)
   */
  public Object executeTask(Object object) throws Exception {

    Map incomingRequest = (Map) object;
    Object result = null;

    try {
      String organizationId = (String) incomingRequest.get("organizationId");
      String userDateFormat = (String) incomingRequest.get("userDateFormat");
      PropertiesManager propertiesManager = PropertiesManager.getInstance(organizationId);
      CatalogSecurity catalogSecurity = (CatalogSecurity) incomingRequest.get("catalogSecurity");
      String isCatalog = HiltonUtility.ckNull((String) incomingRequest.get("isCatalog"));
      String catalogId = (String) catalogSecurity.getCatalogId();
      String accesType = (String) catalogSecurity.getAccessType();
      String accessId = (String) catalogSecurity.getAccessId();

      if (HiltonUtility.isEmpty(userDateFormat)) {
        userDateFormat = propertiesManager.getProperty("MISC", "DateFormat", "MM-dd-yyyy");
      }

      String today = Dates.today(userDateFormat, (String) incomingRequest.get("userTimeZone"));

      if (isCatalog.equalsIgnoreCase("V")) {
        DBSession dbs = (DBSession) incomingRequest.get("dbsession");

        String queryString =
            "from CatalogSecurity as cs "
                + "where cs.catalogId = ? and cs.itemNumber != '0' "
                + "and cs.accessType = ? ";

        List resultList =
            dbs.query(
                queryString,
                new Object[] {catalogId, accesType},
                new Type[] {Hibernate.STRING, Hibernate.STRING});

        if (resultList != null && resultList.size() > 0) {
          for (int i = 0; i < resultList.size(); i++) {
            CatalogSecurity catalogItemSecurity = (CatalogSecurity) resultList.get(i);

            if (!accessId.equalsIgnoreCase(catalogItemSecurity.getAccessId())) {
              PuridiomProcessLoader processLoader =
                  new PuridiomProcessLoader((String) incomingRequest.get("organizationId"));
              PuridiomProcess process = processLoader.loadProcess("catalogsecurity-add.xml");

              Map updateParameters = new HashMap();

              updateParameters.put("organizationId", organizationId);
              updateParameters.put("dbsession", incomingRequest.get("dbsession"));

              updateParameters.put(
                  "CatalogSecurity_catalogId", (String) catalogSecurity.getCatalogId());
              updateParameters.put(
                  "CatalogSecurity_itemNumber", (String) catalogItemSecurity.getItemNumber());
              updateParameters.put(
                  "CatalogSecurity_accessType", (String) catalogSecurity.getAccessType());
              updateParameters.put(
                  "CatalogSecurity_accessId", (String) catalogSecurity.getAccessId());
              updateParameters.put("CatalogSecurity_owner", (String) catalogSecurity.getOwner());
              updateParameters.put("CatalogSecurity_dateEntered", today);
              updateParameters.put("CatalogSecurity_dateChanged", today);
              updateParameters.put(
                  "CatalogSecurity_lastChangedBy", (String) catalogSecurity.getCatalogId());

              process.executeProcess(updateParameters);

              catalogSecurity.setAccessId(accessId);

              dbs.add(catalogSecurity);
              if (dbs.getStatus() != Status.SUCCEEDED) {
                throw new TsaException(
                    "error ocurred at update catalog security from  for "
                        + catalogSecurity.getItemNumber());
              }
            }
          }
        }
      }

      this.setStatus(Status.SUCCEEDED);
    } catch (Exception e) {
      this.setStatus(Status.FAILED);
      Log.error(this, "An Error occurred at CatalogItemSecurityAddFromCatalog" + e);
      e.printStackTrace();
      throw e;
    }
    return result;
  }