Cordra服务启动后,使用https://127.0.0.1:8443可以访问它的UI操作界面,http://127.0.0.1:8080访问不需要登录,但功能不完整。

先来看一下UI界面的各个功能选项
#All Objects(所有对象)
image.png
#Show Only(按schema或特定type过滤显示)
image.png
#Admin(管理员功能)
image.png

对象的增删改查

点击create-document,填写name、description属性内容,并添加一个playload文件,点击save
image.png

回到列表页后可以看到多了一个数据对象了。点击新增的对象,进入详情页。点击edit可以更新或删除对象记录。其它tab页操作内容较简单,就不累述了。
image.png

  • OBJECT 展示刚刚充填的内容
  • ACL 可以设置该对象在对外开放时,需要的权限,包括可读者、可写者、主题信息可读者、接口返回
  • VERSIONS 数据版本归档
  • DO VIEW/DETAILS 对象json显示
  • RELATIVES 引用的其它对象关系展示,标识符id设计时是可以引用其它对象的,后续篇章会详述

Types的增删改查

页面操作比较简单
image.png

  • 可以通过访问https://localhost:8443/search?query=type:"Document进行type的查询。
  • 界面可以通过加载文件进行type新建,文件也可以是具体的一个对象数据
  • 可以操作删除type并删除type结构下的所有对象数据

以下是新建type的一个JSON格式参数

  1. {
  2. "results": [
  3. {
  4. "id": "test/171a0606f7c74580fd39",
  5. "type": "Schema",
  6. "content": {
  7. "identifier": "test/171a0606f7c74580fd39",
  8. "name": "Group",
  9. "schema": < Schema json omitted for brevity >,
  10. "javascript": < JavaScript omitted for brevity >
  11. },
  12. "metadata": {
  13. "createdOn": 1535479938849,
  14. "createdBy": "admin",
  15. "modifiedOn": 1535479938855,
  16. "modifiedBy": "admin",
  17. "txnId": 65
  18. }
  19. },
  20. {
  21. "id": "test/171a0606f7c74580fd39",
  22. "type": "Schema",
  23. "content": {
  24. "identifier": "test/171a0606f7c74580fd39",
  25. "name": "Document",
  26. "schema": < Schema json omitted for brevity >
  27. },
  28. "metadata": {
  29. "createdOn": 1535479938849,
  30. "createdBy": "admin",
  31. "modifiedOn": 1535479938855,
  32. "modifiedBy": "admin",
  33. "txnId": 65
  34. }
  35. },
  36. ]
  37. }

JSON模式中的关键字和属性

  1. 模式引用-属性JSON类型定义

Cordra支持$ref关键字用于在模式中引用或在Cordra中引用其他模式。 下面的例子定义了一个叫Human的type结构。name和address属性必填,name是字符串类型;address是一个JSON对象,且必须包含street_address、city、state三个属性。JSON中的type值需要是基本类型,可选的基本类型有 array、boolean、integer、null、number、object、string。
Human类型定义

  1. {
  2. "type": "object",
  3. "required": [ "name", "address" ],
  4. "properties": {
  5. "name": { "type": "string" },
  6. "address": { "$ref": "#/definitions/address" }
  7. },
  8. "definitions": {
  9. "address": {
  10. "type": "object",
  11. "properties": {
  12. "street_address": { "type": "string" },
  13. "city": { "type": "string" },
  14. "state": { "type": "string" }
  15. },
  16. "required": [ "street_address", "city", "state" ]
  17. }
  18. }
  19. }

使用definitions的方式说明address结构有一个好处是,该字段可以被其它的模式对象引用。如果不需要被引用,在properties里直接定义也是可以的,如:

  1. {
  2. "type": "object",
  3. "required": [
  4. "name",
  5. "address"
  6. ],
  7. "properties": {
  8. "name": {
  9. "type": "string"
  10. },
  11. "address": {
  12. "type": "object",
  13. "properties": {
  14. "street_address": {
  15. "type": "string"
  16. },
  17. "city": {
  18. "type": "string"
  19. },
  20. "state": {
  21. "type": "string"
  22. }
  23. },
  24. "required": [
  25. "street_address",
  26. "city",
  27. "state"
  28. ]
  29. }
  30. }
  31. }

类型定义后可以通过一下代码进行新建(当然通过UI或API直接传JSON参数也可以进行对象新建)。
description属性是代码附加的第三个属性。

  1. CordraClient cordra = new TokenUsingHttpCordraClient("https://127.0.0.1:8443", "admin", "admin123");
  2. CordraObject object = new CordraObject();
  3. object.id="Human/001";
  4. object.type="Human";
  5. JsonObject json = new JsonObject();
  6. json.addProperty("name", "Tony");
  7. json.addProperty("description", "A hairdresser");
  8. JsonObject definitionJson = new JsonObject();
  9. definitionJson.addProperty("street_address", "No.1 Shen mei Road");
  10. definitionJson.addProperty("city", "Shanghai");
  11. definitionJson.addProperty("state", "China");
  12. json.add("address", definitionJson);
  13. object.content = json;
  14. cordra.create(object);

再来看看Human/001的创建结果
image.png

  1. 模式引用-其它模式引用

还可以对其他Cordra模式进行引用。 默认情况下,模式名可以用作$ref的相对URI。 可以包含一个JSON指针。
默认情况下,每个模式都被认为有一个基URI为/cordra/schemas/.schema。 是类型的名称。当使用$ref; 可以包含或省略文件:URI方案。 相对URI解析允许简单地使用“Person”来引用名称为Person的模式。
下面举例定义一个叫Member的类型结构

  1. {
  2. "type": "object",
  3. "required": [
  4. "name",
  5. "address"
  6. ],
  7. "properties": {
  8. "name": {
  9. "type": "string"
  10. },
  11. "address": {
  12. "allOf": [
  13. {
  14. "properties": {
  15. "kind": {
  16. "type": "string",
  17. "enum": [
  18. "residential",
  19. "business"
  20. ]
  21. }
  22. },
  23. "required": [
  24. "kind"
  25. ]
  26. },
  27. {
  28. "$ref": "Person#/definitions/address"
  29. }
  30. ]
  31. }
  32. }
  33. }

引用的Person的类型定义:

  1. {
  2. "type": "object",
  3. "required": [
  4. "name",
  5. "address"
  6. ],
  7. "properties": {
  8. "name": {
  9. "type": "string"
  10. },
  11. "address": {
  12. "$ref": "#/definitions/address"
  13. }
  14. },
  15. "definitions": {
  16. "address": {
  17. "type": "object",
  18. "properties": {
  19. "kind": {
  20. "type": "string",
  21. "enum": [
  22. "residential",
  23. "business"
  24. ]
  25. }
  26. },
  27. "required": [
  28. "kind"
  29. ]
  30. }
  31. }
  32. }

java代码:

  1. CordraClient cordra = new TokenUsingHttpCordraClient("https://127.0.0.1:8443", "admin", "admin123");
  2. CordraObject person = new CordraObject();
  3. person.id = "Person/001";
  4. person.type = "Person";
  5. JsonObject personJson = new JsonObject();
  6. personJson.addProperty("name", "Kevin");
  7. JsonObject personDefinitionJson = new JsonObject();
  8. personDefinitionJson.addProperty("kind", "business");
  9. personJson.add("address", personDefinitionJson);
  10. person.content = personJson;
  11. cordra.create(person);
  12. CordraObject member = new CordraObject();
  13. member.id = "Member/001";
  14. member.type = "Member";
  15. JsonObject memberJson = new JsonObject();
  16. memberJson.addProperty("name", "Kevin");
  17. memberJson.addProperty("description", "A hairdresser");
  18. //根据Person类型的具体对象Id获取到对象,解析拿到其address结构信息后封装
  19. CordraObject personCO = cordra.get("Person/001");
  20. memberJson.add("address", personCO.getContent(JsonObject.class).get("address"));
  21. member.content = memberJson;
  22. cordra.create(member);

最后查看Person/001和Member/001的数据结果
image.png
image.png

  • Cordra的$ref只支持JSON指针。 不支持普通名称
  • Cordra不支持使用$id或id来识别子模式(被引用模式); id是在系统级别上对Cordra来说有意义
  • Cordra UI一般不支持递归使用$ref。
  1. Format关键字

对象属性在UI的显示格式设置,数组类型array属性可以设置表格显示”format” : “table”;字符串可设置文本框显示”format” : “textarea”,或密码框显示”format” : “password”。下面以表格显示为例:
KeywordTestType类型定义

  1. {
  2. "type": "object",
  3. "required": [
  4. "name"
  5. ],
  6. "properties": {
  7. "name": {
  8. "type": "array",
  9. "format": "table"
  10. }
  11. }
  12. }

java代码:

  1. CordraClient cordra = new TokenUsingHttpCordraClient("https://127.0.0.1:8443", "admin", "admin123");
  2. CordraObject person = new CordraObject();
  3. person.id = "KeywordTestType/001";
  4. person.type = "KeywordTestType";
  5. person.content = JsonParser.parseString("{\"name\":[\"Tony\",\"Kevin\",\"Allen\"]}");
  6. cordra.create(person);

UI上查看结果:
image.png

  1. cordra关键字及下辖的模式特定属性关键字

属性可以设置一个以key值为cordra的JSON属性组,内置多个属性。

  • indexPayloads(boolean),当payload文件比较大时,设置”indexPayloads”:false将文件不作为索引存储,可以保证整个服务的搜索性能。该属性在顶层显示,作用于type
  • preview(JSON),前端显示参数组:

showInPreview(boolean):是否在查询结果或关系图中固定显示
isPrimary(boolean):设置为标题,和showInPreview组合使用
excludeTitle(boolean):不作为标题显示,和showInPreview组合使用

  • type(JSON),结构配置组:

suggestedVocabulary(enum):提供一个枚举值列表供UI操作时选择,和前面碰到过的”enum”:[“residential”,”business”]不同的是,这个参数是非强制的

autoGeneratedField(String):自动填充值,可选值handle、createdOn(creationDate)、modifiedOn(modificationDate) 、createdBy、modifiedBy;设置后在UI端就无法编辑,handle即句柄id;当选择句柄进行填充时,还可以配置
type.autoGeneratedField.prepend(string,句柄前缀,以/符号结尾)、type.autoGeneratedField.prependHandleMintingConfigPrefix(boolean,预处理前缀)一起使用,以便在存储时如何设置该属性的标识。

handleReference.types(可引用的其它types列表,为空或不设置则没有限制)
type.handleReference.excludeTypes(与上一个属性互斥,除该types列表外的类型都可引用)

type.handleReference.name(UI中如关系图中用什么来命名这个关系线),example:{{../name}}标识用引用对象的name属性

type.handleReference.prepend(string,句柄前缀,以/符号结尾)
type.handleReference.prependHandleMintingConfigPrefix(boolean,自动带/符号)

下面是前面几个属性的举例定义

  1. {
  2. "type": "object",
  3. "cordra": {
  4. "indexPayloads": false
  5. },
  6. "required": [
  7. "name",
  8. "description",
  9. "reference"
  10. ],
  11. "properties": {
  12. "id": {
  13. "type": "string",
  14. "cordra": {
  15. "type": {
  16. "autoGeneratedField": "handle"
  17. }
  18. }
  19. },
  20. "name": {
  21. "type": "array",
  22. "format": "table"
  23. },
  24. "description": {
  25. "type": "string",
  26. "cordra": {
  27. "preview": {
  28. "showInPreview": true,
  29. "isPrimary": true
  30. },
  31. "type": {
  32. "suggestedVocabulary": [
  33. "Apple",
  34. "Banana",
  35. "Orange"
  36. ]
  37. }
  38. }
  39. },
  40. "reference": {
  41. "title": "Reference",
  42. "type": "string",
  43. "cordra": {
  44. "type": {
  45. "handleReference": {
  46. "types": [
  47. "type1",
  48. "type2",
  49. "type3"
  50. ],
  51. "name": "{{../name}}"
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  • auth(JSON):权限配置,type中设置了该类型属性后,创建出的数据对象将有系统账户功能

users引用的是用户列表

  1. "users": {
  2. "type": "array",
  3. "format": "table",
  4. "title": "Users",
  5. "uniqueItems": true,
  6. "items": {
  7. "type": "string",
  8. "title": "User",
  9. "cordra": {
  10. "type": {
  11. "handleReference": {
  12. "types": [ "user" ]
  13. }
  14. }
  15. }
  16. },
  17. "cordra": {
  18. "auth": "usersList"
  19. }
  20. }

指明字段类型:username用户名、password密码、requirePasswordChange是否在每次请求前更新密码、accountActive账号是否正常、publicKey公钥字段

  1. "username": {
  2. "type": "string",
  3. "title": "Username",
  4. "cordra": {
  5. "auth": "username"
  6. }
  7. }
  8. "password": {
  9. "type": "string",
  10. "format": "password",
  11. "title": "Password",
  12. "cordra": {
  13. "auth": "password"
  14. }
  15. }
  16. "requirePasswordChange": {
  17. "type": "boolean",
  18. "title": "Require Password Change",
  19. "description": "If true a new password must be set on next authentication.",
  20. "cordra": {
  21. "auth": "requirePasswordChange"
  22. }
  23. }
  24. "accountActive": {
  25. "type": "boolean",
  26. "title": "Account active",
  27. "cordra": {
  28. "auth": "accountActive"
  29. }
  30. }
  • response.mediaType(返回信息类型)
    1. "xmlschema": {
    2. "type": "string",
    3. "format": "textarea",
    4. "title": "XML Schema",
    5. "cordra": {
    6. "response": {
    7. "mediaType": "application/xml"
    8. }
    9. }
    10. }
    还有其他一些属性可以在官网里自行查看使用方式

Design Object

服务策略配置,即希望cordra在哪种情况下运转,可配置的内容包括:ids生成规格、权限设置、前端显示规格配置、handle配置、doip配置、javascript配置、旧接口使用策略配置等。可根据业务需求或个人喜好进行这些策略规格的配置。后续篇章会着重说明下handle配置和doip配置