MVCSiteMapProvider overriding GetDynamicNodeCollection with multiple requests - mvcsitemapprovider

I am using MVCSiteMapProvider for MVC5. I have created my own implementation of DynamicNodeProviderBase to dynamically create nodes in my site map based on a collection of categories for our product catalogue.
I am using SimpleInjector and have a MvcSiteMapProviderContainerInitializer that I pull from the sample project for the site map provider. This is working fine.
However, when calling Html.MvcSiteMap().SiteMapPath() this results a call to GetDynamicNodeCollection for every request. Can the dynamic node collection be done once per lifetime of the container rather then on a per request basis?
Thanks in advance

The class I have implemented is actually created as a singleton, so for now I have initialised the nodes collection from within the constructor. This will do now.
However, I saw this blog post from 2012 but the interface seems to have changed in later versions of the provider so this is no longer possible
http://xharze.blogspot.co.uk/2012/04/inside-mvcsitemapprovider-part-2.html?m=1

Related

How to create object together with related object in same POST method using Flask-rest-jsonapi / JSON API?

I have a scenario where i would like to create one new parent object with new child object using FLASK-REST-JSON API package . e.g
Scenario like to create a new Person with new computer in one POST method itself.
As per official documentation , we can create new person and new computer using separate POST and then link them together using relationships.However i would like to create both objects together in same POST method.
Please let me know is it possible ? If yes,any example would be great .
Thanks !
Creating multiple resources with one request is not supported by JSON:API spec v1. There are some discussions to add support for such as an extension in upcoming v1.1: Introduce Atomic Operations extensions. There was an old extension called Bulk extension some time ago but that was experimental and the design of extensions has changed a lot by then.
I don't think any of these proposals / experiments have been implemented in Flask-REST-JSONAPI.

How to retrieve post data, validate it in controller and save it in database using GORM in Micronaut?

I come from Grails background and have recently started a project in Micronaut using GORM.
I tried to find required information in documentation but its not clear how we retrieve post data in controller, validate it similar to Command Objects offered in Grails and save it into database using interface service provided in documentation
PS : I know I can map every field to action argument in controller, and also declare a interface method specifying each argument as property but that does not seems right thing to do as my domain class has so many properties.
Making the action #Transactional or any method would work for saving data as far as I know but I want to know the proper way in Micronaut.
My requirement is simple, save post data in database using GORM in Micronaut.
If I were you I would look back at the documentation, sections 6.4 to 6.11:
https://docs.micronaut.io/snapshot/guide/index.html#binding
https://docs.micronaut.io/snapshot/guide/index.html#datavalidation
http://hibernate.org/validator/
Micronaut is very annotation based, unlike Grails which uses convention over configuration. However in Grails 4, Micronaut will toke over the application context, giving you some of the benefits of Micronaut, but still maintaining the convention over configuration.

Fetching Initial Data from CloudKit

Here is a common scenario: app is installed the first time and needs some initial data. You could bundle it in the app and have it load from a plist or something, or a CSV file. Or you could go get it from a remote store.
I want to get it from CloudKit. Yes, I know that CloudKit is not to be treated as a remote database but rather a hub. I am fine with that. Frankly I think this use case is one of the only holes in that strategy.
Imagine I have an object graph I need to get that has one class at the base and then 3 or 4 related classes. I want the new user to install the app and then get the latest version of this class. If I use CloudKit, I have to load each entity with a separate fetch and assemble the whole. It's ugly and not generic. Once I do that, I will go into change tracking mode. Listening for updates and syncing my local copy.
In some ways this is similar to the challenge that you have using Services on Android: suppose I have a service for the weather forecast. When I subscribe to it, I will not get the weather until tomorrow when it creates its next new forecast. To handle the deficiency of this, the Android Services SDK allows me to make 'sticky' services where I can get the last message that service produced upon subscribing.
I am thinking of doing something similar in a generic way: making it possible to hold a snapshot of some object graph, probably in JSON, with a version token, and then for initial loads, just being able to fetch those and turn them into CoreData object graphs locally.
Question is does this strategy make sense or should I hold my nose and write pyramid of doom code with nested queries? (Don't suggest using CoreData syncing as that has been deprecated.)
Your question is a bit old, so you probably already moved on from this, but I figured I'd suggest an option.
You could create a record type called Data in the Public database in your CloudKit container. Within Data, you could have a field named structure that is a String (or a CKAsset if you wanted to attach a JSON file).
Then on every app load, you query the public database and pull down the structure string that has your classes definitions and use it how you like. Since it's in the public database, all your users would have access to it. Good luck!

Liferay model listener ordering

Following is my requirement :
Whenever site is created, with help of GroupListener we are adding some custom attributes to created site.
So assume that you are crating "Liferay Test" site then it will have some fix custom attribute "XYZ" with value set in GroupListeners onAfterCreate method.
I can see this value in custom fields under site settings.
Now based on this values, we are creating groups in another system(out of liferay, using webservices).
So far so good.
Whenever we are deleting the site we need to remove the equivalent groups from other system via web service.
But while deleting site, in GroupListener we are not able to retrieve the custom attributes.
On further debug by adding expando listener, I observed that Expando listeners are getting called first and then delete method of GroupLocalService/GroupListener.
And hence we are not able to delete the groups present in another system.
So I was wondering if we can have ordering defined for listeneres.
Note: Since we were not getting custom attributes in listeners we implemented GroupLocalServiceImpl and with this we are getting custom attributes in delete method on local environment but not on our stage environment which has clustering.
You shouldn't use the ModelListeners for this kind of change, rather create ServiceWrappers, e.g. wrap the interesting methods in GroupLocalService (for creation as well as deletion).
This will also enable you to react to failures to create records in your external system etc.

Restkit: GET remote linked object when foreign key refers to missing local object in Core Data

I cannot figure out if Restkit is able to download an object not present locally, in particular when a foreign key is referring to that missing object in a to-one relationship in Core Data.
Take the following example:
- contact 1 refers to company 2
contact 1 is present in the local db but company 2 is not
when in the UI the user inspects the details of contact 1, then a GET for the contact 1 is performed
the GET returns a JSON containing among other contact details the property company_id = 2
I have already setup Restkit via the foreign key convention where I store the foreign key in the contact object (companyID) and I link it to the remote identifier (identifier) stored in the company object:
[contactResponseMapping addConnectionForRelationship:#"forCustomer" connectedBy:#{#"companyID" : #"identifier"}]
I do not manage in this case to configure restkit to download the entity (referred to by the company_id) if not present in the local db.
Is this possible?
The alternative workaround would be to override the companyID setter and double check if the entity exists and if not download the entity, although this is not desirable to me as I have setup an engine that everytime that an object is edited receives a notification and post it to the server. This means I'd have to block the thread execution until the linked object is downloaded.
Also is this mechanism called lazy loading? or hydrating entities?
I cannot find any other similar cases around.
Hope you can help, going a bit crazy on this.
Thanks a lot.
PS: I am using restkit 0.21.0 (i.e. the latest development release which Blake Watters confirmed to be stable)
This is not a feature that RestKit currently offers (probably because of the types of issues you discuss).
For your workaround, consider what your engine is doing in relation to relationship edits - how are they pushed back to the server? Are they always pushed?
Also, think about creating stub objects for your 'foreign' objects so that at least some representation always exists (there are a couple of ways to do this, you can setup mappings to accomplish the task). Then when you come to use one of these objects you can hydrate / lazy load it.
See also Clarifying terminology : "Hydrating" an entity : Fetching properties from the DB.

Resources