Class OrderServiceImpl
- java.lang.Object
-
- co.mastermindcms.modules.services.OrderServiceImpl
-
- All Implemented Interfaces:
OrderService
@Service public class OrderServiceImpl extends java.lang.Object implements OrderService
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description OrderServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringactiveLogisticsProvider()java.lang.StringactivePaymentProvider()booleanaddAttachment(java.lang.String orderId, Attachment attachment)Adds attachment to the last timeline.booleanaddAttachment(java.lang.String orderId, java.lang.String orderTimelineStep, Attachment attachment)Adds attachment to the last timeline.private voidaddRelations(Order orderUI)booleanapprove(java.lang.String orderId)Approves order.java.math.BigDecimalcalculateDelivery(java.lang.String orderId)Calculates the delivery cost for a specified order.private PackageItemcalculateTotalPackage(java.util.List<CommerceItem> items)booleancanAddAttachment(java.lang.String orderId)Checks if current user can add an Attachment.private booleancanCancel(OrderStatus status)booleancanCancel(java.lang.String orderId)Checks if order is cancelable.booleancancel(java.lang.String orderId)Cancels an order.booleancanChangeStatus(java.lang.String orderId)Checks if current user can change the status of given order.booleanchangeAddress(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> params)Changes shipping address of the order.booleanchangePaymentMethod(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> paymentMethod)Changes payment method for the order's payment intent.private OrderchangeStatus(java.lang.String orderId, OrderStatus status, OrderStatus nextStatus, SellerType nextStepPerformer)private booleancheckTransition(OrderStatus newStatus, OrderStatus oldStatus)OrderclearPaymentInfo(java.lang.String orderId)Removes payment information from orderbooleancomplete(java.lang.String orderId)Complete order.AttachmentcreateInvoiceBuyerToVendor(java.lang.String orderId)This method make an invoice from buyer to vendorjava.util.Optional<Order>createOrder(Order order)This method creates a database entity.java.util.Optional<Order>createOrder(java.util.LinkedHashMap<java.lang.String,java.lang.Object> orderAsMap)This method creates a database entity.private java.util.List<OrderTimeLineBean>createTimeLineList(java.lang.String orderId)booleandeliver(java.lang.String orderId)Deliver order.private booleandeliverSuccess(java.lang.String orderId)CommerceItemRepositorygetCommerceItemRepository()java.lang.StringgetInvoiceTemplate(java.lang.String orderId)This method makes the process of compiling the invoice templateOrderTimeLineBeangetLastOrderTimelineBean(java.lang.String orderId)This method returns bean.private AddressgetOrCreateAddress(java.util.LinkedHashMap<java.lang.String,java.lang.Object> params, Seller buyer)OrderDTOgetOrder(java.lang.String orderId)Gets order by id.java.util.LinkedHashSet<OrderDTO>getOrders(java.lang.String requestJson)This method does search requests and returns data as list.java.util.List<OrderDTO>getOrdersFromLoggedUser()Retrieves orders of current user.java.util.LinkedHashSet<OrderDTO>getOrdersFromLoggedUserByIds(java.util.ArrayList<java.lang.String> orderIds)Retrieves orders of current user.org.springframework.data.domain.Page<Order>getOrdersPaged(java.lang.String requestJson)This method does search requests and returns data as pages.java.util.List<OrderTimeLineBean>getOrderTimeLine(java.lang.String orderId)This method returns beans as list.java.util.Deque<java.util.Map<java.lang.String,java.lang.Object>>getPaginationFilter(java.lang.String requestJson)This method does calculation for a pages based on the request.OrderRepositorygetRepository()java.util.Set<Address>getShippingAddresses()Get saved shipping addresses.voidhandleNotify()booleanisUserParticipatesInOrder(java.lang.String orderId, boolean asVendor)This method checks is database entity belong to other database entity.booleanmustAddAttachments(java.lang.String orderId)Checks if attachments must be added on the current step but currently absent.java.lang.Stringobtain3DSecureLink(java.lang.String orderId)Obtains a payment authorization link;private java.util.Map<Seller,java.util.List<CommerceItem>>obtainSellerToItemsMap(ShoppingCart cart)java.util.List<OrderDTO>orderCheckout()Checkout the orders for the given shopping cart id.PaymentStatuspay(java.lang.String orderId)Commits payment for the order.java.lang.Stringpayout(java.lang.String orderId)Commits payout.private PaymentStatuspaySuccess(Order order)booleanprepareItemsToShipment(java.util.List<CommerceItem> items)This method does reserve for the items which are paid already.private voidprepareRelations(Order orderUI, Order orderDB)booleanremoveAttachment(java.lang.String orderId, java.lang.String attachmentName)Removes attachment from the last timeline.booleanremoveAttachment(java.lang.String orderId, java.lang.String orderTimelineStep, java.lang.String attachmentName)Removes attachment from the last timeline.booleanremoveCommerceItemFromOrder(java.lang.String orderId, java.lang.String commerceItemId)This method removes relationship between database entities.voidremoveOrder(java.lang.String orderId)This method removes database entities.voidremoveOrdersByIds(java.util.ArrayList<java.lang.String> orderIds)This method removes a list of database entities.private voidremoveRelations(Order orderUI, Order orderDB)OrdersaveOrder(Order order)This method saves a database entity.OrdersaveOrder(java.util.LinkedHashMap<java.lang.String,java.lang.Object> orderAsMap)This method save an updates of database entity.voidsendOrderConfirmationEmail(java.util.LinkedHashMap<java.lang.String,java.lang.Object> emailData)Sends a success email for the order.booleanship(java.lang.String orderId)Ships order.private booleanshipSuccess(java.lang.String orderId)CommerceItemupdateCommerceItemMetaInfo(java.lang.String commerceItemId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> metaInfo)Updates the meta information associated with a specific commerce item.private booleanupdateInventoriesOnShip(java.util.Map<CommerceItem,Inventory> map)private voidupdateItems(Order order, java.util.List<CommerceItem> items)
-
-
-
Field Detail
-
sellerRepository
@Autowired private SellerRepository sellerRepository
-
orderRepository
@Autowired private OrderRepository orderRepository
-
accessManagementService
@Autowired private AccessManagementService accessManagementService
-
inventoryRepository
@Autowired private InventoryRepository inventoryRepository
-
commerceItemRepository
@Autowired private CommerceItemRepository commerceItemRepository
-
commerceItemService
@Autowired private CommerceItemService commerceItemService
-
sequenceGenerator
@Autowired private SequenceGeneratorService sequenceGenerator
-
commerceProperties
@Autowired private CommerceProperties commerceProperties
-
shoppingCartRepository
@Autowired private ShoppingCartRepository shoppingCartRepository
-
shoppingCartService
@Autowired private ShoppingCartService shoppingCartService
-
geoLocationService
@Autowired private GeoLocationService geoLocationService
-
paymentProviderService
@Autowired private PaymentProviderService paymentProviderService
-
logisticsProviderService
@Autowired private LogisticsProviderService logisticsProviderService
-
commonProperties
@Autowired private CommonProperties commonProperties
-
templateLocatorService
@Autowired private TemplateLocatorService templateLocatorService
-
pageRenderService
@Autowired private PageRenderService pageRenderService
-
frameworkOperationService
@Autowired private FrameworkOperationService frameworkOperationService
-
fileManagerService
@Autowired private co.mastermindcms.modules.filestorage.services.FileManagerService fileManagerService
-
emailSenderService
@Autowired private EmailSenderService emailSenderService
-
storageService
@Autowired private MongoStorageService storageService
-
emailProperties
@Autowired private EmailProperties emailProperties
-
mongoTemplate
@Autowired private org.springframework.data.mongodb.core.MongoTemplate mongoTemplate
-
webSocketService
@Autowired private WebSocketService webSocketService
-
mapper
private static final com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Method Detail
-
handleNotify
public void handleNotify()
- Specified by:
handleNotifyin interfaceOrderService
-
getRepository
public OrderRepository getRepository()
- Specified by:
getRepositoryin interfaceOrderService
-
activeLogisticsProvider
public java.lang.String activeLogisticsProvider()
- Specified by:
activeLogisticsProviderin interfaceOrderService
-
activePaymentProvider
public java.lang.String activePaymentProvider()
- Specified by:
activePaymentProviderin interfaceOrderService
-
getCommerceItemRepository
public CommerceItemRepository getCommerceItemRepository()
- Specified by:
getCommerceItemRepositoryin interfaceOrderService
-
getPaginationFilter
public java.util.Deque<java.util.Map<java.lang.String,java.lang.Object>> getPaginationFilter(java.lang.String requestJson)
Description copied from interface:OrderServiceThis method does calculation for a pages based on the request.- Specified by:
getPaginationFilterin interfaceOrderService- Parameters:
requestJson- JSON-object of request contains an instructions for search queries- Returns:
- map-representation of data
-
getOrders
public java.util.LinkedHashSet<OrderDTO> getOrders(java.lang.String requestJson)
Description copied from interface:OrderServiceThis method does search requests and returns data as list.- Specified by:
getOrdersin interfaceOrderService- Parameters:
requestJson- search request- Returns:
- data transport entities as list
-
getOrdersPaged
public org.springframework.data.domain.Page<Order> getOrdersPaged(java.lang.String requestJson)
Description copied from interface:OrderServiceThis method does search requests and returns data as pages.- Specified by:
getOrdersPagedin interfaceOrderService- Parameters:
requestJson- JSON-object of request contains an instructions for search queries- Returns:
- database entities separated to pages
-
createOrder
public java.util.Optional<Order> createOrder(java.util.LinkedHashMap<java.lang.String,java.lang.Object> orderAsMap)
Description copied from interface:OrderServiceThis method creates a database entity.- Specified by:
createOrderin interfaceOrderService- Parameters:
orderAsMap- map-representation of database entity- Returns:
- database entity
-
createOrder
public java.util.Optional<Order> createOrder(Order order)
Description copied from interface:OrderServiceThis method creates a database entity.- Specified by:
createOrderin interfaceOrderService- Parameters:
order- map-representation of database entity- Returns:
- database entity
-
saveOrder
public Order saveOrder(java.util.LinkedHashMap<java.lang.String,java.lang.Object> orderAsMap)
Description copied from interface:OrderServiceThis method save an updates of database entity.- Specified by:
saveOrderin interfaceOrderService- Parameters:
orderAsMap- map-representation of database entity- Returns:
- saved instance of database entity
-
saveOrder
public Order saveOrder(Order order)
Description copied from interface:OrderServiceThis method saves a database entity.- Specified by:
saveOrderin interfaceOrderService- Parameters:
order- database entity- Returns:
- saved instance of database entity
-
orderCheckout
public java.util.List<OrderDTO> orderCheckout()
Description copied from interface:OrderServiceCheckout the orders for the given shopping cart id.- Specified by:
orderCheckoutin interfaceOrderService- Returns:
- the list of OrderDTOs representing the checked out orders
-
sendOrderConfirmationEmail
public void sendOrderConfirmationEmail(java.util.LinkedHashMap<java.lang.String,java.lang.Object> emailData)
Description copied from interface:OrderServiceSends a success email for the order.This method sends a success email for the order specified by the given email message.
- Specified by:
sendOrderConfirmationEmailin interfaceOrderService- Parameters:
emailData- the email message object containing the details of the success email
-
getOrCreateAddress
private Address getOrCreateAddress(java.util.LinkedHashMap<java.lang.String,java.lang.Object> params, Seller buyer)
-
createInvoiceBuyerToVendor
public Attachment createInvoiceBuyerToVendor(java.lang.String orderId)
Description copied from interface:OrderServiceThis method make an invoice from buyer to vendor- Specified by:
createInvoiceBuyerToVendorin interfaceOrderService- Parameters:
orderId- order- Returns:
- value as attachment
-
createTimeLineList
private java.util.List<OrderTimeLineBean> createTimeLineList(java.lang.String orderId)
-
obtainSellerToItemsMap
private java.util.Map<Seller,java.util.List<CommerceItem>> obtainSellerToItemsMap(ShoppingCart cart)
-
updateItems
private void updateItems(Order order, java.util.List<CommerceItem> items)
-
updateInventoriesOnShip
private boolean updateInventoriesOnShip(java.util.Map<CommerceItem,Inventory> map)
-
calculateTotalPackage
private PackageItem calculateTotalPackage(java.util.List<CommerceItem> items)
-
removeOrder
@Transactional public void removeOrder(java.lang.String orderId)
Description copied from interface:OrderServiceThis method removes database entities.- Specified by:
removeOrderin interfaceOrderService- Parameters:
orderId- identification for database entity which will be removed
-
removeOrdersByIds
public void removeOrdersByIds(java.util.ArrayList<java.lang.String> orderIds)
Description copied from interface:OrderServiceThis method removes a list of database entities.- Specified by:
removeOrdersByIdsin interfaceOrderService- Parameters:
orderIds- the list of database entities which will be removed
-
removeCommerceItemFromOrder
@Transactional public boolean removeCommerceItemFromOrder(java.lang.String orderId, java.lang.String commerceItemId)Description copied from interface:OrderServiceThis method removes relationship between database entities.- Specified by:
removeCommerceItemFromOrderin interfaceOrderService- Parameters:
orderId- identification for database entity which will be removedcommerceItemId- identification for database entity which will be updated- Returns:
- the status of the action, whether it was successful or not
-
getOrdersFromLoggedUser
@Transactional public java.util.List<OrderDTO> getOrdersFromLoggedUser()
Description copied from interface:OrderServiceRetrieves orders of current user.- Specified by:
getOrdersFromLoggedUserin interfaceOrderService- Returns:
- order
-
getOrdersFromLoggedUserByIds
public java.util.LinkedHashSet<OrderDTO> getOrdersFromLoggedUserByIds(java.util.ArrayList<java.lang.String> orderIds)
Description copied from interface:OrderServiceRetrieves orders of current user.- Specified by:
getOrdersFromLoggedUserByIdsin interfaceOrderService- Parameters:
orderIds- the list of database entities which will be removed- Returns:
- order
-
getOrder
@Transactional public OrderDTO getOrder(java.lang.String orderId)
Description copied from interface:OrderServiceGets order by id.- Specified by:
getOrderin interfaceOrderService- Parameters:
orderId- identification for filter and return data- Returns:
- order DTO
-
approve
public boolean approve(java.lang.String orderId)
Description copied from interface:OrderServiceApproves order.- Specified by:
approvein interfaceOrderService- Parameters:
orderId- order id- Returns:
- true on success
-
pay
@Transactional public PaymentStatus pay(java.lang.String orderId)
Description copied from interface:OrderServiceCommits payment for the order.- Specified by:
payin interfaceOrderService- Parameters:
orderId- order id- Returns:
- status of the payment
-
obtain3DSecureLink
public java.lang.String obtain3DSecureLink(java.lang.String orderId)
Description copied from interface:OrderServiceObtains a payment authorization link;- Specified by:
obtain3DSecureLinkin interfaceOrderService- Parameters:
orderId- order id- Returns:
- the link
-
ship
public boolean ship(java.lang.String orderId)
Description copied from interface:OrderServiceShips order.- Specified by:
shipin interfaceOrderService- Parameters:
orderId- order id- Returns:
- true on success
-
deliver
public boolean deliver(java.lang.String orderId)
Description copied from interface:OrderServiceDeliver order.- Specified by:
deliverin interfaceOrderService- Parameters:
orderId- order id- Returns:
- true on success
-
payout
public java.lang.String payout(java.lang.String orderId)
Description copied from interface:OrderServiceCommits payout.- Specified by:
payoutin interfaceOrderService- Parameters:
orderId- order id- Returns:
- status of the payout
-
complete
public boolean complete(java.lang.String orderId)
Description copied from interface:OrderServiceComplete order.- Specified by:
completein interfaceOrderService- Parameters:
orderId- order id- Returns:
- true on success
-
cancel
public boolean cancel(java.lang.String orderId)
Description copied from interface:OrderServiceCancels an order.- Specified by:
cancelin interfaceOrderService- Parameters:
orderId- order id- Returns:
- true on success
-
changeStatus
private Order changeStatus(java.lang.String orderId, OrderStatus status, OrderStatus nextStatus, SellerType nextStepPerformer)
-
checkTransition
private boolean checkTransition(OrderStatus newStatus, OrderStatus oldStatus)
-
addRelations
private void addRelations(Order orderUI)
-
deliverSuccess
private boolean deliverSuccess(java.lang.String orderId)
-
paySuccess
private PaymentStatus paySuccess(Order order)
-
shipSuccess
private boolean shipSuccess(java.lang.String orderId)
-
getOrderTimeLine
public java.util.List<OrderTimeLineBean> getOrderTimeLine(java.lang.String orderId)
Description copied from interface:OrderServiceThis method returns beans as list.- Specified by:
getOrderTimeLinein interfaceOrderService- Parameters:
orderId- identification for database entity which related beans list be returned- Returns:
- beans as list
-
isUserParticipatesInOrder
public boolean isUserParticipatesInOrder(java.lang.String orderId, boolean asVendor)Description copied from interface:OrderServiceThis method checks is database entity belong to other database entity.- Specified by:
isUserParticipatesInOrderin interfaceOrderService- Parameters:
orderId- identification for database entity which will be checkedasVendor-true- for checking as vendor,false- if as buyer- Returns:
- value as boolean
-
getLastOrderTimelineBean
public OrderTimeLineBean getLastOrderTimelineBean(java.lang.String orderId)
Description copied from interface:OrderServiceThis method returns bean.- Specified by:
getLastOrderTimelineBeanin interfaceOrderService- Parameters:
orderId- identification for database entity which found last bean and returned- Returns:
- bean
-
addAttachment
public boolean addAttachment(java.lang.String orderId, Attachment attachment)Description copied from interface:OrderServiceAdds attachment to the last timeline.- Specified by:
addAttachmentin interfaceOrderService- Parameters:
orderId- id of the orderattachment- attachment- Returns:
- success or not
-
removeAttachment
public boolean removeAttachment(java.lang.String orderId, java.lang.String attachmentName)Description copied from interface:OrderServiceRemoves attachment from the last timeline.- Specified by:
removeAttachmentin interfaceOrderService- Parameters:
orderId- id of the orderattachmentName- attachment name- Returns:
- success or not
-
addAttachment
public boolean addAttachment(java.lang.String orderId, java.lang.String orderTimelineStep, Attachment attachment)Description copied from interface:OrderServiceAdds attachment to the last timeline.- Specified by:
addAttachmentin interfaceOrderService- Parameters:
orderId- id of the orderorderTimelineStep- step of the timelineattachment- attachment- Returns:
- success or not
-
removeAttachment
public boolean removeAttachment(java.lang.String orderId, java.lang.String orderTimelineStep, java.lang.String attachmentName)Description copied from interface:OrderServiceRemoves attachment from the last timeline.- Specified by:
removeAttachmentin interfaceOrderService- Parameters:
orderId- id of the orderorderTimelineStep- step of the timelineattachmentName- attachment name- Returns:
- success or not
-
getShippingAddresses
public java.util.Set<Address> getShippingAddresses()
Description copied from interface:OrderServiceGet saved shipping addresses.- Specified by:
getShippingAddressesin interfaceOrderService- Returns:
- addresses set
-
canCancel
public boolean canCancel(java.lang.String orderId)
Description copied from interface:OrderServiceChecks if order is cancelable.- Specified by:
canCancelin interfaceOrderService- Parameters:
orderId- id of the order- Returns:
- true if order status could be changed to
OrderStatus.CANCELEDorOrderStatus.DENIED
-
canCancel
private boolean canCancel(OrderStatus status)
-
canAddAttachment
public boolean canAddAttachment(java.lang.String orderId)
Description copied from interface:OrderServiceChecks if current user can add an Attachment.- Specified by:
canAddAttachmentin interfaceOrderService- Parameters:
orderId- order ID- Returns:
- true if the user has rights to add an attachment to the order.
-
changeAddress
@Transactional public boolean changeAddress(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> params)Description copied from interface:OrderServiceChanges shipping address of the order.- Specified by:
changeAddressin interfaceOrderService- Parameters:
orderId- order idparams- params of address- Returns:
- true if successful
-
changePaymentMethod
@Transactional public boolean changePaymentMethod(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> paymentMethod)Description copied from interface:OrderServiceChanges payment method for the order's payment intent.- Specified by:
changePaymentMethodin interfaceOrderService- Parameters:
orderId- order idpaymentMethod- params of a new payment method- Returns:
- true if successful
-
canChangeStatus
public boolean canChangeStatus(java.lang.String orderId)
Description copied from interface:OrderServiceChecks if current user can change the status of given order.- Specified by:
canChangeStatusin interfaceOrderService- Parameters:
orderId- order- Returns:
- true if user can change the status
-
mustAddAttachments
public boolean mustAddAttachments(java.lang.String orderId)
Description copied from interface:OrderServiceChecks if attachments must be added on the current step but currently absent.- Specified by:
mustAddAttachmentsin interfaceOrderService- Parameters:
orderId- order- Returns:
- true if attachments must be added
-
prepareItemsToShipment
public boolean prepareItemsToShipment(java.util.List<CommerceItem> items)
Description copied from interface:OrderServiceThis method does reserve for the items which are paid already.- Specified by:
prepareItemsToShipmentin interfaceOrderService- Parameters:
items- commerce items which will be reserved- Returns:
- true if it successful
-
getInvoiceTemplate
public java.lang.String getInvoiceTemplate(java.lang.String orderId)
Description copied from interface:OrderServiceThis method makes the process of compiling the invoice template- Specified by:
getInvoiceTemplatein interfaceOrderService- Parameters:
orderId- order- Returns:
- compiled invoice template as a string
-
calculateDelivery
public java.math.BigDecimal calculateDelivery(java.lang.String orderId)
Description copied from interface:OrderServiceCalculates the delivery cost for a specified order.- Specified by:
calculateDeliveryin interfaceOrderService- Parameters:
orderId- the unique identifier for the order- Returns:
- the calculated delivery cost as a BigDecimal value
-
clearPaymentInfo
public Order clearPaymentInfo(java.lang.String orderId)
Description copied from interface:OrderServiceRemoves payment information from order- Specified by:
clearPaymentInfoin interfaceOrderService- Parameters:
orderId- the unique identifier for the order- Returns:
- order without payment information
-
updateCommerceItemMetaInfo
public CommerceItem updateCommerceItemMetaInfo(java.lang.String commerceItemId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> metaInfo)
Description copied from interface:OrderServiceUpdates the meta information associated with a specific commerce item.- Specified by:
updateCommerceItemMetaInfoin interfaceOrderService- Parameters:
commerceItemId- The ID of the commerce item to update meta info formetaInfo- A LinkedHashMap containing the new meta information to be updated- Returns:
- The updated CommerceItem with the new meta information
-
-