public Object executeTask(Object object) throws Exception { Map incomingRequest = (Map) object; Object result = null; try { SendQueue sendQueue = (SendQueue) incomingRequest.get("sendQueue"); if (sendQueue == null) { sendQueue = new SendQueue(); } if (incomingRequest.containsKey("SendQueue_queueid")) { String queueidString = (String) incomingRequest.get("SendQueue_queueid"); if (Utility.isEmpty(queueidString)) { queueidString = "0"; } BigDecimal queueid = new BigDecimal(queueidString); sendQueue.setQueueid(queueid); } if (incomingRequest.containsKey("SendQueue_doctype")) { String doctype = (String) incomingRequest.get("SendQueue_doctype"); sendQueue.setDoctype(doctype); } if (incomingRequest.containsKey("SendQueue_docic")) { String docicString = (String) incomingRequest.get("SendQueue_docic"); if (Utility.isEmpty(docicString)) { docicString = "0"; } BigDecimal docic = new BigDecimal(docicString); sendQueue.setDocic(docic); } if (incomingRequest.containsKey("SendQueue_subject")) { String subject = (String) incomingRequest.get("SendQueue_subject"); sendQueue.setSubject(subject); } if (incomingRequest.containsKey("SendQueue_messagetext")) { String messagetext = (String) incomingRequest.get("SendQueue_messagetext"); sendQueue.setMessage(messagetext); } if (incomingRequest.containsKey("SendQueue_messagetext2")) { String messagetext2 = (String) incomingRequest.get("SendQueue_messagetext2"); sendQueue.setMessagetext2(messagetext2); } if (incomingRequest.containsKey("SendQueue_owner")) { String owner = (String) incomingRequest.get("SendQueue_owner"); sendQueue.setOwner(owner); } if (incomingRequest.containsKey("SendQueue_sendfromtype")) { String sendfromtype = (String) incomingRequest.get("SendQueue_sendfromtype"); sendQueue.setSendfromtype(sendfromtype); } if (incomingRequest.containsKey("SendQueue_sendfrom")) { String sendfrom = (String) incomingRequest.get("SendQueue_sendfrom"); sendQueue.setSendfrom(sendfrom); } if (incomingRequest.containsKey("SendQueue_sendtotype")) { String sendtotype = (String) incomingRequest.get("SendQueue_sendtotype"); sendQueue.setSendtotype(sendtotype); } if (incomingRequest.containsKey("SendQueue_sendto")) { String sendto = (String) incomingRequest.get("SendQueue_sendto"); sendQueue.setSendto(sendto); } if (incomingRequest.containsKey("SendQueue_status")) { String status = (String) incomingRequest.get("SendQueue_status"); sendQueue.setStatus(status); } if (incomingRequest.containsKey("SendQueue_dateadded")) { String dateadded = (String) incomingRequest.get("SendQueue_dateadded"); sendQueue.setDateadded(dateadded); } if (incomingRequest.containsKey("SendQueue_timeadded")) { String timeadded = (String) incomingRequest.get("SendQueue_timeadded"); sendQueue.setTimeadded(timeadded); } if (incomingRequest.containsKey("SendQueue_action")) { String action = (String) incomingRequest.get("SendQueue_action"); sendQueue.setAction(action); } if (incomingRequest.containsKey("SendQueue_datesent")) { String datesent = (String) incomingRequest.get("SendQueue_datesent"); sendQueue.setDatesent(datesent); } if (incomingRequest.containsKey("SendQueue_timesent")) { String timesent = (String) incomingRequest.get("SendQueue_timesent"); sendQueue.setTimesent(timesent); } if (incomingRequest.containsKey("SendQueue_attachment")) { String attachment = (String) incomingRequest.get("SendQueue_attachment"); sendQueue.setAttachment(attachment); } if (incomingRequest.containsKey("SendQueue_vendorId")) { String vendorId = (String) incomingRequest.get("SendQueue_vendorId"); sendQueue.setVendorId(vendorId); } if (incomingRequest.containsKey("SendQueue_attempts")) { String attempts = (String) incomingRequest.get("SendQueue_attempts"); if (Utility.isEmpty(attempts)) { attempts = "0"; } sendQueue.setAttempts(new BigDecimal(attempts)); } if (incomingRequest.containsKey("SendQueue_errorText")) { String errorText = (String) incomingRequest.get("SendQueue_errorText"); sendQueue.setErrorText(errorText); } if (incomingRequest.containsKey("SendQueue_args")) { String args = (String) incomingRequest.get("SendQueue_args"); sendQueue.setArgs(args); } result = sendQueue; this.status = Status.SUCCEEDED; } catch (Exception e) { this.status = Status.FAILED; e.printStackTrace(); throw e; } return result; }
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; }