-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
209 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.camunda.latera.bss.connectors.hoper.hydra | ||
|
||
import org.camunda.latera.bss.utils.StringUtil | ||
|
||
trait Entity { | ||
LinkedHashMap getEntityDefaultParams() { | ||
return [:] | ||
} | ||
|
||
LinkedHashMap getEntityParamsMap(LinkedHashMap params) { | ||
return [:] | ||
} | ||
|
||
LinkedHashMap getEntityParams(LinkedHashMap input) { | ||
def params = getEntityDefaultParams() + input | ||
def where = getEntityParamsMap(params) | ||
return getEntityParamsMap(params) | ||
} | ||
|
||
LinkedHashMap getEntity(def type, def id) { | ||
def result = null | ||
try { | ||
result = hoper.sendRequest( | ||
'get', | ||
path : "${type.parent}/${type.plural}/${id}" | ||
)?."${type.one}" | ||
} catch (Exception e) { | ||
logger.error(e) | ||
} | ||
return result | ||
} | ||
|
||
LinkedHashMap createEntity(def type, LinkedHashMap params) { | ||
def result = null | ||
try { | ||
logger.info("Creating ${type.one} with params ${params}") | ||
result = hoper.sendRequest( | ||
'post', | ||
path : "${type.parent}/${type.plural}", | ||
body : ["${type.one}": params] | ||
)?."${type.one}" | ||
logger.info(" ${StringUtil.capitalize(type.one.toUppercase} was created successfully!") | ||
} catch (Exception e) { | ||
logger.error(" Error while creating ${type.one}") | ||
logger.error(e) | ||
} | ||
return result | ||
} | ||
|
||
LinkedHashMap updateEntity(def type, def id, LinkedHashMap params) { | ||
def result = null | ||
try { | ||
logger.info("Updating ${type.one} id ${id} with params ${params}") | ||
result = hoper.sendRequest( | ||
'put', | ||
path : "${type.parent}/${type.plural}/${id}", | ||
body : ["${type.one}": params] | ||
)?."${type.one}" | ||
logger.info(" ${StringUtil.capitalize(type.one.toUppercase} was updated successfully!") | ||
} catch (Exception e) { | ||
logger.error(" Error while updating ${type.one}") | ||
logger.error(e) | ||
} | ||
return result | ||
} | ||
|
||
Boolean deleteEntity(def type, def id) { | ||
try { | ||
logger.info("Deleting ${type.one} id ${id}") | ||
hoper.sendRequest( | ||
'delete', | ||
path : "${type.parent}/${type.plural}/${id}" | ||
) | ||
logger.info(" ${StringUtil.capitalize(type.one.toUppercase} was deleted successfully!") | ||
return true | ||
} catch (Exception e) { | ||
logger.error(" Error while deleting ${type.one}") | ||
logger.error(e) | ||
return false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.camunda.latera.bss.connectors.hoper.hydra | ||
|
||
trait Main { | ||
LinkedHashMap nvlParams(LinkedHashMap input) { | ||
def params = [:] | ||
input.each { key, value -> | ||
if (value != null) { | ||
params[key] = value | ||
} | ||
} | ||
|
||
return params | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/org/camunda/latera/bss/connectors/hoper/hydra/Person.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package org.camunda.latera.bss.connectors.hoper.hydra | ||
|
||
trait Person { | ||
private static LinkedHashMap PERSON_ENTITY_TYPE = [ | ||
parent : 'subjects', | ||
one : 'person', | ||
plural : 'persons' | ||
] | ||
|
||
def getPersonEntityType() { | ||
return PERSON_ENTITY_TYPE | ||
} | ||
|
||
LinkedHashMap getPersonDefaultParams() { | ||
return [ | ||
firstName : null, | ||
secondName : null, | ||
lastName : null, | ||
opfId : null, | ||
sexId : null, | ||
inn : null, | ||
docTypeId : null, | ||
docSerial : null, | ||
docNumber : null, | ||
docDate : null, | ||
docDepartment : null, | ||
docAuthor : null, | ||
birthDate : null, | ||
birthPlace : null, | ||
rem : null, | ||
groupId : null, | ||
stateId : null | ||
//firmId : getFirmId() | ||
] | ||
} | ||
|
||
LinkedHashMap getPersonParamsMap(LinkedHashMap params, LinkedHashMap additionalParams = [:]) { | ||
def result = [ | ||
vc_first_name : params.firstName, | ||
vc_second_name : params.secondName, | ||
vc_surname : params.lastName, | ||
n_opf_id : params.opfId, | ||
n_sex_id : params.sexId, | ||
vc_inn : params.inn, | ||
vc_doc_serial : params.docSerial, | ||
vc_doc_no : params.docNumber, | ||
d_doc : params.docDate, | ||
vc_doc_department : params.docDepartment, | ||
vc_document : params.docAuthor, | ||
d_birth : params.birthDate, | ||
vc_birth_place : params.birthPlace, | ||
vc_pens_insurance : params.pensInsurance, | ||
vc_med_insurance : params.medInsurance, | ||
vc_rem : params.rem, | ||
n_subj_state_id : params.stateId, | ||
n_firm_id : params.firmId, | ||
t_tags : params.tags | ||
] | ||
if (additionalParams) { | ||
result.additional_values = params.additionalParams | ||
} | ||
return result | ||
} | ||
|
||
LinkedHashMap getPersonParams(LinkedHashMap input, LinkedHashMap additionalParams = [:]) { | ||
def params = getPersonDefaultParams() + input | ||
def data = getPersonParamsMap(params + additionalParams) | ||
return nvlParams(data) | ||
} | ||
|
||
LinkedHashMap getPerson(def id) { | ||
return getEntity(getPersonEntityType(), id) | ||
} | ||
|
||
LinkedHashMap createPerson(LinkedHashMap input, LinkedHashMap additionalParams = [:]) { | ||
LinkedHashMap params = getPersonParams(input, additionalParams) | ||
return createEntity(getPersonEntityType(), params) | ||
} | ||
|
||
LinkedHashMap updatePerson(def id, LinkedHashMap input, LinkedHashMap additionalParams = [:]) { | ||
LinkedHashMap params = getPersonParams(input, additionalParams) | ||
return updateEntity(getPersonEntityType(), id, params) | ||
} | ||
|
||
LinkedHashMap putPerson(LinkedHashMap input, LinkedHashMap additionalParams = [:]) { | ||
def personId = input.personId | ||
input.remove('personId') | ||
|
||
if (personId) { | ||
return updatePerson(personId, input, additionalParams) | ||
} else { | ||
return createPerson(input, additionalParams) | ||
} | ||
} | ||
|
||
Boolean deletePerson(def id) { | ||
return deleteEntity(getPersonEntityType(), id) | ||
} | ||
} |