MNT-21398 Unable to override standard rendition definitions (#913)

Relaxed the checks so that it is possible to override rendition definitions. DEBUG is logged in this case.
This commit is contained in:
Alan Davis
2020-04-01 15:48:39 +01:00
committed by GitHub
parent 6e33a5857c
commit 79698488cd
3 changed files with 36 additions and 7 deletions

View File

@@ -252,8 +252,13 @@ public class RenditionDefinitionRegistry2Impl implements RenditionDefinitionRegi
{
map.put(RenditionDefinition2.TIMEOUT, timeoutDefault);
}
RenditionDefinition2 original = getRenditionDefinition(def.renditionName);
new RenditionDefinition2Impl(def.renditionName, def.targetMediaType, map, true,
RenditionDefinitionRegistry2Impl.this);
if (original != null)
{
log.debug(readFromMessage+" replaced the rendition "+def.renditionName);
}
}
}
}
@@ -314,13 +319,11 @@ public class RenditionDefinitionRegistry2Impl implements RenditionDefinitionRegi
public void register(RenditionDefinition2 renditionDefinition)
{
String renditionName = renditionDefinition.getRenditionName();
RenditionDefinition2 original = getDefinition(renditionName);
if (original != null)
{
throw new IllegalArgumentException("RenditionDefinition "+renditionName+" was already registered.");
}
Data data = getData();
// There may already be a rendition defined, but an extension may replace it.
// This is logged in a caller of this method were the file name is known.
data.renditionDefinitions.put(renditionName, renditionDefinition);
if (renditionDefinition instanceof RenditionDefinition2Impl &&
!((RenditionDefinition2Impl)renditionDefinition).isDynamicallyLoaded())
{

View File

@@ -56,6 +56,7 @@ import java.util.Map;
import java.util.Set;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -123,7 +124,6 @@ public class RenditionService2Test
when(nodeService.exists(nodeRef)).thenReturn(true);
when(nodeService.exists(nodeRefMissing)).thenReturn(false);
when(nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentData);
when(nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED)).thenReturn(new Date());
when(contentData.getContentUrl()).thenReturn(contentUrl);
doAnswer(invocation ->
@@ -155,6 +155,7 @@ public class RenditionService2Test
renditionService2.setEnabled(true);
renditionService2.setThumbnailsEnabled(true);
renditionDefinitionRegistry2.setRenditionConfigDir("alfresco/renditions/test");
renditionDefinitionRegistry2.afterPropertiesSet();
renditionService2.afterPropertiesSet();
@@ -273,4 +274,13 @@ public class RenditionService2Test
assertTrue("Expected rendition "+name, renditionNames.contains(name));
}
}
@Test()
public void overriddenRendition()
{
// Check the standard rendition doclib has been overridden by one in alfresco/renditions/test/overrideRendition.json
RenditionDefinition2 doclib = renditionDefinitionRegistry2.getRenditionDefinition("doclib");
String resizeWidth = doclib.getTransformOptions().get("resizeWidth");
assertEquals("doclib has not been overridden", "180", resizeWidth);
}
}

View File

@@ -0,0 +1,16 @@
{
"renditions": [
{
"renditionName": "doclib",
"targetMediaType": "image/png",
"options": [
{"name": "resizeWidth", "value": 180},
{"name": "resizeHeight", "value": 180},
{"name": "allowEnlargement", "value": false},
{"name": "maintainAspectRatio", "value": true},
{"name": "autoOrient", "value": true},
{"name": "thumbnail", "value": true}
]
}
]
}