---
# System prepended metadata

title: mPOS / Tomcat Server / Classes
tags: [mPOS]

---

---
tags: mPOS
---
<style>
/*.mermaid{
margin:-px;
}
#doc{
margin:-px
}*/
</style>

# mPOS / Tomcat Server / Classes

[toc]


## Abstract
### Packages
- `mailman`: Main API endpoint controller; database operation
  - `SCDataService` : WebListener, server initializer, singleton getter/setter
  - `SCDataResource` : Parent class of API endpoint classes
- `packer`: Utility classes: MQTT/External API connection; Printer communication...
- `parcel`: Entity/model

```plantuml
@startuml
allowmixing

actor client
database SC 
frame "mPOS API (Tomcat)" as mposapi {
file  "<<resource>>\nmpos.properties" as resource

package "mailman (Controller)" as controller {
  class "@WebListener\nSCDataService" as SCDataService
  SCDataService "1" --* "many" SCDataResource
  resource <-- SCDataService
   <> dIsDataResource
  SCDataResource <|-- dIsDataResource
  dIsDataResource -- SCFF
  dIsDataResource --- SCEmployee
   () ". . ." as etc
  dIsDataResource -- etc
  SCFF <-l- client
  SCEmployee <-l- client
  
}


SCDataService -l> SC 
package "packer (Utility)" as util {
  
  
  <> usesUtil
  controller .. usesUtil
  model . usesUtil
  usesUtil ..> MQTTHelper
  usesUtil ..> PrinterProxy
  usesUtil ..> ExternalAPI
  usesUtil ..> Packer
  () ". . ." as etc2
  usesUtil ..> etc2
}

package "parcel (Entity)" as model {
  SCEmployee .. Employee
  SCFF .. FF
  () ". . ." as etc3
}
}
@enduml
```



## SCDataResource (Server Context and API Controller)

```plantuml
@startuml
package "SC / mailman"{
  SCDataService -* SCDataResource
  <> dIsDataResource
  <> dIsDataResource2
  <> dIsInTx
  <> dIsTx

  SCDataResource <|-- dIsDataResource
  dIsDataResource --- dIsDataResource2

  dIsDataResource -- SCFF
  dIsDataResource -- SCInstallment
  dIsDataResource -- SCMember
  
  dIsDataResource -- SCRepair
  dIsDataResource -- SCSerialNo
  dIsDataResource -- SCStatus
  dIsDataResource -- SCDailyAccount
  dIsDataResource2 -- SCCollection
  dIsDataResource2 -- SCPR
  dIsDataResource2 -- SCEmployee
  dIsDataResource2 -- SCReceipt
  dIsDataResource2 -- SCProducts
  dIsDataResource -- SCTransaction
  dIsDataResource2 -- SCBargainReason
  dIsDataResource2 -- SCLogging
  
  dIsInTx --o SCTransaction : @Inject
  SCTransaction <|-- dIsTx
  dIsTx -- SCTransactionPurchase
  dIsTx -- SCTransactionCancel
  dIsTx -- SCSO
  dIsTx -- SCTransactionVoid

  'SCReceipt --o SCEmployee : @Inject
  SCEmployee o- SCReceipt : @Inject
  SCCollection -- dIsInTx
  SCReceipt -- dIsInTx
  SCBargainReason -- dIsInTx
  SCProducts -- dIsInTx
  SCLogging -- dIsInTx
  'SCLogging --o SCPR : @Inject
  SCPR o- SCLogging : @Inject

}

@enduml
```



---

## External API

```plantuml
@startuml
package "SC / mailman"{

  class SCDataService {
    ~ getPaymentAPI() : PaymentAPI 
    ~ getTKAPI() : TKAPI
    ~ getWishAPI() : WishAPI
  }
  class SCDataResource
  class SCMember
  class SCPR
  class SCProducts
  <> isDataResource
  
  SCDataResource <|-- isDataResource 
  SCDataService -* SCDataResource
  
  isDataResource -- SCMember
  isDataResource -- SCPR
  isDataResource -- SCProducts
  
}

package "Util / packer"{
  abstract class ExternalAPI {
    +{static} readyPaymentAPI(PaymentAPISetting) : PaymentAPI 
    +{static} readyTKAPI(TKAPISetting) : TKAPI
    +{static} readyWishAPI(WishAPISetting) : WishAPI
  }
  
  <> isAPISetting
  <> inDataService

  abstract class APISetting
  abstract class TKAPISetting
  abstract class PaymentAPISetting
  abstract class WishAPISetting
  class HttpClient<T> {
  - Class<T> returnType
  
  +{static} newClient(String url) : HttpClient<JsonObject>
  +{static} newClient(String url, Class<T>) : HttpClient<T>
	
  }
  
  APISetting <|-- isAPISetting
  
  isAPISetting -- TKAPISetting
  isAPISetting -- PaymentAPISetting
  isAPISetting -- WishAPISetting
  
  ExternalAPI +-- isAPISetting
  ExternalAPI +-left- APISetting
  
  HttpClient --o PaymentAPI
  HttpClient --o TKAPI
  HttpClient --o WishAPI

  PaymentAPI .. ExternalAPI
  TKAPI .. ExternalAPI
  WishAPI .. ExternalAPI
  
  'SCDataService . ExternalAPI
  TKAPISetting -- inDataService
  PaymentAPISetting -- inDataService
  WishAPISetting -- inDataService
  inDataService --o SCDataService
}


@enduml
```

---
## StatusCode
```plantuml
@startuml
package "Util / packer"{
  interface StatusCode {
    + int getResult()
	+ String getMessage()
    + Object getResultObject()
  }

  class OperationStatus implements StatusCode
  class OperationResult<T> implements StatusCode {
    + <T> getResultObject()
  }
  StatusCode --* OperationResult
  StatusCode --* OperationStatus
}


@enduml
```

---

## Printer

```plantuml
@startuml
package "Util / packer"{
  class PrinterProxy
  class MQTTHelper

  MQTTHelper -* PrinterProxy

}

package "SC / mailman"{
  class SCTransaction
  class SCDataService {
    ~ getMQTTMessenger() : MQTTHelper 
    ~ getPrinterProxy() : PrinterProxy
  }
  class SCDataResource
  PrinterProxy --o SCDataService
  MQTTHelper --o SCDataService
  SCDataService -* SCDataResource
  SCTransaction -left|> SCDataResource
}


@enduml
```


---
---
---
---
---
---
---
---
---
---

## APIEndpoint (refactor proposal) (OBSOLETE, kept for future reference)

### Problem
- Current structure uses controller for both API endpoint entry and business logic
- Difficult to maintain and highly coupled

### Suggested changes
- Seperate endpoint and SC data manipulation
- Use CDI for dependency between controller and business logic

```plantuml
@startuml
allowmixing
left to right direction

rectangle APIEndpoint {
  class "@Path('/')\nAPIEndpoint" as clAPIEndpoint {
    @Path("collect")
    public Collect getCollectController() ;

    @Path("employee")
    public Employee getEmployeeController() ;

    @Path("ff")
    public FF getFFController() ;

    @Path("installment")
    public Installment getInstallmentController() ;

    @Path("member")
    public Member getMemberController() ;

    @Path("pr")
    public PR getPRController() ;

    @Path("product")
    public Product getProductController() ;

    @Path("invoice")
    public Receipt getReceiptController() ;

    @Path("repair")
    public Repair getRepairController() ;

    @Path("status")
    public Status getStatusController() ;

    @Path("transaction")
    public Transaction getTransactionController() ;
  }
  
  class Controller {
    ~handler(T response): Response
    ~handler(StatusCode status): Response
  }
  
  clAPIEndpoint +- Controller
  
  <> isController
  <> isController1
  <> isController2
  Controller <|-- isController
  isController --- isController1
  isController --- isController2
  isController1 --- Collect
  isController1 --- Employee
  isController1 --- FF
  isController1 --- Installment
  isController1 --- Member
  isController1 --- PR
  isController1 --- Product
  isController2 --- Receipt
  isController2 --- Repair
  isController2 --- Status
  isController2 --- Transaction
  isController1 --- SO
}

<> inTx
Transaction -- inTx

rectangle SCDataResource {
  Collect --* SCCollection
  Employee --* SCEmployee
  FF --* SCFF
  Installment --* SCInstallment
  Member --* SCMember
  PR --* SCPR
  Product --* SCProduct
  Receipt ---* SCSequential
  Repair --* SCRepair
  Status --* SCStatus
  inTx --* SCSequential
  inTx --* SCDailyAccount
  inTx --* SCBargainReason
  inTx --* SCTransactionPurchase
  inTx --* SCTransactionVoid
  inTx --* SCTransactionCancel
  SO --* SCSO 
}

@enduml
```
![](https://i.imgur.com/UpaxU4Z.png)


![](https://i.imgur.com/WToaefD.png)
