Groovy equivalent to python urllib.quote?

2021-09-23 Thread James McMahon
Hello. I am new to groovy, assigned an effort to convert legacy python scripts to groovy replacements. We are doing this in an effort to decouple from dependencies on the jython engine in NiFi for scripts we run from its ExecuteScript processor. In one of these python scripts, this gets done to

Re: Groovy equivalent to python urllib.quote?

2021-09-23 Thread James McMahon
%5CLas%24o%20%26%20Roy%20Kent%2C%20%40%20AFC%20Richmond%2C%20%C3%B6%C3%B6%C3%B6%C3%B6%20%21' On Thu, Sep 23, 2021 at 6:24 AM James McMahon wrote: > Hello. I am new to groovy, assigned an effort to convert legacy python > scripts to groovy replacements. We are doing this in an effort to

Re: Checking directory state using Groovy

2021-10-21 Thread James McMahon
ng curly > braces can be used in these cases > (same goes for setters) > > Cheers, > mg > > > On 20/10/2021 12:14, James McMahon wrote: > > Many thanks to each of you who offered guidance. Redirecting back to this > today, anticipating success given your advice. Still g

Re: Checking directory state using Groovy

2021-10-20 Thread James McMahon
>> Rachel Greenham >> rac...@merus.eu >> >> > On 15 Oct 2021, at 15:57, Nelson, Erick >> wrote: >> > >> > import java.nio.file.Path >> > import java.nio.file.Files >> > >> > File f = new File('test') >> > Path p =

Re: Checking directory state using Groovy

2021-10-20 Thread James McMahon
be accessed without the "get" prefix with a lowercase > first char > 2. A simplified string interpolation syntax without the enclosing curly > braces can be used in these cases > (same goes for setters) > > Cheers, > mg > > > On 20/10/2021 12:14, James McMahon

Checking directory state using Groovy

2021-10-15 Thread James McMahon
Hello. I am trying to convert an existing script from python to Groovy. It executes a number of os.path and os.access commands, which I've not yet been able to find examples of that are written in Groovy. I have found similar implementations that employ "add on" Jenkins libraries for Groovy, but I

Determine whether a text string is valid JSON representation

2021-09-21 Thread James McMahon
Hello. Newbie to Groovy. Have a text string that I need to verify is a representation of valid JSON, or not. What is an effective means to do this in Groovy? I'm having difficulty determining what a method like JSONSlurper will return to me if the string can't be parsed because it is not valid

Re: Determine whether a text string is valid JSON representation

2021-09-21 Thread James McMahon
alue of idValue is " + idValue + "\nThe value of jsonString is \n" + thisString); println 'Valid JSON' } catch(error) { println "Invalid: $error.message" } On Tue, Sep 21, 2021 at 7:52 AM Paul King wrote: > Yes, I also agree with Rachel's comment about groov

Misformatting json output

2022-06-06 Thread James McMahon
I am having problems properly formatting Json output to requirements. I have three fields, similar to this: fieldA has value {"lname":"Smith", "fname":"John"} fieldB has value {"age":"21", "gender":"M"} fields has value 12345 I put each into an empty Groovy map, result[:] . I'm required to

Re: Misformatting json output

2022-06-06 Thread James McMahon
; {"fieldA":{"lname":"Smith","fname":"John"},"fieldB":{"age":21,"gender":"M"},"fieldC":12345} > > > > What is the source of your data look like? > > Is fieldC a number or a string? >

Foreign language chars as map keys

2023-02-22 Thread James McMahon
I have a Groovy list that holds the unicode representation of select foreign language characters, something like this simplified version: def myList = ['*\u00E4*','\u00D6','\u00F8'] I have built myself a Groovy map that is the crosstabulation of characters by count in an incoming document, so my

Re: Foreign language chars as map keys

2023-02-22 Thread James McMahon
Greenham > rac...@merus.eu > > On 22 Feb 2023, at 11:58, James McMahon wrote: > > I have a Groovy list that holds the unicode representation of select > foreign language characters, something like this simplified version: > > def myList = ['*\u00E4*','\u00D6','\u00F8

Re: Dynamic assignment of list name in iterator statement?

2023-03-04 Thread James McMahon
> Best regards, > Søren Berg Glasius > > Hedevej 1, Gl. Rye, 8680 Ry > Mobile: +45 40 44 91 88 > --- Press ESC once to quit - twice to save the changes. > > > Den tor. 23. feb. 2023 kl. 01.52 skrev James McMahon >: > >> Good evening. I have a list named languageCh

Re: Dynamic assignment of list name in iterator statement?

2023-03-05 Thread James McMahon
ej 1, Gl. Rye, 8680 Ry > Mobile: +45 40 44 91 88 > --- Press ESC once to quit - twice to save the changes. > > > Den søn. 5. mar. 2023 kl. 09.37 skrev James McMahon >: > >> Was trying to come up with a Groovy way to collapse a lengthy switch >> statement

Re: Dynamic assignment of list name in iterator statement?

2023-03-05 Thread James McMahon
nce and brevity to me. Thanks again. Jim On Sat, Mar 4, 2023 at 5:10 PM James McMahon wrote: > Søren , > May I ask you a follow up? I am trying what I thought I read in your reply > (thank you for that, by the way). But I continue to get this error: > "The LHS of an assig

Dynamic assignment of list name in iterator statement?

2023-02-22 Thread James McMahon
Good evening. I have a list named languageCharactersList. I begin my iteration through elements in that list with this: languageCharactersList.eachWithIndex( it, i -> I hope to make this more generic, so that I can build a variable name that points to the appropriate list, which then allows me

Re: Foreign language chars as map keys

2023-02-22 Thread James McMahon
building the crosstabulation > map? > Somehow, some spacing is introduced, and that would probably in that map > creation that this takes place. > > Guillaume > > On Wed, Feb 22, 2023 at 3:24 PM James McMahon > wrote: > >> Thank you Rachel. I will look at employing

Re: Dynamic assignment of list name in iterator statement?

2023-02-23 Thread James McMahon
Berg Glasius > > Hedevej 1, Gl. Rye, 8680 Ry > Mobile: +45 40 44 91 88 > --- Press ESC once to quit - twice to save the changes. > > > Den tor. 23. feb. 2023 kl. 01.52 skrev James McMahon >: > >> Good evening. I have a list named languageCharactersList. I begin my &g

Improving what I extract for my xml tag

2023-04-02 Thread James McMahon
Hello. I am developing a Groovy script to work through all the tags in an incoming text representation of an xml file. I've read my xml from the content of a NiFi flowfile, like so: session.read(ff, {inputStream -> text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)

Re: Existing resources to seek date patterns from raw data and normalize them

2023-06-14 Thread James McMahon
-- > *From:* Jochen Theodorou > *Sent:* Wednesday, 14 June 2023 4:42 AM > *To:* users@groovy.apache.org > *Subject:* Re: Existing resources to seek date patterns from raw data and > normalize them > > On 13.06.23 16:52, James McMahon wrote: > > Hell

Existing resources to seek date patterns from raw data and normalize them

2023-06-13 Thread James McMahon
Hello. I have a task to parse dates out of incoming raw content. Of course the date patterns can assume any number of forms - -MM-DD, /MM/DD, MMDD, MMDD, etc etc etc. I can build myself a robust regex to match a broad set of such patterns in the raw data, but I wonder if there

matcher is failing

2023-07-09 Thread James McMahon
Hello. I have a conditional clause in my Groovy script that attempts to parse a date pattern of this form: 06-14-2023. It fails - I believe in the matcher. I am running from a NiFi ExecuteScript processor. Here is my conditional: } else if ( candidate =~

Re: matcher is failing

2023-07-09 Thread James McMahon
-1df4-128b-52be-aaa96b947012] Could not parse: 06-14-2023 On Sun, Jul 9, 2023 at 11:59 AM James McMahon wrote: > Hello. I have a conditional clause in my Groovy script that attempts to > parse a date pattern of this form: 06-14-2023. It fails - I believe in the > matcher. > > I am run

Re: matcher is failing

2023-07-10 Thread James McMahon
se of using slashy-string for the regex (as only forward slash >> needs to be escaped) >> >> -Spencer >> >> On Sunday, July 9, 2023 at 12:08:17 PM EDT, James McMahon < >> jsmcmah...@gmail.com> wrote: >> >> >> Correc

Why is my global variable not visible to my function?

2023-08-10 Thread James McMahon
Hello. I am trying to use a variable I define globally in a function that follows within my script. Here is my code: def currentYear = LocalDate.now().getYear() def yearValue def monthValue def dayValue boolean validateDate(String my, String myMM, String myDD) { // Acceptable range for

Working with Calendar object in Groovy

2023-06-19 Thread James McMahon
If I have a Calendar object created for 1999-01-01, a get() of calendar.MONTH will return 0. From references I’ve found through Google, we have to add 1 to MONTH to get the 1 for January. The calendar object has 0 for MONTH. Now let’s take the case where we set our calendar object from “1999”,.

Re: Working with Calendar object in Groovy

2023-06-19 Thread James McMahon
e those that > don't. Not very nice OO or helpful as an API. > > It MAY be (speaking off the top of my head here) that you don't need/want > Calendar...the newer java.time package has many "finer-grained" classes for > things like Instance, Period, Duration, etc.

Groovy script error, JsonSlurper

2023-05-08 Thread James McMahon
Hello. I have incoming data that is json. An example of one case looks like this: {"id": "20230508215236_4447cd0a-9dca-47cb-90b1-6562cf34155a_Timer-Driven Process Thread-9", "te": "0.9494", "diskusage": "0.2776125422110003.3 MB", "memory": 77, "cpu": 0.58, "host":

Re: Unable to properly tally all keys in nested json

2023-05-13 Thread James McMahon
g read in as strings? On Sat, May 13, 2023 at 12:01 PM James McMahon wrote: > Thank you Paul. I have integrated this approach into the framework of my > NiFi ExecuteScript code, which reads the flowfile content from the stream. > I am seeing an undefined method error, and it seems t

Re: Unable to properly tally all keys in nested json

2023-05-13 Thread James McMahon
) > } > println tallyMap > println topValuesMap.collectEntries{ k, m -> [(k), m.sort{ _, v -> > -v.value }] }.take(10) > > > > <https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail> > Virus-free.www.avast.com >

Unable to properly tally all keys in nested json

2023-05-11 Thread James McMahon
I have this incoming json: { "name": "John Doe", "age": 42, "address": { "street": "123 Main St", "city": "Anytown", "state": "CA", "zip": "12345" }, "phoneNumbers": [ { "type": "home", "number": "555-1234" }, { "type": "work", "number": "555-5678" } ] } I wish to tally all the keys in this json

Re: Unable to properly tally all keys in nested json

2023-05-12 Thread James McMahon
email_content=webmail> > Virus-free.www.avast.com > <https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail> > <#m_3707991732434518544_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > On Fri, May 12, 2023 at 10:38 AM James McMahon > w

Re: Groovy script error, JsonSlurper

2023-05-09 Thread James McMahon
each { k,v ->" > instead and use the key k and value v in your script. > > On Mon, May 8, 2023 at 9:32 PM James McMahon wrote: > > > > Hello. I have incoming data that is json. An example of one case looks > like this: > > > > {"id": "2023050821

Cannot process zip file with Groovy

2024-02-15 Thread James McMahon
I am struggling to build a Groovy scri[t I can run from a NiFi ExecuteScript processor to extract from a zip file and stream to a tar archive. I tried to tackle it all at once and made little progress. I am now just trying to read the zip file, and am getting this error:

Re: Cannot process zip file with Groovy

2024-02-16 Thread James McMahon
=link_campaign=sig-email_content=webmail > > > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > On Fri, Feb 16, 2024 at 8:48 AM James McMahon > wrote: > > > > I am struggling to build a Groovy scri[t I can run from a NiFi > ExecuteScript processor to extract from a

Re: Cannot process zip file with Groovy

2024-02-17 Thread James McMahon
zip files. > > > > Also, apparently “java.util.Zip does not support DEFLATE64 compression > method.” : > https://www.ibm.com/support/pages/zip-file-fails-route-invalid-compression-method-error > > > > IF this is the case, you may need to use: > https://commons