use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class FileSystemStorageService method moveFolder.
@Override
public void moveFolder(String objectId, String sourcePath, String targetPath) throws IOException, IllegalArgumentException {
LOG.info("Move Folder for Sourcepath and Targetpath{},{}", sourcePath, targetPath);
try {
String rootpath = this.storeSettings.getFileLocation();
if (rootpath == null) {
LOG.error("Local storage path is undefined");
throw new CmisConstraintException("Local storage path is undefined");
}
File sourceDir = new File(gettingFolderPath(this.storeSettings.getFileLocation(), sourcePath));
targetPath = createSourceInTarget(gettingFolderPath(this.storeSettings.getFileLocation(), targetPath), sourcePath);
File targetDir = new File(targetPath);
FileUtils.copyDirectory(sourceDir, targetDir);
File deleteSourceDir = new File(gettingFolderPath(this.storeSettings.getFileLocation(), sourcePath));
FileUtils.deleteDirectory(deleteSourceDir);
} catch (IOException e) {
LOG.error("createLocalStorageService exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
throw new IllegalArgumentException("Could not create Folder: " + e.getMessage());
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class FileSystemStorageService method deleteFolder.
@Override
public void deleteFolder(String folderName) {
LOG.info("Delete Folder:{}" + folderName);
String respositoryRoot = null;
try {
LOG.debug("Delete Folder:{}" + folderName);
String rootpath = this.storeSettings.getFileLocation();
if (rootpath == null) {
LOG.error("Local storage path is undefined");
throw new CmisConstraintException("Local storage path is undefined");
}
respositoryRoot = rootpath + "\\" + folderName;
File deleteSourceDir = new File(respositoryRoot);
FileUtils.deleteDirectory(deleteSourceDir);
} catch (Exception e) {
LOG.error("createLocalStorageService exception: {}, {}", e.getMessage(), ExceptionUtils.getStackTrace(e));
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class CreateInvalidTypeTest method run.
@Override
public void run(Session session) {
// create a test folder
Folder testFolder = createTestFolder(session);
try {
// test document creation
try {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "never.txt");
properties.put(PropertyIds.OBJECT_TYPE_ID, getFolderTestTypeId());
byte[] contentBytes = IOUtils.toUTF8Bytes("nothing");
ContentStream contentStream = new ContentStreamImpl("never.txt", BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
testFolder.createDocument(properties, contentStream, null);
addResult(createResult(FAILURE, "Creation of a document with a folder type shouldn't work!"));
} catch (Exception e) {
if (!(e instanceof CmisInvalidArgumentException) && !(e instanceof CmisConstraintException)) {
addResult(createResult(WARNING, "Creation of a document with a folder type threw an unexcpeted exception: " + e.toString()));
}
}
// test folder creation
try {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "never");
properties.put(PropertyIds.OBJECT_TYPE_ID, getDocumentTestTypeId());
testFolder.createFolder(properties);
addResult(createResult(FAILURE, "Creation of a folder with a document type shouldn't work!"));
} catch (Exception e) {
if (!(e instanceof CmisInvalidArgumentException) && !(e instanceof CmisConstraintException)) {
addResult(createResult(WARNING, "Creation of a folder with a document type threw an unexcpeted exception: " + e.toString()));
}
}
} finally {
// delete the test folder
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class VersionDeleteTest method deleteVersion.
private void deleteVersion(Document versionDoc, Document previousDoc, int version) {
CmisTestResult f;
// check Allowable Action
if (!versionDoc.hasAllowableAction(Action.CAN_DELETE_OBJECT)) {
addResult(createResult(WARNING, "Version " + version + " does not have the Allowable Action 'canDeleteObject'."));
return;
}
// get version history before delete
List<Document> versionsBefore = versionDoc.getAllVersions();
// delete and check
try {
versionDoc.delete(false);
} catch (CmisInvalidArgumentException iae) {
addResult(createResult(WARNING, "Deletion of version " + version + " failed with an invalidArgument exception. " + "Removing just one version doesn't seem to be supported."));
return;
} catch (CmisConstraintException ce) {
addResult(createResult(WARNING, "Deletion of version " + version + " failed with an constraint exception. " + "Removing just one version doesn't seem to be supported."));
return;
}
f = createResult(FAILURE, "Deleted version " + version + " still exists!");
addResult(assertIsFalse(exists(versionDoc), null, f));
// check version history after delete
if (previousDoc != null) {
List<Document> versionsAfter = previousDoc.getAllVersions();
f = createResult(FAILURE, "After version " + version + " has been deleted, the version history should consist of " + (versionsBefore.size() - 1) + " documents but is has " + versionsAfter.size() + " !");
addResult(assertEquals(versionsBefore.size() - 1, versionsAfter.size(), null, f));
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException in project copper-cms by PogeyanOSS.
the class VersioningStateCreateTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
try {
// create folder and document
Folder testFolder = createTestFolder(session);
DocumentTypeDefinition docType = (DocumentTypeDefinition) session.getTypeDefinition(getDocumentTestTypeId());
if (!docType.isVersionable()) {
addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
return;
}
// major version
Document docMajor = testFolder.createDocument(getProperties("major.txt"), getContentStream(), VersioningState.MAJOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, docMajor, getAllProperties(docMajor), "Major version compliance"));
f = createResult(FAILURE, "Document should be major version.");
addResult(assertIsTrue(docMajor.isMajorVersion(), null, f));
List<Document> versions = docMajor.getAllVersions();
f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
addResult(assertEquals(1, versions.size(), null, f));
deleteObject(docMajor);
// minor version
try {
Document docMinor = testFolder.createDocument(getProperties("minor.txt"), getContentStream(), VersioningState.MINOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, docMinor, getAllProperties(docMinor), "Minor version compliance"));
f = createResult(FAILURE, "Document should be minor version.");
addResult(assertIsFalse(docMinor.isMajorVersion(), null, f));
versions = docMinor.getAllVersions();
f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
addResult(assertEquals(1, versions.size(), null, f));
deleteObject(docMinor);
} catch (CmisConstraintException ce) {
addResult(createResult(WARNING, "Creating a minor version failed! " + "The repository might not support minor versions. Exception: " + ce, ce, false));
} catch (CmisInvalidArgumentException iae) {
addResult(createResult(WARNING, "Creating a minor version failed! " + "The repository might not support minor versions. Exception: " + iae, iae, false));
}
// checked out version
try {
Document docCheckedOut = testFolder.createDocument(getProperties("checkout.txt"), getContentStream(), VersioningState.CHECKEDOUT, null, null, null, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, docCheckedOut, getAllProperties(docCheckedOut), "Checked out version compliance"));
f = createResult(FAILURE, "Version series should be checked out.");
addResult(assertIsTrue(docCheckedOut.isVersionSeriesCheckedOut(), null, f));
versions = docCheckedOut.getAllVersions();
f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
addResult(assertEquals(1, versions.size(), null, f));
docCheckedOut.cancelCheckOut();
} catch (CmisConstraintException ce) {
addResult(createResult(WARNING, "Creating a checked out version failed! " + "The repository might not support creating checked out versions. Exception: " + ce, ce, false));
} catch (CmisInvalidArgumentException iae) {
addResult(createResult(WARNING, "Creating a checked out version failed! " + "The repository might not support creating checked out versions. Exception: " + iae, iae, false));
}
} finally {
deleteTestFolder();
}
}
Aggregations