use of one.kii.summer.io.exception.Conflict in project kiimate by SINeWang.
the class DefaultSubscribeModelsApi method commit.
@Override
public Receipt commit(WriteContext context, Form form) throws Conflict {
AnSubscribeModelExtractor.ModelSubscription modelSubscription = subscribeModelExtractor.extract(form, context);
ModelSubscriptionDai.Status subscription = ValueMapping.from(ModelSubscriptionDai.Status.class, modelSubscription);
try {
modelSubscriptionDai.remember(subscription);
return ValueMapping.from(Receipt.class, modelSubscription);
} catch (ModelSubscriptionDai.DuplicatedSubscription duplicatedSubscription) {
throw new Conflict("id");
}
}
use of one.kii.summer.io.exception.Conflict in project kiimate by SINeWang.
the class TestSubscribeModelsApi method test.
@Test
public void test() {
SubscribeModelsApi.Form form = new SubscribeModelsApi.Form();
form.setGroup("testGroup");
form.setSubSet(pubSet);
long id = idgen.born();
AnSubscribeModelExtractor.ModelSubscription model = new AnSubscribeModelExtractor.ModelSubscription();
model.setSubscriberId(subscriberId);
model.setSubSet(pubSet);
model.setGroup(group);
model.setName(name);
model.setTree(tree);
modelSubscriptionMapper.deleteById(id);
form.setGroup(group);
form.setName(name);
WriteContext context = new WriteContext(requestId, ownerId, operatorId);
SubscribeModelsApi.Receipt receipt = null;
try {
receipt = subscribeModelsApi.commit(context, form);
} catch (Conflict conflict) {
conflict.printStackTrace();
}
modelSubscriptionMapper.deleteById(id);
}
use of one.kii.summer.io.exception.Conflict in project kiimate by SINeWang.
the class DefaultRefreshStatusApi method commit.
@Override
public Receipt commit(WriteContext context, SubIdForm form) throws BadRequest, Conflict, NotFound, Panic {
ModelSubscriptionDai.ChannelSubId channel = ValueMapping.from(ModelSubscriptionDai.ChannelSubId.class, context, form);
ModelSubscriptionDai.ModelPubSet model = modelSubscriptionDai.getModelPubSetByOwnerSubscription(channel);
IntensionDai.ChannelLastExtension lastExtension = new IntensionDai.ChannelLastExtension();
lastExtension.setId(model.getRootExtId());
lastExtension.setBeginTime(model.getBeginTime());
Map<String, IntensionDai.Record> dict = modelRestorer.restoreAsIntensionDict(lastExtension);
List<AnInstanceExtractor.Instance> instances = instanceExtractor.extract(context, form, dict);
List<InstanceDai.Record> record1 = ValueMapping.from(InstanceDai.Record.class, instances);
try {
instanceDai.remember(record1);
} catch (InstanceDai.InstanceDuplicated instanceDuplicated) {
throw new Conflict(KeyFactorTools.find(InstanceDai.Record.class));
}
IntensionDai.ChannelLastExtension rootExtension = ValueMapping.from(IntensionDai.ChannelLastExtension.class, model);
rootExtension.setId(model.getRootExtId());
InstanceDai.ChannelStatusId modelSubId = ValueMapping.from(InstanceDai.ChannelStatusId.class, form);
List<InstanceDai.Instance> newInstances = instanceDai.loadInstances(modelSubId);
List<IntensionDai.Record> recordList = intensionDai.loadLast(rootExtension);
List<Intension> intensions = ValueMapping.from(Intension.class, recordList);
Map<String, Object> map = instanceTransformer.toTimedValue(newInstances, model);
Receipt receipt = ValueMapping.from(Receipt.class, form, context);
receipt.setMap(map);
receipt.setIntensions(intensions);
return receipt;
}
use of one.kii.summer.io.exception.Conflict in project kiimate by SINeWang.
the class DefaultPublishModelApi method commit.
public Receipt commit(WriteContext context, Form form) throws BadRequest, Conflict, NotFound, Panic {
IntensionDai.ChannelLatestExtension latest = new IntensionDai.ChannelLatestExtension();
latest.setId(form.getExtId());
List<IntensionDai.Record> allRecords = new ArrayList<>();
List<IntensionDai.Record> records = intensionDai.load(latest);
allRecords.addAll(records);
List<ModelPublicationDai.Record> publications = publicationExtractor.extract(context, form, records);
try {
modelPublicationDai.save(publications);
} catch (ModelPublicationDai.DuplicatedPublication duplicatedPublication) {
throw new Conflict(KeyFactorTools.find(Form.class));
}
Receipt receipt = ValueMapping.from(Receipt.class, form, context);
List<Intension> snapshotIntensions = ValueMapping.from(Intension.class, allRecords);
receipt.setIntensions(snapshotIntensions);
return receipt;
}
Aggregations