use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method createItem.
@Override
public String createItem(String repositoryId, Properties properties, String folderId, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get the parent folder node ref
final CMISNodeInfo parentInfo = getOrCreateFolderInfo(folderId, "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_ITEM);
connector.checkChildObjectType(parentInfo, type.getTypeId());
/**
* The above code specifies a folder - so the contents of a folder (as defined by the alfresco model) are
* ASSOC cm:contains to a TYPE sys:base
*/
QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(name));
Map<QName, Serializable> props = new HashMap<QName, Serializable>(11);
props.put(ContentModel.PROP_NAME, (Serializable) assocQName.getLocalName());
ChildAssociationRef newRef = connector.getNodeService().createNode(parentInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, assocQName, type.getAlfrescoClass(), props);
NodeRef nodeRef = newRef.getChildRef();
connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
connector.getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, assocQName.getLocalName());
connector.applyPolicies(nodeRef, type, policies);
connector.applyACL(nodeRef, type, addAces, removeAces);
String objectId = connector.createObjectId(nodeRef);
return objectId;
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class CMISConnector method getContentStream.
/**
* Gets the content from the repository.
*/
public ContentStream getContentStream(CMISNodeInfo info, String streamId, BigInteger offset, BigInteger length) {
// get the type and check if the object can have content
TypeDefinitionWrapper type = info.getType();
checkDocumentTypeForContent(type);
// looks like a document, now get the content
ContentStreamImpl result = new ContentStreamImpl();
result.setFileName(info.getName());
// if streamId is set, fetch other content
NodeRef streamNodeRef = info.getNodeRef();
if ((streamId != null) && (streamId.length() > 0)) {
CMISNodeInfo streamInfo = createNodeInfo(streamId);
if (!streamInfo.isVariant(CMISObjectVariant.CURRENT_VERSION)) {
throw new CmisInvalidArgumentException("Stream id is invalid: " + streamId + ", expected variant " + CMISObjectVariant.CURRENT_VERSION + ", got variant " + streamInfo.getObjectVariant());
}
streamNodeRef = streamInfo.getNodeRef();
type = streamInfo.getType();
checkDocumentTypeForContent(type);
}
// get the stream now
try {
ContentReader contentReader = contentService.getReader(streamNodeRef, ContentModel.PROP_CONTENT);
if (contentReader == null) {
throw new CmisConstraintException("Document has no content!");
}
result.setMimeType(contentReader.getMimetype());
long contentSize = contentReader.getSize();
if ((offset == null) && (length == null)) {
result.setStream(contentReader.getContentInputStream());
result.setLength(BigInteger.valueOf(contentSize));
publishReadEvent(streamNodeRef, info.getName(), result.getMimeType(), contentSize, contentReader.getEncoding(), null);
} else {
long off = (offset == null ? 0 : offset.longValue());
long len = (length == null ? contentSize : length.longValue());
if (off + len > contentSize) {
len = contentReader.getSize() - off;
}
result.setStream(new RangeInputStream(contentReader.getContentInputStream(), off, len));
result.setLength(BigInteger.valueOf(len));
publishReadEvent(streamNodeRef, info.getName(), result.getMimeType(), contentSize, contentReader.getEncoding(), off + " - " + len);
}
} catch (Exception e) {
if (e instanceof CmisBaseException) {
throw (CmisBaseException) e;
} else {
StringBuilder msg = new StringBuilder("Failed to retrieve content: " + e.getMessage());
Throwable cause = e.getCause();
if (cause != null) {
// add the cause to the CMIS exception
msg.append(", ");
msg.append(cause.getMessage());
}
throw new CmisRuntimeException(msg.toString(), e);
}
}
return result;
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method cancelCheckOut.
@Override
public void cancelCheckOut(String repositoryId, String objectId, ExtensionsData extension) {
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
// only accept a PWC
if (!info.isVariant(CMISObjectVariant.PWC)) {
NodeRef nodeRef = info.getNodeRef();
NodeRef workingCopyNodeRef = connector.getCheckOutCheckInService().getWorkingCopy(nodeRef);
info = getOrCreateNodeInfo(workingCopyNodeRef.getId());
if (!info.isVariant(CMISObjectVariant.PWC)) {
throw new CmisVersioningException("Object is not a PWC!");
}
}
// get object
final NodeRef nodeRef = info.getNodeRef();
// cancel check out
connector.getCheckOutCheckInService().cancelCheckout(nodeRef);
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method removePolicy.
@Override
public void removePolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// what kind of object is it?
CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
TypeDefinitionWrapper type = info.getType();
if (type == null) {
throw new CmisObjectNotFoundException("No corresponding type found! Not a CMIS object?");
}
throw new CmisConstraintException("Object is not policy controllable!");
}
use of org.alfresco.opencmis.dictionary.CMISNodeInfo in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getObjectInfoIntern.
/**
* Collects the {@link ObjectInfo} about an object.
*
* (Provided by OpenCMIS, but optimized for Alfresco.)
*/
@SuppressWarnings("unchecked")
@Override
protected ObjectInfo getObjectInfoIntern(String repositoryId, ObjectData object) {
// if the object has no properties, stop here
if (object.getProperties() == null || object.getProperties().getProperties() == null) {
throw new CmisRuntimeException("No properties!");
}
String objectId = object.getId();
CMISNodeInfo ni = getOrCreateNodeInfo(objectId);
ObjectInfoImpl info = new ObjectInfoImpl();
// general properties
info.setObject(object);
info.setId(objectId);
info.setName(getStringProperty(object, PropertyIds.NAME));
info.setCreatedBy(getStringProperty(object, PropertyIds.CREATED_BY));
info.setCreationDate(getDateTimeProperty(object, PropertyIds.CREATION_DATE));
info.setLastModificationDate(getDateTimeProperty(object, PropertyIds.LAST_MODIFICATION_DATE));
info.setTypeId(getIdProperty(object, PropertyIds.OBJECT_TYPE_ID));
info.setBaseType(object.getBaseTypeId());
if (ni.isRelationship()) {
// versioning
info.setWorkingCopyId(null);
info.setWorkingCopyOriginalId(null);
info.setVersionSeriesId(null);
info.setIsCurrentVersion(true);
info.setWorkingCopyId(null);
info.setWorkingCopyOriginalId(null);
// content
info.setHasContent(false);
info.setContentType(null);
info.setFileName(null);
// parent
info.setHasParent(false);
// policies and relationships
info.setSupportsRelationships(false);
info.setSupportsPolicies(false);
// renditions
info.setRenditionInfos(null);
// relationships
info.setRelationshipSourceIds(null);
info.setRelationshipTargetIds(null);
// global settings
info.setHasAcl(false);
info.setSupportsDescendants(false);
info.setSupportsFolderTree(false);
} else if (ni.isFolder()) {
// versioning
info.setWorkingCopyId(null);
info.setWorkingCopyOriginalId(null);
info.setVersionSeriesId(null);
info.setIsCurrentVersion(true);
info.setWorkingCopyId(null);
info.setWorkingCopyOriginalId(null);
// content
info.setHasContent(false);
info.setContentType(null);
info.setFileName(null);
// parent
info.setHasParent(!ni.isRootFolder());
// policies and relationships
info.setSupportsRelationships(true);
info.setSupportsPolicies(true);
// renditions
info.setRenditionInfos(null);
// relationships
setRelaionshipsToObjectInfo(object, info);
// global settings
info.setHasAcl(true);
info.setSupportsDescendants(true);
info.setSupportsFolderTree(true);
} else if (ni.isDocument()) {
// versioning
info.setWorkingCopyId(null);
info.setWorkingCopyOriginalId(null);
info.setVersionSeriesId(ni.getCurrentNodeId());
if (ni.isPWC()) {
info.setIsCurrentVersion(false);
info.setWorkingCopyId(ni.getObjectId());
info.setWorkingCopyOriginalId(ni.getCurrentObjectId());
} else {
info.setIsCurrentVersion(ni.isCurrentVersion());
if (ni.hasPWC()) {
info.setWorkingCopyId(ni.getCurrentNodeId() + CMISConnector.ID_SEPERATOR + CMISConnector.PWC_VERSION_LABEL);
info.setWorkingCopyOriginalId(ni.getCurrentObjectId());
} else {
info.setWorkingCopyId(null);
info.setWorkingCopyOriginalId(null);
}
}
// content
String fileName = getStringProperty(object, PropertyIds.CONTENT_STREAM_FILE_NAME);
String mimeType = getStringProperty(object, PropertyIds.CONTENT_STREAM_MIME_TYPE);
String streamId = getIdProperty(object, PropertyIds.CONTENT_STREAM_ID);
BigInteger length = getIntegerProperty(object, PropertyIds.CONTENT_STREAM_LENGTH);
boolean hasContent = fileName != null || mimeType != null || streamId != null || length != null;
if (hasContent) {
info.setHasContent(hasContent);
info.setContentType(mimeType);
info.setFileName(fileName);
} else {
info.setHasContent(false);
info.setContentType(null);
info.setFileName(null);
}
// parent
info.setHasParent(ni.isCurrentVersion() || ni.isPWC());
// policies and relationships
info.setSupportsRelationships(true);
info.setSupportsPolicies(true);
// renditions
String renditionFilter = getRequestParameterRenditionFilter();
List<RenditionInfo> renditionInfos = new ArrayList<>();
CMISNodeInfo nodeInfo = getOrCreateNodeInfo(objectId);
NodeRef nodeRef = nodeInfo.getNodeRef();
if (nodeRef != null) {
List<RenditionData> renditions = connector.getRenditions(nodeRef, renditionFilter, null, null);
for (RenditionData rendition : renditions) {
RenditionInfoImpl renditionInfo = new RenditionInfoImpl();
renditionInfo.setId(rendition.getStreamId());
renditionInfo.setKind(rendition.getKind());
renditionInfo.setContentType(rendition.getMimeType());
renditionInfo.setTitle(rendition.getTitle());
renditionInfo.setLength(rendition.getBigLength());
renditionInfos.add(renditionInfo);
}
}
info.setRenditionInfos(renditionInfos);
// relationships
setRelaionshipsToObjectInfo(object, info);
// global settings
info.setHasAcl(true);
info.setSupportsDescendants(true);
info.setSupportsFolderTree(true);
} else if (ni.isItem()) {
info.setHasAcl(true);
info.setHasContent(false);
}
return info;
}
Aggregations