Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LocalDateTime getApplicationStatusesLastChangeDate(int appId, int statusCode, final boolean throwError = true){
- // build url
- String strStatusCode = statusCode as String //"["+statusCodes.join(",")+"]"
- String strUrl = appStatusesChangesUrl.replaceAll('%appId', appId as String).replaceAll('%statusCode', strStatusCode)
- log.debug('Got strUrl: {}', strUrl)
- String jsonStr = new URL(/*cashupCrmUrl*/ strUrl).getText(
- //connectionTimeout: 5000,
- requestProperties: ['Connection': 'close', 'Cookie': cookies, 'Content-Type': 'application/json', 'Accept': '*/*'] // put here auth headers
- )
- log.debug('Got response: {}', jsonStr)
- if (!jsonStr || jsonStr == '[]'){
- // empty result
- if (throwError) {
- throw new InternalServerErrorException("Got empty status change history for app ${appId} by status id ${strStatusCode}. Most likely database data consistency error")
- } else {
- null
- }
- }
- def appsJson = new JsonSlurper().parseText(jsonStr)
- // appsJson is a list (may be empty) of apps entities
- //TODO: analyze business result?
- /* wil get result in form of list of dicts:
- [
- {
- "id": 421,
- "created": "2017-02-28T15:20:43.605382Z",
- "old_application_status_id": 17,
- "old_application_status_name": "InGracefulPeriod",
- "new_application_status_id": 15,
- "new_application_status_name": "Closed"
- }
- ]
- */
- def lastUpdatedDate = appsJson.findAll {
- (it.new_application_status_id as String) == strStatusCode
- }.max {
- //DatatypeConverter.parseDateTime(it.created)
- //LocalDateTime.parse(it.created)
- LocalDateTime.ofInstant(DatatypeConverter.parseDateTime(it.created).getTime().toInstant(), ZoneId.systemDefault())
- }.created
- if (lastUpdatedDate){
- //lastUpdatedDate = DatatypeConverter.parseDateTime(lastUpdatedDate).getTime()
- lastUpdatedDate = LocalDateTime.ofInstant(DatatypeConverter.parseDateTime(lastUpdatedDate).getTime().toInstant(), ZoneId.systemDefault()) //LocalDateTime.parse(lastUpdatedDate)
- } else {
- throw new IllegalStateException("Could not get lastUpdateDate (got null/empty value)")
- }
- // .collect {
- // DatatypeConverter.parseDateTime(it.change_date)
- // }.first().getTime()
- // def minCredStartDate = report.Contracts.Contract.findAll { con ->
- // con.Roles.Role.count { r -> r.ImportCode == '1' } > 0
- // }.min { con ->
- // Date.parse(DTFM, con.CreditStartDate.toString())
- // }.collect { con ->
- // Date.parse(DTFM, con.CreditStartDate.toString())
- // }.first()
- def ret = lastUpdatedDate // appsJson //.max {} //.apps //.collect { it.id }
- log.debug("Will return {}", ret)
- ret //[2,3,5,6,7]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement