Показаны сообщения с ярлыком alfresco. Показать все сообщения
Показаны сообщения с ярлыком alfresco. Показать все сообщения

суббота, 6 августа 2011 г.

Alfresco: strong text search with wildcard using lucene

My new problem is not very difficult, but have interesting solution (I think :)). For example we have four objects in our alfresco repository that have next titles:
  • James John
  • Li Joan
  • Johan Jazz
  • Bill

For get all objects that begins from 'Joh', I use the next query:
+TYPE:"my:object" +@cm\:title:"joh*"

The result of the query:
  • James John
  • Johan Jazz
  • Li Joan

'Joan' doesn't contain 'joh' in title. For solve that I modify my query:
+TYPE:"my:object" +@cm\:title:"[joh*]"

This query returns the right result:
  • James John
  • Johan Jazz

You can find more lucene tricks in wonderful book that called: "Lucene in Action" :)

пятница, 29 апреля 2011 г.

Process workflow with alfresco and actitviti

Alfresco release new version of their ECM - 3.4.e. Major feature of this release is integration with activiti BPM platform. That's a good news, because JBPM 3 is obsolete. Of course, I try to use it and have some problems ;) In our projects we use WorkflowService to control business processes. To move workflow from one task to another we have to end current task and specify the transition name(more details you can find here:
    workflowService.endTask(task.getId(), "transitionName");

But when we migrate simple workflow from jbpm to activiti, we got exception :(

I start to discover alfresco sources and found interesting method in activiti workflow component:
    private WorkflowTask endNormalTask(String taskId, String localTaskId, String transition)
    {
        // Retrieve task
        Task task = taskService.createTaskQuery().taskId(localTaskId).singleResult();
        
        if(task == null)
        {
            String msg = messageService.getMessage(ERR_END_UNEXISTING_TASK, taskId);
            throw new WorkflowException(msg);
        }
        
        // Signal the transition on the task
        if (transition != null && 
                ActivitiConstants.DEFAULT_TRANSITION_NAME.equals(transition)==false)
        {
            // Only 'Next' is supported as transition.
            String msg = messageService.getMessage(ERR_END_TASK_INVALID_TRANSITION, transition, taskId, ActivitiConstants.DEFAULT_TRANSITION_NAME);
            throw new WorkflowException(msg);
        }
        setOutcome(task);
        taskService.complete(localTaskId);
        // The task should have a historicTaskInstance
        HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult();
        return typeConverter.convert(historicTask);
    }

YOOHOO! Now, you can use only "Next" keyword to move activiti workflow and code to end task should looks like this:
     workflowService.endTask(task.getId(),ActivitiConstants.DEFAULT_TRANSITION_NAME);

среда, 1 сентября 2010 г.

Authentication problems in multithreading

In my application, I have a tree widget that using ajax for loading nodes. Tomcat create some threads to service requests. Each requests validate security ticket that stores in http session:

authenticationService.validate(ticket, null);

And some threads can not validate this ticket and service throws AuthenticationException. If you have particular problem, then you should look at alfresco's jira: ALF-3789. This bug was fixed in revision 21065 at trunk. To fix it in my code, I simple override bean:

<!--Override alfresco-->
    <bean name="ticketsCache" class="org.alfresco.repo.cache.EhCacheAdapter">
       <property name="cache">
          <bean class="org.springframework.cache.ehcache.EhCacheFactoryBean" >
             <property name="cacheManager">
                <ref bean="internalEHCacheManager" />
             </property>
             <property name="cacheName">
                <value>org.alfresco.cache.ticketsCache</value>
             </property>
          </bean>
       </property>
    </bean>

After this all works fine :)

пятница, 20 августа 2010 г.

Fun with alfresco types.

Good day!

Yesterday, I had some fun with alfresco types and permissions. I've created simple type in my model that looks like this:
<type name="my:simpleType">
  <title>Simple type</title>
  <properties>
    <property name="my:prop">
       <type>d:int</type>
    </property>
  </properties>
</type>

I've included it as child-association to the other type and tried to create it:
Node simpleProp = parentNode.addProperty("my:parentProp", "my:simpleType");
  simpleProp.setProperty("my:prop", 1);//AccessDeniedException here!

But, when I ran JUnit test, it threw AccessDeniedException on setProperty for that node. I started debugging alfresco sources, but still I couldn't understand what is going on. Why can I create parent node, add node to association, but can not set property for this node???!!! I tried to use NodeService without JCR API, but I've got the same trouble. Then, I discovered all sources of alfresco's permission subsystem(PermissionServiceImpl, SecurityProvider, etc) with acegi, but still in vain :(

By the end of the day, I have got two cigarettes and zero ideas. After first cigarette, I was looking at my model trying to find problem and finally I've got it! My new type had no parent type! When I added
<parent>cm:content</parent>

everything worked fine! That was hard day: one day - one string...fast work :)

среда, 4 августа 2010 г.

Search content by dates in alfresco using CMIS API

Hi all!

I have a new project that use Alfresco as a backend to store content. I need select content by date. User specifies dates and the service should find and display it. I've chosen CMIS API. It supports query language like SQL to get content. But I've got a problem. I need to specify the date in my query, that looks like this:
SELECT * FROM my:content WHERE my:modifyDate < 01.01.2010
My problem is a date format. In alfresco wiki, I found this description:
datetime literals Based on SQL-92 with 'T' replacing in ,
But it doesn't work. Why???!!! Because I had simply copy-pasted the format for SimpleDateFormat: yyyy-MM-dd'T'HH.mm.ss.SSS. Next hour I could not get why it doesn't work. That format is wrong and must be: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' Also, in alfresco SVN and I've found a good helper class for this: org.alfresco.util.CachingDateFormat. But I didn't hav it in my build of alfresco(I use community build version 3.3, but it was build early). When I upgrade, I will use this class, but for now I wrote simple type helper that looks like this:
package com.blogspot.jajatips.alfresco.util;

import org.apache.commons.lang.time.FastDateFormat;
import java.util.Date;

/**
 * Date: 03.08.2010
 * @author Dmitry N. Pokidov
 */
public class TypeHelper {
    public static String formatDate(Date date) {
        //TODO: CachingDateFormat.getCmisSqlDatetimeFormat()
        FastDateFormat cmisDateFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
        return new StringBuilder("TIMESTAMP '").append(cmisDateFormat.format(date)).append("'").toString();
    }
}
As you can see, I use FastDateFormat from common-lang, that cache date formats. Also, their formats are thread safe, which is very important if you have some static queries.

Well, I'm going to request to make changes in SimpleDateFormat in alfresco wiki, so no one would have this trouble :)

UPD: Good news, I have fixed alfresco wiki page :)

Most popular

Authors