Upadate document in DocumentProcessor in vespa - vespa

How to add new field to existing document in DocumentProcessor when updating document using REST API.
#Override
public Progress process(Processing processing) {
for (DocumentOperation op : processing.getDocumentOperations()) {
if (op instanceof DocumentUpdate) {
DocumentUpdate documentUpdate = (DocumentUpdate) op;
// what shoud I write here to add new field with value
}
}
return Progress.DONE;
}
When I am using code below, this gives me error
DocumentUpdate upd = new DocumentUpdate(type, id);
upd.addFieldUpdate(FieldUpdate.createMap(type.getField("myStrWSet"), "foo", new AssignValueUpdate(100)));
Error : AssignValueUpdate cannot be applies to int.
And, how to create FieldUpdate object with new field and its value.
Please help.

documentUpdate.addFieldUpdate(FieldUpdate.createAssign(documentUpdate.getDocumentType().getField("myField"),
new StringFieldValue("myValue")));

Related

Azure Logic Apps can't programmatically build And / Or Condition using ASP.Net SDK

I'm programmatically building a Condition in a Logic App. If the user selects Or, I use the Or Condition. If the user selects And, I use the And Condition.
I can get Or to work by itself. I can also get And to work by itself.
public class Expression
{
public Or[] or { get; set; }
}
public class Expression
{
public And[] and { get; set; }
}
When I try to use the Expression class below, I get a "Condition has 2 top level properties. Only 1 is allowed." error.
public class Expression
{
public Or[] or { get; set; }
public And[] and { get; set; }
}
If I set one to null, I get the error. If I set one to an empty array, I get the error.
UPDATE 1
Here is the Logic App code view in Azure.
"expression": {
"and":
[
{
"contains": [
"#outputs('Compose_3')",
"foo"
]
},
{
"contains": [
"#outputs('Compose_3')",
"bar"
]
}
]
},
Does anyone know how to get this to work? Am I missing something simple here? Any help is much appreciated. Thanks in advance!
Logic App has a default AND / OR and other conditional operators. If you want to add a custom condition you can use an Azure Function. In the Azure Function, you can implement your custom requirement and it is the correct environment to implement your thoughts of logic.
You can include the Azure Function in a logic app to perform your task. Refer here
Or we have another option to implement a custom requirement which is Logic App Custom Connector. Please have a look here
I finally got this working. When you Serialize the JSON, use "IgnoreNullValues = true". This will ignore the null value this is present when you set the And or Or value in your Expression object. ReplaceFirst simply adds a "$" to the word "schema" on the first occurrence.
var options = new JsonSerializerOptions { WriteIndented = true, IgnoreNullValues = true};
string jsonString = ReplaceFirst(JsonSerializer.Serialize(myApp, options), "schema", "$schema").Replace("_else", "else").Replace("_foreach", "foreach");
string ReplaceFirst(string text, string search, string replace)
{
int pos = text.IndexOf(search);
if (pos < 0)
{
return text;
}
return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
}

.NET Tag Helper to replicate #Html.DisplayFor

I'm discovering .Net Core Tag Helpers and I was just curious to know if there are any tag helpers that replicate the #Html.DisplayFor. I think that the label tag helper replicates #Html.DisplayNameFor since it shows the property name on a model passed to the page, but is there an equivalent for #Html.DisplayFor for displaying a property value?
I'm assuming there isn't because in the microsoft .net core tutorials, razor pages that need to display the property value rather than the property name use the HTML helpers.
First, the tag helper is actually the "label asp-for". You can create a new tag helper that is a "label asp-text" helper.
Another option is to use another tag such as span and create a custom "span asp-for" tag helper.
Here is a simple span implementation:
[HtmlTargetElement("span", Attributes = FOR_ATTRIBUTE_NAME, TagStructure = TagStructure.NormalOrSelfClosing)]
public class CustomSpanTagHelper : InputTagHelper
{
private const string FOR_ATTRIBUTE_NAME = "asp-for";
public CustomSpanTagHelper(IHtmlGenerator generator) : base(generator)
{
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
var metadata = base.For.Metadata;
if (metadata == null)
{
throw new InvalidOperationException(string.Format("No provided metadata " + FOR_ATTRIBUTE_NAME));
}
if (!string.IsNullOrWhiteSpace(metadata.Description))
{
output.Content.Append(metadata.Description);
}
if (metadata.IsEnum)
{
var description = (this.For.Model as Enum).GetDescription();
output.Content.Append(description);
}
base.Process(context, output);
}
}
You will need to register your custom tag helper in your _ViewImports.cshtml like this: (don't forget to rebuild)
#namespace MyProject.Web.Pages
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
#addTagHelper MyProject.Web.TagHelpers.CustomSpanTagHelper, MyProject.Web <-- custom import

Make a list field editable when this field is a many_to_one type using in Sonata-project Symfony

My entity
/**
* #ORM\ManyToOne(targetEntity="Estat", inversedBy="temes")
*/
private $estat;
public function setEstat(\Ncd\ForumBundle\Entity\Estat $estat = null)
{
$this->estat = $estat;
return $this;
}
My admin
protected function configureListFields(ListMapper $listMapper)
{
//$estats=$this->getEstatsPossibles()->toArray();
$estats=array();
foreach($this->getEstatsPossibles() as $estat)
{
$estats[$estat->getId()]=$estat->getNom();
}
$listMapper
->add('estat', 'choice',['editable' => true,'choices'=> $estats])
I'd like to make estat field editable in the list grid. Doing it on this way I get make it editable, a combobox appears but when I chose an option I get an exception because setEstat function of my entity does not recive an Estat entity, but a string (the array's key).
Trying
->add('estat', 'many_to_one',['editable' => true,'choices'=> $estats])
Only appears a link to the entity without any possibility to change.
Is it possible?
Waiting for a better and cleaner solution I'v solved this injecting an entityManager in my entity following the solution of this answer:
Get entityManager inside an Entity
Then, in my entity I've changed setEstat function:
public function setEstat( $estat = null)
{
if (is_object($estat) && get_class($estat)=='Ncd\ForumBundle\Entity\Estat')
{
$this->estat=$estat;
} else {
$estat_o=$this->em->getRepository('Ncd\ForumBundle\Entity\Estat')->find((int)$estat);
$this->estat = $estat_o;
}
return $this;
}

CustomValidation Annotation Event Raise Issue MVVM Silverlight 5

I've Created a Model which have few custom validation. These custom validation I've annotated at property by below code
[CustomValidation(typeof(ItemmasterModel), "ValueTextMaxLenghtValidate")]
public decimal Valuetextmaxlength
{
get
{
return _Valuetextmaxlength;
}
set
{
ValidateProperty("Valuetextmaxlength",value);
_Valuetextmaxlength = value;
RaisePropertyChanged(() => Valuetextmaxlength);
}
}
public static ValidationResult ValueTextMaxLenghtValidate(object obj, ValidationContext context)
{
var itmmstr = (ItemmasterModel)context.ObjectInstance;
if (itmmstr.SelectedValuetypeDd != null)
{
string vtype = itmmstr.SelectedValuetypeDd.Key.ToString();
if (vtype.Equals("C"))
{
if (itmmstr.SelectedItemValueCodeTypesDd != null)
{
string vcode = itmmstr.SelectedItemValueCodeTypesDd.Key.ToString();
if (vcode.Equals("T"))
{
if (itmmstr.Valuetextmaxlength == null || itmmstr.Valuetextmaxlength == 0)
{
return new ValidationResult("Value Max Length is not Entered",
new List<string> { "Valuetextmaxlength" });
}
}
}
}
else if (vtype.Equals("T"))
{
if (itmmstr.Valuetextmaxlength == null || itmmstr.Valuetextmaxlength == 0)
{
return new ValidationResult("Value Max Length is not Entered",
new List<string> { "Valuetextmaxlength" });
}
}
}
return ValidationResult.Success;
}
Now this validation code depend on other property. scenerio When User select a value from dropdown it makes 1 checkbox selected automatically and User should enter the value in texbox also.
Issue:
Validation is working. checkbox is selected at first time then also it comes with error popup.
untill user doesn't make changes into this checkbox or texbox it is with error only. 1 time it says error even value has been entered .Next time it goes even user have not entered anything but during final full object validation is again comes with error.
Why this even ambiguity is happening. How to solve this.
Need more code let me know. I'll Post. Code is in Silverlight 5, MVVM Light
During my Custom validation I was using ValidateProperty("Valuetextmaxlength",value); before setting the value of property so It was giving me issue but the moment I set the value first and then Use my ValidateProperty("Valuetextmaxlength",value); everything worked smooth. Still I don't know the reason why but It worked for me.

How do you properly set a custom profile property in DNN?

I'm trying to save a custom property to an existing user profile in DNN 7, but the profile property is not getting set. I must be understanding something incorrectly.
So, how do you properly set a custom profile property in DNN?
UserInfo.Profile.SetProfileProperty("key","value")
// I expect this to return "value", but it's always ""
var value = UserInfo.Profile.GetProfileProperty("key");
// Even if I save it...
ProfileController.UpdateUserProfile(UserInfo);
// It always returns ""
var savedValue = UserInfo.Profile.GetProfileProperty("key");
Note: I also tried InitialiseProfile but that didn't change the behavior.
Here is how I am accessing a propertyvalue from a property in a module base class I have for a client.
public string SomeKey
{
get
{
var ppd = UserInfo.Profile.GetProperty("SomeKey");
if (ppd.PropertyValue == string.Empty)
{
var SomeKeyValue = "blah"
//update the user's profile property
UserInfo.Profile.SetProfileProperty("SomeKey", SomeKeyValue);
//save the user
DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, UserInfo);
//retrieve again
return SomeKey;
}
string returnValue = ppd.PropertyValue ??
(String.IsNullOrEmpty(ppd.DefaultValue) ? String.Empty : ppd.DefaultValue);
return returnValue;
}
}

Resources