Search in sources :

Example 1 with Conflict

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");
    }
}
Also used : Conflict(one.kii.summer.io.exception.Conflict) AnSubscribeModelExtractor(one.kii.kiimate.model.core.fui.AnSubscribeModelExtractor) ModelSubscriptionDai(one.kii.kiimate.model.core.dai.ModelSubscriptionDai)

Example 2 with Conflict

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);
}
Also used : Conflict(one.kii.summer.io.exception.Conflict) SubscribeModelsApi(one.kii.kiimate.model.core.api.SubscribeModelsApi) AnSubscribeModelExtractor(one.kii.kiimate.model.core.fui.AnSubscribeModelExtractor) WriteContext(one.kii.summer.io.context.WriteContext) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Conflict

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;
}
Also used : IntensionDai(one.kii.kiimate.model.core.dai.IntensionDai) InstanceDai(one.kii.kiimate.status.core.dai.InstanceDai) Conflict(one.kii.summer.io.exception.Conflict) ModelSubscriptionDai(one.kii.kiimate.model.core.dai.ModelSubscriptionDai)

Example 4 with Conflict

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;
}
Also used : IntensionDai(one.kii.kiimate.model.core.dai.IntensionDai) ArrayList(java.util.ArrayList) ModelPublicationDai(one.kii.kiimate.model.core.dai.ModelPublicationDai) Conflict(one.kii.summer.io.exception.Conflict)

Aggregations

Conflict (one.kii.summer.io.exception.Conflict)4 IntensionDai (one.kii.kiimate.model.core.dai.IntensionDai)2 ModelSubscriptionDai (one.kii.kiimate.model.core.dai.ModelSubscriptionDai)2 AnSubscribeModelExtractor (one.kii.kiimate.model.core.fui.AnSubscribeModelExtractor)2 ArrayList (java.util.ArrayList)1 SubscribeModelsApi (one.kii.kiimate.model.core.api.SubscribeModelsApi)1 ModelPublicationDai (one.kii.kiimate.model.core.dai.ModelPublicationDai)1 InstanceDai (one.kii.kiimate.status.core.dai.InstanceDai)1 WriteContext (one.kii.summer.io.context.WriteContext)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1