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.String
activeLogisticsProvider()
java.lang.String
activePaymentProvider()
boolean
addAttachment(java.lang.String orderId, Attachment attachment)
Adds attachment to the last timeline.boolean
addAttachment(java.lang.String orderId, java.lang.String orderTimelineStep, Attachment attachment)
Adds attachment to the last timeline.private void
addRelations(Order orderUI)
boolean
approve(java.lang.String orderId)
Approves order.java.math.BigDecimal
calculateDelivery(java.lang.String orderId)
Calculates the delivery cost for a specified order.private PackageItem
calculateTotalPackage(java.util.List<CommerceItem> items)
boolean
canAddAttachment(java.lang.String orderId)
Checks if current user can add an Attachment.private boolean
canCancel(OrderStatus status)
boolean
canCancel(java.lang.String orderId)
Checks if order is cancelable.boolean
cancel(java.lang.String orderId)
Cancels an order.boolean
canChangeStatus(java.lang.String orderId)
Checks if current user can change the status of given order.boolean
changeAddress(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> params)
Changes shipping address of the order.boolean
changePaymentMethod(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> paymentMethod)
Changes payment method for the order's payment intent.private Order
changeStatus(java.lang.String orderId, OrderStatus status, OrderStatus nextStatus, SellerType nextStepPerformer)
private boolean
checkTransition(OrderStatus newStatus, OrderStatus oldStatus)
Order
clearPaymentInfo(java.lang.String orderId)
Removes payment information from orderboolean
complete(java.lang.String orderId)
Complete order.Attachment
createInvoiceBuyerToVendor(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)
boolean
deliver(java.lang.String orderId)
Deliver order.private boolean
deliverSuccess(java.lang.String orderId)
CommerceItemRepository
getCommerceItemRepository()
java.lang.String
getInvoiceTemplate(java.lang.String orderId)
This method makes the process of compiling the invoice templateOrderTimeLineBean
getLastOrderTimelineBean(java.lang.String orderId)
This method returns bean.private Address
getOrCreateAddress(java.util.LinkedHashMap<java.lang.String,java.lang.Object> params, Seller buyer)
OrderDTO
getOrder(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.OrderRepository
getRepository()
java.util.Set<Address>
getShippingAddresses()
Get saved shipping addresses.void
handleNotify()
boolean
isUserParticipatesInOrder(java.lang.String orderId, boolean asVendor)
This method checks is database entity belong to other database entity.boolean
mustAddAttachments(java.lang.String orderId)
Checks if attachments must be added on the current step but currently absent.java.lang.String
obtain3DSecureLink(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.PaymentStatus
pay(java.lang.String orderId)
Commits payment for the order.java.lang.String
payout(java.lang.String orderId)
Commits payout.private PaymentStatus
paySuccess(Order order)
boolean
prepareItemsToShipment(java.util.List<CommerceItem> items)
This method does reserve for the items which are paid already.private void
prepareRelations(Order orderUI, Order orderDB)
boolean
removeAttachment(java.lang.String orderId, java.lang.String attachmentName)
Removes attachment from the last timeline.boolean
removeAttachment(java.lang.String orderId, java.lang.String orderTimelineStep, java.lang.String attachmentName)
Removes attachment from the last timeline.boolean
removeCommerceItemFromOrder(java.lang.String orderId, java.lang.String commerceItemId)
This method removes relationship between database entities.void
removeOrder(java.lang.String orderId)
This method removes database entities.void
removeOrdersByIds(java.util.ArrayList<java.lang.String> orderIds)
This method removes a list of database entities.private void
removeRelations(Order orderUI, Order orderDB)
Order
saveOrder(Order order)
This method saves a database entity.Order
saveOrder(java.util.LinkedHashMap<java.lang.String,java.lang.Object> orderAsMap)
This method save an updates of database entity.void
sendOrderConfirmationEmail(java.util.LinkedHashMap<java.lang.String,java.lang.Object> emailData)
Sends a success email for the order.boolean
ship(java.lang.String orderId)
Ships order.private boolean
shipSuccess(java.lang.String orderId)
CommerceItem
updateCommerceItemMetaInfo(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 boolean
updateInventoriesOnShip(java.util.Map<CommerceItem,Inventory> map)
private void
updateItems(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:
handleNotify
in interfaceOrderService
-
getRepository
public OrderRepository getRepository()
- Specified by:
getRepository
in interfaceOrderService
-
activeLogisticsProvider
public java.lang.String activeLogisticsProvider()
- Specified by:
activeLogisticsProvider
in interfaceOrderService
-
activePaymentProvider
public java.lang.String activePaymentProvider()
- Specified by:
activePaymentProvider
in interfaceOrderService
-
getCommerceItemRepository
public CommerceItemRepository getCommerceItemRepository()
- Specified by:
getCommerceItemRepository
in interfaceOrderService
-
getPaginationFilter
public java.util.Deque<java.util.Map<java.lang.String,java.lang.Object>> getPaginationFilter(java.lang.String requestJson)
Description copied from interface:OrderService
This method does calculation for a pages based on the request.- Specified by:
getPaginationFilter
in 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:OrderService
This method does search requests and returns data as list.- Specified by:
getOrders
in 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:OrderService
This method does search requests and returns data as pages.- Specified by:
getOrdersPaged
in 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:OrderService
This method creates a database entity.- Specified by:
createOrder
in interfaceOrderService
- Parameters:
orderAsMap
- map-representation of database entity- Returns:
- database entity
-
createOrder
public java.util.Optional<Order> createOrder(Order order)
Description copied from interface:OrderService
This method creates a database entity.- Specified by:
createOrder
in 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:OrderService
This method save an updates of database entity.- Specified by:
saveOrder
in interfaceOrderService
- Parameters:
orderAsMap
- map-representation of database entity- Returns:
- saved instance of database entity
-
saveOrder
public Order saveOrder(Order order)
Description copied from interface:OrderService
This method saves a database entity.- Specified by:
saveOrder
in interfaceOrderService
- Parameters:
order
- database entity- Returns:
- saved instance of database entity
-
orderCheckout
public java.util.List<OrderDTO> orderCheckout()
Description copied from interface:OrderService
Checkout the orders for the given shopping cart id.- Specified by:
orderCheckout
in 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:OrderService
Sends a success email for the order.This method sends a success email for the order specified by the given email message.
- Specified by:
sendOrderConfirmationEmail
in 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:OrderService
This method make an invoice from buyer to vendor- Specified by:
createInvoiceBuyerToVendor
in 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:OrderService
This method removes database entities.- Specified by:
removeOrder
in 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:OrderService
This method removes a list of database entities.- Specified by:
removeOrdersByIds
in 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:OrderService
This method removes relationship between database entities.- Specified by:
removeCommerceItemFromOrder
in 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:OrderService
Retrieves orders of current user.- Specified by:
getOrdersFromLoggedUser
in interfaceOrderService
- Returns:
- order
-
getOrdersFromLoggedUserByIds
public java.util.LinkedHashSet<OrderDTO> getOrdersFromLoggedUserByIds(java.util.ArrayList<java.lang.String> orderIds)
Description copied from interface:OrderService
Retrieves orders of current user.- Specified by:
getOrdersFromLoggedUserByIds
in 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:OrderService
Gets order by id.- Specified by:
getOrder
in interfaceOrderService
- Parameters:
orderId
- identification for filter and return data- Returns:
- order DTO
-
approve
public boolean approve(java.lang.String orderId)
Description copied from interface:OrderService
Approves order.- Specified by:
approve
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- true on success
-
pay
@Transactional public PaymentStatus pay(java.lang.String orderId)
Description copied from interface:OrderService
Commits payment for the order.- Specified by:
pay
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- status of the payment
-
obtain3DSecureLink
public java.lang.String obtain3DSecureLink(java.lang.String orderId)
Description copied from interface:OrderService
Obtains a payment authorization link;- Specified by:
obtain3DSecureLink
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- the link
-
ship
public boolean ship(java.lang.String orderId)
Description copied from interface:OrderService
Ships order.- Specified by:
ship
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- true on success
-
deliver
public boolean deliver(java.lang.String orderId)
Description copied from interface:OrderService
Deliver order.- Specified by:
deliver
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- true on success
-
payout
public java.lang.String payout(java.lang.String orderId)
Description copied from interface:OrderService
Commits payout.- Specified by:
payout
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- status of the payout
-
complete
public boolean complete(java.lang.String orderId)
Description copied from interface:OrderService
Complete order.- Specified by:
complete
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- true on success
-
cancel
public boolean cancel(java.lang.String orderId)
Description copied from interface:OrderService
Cancels an order.- Specified by:
cancel
in 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:OrderService
This method returns beans as list.- Specified by:
getOrderTimeLine
in 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:OrderService
This method checks is database entity belong to other database entity.- Specified by:
isUserParticipatesInOrder
in 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:OrderService
This method returns bean.- Specified by:
getLastOrderTimelineBean
in 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:OrderService
Adds attachment to the last timeline.- Specified by:
addAttachment
in 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:OrderService
Removes attachment from the last timeline.- Specified by:
removeAttachment
in 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:OrderService
Adds attachment to the last timeline.- Specified by:
addAttachment
in 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:OrderService
Removes attachment from the last timeline.- Specified by:
removeAttachment
in 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:OrderService
Get saved shipping addresses.- Specified by:
getShippingAddresses
in interfaceOrderService
- Returns:
- addresses set
-
canCancel
public boolean canCancel(java.lang.String orderId)
Description copied from interface:OrderService
Checks if order is cancelable.- Specified by:
canCancel
in interfaceOrderService
- Parameters:
orderId
- id of the order- Returns:
- true if order status could be changed to
OrderStatus.CANCELED
orOrderStatus.DENIED
-
canCancel
private boolean canCancel(OrderStatus status)
-
canAddAttachment
public boolean canAddAttachment(java.lang.String orderId)
Description copied from interface:OrderService
Checks if current user can add an Attachment.- Specified by:
canAddAttachment
in 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:OrderService
Changes shipping address of the order.- Specified by:
changeAddress
in 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:OrderService
Changes payment method for the order's payment intent.- Specified by:
changePaymentMethod
in 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:OrderService
Checks if current user can change the status of given order.- Specified by:
canChangeStatus
in interfaceOrderService
- Parameters:
orderId
- order- Returns:
- true if user can change the status
-
mustAddAttachments
public boolean mustAddAttachments(java.lang.String orderId)
Description copied from interface:OrderService
Checks if attachments must be added on the current step but currently absent.- Specified by:
mustAddAttachments
in interfaceOrderService
- Parameters:
orderId
- order- Returns:
- true if attachments must be added
-
prepareItemsToShipment
public boolean prepareItemsToShipment(java.util.List<CommerceItem> items)
Description copied from interface:OrderService
This method does reserve for the items which are paid already.- Specified by:
prepareItemsToShipment
in 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:OrderService
This method makes the process of compiling the invoice template- Specified by:
getInvoiceTemplate
in 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:OrderService
Calculates the delivery cost for a specified order.- Specified by:
calculateDelivery
in 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:OrderService
Removes payment information from order- Specified by:
clearPaymentInfo
in 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:OrderService
Updates the meta information associated with a specific commerce item.- Specified by:
updateCommerceItemMetaInfo
in 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
-
-