Tuesday, July 31, 2012

Use alfresco forms framework for categories

I wanted to use the forms framework in alfresco for creating new categories ... works fine until you save the changes and the TypeFormProcessor handles the association to the parent (defaults to cm:contains like for folders).

So you need a custom FormProcessor, like:

public class CategoryFormProcessor extends TypeFormProcessor { ...

You need to override the creation of a node:

protected NodeRef createNode(TypeDefinition typeDef, FormData data) {  ...

Take the code from TypeFormProcessor and change the Association saved to ContentModel.ASSOC_SUBCATEGORIES approx. line 107.

Then you must configure you bean in the Repo context (some loaded
*-context.xml file), see alfrescos in form-services-context.xml

<bean id="categoryTypeFormProcessor"     class="com.redpill_linpro.alfresco.noark5.repo.forms.processor.node.CategoryFormProcessor"
      parent="typeFormProcessor">
        <property name="filterRegistry" ref="typeFilterRegistry" />
      <property name="matchPattern">
         <value>category-type</value>
      </property>
   </bean>


NB! the code (class file for the new FormProcessor) must be in the WEB-INF (not share), because of class-loading dependencies.

No you can load a form, example javascript snipplet here with a configured destination.

var templateUrl = YAHOO.lang.substitute(Alfresco.constants.URL_SERVICECONTEXT + "components/form?itemKind={itemKind}&itemId={itemId}&destination={destination}&mode={mode}&submitType={submitType}&formId={formId}&showCancelButton=true",
             {
                itemKind: "category-type",
                itemId: "cm:category",
                destination: destination,
                mode: "create",
                submitType: "json",
                formId: "doclib-common"
             });

             // Using Forms Service, so always create new instance
             var createFolder = new Alfresco.module.SimpleDialog(this.id + "-createCategory");

             createFolder.setOptions(
             {
                width: "33em",
                templateUrl: templateUrl,

...

The itemKind variable trickers the formprocessor! type->TypeFormProcessor, category-type -> CategoryTypeFormProcessor, which I configured in the bean ...

This works for form type 'create' and sub-categories ... I will have to investigate more ... but it is nice to be able to reuse the form-framework/knowledge for categories instead of rolling your own ... this also supports custom categories, children / inherited types of cm:category.

Friday, July 6, 2012

Moving alf_data


Transfering large repositories to new servers (upgrade, backup) - can be time consuming and this can mean downtime for users. Further more often networks can be loaded.So lets do all in one go ....

In remote terminal at source host:

cd /opt/alfresco; tar jcf - alf_data/ | ssh -o 'Compression no' <user>@<host> 'tar jxf -'

Or in terminal at destination host (reverse, pipe back):

ssh -o 'Compression no' <user>@<host> 'cd /opt/alfresco; tar jcf - alf_data/' | tar jxf -

I turn of ssh compresion and above provide reverse method, if you only have acces oneway ....

Thursday, July 5, 2012

Form control Period.ftl

If your into doing the new share 4.0 forms for simple form doc.lib. actions (onActionFormDialog), you might what to use the Period.ftl control setting it up manually.

To do this it needs some specification of what goes into the drop-down etc.

This example adds all possibilities as an control-param containing a json array:

<control template="/org/alfresco/components/form/controls/period.ftl" >
     <control-param name="dataTypeParameters">                   [{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"End Of Quarter","type":"quarterend"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"Year","type":"year"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"Quarter","type":"quarter"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"Day","type":"day"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"End Of Month","type":"monthend"},{"hasExpression":false,"label":"None","type":"none"},{"hasExpression":false,"label":"Immediately","type":"immediately"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"End Of Financial Month","type":"fmend"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"End Of Year","type":"yearend"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"End Of Financial Year","type":"fyend"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"Week","type":"week"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"End Of Financial Quarter","type":"fqend"},{"hasExpression":true,"expressionType":"int","expressionMandatory":false,"defaultExpression":"1","label":"Month","type":"month"}]
     </control-param> 

</control>

:)