MyTetra Share
Делитесь знаниями!
tmp
Время создания: 09.02.2020 18:50
Раздел: INFO - JOB - rtneo - Работа над задачами - Снапшоты
Запись: wwwlir/Tetra/master/base/1581245456129c76sxv7/text.html на raw.githubusercontent.com

import com.groupstp.rtneo.entity.*

import com.haulmont.cuba.core.global.*;

import com.haulmont.cuba.core.app.*;

import com.haulmont.cuba.core.entity.EntitySnapshot;

import com.groupstp.rtneo.service.*;


import com.haulmont.cuba.core.app.serialization.EntitySerializationAPI;

import com.haulmont.cuba.core.app.serialization.ViewSerializationAPI;

import com.haulmont.cuba.core.app.serialization.ViewSerializationOption;

import com.groupstp.rtneo.util.JsonUtil;


EntitySnapshotService entitySnapshotService = AppBeans.get(EntitySnapshotService.NAME);

EntitySerializationAPI entitySerializationAPI = AppBeans.get(EntitySerializationAPI.NAME);

ViewSerializationAPI viewSerializationAPI = AppBeans.get(ViewSerializationAPI.NAME)

ViewRepository viewRepository = AppBeans.get(ViewRepository.NAME)

//viewSerializationAPI.toJson(view, ViewSerializationOption.COMPACT_FORMAT)

//entitySerializationAPI.toJson(contract)


View contractView = viewRepository.getView(Contract.class, "contract-print")

def contract = dataManager.load(Contract.class).id(UUID.fromString('cbda59ad-009a-0d0e-24dc-03b0e7c58a1b')).view(contractView).one()


TestSnapshot testSnapshot = createSnapshot(contract, contractView)


private TestSnapshot createSnapshot(Object object, View view){

EntitySnapshotService entitySnapshotService = AppBeans.get(EntitySnapshotService.NAME)

CommitContext ctx = new CommitContext();

object = dataManager.reload(object, view);

EntitySnapshot snp = entitySnapshotService.createSnapshot(object, view);

TestSnapshot testSnapshot = metadata.create(TestSnapshot.class);

// ctx.addInstanceToCommit(testSnapshot)

// dataManager.commit(ctx)

testSnapshot.setEntityClass(object.getClass().toString());

CustomView customView = createCustomView(view)

testSnapshot.setView(customView)

ctx.addInstanceToCommit(customView)

testSnapshot.setSnapshot(snp.getId())

ctx.addInstanceToCommit(testSnapshot)

dataManager.commit(ctx)

return testSnapshot;

}


private CustomView createCustomView(View view){

ViewSerializationAPI viewSerializationAPI = AppBeans.get(ViewSerializationAPI.NAME)

String json = viewSerializationAPI.toJson(view, ViewSerializationOption.COMPACT_FORMAT)

CustomView customView = metadata.create(CustomView.class);

customView.setViewJson(json)

dataManager.commit(customView)

return customView;

}

/**

*

*/

private _(Object o){

JsonUtil jsonUtil = AppBeans.get(JsonUtil.class)

EntitySerializationAPI entitySerializationAPI = AppBeans.get(EntitySerializationAPI.NAME);

log.debug(o)

// log.debug(entitySerializationAPI.toJson(o))

}


/*

/log

*/

private _(Object obj, String options = ""){


String op = options

if(options.equals("for")){

for(def item : obj){

log(obj)

}

}

if(options.equals("")){

log(obj)

}



}

private log(Object obj){

log.debug(obj)

}

 
MyTetra Share v.0.65
Яндекс индекс цитирования