我尝试将 dotcmis 和 alfresco 集成到我的应用程序中。在创建单元测试时,我遇到了这个问题: - 我通过删除“myfolder”(如果有)来设置我的测试环境 - 我创建了 myfolder 并将文档放入其中
然后我尝试查找文档: - 第一次(当 myfolder 之前不存在时),搜索返回 0 个结果 - 下一次,当 myfolder 之前存在并被我的测试设置删除时,我得到一个异常:
Apache Chemistry OpenCMIS - runtime error
HTTP Status 500 - <!--exception-->runtime<!--/exception--><p><!--message-->Node does not exist: missing://missing/missing(null)<!--/message--></p><hr noshade='noshade'/><!-- stacktrace--><pre>
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: Node does not exist: missing://missing/missing(null)
at org.alfresco.opencmis.AlfrescoCmisExceptionInterceptor.invoke(AlfrescoCmisExceptionInterceptor.java:80)
at ...
当我去 Alfresco 时,该文件存在。似乎文件夹和文档还不能用于查询,但为什么呢?如果我在测试环境init中添加注释,则找到该文件
也许我做错了什么,但什么?
这是我的代码:
[TestMethod()]
[DeploymentItem(@"Files\SearchTest_1", @"Files\SearchTest_1")]
public void SearchTest_2()
{
string myfoldername = "myfolder";
// Session creation
var p = new Dictionary<String, String>();
p[SessionParameter.User] = _userName;
p[SessionParameter.Password] = _userPassword;
p[SessionParameter.BindingType] = BindingType.AtomPub;
p[SessionParameter.AtomPubUrl] = _serverUrl;
var session = DotCMIS.Client.Impl.SessionFactory.NewInstance().GetRepositories(p)[0].CreateSession();
session.DefaultContext.CacheEnabled = false;
var operationContext = session.CreateOperationContext();
operationContext.IncludeAcls = true;
// Delete and create back folder and document
// /*
DotCMIS.Client.IFolder rootFolder = this._testSession.GetRootFolder(operationContext);
DotCMIS.Client.IFolder myFolder = null;
Dictionary<String, Object> properties = null;
// Le dossier de destination des tests existe-t-il ?
var myFolderExists = rootFolder.GetChildren(operationContext).Any(child => child.Name.Equals(myfoldername));
if (myFolderExists)
{
myFolder = (DotCMIS.Client.IFolder)session.GetObjectByPath(String.Format(@"/{0}", myfoldername), operationContext);
myFolder.DeleteTree(true, DotCMIS.Enums.UnfileObject.Delete, true);
}
properties = new Dictionary<String, Object>();
properties[PropertyIds.Name] = myfoldername;
properties[PropertyIds.ObjectTypeId] = "cmis:folder";
myFolder = rootFolder.CreateFolder(properties);
rootFolder.Refresh();
myFolder = (DotCMIS.Client.IFolder)session.GetObjectByPath(String.Format(@"/{0}", myfoldername), operationContext);
FileInfo sourceFile = new FileInfo(@"Files\SearchTest_1\SearchTest_1.pdf");
properties = new Dictionary<String, Object>();
properties[PropertyIds.ObjectTypeId] = "cmis:document";
properties[PropertyIds.Name] = sourceFile.Name;
using (var fileStream = sourceFile.OpenRead())
{
var contentStream = new DotCMIS.Data.Impl.ContentStream();
contentStream.MimeType = "application/pdf";
contentStream.Stream = fileStream;
contentStream.Length = fileStream.Length;
//this._testSession.CreateDocument(properties, this._testSession.CreateObjectId(myFolder.Id), contentStream, null);
DotCMIS.Client.IDocument createdDocument = myFolder.CreateDocument(properties, contentStream, null);
}
// */
// Recherche
string query = @"SELECT * FROM cmis:document WHERE cmis:name = 'SearchTest_1.pdf'";
var results = this._testSession.Query(query, false, operationContext).ToArray();
Assert.AreEqual(1, results.Length);
}