org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImportParameter Java Examples
The following examples show how to use
org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImportParameter.
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: OrderService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 6 votes |
@EdmFunctionImport(name = FunctionImportNames.DELETE_ORDER, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.DELETE) public boolean deleteOrderDetail(@EdmFunctionImportParameter(name = ORDER_ID, type = INT64) Long orderId) throws AppODataException { final OrderDetailDAO orderDetailDAO = new OrderDetailDAO(); final Order order = orderDetailDAO.getOrderByOrderDetailsId(orderId); final OrderDetails details = orderDetailDAO.getById(orderId); final UserPoints userPoints = getUserPoints(order); try { order.removeOrderDetails(details); userPoints.addPoints(calcPointsToAdd(details)); userPointsDAO.save(userPoints); orderDetailDAO.delete(orderId); return true; } catch (IllegalArgumentException ex) { logger.error("Error occur while deleting order with id:{}", orderId, ex); //$NON-NLS-1$ throw new AppODataException("Error occur while deleting order", ex); //$NON-NLS-1$ } }
Example #3
Source File: SalesOrderHeaderProcessor.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@EdmFunctionImport(returnType = @ReturnType(type = Type.ENTITY, isCollection = false), entitySet = "SalesOrders") public SalesOrderHeader calculateNetAmount( @EdmFunctionImportParameter(name = "SoID", facets = @EdmFacets(nullable = false)) final Long soID) throws ODataException { if (soID <= 0L) { throw new ODataException("Invalid SoID"); } Query q = em .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = " + soID + "l"); if (q.getResultList().isEmpty()) { return null; } SalesOrderHeader so = (SalesOrderHeader) q.getResultList().get(0); double amount = 0; for (SalesOrderItem soi : so.getSalesOrderItem()) { amount = amount + (soi.getAmount() * soi.getDiscount() * soi.getQuantity()); } so.setNetAmount(amount); return so; }
Example #4
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 #5
Source File: CampaignService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = EDIT_CAMPAIGN, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.POST) public boolean editCampaign(@EdmFunctionImportParameter(name = START_DATE, type = DATE_TIME) Date startDate, @EdmFunctionImportParameter(name = "endDate", type = DATE_TIME) Date endDate, @EdmFunctionImportParameter(name = "campaignid", type = INT64) Long campaignId) throws AppODataException { final Campaign selectedCampaign = campaignDAO.getById(campaignId); if (selectedCampaign == null) { throw new AppODataException("Campaign does not exist"); //$NON-NLS-1$ } else if (startDate == null || endDate == null || startDate.compareTo(endDate) >= 0) { throw new AppODataException("Incorrect campaign dates"); //$NON-NLS-1$ } selectedCampaign.setStartDate(startDate); selectedCampaign.setEndDate(endDate); campaignDAO.save(selectedCampaign); return true; }
Example #6
Source File: CampaignService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = DELETE_CAMPAIGN, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.DELETE) public boolean deleteCampaign(@EdmFunctionImportParameter(name = CAMPAIGN_ID, type = INT64) Long campaignId) throws AppODataException { try { campaignDAO.delete(campaignId); return true; } catch (IllegalArgumentException ex) { throw new AppODataException("Error occur while deleting campaign", ex); //$NON-NLS-1$ } }
Example #7
Source File: CampaignService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = ADD_CAMPAIGN, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.POST) public boolean addCampaign(@EdmFunctionImportParameter(name = NAME, type = STRING) String campaignName) throws AppODataException { final User user = getLoggedInSfUser(); if (campaignDAO.getByCaseInsensitiveName(campaignName, user) != null) { throw new AppODataException("Campaign with this name already exist"); //$NON-NLS-1$ } final Campaign newCampaign = new Campaign(); newCampaign.setName(campaignName); newCampaign.setOwner(user); campaignDAO.saveNew(newCampaign); new UserPointsDAO().createCampaignUserPoints(newCampaign); return true; }
Example #8
Source File: CampaignService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = STOP_CAMPAIGN, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.POST) public boolean stopCampaign(@EdmFunctionImportParameter(name = CAMPAIGN_ID, type = INT64) Long campaignId) throws AppODataException { final Campaign campaign = campaignDAO.getById(campaignId); if (campaign == null) { throw new AppODataException("Campaign with this name does not exist"); //$NON-NLS-1$ } campaign.setActive(false); campaignDAO.save(campaign); return true; }
Example #9
Source File: CampaignService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = START_CAMPAIGN, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.POST) public boolean startCampaign(@EdmFunctionImportParameter(name = CAMPAIGN_ID, type = INT64) Long campaignId) { final StartCampaignDetails startCampaignDetails = this.canStartCampaign(campaignId); if (startCampaignDetails.getCanBeStarted()) { final Campaign campaign = campaignDAO.getById(campaignId); campaign.setActive(true); campaignDAO.save(campaign); return true; } return false; }
Example #10
Source File: OrderService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = FunctionImportNames.ADD_ORDER, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.POST) public boolean addOrder(@EdmFunctionImportParameter(name = CAMPAIGN_ID, type = INT64) Long campaignId, @EdmFunctionImportParameter(name = USER_ID, type = STRING) String userId, @EdmFunctionImportParameter(name = QUANTITY, type = INT64) Long quantity, @EdmFunctionImportParameter(name = BENEFIT_TYPE_ID, type = INT64) Long benefitTypeId) throws AppODataException { final User loggedInUser = getLoggedInSfUser(); if (!(loggedInUser.getUserId().equals(userId) || UserManager.getIsUserAdmin())) { throw new AppODataException("Unauthorized"); //$NON-NLS-1$ } final User user = userDAO.getByUserId(userId); final Campaign campaign = campaignDAO.getById(campaignId); if (campaign == null) { throw new AppODataException("Incorrect campaign id"); //$NON-NLS-1$ } if (!campaign.getActive()) { throw new AppODataException("The campaign with id " + campaignId + " is not active"); //$NON-NLS-1$ //$NON-NLS-2$ } final OrderDAO orderDAO = new OrderDAO(); final Order userOrder = getOrCreateUserOrder(user, campaign, orderDAO); final BenefitTypeDAO benefitTypeDAO = new BenefitTypeDAO(); final BenefitType benefitType = benefitTypeDAO.getById(benefitTypeId); if (benefitType == null) { throw new AppODataException("Incorrect benefit type id"); //$NON-NLS-1$ } final OrderDetails orderDetails = createOrderDetails(quantity, benefitType); final UserPoints userPoints = getUserPoints(userOrder); final long orderDetailsTotal = calcPointsToAdd(orderDetails); if (userPoints.getAvailablePoints() < orderDetailsTotal) { throw new AppODataException(ORDER_DETAIL_NOT_VALID_MESSAGE); } userOrder.addOrderDetails(orderDetails); new OrderDetailDAO().saveNew(orderDetails); userPoints.subtractPoints(orderDetailsTotal); userPointsDAO.save(userPoints); return true; }
Example #11
Source File: SalesOrderHeaderProcessor.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX)) public Address getAddress( @EdmFunctionImportParameter(name = "SoID", facets = @EdmFacets(nullable = false)) final Long soID) { Query q = em .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = " + soID + "l"); List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q .getResultList(); if (!soList.isEmpty()) { return soList.get(0).getCustomer().getAddress(); } else { return null; } }
Example #12
Source File: SalesOrderHeaderProcessor.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = "CheckATP", returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.GET) public boolean checkATP( @EdmFunctionImportParameter(name = "SoID", facets = @EdmFacets(nullable = false)) final Long soID, @EdmFunctionImportParameter(name = "LiId", facets = @EdmFacets(nullable = false)) final Long lineItemID) { if (soID == 2L) { return false; } else { return true; } }
Example #13
Source File: SalesOrderHeaderProcessor.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @EdmFunctionImport(name = "FindAllSalesOrders", entitySet = "SalesOrders", returnType = @ReturnType( type = Type.ENTITY, isCollection = true)) public List<SalesOrderHeader> findAllSalesOrders( @EdmFunctionImportParameter(name = "DeliveryStatusCode", facets = @EdmFacets(maxLength = 2)) final String status) { Query q = em .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.deliveryStatus = '" + status + "'"); List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q .getResultList(); return soList; }
Example #14
Source File: JPACustomProcessorMock.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = "Method1", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<JPACustomProcessorMock> method1(@EdmFunctionImportParameter(name = "Param1", facets = @EdmFacets( nullable = true, maxLength = 2)) final String param1, final int param2, @EdmFunctionImportParameter(name = "Param3", facets = @EdmFacets(precision = 10, scale = 2)) final double param3) { return new ArrayList<JPACustomProcessorMock>(); }
Example #15
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 #16
Source File: CustomerImageProcessor.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE)) public byte[] getImage( @EdmFunctionImportParameter(name = "CustomerId", facets = @EdmFacets(nullable = false)) Long customerId) { return CustomerImageLoader.loadImage(customerId); }
Example #17
Source File: JPACustomProcessorMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE)) public int method3(@EdmFunctionImportParameter(name = "Param3") final String param3) { return 0; }
Example #18
Source File: JPACustomProcessorMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(name = "Method2", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<JPACustomProcessorMock> method2( @EdmFunctionImportParameter(facets = @EdmFacets(maxLength = 2), name = "Param2") final String param2) { return new ArrayList<JPACustomProcessorMock>(); }
Example #19
Source File: JPACustomProcessorNegativeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX)) public void method17(@EdmFunctionImportParameter(name = "") final int y) { return; }
Example #20
Source File: JPACustomProcessorNegativeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE)) public void method16(@EdmFunctionImportParameter(name = "") final int y) { return; }
Example #21
Source File: JPACustomProcessorNegativeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE)) public int method13(@EdmFunctionImportParameter(name = "") final int y) { return 0; }
Example #22
Source File: BenefitAmountService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 4 votes |
@EdmFunctionImport(name = FunctionImportNames.BENEFIT_AMOUNT, returnType = @ReturnType(type = Type.COMPLEX)) public BenefitsAmount obtainUserBenefitsAmount(@EdmFunctionImportParameter(name = USER_ID, type = EdmType.STRING) String userId) { return odataConnector.getUserBenefitsAmount(userId); }
Example #23
Source File: JPAEdmFunctionImport.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private void buildEdmParameter(final FunctionImport functionImport, final Method method) throws ODataJPAModelException { Annotation[][] annotations = method.getParameterAnnotations(); Class<?>[] parameterTypes = method.getParameterTypes(); List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>(); JPAEdmMapping mapping = null; int j = 0; for (Annotation[] annotationArr : annotations) { Class<?> parameterType = parameterTypes[j++]; for (Annotation element : annotationArr) { if (element instanceof EdmFunctionImportParameter) { EdmFunctionImportParameter annotation = (EdmFunctionImportParameter) element; FunctionImportParameter functionImportParameter = new FunctionImportParameter(); if ("".equals(annotation.name())) { throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_PARAM_NAME_EXP.addContent(method .getDeclaringClass().getName(), method.getName()), null); } else { functionImportParameter.setName(annotation.name()); } functionImportParameter.setType(JPATypeConverter.convertToEdmSimpleType(parameterType, null)); Facets facets = new Facets(); if (annotation.facets().maxLength() > 0) { facets.setMaxLength(annotation.facets().maxLength()); } if (annotation.facets().nullable() == false) { facets.setNullable(false); } else { facets.setNullable(true); } if (annotation.facets().precision() > 0) { facets.setPrecision(annotation.facets().precision()); } if (annotation.facets().scale() >= 0) { facets.setScale(annotation.facets().scale()); } functionImportParameter.setFacets(facets); mapping = new JPAEdmMappingImpl(); mapping.setJPAType(parameterType); functionImportParameter.setMapping((Mapping) mapping); funcImpList.add(functionImportParameter); } } } if (!funcImpList.isEmpty()) { functionImport.setParameters(funcImpList); } }
Example #24
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 #25
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 #26
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(); } }