Is there a way to modify a JCR node without changing its timestamp? - aem

Is there a way to modify a JCR node, but keep its jcr:lastModified and jcr:lastModifiedBy properties unchanged?
And by modifying, I mean via the JCR API. For example:
aNode.setProperty("propName", aValue);

It is possible for the most cases. There are basically two options how a node retrieves both properties and get's them updated.
Either through some higher level API like CQ's PageManager, which is applying it on the jcr:content node or by the repo if the node has the mixin type mix:lastModified in it's type hierarchy.
[mix:lastModified]
mixin
- jcr:lastModified (DATE) autocreated
- jcr:lastModifiedBy (STRING) autocreated
In this case the properties are automatically managed through the repository.
So you should be fine, as long as you avoid to create nodes with the mentioned mixin in it's type hierarchy e.g. nt:resource.

Related

How to pass query parameter to Sling model exporter

I have to implement one API where the API should export the JSON data. For example, there is one container component and many child components. Lets suppose, container component is holding the country and child component is strong different states and its population etc.
So the responsibility of the API is to search the population based on the state name or other query parameter.
One of the option I am thinking about using Sling model exporter because I do not have to write Sling servlet and it is easy to export the child components as json but the problem is, I could not find an option to pass request parameter to Sling model.
For example http://some.com/country/jcr:content/parent-component.model.json will give the result of child components but here how can I pass request parameter to this model endpoint for a specific state?
I know its possible to create a sling servlet but is it possible to do it using Sling model exporter?
You can inject the SlingHttpServletRequest in your model, and get the request parameter there from. Either in the getters or in your #PostConstruct method.
But there are no injectors available for the RequestParameters. This was for security reasons. So if you just use #Inject, then it just cannot happen that unwanted values are injected.
PS: The #RequestAttribute injector is for request-attributes, which are NOT query parameters.
I did face exactly the same issue and looks like the sling model exporter is dropping the parameters however I was able to solve this using request.getHeader("referrer") which gives us the complete URL including the parameters from which we can extract parameters.

Is all DOM nodes inherit from DOM Node interface?

I'm confusing about this point since almost all DOM nodes are some sub-interface of the Node interface, but I can't find the precise definition that can prove this. Is there anybody know more about this? thanks.
Yes, all nodes inherit from the DOM Node interface:
The following interfaces all inherit from Node’s methods and properties: Document, Element, CharacterData (which Text, Comment, and CDATASection inherit), ProcessingInstruction, DocumentFragment, DocumentType, Notation, Entity, EntityReference
And also, according to W3:
The Node interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree. While all objects implementing the Node interface expose methods for dealing with children, not all objects implementing the Node interface may have children. For example, Text nodes may not have children, and adding children to such nodes results in a DOMException being raised.

How to set attribute value to instance of class at runtime

I'm on Enterprise Architect 14. I have a component diagram containing an interface User and two classes Employee and Customer, which both realize interface User.
Furthermore I created two instances, one of each class and specified the values of the attributes via Features & Properties > Set Run State....
Next I created a component with 2 attributes, one of type Employee and one of type Customer. Then I created an instance of the component.
Now I would like to set run state of the component instance by assigning ArbitraryUser to the Employee attribute and ArbitraryCustomer to the Customer attribute of the component instance. According documentation this should be possible (see here).
At run-time, an Object instance can have specific values for its attributes, or exist in a particular state. To model the varying behavior of Objects at run-time, use instance values selected from the 'Select ' dialog and run-time states or run-states.
However I could not figure out how to do so. Can someone help me?
AFAIK that is not possible.
I'm not sure what the quote from the help really means, but I've only ever been able to type a value for the run state.
An partial alternative would be to use associations rather than attributes to model such relations. Then you can create a link as an instance of the association to relate instances of Employee or Customer with instances of a ArbitraryComponent.
This solution doesn't work for datatypes, but it seems a bit far fetched to start modelling instances of datatypes.

OCM or Nodes in JCR?

We are developing a CMS based on JCR/Sling/JSP/Felix/etc.
What I found so far is using Nodes are very straight forward and flexible. But my concern is over time it could become too hard to maintain and manage.
So, is it wise to invest in using a OCM? Would it be just an extra layer of complexity? What's the real benefit in OCM if there's any? Or it's better for us to stick to Nodes instead?
And lastly, is Jackrabbit OCM the best option for us if we are to go down that path?
Thank you.
In my personal experience I can say it severly depends on your situation if OCM is a useful tool for your project or not.
The real problem in using OCM (in my personal experience) is when the definition of a class used in existing persisted data (as objects) in the repository has changed. For example: you found it necessary to change some members and methods of a class to match with functionality changes. By this I mean that the class definition of the persisted data object in the repository no longer matches the definition of actual class. When a persisted data is saved to the jcr repository it is usually saved in a format that java understands in terms of serialization. Which means that when something changes to the definition of the used class, the saved data in the repository can no longer be correctly interpreted by java. This issue tends to lead to complex deployment where you need to convert old persisted data objects to the new definition and save them again in the repository to make sure you can still use "old" but still required persisted data.
What does work (in my opinion) is using a framework that allows to map nodes and node properties to java objects directly (for example by using annotations) and the other way around (persist a java object to the repository as a JCR node where the java member fields are actual node properties). This way you stick to the data representation of jcr (nodes with properties) and can still map them to the members of a java class.
I've used a framework like this in a cms called AEM (of Adobe) before, although I must mention this is in a OSGI context (but the prinicipe still stands). The used framework basically allowed maximum flexibility and persists the java object as a JCR node and the other way around. Because it mapped directly to the jcr definition, code changes in the class and members ment just changing annotations, and old persisted data was still usuable without much effort.

when do we draw association?

Class Engine has "start(c:Component)" method. So do we need to draw an association between Engine and Component Class IF there is no "new Component()" inside Engine class.
No, you do not in general need to have an association to a type even if the type is mentioned in a parameter. It entirely depends on if the state of an Engine maintains a relationship with one or more Components.
If the Component you passed around is only use locally in method start, then there is no real association that persists from one state (one method call) to the next.
This is not an association, it´s a dependency relationship between the two. A dependency means that if the dependee (the Component in your case) changes the depender (the Engine) may become affected (maybe Engine::start was using a Component method that it is no longer available or that has changed its parameters)