use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class ChangeTokenTest method runUpdateDocumentTest.
private void runUpdateDocumentTest(Session session, Folder testFolder) {
Document doc = createDocument(session, testFolder, "update1.txt", "Hello World!");
try {
if (doc.getChangeToken() == null) {
addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!"));
return;
}
DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType();
PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || !doc.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES)) {
addResult(createResult(SKIPPED, "Document 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, "update2.txt");
ObjectId newId = doc.updateProperties(properties2, false);
if (!doc.getId().equals(newId.getId())) {
// the repository created a new version
// -> a change token test does not make sense
addResult(createResult(INFO, "The repository created a new version. Change tokens are not relevant here."));
} else {
try {
Map<String, Object> properties3 = new HashMap<String, Object>();
properties3.put(PropertyIds.NAME, "update3.txt");
doc.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(doc);
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class ChangeTokenTest method runContentTest.
private void runContentTest(Session session, Folder testFolder) {
if (session.getRepositoryInfo().getCapabilities().getContentStreamUpdatesCapability() != CapabilityContentStreamUpdates.ANYTIME) {
addResult(createResult(SKIPPED, "Repository doesn't allow to replace content. Test skipped!"));
return;
}
Document doc = createDocument(session, testFolder, "content1.txt", "Hello World!");
try {
if (doc.getChangeToken() == null) {
addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!"));
return;
}
if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) {
addResult(createResult(SKIPPED, "Document content can't be changed. Test skipped!"));
return;
}
byte[] contentBytes = IOUtils.toUTF8Bytes("New content");
ContentStream contentStream = new ContentStreamImpl("content2.txt", BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
ObjectId newId = doc.setContentStream(contentStream, true, false);
if (newId == null) {
// -> get the latest id from the version series
if (Boolean.TRUE.equals(((DocumentTypeDefinition) doc.getType()).isVersionable())) {
List<Document> versions = doc.getAllVersions();
if (versions == null || versions.size() < 1) {
addResult(createResult(FAILURE, "Repository returned an empty list of document versions!"));
} else {
// the latest document is at the top of the list
newId = versions.get(0);
}
} else {
// the document type is not versionable
// -> the repository couldn't create a new version
newId = doc;
}
}
if (newId != null) {
if (!doc.getId().equals(newId.getId())) {
// the repository created a new version
// -> a change token test does not make sense
addResult(createResult(INFO, "The repository created a new version. Change tokens are not relevant here."));
} else {
try {
doc.setContentStream(contentStream, true, false);
addResult(createResult(FAILURE, "Updating content a second time with the same change token " + "should result in an UpdateConflict exception!"));
// } catch (CmisUpdateConflictException uce) {
} catch (CmisConstraintException e) {
// expected exception
}
}
}
} finally {
deleteObject(doc);
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class FileSystemStorageService method setStoreSettings.
@Override
public void setStoreSettings(IRepositoryStorageSettings storeSettings) {
if (storeSettings instanceof FileSystemStorageStoreSettings) {
FileSystemStorageStoreSettings fileStore = (FileSystemStorageStoreSettings) storeSettings;
String rootpath = fileStore.getFileLocation();
if (rootpath == null) {
LOG.error("Local storage path is undefined");
throw new CmisConstraintException("Local storage path is undefined");
}
File directory = new File(rootpath);
if (!directory.exists()) {
directory.mkdirs();
}
this.storeSettings = (FileSystemStorageStoreSettings) storeSettings;
} else {
LOG.error("writeContent exception: {}", "Respository Setting details not valid");
throw new IllegalArgumentException("Respository Setting details not valid");
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class FileSystemStorageService method rename.
@Override
public void rename(String oldPath, String newPath) throws IOException, IllegalArgumentException {
LOG.debug("Rename of oldname into newname:{},{}", oldPath, newPath);
String rootpath = this.storeSettings.getFileLocation();
if (rootpath == null) {
LOG.error("Local storage path is undefined");
throw new CmisConstraintException("Local storage path is undefined");
}
File oldFile = new File(gettingFolderPath(this.storeSettings.getFileLocation(), oldPath));
File newFile = new File(gettingFolderPath(this.storeSettings.getFileLocation(), newPath));
oldFile.renameTo(newFile);
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project structr by structr.
the class CMISObjectService method updateProperties.
@Override
public void updateProperties(final String repositoryId, final Holder<String> objectId, final Holder<String> changeToken, final Properties properties, final ExtensionsData extension) {
final App app = StructrApp.getInstance();
final String id = objectId.getValue();
try (final Tx tx = app.tx()) {
final AbstractNode obj = app.get(AbstractNode.class, id);
if (obj != null) {
final PropertyMap propertyMap = PropertyMap.cmisTypeToJavaType(securityContext, obj.getClass(), properties);
if (propertyMap != null) {
obj.setProperties(securityContext, propertyMap);
}
} else {
throw new CmisObjectNotFoundException("Object with ID " + objectId + " does not exist");
}
tx.success();
} catch (FrameworkException fex) {
throw new CmisConstraintException(fex.getMessage(), fex);
}
}
Aggregations