Package org.cyclos.impl.marketplace
Class OrderServiceImpl
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractNetworkedServerComponent
-
- org.cyclos.impl.BaseServiceImpl
-
- org.cyclos.impl.CRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
- org.cyclos.impl.marketplace.OrderServiceImpl
-
- All Implemented Interfaces:
CRUDServiceLocal<Order,OrderDTO,OrderData,OrderDataParams>,OrderServiceLocal,CRUDService<OrderDTO,OrderData,OrderDataParams>,CRUDWithConfirmationPasswordService<OrderDTO,OrderData,OrderDataParams>,OrderService,Service
@Service public class OrderServiceImpl extends CRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams> implements OrderServiceLocal
implementation forOrderService
-
-
Field Summary
-
Fields inherited from class org.cyclos.impl.CRUDServiceImpl
$, ATTR_CURRENT_COPY, cacheHandler, dtoClass, entityClass, extensionPointService, idPath, internalNamePath, namePath, ownerEntityIdPath, ownerEntityPath, ownerEntityPropertyName, richTextHandler, withConfirmationPassword
-
Fields inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
authHandler, conversionHandler, customFieldValueHandler, entityManagerHandler, groupsHandler, productsHandler, restBeanPropertyMapping, userLocatorHandler
-
Fields inherited from class org.cyclos.impl.AbstractServerComponent
accountHandler, configurationHandler, dataTranslationHandler, notificationHandler, profileFieldHandler, transactionHandler, translationHandler
-
-
Constructor Summary
Constructors Constructor Description OrderServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OrderStatusaccept(AcceptOrderParams params)Accepts the given order, which should be in eitherOrderStatus.PENDING_BUYERorOrderStatus.PENDING_SELLERstatus, and needs the delivery price to be already set.intaddToCart(BasicAdVO adVO, BigDecimal quantity)Adds the given product to the logged user's shopping cart, returning the total count of ads in the cart.
When the given quantity is null, the minimum allowed quantity on the shopping cart for the given product is assumedShoppingCartDTOadjustAndGetMyCart()Returns the current logged user's shopping cart, adjusting all quantitiesOrderDataadjustShoppingCartAndGetData(OrderVO vo)Perform adjustments to the shopping cart quantities and returns the data for itintcancelOrdersInCurrencies(User user, Collection<Currency> currencies)Cancels all pending orders which are linked to the given currenciesintcancelWithReservedAmount(UserAccount account)Cancels all pending orders which have amount reserved on the given accountvoidcheckCartStock(UserLocatorVO sellerVO, CurrencyVO currencyVO)Checks that all items on the given cart are still on stockShoppingCartCheckoutResultcheckout(ShoppingCartCheckoutParams dto)Checks out the logged user's shopping cart with the given seller and currency, checking the confirmation password (if any), and reserving the amount when the delivery price is previously known (otherwise, the buyer still needs to confirm before the payment is done).intcountCartItems()Returns the total number of items in the logged user's shopping cartIntegercountPending(User user, boolean asSeller, OrderStatus status, Date since)Counts pending orders for the current logged user as either seller or buyer, since the given time, or all time if nullFileInfoexportOrder(ExportFormatVO formatVO, OrderVO orderVO)Exports the given order to fileOrderfindByOrderNumber(String orderNumber)Returns an order by order number, or throwsEntityNotFoundExceptionif not foundOrderDatagetCheckoutData(UserLocatorVO sellerVO, CurrencyVO currencyVO)Returns data for checkout the cart items of the given seller and currencyprotected OrderDatagetData(Order order)Returns details data for the given entityprotected Object[]getExcludedPropertiesToEntity(OrderDTO dto)May be overridden in order to exclude properties when converting the given DTO to entityShoppingCartDTOgetMyCart()Returns the current logged user's shopping cart, without adjusting any quantityOrderDatagetOrderData(OrderVO vo)Returns data of an orderlonggetOrderId(OrderVO order)Return the id of the given order only if the logged user can see the order.OrderSearchDatagetSearchData(@NotNull UserLocatorVO locator, boolean sales)Returns data for searching orders / salesbooleanhasPurchases(User user)Returns whether the given user has ever finished a purchasebooleanhasSales(User user)Returns whether the given user has ever finished a salevoidinitialize()intmodifyQuantityOnCart(BasicAdVO adVO, BigDecimal quantity)Updates the quantity for the given product on the logged user's shopping cart returning the total count of ads in the cart.OrdernewEntity(OrderDataParams params)Should be implemented in order to instantiate a new entity based on the given context parametersprotected voidonAfterSave(Order entity, Order currentCopy, Object dataFromOnBeforeSave)May be overridden in order to perform custom logic after saving an entityprotected ObjectonBeforeSave(Order order, Order currentCopy)May be overridden in order to perform custom logic before saving an entity.protected voidregisterNetworkMappings(NetworkPathRegistry networkPathRegistry)Needs to be overridden by subclasses to register the path up to the networkvoidreject(RejectOrderParams params)Rejects the given orderintremoveCart(UserLocatorVO sellerVO, CurrencyVO currencyVO)Removes the logged user's shopping cart for the given seller and currency returning the remaining count of ads in the cartintremoveCartById(Long id)Same asCRUDService.remove(Long)but returning the total count of items present the whole shopping cartintremoveCartItem(BasicAdVO adVO)Removes the given product from the logged user's shopping cart returning the remaining count of ads in the cart.protected ValidatorresolveValidator(OrderDTO dto)Page<OrderVO>search(OrderQuery params)Searches for orders based onOrderQueryvoidsetDeliveryMethod(SetDeliveryMethodParams params)Updates the delivery method information of an order when it is on theOrderStatus.PENDING_SELLERstatus and there is no delivery information yet.LongsubmitToBuyer(OrderDTO dto)Submits the given order for buyer approvalOrderDTOtoDTO(Order entity)Converts the given entity in a DTO, handling theCRUDServiceImpl.subClassMappings()mappings for subclassesOrdertoEntity(OrderDTO dto)Converts the given DTO in an entity, handling theCRUDServiceImpl.subClassMappings()mappings for subclasses-
Methods inherited from class org.cyclos.impl.CRUDServiceImpl
addCustomInternalNameValidations, addCustomNameValidations, checkConfirmationPassword, doRemove, find, findAll, from, getConfirmationPasswordInput, getConfirmationPasswordInputForRemove, getData, getDataForNew, getDeviceConfirmationParams, getEntityClass, getEntityInternalNameKey, getExcludedPropertiesToDTO, getNameLabel, getUniqueInternalNameQuery, getUniqueNameQuery, isEntityInternalNameRequired, isNameRequired, load, logEntity, onAfterRemove, onBeforeRemove, preProcessCurrentCopy, remove, remove, removeAll, removeAll, removeAllWithConfirmationPassword, removeWithConfirmationPassword, resolveDTOType, resolveEntityType, resolveExtensionPointAccessor, save, saveOrder, saveSkippingEntityLog, saveWithConfirmationPassword, shouldCheckConfirmationPassword, subClassMappings, validate
-
Methods inherited from class org.cyclos.impl.BaseServiceImpl
initializeNetworkMappings
-
Methods inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
canManage, checkManagesUser, checkPermission, checkRelatesToUser, checkValue, clearAlreadyValidated, getBaseEntityManagerHandler, getConfiguration, getLoggedBasicUser, getLoggedUser, getProducts, getTranslatedName, getTranslatedValue, hasPermission, hasValue, inSameNetwork, inSameNetworkOrGlobal, isAdmin, isAlreadyValidated, isBroker, isGlobalAdmin, isGlobalAdminInNetwork, isGuest, isLoggedIn, isMember, isMemberOnly, isNetworkAdmin, isOperator, isRelatedToUser, isSystem, isUserManager, isUserManagerOf, message, message, permission, permission, permissionOptionalValue, permissionOptionalValue, setAlreadyValidated, toDate, toDateTime, validate
-
Methods inherited from class org.cyclos.impl.AbstractServerComponent
dataTranslationProxy, dataTranslationProxy, delete, detach, doDataTranslationProxy, find, flush, from, getApplicationContext, getFormatter, getFormatter, getFormatter, getLogger, getRemoteAddress, getSessionData, mailContentBuilder, message, message, persist, processBatch, processBatch, refresh, remove, selectFrom, subQuery, update
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cyclos.services.CRUDService
getData, getDataForNew, load, remove, removeAll, save
-
Methods inherited from interface org.cyclos.impl.CRUDServiceLocal
find, findAll, getEntityClass, remove, removeAll, saveEntity, saveSkippingEntityLog, validate
-
-
-
-
Method Detail
-
accept
public OrderStatus accept(AcceptOrderParams params) throws FrameworkException, TransferException, PasswordException
Description copied from interface:OrderServiceAccepts the given order, which should be in eitherOrderStatus.PENDING_BUYERorOrderStatus.PENDING_SELLERstatus, and needs the delivery price to be already set. When the buyer hasn't yet chosen a payment type, it is required now. Also, when no amount was reserved, the confirmation password will be checked before performing the actual payment.- Specified by:
acceptin interfaceOrderService- Throws:
PasswordException- The given confirmation password is invalidIllegalActionException- The given order is not in eitherOrderStatus.PENDING_BUYERorOrderStatus.PENDING_SELLERstatusTransferException- When there was a problem while reserving the amount, like there is no available balanceFrameworkException
-
addToCart
public int addToCart(BasicAdVO adVO, BigDecimal quantity) throws FrameworkException, OutOfStockException, CannotBuyException
Description copied from interface:OrderServiceAdds the given product to the logged user's shopping cart, returning the total count of ads in the cart.
When the given quantity is null, the minimum allowed quantity on the shopping cart for the given product is assumed- Specified by:
addToCartin interfaceOrderService- Throws:
OutOfStockException- When the given quantity is greater than the available stockFrameworkExceptionCannotBuyException
-
adjustAndGetMyCart
public ShoppingCartDTO adjustAndGetMyCart() throws FrameworkException
Description copied from interface:OrderServiceReturns the current logged user's shopping cart, adjusting all quantities- Specified by:
adjustAndGetMyCartin interfaceOrderService- Throws:
FrameworkException
-
adjustShoppingCartAndGetData
public OrderData adjustShoppingCartAndGetData(OrderVO vo) throws FrameworkException
Description copied from interface:OrderServicePerform adjustments to the shopping cart quantities and returns the data for it- Specified by:
adjustShoppingCartAndGetDatain interfaceOrderService- Throws:
FrameworkException
-
cancelOrdersInCurrencies
public int cancelOrdersInCurrencies(User user, Collection<Currency> currencies)
Description copied from interface:OrderServiceLocalCancels all pending orders which are linked to the given currencies- Specified by:
cancelOrdersInCurrenciesin interfaceOrderServiceLocal
-
cancelWithReservedAmount
public int cancelWithReservedAmount(UserAccount account)
Description copied from interface:OrderServiceLocalCancels all pending orders which have amount reserved on the given account- Specified by:
cancelWithReservedAmountin interfaceOrderServiceLocal
-
checkCartStock
public void checkCartStock(UserLocatorVO sellerVO, CurrencyVO currencyVO) throws FrameworkException, OutOfStockException
Description copied from interface:OrderServiceChecks that all items on the given cart are still on stock- Specified by:
checkCartStockin interfaceOrderService- Throws:
FrameworkExceptionOutOfStockException
-
checkout
public ShoppingCartCheckoutResult checkout(ShoppingCartCheckoutParams dto)
Description copied from interface:OrderServiceChecks out the logged user's shopping cart with the given seller and currency, checking the confirmation password (if any), and reserving the amount when the delivery price is previously known (otherwise, the buyer still needs to confirm before the payment is done).- Specified by:
checkoutin interfaceOrderService- Returns:
- A result containing the order and the remaining webshop ads added to the shopping cart.
-
countCartItems
public int countCartItems() throws FrameworkExceptionDescription copied from interface:OrderServiceReturns the total number of items in the logged user's shopping cart- Specified by:
countCartItemsin interfaceOrderService- Throws:
FrameworkException
-
countPending
public Integer countPending(User user, boolean asSeller, OrderStatus status, Date since)
Description copied from interface:OrderServiceLocalCounts pending orders for the current logged user as either seller or buyer, since the given time, or all time if null- Specified by:
countPendingin interfaceOrderServiceLocal
-
exportOrder
public FileInfo exportOrder(ExportFormatVO formatVO, OrderVO orderVO) throws FrameworkException
Description copied from interface:OrderServiceExports the given order to file- Specified by:
exportOrderin interfaceOrderService- Throws:
FrameworkException
-
findByOrderNumber
public Order findByOrderNumber(String orderNumber)
Description copied from interface:OrderServiceLocalReturns an order by order number, or throwsEntityNotFoundExceptionif not found- Specified by:
findByOrderNumberin interfaceOrderServiceLocal
-
getCheckoutData
public OrderData getCheckoutData(UserLocatorVO sellerVO, CurrencyVO currencyVO)
Description copied from interface:OrderServiceReturns data for checkout the cart items of the given seller and currency- Specified by:
getCheckoutDatain interfaceOrderService
-
getMyCart
public ShoppingCartDTO getMyCart()
Description copied from interface:OrderServiceReturns the current logged user's shopping cart, without adjusting any quantity- Specified by:
getMyCartin interfaceOrderService
-
getOrderData
public OrderData getOrderData(OrderVO vo) throws FrameworkException
Description copied from interface:OrderServiceReturns data of an order- Specified by:
getOrderDatain interfaceOrderService- Throws:
FrameworkException
-
getOrderId
public long getOrderId(OrderVO order) throws FrameworkException
Description copied from interface:OrderServiceReturn the id of the given order only if the logged user can see the order.- Specified by:
getOrderIdin interfaceOrderService- Throws:
FrameworkException
-
getSearchData
public OrderSearchData getSearchData(@NotNull @NotNull UserLocatorVO locator, boolean sales) throws FrameworkException
Description copied from interface:OrderServiceReturns data for searching orders / sales- Specified by:
getSearchDatain interfaceOrderService- Throws:
FrameworkException
-
hasPurchases
public boolean hasPurchases(User user)
Description copied from interface:OrderServiceLocalReturns whether the given user has ever finished a purchase- Specified by:
hasPurchasesin interfaceOrderServiceLocal
-
hasSales
public boolean hasSales(User user)
Description copied from interface:OrderServiceLocalReturns whether the given user has ever finished a sale- Specified by:
hasSalesin interfaceOrderServiceLocal
-
initialize
@PostConstruct public void initialize()
-
modifyQuantityOnCart
public int modifyQuantityOnCart(BasicAdVO adVO, BigDecimal quantity) throws FrameworkException, IllegalActionException, OutOfStockException
Description copied from interface:OrderServiceUpdates the quantity for the given product on the logged user's shopping cart returning the total count of ads in the cart.- Specified by:
modifyQuantityOnCartin interfaceOrderService- Throws:
IllegalActionException- When the given ad is not in the logged user's shopping cartOutOfStockException- When the new quantity is greater than the available stockFrameworkException
-
newEntity
public Order newEntity(OrderDataParams params)
Description copied from class:CRUDServiceImplShould be implemented in order to instantiate a new entity based on the given context parameters- Specified by:
newEntityin interfaceCRUDServiceLocal<Order,OrderDTO,OrderData,OrderDataParams>- Specified by:
newEntityin classCRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
reject
public void reject(RejectOrderParams params) throws FrameworkException
Description copied from interface:OrderServiceRejects the given order- Specified by:
rejectin interfaceOrderService- Throws:
IllegalActionException- When the given order is not in eitherOrderStatus.PENDING_BUYERorOrderStatus.PENDING_SELLERstatuses.FrameworkException
-
removeCart
public int removeCart(UserLocatorVO sellerVO, CurrencyVO currencyVO)
Description copied from interface:OrderServiceRemoves the logged user's shopping cart for the given seller and currency returning the remaining count of ads in the cart- Specified by:
removeCartin interfaceOrderService
-
removeCartById
public int removeCartById(Long id) throws EntityNotFoundException, DataAccessException, ValidationException
Description copied from interface:OrderServiceSame asCRUDService.remove(Long)but returning the total count of items present the whole shopping cart- Specified by:
removeCartByIdin interfaceOrderService- Throws:
EntityNotFoundExceptionDataAccessExceptionValidationException- See Also:
CRUDService.remove(java.lang.Long)
-
removeCartItem
public int removeCartItem(BasicAdVO adVO) throws FrameworkException
Description copied from interface:OrderServiceRemoves the given product from the logged user's shopping cart returning the remaining count of ads in the cart.- Specified by:
removeCartItemin interfaceOrderService- Throws:
IllegalActionException- When the given ad is not in the logged user's shopping cartFrameworkException
-
search
public Page<OrderVO> search(OrderQuery params)
Description copied from interface:OrderServiceSearches for orders based onOrderQuery- Specified by:
searchin interfaceOrderService
-
setDeliveryMethod
public void setDeliveryMethod(SetDeliveryMethodParams params) throws FrameworkException
Description copied from interface:OrderServiceUpdates the delivery method information of an order when it is on theOrderStatus.PENDING_SELLERstatus and there is no delivery information yet. Afterwards, the new status will beOrderStatus.PENDING_BUYERfor final approval.- Specified by:
setDeliveryMethodin interfaceOrderService- Throws:
IllegalActionException- When the referenced order is not on theOrderStatus.PENDING_SELLERstatus or already has delivery informationFrameworkException
-
submitToBuyer
public Long submitToBuyer(OrderDTO dto) throws FrameworkException
Description copied from interface:OrderServiceSubmits the given order for buyer approval- Specified by:
submitToBuyerin interfaceOrderService- Throws:
FrameworkException
-
toDTO
public OrderDTO toDTO(Order entity)
Description copied from class:CRUDServiceImplConverts the given entity in a DTO, handling theCRUDServiceImpl.subClassMappings()mappings for subclasses- Specified by:
toDTOin interfaceCRUDServiceLocal<Order,OrderDTO,OrderData,OrderDataParams>- Overrides:
toDTOin classCRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
toEntity
public Order toEntity(OrderDTO dto)
Description copied from class:CRUDServiceImplConverts the given DTO in an entity, handling theCRUDServiceImpl.subClassMappings()mappings for subclasses- Specified by:
toEntityin interfaceCRUDServiceLocal<Order,OrderDTO,OrderData,OrderDataParams>- Overrides:
toEntityin classCRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
getData
protected OrderData getData(Order order)
Description copied from class:CRUDServiceImplReturns details data for the given entity- Specified by:
getDatain classCRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
getExcludedPropertiesToEntity
protected Object[] getExcludedPropertiesToEntity(OrderDTO dto)
Description copied from class:CRUDServiceImplMay be overridden in order to exclude properties when converting the given DTO to entity- Overrides:
getExcludedPropertiesToEntityin classCRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
onAfterSave
protected void onAfterSave(Order entity, Order currentCopy, Object dataFromOnBeforeSave)
Description copied from class:CRUDServiceImplMay be overridden in order to perform custom logic after saving an entity- Overrides:
onAfterSavein classCRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
onBeforeSave
protected Object onBeforeSave(Order order, Order currentCopy)
Description copied from class:CRUDServiceImplMay be overridden in order to perform custom logic before saving an entity. Any returned value will be passed to theCRUDServiceImpl.onAfterSave(BaseEntity, BaseEntity, Object)method- Overrides:
onBeforeSavein classCRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
registerNetworkMappings
protected void registerNetworkMappings(NetworkPathRegistry networkPathRegistry)
Description copied from class:BaseServiceImplNeeds to be overridden by subclasses to register the path up to the network- Specified by:
registerNetworkMappingsin classBaseServiceImpl
-
resolveValidator
protected Validator resolveValidator(OrderDTO dto)
- Specified by:
resolveValidatorin classCRUDServiceImpl<Order,QOrder,OrderDTO,OrderData,OrderDataParams>
-
-