mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
REPO-2926: CMIS update now ignores aspects in the sys namespace
Includes tests
This commit is contained in:
@@ -238,6 +238,8 @@ import org.springframework.context.event.ApplicationContextEvent;
|
||||
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
/**
|
||||
* Bridge connecting Alfresco and OpenCMIS.
|
||||
* <p/>
|
||||
@@ -3183,28 +3185,34 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
||||
}
|
||||
}
|
||||
|
||||
Set<QName> ignore = new HashSet<QName>();
|
||||
ignore.add(ContentModel.ASPECT_REFERENCEABLE);
|
||||
ignore.add(ContentModel.ASPECT_LOCALIZED);
|
||||
ignore.add(ContentModel.ASPECT_WORKING_COPY);
|
||||
Set<QName> aspectsToIgnore = new HashSet<>();
|
||||
aspectsToIgnore.add(ContentModel.ASPECT_REFERENCEABLE);
|
||||
aspectsToIgnore.add(ContentModel.ASPECT_LOCALIZED);
|
||||
aspectsToIgnore.add(ContentModel.ASPECT_WORKING_COPY);
|
||||
|
||||
Set<String> namespacesToIgnore = new HashSet<>(singletonList(NamespaceService.SYSTEM_MODEL_1_0_URI));
|
||||
|
||||
// aspects to add == the list of secondary types - existing aspects - ignored aspects
|
||||
Set<QName> toAdd = new HashSet<QName>(secondaryTypeAspects);
|
||||
toAdd.removeAll(existingAspects);
|
||||
toAdd.removeAll(ignore);
|
||||
toAdd.removeAll(aspectsToIgnore);
|
||||
toAdd.removeIf(a -> namespacesToIgnore.contains(a.getNamespaceURI()));
|
||||
|
||||
// aspects to remove == existing aspects - secondary types
|
||||
Set<QName> aspectsToRemove = new HashSet<QName>();
|
||||
aspectsToRemove.addAll(existingAspects);
|
||||
aspectsToRemove.removeAll(ignore);
|
||||
aspectsToRemove.removeAll(aspectsToIgnore);
|
||||
Iterator<QName> it = aspectsToRemove.iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
QName aspectQName = it.next();
|
||||
TypeDefinitionWrapper w = getOpenCMISDictionaryService().findNodeType(aspectQName);
|
||||
if(w == null || secondaryTypeAspects.contains(aspectQName))
|
||||
if(w == null || secondaryTypeAspects.contains(aspectQName) || namespacesToIgnore.contains(aspectQName.getNamespaceURI()))
|
||||
{
|
||||
// the type is not exposed or is in the secondary types to set, so remove it from the to remove set
|
||||
// the type is not exposed,
|
||||
// or is in the secondary types to set,
|
||||
// or is in the set of namespaces to ignore,
|
||||
// so remove it from the "to remove" set
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
@@ -1754,13 +1754,25 @@ public class CMISTest
|
||||
}
|
||||
}, CmisVersion.CMIS_1_1);
|
||||
|
||||
List secondaryTypeIds = currentProperties.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
|
||||
List<String> secondaryTypeIds = (List<String>) currentProperties.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
|
||||
|
||||
assertTrue(secondaryTypeIds.contains(aspectName));
|
||||
// We don't actually want to add these! (REPO-2926)
|
||||
final Set<String> sysAspectsToAdd = new HashSet<>(Arrays.asList(
|
||||
"P:sys:undeletable",
|
||||
"P:sys:hidden"));
|
||||
// Pre-condition of further test is that these aspects are not present
|
||||
assertEquals(0, secondaryTypeIds.stream().filter(sysAspectsToAdd::contains).count());
|
||||
// We also want to check that existing sys aspects aren't accidentally removed
|
||||
assertTrue(secondaryTypeIds.contains("P:sys:localized"));
|
||||
|
||||
// Check we can remove an aspect - through its absence
|
||||
secondaryTypeIds.remove(aspectName);
|
||||
// Check that attempts to update/add sys:* aspects are ignored
|
||||
secondaryTypeIds.addAll(sysAspectsToAdd);
|
||||
final PropertiesImpl newProperties = new PropertiesImpl();
|
||||
newProperties.addProperty(new PropertyStringImpl(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypeIds));
|
||||
|
||||
final String updatedName = "My_new_name_"+UUID.randomUUID().toString();
|
||||
newProperties.replaceProperty(new PropertyStringImpl(PropertyIds.NAME, updatedName));
|
||||
|
||||
@@ -1787,10 +1799,14 @@ public class CMISTest
|
||||
return properties;
|
||||
}
|
||||
}, CmisVersion.CMIS_1_1);
|
||||
secondaryTypeIds = currentProperties1.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
|
||||
secondaryTypeIds = (List<String>) currentProperties1.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
|
||||
|
||||
assertFalse(secondaryTypeIds.contains(aspectName));
|
||||
assertEquals(updatedName, currentProperties1.getProperties().get(PropertyIds.NAME).getFirstValue());
|
||||
// sys aspects must not be added through CMIS (REPO-2926)
|
||||
assertEquals(0, secondaryTypeIds.stream().filter(sysAspectsToAdd::contains).count());
|
||||
// Check pre-existing sys aspects aren't accidentally removed
|
||||
assertTrue(secondaryTypeIds.contains("P:sys:localized"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user