{"id":132,"date":"2019-08-26T08:15:31","date_gmt":"2019-08-26T08:15:31","guid":{"rendered":"http:\/\/lhotsetechnologies.com\/blog\/?p=132"},"modified":"2019-09-19T13:12:49","modified_gmt":"2019-09-19T13:12:49","slug":"ocd-issue-with-activate-annotation","status":"publish","type":"post","link":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/","title":{"rendered":"OCD issue with @Activate annotation"},"content":{"rendered":"<p>In this blog, I will explain a very common error made by AEM developers during the development of OSGi Components. So most of the AEM developers those earlier used Felix SCR annotation for OSGi component creation, made this common mistake.<\/p>\n<p>&nbsp;<\/p>\n<p>Here are some common issue statements said by AEM developers.<\/p>\n<ol>\n<li>Some developers said that during component activation configuration values are not getting applied firs time.<\/li>\n<li>Some developers said that their OSGi component is not working for the first time and after that, it is working fine.<\/li>\n<li>Some developers said that we are adding log message in @Activate method having @Modified annotation as well and the first time I am getting two log messages print in my log file. After that, I am getting one log message.<\/li>\n<li>Some developers say that-<br \/>\nWhen we were creating a component using Felix SCR annotation we normally used @Properties annotation or @Property annotation for adding configurations. We used @Activate annotation on the method which we want to call at the time of component activation. when all code builds for the first time all the properties got populated with default values and it works. But now, we are using OSGi annotations in place of Felix SCR annotations. So, in OSGi components, we use OCD configurations for our component. But our code is not working as expected. We are not getting values at the time of activation after that we are getting the values.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong>Here is the reason for all of these issues-<br \/>\n<\/strong><span style=\"font-size: inherit;\">OSGi components got installed first and activated before activation of these OCD configurations. So that @Activate method got called before the population of OCD configuration with default values. That&#8217;s why OSGi component found null or blank values for the first time.<\/span><\/p>\n<p>The actual process of these OCD configurations activation is &#8211; First they got installed and activated and they got modified with default values. So if you add a log message in a method having @Activate and @Modified annotation than when the code got deployed you will see 2 log messages in the log file for the first time only. one for activation and second for modified event.<\/p>\n<p>So if you want to do some configuration at the time of activation it will be triggered with empty or null values.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>What is the best way to deal with it?<br \/>\n<\/strong><span style=\"font-size: inherit;\">In place of @Activate annotation only use @Modified annotation on your method and build the code. Then you will see your method will work fine.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>What if I want to perform a one-time activity at the time of code installation?<br \/>\n<\/strong><span style=\"font-size: inherit;\">In this case, the developer can use normal java practice and can add a flag with true or false values. For the first time keep its value as false and once the @Modified method runs for the first time change it&#8217;s value to true and for next time check this flag value and don&#8217;t perform the same activity for next times.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Happy Coding<\/strong><br \/>\n<strong>Namah Shivay<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, I will explain a very common error made by AEM developers during the development of OSGi Components. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168,167],"tags":[],"class_list":["post-132","post","type-post","status-publish","format-standard","hentry","category-aem-ocd-configuration","category-osgi-configuration"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>OCD issue with @Activate annotation - AEM Blog | Lhotse Technologies<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OCD issue with @Activate annotation - AEM Blog | Lhotse Technologies\" \/>\n<meta property=\"og:description\" content=\"In this blog, I will explain a very common error made by AEM developers during the development of OSGi Components. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/\" \/>\n<meta property=\"og:site_name\" content=\"AEM Blog | Lhotse Technologies\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-26T08:15:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-19T13:12:49+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/person\/d1daa7081420d3cf2a02c309ee3f5800\"},\"headline\":\"OCD issue with @Activate annotation\",\"datePublished\":\"2019-08-26T08:15:31+00:00\",\"dateModified\":\"2019-09-19T13:12:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/\"},\"wordCount\":502,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#organization\"},\"articleSection\":[\"AEM OCD Configuration\",\"OSGI Configuration\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/\",\"url\":\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/\",\"name\":\"OCD issue with @Activate annotation - AEM Blog | Lhotse Technologies\",\"isPartOf\":{\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#website\"},\"datePublished\":\"2019-08-26T08:15:31+00:00\",\"dateModified\":\"2019-09-19T13:12:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/lhotsetechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OCD issue with @Activate annotation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#website\",\"url\":\"https:\/\/lhotsetechnologies.com\/blog\/\",\"name\":\"AEM Blog | Lhotse Technologies\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/lhotsetechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#organization\",\"name\":\"AEM Blog | Lhotse Technologies\",\"url\":\"https:\/\/lhotsetechnologies.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/lhotsetechnologies.com\/blog\/wp-content\/uploads\/2019\/07\/lhotse-logo.png\",\"contentUrl\":\"https:\/\/lhotsetechnologies.com\/blog\/wp-content\/uploads\/2019\/07\/lhotse-logo.png\",\"width\":539,\"height\":172,\"caption\":\"AEM Blog | Lhotse Technologies\"},\"image\":{\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/person\/d1daa7081420d3cf2a02c309ee3f5800\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/829547de0cecf5477afeaf7ff2a49fc87a026be43cb5403fa54d0fd419192479?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/829547de0cecf5477afeaf7ff2a49fc87a026be43cb5403fa54d0fd419192479?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/lhotsetechnologies.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OCD issue with @Activate annotation - AEM Blog | Lhotse Technologies","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/","og_locale":"en_US","og_type":"article","og_title":"OCD issue with @Activate annotation - AEM Blog | Lhotse Technologies","og_description":"In this blog, I will explain a very common error made by AEM developers during the development of OSGi Components. [&hellip;]","og_url":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/","og_site_name":"AEM Blog | Lhotse Technologies","article_published_time":"2019-08-26T08:15:31+00:00","article_modified_time":"2019-09-19T13:12:49+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/#article","isPartOf":{"@id":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/"},"author":{"name":"admin","@id":"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/person\/d1daa7081420d3cf2a02c309ee3f5800"},"headline":"OCD issue with @Activate annotation","datePublished":"2019-08-26T08:15:31+00:00","dateModified":"2019-09-19T13:12:49+00:00","mainEntityOfPage":{"@id":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/"},"wordCount":502,"commentCount":0,"publisher":{"@id":"https:\/\/lhotsetechnologies.com\/blog\/#organization"},"articleSection":["AEM OCD Configuration","OSGI Configuration"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/","url":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/","name":"OCD issue with @Activate annotation - AEM Blog | Lhotse Technologies","isPartOf":{"@id":"https:\/\/lhotsetechnologies.com\/blog\/#website"},"datePublished":"2019-08-26T08:15:31+00:00","dateModified":"2019-09-19T13:12:49+00:00","breadcrumb":{"@id":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/lhotsetechnologies.com\/blog\/ocd-issue-with-activate-annotation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lhotsetechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"OCD issue with @Activate annotation"}]},{"@type":"WebSite","@id":"https:\/\/lhotsetechnologies.com\/blog\/#website","url":"https:\/\/lhotsetechnologies.com\/blog\/","name":"AEM Blog | Lhotse Technologies","description":"","publisher":{"@id":"https:\/\/lhotsetechnologies.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/lhotsetechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/lhotsetechnologies.com\/blog\/#organization","name":"AEM Blog | Lhotse Technologies","url":"https:\/\/lhotsetechnologies.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/lhotsetechnologies.com\/blog\/wp-content\/uploads\/2019\/07\/lhotse-logo.png","contentUrl":"https:\/\/lhotsetechnologies.com\/blog\/wp-content\/uploads\/2019\/07\/lhotse-logo.png","width":539,"height":172,"caption":"AEM Blog | Lhotse Technologies"},"image":{"@id":"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/person\/d1daa7081420d3cf2a02c309ee3f5800","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lhotsetechnologies.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/829547de0cecf5477afeaf7ff2a49fc87a026be43cb5403fa54d0fd419192479?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/829547de0cecf5477afeaf7ff2a49fc87a026be43cb5403fa54d0fd419192479?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/lhotsetechnologies.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":9,"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"predecessor-version":[{"id":210,"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions\/210"}],"wp:attachment":[{"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lhotsetechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}