use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class ChangeTokenTest method runUpdateFolderTest.
private void runUpdateFolderTest(Session session, Folder testFolder) {
Folder folder = createFolder(session, testFolder, "folder1");
try {
if (folder.getChangeToken() == null) {
addResult(createResult(SKIPPED, "Repository does not provide change tokens for folders. Test skipped!"));
return;
}
if (!folder.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)) {
addResult(createResult(SKIPPED, "Folder name can't be changed. Test skipped!"));
return;
}
// the first update should succeed
Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put(PropertyIds.NAME, "folder2");
folder.updateProperties(properties2, false);
try {
Map<String, Object> properties3 = new HashMap<String, Object>();
properties3.put(PropertyIds.NAME, "folder3");
folder.updateProperties(properties3, false);
addResult(createResult(FAILURE, "Updating properties a second time with the same change token " + "should result in an UpdateConflict exception!"));
// } catch (CmisUpdateConflictException e) {
} catch (CmisConstraintException e) {
// expected exception
}
} finally {
deleteObject(folder);
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project structr by structr.
the class CMISObjectService method createFolder.
@Override
public String createFolder(final String repositoryId, final Properties properties, final String folderId, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
final App app = StructrApp.getInstance(securityContext);
String uuid = null;
try (final Tx tx = app.tx()) {
final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_FOLDER, Folder.class);
// check if type exists
if (type != null) {
// check that base type is cmis:folder
final BaseTypeId baseTypeId = getBaseTypeId(type);
if (baseTypeId != null && BaseTypeId.CMIS_FOLDER.equals(baseTypeId)) {
// create folder
final AbstractFile newFolder = (AbstractFile) app.create(type, PropertyMap.cmisTypeToJavaType(securityContext, type, properties));
// find and set parent if it exists
if (!CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
final Folder parent = app.get(Folder.class, folderId);
if (parent != null) {
newFolder.setParent(parent);
} else {
throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
}
}
uuid = newFolder.getUuid();
} else {
throw new CmisConstraintException("Cannot create cmis:folder of type " + objectTypeId);
}
} else {
throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
}
tx.success();
} catch (Throwable t) {
throw new CmisRuntimeException("New folder could not be created: " + t.getMessage());
}
return uuid;
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project structr by structr.
the class CMISContentStream method getStream.
@Override
public InputStream getStream() {
try {
final FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ);
final long mappedLength = Math.max(0, Math.min(channel.size() - offset, length));
final MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, offset, mappedLength);
return new MappedInputStream(buffer);
} catch (IOException ioex) {
throw new CmisConstraintException(ioex.getMessage());
}
}
Aggregations