Skip to Content
1
Former Member
Feb 15, 2016 at 08:44 AM

Overriding getDownloadUrl of MediaModel

806 Views

Hello experts, We have a property calling as downloadURL belonged to Media type in core-items.xml. When we needed to manipulate this property return value, we had used aspect for that. But now, we have some performance issues. So, we try to get rid of aop usage. I guess, I have no chance with interceptor because of non-writable property. What practice would you suggest me in this situation? Thx

             <attribute autocreate="true" qualifier="downloadURL" type="java.lang.String">
                 <custom-properties>
                     <property name="modelPrefetchMode">
                         <value>java.lang.Boolean.FALSE</value>
                     </property>
                 </custom-properties>
                 <persistence type="jalo"/>
                 <modifiers read="true" write="false" removable="true" search="false" optional="true"/>
                 <model>
                     <getter name="downloadurl" deprecated="true"/>
                     <setter name="downloadurl" deprecated="true"/>
                 </model>
             </attribute>

Solution with aspect (already existed in system now): The code is here what i want to override out of aop: (it is in an aspect class for now)

 @Around("execution(public * de.hybris.platform.core.model.media.MediaModel.getDownloadURL(..))")
 public String getDownloadUrlByAspect(final ProceedingJoinPoint pjp) throws Throwable
 {
     final LocalMediaWebURLStrategy localMediaWebURLStrategy = Registry.getApplicationContext()
             .getBean(LocalMediaWebURLStrategy.class);

     final MediaStorageConfigService mediaStorageConfigService = Registry.getApplicationContext()
             .getBean(MediaStorageConfigService.class);

     MediaModel mediaModel = (MediaModel) pjp.getThis();

     MediaStorageConfigService.MediaFolderConfig config = mediaStorageConfigService
             .getConfigForFolder(mediaModel.getFolder().getQualifier());

     final String downloadURL = localMediaWebURLStrategy.getDownloadUrlForMedia(config, new ModelMediaSource(mediaModel));

     LogMF.debug(LOG, "new media download url for media is {0}", new Object[]
     { downloadURL });

     return downloadURL;
 }