mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Feature/repo 5172 node definition (#672)
* [REPO-5172] Added Definition to Node API * [REPO-5172] fix braces style * [REPO-5172] Code review * [REPO-5172] Type information deleted from Definition * [REPO-5172] Added excluded properties * [REPO-5172] Deleted attribute isOverride from NodeDefinitionProperty * [REPO-5172] Added test * [REPO-5172] temporary change to traviso conf file for test purpose * [maven-release-plugin][skip ci] prepare release alfresco-remote-api-repo-5172-8.190-1 * [maven-release-plugin][skip ci] prepare for next development iteration * Revert "[REPO-5172] temporary change to travis conf file for test purpose" * [REPO-5172] fix import in NodeApiTest
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.rest.api.model.NodeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.cmr.i18n.MessageLookup;
|
||||
/**
|
||||
* Maps representations from TypeDefinition to NodeDefinition
|
||||
*
|
||||
* @author gfertuso
|
||||
*/
|
||||
public interface NodeDefinitionMapper
|
||||
{
|
||||
NodeDefinition fromTypeDefinition(TypeDefinition typeDefinition, MessageLookup messageLookup);
|
||||
}
|
@@ -380,6 +380,7 @@ public interface Nodes
|
||||
String PARAM_INCLUDE_ISFAVORITE = "isFavorite";
|
||||
|
||||
String PARAM_INCLUDE_ASSOCIATION = "association";
|
||||
String PARAM_INCLUDE_DEFINITION = "definition";
|
||||
|
||||
String PARAM_ISFOLDER = "isFolder";
|
||||
String PARAM_ISFILE = "isFile";
|
||||
|
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.rest.api.NodeDefinitionMapper;
|
||||
import org.alfresco.rest.api.model.NodeDefinitionConstraint;
|
||||
import org.alfresco.rest.api.model.NodeDefinition;
|
||||
import org.alfresco.rest.api.model.NodeDefinitionProperty;
|
||||
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.cmr.i18n.MessageLookup;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
/**
|
||||
* Maps representations from TypeDefinition to NodeDefinition
|
||||
*
|
||||
* @author gfertuso
|
||||
*/
|
||||
public class NodeDefinitionMapperImpl implements NodeDefinitionMapper
|
||||
{
|
||||
|
||||
private final List<String> EXCLUDED_NS = Arrays.asList(NamespaceService.SYSTEM_MODEL_1_0_URI);
|
||||
private static final List<QName> EXCLUDED_PROPS = Arrays.asList(ContentModel.PROP_CONTENT);
|
||||
|
||||
@Override
|
||||
public NodeDefinition fromTypeDefinition(TypeDefinition typeDefinition,
|
||||
MessageLookup messageLookup)
|
||||
{
|
||||
|
||||
if (typeDefinition == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Undefined definition for the node");
|
||||
}
|
||||
NodeDefinition nodeDefinition = new NodeDefinition();
|
||||
nodeDefinition.setProperties(getProperties(typeDefinition.getProperties(), messageLookup));
|
||||
|
||||
return nodeDefinition;
|
||||
}
|
||||
|
||||
private boolean isPropertyExcluded(QName propertyName)
|
||||
{
|
||||
return EXCLUDED_NS.contains(propertyName.getNamespaceURI()) || EXCLUDED_PROPS.contains(propertyName);
|
||||
}
|
||||
|
||||
private List <NodeDefinitionProperty> getProperties(Map<QName, PropertyDefinition> propertiesMap, MessageLookup messageLookup)
|
||||
{
|
||||
return propertiesMap.values().stream()
|
||||
.filter(p -> !isPropertyExcluded(p.getName()))
|
||||
.map(p -> fromPropertyDefinitionToProperty(p , messageLookup))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private NodeDefinitionProperty fromPropertyDefinitionToProperty(PropertyDefinition propertyDefinition,
|
||||
MessageLookup messageLookup)
|
||||
{
|
||||
NodeDefinitionProperty property = new NodeDefinitionProperty();
|
||||
property.setId(propertyDefinition.getName().toPrefixString());
|
||||
property.setTitle(propertyDefinition.getTitle(messageLookup));
|
||||
property.setDescription(propertyDefinition.getDescription(messageLookup));
|
||||
property.setDefaultValue(propertyDefinition.getDefaultValue());
|
||||
property.setDataType(propertyDefinition.getDataType().getName().toPrefixString());
|
||||
property.setIsMultiValued(propertyDefinition.isMultiValued());
|
||||
property.setIsMandatory(propertyDefinition.isMandatory());
|
||||
property.setIsMandatoryEnforced(propertyDefinition.isMandatoryEnforced());
|
||||
property.setIsProtected(propertyDefinition.isProtected());
|
||||
property.setConstraints(getConstraints(propertyDefinition.getConstraints(), messageLookup));
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
private List<NodeDefinitionConstraint> getConstraints( Collection<ConstraintDefinition> constraintDefinitions,
|
||||
MessageLookup messageLookup)
|
||||
{
|
||||
|
||||
return constraintDefinitions.stream()
|
||||
.filter(constraint -> constraint.getConstraint() != null)
|
||||
.map(constraint -> fromConstraintDefinitionToConstraint(constraint, messageLookup))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private NodeDefinitionConstraint fromConstraintDefinitionToConstraint(ConstraintDefinition constraintDefinition,
|
||||
MessageLookup messageLookup)
|
||||
{
|
||||
NodeDefinitionConstraint constraint = new NodeDefinitionConstraint();
|
||||
constraint.setId(constraintDefinition.getConstraint().getShortName());
|
||||
constraint.setType(constraintDefinition.getConstraint().getType());
|
||||
constraint.setTitle(constraintDefinition.getTitle(messageLookup));
|
||||
constraint.setDescription(constraintDefinition.getDescription(messageLookup));
|
||||
constraint.setParameters(constraintDefinition.getConstraint().getParameters());
|
||||
return constraint;
|
||||
}
|
||||
|
||||
}
|
@@ -80,10 +80,12 @@ import org.alfresco.repo.version.VersionModel;
|
||||
import org.alfresco.repo.virtual.store.VirtualStore;
|
||||
import org.alfresco.rest.antlr.WhereClauseParser;
|
||||
import org.alfresco.rest.api.Activities;
|
||||
import org.alfresco.rest.api.NodeDefinitionMapper;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.QuickShareLinks;
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
import org.alfresco.rest.api.model.NodeDefinition;
|
||||
import org.alfresco.rest.api.model.Document;
|
||||
import org.alfresco.rest.api.model.Folder;
|
||||
import org.alfresco.rest.api.model.LockInfo;
|
||||
@@ -125,6 +127,7 @@ import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.lock.NodeLockedException;
|
||||
import org.alfresco.service.cmr.model.FileExistsException;
|
||||
@@ -215,6 +218,7 @@ public class NodesImpl implements Nodes
|
||||
private RetryingTransactionHelper retryingTransactionHelper;
|
||||
private LockService lockService;
|
||||
private VirtualStore smartStore; // note: remove as part of REPO-1173
|
||||
private NodeDefinitionMapper nodeDefinitionMapper;
|
||||
|
||||
private enum Activity_Type
|
||||
{
|
||||
@@ -312,6 +316,11 @@ public class NodesImpl implements Nodes
|
||||
{
|
||||
this.smartStore = smartStore;
|
||||
}
|
||||
|
||||
public void setNodeDefinitionMapper(NodeDefinitionMapper nodeDefinitionMapper)
|
||||
{
|
||||
this.nodeDefinitionMapper = nodeDefinitionMapper;
|
||||
}
|
||||
|
||||
// excluded namespaces (aspects, properties, assoc types)
|
||||
private static final List<String> EXCLUDED_NS = Arrays.asList(NamespaceService.SYSTEM_MODEL_1_0_URI);
|
||||
@@ -1026,12 +1035,26 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
}
|
||||
|
||||
if (includeParam.contains(PARAM_INCLUDE_DEFINITION))
|
||||
{
|
||||
NodeDefinition nodeDefinition = nodeDefinitionMapper.fromTypeDefinition(getTypeDefinition(nodeRef), dictionaryService);
|
||||
node.setDefinition(nodeDefinition);
|
||||
}
|
||||
|
||||
node.setNodeType(nodeTypeQName.toPrefixString(namespaceService));
|
||||
node.setPath(pathInfo);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
private TypeDefinition getTypeDefinition(NodeRef nodeRef)
|
||||
{
|
||||
QName type = nodeService.getType(nodeRef);
|
||||
Set<QName> aspectNames = nodeService.getAspects(nodeRef);
|
||||
TypeDefinition typeDefinition = dictionaryService.getAnonymousType(type, aspectNames);
|
||||
return typeDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathInfo lookupPathInfo(NodeRef nodeRefIn, ChildAssociationRef archivedParentAssoc)
|
||||
{
|
||||
@@ -3668,4 +3691,3 @@ public class NodesImpl implements Nodes
|
||||
return repositoryHelper;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -95,6 +95,7 @@ public class Node implements Comparable<Node>
|
||||
|
||||
protected List<String> allowableOperations;
|
||||
protected NodePermissions nodePermissions;
|
||||
protected NodeDefinition definition;
|
||||
|
||||
//optional SearchEntry (only ever returned from a search)
|
||||
protected SearchEntry search = null;
|
||||
@@ -469,6 +470,16 @@ public class Node implements Comparable<Node>
|
||||
this.secondaryChildren = secondaryChildren;
|
||||
}
|
||||
|
||||
public NodeDefinition getDefinition()
|
||||
{
|
||||
return definition;
|
||||
}
|
||||
|
||||
public void setDefinition(NodeDefinition definition)
|
||||
{
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Node node)
|
||||
{
|
||||
|
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* Represents the node definition.
|
||||
*
|
||||
* @author gfertuso
|
||||
*/
|
||||
public class NodeDefinition
|
||||
{
|
||||
|
||||
List <NodeDefinitionProperty> properties;
|
||||
|
||||
public List<NodeDefinitionProperty> getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(List<NodeDefinitionProperty> properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.Map;
|
||||
/**
|
||||
* Represents a constraint of a node definition property.
|
||||
*
|
||||
* @author gfertuso
|
||||
*/
|
||||
public class NodeDefinitionConstraint
|
||||
{
|
||||
private String id;
|
||||
private String type;
|
||||
private String title;
|
||||
private String description;
|
||||
private Map<String, Object> parameters;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(Map<String, Object> parameters)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* Represents a property of the node definition.
|
||||
*
|
||||
* @author gfertuso
|
||||
*/
|
||||
public class NodeDefinitionProperty
|
||||
{
|
||||
private String id;
|
||||
private String title;
|
||||
private String description;
|
||||
private String defaultValue;
|
||||
private String dataType;
|
||||
private Boolean isMultiValued;
|
||||
private Boolean isMandatory;
|
||||
private Boolean isMandatoryEnforced;
|
||||
private Boolean isProtected;
|
||||
private List<NodeDefinitionConstraint> constraints;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDefaultValue()
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue)
|
||||
{
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getDataType()
|
||||
{
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType)
|
||||
{
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public boolean getIsProtected()
|
||||
{
|
||||
return isProtected;
|
||||
}
|
||||
|
||||
public void setIsProtected(boolean isProtected)
|
||||
{
|
||||
this.isProtected = isProtected;
|
||||
}
|
||||
|
||||
public List<NodeDefinitionConstraint> getConstraints()
|
||||
{
|
||||
return constraints;
|
||||
}
|
||||
|
||||
public void setConstraints(List<NodeDefinitionConstraint> constraints)
|
||||
{
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
public boolean getIsMultiValued()
|
||||
{
|
||||
return isMultiValued;
|
||||
}
|
||||
|
||||
public void setIsMultiValued(boolean isMultiValued)
|
||||
{
|
||||
this.isMultiValued = isMultiValued;
|
||||
}
|
||||
|
||||
public boolean getIsMandatory()
|
||||
{
|
||||
return isMandatory;
|
||||
}
|
||||
|
||||
public void setIsMandatory(boolean isMandatory)
|
||||
{
|
||||
this.isMandatory = isMandatory;
|
||||
}
|
||||
|
||||
public boolean getIsMandatoryEnforced()
|
||||
{
|
||||
return isMandatoryEnforced;
|
||||
}
|
||||
|
||||
public void setIsMandatoryEnforced(boolean isMandatoryEnforced)
|
||||
{
|
||||
this.isMandatoryEnforced = isMandatoryEnforced;
|
||||
}
|
||||
|
||||
}
|
@@ -518,6 +518,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="nodeDefinitionMapper" class="org.alfresco.rest.api.impl.NodeDefinitionMapperImpl"/>
|
||||
|
||||
<bean id="nodes" class="org.alfresco.rest.api.impl.NodesImpl" init-method="init">
|
||||
<property name="serviceRegistry" ref="ServiceRegistry"/>
|
||||
<property name="repositoryHelper" ref="repositoryHelper"/>
|
||||
@@ -527,6 +529,7 @@
|
||||
<property name="nonAttachContentTypes" ref="nodes.nonAttachContentTypes"/>
|
||||
<property name="poster" ref="activitiesPoster" />
|
||||
<property name="smartStore" ref="smartStore"/>
|
||||
<property name="nodeDefinitionMapper" ref="nodeDefinitionMapper" />
|
||||
</bean>
|
||||
|
||||
<bean id="Nodes" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
|
@@ -53,6 +53,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.ContentLimitProvider.SimpleFixedLimitProvider;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
@@ -61,8 +62,11 @@ import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.LockInfo;
|
||||
import org.alfresco.rest.api.model.NodeDefinition;
|
||||
import org.alfresco.rest.api.model.NodeDefinitionConstraint;
|
||||
import org.alfresco.rest.api.model.NodePermissions;
|
||||
import org.alfresco.rest.api.model.NodeTarget;
|
||||
import org.alfresco.rest.api.model.NodeDefinitionProperty;
|
||||
import org.alfresco.rest.api.model.Site;
|
||||
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
@@ -95,6 +99,7 @@ import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.commons.collections.map.MultiValueMap;
|
||||
@@ -130,6 +135,8 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
protected PermissionService permissionService;
|
||||
protected AuthorityService authorityService;
|
||||
private NodeService nodeService;
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
|
||||
private String rootGroupName = null;
|
||||
private String groupA = null;
|
||||
@@ -143,6 +150,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
|
||||
authorityService = (AuthorityService) applicationContext.getBean("AuthorityService");
|
||||
nodeService = applicationContext.getBean("NodeService", NodeService.class);
|
||||
namespaceService= (NamespaceService) applicationContext.getBean("NamespaceService");
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -5885,5 +5893,102 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
return "public";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveNodeDefinition() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), user1, null);
|
||||
|
||||
String node1 = "nodeSample" + RUNID + "_1";
|
||||
String node1Type = TYPE_CM_CONTENT;
|
||||
Map<String,Object> props = new HashMap<>();
|
||||
props.put("cm:title", "add aspect property");
|
||||
Node node = createNode(Nodes.PATH_MY, node1, node1Type, props);
|
||||
String nodeId = node.getId();
|
||||
|
||||
HttpResponse response = getSingle(NodesEntityResource.class, nodeId, null, 200);
|
||||
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
|
||||
assertNull("Definition should not be retrieved unless included!", nodeResp.getDefinition());
|
||||
|
||||
Map params = new HashMap<>();
|
||||
params.put("include", "definition");
|
||||
response = getSingle(NodesEntityResource.class, nodeId, params, 200);
|
||||
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
|
||||
NodeDefinition nodeDefinition = nodeResp.getDefinition();
|
||||
assertNotNull(nodeDefinition);
|
||||
checkDefinitionProperties(nodeDefinition.getProperties());
|
||||
}
|
||||
|
||||
private void checkDefinitionProperties(List<NodeDefinitionProperty> properties)
|
||||
{
|
||||
assertNotNull(properties);
|
||||
shouldNotContainSystemProperties(properties);
|
||||
shouldContainParentProperties(properties);
|
||||
shouldContainAspectProperties(properties);
|
||||
|
||||
NodeDefinitionProperty testProperty = properties.stream().
|
||||
filter(property ->
|
||||
property.getId().equals("cm:name"))
|
||||
.findFirst()
|
||||
.get();
|
||||
assertNotNull(testProperty);
|
||||
assertEquals("Name", testProperty.getTitle());
|
||||
assertEquals("d:text", testProperty.getDataType());
|
||||
assertEquals("Name", testProperty.getDescription());
|
||||
assertTrue(testProperty.getIsMandatory());
|
||||
assertTrue(testProperty.getIsMandatoryEnforced());
|
||||
assertFalse(testProperty.getIsMultiValued());
|
||||
assertNull(testProperty.getDefaultValue());
|
||||
checkPropertyConstraints(testProperty.getConstraints());
|
||||
|
||||
}
|
||||
|
||||
private void shouldNotContainSystemProperties(List<NodeDefinitionProperty> properties)
|
||||
{
|
||||
assertTrue(properties.stream()
|
||||
.noneMatch(property ->
|
||||
property.getId().startsWith(NamespaceService.SYSTEM_MODEL_PREFIX) ||
|
||||
property.getId().equals(ContentModel.PROP_CONTENT.toPrefixString(namespaceService))));
|
||||
}
|
||||
|
||||
private void shouldContainParentProperties(List<NodeDefinitionProperty> properties)
|
||||
{
|
||||
assertTrue(properties.stream()
|
||||
.anyMatch(property ->
|
||||
property.getId().equals("cm:name")));
|
||||
}
|
||||
|
||||
private void shouldContainAspectProperties(List<NodeDefinitionProperty> properties)
|
||||
{
|
||||
NodeDefinitionProperty mandatoryAspectProperty = properties.stream()
|
||||
.filter(property -> property.getId().equals("cm:created"))
|
||||
.findFirst()
|
||||
.get();
|
||||
assertNotNull(mandatoryAspectProperty);
|
||||
|
||||
NodeDefinitionProperty nodeAspectProperty = properties.stream()
|
||||
.filter(property -> property.getId().equals("cm:title"))
|
||||
.findFirst()
|
||||
.get();
|
||||
assertNotNull(nodeAspectProperty);
|
||||
}
|
||||
|
||||
private void checkPropertyConstraints(List<NodeDefinitionConstraint> constraints)
|
||||
{
|
||||
assertNotNull(constraints);
|
||||
NodeDefinitionConstraint nodeDefinitionConstraint = constraints.stream()
|
||||
.filter(constraint -> constraint.getId().equals("cm:filename"))
|
||||
.findFirst()
|
||||
.get();
|
||||
assertNotNull(nodeDefinitionConstraint);
|
||||
assertEquals("REGEX", nodeDefinitionConstraint.getType());
|
||||
Map<String, Object> constraintParameters = nodeDefinitionConstraint.getParameters();
|
||||
assertNotNull(constraintParameters);
|
||||
assertNull(nodeDefinitionConstraint.getDescription());
|
||||
assertNull(nodeDefinitionConstraint.getTitle());
|
||||
assertEquals(2, constraintParameters.size());
|
||||
assertEquals("(.*[\\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)", constraintParameters.get("expression"));
|
||||
assertFalse((Boolean) constraintParameters.get("requiresMatch"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,7 @@ package org.alfresco.rest.api.tests.client.data;
|
||||
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
import org.alfresco.rest.api.model.NodeDefinition;
|
||||
import org.alfresco.rest.api.model.NodePermissions;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -79,6 +80,7 @@ public class Node
|
||||
|
||||
protected List<String> allowableOperations;
|
||||
protected NodePermissions nodePermissions;
|
||||
protected NodeDefinition definition;
|
||||
|
||||
// please note: these are currently only used (optionally) for node create request
|
||||
protected String relativePath;
|
||||
@@ -323,6 +325,15 @@ public class Node
|
||||
this.targets = targets;
|
||||
}
|
||||
|
||||
public NodeDefinition getDefinition()
|
||||
{
|
||||
return definition;
|
||||
}
|
||||
|
||||
public void setDefinition(NodeDefinition definition)
|
||||
{
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
// note: can be child or peer (latter has assocType only)
|
||||
protected Association association;
|
||||
|
Reference in New Issue
Block a user