use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class CMISConnector method setProperty.
/**
* Sets a property value.
*/
public void setProperty(NodeRef nodeRef, TypeDefinitionWrapper type, String propertyId, Serializable value) {
if (propertyId == null) {
throw new CmisInvalidArgumentException("Cannot process not null property!");
}
PropertyDefinitionWrapper propDef = type.getPropertyById(propertyId);
if (propDef == null) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!");
}
Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef);
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
if (!isUpdatable(updatability, isOnWorkingCopy)) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
}
if (propDef.getPropertyId().equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
throw new IllegalArgumentException("Cannot process " + PropertyIds.SECONDARY_OBJECT_TYPE_IDS + " in setProperty");
} else {
QName propertyQName = propDef.getPropertyAccessor().getMappedProperty();
if (propertyQName == null) {
throw new CmisConstraintException("Unable to set property " + propertyId + "!");
}
if (propertyId.equals(PropertyIds.NAME)) {
if (!(value instanceof String)) {
throw new CmisInvalidArgumentException("Object name must be a string!");
}
try {
String newName = value.toString();
// If the node is checked out and the name property is set on the working copy, make sure the new name has the working copy format
if (isOnWorkingCopy) {
String wcLabel = (String) this.nodeService.getProperty(nodeRef, ContentModel.PROP_WORKING_COPY_LABEL);
if (wcLabel == null) {
wcLabel = CheckOutCheckInServiceImpl.getWorkingCopyLabel();
}
if (!newName.contains(wcLabel)) {
newName = CheckOutCheckInServiceImpl.createWorkingCopyName(newName, wcLabel);
}
}
fileFolderService.rename(nodeRef, newName);
} catch (FileExistsException e) {
throw new CmisContentAlreadyExistsException("An object with this name already exists!", e);
} catch (FileNotFoundException e) {
throw new CmisInvalidArgumentException("Object with id " + nodeRef.getId() + " not found!");
}
} else {
// overflow check
if (propDef.getPropertyDefinition().getPropertyType() == PropertyType.INTEGER && value instanceof BigInteger) {
org.alfresco.service.cmr.dictionary.PropertyDefinition def = dictionaryService.getProperty(propertyQName);
QName dataDef = def.getDataType().getName();
BigInteger bigValue = (BigInteger) value;
if ((bigValue.compareTo(maxInt) > 0 || bigValue.compareTo(minInt) < 0) && dataDef.equals(DataTypeDefinition.INT)) {
throw new CmisConstraintException("Value is out of range for property " + propertyQName.getLocalName());
}
if ((bigValue.compareTo(maxLong) > 0 || bigValue.compareTo(minLong) < 0) && dataDef.equals(DataTypeDefinition.LONG)) {
throw new CmisConstraintException("Value is out of range for property " + propertyQName.getLocalName());
}
}
nodeService.setProperty(nodeRef, propertyQName, value);
}
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method create.
// --- object service ---
@Override
public String create(String repositoryId, Properties properties, String folderId, ContentStream contentStream, VersioningState versioningState, List<String> policies, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// check properties
if (properties == null || properties.getProperties() == null) {
throw new CmisInvalidArgumentException("Properties must be set!");
}
// get the type
String objectTypeId = connector.getObjectTypeIdProperty(properties);
// find the type
TypeDefinitionWrapper type = connector.getOpenCMISDictionaryService().findType(objectTypeId);
if (type == null) {
throw new CmisInvalidArgumentException("Type '" + objectTypeId + "' is unknown!");
}
// create object
String newId = null;
switch(type.getBaseTypeId()) {
case CMIS_DOCUMENT:
versioningState = getDocumentDefaultVersioningState(versioningState, type);
newId = createDocument(repositoryId, properties, folderId, contentStream, versioningState, policies, null, null, extension);
break;
case CMIS_FOLDER:
newId = createFolder(repositoryId, properties, folderId, policies, null, null, extension);
break;
case CMIS_POLICY:
newId = createPolicy(repositoryId, properties, folderId, policies, null, null, extension);
break;
case CMIS_ITEM:
newId = createItem(repositoryId, properties, folderId, policies, null, null, extension);
break;
default:
break;
}
// check new object id
if (newId == null) {
throw new CmisRuntimeException("Creation failed!");
}
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
try {
getObjectInfo(repositoryId, newId, "*", IncludeRelationships.NONE);
} catch (InvalidNodeRefException e) {
throw new CmisRuntimeException("Creation failed! New object not found!");
}
}
// return the new object id
return newId;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method deleteTree.
@Override
public FailedToDeleteData deleteTree(String repositoryId, String folderId, Boolean allVersions, UnfileObject unfileObjects, final Boolean continueOnFailure, ExtensionsData extension) {
checkRepositoryId(repositoryId);
if (!allVersions) {
throw new CmisInvalidArgumentException("Only allVersions=true supported!");
}
if (unfileObjects == UnfileObject.UNFILE) {
throw new CmisInvalidArgumentException("Unfiling not supported!");
}
final NodeRef folderNodeRef = getOrCreateFolderInfo(folderId, "Folder").getNodeRef();
final FailedToDeleteDataImpl result = new FailedToDeleteDataImpl();
try {
connector.deleteNode(folderNodeRef, true);
} catch (Exception e) {
List<String> ids = new ArrayList<String>();
ids.add(folderId);
result.setIds(ids);
}
return result;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method createRelationship.
@Override
public String createRelationship(String repositoryId, Properties properties, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get type
String objectTypeId = connector.getObjectTypeIdProperty(properties);
final TypeDefinitionWrapper type = connector.getTypeForCreate(objectTypeId, BaseTypeId.CMIS_RELATIONSHIP);
// get source object
String sourceId = connector.getSourceIdProperty(properties);
CMISNodeInfo sourceInfo = getOrCreateNodeInfo(sourceId, "Source");
if (!sourceInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !sourceInfo.isVariant(CMISObjectVariant.FOLDER) && !sourceInfo.isVariant(CMISObjectVariant.ITEM)) {
throw new CmisInvalidArgumentException("Source is not the latest version of a document, a folder or an item object!");
}
final NodeRef sourceNodeRef = sourceInfo.getNodeRef();
// get target object
String targetId = connector.getTargetIdProperty(properties);
CMISNodeInfo targetInfo = getOrCreateNodeInfo(targetId, "Target");
if (!targetInfo.isVariant(CMISObjectVariant.CURRENT_VERSION) && !targetInfo.isVariant(CMISObjectVariant.FOLDER) && !targetInfo.isVariant(CMISObjectVariant.ITEM)) {
throw new CmisInvalidArgumentException("Target is not the latest version of a document, a folder or an item object!!");
}
final NodeRef targetNodeRef = targetInfo.getNodeRef();
// check policies and ACLs
if ((policies != null) && (!policies.isEmpty())) {
throw new CmisConstraintException("Relationships are not policy controllable!");
}
if ((addAces != null) && (addAces.getAces() != null) && (!addAces.getAces().isEmpty())) {
throw new CmisConstraintException("Relationships are not ACL controllable!");
}
if ((removeAces != null) && (removeAces.getAces() != null) && (!removeAces.getAces().isEmpty())) {
throw new CmisConstraintException("Relationships are not ACL controllable!");
}
// create relationship
// ALF-10085 : disable auditing behaviour for this use case
// Lasts for txn
boolean wasEnabled = connector.disableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
try {
AssociationRef assocRef = connector.getNodeService().createAssociation(sourceNodeRef, targetNodeRef, type.getAlfrescoClass());
return CMISConnector.ASSOC_ID_PREFIX + assocRef.getId();
} finally {
if (wasEnabled) {
connector.enableBehaviour(ContentModel.ASPECT_AUDITABLE, sourceNodeRef);
}
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method moveObject.
@Override
public void moveObject(String repositoryId, Holder<String> objectId, String targetFolderId, String sourceFolderId, ExtensionsData extension) {
checkRepositoryId(repositoryId);
// get object and source and target parent
CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");
final NodeRef nodeRef = info.getCurrentNodeNodeRef();
final CMISNodeInfo sourceInfo = getOrCreateFolderInfo(sourceFolderId, "Source Folder");
final CMISNodeInfo targetInfo = getOrCreateFolderInfo(targetFolderId, "Target Folder");
connector.checkChildObjectType(targetInfo, info.getType().getTypeId());
ChildAssociationRef primaryParentRef = connector.getNodeService().getPrimaryParent(nodeRef);
// if this is a primary child node, move it
if (primaryParentRef.getParentRef().equals(sourceInfo.getNodeRef())) {
connector.getNodeService().moveNode(nodeRef, targetInfo.getNodeRef(), primaryParentRef.getTypeQName(), primaryParentRef.getQName());
} else {
boolean found = false;
// otherwise, reparent it
for (ChildAssociationRef parent : connector.getNodeService().getParentAssocs(nodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL)) {
if (parent.getParentRef().equals(sourceInfo.getNodeRef())) {
connector.getNodeService().removeChildAssociation(parent);
connector.getNodeService().addChild(targetInfo.getNodeRef(), nodeRef, ContentModel.ASSOC_CONTAINS, parent.getQName());
found = true;
}
}
if (!found) {
throw new IllegalArgumentException(new CmisInvalidArgumentException("Document is not a child of the source folder that was specified!"));
}
}
}
Aggregations