Files
alfresco-community-repo/source/java/org/alfresco/repo/virtual/template/TemplateFilingRule.java
Alan Davis c6f0ce491f Merged 5.1.N (5.1.1) to HEAD (5.1)
- Merges from 5.1.0 (when it was 5.1) that did not make it to HEAD:
     122506,122513,123118-123119
   - RECORD ONLY Merges from HEAD: 119613-119617,119622,119706-119708,
     119752-119753,120076-120078,120116,120166-120178,120182-120183,
     120185-120193,120197-120201,120378-120385,120387,120431,120526,
     120604-120625,120832-120842,120844-120849,120977-120982,121142-121144,
     121313,121347-121348,121410,121412-121417,121684-121687,121802-121805,
     121810-121815,121861,122287,122342,122361,122439-122441,122579,122921
   - RECORD ONLY merges: 119602,119821-119822,119849,120065,120107,
     120159,120260,120295,120339,120342,120371,120411-120412,120524,120527,
     120696-120697,120705,120720,120746,120761,120819,120822,120893,
     120935-120936,120993,121045,121119,121121,121132,121156-121157,
     121299,121301,121309,121394,121408,121442,121481,121624,121626,
     121672,121675,121692,121753,121795,121798,121852,121898,121981,
     122030,122088,122114,122142,122213,122215,122217,122277,122340,
     122343,122426,122487,122552,122554,122607,122654,122734,122861,
     122906,122982,122985,122988,122996,123014,123031,123090,
     123115-123117,123120    
   - Merge from 5.1.N of fix that should have gone into 5.1 (found because of conflict on merge)
     123128: ACE-5155 Garbled message in patch-service.properties


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@123129 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-03-04 18:14:23 +00:00

229 lines
7.8 KiB
Java

/*
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see http://www.gnu.org/licenses/.
*/
package org.alfresco.repo.virtual.template;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.virtual.ActualEnvironment;
import org.alfresco.repo.virtual.VirtualizationException;
import org.alfresco.repo.virtual.config.NodeRefPathExpression;
import org.alfresco.repo.virtual.ref.GetActualNodeRefMethod;
import org.alfresco.repo.virtual.ref.Reference;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ISO9075;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* A {@link FilingRule} created with the criteria given in the applied virtual
* folder template.
*
* @author Bogdan Horje
*/
public class TemplateFilingRule implements FilingRule
{
private static Log logger = LogFactory.getLog(TemplateFilingRule.class);
private ActualEnvironment env;
private String path;
private String type;
private Set<String> aspects;
private Map<String, String> stringProperties;
public TemplateFilingRule(ActualEnvironment environment, String path, String type, Set<String> aspects,
Map<String, String> properties)
{
this.env = environment;
this.path = path;
this.type = type;
this.aspects = aspects;
this.stringProperties = properties;
}
@Override
public FilingData createFilingData(FilingParameters parameters) throws VirtualizationException
{
return createFilingData(parameters.getParentRef(),
parameters.getAssocTypeQName(),
parameters.getAssocQName(),
parameters.getNodeTypeQName(),
parameters.getProperties());
}
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);
// CM-528 acceptance criteria 3 :
// Given that the current user can upload new content into a
// specific virtual folder (filing rule)
// when a filing rule specifies a type or sub type of cm:folder
// (which is a non supported configuration)
// uploading content will create a document, not a folder
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;
}
// Explicit type matching follows.
// It might cause non-transactional behavior.
// To avoid it we rely on folder creation exclusion in
// VirtualNodeServiceExtension#createNode
// See CM-533 Suppress options to create folders in a virtual folder
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);
}
private NodeRef parentNodeRefFor(Reference parentReference, boolean failIfNotFound)
{
NodeRef fParentRef;
if (path == null || path.length() == 0)
{
fParentRef = parentReference.execute(new GetActualNodeRefMethod(env));
}
else
{
String[] pathElements = NodeRefPathExpression.splitAndNormalizePath(path);
for (int i = 0; i < pathElements.length; i++)
{
pathElements[i] = ISO9075.decode(pathElements[i]);
}
fParentRef = env.findQNamePath(pathElements);
}
boolean noReadPermissions = false;
if (fParentRef != null && !env.hasPermission(fParentRef,
PermissionService.READ_PERMISSIONS))
{
fParentRef = null;
noReadPermissions = true;
}
if (logger.isDebugEnabled())
{
if (fParentRef == null)
{
if (noReadPermissions)
{
logger.debug("Current user does not have READ_PERMISSIONS for filing path" + path + ".");
}
else
{
logger.debug("The filing path " + path + " doesn't exist.");
}
}
}
if (failIfNotFound && fParentRef == null)
{
throw new VirtualizationException("The filing path " + path + " could not be resolved.");
}
return fParentRef;
}
@Override
public boolean isNullFilingRule()
{
return false;
}
@Override
public NodeRef filingNodeRefFor(FilingParameters parameters) throws VirtualizationException
{
return parentNodeRefFor(parameters.getParentRef(),
false);
}
}