title: Alfresco delete node permanently using a web service
body: <p>I am trying to delete a node in Alfresco(CE, v. 2.1) permanently(without moving it to trash can first) using web service. </p>
  
  <p>My use case is this: create a standalone job that queries the repo for files older than 2 years and delete them permanently using web service. Then the cleanup job moves the deleted files to content.deleted which I can safely delete.</p>
  
  <p>Below is my code</p>
  
  <pre><code>import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
  import org.alfresco.webservice.types.CML;
  import org.alfresco.webservice.types.CMLAddAspect;
  import org.alfresco.webservice.types.CMLDelete;
  import org.alfresco.webservice.types.Node;
  import org.alfresco.webservice.types.Predicate;
  import org.alfresco.webservice.types.Reference;
  import org.alfresco.webservice.types.Store;
  import org.alfresco.webservice.util.AuthenticationUtils;
  import org.alfresco.webservice.util.Constants;
  import org.alfresco.webservice.util.ContentUtils;
  import org.alfresco.webservice.util.WebServiceFactory;
  
  public class NodeDeletionService {
  
      protected static final Store STORE = new Store(Constants.WORKSPACE_STORE,
              "SpacesStore");
  
      public static void main(String[] args) {
  
          try {
  
              AuthenticationUtils.startSession("admin", "admin");
  
              RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory
                      .getRepositoryService();
  
              Reference reference = new Reference(STORE,
                      "8abb6223-11bb-11e4-a335-65e3a9c8626a", null);
              Predicate predicate = new Predicate(new Reference[] { reference },
                      null, null);
              Node[] nodes = repositoryService.get(predicate);
  
              CMLDelete delete = new CMLDelete(predicate);
  
              CML cml = new CML();
  
              cml.setDelete(new CMLDelete[] { delete });
  
              CMLAddAspect addAspect = new CMLAddAspect("temporary", null, predicate, null);
  
              cml.setAddAspect(new CMLAddAspect[]{addAspect});
  
              // Execute the CMLDelete statement
  
              try {
                  WebServiceFactory.getRepositoryService().update(cml);
                  System.out.println("Deleted succesfully");
              } catch (Exception e2) {
                  System.err.println("Can not delete the space.");
                  throw e2;
              }
  
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } finally {
              AuthenticationUtils.endSession();
          }
      }
  }
  </code></pre>
  
  <p>But I get an exception  </p>
  
  <p><code>{http://www.alfresco.org/ws/service/repository/1.0}RepositoryFault:&lt;ns1:errorCode&gt;0&lt;/ns1:errorCode&gt;&lt;ns1:message&gt;org.alfresco.service.cmr.dictionary.InvalidAspectException: The aspect is invalid: {}temporary&lt;/ns1:message&gt;
      {http://xml.apache.org/axis/}exceptionName:org.alfresco.repo.webservice.repository.RepositoryFault</code></p>
  
  <p>I tried different aspects like <code>temporary</code>, <code>cm:temporary</code>, <code>sys:temporary</code> - but all in vain. Any idea?</p>