Java Code Examples for org.apache.olingo.odata2.api.commons.HttpStatusCodes#BAD_REQUEST
The following examples show how to use
org.apache.olingo.odata2.api.commons.HttpStatusCodes#BAD_REQUEST .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomerProcessor.java From cloud-espm-v2 with Apache License 2.0 | 6 votes |
/** * Function Import implementation for getting customer by email address * * @param emailAddress * email address of the customer * @return customer entity. * @throws ODataException */ @SuppressWarnings("unchecked") @EdmFunctionImport(name = "GetCustomerByEmailAddress", entitySet = "Customers", returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<Customer> getCustomerByEmailAddress( @EdmFunctionImportParameter(name = "EmailAddress") String emailAddress) throws ODataException { EntityManagerFactory emf = Utility.getEntityManagerFactory(); EntityManager em = emf.createEntityManager(); List<Customer> custList = null; try { Query query = em.createNamedQuery("Customer.getCustomerByEmailAddress"); query.setParameter("emailAddress", emailAddress); try { custList = query.getResultList(); return custList; } catch (NoResultException e) { throw new ODataApplicationException("No matching customer with Email Address:" + emailAddress, Locale.ENGLISH, HttpStatusCodes.BAD_REQUEST, e); } } finally { em.close(); } }
Example 2
Source File: SalesOrderProcessor.java From cloud-espm-v2 with Apache License 2.0 | 5 votes |
/** * Function Import implementation for confirming a sales order * * @param salesOrderId * sales order id of sales order to be confirmed * @return SalesOrderHeader entity * @throws ODataException */ @SuppressWarnings("unchecked") @EdmFunctionImport(name = "ConfirmSalesOrder", entitySet = "SalesOrderHeaders", returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<SalesOrderHeader> confirmSalesOrder( @EdmFunctionImportParameter(name = "SalesOrderId") String salesOrderId) throws ODataException { EntityManagerFactory emf = Utility.getEntityManagerFactory(); EntityManager em = emf.createEntityManager(); try { Query query = em.createNamedQuery("SalesOrderHeader.getSOHBySaledOrderId"); query.setParameter("salesOrderId", salesOrderId); try { SalesOrderHeader so = (SalesOrderHeader) query.getSingleResult(); em.getTransaction().begin(); so.setLifeCycleStatus("P"); so.setLifeCycleStatusName("In Process"); em.persist(so); em.getTransaction().commit(); List<SalesOrderHeader> salesorderlist = null; query = em.createNamedQuery("SalesOrderHeader.getSOHBySaledOrderId"); query.setParameter("salesOrderId", salesOrderId); salesorderlist = query.getResultList(); return salesorderlist; } catch (NoResultException e) { throw new ODataApplicationException("No Sales Order with Sales Order Id:" + salesOrderId, Locale.ENGLISH, HttpStatusCodes.BAD_REQUEST, e); } } finally { em.close(); } }
Example 3
Source File: SalesOrderProcessor.java From cloud-espm-v2 with Apache License 2.0 | 5 votes |
/** * Function Import implementation for cancelling a sales order * * @param salesOrderId * sales order id of sales order to be cancelled * @return SalesOrderHeader entity * @throws ODataException */ @SuppressWarnings("unchecked") @EdmFunctionImport(name = "CancelSalesOrder", entitySet = "SalesOrderHeaders", returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<SalesOrderHeader> cancelSalesOrder( @EdmFunctionImportParameter(name = "SalesOrderId") String salesOrderId) throws ODataException { EntityManagerFactory emf = Utility.getEntityManagerFactory(); EntityManager em = emf.createEntityManager(); try { Query query = em.createNamedQuery("SalesOrderHeader.getSOHBySaledOrderId"); query.setParameter("salesOrderId", salesOrderId); try { SalesOrderHeader so = (SalesOrderHeader) query.getSingleResult(); em.getTransaction().begin(); so.setLifeCycleStatus("X"); so.setLifeCycleStatusName("Cancelled"); em.persist(so); em.getTransaction().commit(); List<SalesOrderHeader> salesOrderList = null; query = em.createNamedQuery("SalesOrderHeader.getSOHBySaledOrderId"); query.setParameter("salesOrderId", salesOrderId); salesOrderList = query.getResultList(); return salesOrderList; } catch (NoResultException e) { throw new ODataApplicationException("No Sales Order with Sales Order Id:" + salesOrderId, Locale.ENGLISH, HttpStatusCodes.BAD_REQUEST , e); } } finally { em.close(); } }
Example 4
Source File: SalesOrderProcessor.java From cloud-espm-v2 with Apache License 2.0 | 4 votes |
/** * Function Import implementation for getting all the Sales Order Items * under a Sales Order Header * * @param SalesOrderId * Sales Order Id of a Sales Order * @return SalesOrderItem entity. * @throws ODataException */ @SuppressWarnings("unchecked") @EdmFunctionImport(name = "GetSalesOrderItemsById", entitySet = "SalesOrderItems", returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<SalesOrderItem> getSalesOrderById( @EdmFunctionImportParameter(name = "SalesOrderId") String salesOrderId) throws ODataException { EntityManagerFactory emf = Utility.getEntityManagerFactory(); EntityManager em = emf.createEntityManager(); List<SalesOrderItem> soiList = null; try { Query query = em.createNamedQuery("SalesOrderItem.getSOIBySalesOrderItemId"); query.setParameter("id", salesOrderId); try { soiList = query.getResultList(); if (soiList != null && soiList.size() >= 1) { for (SalesOrderItem salesOrderItem : soiList) { query = em.createNamedQuery("Product.getProductByProductId"); query.setParameter("productId", salesOrderItem.getProductId()); Product product = (Product) query.getSingleResult(); salesOrderItem.setProduct(product); } // if the sales order are fetched successfully, generate the // pdf report data. try { if (CMISSessionHelper.getInstance().getSession() != null) { InvoiceBuilder builder = new InvoiceBuilder(); String reportPath = builder.generateInvoice(soiList); updateSalesOrderHeader(reportPath, soiList, em); } } catch (CMISConnectionException cmisConnectionException) { // There was an exception while generating the report. LOGGER.error(cmisConnectionException.getMessage()); } } } catch (NoResultException e) { throw new ODataApplicationException("No matching Sales Order with Sales Order Id:" + salesOrderId, Locale.ENGLISH, HttpStatusCodes.BAD_REQUEST, e); } catch (ReportGenerationException reportGenerationException) { //LOGGER.error("Exception while generating the report : " + reportGenerationException.getMessage()); reportGenerationException.printStackTrace(); throw new ODataApplicationException("PDF Report Generation Error for :" + salesOrderId, Locale.ENGLISH, HttpStatusCodes.INTERNAL_SERVER_ERROR, reportGenerationException); } return soiList; } finally { em.close(); } }
Example 5
Source File: SalesOrderProcessor.java From cloud-espm-v2 with Apache License 2.0 | 4 votes |
/** * Function Import implementation for getting all the Sales Order invoices * by email Address under a Sales Order Header * * @param emailAddreaa * * @return SalesOrderHeader entity. * @throws ODataException */ @SuppressWarnings("unchecked") @EdmFunctionImport(name = "GetSalesOrderInvoiceByEmail", entitySet = "SalesOrderHeaders", returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<SalesOrderHeader> getSalesOrderInvoiceByEmail( @EdmFunctionImportParameter(name = "EmailAddress") String emailAddress) throws ODataException { EntityManagerFactory emf = Utility.getEntityManagerFactory(); EntityManager em = emf.createEntityManager(); List<SalesOrderHeader> orderList = new ArrayList<>(); List<SalesOrderHeader> salesOrderHeaderList = new ArrayList<>(); List<SalesOrderItem> itemList = new ArrayList<>(); try { Query querySOItems; Query queryCustomer = em.createNamedQuery("Customer.getCustomerByEmailAddress"); queryCustomer.setParameter("emailAddress", emailAddress); Customer c = (Customer) queryCustomer.getSingleResult(); String customerId = c.getCustomerId(); Query querySOHeader = em.createNamedQuery("SalesOrderHeader.getSOHByCustomerId"); querySOHeader.setParameter("customerId", customerId); orderList = querySOHeader.getResultList(); for (SalesOrderHeader salesOrderHeader : orderList) { querySOItems = em.createNamedQuery("SalesOrderItem.getSOIBySalesOrderItemId"); querySOItems.setParameter("id", salesOrderHeader.getSalesOrderId()); itemList = querySOItems.getResultList(); salesOrderHeader.setSalesOrderItems(itemList); salesOrderHeader.setCustomer(c); salesOrderHeaderList.add(salesOrderHeader); } } catch (NoResultException e) { throw new ODataApplicationException("No Sales Order Invoices with emailId Id:......." + emailAddress, Locale.ENGLISH, HttpStatusCodes.BAD_REQUEST, e); } catch (Exception exception) { throw new ODataApplicationException("No Sales Order Invoices with emailId Id:" + emailAddress, Locale.ENGLISH, HttpStatusCodes.BAD_REQUEST, exception); } finally { em.close(); } return salesOrderHeaderList; }
Example 6
Source File: CustomerReviewProcessor.java From cloud-espm-v2 with Apache License 2.0 | 4 votes |
/** * Function Import implementation for getting customer reviews created * * @param productId * productId of the reviewed product * @param firstName * firstname of the reviewer * @param lastName * lastname of the reviewer * @param rating * rating for the product * @param creationDate * date of creation of the review * @param comment * comments for the review * @return customer entity. * @throws ODataException * @throws ParseException */ @SuppressWarnings("unchecked") @EdmFunctionImport(name = "CreateCustomerReview", entitySet = "CustomerReviews", returnType = @ReturnType(type = Type.ENTITY, isCollection = false)) public CustomerReview createCustomerReview(@EdmFunctionImportParameter(name = "ProductId") String productId, @EdmFunctionImportParameter(name = "FirstName") String firstName, @EdmFunctionImportParameter(name = "LastName") String lastName, @EdmFunctionImportParameter(name = "Rating") String rating, @EdmFunctionImportParameter(name = "CreationDate") String creationDate, @EdmFunctionImportParameter(name = "Comment") String comment) throws ODataException, ParseException { EntityManagerFactory emf = Utility.getEntityManagerFactory(); EntityManager em = emf.createEntityManager(); Product prod = null; CustomerReview customerReview = null; try { em.getTransaction().begin(); prod = em.find(Product.class, productId); try { customerReview = new CustomerReview(); customerReview.setComment(comment); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(Long.parseLong(creationDate))); customerReview.setCreationDate(cal); customerReview.setFirstName(firstName); customerReview.setLastName(lastName); customerReview.setRating(Integer.parseInt(rating)); customerReview.setProductId(productId); customerReview.setProduct(prod); em.persist(customerReview); if (prod != null) { prod.addReview(customerReview); } em.getTransaction().commit(); return customerReview; } catch (NoResultException e) { throw new ODataApplicationException("Error creating customer review:", Locale.ENGLISH, HttpStatusCodes.BAD_REQUEST, e); } } finally { em.close(); } }
Example 7
Source File: ODataBadRequestException.java From olingo-odata2 with Apache License 2.0 | 4 votes |
public ODataBadRequestException(final MessageReference messageReference) { super(messageReference, HttpStatusCodes.BAD_REQUEST); }
Example 8
Source File: ODataBadRequestException.java From olingo-odata2 with Apache License 2.0 | 4 votes |
public ODataBadRequestException(final MessageReference messageReference, final String errorCode) { super(messageReference, HttpStatusCodes.BAD_REQUEST, errorCode); }
Example 9
Source File: ODataBadRequestException.java From olingo-odata2 with Apache License 2.0 | 4 votes |
public ODataBadRequestException(final MessageReference messageReference, final Throwable cause) { super(messageReference, cause, HttpStatusCodes.BAD_REQUEST); }
Example 10
Source File: ODataBadRequestException.java From olingo-odata2 with Apache License 2.0 | 4 votes |
public ODataBadRequestException(final MessageReference messageReference, final Throwable cause, final String errorCode) { super(messageReference, cause, HttpStatusCodes.BAD_REQUEST, errorCode); }