Hello,
AEM: 6.2
I have a use case where on inject properties of a component, my sling model executes a @PostConstruct method to configure a state of content by setting a node property value. For example:
@PostConstruct
protected void setProperty() {
try {
ModifiableValueMap map = this.resource.adaptTo(ModifiableValueMap.class);
(*) map.put("customProperty", "initalStateValue");
resource.getResourceResolver().commit();
} catch (PersistenceException e) {
LOGGER.error(e);
}
}
Now, when i publish a page which uses this AEM component, the anonymous user on the published site gets an error message:
Post-construct method has thrown an exception for model class
On further analysis: I have found that since "anonymous" user does not have permissions to write on /content nodes, the statement marked above with an (*) sets map object to null.
My Question is: Is there a better implementation pattern to achieve the scenario of configuring the state of content node such that the state of the content can be set through node property only for authors?