Extending AbstractSocialComponentFactory for AEM 6.5 with R6 annotations

Avatar

Avatar
Boost 100
Level 6
snbaem
Level 6

Likes

115 likes

Total Posts

246 posts

Correct reply

37 solutions
Top badges earned
Boost 100
Springboard
Establish
Validate 25
Validate 10
View profile

Avatar
Boost 100
Level 6
snbaem
Level 6

Likes

115 likes

Total Posts

246 posts

Correct reply

37 solutions
Top badges earned
Boost 100
Springboard
Establish
Validate 25
Validate 10
View profile
snbaem
Level 6

30-04-2021

Hello All,

As part of upgrade from AEM 6.2 to AEM 6.5, I am looking to find a correct way to extend the 

AbstractSocialComponentFactory 
This is an example - https://github.com/Adobe-Marketing-Cloud/aem-scf-sample-components-extension/blob/master/bundles/aem... similar to which we have our custom implementation working for AEM 6.2. We are also using org.apache.felix.scr.annotations.Component; annotations in 6.2
 
However which updating the code to 6.5 I am looking to update the annotations as per https://docs.osgi.org/javadoc/r6/cmpn/org/osgi/service/component/annotations/Component.html#factory(...
 
I have tried 
@Component(name = "Custom Community Component Factory", factory = "com.path.to..CustomCommunityComponentFactory", service = SocialComponentFactory.class, configurationPolicy = ConfigurationPolicy.OPTIONAL)
&
@Component(name = "Custom Community Component Factory", factory = "com.path.to..CustomCommunityComponentFactory")
and other combinations. But still the class never gets called. The bundle is active and the service class is active too (/system/console/components)

I see that the current custom factory is not registered as SocialComponentFactory but rather as ComponentFactory
 
Eg:
Desired:  [Custom COmmunity Component Factory,21308, [com.adobe.cq.social.scf.SocialComponentFactory]] ServiceEvent REGISTERED
Actual :   [Custom COmmunity Component Factory,21308, [org.osgi.service.component.ComponentFactory]] ServiceEvent REGISTERED 
 Below is the sample code that I am using.

 

 

  
package path.to.package;

import com.adobe.cq.social.scf.ClientUtilities;
import com.adobe.cq.social.scf.QueryRequestInfo;
import com.adobe.cq.social.scf.SocialComponent;
import com.adobe.cq.social.scf.SocialComponentFactory;
import com.adobe.cq.social.scf.core.AbstractSocialComponentFactory;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;

/** Factory Class for Custom Community Component. 
 * @author Shubham
 *
 */
@Component(name = "Custom Community Component", factory = "path.to.current.class.CustomCommunityComponentFactory", service = SocialComponentFactory.class, configurationPolicy = ConfigurationPolicy.OPTIONAL)
public class CustomCommunityComponentFactory extends AbstractSocialComponentFactory implements SocialComponentFactory {
	
	@Override
    public SocialComponent getSocialComponent(final Resource resource) {
        return new CustomCommunityComponent(resource, this.getClientUtilities(resource.getResourceResolver()));
    }
 
    @Override
    public SocialComponent getSocialComponent(final Resource resource, final SlingHttpServletRequest request) {
        return new CustomCommunityComponent(resource, this.getClientUtilities(request));
    }
     
    @Override
    public SocialComponent getSocialComponent(Resource resource, ClientUtilities clientUtils, QueryRequestInfo listInfo) {
        return new CustomCommunityComponent(resource, clientUtils);
    }
 
 

    @Override
    public int getPriority() {
        return 1000;
    }
 
	 
	@Override
	public String getSupportedResourceType() {
		return "project/path/to/component";
	}
}

 

 


I have updated to R6 annotations for other services and servlet class but for this particular one updating to R6 reference and using @Component annotation does not seem to work. The component hbs does not render any thing and there are no errors in any of the logs. During debug as well on component page load I should be able to hit the lines with return statements, but I am unable to. This does work when I use the old annotations. Tried adding immediate=true, socialFactory=true but in vain.

Please help out if there is anything I am missing in terms of binding the custom component with the Social Component Factory class. Not sure if any one has tried this already. Could that be because the OOTB AbstractSocialComponentFactory is still using felix annotations?

cc @aponnusa 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

207 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

207 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

30-04-2021

Hi @snbaem 

 

Please remove the factory attribute. It will resolve the issue and the component will be registered using SocialComponentFactory.

 

@Component(name = "Custom Community Component Factory", configurationPolicy = ConfigurationPolicy.OPTIONAL, service = SocialComponentFactory.class)
public class CustomCommunityComponentFactory extends AbstractSocialComponentFactory {
// Rest of the Code.
}

 

[Custom Community Component Factory,23947, [com.adobe.cq.social.scf.SocialComponentFactory]] ServiceEvent REGISTERED

 

Hope this helps!

Thanks

Answers (1)

Answers (1)

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,135 likes

Total Posts

3,167 posts

Correct reply

1,080 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,135 likes

Total Posts

3,167 posts

Correct reply

1,080 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

01-05-2021

SCR inheritance (which is supported by the Felix SCR annotations) is no longer possible with the OSGI annotations, and that's by design. IIRC Carsten Ziegeler (of the OSGI alliance) wrote that it caused more problems can benefits, so it was not included into the OSGI annotations