Skip to content

Commit

Permalink
Some code beautify
Browse files Browse the repository at this point in the history
Get rid of execution fields in connectors class
Get rid of 4-spaces identation
Shorten lines with sendRequest method calls
Only tokens and passwords are private fields
  • Loading branch information
dolfinus committed May 9, 2019
1 parent 9dfbfff commit 8d38d30
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 164 deletions.
15 changes: 9 additions & 6 deletions src/org/camunda/latera/bss/connectors/HID.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import org.camunda.latera.bss.connectors.hid.Table
import org.camunda.bpm.engine.delegate.DelegateExecution

class HID implements Table {
String url
String user
private String password
XMLRPCServerProxy proxy

HID(DelegateExecution execution) {
def url = execution.getVariable('hidUrl') ?: 'http://hid:10080'
def user = execution.getVariable('hidUser') ?: 'hydra'
def password = execution.getVariable('hidPassword')
this.url = execution.getVariable('hidUrl') ?: 'http://hid:10080'
this.user = execution.getVariable('hidUser') ?: 'hydra'
this.password = execution.getVariable('hidPassword')

this.proxy = new XMLRPCServerProxy(url)
this.proxy.setBasicAuth(user, password)
this.proxy = new XMLRPCServerProxy(this.url)
this.proxy.setBasicAuth(this.user, this.password)
}

Object queryDatabase(String query, Boolean asMap = false, Boolean noLimit = false) {
Expand Down Expand Up @@ -50,7 +53,7 @@ class HID implements Table {
}
}
}

return result
}

Expand Down
75 changes: 46 additions & 29 deletions src/org/camunda/latera/bss/connectors/HOMS.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import org.camunda.latera.bss.utils.JSON
import org.camunda.latera.bss.utils.Base64Converter

class HOMS {
HTTPRestProcessor processor
String url
String user
private String password
HTTPRestProcessor http
DelegateExecution execution
String homsOrderCode
String homsOrderId
Expand All @@ -18,17 +21,19 @@ class HOMS {
this.execution = execution
this.logger = new SimpleLogger(this.execution)

def url = execution.getVariable("homsUrl")
def user = execution.getVariable("homsUser")
def password = execution.getVariable("homsPassword")
this.url = execution.getVariable("homsUrl")
this.user = execution.getVariable("homsUser")
this.password = execution.getVariable("homsPassword")
def supress = execution.getVariable('homsOrderSupress') ?: false

this.processor = new HTTPRestProcessor(baseUrl : url,
user : user,
password : password,
supressRequestBodyLog: supress,
supressResponseBodyLog: supress,
execution : execution)
this.http = new HTTPRestProcessor(
baseUrl : this.url,
user : this.user,
password : this.password,
supressRequestBodyLog: supress,
supressResponseBodyLog: supress,
execution : this.execution
)
this.homsOrderCode = execution.getVariable('homsOrderCode')
this.homsOrderId = execution.getVariable('homsOrderId')
}
Expand All @@ -41,11 +46,13 @@ class HOMS {
]
]
logger.info("/ Creating new order ...")
def result = processor.sendRequest(path: '/api/orders',
supressRequestBodyLog: false,
supressResponseBodyLog: false,
body: body,
'post')
def result = http.sendRequest(
'post',
path: '/api/orders',
supressRequestBodyLog: false,
supressResponseBodyLog: false,
body: body
)
LinkedHashMap order = result.order
homsOrderCode = order.code
homsOrderId = order.id
Expand All @@ -67,9 +74,11 @@ class HOMS {
]
]
logger.info("/ Starting order ...")
def result = this.processor.sendRequest(path: "/api/orders/${homsOrderCode}",
body: body,
'put')
def result = this.http.sendRequest(
'put',
path: "/api/orders/${homsOrderCode}",
body: body
)
logger.info('\\ Order started')
}

Expand All @@ -81,16 +90,20 @@ class HOMS {
]
]
logger.info('/ Saving order data...')
def result = this.processor.sendRequest(path: "/api/orders/${homsOrderCode}",
body: body,
'put')
def result = this.http.sendRequest(
'put',
path: "/api/orders/${homsOrderCode}",
body: body
)
logger.info('\\ Order data saved')
}

void getOrderData() {
logger.info('/ Receiving order data...')
def result = this.processor.sendRequest(path: "/api/orders/${homsOrderCode}",
'get')
def result = this.http.sendRequest(
'get',
path: "/api/orders/${homsOrderCode}"
)
homsOrderId = result.order.id
execution.setVariable('homsOrderId', homsOrderId)

Expand All @@ -112,9 +125,11 @@ class HOMS {
]
]
logger.info("/ Finishing order ...")
def result = this.processor.sendRequest(path: "/api/orders/${homsOrderCode}",
body: body,
'put')
def result = this.http.sendRequest(
'put',
path: "/api/orders/${homsOrderCode}",
body: body
)
logger.info('\\ Order finished')
}

Expand All @@ -128,9 +143,11 @@ class HOMS {
files: JSON.to(files)
]
logger.info("Attaching files to order ${homsOrderId}")
def newFiles = processor.sendRequest(path: '/widget/file_upload',
body: body,
'post')
def newFiles = this.http.sendRequest(
'post',
path: '/widget/file_upload',
body: body
)
if (save) {
def existingFiles = JSON.from(execution.getVariable('homsOrderDataFileList'))
def newList = existingFiles + newFiles
Expand Down
26 changes: 14 additions & 12 deletions src/org/camunda/latera/bss/connectors/Hoper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,39 @@ import org.camunda.bpm.engine.delegate.DelegateExecution

class Hoper {
String url
private String user
String user
private String password
Integer version
HTTPRestProcessor http
DelegateExecution execution
SimpleLogger logger

Hoper(DelegateExecution execution) {
this.execution = execution
this.logger = new SimpleLogger(execution)

this.url = execution.getVariable("hoperUrl") ?: 'http://hoper:3000'
this.version = execution.getVariable("hoperVersion") ?: 2
this.user = execution.getVariable("hydraUser")
this.password = execution.getVariable("hydraPassword")
this.http = new HTTPRestProcessor(baseUrl : this.url,
execution : execution)
this.http = new HTTPRestProcessor(
baseUrl : this.url,
execution : execution
)
}

private def authToken() {
def auth = [
session: [
login : user,
password : password
login : this.user,
password : this.password
]
]
return http.sendRequest('get',
path : "/rest/v${this.version}/login",
body : auth,
supressRequestBodyLog : true,
supressResponseBodyLog : true)?.session?.token
return http.sendRequest(
'get',
path : "/rest/v${this.version}/login",
body : auth,
supressRequestBodyLog : true,
supressResponseBodyLog : true
)?.session?.token
}

private def authBasic() {
Expand Down
35 changes: 20 additions & 15 deletions src/org/camunda/latera/bss/connectors/Imprint.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@ import org.camunda.latera.bss.utils.DateTimeUtil
import org.camunda.bpm.engine.delegate.DelegateExecution

class Imprint {
HTTPRestProcessor processor
String url
String version
private String token
HTTPRestProcessor http
LinkedHashMap headers
DelegateExecution execution
SimpleLogger logger
String locale

Imprint(DelegateExecution execution) {
this.execution = execution
this.logger = new SimpleLogger(execution)

this.locale = execution.getVariable("locale") ?: 'en'
def url = execution.getVariable("imprintUrl")
def version = execution.getVariable("imprintVersion")
def token = execution.getVariable("imprintToken")
this.url = execution.getVariable("imprintUrl")
this.version = execution.getVariable("imprintVersion")
this.token = execution.getVariable("imprintToken")
def headers = [
'X_IMPRINT_API_VERSION' : version,
'X_IMPRINT_API_TOKEN' : token
'X_IMPRINT_API_VERSION' : this.version,
'X_IMPRINT_API_TOKEN' : this.token
]
this.processor = new HTTPRestProcessor(baseUrl : url,
headers : headers,
execution : execution)
this.http = new HTTPRestProcessor(
baseUrl : url,
headers : headers,
execution : execution
)
}

def print(String template, LinkedHashMap data) {
Expand All @@ -39,10 +42,12 @@ class Imprint {
todayFull : DateTimeUtil.format(DateTimeUtil.local(), DateTimeUtil.FULL_DATE_FORMAT, this.locale)
] + data
]
def result = this.processor.sendRequest(path : '/api/print',
body : body,
contentType : 'application/json',
'post')
def result = this.http.sendRequest(
'post',
path : '/api/print',
body : body,
contentType : 'application/json'
)
def file = result
return file
}
Expand Down
6 changes: 3 additions & 3 deletions src/org/camunda/latera/bss/connectors/Mail.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import javax.mail.Message

class MailSender {

private String host
private Integer port
private String user
String host
Integer port
String user
private String password
private Session session
private Message message
Expand Down
13 changes: 8 additions & 5 deletions src/org/camunda/latera/bss/connectors/Odoo.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.camunda.latera.bss.connectors.odoo.types.Country

class Odoo implements Main, Entity, Lead, Customer, Country {
String url
private String user
String user
private String password
private String token
String db
Expand All @@ -30,9 +30,11 @@ class Odoo implements Main, Entity, Lead, Customer, Country {
this.password = execution.getVariable('crmPassword')
this.token = execution.getVariable('crmToken')
this.db = execution.getVariable('crmDatabase') ?: 'odoo'
this.http = new HTTPRestProcessor(baseUrl : url,
contentType : 'application/x-www-form-urlencoded',
execution : execution)
this.http = new HTTPRestProcessor(
baseUrl : url,
contentType : 'application/x-www-form-urlencoded',
execution : execution
)
}

private String authToken() {
Expand All @@ -49,7 +51,8 @@ class Odoo implements Main, Entity, Lead, Customer, Country {
return http.sendRequest(
'get',
path : '/api/auth/token',
query : query)?.access_token?.toString()
query : query
)?.access_token?.toString()
}

private LinkedHashMap authHeader() {
Expand Down
Loading

0 comments on commit 8d38d30

Please sign in to comment.