Skip to content

Instantly share code, notes, and snippets.

@bikisuke
Created November 6, 2011 01:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bikisuke/1342313 to your computer and use it in GitHub Desktop.
Save bikisuke/1342313 to your computer and use it in GitHub Desktop.
gexcelapiを使って、Excelからastah*のドメイン定義を作成するサンプル。(要astah* professionalライセンス)
import com.change_vision.jude.api.inf.project.*
import com.change_vision.jude.api.inf.model.*
import com.change_vision.jude.api.inf.editor.*
import org.jggug.kobo.gexcelapi.GExcel
class AstahGenerator {
static generate(data) {
def pa = ProjectAccessorFactory.getProjectAccessor()
def editor = ModelEditorFactory.getERModelEditor()
pa.create(‘output.asta’)
TransactionManager.beginTransaction()
def model = editor.createERModel(pa.getProject(), ‘ER’)
data.each {
def elements = pa.findElements(IERDatatype.class, it.type)
def type = elements? elements[0] : editor.createERDatatype(model, it.type)
editor.createERDomain(model, null, it.logicalName, null, type)
}
TransactionManager.endTransaction()
pa.save()
pa.close()
}
}
// excel読み込みはgexcelapiが便利です。
def book = GExcel.open(‘demo.xls’)
def sheet = book[0]
def nameList = sheet.A_.findAll{it}
def typeList = sheet.C_.findAll{it}
def data = []
for(i=0;i<nameList.size();i++) {
def params = [:]
params.logicalName = nameList[i] as String
params.type = typeList[i] as String
data << params
}
AstahGenerator.generate(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment