def servletContext = ServletContextHolder.servletContext
if(State.findAll().size() == 0){
//upload states
new File(servletContext.getRealPath("/dataCsv/states.csv")).eachLine {
new State(name:it.split(',')[0]).save()
}
}
def states = State.list()
//upload Cities
if(Cities.findAll().size() == 0){
new File(servletContext.getRealPath("/dataCsv/Cities.csv")).eachLine {token->
states.each{st->
def record = token.split(',')
if(st.id == record[1] as Long){
new Cities(stateId:st.id,name:record[0]).save()
}
}
}
}
if(State.findAll().size() == 0){
//upload states
new File(servletContext.getRealPath("/dataCsv/states.csv")).eachLine {
new State(name:it.split(',')[0]).save()
}
}
def states = State.list()
//upload Cities
if(Cities.findAll().size() == 0){
new File(servletContext.getRealPath("/dataCsv/Cities.csv")).eachLine {token->
states.each{st->
def record = token.split(',')
if(st.id == record[1] as Long){
new Cities(stateId:st.id,name:record[0]).save()
}
}
}
}
No comments:
Post a Comment