Asignar Categoría al subir documento

cancel
Showing results for 
Search instead for 
Did you mean: 
baskeyfield
Member II

Asignar Categoría al subir documento

Buenas,

Cuando subimos un documento a Alfresco, nos aparece un wizard de 2 pasos para añadirle metadatos. Me gustaría poder añadirle categorías en ese momento, en lugar de tener que ir hasta su vista de detalles y asignarselas a posteriori. No me interesa que lo haga una regla, necesito que sea manual. ¿Como podria hacerse esto? (asignando el aspecto categorizable no es suficiente).

Por otro lado, he visto que con las "tags" si se puede hacer, se asigna el aspecto "taggable" y ya desde el wizard de metadatos se pueden seleccionar, pero, ¿como se borran estas tags? no hablo de las que se le han asignado a un doc, sino quitarlas totalmente del listado, algo similar a lo que se puede hacer desde el administrador de categorias.

**Edito, acabo de leer en un post reciente preguntando como borrar las tags, y se sugiere borrar la tag en todos los documentos en los que aparezca, ¿no hay nada más rapido? ¿como localizo esos documentos?

Un saludo.
2 Replies
baskeyfield
Member II

Re: Asignar Categoría al subir documento

Hola,

Os cuento mis avances, estoy modificando el dialog addContentDialog.java, y el add-content-dialog.jsp. También he tocado el custom-faces-config.xml

CustomAddContentDialog.java:

    package org.alfresco.sample;

    import java.io.Serializable;
    import java.util.List;
    import java.util.Map;
    import javax.faces.context.FacesContext;
    import org.alfresco.model.ContentModel;
    import org.alfresco.service.cmr.dictionary.DictionaryService;
    import org.alfresco.service.cmr.repository.NodeRef;
    import org.alfresco.service.cmr.repository.NodeService;
    import org.alfresco.util.ParameterCheck;
    import org.alfresco.web.app.Application;
    import org.alfresco.web.bean.content.AddContentDialog;
    import org.alfresco.web.bean.dialog.BaseDialogBean;
    import org.alfresco.web.bean.repository.Node;


    @SuppressWarnings({"serial", "unchecked"})
    public class CustomAddContentDialog extends AddContentDialog{

       protected Node node;
       protected NodeRef addedCategory;
       protected List categories;
       protected String description;
      
       @Override
       public void init(Map<String, String> parameters)
       {
         super.init(parameters);

         this.categories = null;
         this.addedCategory = null;

         String nodeRef = (String)parameters.get("nodeRef");

         ParameterCheck.mandatoryString("nodeRef", nodeRef);

         this.node = new Node(new NodeRef(nodeRef));

         FacesContext context = FacesContext.getCurrentInstance();
         if (getDictionaryService().isSubClass(this.node.getType(), ContentModel.TYPE_FOLDER))
         {
           this.description = Application.getMessage(context, "editcategory_space_description");
         }
         else
         {
           this.description = Application.getMessage(context, "editcategory_description");
         }
       }
      
       public boolean getFinishButtonDisabled()
       {
         return false;
       }

       public String getContainerTitle()
       {
         return Application.getMessage(FacesContext.getCurrentInstance(), "modify_categories_of") + " '" + this.node.getName() + "'";
       }

       public String getContainerDescription()
       {
         return this.description;
       }

       protected String getErrorMessageId()
       {
         return "error_update_category";
       }

       public List getCategories()
       {
         if (this.categories == null)
         {
           this.categories = ((List)getNodeService().getProperty(this.node.getNodeRef(), ContentModel.PROP_CATEGORIES));
         }

         return this.categories;
       }

       public void setCategories(List categories)
       {
         this.categories = categories;
       }

       public NodeRef getAddedCategory()
       {
         return this.addedCategory;
       }

       public void setAddedCategory(NodeRef addedCategory)
       {
         this.addedCategory = addedCategory;
       }
      
        @Override
        protected String finishImpl(FacesContext context, String outcome)
              throws Exception {
      
           outcome = super.finishImpl(context, outcome);    
          
           Map updateProps = getNodeService().getProperties(this.node.getNodeRef());

           updateProps.put(ContentModel.PROP_CATEGORIES, (Serializable)this.categories);

           getNodeService().setProperties(this.node.getNodeRef(), updateProps);         

          
           return outcome;
        }
    }



El add-content-dialog.jsp:


<table cellpadding="2" cellspacing="2" border="0" width="100%">
<tr>
<td colspan="2" class="paddingRow"></td></tr>
<tr>
<td></f:verbatim>
<h:outputText value="#{msg.categories}" /><f:verbatim>:</td>
<td width="98%">
</f:verbatim>
<r:multiValueSelector id="multi-category-selector"
value="#{AddContentDialog.categories}"
lastItemAdded="#{AddContentDialog.addedCategory}"
selectItemMsg="#{msg.select_category}"
selectedItemsMsg="#{msg.selected_categories}"
noSelectedItemsMsg="#{msg.no_selected_categories}"
styleClass="multiValueSelector">
<f:subview id="categorySelector">
<r:ajaxCategorySelector id="catSelector" styleClass="selector"
value="#{AddContentDialog.addedCategory}"
label="#{msg.select_category_prompt}" />
</f:subview>
</r:multiValueSelector>
<f:verbatim>
</td>
</tr>
<tr><td colspan="2" class="paddingRow"></td></tr>
</table>


El jsp se visualiza bien, puedo seleccionar categorias, pero cuando le doy a OK en wizard, obtengo un null pointer exception en el metodo finishImpl.

¿Sabeis que puede estar pasando? ¿Alguna sugerencia?

Gracias! un saludo.
baskeyfield
Member II

Re: Asignar Categoría al subir documento

Buenas,

Ya está solucionado, habían unos cuantos fallos, entre ellos que faltaba el método init y que no estaba leyendo bien el "createdNode".

Aquí está el codigo final:


    package org.alfresco.sample;

    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;

    import javax.faces.context.FacesContext;

    import org.alfresco.model.ContentModel;
    import org.alfresco.service.cmr.repository.NodeRef;
    import org.alfresco.web.bean.content.AddContentDialog;


    @SuppressWarnings({"serial", "unchecked"})
    public class CustomAddContentDialog extends AddContentDialog{
       
       private NodeRef addedCategory;
       private List<NodeRef> categories;
      
       public void init(Map<String, String> parameters)
       {
         super.init(parameters);

         this.categories = new ArrayList<NodeRef>();
         this.addedCategory = null;
       }

      
       public List getCategories(){
          return this.categories;
       }
      
       public void setCategories(List categories)
       {
         this.categories = categories;
       }     
      
      
       public void setAddedCategory(NodeRef addedCategory)
       {
         this.addedCategory = addedCategory;
       }
         
       public NodeRef getAddedCategory()
       {
         return this.addedCategory;
       }
      
      
        @Override
        protected String finishImpl(FacesContext context, String outcome)
              throws Exception {
      
           outcome = super.finishImpl(context, outcome);          
          
           Map updateProps = getNodeService().getProperties(this.createdNode);

           updateProps.put(ContentModel.PROP_CATEGORIES, (Serializable)this.categories);

           getNodeService().setProperties(this.createdNode, updateProps);
           
           return outcome;
        }
    }


Saludos.