MyTetra Share
Делитесь знаниями!
Сериализация
Время создания: 09.02.2020 18:08
Раздел: INFO - JOB - rtneo - Работа над задачами - Снапшоты
Запись: wwwlir/Tetra/master/base/1581242892yozxazsech/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);

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)

_(testSnapshot)

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))

}

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