mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Additional work for RM-2614. Validation that the configured model property name is either null or a valid QName for a property recognised by the dictionary.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/caveatmarkdatatype@114957 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
<bean id="caveatDAOFromJSON" class="org.alfresco.module.org_alfresco_module_rm.caveat.dao.CaveatDAOFromJSON">
|
||||
<property name="configLocation" value="${rm.caveat.configFile}" />
|
||||
<property name="namespaceService" ref="namespaceService" />
|
||||
<property name="dictionaryService" ref="dictionaryService" />
|
||||
</bean>
|
||||
|
||||
<bean id="caveatDAO" class="org.alfresco.module.org_alfresco_module_rm.caveat.dao.CaveatDAOCache">
|
||||
|
@@ -36,6 +36,7 @@ import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.Malform
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroupType;
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatMark;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -78,6 +79,7 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
|
||||
/** The location of the configuration file relative to the classpath. */
|
||||
private String configLocation;
|
||||
|
||||
private DictionaryService dictionaryService;
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
/** Set the location of the configuration file relative to the classpath. */
|
||||
@@ -90,6 +92,10 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
|
||||
{
|
||||
this.namespaceService = service;
|
||||
}
|
||||
public void setDictionaryService(DictionaryService service)
|
||||
{
|
||||
this.dictionaryService = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -224,12 +230,40 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
|
||||
|
||||
// Instantiate the group (and associate the marks with the group).
|
||||
CaveatGroup caveatGroup = new CaveatGroup(id, displayLabelKey, descriptionKey,
|
||||
modelProperty == null ? null : createQName(modelProperty, namespaceService),
|
||||
validatedPropertyName(modelProperty),
|
||||
caveatGroupType, caveatMarks);
|
||||
|
||||
return caveatGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the provided qname string is a valid model property.
|
||||
* @param qnameString the short form qname string e.g. {@code cm:content} or {@code null}.
|
||||
* @return the valid {@link QName} or {@code null} if the qnameString was {@code null}.
|
||||
* @throws MalformedConfiguration if the provided qnameString was not {@code null} and was not a valid property name.
|
||||
*/
|
||||
private QName validatedPropertyName(String qnameString)
|
||||
{
|
||||
if (qnameString == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
final QName qname = createQName(qnameString, namespaceService);
|
||||
final boolean isProperty = dictionaryService.getProperty(qname) != null;
|
||||
|
||||
if (isProperty)
|
||||
{
|
||||
return qname;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MalformedConfiguration("Property name not recognised: '" + qnameString + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a caveat mark from the supplied JSON. This does not set the group id of the caveat mark.
|
||||
*
|
||||
|
@@ -21,6 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.caveat.dao;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -29,7 +30,10 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.MalformedConfiguration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -49,6 +53,11 @@ public class CaveatDAOFromJSONUnitTest
|
||||
NamespaceService namespaceService = mock(NamespaceService.class);
|
||||
when(namespaceService.getNamespaceURI(anyString())).thenReturn("{mockedNamespace}");
|
||||
|
||||
DictionaryService dictionaryService = mock(DictionaryService.class);
|
||||
PropertyDefinition mockProperty = mock(PropertyDefinition.class);
|
||||
when(dictionaryService.getProperty(any(QName.class))).thenReturn(mockProperty);
|
||||
|
||||
caveatDAOFromJSON.setDictionaryService(dictionaryService);
|
||||
caveatDAOFromJSON.setNamespaceService(namespaceService);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user