How can I set validation and default value in proto3? - protocol-buffers

I'm trying to add default value to an optional field alongside with validation, but could not find any infos in the docs for multiple conditions in a proto field.
This is the example:
optional string date = 1 [(validate.rules).string = { pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|[+,-][0-9]{2}:[0-9]{2})"}];
After this I'd like to add a [default = "0001-01-01T00:00:00Z"].
How can I perform this?

Related

Filebeat Script Processor Event.Get All Fields In Log

I am looking to get all of the fields in a record in filebeat using the Script processor and perform an action on them. Using the event.Get() from the script processor, it says, "Get a value from the event (either a scalar or an object). If the key does not exist null is returned. If no key is provided then an object containing all fields is returned."
https://www.elastic.co/guide/en/beats/filebeat/current/processor-script.html
Therefore, my question is, what would I do to ensure that no key is provided to get an object that contains all of the fields are returned?
The event.Get() field will provide the top level fields. To look through these top level fields, use a for loop like:
- script:
lang: javascript
id: get_fields
source: >
function process(event) {
var a = event.Get();
for (var key in a) {
if(event.Get(key) == ""){
event.Delete(key);
}
}
}
I am unsure how to do this for nested fields in this way nor have I tried to extend it to nested fields, but this is how it works for now.

Django rest framework mongoengine update new field with default value

I'm using Django rest framework mongoengine after created few documents, if i want add a new field with default value. Is there any way to do that orelse i need to update with few custom function.
Note: I want to fetch the data with filter having a new field name. That time the field is not there. So i'm getting empty.
From what I understand, you are modifying a MongoEngine model (adding a field with a default value) after documents were inserted. And you are having issue when filtering your collection on that new field.
Basically you have the following confusing situation:
from mongoengine import *
conn = connect()
conn.test.test_person.insert({'age': 5}) # Simulate an old object
class TestPerson(Document):
name = StringField(default='John') # the new field
age = IntField()
person = TestPerson.objects().first()
assert person.name == "John"
assert Test.objects(name='John').count() == 0
In fact, MongoEngine dynamically applies the default value when the field of the underlying pymongo document is empty but it doesn't account for that when filtering.
The only reliable way to guarantee that filtering will work is to migrate your existing documents.
If its only adding a field with a default value, you could do this with MongoEngine: TestPerson.objects().update(name='John')
If you did more important/complicated changes to your document structure, then the best option is to get down to pymongo.
coll = TestPerson._get_collection()
coll.update({}, {'$set': {'name': 'John'}})

How to check a field value is must be a string when it filled out in laravel 5.4 validator

I have a field called middle name which is an optional field. I want to check this field if it has some value otherwise I dont want to check this field value.
How can I do this in laravel 5.4 validator.
String is an object type its not primitive type like integer or char. I didn't check how laravel handles this validation but based on documentation you have to put nullable. Probably because string returns an object with empty attribute. so #Gaurav Gupta's answer not going to work.
The field under validation must be a string. If you would like to
allow the field to also be null, you should assign the nullable rule
to the field.
'middle_name' => 'nullable|string'
you can just simply write
'middle_name' => 'nullable|string',
in your validation array it check only when some value exits .Means it not required value

How to retrieve both value & currency type from currency type attribute

In MS Dynamics CRM 2013 I am trying to get the value & currency type from a currency type attribute using LINQ.
By this code I can only get the value.
actualvalue = (Money)opportunity.GetAttributeValue("actualvalue")
Can anyone suggest how to get the currency associated with this attribute, I need to use LINQ only.
The currency is stored inside the transactioncurrencyid field. It's a lookup so by code is an EntityReference.
var currencyRef = (EntityReference)opportunity.GetAttributeValue("transactioncurrencyid");
after you can retrieve the currency details using the Id property (so will be like currencyRef.Id)
Get and Set Currency(Money) using C#
Get:
var moneyValue = ((Money)item.Attributes[attributeName]).Value;
Set:
newSalesOrder[attributeName] = new Money((decimal)moneyValue);

grails integer field default validation

I have a grails domain class that looks like:
class Person {
String name
int age
}
When I show the default "create" view (using scaffolding), the age field shows as a required field (with an asterisk next to it). Is there a way to make it show up as non-required and default to blank?
I've tried adding
constraints = {
age blank:true, nullable:true
}
This results in the field being allowed to be empty but it still shows up with the asterisk next to it.
An int is a primitive type and cannot be blank. You would have to change it to an Integer, then a null value would mean that it's blank.

Resources