org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType.Type Java Examples

The following examples show how to use org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType.Type. 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: SalesOrderHeaderProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: CustomerProcessor.java    From cloud-espm-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #3
Source File: UserService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 6 votes vote down vote up
@EdmFunctionImport(name = FunctionImportNames.USER_INFO, entitySet = FunctionImportNames.USER_INFO, returnType = @ReturnType(type = Type.COMPLEX, isCollection = true))
public List<UserInfo> getInfoProfile() throws AppODataException {
	User currentUser = getLoggedInSfUser();
	UserInfo userInfo = new UserInfo();
	UserInfo hrInfo = new UserInfo();
	List<UserInfo> users = new ArrayList<>();

	try {
		userInfo = ECAPIConnector.getInstance().getUserInfoProfile(currentUser.getUserId());
		users.add(userInfo);
		if (currentUser.getHrManager() != null) {
			hrInfo = ECAPIConnector.getInstance().getUserInfoProfile(currentUser.getHrManager().getUserId());
			users.add(hrInfo);
		}
	} catch (IOException | InvalidResponseException ex) {
		throw new AppODataException("Cannot get information about the user", ex); //$NON-NLS-1$
	}

	return users;
}
 
Example #4
Source File: OrderService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 6 votes vote down vote up
@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: SalesOrderProcessor.java    From cloud-espm-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #6
Source File: SalesOrderHeaderProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: SalesOrderHeaderProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: SalesOrderHeaderProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: AdministrationService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: AdministrationService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: OrderService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: UserService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@EdmFunctionImport(name = FunctionImportNames.HR_PHOTO, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.GET)
public String getHrManagerPhoto(@EdmFunctionImportParameter(name = PHOTO_TYPE, type = EdmType.INT32) Integer photoType) throws AppODataException {
	User hrManager = getLoggedInSfUser().getHrManager();
	if (hrManager == null) {
		return ""; //$NON-NLS-1$
	}
	return getUserPhoto(hrManager.getUserId(), photoType);
}
 
Example #13
Source File: UserService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@EdmFunctionImport(name = FunctionImportNames.USER_POINTS, entitySet = FunctionImportEntitySets.USER_POINTS, returnType = @ReturnType(type = Type.ENTITY), httpMethod = HttpMethod.GET)
public UserPoints getCampaignUserPoints(@EdmFunctionImportParameter(name = CAMPAIGN_ID, type = EdmType.INT64) Long campaignId,
		@EdmFunctionImportParameter(name = USER_ID, type = EdmType.STRING) String userId) {
	User currentUser = getLoggedInSfUser();
	if (UserManager.getIsUserAdmin() || currentUser.getUserId().equals(userId)) {
		return new UserPointsDAO().getUserPoints(userId, campaignId);
	}
	throw new IllegalArgumentException("Missing user points for campaign wit id " + campaignId); //$NON-NLS-1$
}
 
Example #14
Source File: CampaignService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: CampaignService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: CampaignService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: CampaignService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: CampaignService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: SalesOrderProcessor.java    From cloud-espm-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #20
Source File: JPACustomProcessorMock.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: UserService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(name = FunctionImportNames.MANAGED_USER_NAMES, entitySet = FunctionImportEntitySets.MANAGED_USER_NAMES, returnType = @ReturnType(type = Type.ENTITY, isCollection = true))
public List<User> getManagedUsers() {
	User currentUser = getLoggedInSfUser();
	return currentUser.getEmployees();
}
 
Example #22
Source File: SalesOrderProcessor.java    From cloud-espm-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * 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 #23
Source File: SalesOrderProcessor.java    From cloud-espm-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * 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 #24
Source File: CustomerReviewProcessor.java    From cloud-espm-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * 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: JPACustomProcessorNegativeMock.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(name = "Method5", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY,
    isCollection = false))
public List<JPACustomProcessorNegativeMock> method5() {
  return null;
}
 
Example #26
Source File: CampaignService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 4 votes vote down vote up
@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 #27
Source File: CampaignService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 4 votes vote down vote up
@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 #28
Source File: JPACustomProcessorNegativeMock.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(entitySet = "MockSet", returnType = @ReturnType(type = Type.SIMPLE, isCollection = true))
public void method6() {
  return;
}
 
Example #29
Source File: JPACustomProcessorNegativeMock.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE, isCollection = true), entitySet = "MockSet")
public JPACustomProcessorNegativeMock method8() {
  return null;
}
 
Example #30
Source File: UserService.java    From cloud-sfsf-benefits-ext with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(name = FunctionImportNames.USER_PHOTO, returnType = @ReturnType(type = Type.SIMPLE, isCollection = false), httpMethod = HttpMethod.GET)
public String getUserPhoto(@EdmFunctionImportParameter(name = PHOTO_TYPE, type = EdmType.INT32) Integer photoType) throws AppODataException {
	return getUserPhoto(getLoggedInSfUser().getUserId(), photoType);
}