2

我尝试将 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 时,该文件存在。似乎文件夹和文档还不能用于查询,但为什么呢?如果我在测试环境in​​it中添加注释,则找到该文件

也许我做错了什么,但什么?

这是我的代码:

[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);
}
4

2 回答 2

3

您是否使用带有 Solr 的 Alfresco 4.0 进行索引?Solr 索引最终是一致的,这意味着更新可能需要一段时间(默认配置中最多 15 秒)才能显示在搜索结果中。

如果您需要立即显示更新,您可以切换到 Lucene 作为索引子系统。

于 2012-07-04T11:15:01.950 回答
0

我不认为 solr 的“最终一致”方面是生产中的问题。可能是在测试时,但我更喜欢在生产中拥有更好的系统并且在调试中遇到一些问题而不是相反。

为了在调试中解决我的问题,我首先放置了一个 Thread.Sleep(20)... 并且它有效,但是.. 调试时很长。

我的第二个似乎可行的解决方案是使用 url 地址检查 solr 的索引状态:8080/solr/admin/cores?action=REPORT(我的代码中的 _solrStateUrl)。问题是默认情况下它只能通过 SSL 访问。所以你需要从afresco服务器获取文件“browser.p12”,放到你的项目中。

所以我做了 2 种方法: - CheckIndexingState 正在解析 xml 响应以查找正在进行的事务 - WaitForIndexingDone 在 CheckIndexingState 上循环

这段代码可能不是很安全,但它只是为了测试......

这里是。希望这会帮助某人...

private bool CheckIndexingState()
{
    ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(delegate(object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; });
    System.Net.HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(_solrStateUrl);
    request.ClientCertificates.Add(new X509Certificate2(@"ssl/browser.p12", "alfresco"));
    var sb = new System.Text.StringBuilder();
    byte[] buffer = new byte[256];
    int nbRead = -1;
    using (var stream = request.GetResponse().GetResponseStream())
    {
        while (nbRead != 0)
        {
            nbRead = stream.Read(buffer, 0, 256);
            sb.Append(System.Text.Encoding.UTF8.GetString(buffer, 0, nbRead));
        }
    }

    String state = sb.ToString();

    try
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(sb.ToString());

        var node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of transactions in the index but not the DB']");
        int count = Int32.Parse(node.InnerText);
        if (count > 0)
            return false;

        node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of acl transactions in the index but not the DB']");
        count = Int32.Parse(node.InnerText);
        if (count > 0)
            return false;

        node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of missing transactions from the Index']");
        count = Int32.Parse(node.InnerText);
        if (count > 0)
            return false;

        node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of missing acl transactions from the Index']");
        count = Int32.Parse(node.InnerText);
        if (count > 0)
            return false;
    }
    catch (Exception)
    {
        throw;
    }

    return true;

}
于 2012-07-05T09:18:30.890 回答