Search in sources :

Example 1 with Panic

use of one.kii.summer.io.exception.Panic in project kiimate by SINeWang.

the class VisitRawAssetCtl method visit.

@RequestMapping(value = "/{" + GROUP + "}/{" + NAME + "}/{" + STABILITY + "}/{" + VERSION + ":.+}/raw")
public ResponseEntity<?> visit(@RequestHeader(value = ErestHeaders.REQUEST_ID, required = false) String requestId, @RequestHeader(ErestHeaders.VISITOR_ID) String visitorId, @PathVariable(OWNER_ID) String ownerId, @PathVariable(GROUP) String group, @PathVariable(NAME) String name, @PathVariable(STABILITY) String stability, @PathVariable(VERSION) String version, @RequestParam(value = FORMAT_YML, required = false) String yml) {
    ReadContext context = buildContext(requestId, ownerId, visitorId);
    VisitRawAssetApi.GroupNameForm form = new VisitRawAssetApi.GroupNameForm();
    form.setGroup(group);
    form.setName(name);
    if (null != stability) {
        form.setStability(stability);
    }
    if (null != version) {
        form.setVersion(version);
    }
    try {
        if (yml == null) {
            return VisitApiCaller.sync(api, context, form);
        } else {
            DumperOptions options = new DumperOptions();
            options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
            try {
                Yaml yaml = new Yaml(options);
                return ErestResponse.ok(requestId, yaml.dump(api.visit(context, form)));
            } catch (BadRequest badRequest) {
                return ErestResponse.badRequest(requestId, badRequest.getKeys());
            } catch (Panic panic) {
                return ErestResponse.badRequest(requestId, panic.getKeys());
            }
        }
    } catch (NotFound notFound) {
        return ErestResponse.notFound(requestId, notFound.getKeys());
    }
}
Also used : BadRequest(one.kii.summer.io.exception.BadRequest) Panic(one.kii.summer.io.exception.Panic) ReadContext(one.kii.summer.io.context.ReadContext) DumperOptions(org.yaml.snakeyaml.DumperOptions) VisitRawAssetApi(one.kii.kiimate.status.core.api.VisitRawAssetApi) Yaml(org.yaml.snakeyaml.Yaml) NotFound(one.kii.summer.io.exception.NotFound)

Example 2 with Panic

use of one.kii.summer.io.exception.Panic in project kiimate by SINeWang.

the class DefaultSearchGlimpseIntensionsApi method search.

@Override
public List<Intension> search(ReadContext context, ZoomOutBySet form) throws BadRequest, Panic {
    GlimpsesDai.Publication publication = glimpsesDai.load(form);
    ModelSubscriptionDai.ClueModelSubId modelSubId = new ModelSubscriptionDai.ClueModelSubId();
    modelSubId.setId(publication.getModelSubId());
    ModelSubscriptionDai.Instance instance;
    try {
        instance = modelSubscriptionDai.load(modelSubId);
    } catch (NotFound notFound) {
        throw new Panic(notFound.getKeys());
    }
    IntensionDai.ChannelPubSet set = ValueMapping.from(IntensionDai.ChannelPubSet.class, instance);
    List<IntensionDai.Record> records = intensionDai.loadLast(set);
    List<Intension> intensions = ValueMapping.from(Intension.class, records);
    return NotBadResponse.of(intensions);
}
Also used : IntensionDai(one.kii.kiimate.model.core.dai.IntensionDai) Panic(one.kii.summer.io.exception.Panic) GlimpsesDai(one.kii.kiimate.status.core.dai.GlimpsesDai) ModelSubscriptionDai(one.kii.kiimate.model.core.dai.ModelSubscriptionDai) NotFound(one.kii.summer.io.exception.NotFound)

Example 3 with Panic

use of one.kii.summer.io.exception.Panic in project kiimate by SINeWang.

the class TestDeclareReceiptApi method testSave.

@Test
public void testSave() {
    String group = "testGroup";
    String name = "testName";
    String tree = "testTree";
    DeclareExtensionApi.CommitForm commitForm = new DeclareExtensionApi.CommitForm();
    commitForm.setGroup(group);
    commitForm.setName(name);
    commitForm.setTree(tree);
    WriteContext context = new WriteContext(requestId, ownerId, operatorId);
    commitForm.setVisibility("protected");
    DeclareExtensionApi.CommitReceipt response = null;
    try {
        response = declareExtensionApi.commit(context, commitForm);
    } catch (Exception e) {
        e.printStackTrace();
    }
    String id = response.getId();
    Assert.assertNotNull(id);
    ExtensionDai.ChannelId extId = new ExtensionDai.ChannelId();
    extId.setId(Long.valueOf(id));
    ExtensionDai.Record record = null;
    try {
        record = extensionDai.loadLast(extId);
    } catch (Panic panic) {
        panic.printStackTrace();
    }
    Assert.assertNotNull(record);
    extensionMapper.deleteExtensionById(Long.valueOf(id));
}
Also used : Panic(one.kii.summer.io.exception.Panic) ExtensionDai(one.kii.kiimate.model.core.dai.ExtensionDai) WriteContext(one.kii.summer.io.context.WriteContext) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Panic

use of one.kii.summer.io.exception.Panic in project kiimate by SINeWang.

the class SearchModelsCtl method exploreModels.

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<SearchModelsApi.Models>> exploreModels(@RequestHeader(value = ErestHeaders.REQUEST_ID, required = false) String requestId, @RequestHeader(ErestHeaders.VISITOR_ID) String visitorId, @RequestParam("q") String query) {
    ReadContext context = buildContext(requestId, null, visitorId);
    SearchModelsApi.QueryModelsForm form = new SearchModelsApi.QueryModelsForm();
    form.setGroup(query);
    try {
        return ErestResponse.ok(requestId, searchModelsApi.search(context, form));
    } catch (Panic panic) {
        return ErestResponse.panic(requestId, panic.getKeys());
    }
}
Also used : Panic(one.kii.summer.io.exception.Panic) ReadContext(one.kii.summer.io.context.ReadContext) SearchModelsApi(one.kii.kiimate.model.core.api.SearchModelsApi)

Aggregations

Panic (one.kii.summer.io.exception.Panic)4 ReadContext (one.kii.summer.io.context.ReadContext)2 NotFound (one.kii.summer.io.exception.NotFound)2 SearchModelsApi (one.kii.kiimate.model.core.api.SearchModelsApi)1 ExtensionDai (one.kii.kiimate.model.core.dai.ExtensionDai)1 IntensionDai (one.kii.kiimate.model.core.dai.IntensionDai)1 ModelSubscriptionDai (one.kii.kiimate.model.core.dai.ModelSubscriptionDai)1 VisitRawAssetApi (one.kii.kiimate.status.core.api.VisitRawAssetApi)1 GlimpsesDai (one.kii.kiimate.status.core.dai.GlimpsesDai)1 WriteContext (one.kii.summer.io.context.WriteContext)1 BadRequest (one.kii.summer.io.exception.BadRequest)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 DumperOptions (org.yaml.snakeyaml.DumperOptions)1 Yaml (org.yaml.snakeyaml.Yaml)1