cancel
Showing results for 
Search instead for 
Did you mean: 

delete node

salma1
Champ in-the-making
Champ in-the-making
hi
I have a node  called node1
I want to delete this node using a java code
i try to use node1.remove() but it doesn't work
does someone Know how to do that with a simple java code? and what are importations that I should do.
Thanks
10 REPLIES 10

fluca1978
Champ in-the-making
Champ in-the-making
Using a CMLDelete instruction?
Something like this using web services:

CMLDelete deleteInstruction = new CMLDelete();deleteInstruction.setWhere(  new Predicate( referencesToDelete, myStore, null ) );CML executor = new CML();executor.setDelete( new CMLDelete[]{ deleteInstruction } );UpdateResult[] result = WebServiceFactory.getRepositoryService().update(executor);‍‍‍‍‍‍‍‍‍‍‍

salma1
Champ in-the-making
Champ in-the-making
my node has the type org.alfresco.webservice.types.Node
how can I  delete it using  the  CML  method or other mehod

i think I must show the code
it 's of the alfresco-search  portlet of lifeary that I want to adapt it to delete the node after having search it
<%/** * Copyright (C) 2010  John Baskeyfield, john.baskeyfield@gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */%><%@ include file="init.jsp" %><%   Log logger = LogFactory.getLog("alfrescosearch");      PortletPreferences preferences = renderRequest.getPreferences();   String endPoint = preferences.getValue("endPoint", new String());   String user = preferences.getValue("user", new String());   String password = preferences.getValue("password", new String());   String keywords = request.getParameter("keywords");   int results = Integer.parseInt(preferences.getValue("results", new String()));      PortletURL portletURL = renderResponse.createRenderURL();%><form action="<%=portletURL%>" method="POST">   <input type="text" name="keywords" value="<%if(keywords != null) out.println(keywords); %>"/>   <input type="submit" value="Search" /></form><br><%   if (keywords != null){            try{               WebServiceFactory.setEndpointAddress(endPoint+"/api");         AuthenticationUtils.startSession(user, password);         Reference parentReference = null;                 RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();          Query query = new Query("lucene", "ALL:'" + keywords + "'");                Store storeRef = new Store("workspace", "SpacesStore");         Node [] nodes = null;         nodes = WebServiceFactory.getRepositoryService().get(new Predicate(null,storeRef,query));                  int pageIndex = 0;         int resultIndex = 0;         int pageResults = 0;         int iterations = 0;         String name = null;         String uuid = null;         String description = null;                  if (request.getParameter("position") == null ){ pageIndex = 0;} else { pageIndex = Integer.parseInt(request.getParameter("position"));}            if (nodes != null){            NamedValue[] props = null;%><table width="100%" class="lfr-table">      <tbody>        <tr>          <td width="70%" valign="top">            <div style="padding-bottom: 5px;">              <b>Alfresco</b>            </div>            <div class="results-grid">              <table class="taglib-search-iterator">                <tbody>                  <tr class="portlet-section-header results-header">                    <th width="18px" class="col-1">                      #                    </th>                    <th class="col-2">                      Name                    </th>                    <th class="col-3">                      Description                    </th>                  </tr>                  <tr class="lfr-template portlet-section-body results-row">                    <td width="18px"></td>                    <td></td>                    <td></td>                  </tr><%   if (nodes.length - (pageIndex * results) > results){iterations = (pageIndex * results)+results;}else{iterations=nodes.length;}      for (int x = pageIndex * results; x < iterations; x++)      {         props=nodes[x].getProperties();         pageResults++;         for(int y = 0; y < props.length; y++)          {            if(props[y].getName().endsWith("{http://www.alfresco.org/model/content/1.0}name") == true) {                                  name=props[y].getValue();            }            if(props[y].getName().endsWith("{http://www.alfresco.org/model/content/1.0}description") == true) {                                  description=props[y].getValue();            }            if(props[y].getName().endsWith("{http://www.alfresco.org/model/system/1.0}node-uuid") == true) {                            uuid=props[y].getValue();            }         }            if((x-(pageIndex * results))%2 == 0) {%>               <tr height="22px" onmouseout="this.className = 'portlet-section-body results-row';"                       onmouseover="this.className = 'portlet-section-body-hover results-row hover';"                       class="portlet-section-body results-row"><%}else{%>               <tr height="22px" onmouseout="this.className = 'portlet-section-alternate results-row alt';"                       onmouseover="this.className = 'portlet-section-alternate-hover results-row alt hover';"                       class="portlet-section-alternate results-row alt"><%}%>                        <td width="18px" align="left" valign="middle" colspan="1" class="col-1">                          <%=resultIndex+1+(pageIndex*results)%>.                        </td>                        <td align="left" valign="middle" colspan="1" class="col-2">                           <a target="_blank" href="<%=endPoint%>/d/a/workspace/SpacesStore/<%=uuid%>/<%=name%>"><%=name%></a>                        </td>                        <td align="left" valign="middle" colspan="1" class="col-3">                        <%if(description!=null) out.println(description); %>                        </td>               </tr><%            resultIndex++;                                    }%>                     </tbody>                  </table>               </div>            <div class="taglib-search-iterator-page-iterator-bottom">               <div class="taglib-page-iterator">                  <div class="search-results">                     <%if(nodes.length <= results){%>                        <%=pageResults%> results.<p> </p>                     <%}else{%>                        Results <%=(pageIndex * results)+1%> - <%=(resultIndex+(pageIndex * results))%> of <%=nodes.length%>.                     <%}%>                  </div>               </div>            </div>         </td>      </tr>   </tbody></table><%      PortletURL portletURLpage = renderResponse.createRenderURL();      portletURLpage.setParameter("keywords", keywords);      if(nodes.length > results){         for (int x = 0; x < Math.ceil( (double)nodes.length / (double)results ); x++){%>            <a href="<%=portletURLpage%>&position=<%=x%>"><%=x+1%></a><%            if(x != (Math.ceil( (double)nodes.length / (double)results ))-1){out.println(" ,");}         }%><p> </p><%      }                }else{%>          <p>No results found.</p><%      }                }catch(AuthenticationFault af){         out.println("<p>Invalid User/Password for Alfresco. Please set preferences.</p>");        }catch(WebServiceException wse){         out.println("<p>Unable to connect to Alfresco url. Please set preferences.</p>");              }catch(Exception ex){           logger.error(ex.getMessage());      }        finally        {            // End the session            AuthenticationUtils.endSession();              }}%>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
can I do that? because i want to delete node using liferay

fluca1978
Champ in-the-making
Champ in-the-making
When you have a node you can get the reference from it, then you can build a predicate around such reference, then you can insert such predicate in the cmldelete and then you can execute the delete.
This is the only way I know to delete a node.

salma1
Champ in-the-making
Champ in-the-making
Hi,
thanks, I used the CML delete and it works rigth
now I want to delete from a specific folder

I want o delete for exemple from the Sites folder which is ander the company home
I replace Query query = new Query("lucene", "TEXT:' "+keywords+"'");
with    Query query = new Query("lucene", "PATH:\"/app:company_home/
cmSmiley Frustratedites/"+keywords+"\"");      
but it doesn't work
what's wrong in my query?
please help me

fluca1978
Champ in-the-making
Champ in-the-making
I'm not an expert of Lucene query sintax, so I cannot help you. What I note is that in the first case you have specified the keywords with the TEXT modifier, while in the second no. I don't know if the PATH and TEXT modifiers can be specified both in a lucene query.

salma1
Champ in-the-making
Champ in-the-making
Thanks
but I want ,if that possible a concrete code that helps me.
Does any one have an idea?

mrogers
Star Contributor
Star Contributor

salma1
Champ in-the-making
Champ in-the-making
thanks for you
I have already found the mistake
there is what Ichanged in my query
Query query = new Query("lucene", "PATH:\"/app:company_home/
stSmiley Frustratedites//*\" AND ALL:' "+keywords+"'");

rice8702
Champ in-the-making
Champ in-the-making
Have also here been looking for a substantial code to help with this delete.