import com.groupstp.rtneo.entity.*
import com.haulmont.cuba.core.global.*
import com.haulmont.cuba.core.global.ViewRepository;
import com.haulmont.cuba.core.global.View;
import com.groupstp.rtneo.core.bean.ContragentWorker;
ContragentWorker сontragentWorker = AppBeans.get(ContragentWorker.NAME)
def i = 0
def contragents = dataManager.load(Contragent.class)
.query('select c from rtneo$Contragent c where c.personalAccount is null and c.type = 3')
.firstResult(i*10000)
.maxResults(10000)
.view("_local")
.list();
_("Commit START! size - ${contragents.getSize()}")
CommitContext ctx = new CommitContext()
for(def contragent : contragents){
def pa = сontragentWorker.createAccountNumber(contragent)
contragent.setPersonalAccount(pa)
_("Name - ${contragent.getName()}; pa - ${pa}")
ctx.addInstanceToCommit(contragent)
}
dataManager.commit(ctx)
_("Commit OK!")
/**
* Логирование
*/
import com.haulmont.cuba.core.app.serialization.EntitySerializationAPI;
import com.groupstp.rtneo.util.JsonUtil;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
private _(Object obj, String... options){
if(obj == null){log("LOG.ERROR: Object is null!!!");return}
if(options.size() == 0){log(obj)}
for(def option : options){
if(option.equals("str")){log(obj)}
if(option.equals("for")){obj.each({_(it)})}
if(option.equals("json")){
EntitySerializationAPI entitySerializationAPI = AppBeans.get(EntitySerializationAPI.NAME)
try{log(entitySerializationAPI.toJson(obj))}
catch(Exception e){log("LOG.ERROR: JSON entity serialization failed")}
}
if(option.equals("objJson")){
JsonUtil jsonUtil = AppBeans.get(JsonUtil.NAME)
try{log.(jsonUtil.toJson(obj))}
catch(Exception e){log("LOG.ERROR: JSON object serialization failed")}
}
if(option.equals("date")){
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
try{log(df.format(obj))}
catch(Exception e){log("LOG.ERROR: Failed date format")}
}
}
}
private log(Object obj){log.debug(obj)}