use of one.kii.summer.io.exception.BadRequest 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());
}
}
use of one.kii.summer.io.exception.BadRequest in project kiimate by SINeWang.
the class SearchSubscriptionsCtl method search.
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<SearchSubscriptionsApi.Subscriptions>> search(@RequestHeader(value = ErestHeaders.REQUEST_ID, required = false) String requestId, @RequestHeader(ErestHeaders.VISITOR_ID) String visitorId, @PathVariable(OWNER_ID) String ownerId, @RequestParam("q") String query) {
ReadContext context = buildContext(requestId, ownerId, visitorId);
SearchSubscriptionsApi.QueryForm form = new SearchSubscriptionsApi.QueryForm();
form.setGroup(query);
try {
return ErestResponse.ok(requestId, searchSubscriptionsApi.search(context, form));
} catch (BadRequest badRequest) {
return ErestResponse.badRequest(requestId, badRequest.getKeys());
}
}
use of one.kii.summer.io.exception.BadRequest in project kiimate by SINeWang.
the class DefaultExtensionExtractor method extract.
@Override
public ExtensionDai.Record extract(WriteContext context, DeclareExtensionApi.CommitForm form) throws BadRequest, Panic {
NotBadRequest.from(form);
form.setGroup(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, form.getGroup()));
form.setName(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, form.getName()));
form.setTree(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, form.getTree()));
form.setVisibility(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, form.getVisibility()));
ExtensionDai.Record record = ValueMapping.from(ExtensionDai.Record.class, form, context);
try {
String visibility = form.getVisibility();
Visibility.valueOf(visibility.toUpperCase());
} catch (IllegalArgumentException e) {
throw new BadRequest("visibility");
}
hash(record);
record.setId(idgen.born());
return NotBadResponse.of(ExtensionDai.Record.class, MayHave.class, record);
}
Aggregations