use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getObjectRelationships.
// --- relationship service ---
@Override
public ObjectList getObjectRelationships(String repositoryId, String objectId, Boolean includeSubRelationshipTypes, RelationshipDirection relationshipDirection, String typeId, String filter, Boolean includeAllowableActions, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// what kind of object is it?
CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
if (info.isVariant(CMISObjectVariant.ASSOC)) {
throw new CmisInvalidArgumentException("Object is a relationship!");
}
if (info.isVariant(CMISObjectVariant.VERSION)) {
throw new CmisInvalidArgumentException("Object is a document version!");
}
// check if the relationship base type is requested
if (BaseTypeId.CMIS_RELATIONSHIP.value().equals(typeId)) {
boolean isrt = (includeSubRelationshipTypes == null ? false : includeSubRelationshipTypes.booleanValue());
if (isrt) {
// all relationships are a direct subtype of the base type in
// Alfresco -> remove filter
typeId = null;
} else {
// there are no relationships of the base type in Alfresco ->
// return empty list
ObjectListImpl result = new ObjectListImpl();
result.setHasMoreItems(false);
result.setNumItems(BigInteger.ZERO);
result.setObjects(new ArrayList<ObjectData>());
return result;
}
}
return connector.getObjectRelationships(info.getNodeRef(), relationshipDirection, typeId, filter, includeAllowableActions, maxItems, skipCount);
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method updateProperties.
@Override
public void updateProperties(String repositoryId, Holder<String> objectId, Holder<String> changeToken, final Properties properties, ExtensionsData extension) {
checkRepositoryId(repositoryId);
final CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
if (info.isVariant(CMISObjectVariant.ASSOC)) {
throw new CmisInvalidArgumentException("Relationship properties cannot be updated!");
} else {
if (info.isVariant(CMISObjectVariant.VERSION)) {
throw new CmisInvalidArgumentException("Document is not the latest version!");
}
final NodeRef nodeRef = info.getNodeRef();
connector.setProperties(nodeRef, info.getType(), properties, new String[0]);
objectId.setValue(connector.createObjectId(nodeRef));
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, objectId.getValue(), "*", IncludeRelationships.NONE);
}
connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
}
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getContentStream.
@Override
public ContentStream getContentStream(String repositoryId, String objectId, String streamId, BigInteger offset, BigInteger length, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// what kind of object is it?
CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
// relationships cannot have content
if (info.isVariant(CMISObjectVariant.ASSOC)) {
throw new CmisInvalidArgumentException("Object is a relationship and cannot have content!");
}
// now get it
return connector.getContentStream(info, streamId, offset, length);
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method createDocument.
@Override
public String createDocument(String repositoryId, final Properties properties, String folderId, final ContentStream contentStream, VersioningState versioningState, final List<String> policies, final Acl addAces, final Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get the parent folder node ref
final CMISNodeInfo parentInfo = getOrCreateFolderInfo(folderId, "Parent folder");
// get name and type
final String name = connector.getNameProperty(properties, null);
final String objectTypeId = connector.getObjectTypeIdProperty(properties);
final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_DOCUMENT);
connector.checkChildObjectType(parentInfo, type.getTypeId());
DocumentTypeDefinition docType = (DocumentTypeDefinition) type.getTypeDefinition(false);
if ((docType.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) && (contentStream != null)) {
throw new CmisConstraintException("This document type does not support content!");
}
if ((docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) && (contentStream == null)) {
throw new CmisConstraintException("This document type does requires content!");
}
if (!docType.isVersionable() && (versioningState != VersioningState.NONE)) {
throw new CmisConstraintException("This document type is not versionable!");
}
versioningState = getDocumentDefaultVersioningState(versioningState, type);
FileInfo fileInfo = connector.getFileFolderService().create(parentInfo.getNodeRef(), name, type.getAlfrescoClass());
NodeRef nodeRef = fileInfo.getNodeRef();
connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
connector.applyPolicies(nodeRef, type, policies);
connector.applyACL(nodeRef, type, addAces, removeAces);
// handle content
if (contentStream != null) {
// write content
String mimeType = parseMimeType(contentStream);
String encoding = getEncoding(contentStream.getStream(), mimeType);
ContentWriter writer = connector.getFileFolderService().getWriter(nodeRef);
writer.setMimetype(mimeType);
writer.setEncoding(encoding);
writer.putContent(contentStream.getStream());
}
connector.extractMetadata(nodeRef);
// generate "doclib" thumbnail asynchronously
connector.createThumbnails(nodeRef, Collections.singleton("doclib"));
connector.applyVersioningState(nodeRef, versioningState);
String objectId = connector.createObjectId(nodeRef);
connector.getActivityPoster().postFileFolderAdded(nodeRef);
return objectId;
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getObjectByPath.
@Override
public ObjectData getObjectByPath(String repositoryId, String path, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds, Boolean includeAcl, ExtensionsData extension) {
long start = System.currentTimeMillis();
boolean isObjectInfoRequired = false;
checkRepositoryId(repositoryId);
// start at the root node
NodeRef rootNodeRef = connector.getRootNodeRef();
ObjectData object;
if (path.equals("/")) {
object = connector.createCMISObject(createNodeInfo(rootNodeRef), filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl);
} else {
try {
// resolve path and get the node ref
FileInfo fileInfo = connector.getFileFolderService().resolveNamePath(rootNodeRef, Arrays.asList(path.substring(1).split("/")));
if (connector.filter(fileInfo.getNodeRef())) {
throw new CmisObjectNotFoundException("Object not found: " + path);
}
CMISNodeInfo info = createNodeInfo(fileInfo.getNodeRef(), fileInfo.getType(), fileInfo.getProperties(), null, false);
object = connector.createCMISObject(info, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl);
isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, info.getObjectId(), includeRelationships);
}
} catch (FileNotFoundException e) {
throw new CmisObjectNotFoundException("Object not found: " + path);
}
}
logGetObjectCall("getObjectByPath", start, path, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl, isObjectInfoRequired, extension);
return object;
}
Aggregations