use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class OpenCmisQueryTest method testBasicDefaultMetaData.
public void testBasicDefaultMetaData() {
CMISQueryOptions options = new CMISQueryOptions("SELECT * FROM cmis:document", rootNodeRef.getStoreRef());
CMISResultSet rs = cmisQueryService.query(options);
CMISResultSetMetaData md = rs.getMetaData();
assertNotNull(md.getQueryOptions());
TypeDefinitionWrapper typeDef = cmisDictionaryService.findType(BaseTypeId.CMIS_DOCUMENT.value());
int count = 0;
for (PropertyDefinitionWrapper pdef : typeDef.getProperties()) {
count++;
}
assertEquals(count, md.getColumnNames().length);
assertNotNull(md.getColumn(PropertyIds.OBJECT_ID));
assertEquals(1, md.getSelectors().length);
assertNotNull(md.getSelector(""));
rs.close();
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method getRelationships.
public List<ObjectData> getRelationships(NodeRef nodeRef, IncludeRelationships includeRelationships) /*, CmisVersion cmisVersion*/
{
List<ObjectData> result = new ArrayList<ObjectData>();
if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL)) {
// relationships from and to versions are not preserved
return result;
}
// get relationships
List<AssociationRef> assocs = new ArrayList<AssociationRef>();
if (includeRelationships == IncludeRelationships.SOURCE || includeRelationships == IncludeRelationships.BOTH) {
assocs.addAll(nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
}
if (includeRelationships == IncludeRelationships.TARGET || includeRelationships == IncludeRelationships.BOTH) {
assocs.addAll(nodeService.getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
}
// filter relationships that not map the CMIS domain model
for (AssociationRef assocRef : assocs) {
TypeDefinitionWrapper assocTypeDef = getOpenCMISDictionaryService().findAssocType(assocRef.getTypeQName());
if (assocTypeDef == null || getType(assocRef.getSourceRef()) == null || getType(assocRef.getTargetRef()) == null) {
continue;
}
try {
result.add(createCMISObject(createNodeInfo(assocRef), null, false, IncludeRelationships.NONE, RENDITION_NONE, false, false));
} catch (AccessDeniedException e) {
// PUBLICAPI-110
// ok, just skip it
} catch (CmisObjectNotFoundException e) {
// ignore objects that have not been found (perhaps because their type is unknown to CMIS)
}// TODO: Somewhere this has not been wrapped correctly
catch (net.sf.acegisecurity.AccessDeniedException e) {
// skip
}
}
return result;
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method checkChildObjectType.
/**
* Checks if a child of a given type can be added to a given folder.
*/
@SuppressWarnings("unchecked")
public void checkChildObjectType(CMISNodeInfo folderInfo, String childType) {
TypeDefinitionWrapper targetType = folderInfo.getType();
PropertyDefinitionWrapper allowableChildObjectTypeProperty = targetType.getPropertyById(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS);
List<String> childTypes = (List<String>) allowableChildObjectTypeProperty.getPropertyAccessor().getValue(folderInfo);
if ((childTypes == null) || childTypes.isEmpty()) {
return;
}
if (!childTypes.contains(childType)) {
throw new CmisConstraintException("Objects of type '" + childType + "' cannot be added to this folder!");
}
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method getObjectRelationships.
public ObjectList getObjectRelationships(NodeRef nodeRef, RelationshipDirection relationshipDirection, String typeId, String filter, Boolean includeAllowableActions, BigInteger maxItems, BigInteger skipCount) {
ObjectListImpl result = new ObjectListImpl();
result.setHasMoreItems(false);
result.setNumItems(BigInteger.ZERO);
result.setObjects(new ArrayList<ObjectData>());
if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL)) {
// relationships from and to versions are not preserved
return result;
}
// get relationships
List<AssociationRef> assocs = new ArrayList<AssociationRef>();
if (relationshipDirection == RelationshipDirection.SOURCE || relationshipDirection == RelationshipDirection.EITHER) {
assocs.addAll(nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
}
if (relationshipDirection == RelationshipDirection.TARGET || relationshipDirection == RelationshipDirection.EITHER) {
assocs.addAll(nodeService.getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
}
int skip = (skipCount == null ? 0 : skipCount.intValue());
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
int counter = 0;
boolean hasMore = false;
if (max > 0) {
// filter relationships that not map the CMIS domain model
for (AssociationRef assocRef : assocs) {
TypeDefinitionWrapper assocTypeDef = getOpenCMISDictionaryService().findAssocType(assocRef.getTypeQName());
if (assocTypeDef == null || getType(assocRef.getSourceRef()) == null || getType(assocRef.getTargetRef()) == null) {
continue;
}
if ((typeId != null) && !assocTypeDef.getTypeId().equals(typeId)) {
continue;
}
counter++;
if (skip > 0) {
skip--;
continue;
}
max--;
if (max > 0) {
try {
result.getObjects().add(createCMISObject(createNodeInfo(assocRef), filter, includeAllowableActions, IncludeRelationships.NONE, RENDITION_NONE, false, false));
} catch (CmisObjectNotFoundException e) {
// ignore objects that have not been found (perhaps because their type is unknown to CMIS)
}
} else {
hasMore = true;
}
}
}
result.setNumItems(BigInteger.valueOf(counter));
result.setHasMoreItems(hasMore);
return result;
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method setProperties.
/**
* Sets property values.
*/
@SuppressWarnings({ "rawtypes" })
public void setProperties(NodeRef nodeRef, TypeDefinitionWrapper type, Properties properties, String... exclude) {
if (properties == null) {
return;
}
Map<String, PropertyData<?>> incomingPropsMap = properties.getProperties();
if (incomingPropsMap == null) {
return;
}
// extract property data into an easier to use form
Map<String, Pair<TypeDefinitionWrapper, Serializable>> propsMap = new HashMap<String, Pair<TypeDefinitionWrapper, Serializable>>();
for (String propertyId : incomingPropsMap.keySet()) {
PropertyData<?> property = incomingPropsMap.get(propertyId);
PropertyDefinitionWrapper propDef = type.getPropertyById(property.getId());
if (propDef == null) {
propDef = getOpenCMISDictionaryService().findProperty(propertyId);
if (propDef == null) {
throw new CmisInvalidArgumentException("Property " + property.getId() + " is unknown!");
}
}
Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef);
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
if (!isUpdatable(updatability, isOnWorkingCopy)) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
}
TypeDefinitionWrapper propType = propDef.getOwningType();
Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI);
Pair<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, value);
propsMap.put(propertyId, pair);
}
// Need to do deal with secondary types first
Pair<TypeDefinitionWrapper, Serializable> pair = propsMap.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
Serializable secondaryTypesProperty = (pair != null ? pair.getSecond() : null);
if (secondaryTypesProperty != null) {
if (!(secondaryTypesProperty instanceof List)) {
throw new CmisInvalidArgumentException("Secondary types must be a list!");
}
List secondaryTypes = (List) secondaryTypesProperty;
if (secondaryTypes != null && secondaryTypes.size() > 0) {
// add/remove secondary types/aspects
processSecondaryTypes(nodeRef, secondaryTypes, propsMap);
}
}
for (String propertyId : propsMap.keySet()) {
if (propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
// already handled above
continue;
}
pair = propsMap.get(propertyId);
TypeDefinitionWrapper propType = pair.getFirst();
Serializable value = pair.getSecond();
if (Arrays.binarySearch(exclude, propertyId) < 0) {
setProperty(nodeRef, propType, propertyId, value);
}
}
List<CmisExtensionElement> extensions = properties.getExtensions();
if (extensions != null) {
boolean isNameChanging = properties.getProperties().containsKey(PropertyIds.NAME);
for (CmisExtensionElement extension : extensions) {
if (ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace()) && SET_ASPECTS.equals(extension.getName())) {
setAspectProperties(nodeRef, isNameChanging, extension);
break;
}
}
}
}
Aggregations