Dynamic attributes in katharsis resource - katharsis

Is it possible to use a map to specify attributes in a katharsis model class. Ive tried adding a Map property with annotation #JsonAnyGetter but that just includes the map as an atrtribute rather than specifying the attributes themselves.

There's an issue concerning this feature: https://github.com/katharsis-project/katharsis-core/issues/267

Related

How to access parent node properties in sightly?

We'l do in cq5(jsp) by accessing currentNode.getParent().getProperties();
How can we do similar thing in sightly?
You will need to implement a use class extending WCMUsePojo class or a sling model that exposes a method that returns you the properties of the parent node/resource.
Refer here for sling models, also refer to similar question here
You can still access these by ${currentNode.parent.properties}. Unfortunately this will return a PropertyIterator (see docs) and data-sly-list does not currently offer support for iterators.
So you will need to implement a Use API helper to gather those into a collection.
Just use
${currentPage.parent.properties['jcr:title']} or ${currentPage.parent.title}

How does Jackrabbit generate jcr:uuid (in AEM)?

I am trying to create an auto-generated GUID property on all cq:PageContent nodes. This will be similar to the jcr:uuid property, but will be persisted with content promotion/replication/package installs (whereas the jcr:uuid for a content item changes between different environments).
I am trying to determine how AEM/JCR generates the jcr:uuid property on node creation. The CND defining the property is:
[mix:referenceable]
mixin
- jcr:uuid (string) mandatory autocreated protected initialize
I've tried defining my GUID property in a similar manor, specifying the autocreated and initialize attributes, but this did not result in auto-generation of the property.
Could anybody point me to the source of the jcr:uuid's generation?
As an aside, I asked a related question on the Adobe Community Forum: http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.5_ciot.html/forum__bnxr-i_am_tryingtocreat.html
You don't mention which version of AEM (so whether you're dealing with Jackrabbit or Oak), but the mechanism turns out to be basically the same.
When assigning a default value, there are a few hard-coded system property names that get special treatment (jcr:uuid being one of them). If the name of the property being assigned a default value doesn't match any of the special cases, it falls back the static list of default values from the property definition (e.g. listed in the CND file).
In summary, it looks like you cannot piggy-back on this mechanism to assign your own dynamic default value for an arbitrary property. You would need to implement your own event listener or something.
Jackrabbit: See the implementation of setDefaultValues and computeSystemGeneratedPropertyValues
Oak: See the implementation of TreeUtil autoCreateProperty

How to disable automapping of properties in Entity Framework

I've decided to use fluent mapping in Entity Framework. My intention was to map everyting by code without any atributes and auto mapping functions. Best way I've found is class EntityTypeConfiguration, that I implement for each entity in my project.
Later I add property to one of my entity. This property isn't needed to be persisted. I've expected, that until I add mapping for this property, it will be ignored by database and persistence layer. Unfortunatly it doesn't work that way, and property is mapped. Only way is to use Ignore method or NotMapped attribute, but I don't want to do it explicitly.
Is there any way, to stop Entity Framework from automapping? I've tried to remove all Conventions from DbModelBuilder, but it doesn't help.
So far as I am aware, there is no other way around it. You need to use either Ignore() or [NotMapped]. I tend to prefer the former as it does not clutter up the model.
Actually I have tried a lot of ways:
- custom convention to remove mapped properties
- removing all conventions
But the easiest (and cleanest) way was to use reflection inside the mapping class and to disable all property mappings that weren't configured.
The code for that (and also an usage example) is inside my public gist.
https://gist.github.com/hidegh/36d92380c720804dee043fde8a863ecb

Structural design pattern for MVVM View Model?

Are there any recommended structural design patterns for MVVM view models that allow different state and functionality to be added to a base object dynamically, but still maintaining the INotifyPropertyChanged on all the related properties? Something like a decorator pattern but mvvm-ready?
Yes. The WPF binding system will use a custom type descriptor to interact with the properties of your ViewModel at runtime. I've used this before to make keys in a KeyValueCollection<T> appear as properties on the collection.
This has two important benefits. It simplifies binding:
DataContext.SomeCollectionProperty[SomeKey] can be simplified to DataContext.SomeCollectionProperty.SomeKey and, if you make a custom type descriptor for the data context, DataContext.SomeKey which is about as simple as it gets.
And it fixes what I consider a bug--format strings are rendered even when the property is null. Using a CTD, you can skip null (and DBNull) properties, ensuring that format strings won't be rendered if the property doesn't exist:
Imagine you have a double? that you must render as a dollar amount. If you use the following binding: {Binding Price, FormatString='Price: {0:c}'} and the Price is null, you get the following in your UI: Price: $. This is ugly. However, if Price is a PropertyDescriptor-based property on your UI, when the Price is null, you can opt to not to report this property via your CTD. This prevents the format string from being rendered at all.
Here's a pretty good link at MSDN about decorating your types with a CTD.
From my experimentation, you can use the ExpandoObject in .NET 4 to handle what you want. ExpandoObject implements INPC. I've been creating a DynamicViewModel based on the ExpandoObject that does a few other things like calculated Properties that have dependencies on each other and Delegate Command registration.

Entity Framework 4.0: Create an unmapped property in the model (currenty i get : error 11009 - Property is not mapped)?

I know that i can enter/add new properties via code manually into partial classes but i wanted to use the model to add my new properties - reason being is that i can control a number of different attributes like NULL and things like that... and of course the code generations works great..
I added some foreign keys manually just on the model and they work great.
But everytime i add a SCALER PROPERTY i get an error in vs 2010 which says
Error 2538 Error 11009: Property 'testprop' is not mapped.
I can't believe i must map a custom property that i created to a column in the db.... is there no way to say "IGNORE" this property or treat as an unmapped property??
This way my code generation will create the required items BUT i don't get the error
Any help on this would be really helpful.
As i say i know i can edit things manually but wanted to update the model rather than edit a partial class....
I am sure i am missing something obvious?
With EntityFramework 5 you can use the NotMappedAttribute for unmapped properties. So, you can migrate to EF5 or use partial classes on EF4.
I believe that EF will on allow you to use the Model Designer to map to something that exists. If you want to create a property that doesnt exist, you'll have to use the partial class.
I had the same error - you can use the NotMappedAttribute for unmapped properties...