The SaveSchema API allows the Account Owner to create or update a Schema. Documents can be created based on the Schema to take advantage of the validation and security that the Schema offers.
In apstrata, Schemas are used to define the kind of data you expect to store for a certain business entity, along with the validation and security rules, in a declarative way. You can think of a Schema as a template for business entities. For example, you might want to have an employee entity in your application. You can define a schema for that entity, specifying that first name, last name, age, and employment date represent the data to be collected by default for each employee. For each of these employee attributes, you can associate validation and security rules. Hence, a Schema provides a uniform way of dealing with employees. Note that employee attributes that are not defined in the schema can still be persisted as part of an employee Document; however, no specific validation or security rules can be applied to them. Such fields or attributes are called dynamic fields.
Apstrata does not enforce the use of Schemas. Alternatively, you can always persist data without specifying a Schema. In this case, no security or validation rules can be applied at the level of the fields. Note that "schema-less" Documents are actually Documents with a default Schema, which gets created for each account upon registration. The default Schema is not exposed, and hence cannot be customized. The default Schema is totally based on dynamic fields, implying that no field-level security or validation rules can be applied. This "schema-less" mode is meant for prototyping and experimenting purposes. We fully recommend that business applications be built in a "schema-full" mode.
For specific details on schema creation, please check the SaveSchema API.
A simple example schema:
Schema ACL: Set read, write, delete ACLs for a schema
The developer can create a schema and specify users or groups who can read/write/delete to it. Note the <schemaACL>s:
If the user is not within the schema ACL, getSchema, and saveSchema (over existing schemas) will fail and trigger a permission denied error. Note that the user is responsible for managing the schema ACL and that schema ACLs are required. Refer to Data Security page to learn more about ACLs.
Document versioning can be set at the schema level. Versioning can be "disabled", "enabled", or "forced" and will affect documents of the schema. If not specified, versioning will be disabled. Please refer to the SaveDocument documentation for more details.
The schema sent by the user should conform to the xsd. Further restrictions include:
1. Minimum cardinality should always be less than or equal to maximum cardinality.
2. Minimum range should always be less than or equal to maximum range.
3. Range validation can be only applied to fields of type numeric.
4. Duplicate fields are not allowed.
5. All fields should belong to an aclGroup.
Specific Request Parameters
(Refer to Common Request Parameters)
Represents the full schema name that can consist of up to 5 folders and the schema file name separated by the character '/'.
The same set of rules applies to a schema name and a directory name:
Note: the full schema name including any folders must be minimum 3 characters and maximum 64 characters long.
Represents the schema xml (content)
Should be set in order to update existing schema
If apsdb.default is set to true, the parameter apsdb.schema should not be sent. If it is, an error occurs.
This is sent when the user wishes to rename the schema.
Specific Response Elements
(Refer to Common Response Elements)
Specific Logical Errors
(Refer to Common Logical Error Codes)
Cannot create schema [schemaName] because it already exists
Cannot update schema [schemaName] to [newSchemaNameParam] because it already exists.
The parameter [apsdb.schema] must not be sent if the [apsdb.default] parameter is set to 'true'
The parameter [apsdb.update] must have a value of 'true' or 'false'
The field [fieldName] of type [fieldType] is required.
The type of the [fieldName] field is invalid. it should be [fieldType].
[regex] is not a valid regex.
Incorrect cardinality validation on field [fieldName].
Incorrect range validation on field [fieldName].
Range validation can only be applied to fields of type numeric.
Field [fieldName] is duplicated.
The type of the [field] field is invalid. it should be [fieldType]
Invalid aclGroup name, \"document\" and \"default\" are reserved names.
AclGroup [aclGroupName] is duplicated.
Field [fieldName] exist in more than one aclGroup.
All fields should belong to an aclGroup.
Each field belonging to an aclGroup should be declared as a field.
Error renaming the schema [fullSchemaName] to [newSchemaNameParam]
Error parsing XML.
Invalid schema name [schemaName]. Please refer to the documentation for more details on the appropriate syntax.
The field [fieldName] is a restricted field.
The schema is being used, please delete all the documents using this schema before updating it.
Cannot find schema [schemaName]
Sample XML Response
Sample JSON Response