Avro Schema Data Validations with Regular Expressions in Java - java

I'm very new to Using AVRO Schema and I have a use case where I need to validate AVRO schema data with regular expressions. I mean the field value can allow Numbers OR only allow Alphabets OR AlphaNumeric values OR fixed min-max length etc. I tried like below but it's not working. if any idea please assist me for the same .
AVRO schema is :
{
"type": "record",
"name": "Employee",
"namespace": "com.test.avro",
"fields": [
{
"name": "empId",
"type": "string",
"pattern": "[1-9]"
},
{
"name": "empName",
"type": "string",
"pattern": "[a-zA-Z]"
},
{
"name": "createdDate",
"type": "string",
"pattern": "^[1-9]$"
},
{
"name": "mobile",
"type": "string",
"pattern": "^[1-9]*$"
}
]
}
Thanks in Advance.

Related

Json Schema to json conversion library in java or groovy

I have Json schema as input I want to know whether there is a method by which I can generate sample json output. Do we have any such library in java which I can use?
{
"title": "InputSchema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
}
},
"required": ["firstName", "lastName"]
}
output =>
{
"firstName" : "FirstName",
"lastName" : "LastName"
}

Alfresco Rest api get document shared link

I need to share and unshare the content in alfresco using Rest API,
I read the sharedLinks documentation but I don't know how to retrieve the document url I want to share.
This endpoint return an object with this properties :
{
"entry": {
"id": "string",
"expiresAt": "2022-03-23T18:16:00.603Z",
"nodeId": "string",
"name": "string",
"title": "string",
"description": "string",
"modifiedAt": "2022-03-23T18:16:00.603Z",
"modifiedByUser": {
"displayName": "string",
"id": "string"
},
"sharedByUser": {
"displayName": "string",
"id": "string"
},
"content": {
"mimeType": "string",
"mimeTypeName": "string",
"sizeInBytes": 0,
"encoding": "string"
},
"allowableOperations": [
"string"
],
"allowableOperationsOnTarget": [
"string"
],
"isFavorite": true,
"properties": {},
"aspectNames": [
"string"
],
"path": {
"elements": [
{
"id": "string",
"name": "string",
"nodeType": "string",
"aspectNames": [
"string"
]
}
],
"name": "string",
"isComplete": true
}
}
}
How can i retrieve the path from the response?
Is there another way to get the effective complete shared link for a document ?
The response returns you an ID of the share link.
Example: "id": "riqJ3xV3M4RNxJm6Haa7-w"
Use this ID to access the share link :
https://your.alfresco.domaine/share/s/riqJ3xV3M4RNxJm6Haa7-w
You can also use this web service : emailSharedLink to send an email with the link to the shared document.

How to validate a field to have specific value only in AVRO Schema

I am using Avro Schema to validate my schema is:
{
"name": "Example",
"type": "record",
"fields": [
{
"name": "custId",
"type": "string"
},
{
"name": "danger",
"type": {
"type": "enum",
"symbols": [0,1,2,3],
"name": "danger"
}}
]
}
i have a requirement where i want field "danger" to have values 0,1,2,3 . If something else is given schema should not validate it. I know enum type are used for that but it allow only string.
How can i achieve this.

Apache Avro - Complex type in Avro's Map values

Can I have a complex type in an Avro's map value?
Example:
{
"type": "record",
"default": null,
"name": "Student",
"namespace": "com.schema",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "age",
"type": "int"
},
{
"name": "grades",
"default": null,
"type": ["null", {"type": "map", "values": ["null","string", "int"]}]
}
]
}
{"type" : "map", "values" : "Student"}
I tried to insert the record creation directly on the values. It's compile and creates the class, but when I try to send a message, I have an exception: org.apache.avro.UnresolvedUnionException: Not in union

How can I get Avro SchemaBuilder to build a schema of a map between two 'records'?

Trying to serialize Java Objects represented as a Map. This requires me to build an Avro Schema first. I am using Avro SchemaBuilder for schema generation. Have already succeeded in schema generation for Map's objects. However can't deal with schema building for overall Map.
Final schema should look like the following (created this one manually):
{
"type": "record",
"name": "MapObject",
"namespace": "test",
"fields": [
{
"name": "CacheMap",
"type": {
"type": "map",
"values": [
{
"type": "record",
"name": "User",
"namespace": "test",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "status",
"type": "string"
}
]
},
{
"type": "record",
"name": "UserKey",
"namespace": "test",
"fields": [
{
"name": "key",
"type": "long"
},
{
"name": "keyPrint",
"type": "string"
}
]
}
]
}
}
]
}
How can I pass to different records for key and value of a map in SchemaBuilder?
SchemaBuilder.map().values() does not allow to pass more than one Schema as a parameter for .value().
Apache Avro Unions can be of help here.
SchemaBuilder.builder()
.map()
.values(SchemaBuilder.unionOf().type(firstSchema).and().type(secondSchema).endUnion());
where the firstSchema and the secondSchema are separate schemas already defined for required User and UserKey 'records' (considering the schema from question)

Categories

Resources