ValueMap - Content node updation - @PostConstruct only on Author

Avatar

Avatar

sud_varun

Avatar

sud_varun

sud_varun

15-09-2016

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?

Replies

Avatar

Avatar

Tuhin_Ghosh

Avatar

Tuhin_Ghosh

Tuhin_Ghosh

18-09-2016

Hi sud.varun,

this is a duplicate question to "http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage..." initiated by you. Since that one had some response please follow up on that one and kindly close this one.

Thanks

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

19-09-2016

Via runmodes you can have this code only run on your author instance.