Search in sources :

Example 1 with NamespacePrefixResolver

use of org.alfresco.service.namespace.NamespacePrefixResolver in project alfresco-repository by Alfresco.

the class TemplateFilingRule method createFilingData.

private FilingData createFilingData(Reference parentRef, QName assocTypeQName, QName assocQName, QName nodeTypeQName, Map<QName, Serializable> properties) throws VirtualizationException {
    NodeRef fParentRef = null;
    QName fType = null;
    Set<QName> fAspects = null;
    Map<QName, Serializable> fProperties = null;
    NamespacePrefixResolver nsPrefixResolver = env.getNamespacePrefixResolver();
    if (type == null || type.length() == 0) {
        fType = nodeTypeQName;
    } else {
        fType = QName.createQName(type, nsPrefixResolver);
        if (env.isSubClass(fType, ContentModel.TYPE_FOLDER)) {
            if (logger.isDebugEnabled()) {
                logger.debug("CM-528 acceptance criteria 3 : we deny the creation of folders subtype " + fType + " and force cm:content instead.");
            }
            fType = ContentModel.TYPE_CONTENT;
        }
        if (env.isSubClass(nodeTypeQName, fType)) {
            fType = nodeTypeQName;
        }
    }
    fParentRef = parentNodeRefFor(parentRef, true);
    fProperties = new HashMap<QName, Serializable>(properties);
    Set<Entry<String, String>> propertyEntries = stringProperties.entrySet();
    for (Entry<String, String> propertyEntry : propertyEntries) {
        String name = propertyEntry.getKey();
        QName qName = QName.createQName(name, nsPrefixResolver);
        if (!fProperties.containsKey(qName)) {
            fProperties.put(qName, stringProperties.get(name));
        }
    }
    fAspects = new HashSet<>();
    for (String aspect : aspects) {
        fAspects.add(QName.createQName(aspect, env.getNamespacePrefixResolver()));
    }
    return new FilingData(fParentRef, assocTypeQName, assocQName, fType, fAspects, fProperties);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Entry(java.util.Map.Entry) NamespacePrefixResolver(org.alfresco.service.namespace.NamespacePrefixResolver)

Example 2 with NamespacePrefixResolver

use of org.alfresco.service.namespace.NamespacePrefixResolver in project alfresco-repository by Alfresco.

the class TypeVirtualizationMethodUnitTest method mockNamespacePrefixResolver.

static NamespacePrefixResolver mockNamespacePrefixResolver() {
    NamespacePrefixResolver mockNamespacePrefixResolver = Mockito.mock(NamespacePrefixResolver.class, new ThrowsException(new NamespaceException("Mock exception ")));
    Mockito.doReturn(Arrays.<String>asList(SiteModel.SITE_MODEL_PREFIX)).when(mockNamespacePrefixResolver).getPrefixes(SiteModel.SITE_MODEL_URL);
    Mockito.doReturn(SiteModel.SITE_MODEL_URL).when(mockNamespacePrefixResolver).getNamespaceURI(SiteModel.SITE_MODEL_PREFIX);
    Mockito.doReturn(Arrays.<String>asList(NamespaceService.CONTENT_MODEL_PREFIX)).when(mockNamespacePrefixResolver).getPrefixes(NamespaceService.CONTENT_MODEL_1_0_URI);
    Mockito.doReturn(NamespaceService.CONTENT_MODEL_1_0_URI).when(mockNamespacePrefixResolver).getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX);
    Mockito.doReturn("mock(NamespacePrefixResolver)@" + TypeVirtualizationMethod.class.toString()).when(mockNamespacePrefixResolver).toString();
    return mockNamespacePrefixResolver;
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) NamespaceException(org.alfresco.service.namespace.NamespaceException) NamespacePrefixResolver(org.alfresco.service.namespace.NamespacePrefixResolver)

Example 3 with NamespacePrefixResolver

use of org.alfresco.service.namespace.NamespacePrefixResolver in project alfresco-repository by Alfresco.

the class VirtualStoreImpl method getProperties.

@Override
public Map<QName, Serializable> getProperties(Reference reference) throws VirtualizationException {
    final Protocol protocol = reference.getProtocol();
    if (Protocols.VIRTUAL.protocol.equals(protocol) || Protocols.VANILLA.protocol.equals(protocol)) {
        VirtualFolderDefinition folderDefinition = resolveVirtualFolderDefinition(reference);
        Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
        // We first set default property values. They might be overridden by
        // folder definition properties.
        properties.put(ContentModel.PROP_NAME, folderDefinition.getName());
        StoreRef storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
        properties.put(ContentModel.PROP_STORE_IDENTIFIER, storeRef.getIdentifier());
        properties.put(ContentModel.PROP_STORE_PROTOCOL, storeRef.getProtocol());
        properties.put(ContentModel.PROP_LOCALE, Locale.UK.toString());
        properties.put(ContentModel.PROP_MODIFIED, new Date());
        properties.put(ContentModel.PROP_MODIFIER, AuthenticationUtil.SYSTEM_USER_NAME);
        properties.put(ContentModel.PROP_CREATED, new Date());
        properties.put(ContentModel.PROP_CREATOR, AuthenticationUtil.SYSTEM_USER_NAME);
        properties.put(ContentModel.PROP_NODE_DBID, 0);
        properties.put(ContentModel.PROP_DESCRIPTION, folderDefinition.getDescription());
        // ACE-5303 : ContentModel.PROP_TITLE remains unset
        // We add virtual folder definition structure properties. They might
        // override the above defaults.
        Map<String, String> nodeProperties = folderDefinition.getProperties();
        if (nodeProperties != null) {
            Set<Entry<String, String>> propertyEntries = nodeProperties.entrySet();
            NamespacePrefixResolver nsPrefixResolver = environment.getNamespacePrefixResolver();
            for (Entry<String, String> propertyValueEntry : propertyEntries) {
                QName propertyQName = QName.createQName(propertyValueEntry.getKey(), nsPrefixResolver);
                properties.put(propertyQName, propertyValueEntry.getValue().toString());
            }
        }
        return properties;
    } else {
        NodeRef actual = reference.execute(new GetActualNodeRefMethod(environment));
        Map<QName, Serializable> properties = environment.getProperties(actual);
        properties.put(VirtualContentModel.PROP_ACTUAL_NODE_REF, actual.toString());
        return properties;
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) Entry(java.util.Map.Entry) NamespacePrefixResolver(org.alfresco.service.namespace.NamespacePrefixResolver) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) Protocol(org.alfresco.repo.virtual.ref.Protocol) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition)

Aggregations

NamespacePrefixResolver (org.alfresco.service.namespace.NamespacePrefixResolver)3 Serializable (java.io.Serializable)2 Entry (java.util.Map.Entry)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 QName (org.alfresco.service.namespace.QName)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 NodePermissionEntry (org.alfresco.repo.security.permissions.NodePermissionEntry)1 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)1 Protocol (org.alfresco.repo.virtual.ref.Protocol)1 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 NamespaceException (org.alfresco.service.namespace.NamespaceException)1 ThrowsException (org.mockito.internal.stubbing.answers.ThrowsException)1