on 02-15-2016 8:44 AM
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;
}
Hi Mustafa,
Just change the write
attribute to write="true"
, in the XML that you have above, then build and run the platform. This will generate the setDownloadURL(String downloadURL)
method in the class.
The downside of this, is when you migrate to a later hybris version, for patches or major releases, you'll need to apply this change every time. If you create a Unit Test to check for the setDownloadURL(...)
method presence, and put in a detailed AssertionError message to remind you how to make the update.
I hope this helps,
Luke
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Luke, thank you again. This approach works, right. But is there a way to make this change in our custom projects's *items.xml? When i try that accordingly wiki (but wiki tells that for subtype situation), unfortunately i see duplicate item exception. As far as i understood, issue was investigated in experts previously. But there is not valid answer till now. Regards
I would change the default media strategy.
Add this propertie:
media.default.url.strategy=yourMediaStrategyBean
Create a class that extends LocalMediaWebURLStrategy and overwrite the following method:
public String getDownloadUrlForMedia(MediaFolderConfig config, MediaSource mediaSource)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sebaastien, Thank you for your answer. But i guess that i do not understand what you meant clearly. Because, my concern is not about directly Strategy. I just want to override mediaModel.getDownloadURL method not mediaStrategy. Maybe i am not looking at right point. I suppose that getDownloadURL method does not involve strategy code or am missing something.
User | Count |
---|---|
6 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.