Asset Share Commons Override Sling Model | Community
Skip to main content
Level 2
November 30, 2024
Question

Asset Share Commons Override Sling Model

  • November 30, 2024
  • 2 replies
  • 755 views

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 ?

2 replies

gkalyan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
December 1, 2024

@ayushag3 

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

 

AyushAg3Author
Level 2
December 1, 2024

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/Download.java at develop · adobe/asset-share-commons · GitHub.


 

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();
    }
 }




gkalyan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
December 2, 2024

@ayushag3 

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

 

kautuk_sahni
Community Manager
Community Manager
January 27, 2025

@ayushag3 Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni