List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:org.ofbiz.order.shoppingcart.ShoppingCartEvents.java
/** * Add agreement order term */*from ww w . j av a 2 s . co m*/ */ public static String addAgreementOrderTerm(HttpServletRequest request, HttpServletResponse response) { ShoppingCart cart = getCartObject(request); Locale locale = UtilHttp.getLocale(request); cart.removeOrderTerms(); String termTypeId = request.getParameter("termTypeId"); String termValueStr = request.getParameter("termValue"); String termDaysStr = request.getParameter("termDays"); String textValue = request.getParameter("textValue"); String textValueCodeudor = request.getParameter("textValueCodeudor"); String termValueAnticipo = request.getParameter("termValueAnticipo"); String termValueCuotas = request.getParameter("termValueCuotas"); String textValueDate = request.getParameter("textValueDate"); String termValueVencimiento = request.getParameter("termValueVencimiento"); String textValueRefNom1 = request.getParameter("textValueRefNom1"); String termValueRefTel1 = request.getParameter("termValueRefTel1"); String textValueRefNom2 = request.getParameter("textValueRefNom2"); String termValueRefTel2 = request.getParameter("termValueRefTel2"); // ANTICIPO termTypeId = "CRD_ANTICIPO"; termValueStr = termValueAnticipo; GenericValue termType = null; Delegator delegator = (Delegator) request.getAttribute("delegator"); BigDecimal termValue = null; Long termDays = null; Long DiaVencimiento = null; Timestamp termDate = null; Timestamp termDateIni = null; Long termSec = Long.valueOf(0); termSec++; if (UtilValidate.isNotEmpty(termValueStr)) { // if (UtilValidate.isEmpty(termTypeId)) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); // return "error"; // } try { termType = delegator.findOne("TermType", UtilMisc.toMap("termTypeId", termTypeId), false); } catch (GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } // if (("FIN_PAYMENT_TERM".equals(termTypeId) && UtilValidate.isEmpty(termDaysStr)) || (UtilValidate.isNotEmpty(termType) && "FIN_PAYMENT_TERM".equals(termType.get("parentTypeId")) && UtilValidate.isEmpty(termDaysStr))) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysIsRequired", locale)); // return "error"; // } // if (UtilValidate.isNotEmpty(termValueStr)) { try { termValue = new BigDecimal(termValueStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } } if (UtilValidate.isNotEmpty(termDaysStr)) { try { termDays = Long.valueOf(termDaysStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays", termDaysStr), locale)); return "error"; } } //removeOrderTerm(request, response); cart.addOrderTerm(termTypeId, termValue, termDays, textValue, termDate, termSec); } // //----------------------------------------------------// termTypeId = null; termValueStr = null; termDaysStr = null; textValue = null; termTypeId = "CRD_CODEUDOR"; textValue = textValueCodeudor; termType = null; termValue = null; termDays = null; termSec++; if (UtilValidate.isNotEmpty(textValueCodeudor)) { // if (UtilValidate.isEmpty(termTypeId)) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); // return "error"; // } try { termType = delegator.findOne("TermType", UtilMisc.toMap("termTypeId", termTypeId), false); } catch (GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } if (("FIN_PAYMENT_TERM".equals(termTypeId) && UtilValidate.isEmpty(termDaysStr)) || (UtilValidate.isNotEmpty(termType) && "FIN_PAYMENT_TERM".equals(termType.get("parentTypeId")) && UtilValidate.isEmpty(termDaysStr))) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysIsRequired", locale)); return "error"; } if (UtilValidate.isNotEmpty(termValueStr)) { try { termValue = new BigDecimal(termValueStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } } if (UtilValidate.isNotEmpty(termDaysStr)) { try { termDays = Long.valueOf(termDaysStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays", termDaysStr), locale)); return "error"; } } //removeOrderTerm(request, response); cart.addOrderTerm(termTypeId, termValue, termDays, textValue, termDate, termSec); } //----------------------------------------------------// termTypeId = null; termValueStr = null; termDaysStr = null; textValue = null; termTypeId = "CRD_REFERENCIA"; textValue = textValueRefNom1.toUpperCase(); termValueStr = termValueRefTel1; termType = null; termValue = null; termDays = null; termSec++; if (UtilValidate.isNotEmpty(textValueRefNom1)) { // if (UtilValidate.isEmpty(termTypeId)) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); // return "error"; // } try { termType = delegator.findOne("TermType", UtilMisc.toMap("termTypeId", termTypeId), false); } catch (GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } if (("FIN_PAYMENT_TERM".equals(termTypeId) && UtilValidate.isEmpty(termDaysStr)) || (UtilValidate.isNotEmpty(termType) && "FIN_PAYMENT_TERM".equals(termType.get("parentTypeId")) && UtilValidate.isEmpty(termDaysStr))) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysIsRequired", locale)); return "error"; } if (UtilValidate.isNotEmpty(termValueStr)) { try { termValue = new BigDecimal(termValueStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } } if (UtilValidate.isNotEmpty(termDaysStr)) { try { termDays = Long.valueOf(termDaysStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays", termDaysStr), locale)); return "error"; } } //removeOrderTerm(request, response); cart.addOrderTerm(termTypeId, termValue, termDays, textValue, termDate, termSec); } //----------------------------------------------------// termTypeId = null; termValueStr = null; termDaysStr = null; textValue = null; termTypeId = "CRD_REFERENCIA"; textValue = textValueRefNom2.toUpperCase(); termValueStr = termValueRefTel2; termType = null; termValue = null; termDays = null; termSec++; if (UtilValidate.isNotEmpty(textValueRefNom2)) { // if (UtilValidate.isEmpty(termTypeId)) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); // return "error"; // } try { termType = delegator.findOne("TermType", UtilMisc.toMap("termTypeId", termTypeId), false); } catch (GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } if (("FIN_PAYMENT_TERM".equals(termTypeId) && UtilValidate.isEmpty(termDaysStr)) || (UtilValidate.isNotEmpty(termType) && "FIN_PAYMENT_TERM".equals(termType.get("parentTypeId")) && UtilValidate.isEmpty(termDaysStr))) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysIsRequired", locale)); return "error"; } if (UtilValidate.isNotEmpty(termValueStr)) { try { termValue = new BigDecimal(termValueStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } } if (UtilValidate.isNotEmpty(termDaysStr)) { try { termDays = Long.valueOf(termDaysStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays", termDaysStr), locale)); return "error"; } } //removeOrderTerm(request, response); cart.addOrderTerm(termTypeId, termValue, termDays, textValue, termDate, termSec); } //----------------------------------------------------// termTypeId = null; termValueStr = null; termDaysStr = null; textValue = null; termTypeId = "CRD_FECHA_INI"; textValue = textValueDate; termType = null; termValue = null; termDays = null; termSec++; if (UtilValidate.isNotEmpty(textValueDate)) { // if (UtilValidate.isEmpty(termTypeId)) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); // return "error"; // } textValueDate = textValueDate + " 00:00:00"; termDate = Timestamp.valueOf(textValueDate); termDateIni = termDate; try { termType = delegator.findOne("TermType", UtilMisc.toMap("termTypeId", termTypeId), false); } catch (GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } // if (("FIN_PAYMENT_TERM".equals(termTypeId) && UtilValidate.isEmpty(termDaysStr)) || (UtilValidate.isNotEmpty(termType) && "FIN_PAYMENT_TERM".equals(termType.get("parentTypeId")) && UtilValidate.isEmpty(termDaysStr))) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysIsRequired", locale)); // return "error"; // } if (UtilValidate.isNotEmpty(termValueStr)) { try { termValue = new BigDecimal(termValueStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } } if (UtilValidate.isNotEmpty(termDaysStr)) { try { termDays = Long.valueOf(termDaysStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays", termDaysStr), locale)); return "error"; } } //removeOrderTerm(request, response); //cart.addOrderTerm(termTypeId, termValue, termDays, textValue, termDate, termSec); } else { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "Debe Cargar Fecha", UtilMisc.toMap("textValueDate", textValueDate), locale)); return "error"; } // //---------------------------------------------------------------// termTypeId = null; termValueStr = null; termDaysStr = null; textValue = null; termTypeId = "CRD_DIA_VENCIMIENTO"; termDaysStr = termValueVencimiento; termType = null; termValue = null; termDays = null; termDate = null; termSec++; if (UtilValidate.isNotEmpty(termValueVencimiento)) { // if (UtilValidate.isEmpty(termTypeId)) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); // return "error"; // } try { termType = delegator.findOne("TermType", UtilMisc.toMap("termTypeId", termTypeId), false); } catch (GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } // if (("FIN_PAYMENT_TERM".equals(termTypeId) && UtilValidate.isEmpty(termDaysStr)) || (UtilValidate.isNotEmpty(termType) && "FIN_PAYMENT_TERM".equals(termType.get("parentTypeId")) && UtilValidate.isEmpty(termDaysStr))) { // request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysIsRequired", locale)); // return "error"; // } if (UtilValidate.isNotEmpty(termValueStr)) { try { termValue = new BigDecimal(termValueStr); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } } if (UtilValidate.isNotEmpty(termDaysStr)) { try { termDays = Long.valueOf(termDaysStr); DiaVencimiento = termDays; } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermDaysError", UtilMisc.toMap("orderTermDays", termDaysStr), locale)); return "error"; } } //removeOrderTerm(request, response); //cart.addOrderTerm(termTypeId, termValue, termDays, textValue, termDate, termSec); } else { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "Debe Cargar Vencimiento", UtilMisc.toMap("textValueDate", textValueDate), locale)); return "error"; } // //---------------------------------------------------------------// int Cuotas = 0; BigDecimal MtTotal = null; BigDecimal MtAnticipo = null; BigDecimal MtCuota = null; BigDecimal CantCuotas = null; if (cart.getOrderType().equals("PURCHASE_ORDER")) { MtTotal = cart.getDisplayGrandTotal();// Para tomar el que tiene IVA } else { MtTotal = cart.getGrandTotal(); } if (UtilValidate.isNotEmpty(termValueCuotas)) { // if (UtilValidate.isNotEmpty(termValueCuotas)) { try { CantCuotas = new BigDecimal(termValueCuotas); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } // } if (UtilValidate.isNotEmpty(termValueAnticipo)) { try { MtAnticipo = new BigDecimal(termValueAnticipo); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } MtTotal = MtTotal.subtract(MtAnticipo); } //CODIGOLINUX Redondea sin decimal MtCuota = MtTotal.divide(CantCuotas, generalRounding).setScale(0, ROUNDING); if (UtilValidate.isNotEmpty(termValueCuotas)) { try { Cuotas = Integer.parseInt(termValueCuotas); } catch (NumberFormatException e) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermValueError", UtilMisc.toMap("orderTermValue", termValueStr), locale)); return "error"; } } termTypeId = "CRD_CUOTA"; if (UtilValidate.isEmpty(termTypeId)) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderOrderTermTypeIsRequired", locale)); return "error"; } try { termType = delegator.findOne("TermType", UtilMisc.toMap("termTypeId", termTypeId), false); } catch (GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } termValueStr = null; termDaysStr = null; textValue = null; termType = null; termValue = null; termDays = null; // termValue = BigDecimal.valueOf(x); //CODIGOLINUX TimeZone timeZone = UtilHttp.getTimeZone(request); termValue = MtCuota; termDate = termDateIni; int ultimoDiaProximoMes = 0; int sumar_dias = 1; Timestamp proximoMes = null; proximoMes = UtilDateTime.nowTimestamp(); for (int x = 1; x <= Cuotas; x++) { textValue = textValueDate; textValue = "Nro." + String.valueOf(x); termDays = (long) x; termSec++; //removeOrderTerm(request, response); cart.addOrderTerm(termTypeId, termValue, termDays, textValue, termDate, termSec); termDate = UtilDateTime.getMonthEnd(termDate, timeZone, locale); proximoMes = UtilDateTime.addDaysToTimestamp(termDate, sumar_dias); termDate = UtilDateTime.getMonthEnd(proximoMes, timeZone, locale); ultimoDiaProximoMes = UtilDateTime.getDayOfMonth(termDate, timeZone, locale); if (ultimoDiaProximoMes > DiaVencimiento) { //termDate=UtilDateTime.adjustTimestamp(termDate, Calendar.DAY_OF_MONTH, DiaVencimiento.intValue(), timeZone, locale); //termDate=UtilDateTime.adjustTimestamp(termDate, Calendar.DAY_OF_MONTH, DiaVencimiento.intValue()); termDate = UtilDateTime.toTimestamp(UtilDateTime.getMonth(proximoMes, timeZone, locale) + 1, DiaVencimiento.intValue(), UtilDateTime.getYear(termDate, timeZone, locale), 0, 0, 0); } else { termDate = UtilDateTime.toTimestamp(UtilDateTime.getMonth(proximoMes, timeZone, locale) + 1, ultimoDiaProximoMes, UtilDateTime.getYear(termDate, timeZone, locale), 0, 0, 0); } } } else { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "Debe Ingresar Numero de Cuotas", UtilMisc.toMap("termValueCuotas", termValueCuotas), locale)); return "error"; } //---------------------------------------------------------------// return "success"; }
From source file:edu.ku.brc.dbsupport.ImportExportDB.java
/** * set the value of an element to the correct type * @param compareMe the element// ww w .j a v a2 s . c o m * @param dbTable the class name of the table * @param parentObject the parent record * @param parentName the parentName * @return an object, "ManyToMany", "OneToMany", or null if it could not find the type */ protected Object findType(Element compareMe, String dbTable, Object parentObject, String parentName) { try { // get the fieldinfo String lowerdbTable = dbTable.toLowerCase(); DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable); // find element with compareme.getName() DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName()); // if the element is an id, ignore it if (!compareMe.getName().equals(lowerFirstChar(dbTable) + "Id")) //$NON-NLS-1$ { // if it is a normal field if (fieldInfo != null) { String type = fieldInfo.getType(); // check the type if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$ { return compareMe.getStringValue(); } else if (type.equals("java.util.Date")) //$NON-NLS-1$ { Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$ .getStringValue()); return dtTmp; } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$ { Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue()); return tmstmp; } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$ { int num = new Integer(compareMe.getStringValue()).intValue(); return num; } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$ { Boolean bool = Boolean.valueOf(compareMe.getStringValue()); return bool; } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$ { BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue()); return num; } else if (type.equals("java.lang.Double")) //$NON-NLS-1$ { double num = new Double(compareMe.getStringValue()).doubleValue(); return num; } else if (type.equals("java.lang.Float")) //$NON-NLS-1$ { float num = new Float(compareMe.getStringValue()).floatValue(); return num; } else if (type.equals("java.lang.Long")) //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); return num; } else if (type.equals("java.lang.Short")) //$NON-NLS-1$ { short num = new Short(compareMe.getStringValue()).shortValue(); return num; } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$ { byte num = new Byte(compareMe.getStringValue()).byteValue(); return num; } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$ { Calendar date = dateString2Calendar(compareMe.getStringValue()); return date; } } else // check if it is a many-to-one { DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName()); if (tablerel != null && tablerel.getType().name() == "ManyToOne") //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); if (compareMe.getName().equals(parentName)) { return parentObject; } // else check if the xml fiel is there, // if so run it // otherwise make a generic thing // some things cant be generic // also check the order of how buildsampledb does it ^.^ // a generic map // get the classtype /* * if(compareMe.getName() == "deaccessionPreparation"){ String className = * tablerel.getClassName().substring(29).toLowerCase();//strip working * set Object tableObject2 = genericDBObject2(className, num); return * tableObject2; } */// else{ // if(compareMe.getName() == "referenceWork"){File path = new // File(importFolderPath+"ReferenceWork"+".xml"); try {// if a generic exsists File path = new File( importFolderPath + capFirstChar(compareMe.getName()) + "Generic.xml"); //$NON-NLS-1$ Element dbImport2 = XMLHelper.readFileToDOM4J(path); Object tableObject = dynamicXMLImportRecReturn(dbImport2, capFirstChar(compareMe.getName())); return tableObject; } catch (FileNotFoundException e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, e); // normal String className = tablerel.getClassName().substring(29).toLowerCase();// strip working set Object tableObject = genericDBObject2(className, num); return tableObject; } // }else{ /* * Element dbImport = XMLHelper.readFileToDOM4J(path); Object * tableObject = dynamicXMLImportRecReturn(dbImport, * capFirstChar(compareMe.getName())); return tableObject; */ // } // check if its a collection (one-to-many) } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$ || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$ { // if many-to-many if (compareMe.getName().equals(parentName + "s")) { //$NON-NLS-0$ return "ManyToMany"; //$NON-NLS-1$ } // else one-to-many return "OneToMany"; //$NON-NLS-1$ } else { log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$ + ", with data:" + compareMe.getData()); //$NON-NLS-1$ } } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex); ex.printStackTrace(); } return null; }
From source file:edu.ku.brc.dbsupport.ImportExportDB.java
protected Object findTypeSequential(Element compareMe, String dbTable, long parentId, String parentName) { try { // get the fieldinfo String lowerdbTable = dbTable.toLowerCase(); DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable); /*/*from ww w . j av a 2 s .c o m*/ * List<DBTableIdMgr.FieldInfo> list = info.getFields(); * //log.debug(compareMe.getName()); for( DBTableIdMgr.FieldInfo i: list){ * System.out.println(i.getName()); } */ // find element with compareme.getName() DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName()); // if the element is an id, ignore it if (!compareMe.getName().equals(lowerFirstChar(dbTable) + "Id")) //$NON-NLS-1$ { // if it is a normal field if (fieldInfo != null) { String type = fieldInfo.getType(); // check the type if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$ { return compareMe.getStringValue(); } else if (type.equals("java.util.Date")) //$NON-NLS-1$ { Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$ .getStringValue()); return dtTmp; } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$ { Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue()); return tmstmp; } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$ { int num = new Integer(compareMe.getStringValue()).intValue(); return num; } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$ { Boolean bool = Boolean.valueOf(compareMe.getStringValue()); return bool; } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$ { BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue()); return num; } else if (type.equals("java.lang.Double")) //$NON-NLS-1$ { double num = new Double(compareMe.getStringValue()).doubleValue(); return num; } else if (type.equals("java.lang.Float")) //$NON-NLS-1$ { float num = new Float(compareMe.getStringValue()).floatValue(); return num; } else if (type.equals("java.lang.Long")) //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); return num; } else if (type.equals("java.lang.Short")) //$NON-NLS-1$ { short num = new Short(compareMe.getStringValue()).shortValue(); return num; } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$ { byte num = new Byte(compareMe.getStringValue()).byteValue(); return num; } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$ { Calendar date = dateString2Calendar(compareMe.getStringValue()); return date; } } else // check if it is a many-to-one { DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName()); if (tablerel != null && tablerel.getType().name() == "ManyToOne") //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); if (compareMe.getName().equals(lowerFirstChar(parentName)))// if they // equal, load // the parent // from the // database { String className = tablerel.getClassName().substring(29).toLowerCase();// strip // working // set Object tableObject = genericDBObject2(className, parentId); return tableObject; } // else check if the xml file is there, // if so run it // otherwise make a generic thing // some things cant be generic // also check the order of how buildsampledb does it ^.^ // a generic map // get the classtype /* * if(compareMe.getName() == "deaccessionPreparation"){ String className = * tablerel.getClassName().substring(29).toLowerCase();//strip working * set Object tableObject2 = genericDBObject2(className, num); return * tableObject2; } */// else{ // if(compareMe.getName() == "referenceWork"){File path = new // File(importFolderPath+"ReferenceWork"+".xml"); try {// if a generic exsists File path = new File( importFolderPath + capFirstChar(compareMe.getName()) + "Generic.xml"); //$NON-NLS-1$ Element dbImport2 = XMLHelper.readFileToDOM4J(path); Object tableObject = dynamicXMLImportRecReturn(dbImport2, capFirstChar(compareMe.getName())); return tableObject; } catch (FileNotFoundException e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, e); // normal String className = tablerel.getClassName().substring(29).toLowerCase();// strip working set Object tableObject = genericDBObject2(className, num); return tableObject; } // }else{ /* * Element dbImport = XMLHelper.readFileToDOM4J(path); Object * tableObject = dynamicXMLImportRecReturn(dbImport, * capFirstChar(compareMe.getName())); return tableObject; */ // } // check if its a collection (one-to-many) } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$ || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$ { // if many-to-many if (compareMe.getName().equals(parentName + "s")) { //$NON-NLS-0$ return "ManyToMany"; //$NON-NLS-1$ } // else one-to-many return "OneToMany"; //$NON-NLS-1$ } else { log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$ + ", with data:" + compareMe.getData()); //$NON-NLS-1$ } } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex); ex.printStackTrace(); } return null; }
From source file:edu.ku.brc.dbsupport.ImportExportDB.java
protected Object findTypeRecordSet(Element compareMe, String dbTable, @SuppressWarnings("unused") long parentId, String parentName) { try { // get the fieldinfo String lowerdbTable = dbTable.toLowerCase(); DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable); // find element with compareme.getName() DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName()); // if the element is an id, ignore it // TODO: shouldl check for primary key if (!compareMe.getName().equals(lowerFirstChar(dbTable) + "Id")) //$NON-NLS-1$ {// w w w . j ava2s .c om // if it is a normal field if (fieldInfo != null) { String type = fieldInfo.getType(); // check the type if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$ { return compareMe.getStringValue(); } else if (type.equals("java.util.Date")) //$NON-NLS-1$ { Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$ .getStringValue()); return dtTmp; } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$ { Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue()); return tmstmp; } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$ { int num = new Integer(compareMe.getStringValue()).intValue(); return num; } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$ { Boolean bool = Boolean.valueOf(compareMe.getStringValue()); return bool; } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$ { BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue()); return num; } else if (type.equals("java.lang.Double")) //$NON-NLS-1$ { double num = new Double(compareMe.getStringValue()).doubleValue(); return num; } else if (type.equals("java.lang.Float")) //$NON-NLS-1$ { float num = new Float(compareMe.getStringValue()).floatValue(); return num; } else if (type.equals("java.lang.Long")) //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); return num; } else if (type.equals("java.lang.Short")) //$NON-NLS-1$ { short num = new Short(compareMe.getStringValue()).shortValue(); return num; } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$ { byte num = new Byte(compareMe.getStringValue()).byteValue(); return num; } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$ { Calendar date = dateString2Calendar(compareMe.getStringValue()); return date; } } else // check if it is a many-to-one { DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName()); // check for many to one, and make sure it has a value if (tablerel != null && tablerel.getType().name() == "ManyToOne" //$NON-NLS-1$ && !compareMe.getStringValue().equals("")) //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); String className = tablerel.getClassName().substring(29);// strip working // set // TODO: remove this condition for agent if (className.equals("Agent")) //$NON-NLS-1$ { className = className.toLowerCase(); Object tableObject = genericDBObject2(className, num); return tableObject; } Object tableObject = getParentDBObject(className, num); return tableObject; // check if its a collection (one-to-many) } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$ || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$ { // if many-to-many if (compareMe.getName().equals(parentName + "s")) { //$NON-NLS-0$ return "ManyToMany"; //$NON-NLS-1$ } // else one-to-many return "OneToMany"; //$NON-NLS-1$ } else { log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$ + ", with data:" + compareMe.getData()); //$NON-NLS-1$ } } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex); if (ex.toString().startsWith("java.lang.NumberFormatException")) { //$NON-NLS-0$ return null; } // else ex.printStackTrace(); } return null; }
From source file:com.krawler.formbuilder.servlet.ReportBuilderDaoImpl.java
public String insertComment(HttpServletRequest request) throws ServiceException { String result = "{\"success\":false}"; try {// ww w. j a v a 2 s .c om String recordid = request.getParameter("recordid"); String reftable = ""; reftable = getReportTableName(request.getParameter("moduleid")); String commentstr = request.getParameter("comment"); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(ModuleBuilderController.USER_DATEPREF); java.sql.Timestamp timestamp1 = Timestamp.valueOf(sdf.format(new java.util.Date())); comments comment = new comments(); comment.setAddedby(sessionHandlerDao.getUserid()); comment.setComment(commentstr); comment.setCreateddate(timestamp1); comment.setDeleteflag(0); comment.setRecordid(recordid); comment.setReftable(reftable); save(comment); result = "{\"success\":true, 'msg':'Comment added successfully.'}"; // String actionType = "Delete Report"; // String reportName = AuditTrialHandler.getReportName(session, reportid); // String details = reportName + " Report Deleted"; // long actionId = AuditTrialHandler.getActionId(session, actionType); // AuditTrialHandler.insertAuditLog(session, actionId, details, request); } catch (Exception e) { logger.warn(e.getMessage(), e); result = "{\"success\":false}"; throw ServiceException.FAILURE("FormServlet.getAllForms", e); } return result; }
From source file:edu.ku.brc.dbsupport.ImportExportDB.java
protected Object findTypeDataBase(Element compareMe, String dbTable, @SuppressWarnings("unused") long parentId, String parentName) { try { // get the fieldinfo String lowerdbTable = dbTable.toLowerCase(); DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable); // find element with compareme.getName() DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName()); // if the element is an id, ignore it // TODO: shouldl check for primary key if (!compareMe.getName().equals(lowerFirstChar(dbTable) + "Id")) //$NON-NLS-1$ {//from w w w. ja va 2s. co m // if it is a normal field if (fieldInfo != null) { String type = fieldInfo.getType(); // check the type if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$ { return compareMe.getStringValue(); } else if (type.equals("java.util.Date")) //$NON-NLS-1$ { Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$ .getStringValue()); return dtTmp; } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$ { Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue()); return tmstmp; } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$ { int num = new Integer(compareMe.getStringValue()).intValue(); return num; } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$ { Boolean bool = Boolean.valueOf(compareMe.getStringValue()); return bool; } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$ { BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue()); return num; } else if (type.equals("java.lang.Double")) //$NON-NLS-1$ { double num = new Double(compareMe.getStringValue()).doubleValue(); return num; } else if (type.equals("java.lang.Float")) //$NON-NLS-1$ { float num = new Float(compareMe.getStringValue()).floatValue(); return num; } else if (type.equals("java.lang.Long")) //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); return num; } else if (type.equals("java.lang.Short")) //$NON-NLS-1$ { short num = new Short(compareMe.getStringValue()).shortValue(); return num; } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$ { byte num = new Byte(compareMe.getStringValue()).byteValue(); return num; } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$ { Calendar date = dateString2Calendar(compareMe.getStringValue()); return date; } } else // check if it is a many-to-one { DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName()); // check for many to one, and make sure it has a value if (tablerel != null && tablerel.getType().name() == "ManyToOne" //$NON-NLS-1$ && !compareMe.getStringValue().equals("")) //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); String className = tablerel.getClassName().substring(29);// strip working // set // TODO: remove this condition for agent if (className.equals("Agent")) //$NON-NLS-1$ { className = className.toLowerCase(); Object tableObject = genericDBObject2(className, num); return tableObject; } else { Object tableObject = loadOrCreateParentDataBaseObject(className, num); return tableObject; } // check if its a collection (one-to-many) } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$ || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$ { // if many-to-many if (compareMe.getName().equals(parentName + "s")) { //$NON-NLS-0$ return "ManyToMany"; //$NON-NLS-1$ } // else one-to-many return "OneToMany"; //$NON-NLS-1$ } else { log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$ + ", with data:" + compareMe.getData()); //$NON-NLS-1$ } } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex); if (ex.toString().startsWith("java.lang.NumberFormatException")) { //$NON-NLS-0$ return null; } // else ex.printStackTrace(); } return null; }
From source file:edu.ku.brc.dbsupport.ImportExportDB.java
protected Object findTypeDataBaseParent(Element compareMe, String dbTable, @SuppressWarnings("unused") long parentId, String parentName) { try { // get the fieldinfo String lowerdbTable = dbTable.toLowerCase(); DBTableInfo info = DBTableIdMgr.getInstance().getInfoByTableName(lowerdbTable); String primaryKey = info.getPrimaryKeyName(); // find element with compareme.getName() DBFieldInfo fieldInfo = info.getFieldByName(compareMe.getName()); // if the element is an id, ignore it // if( !compareMe.getName().equals( lowerFirstChar(dbTable) + "Id") ) // { // if(!primaryKey.equals(compareMe.getName())) // { // if it is a normal field if (fieldInfo != null || primaryKey.equals(compareMe.getName())) // if(fieldInfo != null ) {//from ww w. j a v a2 s . c om String type = new String(); if (fieldInfo == null) {// it is an id type = "java.lang.Integer"; //$NON-NLS-1$ System.out.println(compareMe.getStringValue()); } else { type = fieldInfo.getType(); } // check the type if (type.equals("java.lang.String") || type.equals("text")) //$NON-NLS-1$ //$NON-NLS-2$ { return compareMe.getStringValue(); } else if (type.equals("java.util.Date")) //$NON-NLS-1$ { Date dtTmp = new SimpleDateFormat("yy-MM-dd H:mm:ss").parse(compareMe //$NON-NLS-1$ .getStringValue()); return dtTmp; } else if (type.equals("java.sql.Timestamp")) //$NON-NLS-1$ { Timestamp tmstmp = Timestamp.valueOf(compareMe.getStringValue()); return tmstmp; } else if (type.equals("java.lang.Integer")) //$NON-NLS-1$ { int num = new Integer(compareMe.getStringValue()).intValue(); return num; } else if (type.equals("java.lang.Boolean")) //$NON-NLS-1$ { Boolean bool = Boolean.valueOf(compareMe.getStringValue()); return bool; } else if (type.equals("java.math.BigDecimal")) //$NON-NLS-1$ { BigDecimal num = UIHelper.parseDoubleToBigDecimal(compareMe.getStringValue()); return num; } else if (type.equals("java.lang.Double")) //$NON-NLS-1$ { double num = new Double(compareMe.getStringValue()).doubleValue(); return num; } else if (type.equals("java.lang.Float")) //$NON-NLS-1$ { float num = new Float(compareMe.getStringValue()).floatValue(); return num; } else if (type.equals("java.lang.Long")) //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); return num; } else if (type.equals("java.lang.Short")) //$NON-NLS-1$ { short num = new Short(compareMe.getStringValue()).shortValue(); return num; } else if (type.equals("java.lang.Byte")) //$NON-NLS-1$ { byte num = new Byte(compareMe.getStringValue()).byteValue(); return num; } else if (type.equals("java.util.Calendar")) //$NON-NLS-1$ { Calendar date = dateString2Calendar(compareMe.getStringValue()); return date; } } else // check if it is a many-to-one { DBRelationshipInfo tablerel = info.getRelationshipByName(compareMe.getName()); // check for many to one, and make sure it has a value if (tablerel != null && tablerel.getType().name() == "ManyToOne" //$NON-NLS-1$ && !compareMe.getStringValue().equals("")) //$NON-NLS-1$ { long num = new Long(compareMe.getStringValue()).longValue(); String className = tablerel.getClassName().substring(29);// strip working set // TODO: remove this condition for agent if (className.equals("Agent")) //$NON-NLS-1$ { className = className.toLowerCase(); Object tableObject = genericDBObject2(className, num); return tableObject; } else { Object tableObject = loadOrCreateParentDataBaseObject(className, num); return tableObject; } // check if its a collection (one-to-many) } else if ((tablerel != null && tablerel.getType().name() == "OneToMany") //$NON-NLS-1$ || (tablerel != null && tablerel.getType().name() == "ManyToMany")) //$NON-NLS-1$ { // if many-to-many if (compareMe.getName().equals(parentName + "s")) { //$NON-NLS-0$ return "ManyToMany"; //$NON-NLS-1$ } // else one-to-many return "OneToMany"; //$NON-NLS-1$ } else { log.debug("could not import element: " + compareMe.getName() //$NON-NLS-1$ + ", with data:" + compareMe.getData()); //$NON-NLS-1$ } } // } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex); if (ex.toString().startsWith("java.lang.NumberFormatException")) { //$NON-NLS-0$ return null; } // else ex.printStackTrace(); } return null; }
From source file:edu.ku.brc.dbsupport.ImportExportDB.java
@SuppressWarnings("unchecked") protected Object genericDBObject(String className, long id) { // use the classtype to get the tableinfo DBTableInfo manyToOneInfo = DBTableIdMgr.getInstance().getInfoByTableName(className); // make an object from the tableinfo Object tableObject = new Object(); try {/*from www .j a v a 2 s . com*/ tableObject = manyToOneInfo.getClassObj().newInstance(); // make a map for the object Map relationMap = new HashMap(); Timestamp tmstmp = Timestamp.valueOf("9999-08-22 10:09:05"); //$NON-NLS-1$ relationMap.put(className.concat("Id"), id); //$NON-NLS-1$ relationMap.put("timestampCreated", tmstmp); //$NON-NLS-1$ relationMap.put("timestampModified", tmstmp); //$NON-NLS-1$ // populate the object BeanUtils.populate(tableObject, relationMap); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ImportExportDB.class, ex); ex.printStackTrace(); } // return the object return tableObject; }
From source file:org.wso2.carbon.apimgt.core.dao.impl.ApiDAOImpl.java
/** * Update an Endpoint//from ww w. j a v a 2 s . c o m * * @param endpoint Endpoint Object. * @return Success of the update operation. * @throws APIMgtDAOException If failed to update endpoint. */ @Override public boolean updateEndpoint(Endpoint endpoint) throws APIMgtDAOException { final String query = "UPDATE AM_ENDPOINT SET ENDPOINT_CONFIGURATION = ?,TPS = ?,TYPE = " + "?,SECURITY_CONFIGURATION =?, LAST_UPDATED_TIME = ?, GATEWAY_CONFIG = ? WHERE UUID = ?"; try (Connection connection = DAOUtil.getConnection()) { connection.setAutoCommit(false); try (PreparedStatement statement = connection.prepareStatement(query)) { InputStream byteArrayInputStream = IOUtils.toInputStream(endpoint.getEndpointConfig()); statement.setBinaryStream(1, byteArrayInputStream); if (endpoint.getMaxTps() != null) { statement.setLong(2, endpoint.getMaxTps()); } else { statement.setNull(2, Types.INTEGER); } statement.setString(3, endpoint.getType()); statement.setBinaryStream(4, IOUtils.toInputStream(endpoint.getSecurity())); statement.setTimestamp(5, Timestamp.valueOf(LocalDateTime.now())); statement.setBinaryStream(6, IOUtils.toInputStream(endpoint.getConfig())); statement.setString(7, endpoint.getId()); statement.execute(); connection.commit(); return true; } catch (SQLException e) { String msg = "Couldn't Update Endpoint " + endpoint.getName(); log.error(msg, e); connection.rollback(); throw new APIMgtDAOException(e); } finally { connection.setAutoCommit(DAOUtil.isAutoCommit()); } } catch (SQLException e) { throw new APIMgtDAOException(e); } }
From source file:org.ofbiz.order.shoppingcart.ShoppingCartEvents.java
public static String bulkAddProductsInApprovedOrder(HttpServletRequest request, HttpServletResponse response) { LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); Locale locale = UtilHttp.getLocale(request); String productId = null;//from w w w. j a v a 2 s . co m String productCategoryId = null; String quantityStr = null; String itemDesiredDeliveryDateStr = null; BigDecimal quantity = BigDecimal.ZERO; String itemType = null; String itemDescription = ""; String orderId = null; String shipGroupSeqId = null; Map<String, Object> paramMap = UtilHttp.getParameterMap(request); //FIXME can be removed ? // String itemGroupNumber = request.getParameter("itemGroupNumber"); int rowCount = UtilHttp.getMultiFormRowCount(paramMap); if (rowCount < 1) { Debug.logWarning("No rows to process, as rowCount = " + rowCount, module); } else { for (int i = 0; i < rowCount; i++) { String thisSuffix = UtilHttp.MULTI_ROW_DELIMITER + i; if (paramMap.containsKey("productId" + thisSuffix)) { productId = (String) paramMap.remove("productId" + thisSuffix); } if (paramMap.containsKey("quantity" + thisSuffix)) { quantityStr = (String) paramMap.remove("quantity" + thisSuffix); } if ((quantityStr == null) || (quantityStr.equals(""))) { quantityStr = "0"; } try { quantity = new BigDecimal(quantityStr); } catch (Exception e) { Debug.logWarning(e, "Problems parsing quantity string: " + quantityStr, module); quantity = BigDecimal.ZERO; } String selectedAmountStr = null; if (paramMap.containsKey("amount" + thisSuffix)) { selectedAmountStr = (String) paramMap.remove("amount" + thisSuffix); } BigDecimal amount = null; if (UtilValidate.isNotEmpty(selectedAmountStr)) { try { amount = new BigDecimal(selectedAmountStr); } catch (Exception e) { Debug.logWarning(e, "Problem parsing amount string: " + selectedAmountStr, module); amount = null; } } else { amount = BigDecimal.ZERO; } if (paramMap.containsKey("itemDesiredDeliveryDate" + thisSuffix)) { itemDesiredDeliveryDateStr = (String) paramMap.remove("itemDesiredDeliveryDate" + thisSuffix); } Timestamp itemDesiredDeliveryDate = null; if (UtilValidate.isNotEmpty(itemDesiredDeliveryDateStr)) { try { itemDesiredDeliveryDate = Timestamp.valueOf(itemDesiredDeliveryDateStr); } catch (Exception e) { Debug.logWarning(e, "Problems parsing Reservation start string: " + itemDesiredDeliveryDateStr, module); itemDesiredDeliveryDate = null; request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "shoppingCartEvents.problem_parsing_item_desiredDeliveryDate_string", locale)); } } if (paramMap.containsKey("itemType" + thisSuffix)) { itemType = (String) paramMap.remove("itemType" + thisSuffix); } if (paramMap.containsKey("itemDescription" + thisSuffix)) { itemDescription = (String) paramMap.remove("itemDescription" + thisSuffix); } if (paramMap.containsKey("orderId" + thisSuffix)) { orderId = (String) paramMap.remove("orderId" + thisSuffix); } if (paramMap.containsKey("shipGroupSeqId" + thisSuffix)) { shipGroupSeqId = (String) paramMap.remove("shipGroupSeqId" + thisSuffix); } if (quantity.compareTo(BigDecimal.ZERO) > 0) { Debug.logInfo("Attempting to add to cart with productId = " + productId + ", categoryId = " + productCategoryId + ", quantity = " + quantity + ", itemType = " + itemType + " and itemDescription = " + itemDescription, module); HttpSession session = request.getSession(); GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); Map<String, Object> appendOrderItemMap = FastMap.newInstance(); appendOrderItemMap.put("productId", productId); appendOrderItemMap.put("quantity", quantity); appendOrderItemMap.put("orderId", orderId); appendOrderItemMap.put("userLogin", userLogin); appendOrderItemMap.put("amount", amount); appendOrderItemMap.put("itemDesiredDeliveryDate", itemDesiredDeliveryDate); appendOrderItemMap.put("shipGroupSeqId", shipGroupSeqId); try { Map<String, Object> result = dispatcher.runSync("appendOrderItem", appendOrderItemMap); request.setAttribute("shoppingCart", result.get("shoppingCart")); ShoppingCartEvents.destroyCart(request, response); } catch (GenericServiceException e) { Debug.logError(e, "Failed to execute service appendOrderItem", module); request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; } } } } request.setAttribute("orderId", orderId); return "success"; }