Hey all,
I have created a custom maintenance task by using the following class. I can add the task in the maintenance page, but the "configure" icon is missing. It only shows the start icon. Any clue on what I am missing?
Thanks!
Roy
@Component( property = { MaintenanceConstants.PROPERTY_TASK_NAME + "=" + "FullIndexerTask", MaintenanceConstants.PROPERTY_TASK_TITLE + "=" + "Full Indexer", JobExecutor.PROPERTY_TOPICS + "=" + MaintenanceConstants.TASK_TOPIC_PREFIX + "FullIndexerTask" } ) @Designate(ocd = FullIndexer.Config.class) public class FullIndexer implements JobExecutor { private static final Logger LOG = LoggerFactory.getLogger(FullIndexer.class); private static final String SUBSERVICE_NAME = "fullindexer"; @ObjectClassDefinition(name = "Full Indexer Task", description = "Full indexer that will reindex all pages for the included site names") @interface Config { @AttributeDefinition(description = "Site names that should be reindexed") String[] site_names(); } private List<String> siteNames = new ArrayList<>(); @Activate protected void activate(Config config) { if (config.site_names() != null) { this.siteNames = Arrays.asList(config.site_names()); } } @Override public JobExecutionResult process(Job job, JobExecutionContext context) { ... } }
Solved! Go to Solution.
Views
Replies
Total Likes
Yes of course, if you want I can give you the entire class? This is the new way of adding properties, please read the blog of Carsten Ziegler:
http://blog.osoco.de/2015/08/osgi-components-simply-simple-part-i/
package my.testpackage; import com.adobe.granite.maintenance.MaintenanceConstants; import com.day.cq.wcm.api.Page; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.event.jobs.Job; import org.apache.sling.event.jobs.JobManager; import org.apache.sling.event.jobs.consumer.JobExecutionContext; import org.apache.sling.event.jobs.consumer.JobExecutionResult; import org.apache.sling.event.jobs.consumer.JobExecutor; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.osgi.service.metatype.annotations.Designate; import org.osgi.service.metatype.annotations.ObjectClassDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Iterator; import java.util.List; @Component( property = { MaintenanceConstants.PROPERTY_TASK_NAME + "=" + "FullIndexerTask", MaintenanceConstants.PROPERTY_TASK_TITLE + "=" + "Full Indexer", MaintenanceConstants.PROPERTY_TASK_MANDATORY + "=" + "true", JobExecutor.PROPERTY_TOPICS + "=" + MaintenanceConstants.TASK_TOPIC_PREFIX + "FullIndexerTask" } ) @Designate(ocd = FullIndexer.Config.class) public class FullIndexer implements JobExecutor { private static final Logger LOG = LoggerFactory.getLogger(FullIndexer.class); @ObjectClassDefinition(name = "Full Indexer Task") @interface Config { boolean enabled() default false; } private boolean enabled; @Activate protected void activate(Config config) { this.enabled = config.enabled(); } @Override public JobExecutionResult process(Job job, JobExecutionContext context) { LOG.info("Starting full indexer task"); if (enabled) { // do some indexing stuff return context.result().message("Executed full indexer task").succeeded(); } else { return context.result().message("Full indexer task not enabled on this server").succeeded(); } } }
Views
Replies
Total Likes
Hi
Please have a look at this Adobe Helpx article
Link:- http://www.aemcq5tutorials.com/tutorials/custom-osgi-configuration-aem/
// Create Custom OSGI Configuration in AEM
In this you will learn
How to Set and Get OSGI configuration values using Text Field.
How to Set and Get OSGI configuration values using Drop Down List.
How to Set and Get OSGI configuration values using Check Box.
How to Set and Get OSGI configuration values using Multi Field.
Set and Get OSGI configuration values using Textfield: When user wants to get and set single value in osgi configuration, Text Field is preferred. Setting Values: 1 2 @Property(label="Name of the Author",value = "author") @Property(label="Age of the Author",intValue = 15) Getting Values: 1 2 private static final String AUTHOR_NAME = "author.value"; private static final String AUTHOR_AGE = "author.age"; value: This property indicates default value of the configuration. intValue : If you want to take only integer value ,use this property to set default value.
Note:- @Property annotation helps us to define the properties in felix console.
I hope this would help you.
~kautuk
Views
Replies
Total Likes
Hey kautuk,
That is the old way of working, it is outdated, the new way is with OSGi DS annotations.
Greetings,
Roy
Views
Replies
Total Likes
Does this code work?
Views
Replies
Total Likes
Yes of course, if you want I can give you the entire class? This is the new way of adding properties, please read the blog of Carsten Ziegler:
http://blog.osoco.de/2015/08/osgi-components-simply-simple-part-i/
package my.testpackage; import com.adobe.granite.maintenance.MaintenanceConstants; import com.day.cq.wcm.api.Page; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.event.jobs.Job; import org.apache.sling.event.jobs.JobManager; import org.apache.sling.event.jobs.consumer.JobExecutionContext; import org.apache.sling.event.jobs.consumer.JobExecutionResult; import org.apache.sling.event.jobs.consumer.JobExecutor; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.osgi.service.metatype.annotations.Designate; import org.osgi.service.metatype.annotations.ObjectClassDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Iterator; import java.util.List; @Component( property = { MaintenanceConstants.PROPERTY_TASK_NAME + "=" + "FullIndexerTask", MaintenanceConstants.PROPERTY_TASK_TITLE + "=" + "Full Indexer", MaintenanceConstants.PROPERTY_TASK_MANDATORY + "=" + "true", JobExecutor.PROPERTY_TOPICS + "=" + MaintenanceConstants.TASK_TOPIC_PREFIX + "FullIndexerTask" } ) @Designate(ocd = FullIndexer.Config.class) public class FullIndexer implements JobExecutor { private static final Logger LOG = LoggerFactory.getLogger(FullIndexer.class); @ObjectClassDefinition(name = "Full Indexer Task") @interface Config { boolean enabled() default false; } private boolean enabled; @Activate protected void activate(Config config) { this.enabled = config.enabled(); } @Override public JobExecutionResult process(Job job, JobExecutionContext context) { LOG.info("Starting full indexer task"); if (enabled) { // do some indexing stuff return context.result().message("Executed full indexer task").succeeded(); } else { return context.result().message("Full indexer task not enabled on this server").succeeded(); } } }
Views
Replies
Total Likes
Hey,
It seems that the latest that I show does work, so everything is fine, thanks guys
Greets,
Roy
Views
Replies
Total Likes
Views
Likes
Replies