cancel
Showing results for 
Search instead for 
Did you mean: 

behaviour cancel delete node

dacedos
Champ in-the-making
Champ in-the-making
Hi,

I need to implement a behaviour to check some conditions before deleting a node. Can I cancel the delete action if the node does not match all conditions?

thanks!
11 REPLIES 11

derek
Star Contributor
Star Contributor
Hi,
Look at org.alfresco.repo.model.ml.MultilingualDocumentAspect for an example of how you can react to 'beforeDeleteNode'.  Throw any exception to terminate the process and force a rollback.  You may need to do some UI work to ensure the user gets to see pretty messages.
Regards

dacedos
Champ in-the-making
Champ in-the-making
Thanks Derek that was what exactly I need, throwing an exception

dacedos
Champ in-the-making
Champ in-the-making
I have another question now about throwing exceptions.

I try to throw a new AlfrescoRuntimeException, constructor needs "String msgId" but it is actually the string he shows on screen. how could I show messages from webclient.properties? Because messages should be showed in different languages.

derek
Star Contributor
Star Contributor
Have you tried to pass in the message ID?

dacedos
Champ in-the-making
Champ in-the-making
hi Derek, thanks for writing back,

Yes, I think so,  I add the message to the file properties

message_delete1=Document cannot be deleted.


and I try to throw the exception

throw new AlfrescoRuntimeException("message_delete1");

when it shows the bar on the top it says:

Error  Please correct the errors below then click OK.

    * Unable to delete File due to system error: message_delete1

is there any other exception I can use to cancel the delete node and show another message less… "fatalistic" it is just the node could not be deleted because it do not match a condition is not a real  system error.

derek
Star Contributor
Star Contributor
Hi,
You would need a bean like this to load your resources:

   <bean id="emailResourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
        <property name="resourceBundles">
            <list>
                <value>alfresco.messages.email-service</value>
            </list>
        </property>
   </bean>
If you want to change the reporting behaviour, you will have to hack BaseDialogBean.

dacedos
Champ in-the-making
Champ in-the-making
is that bean necessary if I add those messages within webclient.properties and webclient_es_ES.properties ??

does Alfresco know by itself those String are message ids ? do not they need any '#' or something like jsp's with labels? …

and… EDIT: I have just noticed that Alfresco doesn't show any of my messages if I set the language to Spanish. It shows only the head

derek
Star Contributor
Star Contributor
Hi,
You probably need the bean and the resource file as the error message is generated in the repository.  Hacking the dialog bean will suit you best, it seems.
Regards

dacedos
Champ in-the-making
Champ in-the-making
Sorry Derek but I need a little bit more help with that.

I have those properties files within alfresco.messages:

delete-behaviour.properties

message_delete1=Document cannot be deleted. Document is not in draft status.
message_delete2=You do not have permissions to delete the document. You are not part of coordinators group.
message_delete3=You cannot delete the document. There was a fail trying to get the authors list.
message_delete4=You do not have permissions to delete the document. You do not belong to the authors list.
message_delete5=Document cannot be deleted. It has other documents related besides their own renditions.

delete-behaviour_es_ES.properties

message_delete1=No se puede borrar el documento. No se encuentra en estado borrador.
message_delete2=No tiene permisos para borrar el documento. No pertenece al grupo de coordinadores.
message_delete3=No puede borrar el documento. No puede comprobarse que usted pertenece a la lista de autores.
message_delete4=Usted no esta autorizado a borrar el documento. No pertenece a la lista de autores o autores externos.
message_delete5=No puede borrarse el documento. Contiene otros documentos relacionados además de la rendition.

the bean in behaviours-context.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
   <bean id="SGDocumentBeforeDeleteBehaviour" class="com.sysdoc.behaviours.SGDocumentBeforeDeleteBehaviour" init-method="init">
         <property name="policyComponent">
            <ref bean="policyComponent" />
         </property>
     </bean>
    <bean id="SGDocumentDeleteBehaviour" class="com.sysdoc.behaviours.SGDocumentDeleteBehaviour" init-method="init">
         <property name="policyComponent">
            <ref bean="policyComponent" />
         </property>
         <property name="nodeService">
            <ref bean="nodeService" />
         </property>
      </bean>
<bean id="deleteResourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
        <property name="resourceBundles">
            <list>
                <value>alfresco.messages.delete-behaviour</value>
            </list>
        </property>
   </bean>
</beans>

now, it shows the English messages but it misses the Spanish language. I mean. If I select English it shows something like:

  Please correct the errors below then click OK.

    * Unable to delete File due to system error: Document cannot be deleted. Document is not in draft status.

whereas if language is Spanish it shows:
 Por favor corrija los errores siguientes y pulse Aceptar.

    * No se puede eliminar el fichero debido a un error del sistema:
As you can see message is missed.

Should I report it in jira??