Java Code Examples for org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType.Type#SIMPLE

The following examples show how to use org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType.Type#SIMPLE . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 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: 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 11
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 12
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);
}
 
Example 13
Source File: CustomerImageProcessor.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
public byte[] getImage(
    @EdmFunctionImportParameter(name = "CustomerId", facets = @EdmFacets(nullable = false)) Long customerId) {
  return CustomerImageLoader.loadImage(customerId);
}
 
Example 14
Source File: JPACustomProcessorMock.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
public int method3(@EdmFunctionImportParameter(name = "Param3") final String param3) {
  return 0;
}
 
Example 15
Source File: JPACustomProcessorNegativeMock.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
public void method16(@EdmFunctionImportParameter(name = "") final int y) {
  return;
}
 
Example 16
Source File: JPACustomProcessorNegativeMock.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
public int method13(@EdmFunctionImportParameter(name = "") final int y) {
  return 0;
}
 
Example 17
Source File: JPACustomProcessorNegativeMock.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
public JPACustomProcessorMock method12() {
  return null;
}
 
Example 18
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;
}