use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getAllVersions.
@Override
public List<ObjectData> getAllVersions(String repositoryId, String objectId, String versionSeriesId, String filter, Boolean includeAllowableActions, ExtensionsData extension) {
checkRepositoryId(repositoryId);
if (versionSeriesId == null && objectId != null) {
// it's a browser binding call
versionSeriesId = connector.getCurrentVersionId(objectId);
}
if (versionSeriesId == null) {
throw new CmisInvalidArgumentException("Object Id or Object Series Id must be set!");
}
List<ObjectData> result = new ArrayList<ObjectData>();
// what kind of object is it?
CMISNodeInfo info = getOrCreateNodeInfo(versionSeriesId, "Version Series");
if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION)) {
// document
throw new CmisInvalidArgumentException("Version Series does not exist!");
}
// get current version and it's history
NodeRef nodeRef = info.getNodeRef();
VersionHistory versionHistory = ((CMISNodeInfoImpl) info).getVersionHistory();
if (versionHistory == null) {
// add current version
result.add(connector.createCMISObject(info, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, info.getObjectId(), IncludeRelationships.NONE);
}
} else {
if (info.hasPWC()) {
CMISNodeInfo pwcInfo = createNodeInfo(connector.getCheckOutCheckInService().getWorkingCopy(nodeRef));
result.add(connector.createCMISObject(pwcInfo, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, pwcInfo.getObjectId(), IncludeRelationships.NONE);
}
}
// convert the version history
for (Version version : versionHistory.getAllVersions()) {
// TODO do we need to check existence ?
CMISNodeInfo versionInfo = createNodeInfo(version.getFrozenStateNodeRef(), versionHistory, true);
// MNT-9557 fix. Replace head version with current node info
if (versionHistory.getHeadVersion().equals(version)) {
versionInfo = createNodeInfo(nodeRef);
}
result.add(connector.createCMISObject(versionInfo, filter, includeAllowableActions, IncludeRelationships.NONE, CMISConnector.RENDITION_NONE, false, false));
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, versionInfo.getObjectId(), IncludeRelationships.NONE);
}
}
}
return result;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getTypeDescendants.
@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData extension) {
checkRepositoryId(repositoryId);
List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>();
// check depth
int d = (depth == null ? -1 : depth.intValue());
if (d == 0) {
throw new CmisInvalidArgumentException("Depth must not be 0!");
}
if (typeId == null) {
for (TypeDefinitionWrapper tdw : connector.getOpenCMISDictionaryService().getBaseTypes(true)) {
result.add(getTypesDescendants(d, tdw, includePropertyDefinitions));
}
} else {
TypeDefinitionWrapper tdw = connector.getOpenCMISDictionaryService().findType(typeId);
if (tdw == null) {
throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
}
List<TypeDefinitionWrapper> children = connector.getOpenCMISDictionaryService().getChildren(typeId);
if (children != null) {
for (TypeDefinitionWrapper child : children) {
result.add(getTypesDescendants(d, child, includePropertyDefinitions));
}
}
}
return result;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method checkOut.
// --- versioning service ---
@Override
public void checkOut(String repositoryId, final Holder<String> objectId, ExtensionsData extension, final Holder<Boolean> contentCopied) {
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
// Check for current version
if (info.isVariant(CMISObjectVariant.CURRENT_VERSION)) {
// Good
} else if (info.isVariant(CMISObjectVariant.VERSION)) {
throw new CmisInvalidArgumentException("Can't check out an old version of a document");
} else {
throw new CmisInvalidArgumentException("Only documents can be checked out! Object was a " + info.getObjectVariant().toString());
}
// get object
final NodeRef nodeRef = info.getNodeRef();
if (!((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).isVersionable()) {
throw new CmisConstraintException("Document is not versionable!");
}
// check out
NodeRef pwcNodeRef = connector.getCheckOutCheckInService().checkout(nodeRef);
CMISNodeInfo pwcNodeInfo = createNodeInfo(pwcNodeRef);
objectId.setValue(pwcNodeInfo.getObjectId());
if (contentCopied != null) {
contentCopied.setValue(connector.getFileFolderService().getReader(pwcNodeRef) != null);
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method appendContentStream.
@Override
public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String> changeToken, ContentStream contentStream, boolean isLastChunk, ExtensionsData extension) {
if ((contentStream == null) || (contentStream.getStream() == null)) {
throw new CmisInvalidArgumentException("No content!");
}
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
}
// ALF-21852 - Separated appendContent and objectId.setValue in two different transactions because
// after executing appendContent, the new objectId is not visible.
RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
helper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
try {
connector.appendContent(info, contentStream, isLastChunk);
} catch (IOException e) {
throw new ContentIOException("", e);
}
return null;
}
}, false, true);
String objId = helper.doInTransaction(new RetryingTransactionCallback<String>() {
public String execute() throws Throwable {
return connector.createObjectId(nodeRef);
}
}, true, true);
objectId.setValue(objId);
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method setContentStream.
@Override
public void setContentStream(String repositoryId, Holder<String> objectId, Boolean overwriteFlag, Holder<String> changeToken, final ContentStream contentStream, ExtensionsData extension) {
checkRepositoryId(repositoryId);
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
if (!info.isVariant(CMISObjectVariant.CURRENT_VERSION) && !info.isVariant(CMISObjectVariant.PWC)) {
throw new CmisStreamNotSupportedException("Content can only be set on private working copies or current versions.");
}
final NodeRef nodeRef = info.getNodeRef();
if (((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
throw new CmisStreamNotSupportedException("Document type doesn't allow content!");
}
boolean existed = connector.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT) != null;
if (existed && !overwriteFlag) {
throw new CmisContentAlreadyExistsException("Content already exists!");
}
if ((contentStream == null) || (contentStream.getStream() == null)) {
throw new CmisInvalidArgumentException("No content!");
}
// ALF-21852 - Separated setContent and objectId.setValue in two different transactions because
// after executing setContent, the new objectId is not visible.
RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
helper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
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.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
return null;
}
}, false, true);
String objId = helper.doInTransaction(new RetryingTransactionCallback<String>() {
public String execute() throws Throwable {
return connector.createObjectId(nodeRef);
}
}, true, true);
objectId.setValue(objId);
}
Aggregations