Using the metadata DSL in the console (FOR ADMINS ONLY)

Simple Example:


import org.modelcatalogue.core.*
import org.modelcatalogue.core.audit.*

AuditService auditService = ctx.getBean('auditService')
DataElement de = DataElement.get( 1304552)

auditService.betterMute {
de.description = "Hello"
de.save(flush:true)
}




Start by adding any java dependencies (you'll need these):

import org.modelcatalogue.core.*

and add the quiet save method:

void quietSave(CatalogueElement ce) {
try {
ce.save()
} catch (Exception e) {
println "Exception caught: ${e.getMessage()}"
}
}

Then you can access a data model using the data model .get() method and adding the id of the data model you want:

DataModel NCRASDictionary = DataModel.get(135999)

Then you can print out the results:

println(NCRASDictionary)

press play:

insert screenshot

Next, we want to get all the data classes, data elements and data types from another model (NCRAS AV PATIENT) and put them into the NCRASDICTIONARY Model.

DataModel NCRASAVPATIENT = DataModel.get(99994)

Next, we cant to create a top-level class in the NCRASDictionary with the model name and description, so create a new data class with the info from the patient model and add it to the Dictionary Model:

DataClass avPatient = new DataClass(name:NCRASAVPATIENT.name, description: NCRASAVPATIENT.description, dataModel: NCRASDictionary)
quietSave(avPatient)

Next, we get all the classes that are in the patient model and then add them to the new class we've created

def avPatientClasses = DataClass.findAllByDataModel(NCRASAVPATIENT)

avPatientClasses.each{ cls ->
avPatient.addToContains(cls)
}


Now get all the catalogue elements from the patients model:


def allElements = CatalogueElement.findAllByDataModel(NCRASAVPATIENT)

allElements.each{ el ->

el.dataModel = NCRASDictionary
quietSave(el)
}







Instructions