use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException 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.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException 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.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException 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.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class CMISConnector method addSecondaryTypes.
public void addSecondaryTypes(NodeRef nodeRef, List<String> secondaryTypes) {
if (secondaryTypes != null && secondaryTypes.size() > 0) {
for (String secondaryType : secondaryTypes) {
TypeDefinitionWrapper type = getType(secondaryType);
if (type == null) {
throw new CmisInvalidArgumentException("Invalid secondaryType: " + secondaryType);
}
nodeService.addAspect(nodeRef, type.getAlfrescoName(), null);
}
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException 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;
}
Aggregations