Ananda Ananda - 2 months ago 8x
Groovy Question

Find a value in a collection and assign top an variable using groovy

Hello Groovy Experts,

I am using the below command to get all the ODI Dataservers.

def PSchema=DServer.getPhysicalSchemas();

When I print the
variable I getting the following values.

[oracle.odi.domain.topology.OdiPhysicalSchema ABC.X1, oracle.odi.domain.topology.OdiPhysicalSchema ABC.X2]

What I am trying to achieve here I will be passing
during runtime...

And then I want to validate this value with the
result and the print the following value:

oracle.odi.domain.topology.OdiPhysicalSchema ABC.X2

I tried using the following options:

def PSchema44 = PSchema11.findIndexValues { it =~ /(X1)/ }
def pl=PSchema11.collect{if(it.contains ('X1)){return it}}

I tried for loop to check whether values are getting printed properly ..result is fine:

for (item in PSchema11 )
println item


Assuming 'X1' and 'X2' are the names for the physical schemas, you should be able to do something like this:

def phys = "X1"
def pSchemas = dServer.getPhysicalSchemas()
def schema = pSchemas.find{it.schemaName == phys}

also I guess you are new to Groovy, I suggest you read up on syntax and naming conventions. For example, variable names should always start with a lower case letter