org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport Java Examples
The following examples show how to use
org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.
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: 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 #3
Source File: JPAEdmFunctionImport.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private FunctionImport buildEdmFunctionImport(final Method method, final EdmFunctionImport edmAnnotationFunctionImport) throws ODataJPAModelException { if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) { FunctionImport functionImport = new FunctionImport(); if ("".equals(edmAnnotationFunctionImport.name())) { functionImport.setName(method.getName()); } else { functionImport.setName(edmAnnotationFunctionImport.name()); } JPAEdmMapping mapping = new JPAEdmMappingImpl(); ((Mapping) mapping).setInternalName(method.getName()); mapping.setJPAType(method.getDeclaringClass()); functionImport.setMapping((Mapping) mapping); functionImport.setHttpMethod(edmAnnotationFunctionImport.httpMethod().name().toString()); buildEdmReturnType(functionImport, method, edmAnnotationFunctionImport); buildEdmParameter(functionImport, method); return functionImport; } return null; }
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: AdministrationService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = RESET_DB, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.POST) public boolean resetDatabase() { cleanDB(); forceSubsequentInitialization(); final BenefitsDataImporter benefitImporter = new BenefitsDataImporter(); try { benefitImporter.importDataFromCSV(BENEFITS_CSV_PATH); } catch (IOException e) { logger.error("Could not insert beneits data into DB", e); //$NON-NLS-1$ return false; } return true; }
Example #11
Source File: AdministrationService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 5 votes |
@EdmFunctionImport(name = UI_CONFIG, returnType = @ReturnType(type = Type.COMPLEX, isCollection = false), httpMethod = HttpMethod.GET) public UIConfig getUIConfigurationData() { final UIConfig config = new UIConfig(); if (UserManager.getIsUserAdmin()) { config.initAdminConfiguration(); } else { config.initEmployeeConfiguration(); } return config; }
Example #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
Source File: JPAEdmFunctionImport.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private FunctionImport buildFunctionImport(final Method method) throws ODataJPAModelException { EdmFunctionImport edmAnnotationFunctionImport = method.getAnnotation(EdmFunctionImport.class); if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) { return buildEdmFunctionImport(method, edmAnnotationFunctionImport); } return null; }
Example #20
Source File: JPACustomProcessorNegativeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE, isCollection = true), entitySet = "MockSet") public JPACustomProcessorNegativeMock method8() { return null; }
Example #21
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 #22
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 #23
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 #24
Source File: CampaignService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 4 votes |
@EdmFunctionImport(name = HR_CAMPAIGNS, entitySet = CAMPAIGNS, returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<Campaign> getHrCampaigns() { final User currentUser = getLoggedInSfUser(); return currentUser.getCampaigns(); }
Example #25
Source File: CampaignService.java From cloud-sfsf-benefits-ext with Apache License 2.0 | 4 votes |
@EdmFunctionImport(name = USER_CAMPAIGNS, entitySet = CAMPAIGNS, returnType = @ReturnType(type = Type.ENTITY, isCollection = true)) public List<Campaign> getUserCampaigns() { final User currentUser = getLoggedInSfUser(); User hr = currentUser.getHrManager(); return hr != null ? hr.getCampaigns() : Collections.<Campaign> emptyList(); }
Example #26
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 #27
Source File: JPAEdmFunctionImport.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private void buildEdmReturnType(final FunctionImport functionImport, final Method method, final EdmFunctionImport edmAnnotationFunctionImport) throws ODataJPAModelException { ReturnType returnType = edmAnnotationFunctionImport.returnType(); if (returnType != null) { org.apache.olingo.odata2.api.edm.provider.ReturnType functionReturnType = new org.apache.olingo.odata2.api.edm.provider.ReturnType(); if (returnType.isCollection()) { functionReturnType.setMultiplicity(EdmMultiplicity.MANY); } else { functionReturnType.setMultiplicity(EdmMultiplicity.ONE); } if (returnType.type() == ReturnType.Type.ENTITY) { String entitySet = edmAnnotationFunctionImport.entitySet(); if ("".equals(entitySet)) { throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_ENTITYSET_EXP, null); } functionImport.setEntitySet(entitySet); } Class<?> methodReturnType = method.getReturnType(); if (methodReturnType == null || "void".equals(methodReturnType.getName())) { throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.addContent(method .getDeclaringClass(), method.getName()), null); } switch (returnType.type()) { case ENTITY: EntityType edmEntityType = null; if (returnType.isCollection() == false) { edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(methodReturnType.getSimpleName()); } else { edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(getReturnTypeSimpleName(method)); } if (edmEntityType == null) { throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null); } functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, edmEntityType.getName())); break; case SIMPLE: EdmSimpleTypeKind edmSimpleTypeKind = JPATypeConverter.convertToEdmSimpleType(methodReturnType, null); functionReturnType.setTypeName(edmSimpleTypeKind.getFullQualifiedName()); break; case COMPLEX: String embeddableTypeName = null; ComplexType complexType = null; boolean exists = false; if (returnType.isCollection() == false) { embeddableTypeName = methodReturnType.getName(); } else { embeddableTypeName = getReturnTypeName(method); } complexType = jpaEdmComplexTypeView.searchEdmComplexType(embeddableTypeName); if (complexType == null) {// This could occure of non JPA Embeddable Types : Extension Scenario List<ComplexType> complexTypeList = schemaView.getEdmSchema().getComplexTypes(); String[] complexTypeNameParts = embeddableTypeName.split("\\."); String complexTypeName = complexTypeNameParts[complexTypeNameParts.length - 1]; for (ComplexType complexType1 : complexTypeList) { if (complexType1.getName().equals(complexTypeName)) { complexType = complexType1; exists = true; break; } } if (exists == false) { throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null); } } functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName())); break; default: break; } functionImport.setReturnType(functionReturnType); } }
Example #28
Source File: JPACustomProcessorNegativeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(name = "Method5", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY, isCollection = false)) public List<JPACustomProcessorNegativeMock> method5() { return null; }
Example #29
Source File: JPACustomProcessorNegativeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@EdmFunctionImport(entitySet = "MockSet", returnType = @ReturnType(type = Type.SIMPLE, isCollection = true)) public void method6() { return; }
Example #30
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; }