Expand my Community achievements bar.

Asset Share Commons Override Sling Model

Avatar

Level 2

Hi All,

 

I am working on a use case where I need to override the sling model of the OOTB asset share commons code. I have ModelA implementing Interface. I want to write ModelB which will implement interface only with the custom logic. Rest of the code should stay as is. Is there any way we can do it ? I tried Sling Model Delegation but it did not work. Can anybody help on this ?

3 Replies

Avatar

Community Advisor

@ayush_aem 

When you say it didn't work with Delegation pattern, what is the issue you are facing? Can you specify.

 

Are you seeing null values for the properties? Is the custom logic not working?

 

Are you following this? https://github.com/adobe/aem-core-wcm-components/wiki/Delegation-Pattern-for-Sling-Models

 

Avatar

Level 2

Yes @gkalyan I have followed the same link. For null values for the properties I understand we need to override the functions of the interface. But the problem is that custom sling model is not getting invoked.I am trying to write custom sling model for interface asset-share-commons/core/src/main/java/com/adobe/aem/commons/assetshare/components/actions/download/....


 

I have tried the below.

@Model(
         adaptables = {SlingHttpServletRequest.class},
         adapters = {Download.class, ComponentExporter.class},
         resourceType = "mysite/components/modals/download",
         defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
 )
 @Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
 public class DownloadImpl implements Download {

    private Logger LOG = LoggerFactory.getLogger(DownloadImpl.class);

    @Self @Via(type = ResourceSuperType.class)
    private Download download;

    @Override
    public Collection<AssetModel> getAssets() {
        return download.getAssets();
    }

    @Override
    public String getZipFileName() {
        return download.getZipFileName();
    }

    @Override
    public long getMaxContentSize() {
        return download.getMaxContentSize();
    }

    @Override
    public long getDownloadContentSize() {
        return download.getDownloadContentSize();
    }

    @Override
    public String getMaxContentSizeLabel() {
        return download.getMaxContentSizeLabel();
    }

    @Override
    public String getDownloadContentSizeLabel() {
        return download.getDownloadContentSizeLabel();
    }

    @Override
    public boolean isAsynchronous() {
        return download.isAsynchronous();
    }
 }




Avatar

Community Advisor

@ayush_aem 

Can you check the below if not already:

1. Your custom sling model is registered and active in OSGI console.

2. Sling:resourceSuperType property of the component is set to OOTB Download component resource type.

 

Finally, try clear component cache and restrart AEM.

 

If the above doesn't work, let's look at the logs