List of usage examples for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES
FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES
To view the source code for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES.
Click Source Link
From source file:com.yaesta.integration.datil.service.DatilService.java
@SuppressWarnings("unused") public FacturaRespuestaSRI processInvoiceOrder(OrderComplete orderComplete) { FacturaSRI factura = new FacturaSRI(); // Preparar informacion de la factura factura.setSecuencial(tableSequenceService.getNextValue("SEQ_INVOICE").intValue()); factura.setTipoEmision(new Integer(datilEmissionType).intValue()); factura.setAmbiente(new Integer(datilEnviromentType).intValue()); factura.setMoneda(datilCurrencyCode); factura.setFechaEmision(UtilDate.formatDateISO(new Date())); List<Item> items = new ArrayList<Item>(); factura.setEmisor(loadEmisorInfo()); factura.setComprador(loadComprador(orderComplete)); Double subTotalShipping = new Double(0); Double subTotalIVAShipping = new Double(0); Double addDiscount = 0D;//from ww w .j a v a 2 s .c o m for (ItemComplete ic : orderComplete.getItems()) { Item it = new Item(); Double quantity = 1D; if (ic.getQuantity() != null) { quantity = ic.getQuantity().doubleValue(); } it.setCantidad(quantity); Double discount = 0D; Double unitPrice = 0D; Double taxValue = 0D; unitPrice = ic.getPrice(); Double itemPrice = ic.getPrice() * quantity; itemPrice = (double) Math.round(itemPrice * 100) / 100; it.setDescripcion(ic.getName()); // it.setCodigoPrincipal(ic.getProductId()); String refId = (String) ic.getRefId(); String productCode[] = SupplierUtil.returnSupplierCode(refId); String principalCode = productCode[0]; if (principalCode.length() > 25) { principalCode = principalCode.substring(0, 24); } it.setCodigoPrincipal(principalCode); Boolean hasTax = Boolean.FALSE; if (ic.getPriceTags() != null && !ic.getPriceTags().isEmpty()) { for (PriceTag pt : ic.getPriceTags()) { if (pt.getName().contains("discount@price")) { Double val = pt.getValue(); if (val < 0) { val = val * (-1); } val = (double) Math.round(val * 100) / 100; discount = discount + Math.abs(val); discount = (double) Math.round(discount * 100) / 100; it.setDescuento(discount); // break; } if (pt.getName().contains("DISCOUNT@MARKETPLACE")) { Double val = pt.getValue(); if (val < 0) { val = val * (-1); } val = (double) Math.round(val * 100) / 100; addDiscount = addDiscount + Math.abs(val); discount = discount + addDiscount; discount = (double) Math.round(discount * 100) / 100; it.setDescuento(discount); } if (pt.getName().contains("tax@price")) { hasTax = Boolean.TRUE; taxValue = pt.getValue(); } } } else { it.setDescuento(discount); } it.setDescuento(discount); // unitPrice = unitPrice - discount; unitPrice = (double) Math.round(unitPrice * 100) / 100; it.setPrecioUnitario(unitPrice); Double precioTotalSinImpuestos = itemPrice - discount; precioTotalSinImpuestos = (double) Math.round(precioTotalSinImpuestos * 100) / 100; it.setPrecioTotalSinImpuestos(precioTotalSinImpuestos); Impuesto_ iva = new Impuesto_(); if (ic.getTax() > 0) { iva.setValor(ic.getTax()); } else { if (hasTax) { iva.setValor(BaseUtil.calculateIVA(precioTotalSinImpuestos, new Integer(datilIvaValue), datilIvaPercentValue)); } } iva.setCodigo(datilIvaCode); iva.setCodigoPorcentaje(datilIvaCodePercent); iva.setBaseImponible(precioTotalSinImpuestos); iva.setTarifa(new Double(datilIvaValue)); List<Impuesto_> impuestos = new ArrayList<Impuesto_>(); impuestos.add(iva); it.setImpuestos(impuestos); items.add(it); } // fin del for de items Double subTotal = new Double(0); for (Total vtot : orderComplete.getTotals()) { if (vtot.getId().equals("Items")) { subTotal = subTotal + vtot.getValue(); } if (vtot.getId().equals("Shipping")) { subTotalShipping = subTotalShipping + vtot.getValue(); if (vtot.getValue() > 0) { Item it = new Item(); it.setCantidad(1D); it.setPrecioTotalSinImpuestos(vtot.getValue()); it.setPrecioUnitario(vtot.getValue()); it.setDescripcion(vtot.getSpanishName()); it.setCodigoPrincipal(datilTransportCode); it.setDescuento(0D); Impuesto_ iva = new Impuesto_(); iva.setValor(BaseUtil.calculateIVA(vtot.getValue(), new Integer(datilIvaValue), datilIvaPercentValue)); iva.setCodigo(datilIvaCode); iva.setCodigoPorcentaje(datilIvaCodePercent); iva.setBaseImponible(vtot.getValue()); iva.setTarifa(new Double(datilIvaValue)); subTotalIVAShipping = subTotalIVAShipping + iva.getValor(); List<Impuesto_> impuestos = new ArrayList<Impuesto_>(); impuestos.add(iva); it.setImpuestos(impuestos); items.add(it); } } if (vtot.getId().equals("Discounts")) { subTotal = subTotal - Math.abs(vtot.getValue()); } } Totales totales = new Totales(); List<Impuesto> impList = new ArrayList<Impuesto>(); for (Total tot : orderComplete.getTotals()) { if (tot.getId().equals("Items")) { Double val = (double) Math.round((subTotal + subTotalShipping) * 100) / 100; totales.setTotalSinImpuestos(val); } else if (tot.getId().equals("Discounts")) { Double val = tot.getValue(); if (val < 0) { val = val * (-1); } totales.setDescuento(Math.abs(val)); // totales.setDescuentoAdicional(Math.abs(val)); totales.setDescuentoAdicional(0D); } else if (tot.getId().equals("Shipping")) { // NOTHING TODO } else if (tot.getId().equals("Tax")) { // taxes = taxes + tot.getValue(); Impuesto imp = new Impuesto(); Double val = (double) Math.round(tot.getValue() * 100) / 100; imp.setValor(val); imp.setCodigo(datilIvaCode); imp.setCodigoPorcentaje(datilIvaCodePercent); imp.setBaseImponible(totales.getTotalSinImpuestos()); impList.add(imp); } } if (addDiscount.intValue() > 0) { totales.setDescuentoAdicional(addDiscount); } totales.setImpuestos(impList); totales.setPropina(0D); totales.setImporteTotal(orderComplete.getValue().doubleValue()); factura.setTotales(totales); factura.setItems(items); List<Pago> pagos = new ArrayList<Pago>(); if (orderComplete.getPaymentData().getTransactions() != null && !orderComplete.getPaymentData().getTransactions().isEmpty()) { for (Transaction tr : orderComplete.getPaymentData().getTransactions()) { if (tr.getPayments() != null && !tr.getPayments().isEmpty()) { for (Payment py : tr.getPayments()) { Pago pago = new Pago(); pago.setTotal(py.getValue()); systemOut.println("SystemPaymentname " + py.getPaymentSystemName()); if (py.getPaymentSystemName() .equals(PaymentEnum.PAGO_CONTRA_ENTREGA.getPaymentSystemName())) { pago.setMedio(PagoEnum.EFECTIVO.getCodigoDatil()); } else if (py.getPaymentSystemName().equals(PaymentEnum.SAFETYPAY.getPaymentSystemName())) { pago.setMedio(PagoEnum.TRANSFER_OTRO_BANCO.getCodigoDatil()); } else if (py.getPaymentSystemName().equals( PaymentEnum.TRANSFERENCIA_BANCARIA_OTRAS_ENTIDADES.getPaymentSystemName())) { pago.setMedio(PagoEnum.TRANSFER_OTRO_BANCO.getCodigoDatil()); } else if (py.getPaymentSystemName() .equals(PaymentEnum.CONSIGNACION_BANCARIA.getPaymentSystemName())) { pago.setMedio(PagoEnum.TRANSFER_OTRO_BANCO.getCodigoDatil()); } else if (py.getPaymentSystemName() .equals(PaymentEnum.TRANSFERENCIA_BANCARIA.getPaymentSystemName())) { pago.setMedio(PagoEnum.TRANSFER_OTRO_BANCO.getCodigoDatil()); } else if (py.getPaymentSystemName().equals(PaymentEnum.PAYCLUB.getPaymentSystemName())) { pago.setMedio(PagoEnum.TARJETA_CREDITO_NACIONAL.getCodigoDatil()); } else if (py.getPaymentSystemName() .equals(PaymentEnum.TARJETA_ALIA.getPaymentSystemName())) { pago.setMedio(PagoEnum.TARJETA_CREDITO_NACIONAL.getCodigoDatil()); } else if (py.getPaymentSystemName() .equals(PaymentEnum.TARJETA_CREDITO.getPaymentSystemName())) { pago.setMedio(PagoEnum.TARJETA_CREDITO_NACIONAL.getCodigoDatil()); } else if (py.getPaymentSystemName().equals(PaymentEnum.PAYPAL.getPaymentSystemName())) { pago.setMedio(PagoEnum.TARJETA_CREDITO_INTERNACIONAL.getCodigoDatil()); } systemOut.println("Medio " + pago.getMedio()); pagos.add(pago); } // fin for factura.setPagos(pagos); } // } } FacturaRespuestaSRI response = invoice(factura, orderComplete); Order order = orderService.findByVitexId(orderComplete.getOrderId()); Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); String toJson = gson.toJson(response); order.setInvoice(toJson); order.setInvoiceReference(response.getId()); // Marcar como facturada la orden order.setStatus("invoiced"); order.setPendingInvoice(Boolean.FALSE); orderService.saveOrder(order); // Consultar la factura generada FacturaConsulta fc = findInvoice(order.getInvoiceReference()); if (fc != null) { String invoiceNumber = formatInvoiceNumber(fc.getSecuencial()); order.setInvoiceNumber(invoiceNumber); order.setSriAut(fc.getAutorizacion().getNumero()); orderService.saveOrder(order); } return response; }
From source file:com.yaesta.integration.datil.service.DatilService.java
public NotaCreditoRespuesta processCreditNote(CreditNoteBean creditNoteBean) { Order order = orderService.findByVitexId(creditNoteBean.getOrderComplete().getOrderId()); systemOut.println("Obtiene orden " + order.getId()); Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); FacturaRespuestaSRI fr = gson.fromJson(order.getInvoice(), FacturaRespuestaSRI.class); systemOut.println("Obtiene factura " + fr.getId()); creditNoteBean.setInvoiceNumber(formatInvoiceNumber(fr.getSecuencial() + "")); creditNoteBean.setInvoiceDate(fr.getFechaEmision()); NotaCredito notaCredito = new NotaCredito(); notaCredito.setAmbiente(new Integer(datilEnviromentType).intValue()); notaCredito.setSecuencial(tableSequenceService.getNextValue("SEQ_CREDIT_NOTE").intValue()); notaCredito.setTipoEmision(new Integer(datilEmissionType).intValue()); notaCredito.setMoneda(datilCurrencyCode); notaCredito.setMotivo(creditNoteBean.getMotive()); notaCredito.setEmisor(loadEmisorInfo()); notaCredito.setComprador(loadComprador(creditNoteBean.getOrderComplete())); notaCredito.setFechaEmision(UtilDate.formatDateISO(new Date())); notaCredito.setFechaEmisionDocumentoModificado(creditNoteBean.getInvoiceDate()); notaCredito.setNumeroDocumentoModificado(formatInvoiceNumber(fr.getSecuencial() + "")); notaCredito.setTipoDocumentoModificado(TipoDocumentoEnum.FACTURA.getCode()); List<Item> items = new ArrayList<Item>(); Double subTotalShipping = new Double(0); Double subTotalIVAShipping = new Double(0); for (ItemComplete ic : creditNoteBean.getOrderComplete().getItems()) { Item it = new Item(); Double quantity = 1D;//w w w . j ava2 s . co m if (ic.getQuantity() != null) { quantity = ic.getQuantity().doubleValue(); } it.setCantidad(quantity); Double unitPrice = 0D; Double discount = 0D; Double itemPrice = ic.getPrice() * quantity; itemPrice = (double) Math.round(itemPrice * 100) / 100; unitPrice = ic.getPrice(); it.setPrecioTotalSinImpuestos(itemPrice); it.setDescripcion(ic.getName()); // it.setCodigoPrincipal(ic.getProductId()); String refId = (String) ic.getRefId(); String productCode[] = SupplierUtil.returnSupplierCode(refId); String principalCode = productCode[0]; if (principalCode.length() > 25) { principalCode = principalCode.substring(0, 24); } it.setCodigoPrincipal(principalCode); Boolean hasTax = Boolean.FALSE; if (ic.getPriceTags() != null && !ic.getPriceTags().isEmpty()) { for (PriceTag pt : ic.getPriceTags()) { if (pt.getName().contains("discount@price")) { Double val = pt.getValue(); if (val < 0) { val = val * (-1); } val = (double) Math.round(val * 100) / 100; discount = discount + Math.abs(val); it.setDescuento(discount); // break; } if (pt.getName().contains("DISCOUNT@MARKETPLACE")) { Double val = pt.getValue(); if (val < 0) { val = val * (-1); } val = (double) Math.round(val * 100) / 100; discount = discount + Math.abs(val); it.setDescuento(discount); } if (pt.getName().contains("tax@price")) { hasTax = Boolean.TRUE; // vTax = pt.getValue(); } } } else { it.setDescuento(discount); } // unitPrice = unitPrice -discount; unitPrice = (double) Math.round(unitPrice * 100) / 100; it.setDescuento(discount); it.setPrecioUnitario(unitPrice); Double precioTotalSinImpuestos = itemPrice - discount; precioTotalSinImpuestos = (double) Math.round(precioTotalSinImpuestos * 100) / 100; it.setPrecioTotalSinImpuestos(precioTotalSinImpuestos); Impuesto_ iva = new Impuesto_(); if (ic.getTax() > 0) { iva.setValor(ic.getTax()); } else { if (hasTax) { iva.setValor(BaseUtil.calculateIVA(precioTotalSinImpuestos, new Integer(datilIvaValue), datilIvaPercentValue)); } } iva.setCodigo(datilIvaCode); iva.setCodigoPorcentaje(datilIvaCodePercent); iva.setBaseImponible(precioTotalSinImpuestos); iva.setTarifa(new Double(datilIvaValue)); List<Impuesto_> impuestos = new ArrayList<Impuesto_>(); impuestos.add(iva); it.setImpuestos(impuestos); items.add(it); } Double subTotal = new Double(0); for (Total vtot : creditNoteBean.getOrderComplete().getTotals()) { if (vtot.getId().equals("Items")) { subTotal = subTotal + vtot.getValue(); } if (vtot.getId().equals("Shipping")) { subTotalShipping = subTotalShipping + vtot.getValue(); if (vtot.getValue() > 0) { Item it = new Item(); it.setCantidad(1D); it.setPrecioTotalSinImpuestos(vtot.getValue()); it.setPrecioUnitario(vtot.getValue()); it.setDescripcion(vtot.getSpanishName()); it.setCodigoPrincipal(datilTransportCode); it.setDescuento(0D); Impuesto_ iva = new Impuesto_(); iva.setValor(BaseUtil.calculateIVA(vtot.getValue(), new Integer(datilIvaValue), datilIvaPercentValue)); iva.setCodigo(datilIvaCode); iva.setCodigoPorcentaje(datilIvaCodePercent); iva.setBaseImponible(vtot.getValue()); iva.setTarifa(new Double(datilIvaValue)); subTotalIVAShipping = subTotalIVAShipping + iva.getValor(); List<Impuesto_> impuestos = new ArrayList<Impuesto_>(); impuestos.add(iva); it.setImpuestos(impuestos); items.add(it); } } } Totales totales = new Totales(); List<Impuesto> impList = new ArrayList<Impuesto>(); for (Total tot : creditNoteBean.getOrderComplete().getTotals()) { if (tot.getId().equals("Items")) { Double val = (double) Math.round((subTotal + subTotalShipping) * 100) / 100; totales.setTotalSinImpuestos(val); } else if (tot.getId().equals("Discounts")) { Double val = tot.getValue(); if (val < 0) { val = val * (-1); } // totales.setDescuento(val); // totales.setDescuentoAdicional(val); } else if (tot.getId().equals("Shipping")) { // NOTHING TODO } else if (tot.getId().equals("Tax")) { // taxes = taxes + tot.getValue(); Impuesto imp = new Impuesto(); Double val = (double) Math.round(tot.getValue() * 100) / 100; imp.setValor(val); imp.setCodigo(datilIvaCode); imp.setCodigoPorcentaje(datilIvaCodePercent); imp.setBaseImponible(totales.getTotalSinImpuestos()); impList.add(imp); } } totales.setImpuestos(impList); // totales.setPropina(0D); totales.setImporteTotal(creditNoteBean.getOrderComplete().getValue().doubleValue()); notaCredito.setTotales(totales); notaCredito.setItems(items); NotaCreditoRespuesta response = creditNote(notaCredito, creditNoteBean.getOrderComplete()); String toJson = gson.toJson(response); order.setCreditNote(toJson); orderService.saveOrder(order); return response; }
From source file:com.yucun.presentation.di.modules.ApplicationModule.java
License:Apache License
@Provides @Singleton Gson provideGson() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); return gsonBuilder.create(); }
From source file:com.zanclus.nexus.auth.proxy.Main.java
License:Open Source License
public static void main(String[] args) throws Exception { Gson gson = (new GsonBuilder()).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create(); Config params = new Config(); JCommander commander = new JCommander(params); commander.setAcceptUnknownOptions(true); commander.setProgramName("nexus-auth-proxy"); commander.parse(args);/* w ww. j ava 2 s . co m*/ if (params.help()) { commander.usage(); System.exit(0); } LOG.debug("Parsed command-line args: \n\n" + gson.toJson(params) + "\n\n"); if (params.configFile().isFile() && params.configFile().canRead()) { Config fileCfg = gson.fromJson(new String(Files.readAllBytes(params.configFile().toPath())), Config.class); mergeConfigs(params, fileCfg); params = fileCfg; } params.fillDefaults(); LOG.debug("Loaded Config:\n\n" + gson.toJson(params) + "\n\n"); }
From source file:cz.cvut.jirutjak.fastimport.droid.oauth2.AccessTokenUtils.java
License:Open Source License
public static RestTemplate createRestTemplate() { RestTemplate template = new RestTemplate(); Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); template.getMessageConverters().add(new GsonHttpMessageConverter(gson)); return template; }
From source file:edu.chalmers.dat076.moviefinder.service.TraktHandler.java
License:Open Source License
private Gson getGson() { return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); }
From source file:edu.oswego.csc480_hci521_2013.server.RestHandler.java
License:Apache License
public RestHandler() { gson = new GsonBuilder().registerTypeAdapter(Inspect.Row.class, new InspectRowDeserializer()) .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); }
From source file:hu.vitamas.enotesz.controller.RegistrationController.java
License:Apache License
private SimpleApiResponse sendRequest(String name, String email, String pass) { String apiKey = Core.getApiKey(); String apiLink = Core.getApiBaseUrl(); if (apiKey == null || apiLink == null) return null; HashMap<String, String> params = MapBuilder.<String, String>newHashMap().set("name", name) .set("email", email).set("pass", pass).set("apiKey", apiKey).build(); try {/*from w ww. j av a2s . co m*/ String response = Core.createApi().setMethod("POST").setUrl(apiLink + "user/registration") .setParams(params).sendRequest(); if (response == null) return null; Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); return gson.fromJson(response, SimpleApiResponse.class); } catch (Exception e) { logger.error("api or gson error", e); } return null; }
From source file:hu.vitamas.enotesz.controller.UserDetailChangeController.java
License:Apache License
private SimpleApiResponse sendChangeRequest(String chpass, String uname, String uemail, Integer userid) { String apiKey = Core.getApiKey(); String apiLink = Core.getApiBaseUrl(); if (apiKey == null || apiLink == null) return null; HashMap<String, String> params = MapBuilder.<String, String>newHashMap().set("userid", userid.toString()) .set("pass", chpass).set("name", uname).set("email", uemail).set("apiKey", apiKey).build(); try {// w w w . j a v a 2s . c o m String response = Core.createApi().setMethod("POST").setUrl(apiLink + "user/changeDetail") .setParams(params).sendRequest(); if (response == null) return null; Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); return gson.fromJson(response, SimpleApiResponse.class); } catch (Exception e) { logger.error("api or gson error", e); } return null; }
From source file:hu.vitamas.enotesz.controller.UserPasswordChangeController.java
License:Apache License
private SimpleApiResponse sendChangeRequest(String newpass, String chpass, Integer userid) { String apiKey = Core.getApiKey(); String apiLink = Core.getApiBaseUrl(); if (apiKey == null || apiLink == null) return null; HashMap<String, String> params = MapBuilder.<String, String>newHashMap().set("userid", userid.toString()) .set("pass", chpass).set("newpass", newpass).set("apiKey", apiKey).build(); try {/* w w w .j a va 2s. com*/ String response = Core.createApi().setMethod("POST").setUrl(apiLink + "user/changePassword") .setParams(params).sendRequest(); if (response == null) return null; Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); return gson.fromJson(response, SimpleApiResponse.class); } catch (Exception e) { logger.error("api or gson error", e); } return null; }