public boolean deleteEntry(User user,Entry entry,String childrenAction,boolean isAdmin,List<String> deletedEntryIds,Errors errors){
  String originalChildrenAction=childrenAction;
  if (entry == null) {
    Errors.add(errors,errorMessages.errorEntryIsNull());
    return false;
  }
  if (user == null) {
    Errors.add(errors,errorMessages.errorUserIsNull());
    return false;
  }
  if (childrenAction != null && !childrenAction.equals("delete") && !childrenAction.equals("orphan") && !childrenAction.equals("parent")) {
    Errors.add(errors,errorMessages.errorChildrenActionInvalid());
    return false;
  }
  if (!canUserModifyEntry(user,entry,isAdmin)) {
    Errors.add(errors,errorMessages.errorUserIsNotEntitledToDelete());
    return false;
  }
  final Entry parent=getEntryById(entry.getParentId());
  if (parent == null && childrenAction != null && childrenAction.equals("parent")) {
    if (entry.isSource() || entry.isQuotation()) {
      childrenAction="delete";
    }
 else {
      Errors.add(errors,errorMessages.errorChildrenActionMayNotBeParentIfTheDeletedEntryHasNoParent());
      return false;
    }
  }
  boolean doNotUpdateSiblings=false;
  if (childrenAction != null && childrenAction.equals("parent")) {
    reparentChildren(entry,parent);
    doNotUpdateSiblings=true;
  }
  if (parent != null) {
    removeEntryFromParent(entry,parent,doNotUpdateSiblings);
  }
  for (  Object objectChild : getEntriesByParentId(entry.getId())) {
    Entry child=(Entry)objectChild;
    if (childrenAction == null || childrenAction.equals("delete")) {
      if (!deleteEntry(user,child,childrenAction,isAdmin,deletedEntryIds,errors)) {
        return false;
      }
    }
 else     if (childrenAction.equals("orphan")) {
      child.setParentId(null);
      child.setNextSiblingId(null);
      child.setPreviousSiblingId(null);
    }
 else     if (childrenAction.equals("parent")) {
      child.setParentId(parent.getId());
    }
  }
  if (deletedEntryIds != null) {
    deletedEntryIds.add(entry.getId());
  }
  db.removeEntry(entry);
  if (entry.isNotebook()) {
    Entry rootEntry=getEntryById(entry.getRootId());
    return deleteEntry(user,rootEntry,"delete",isAdmin,deletedEntryIds,errors);
  }
 else   if (entry.isSource()) {
    for (    Object objectQuotation : getEntriesBySourceId(entry.getId(),0,Integer.MAX_VALUE)) {
      Entry quotation=(Entry)objectQuotation;
      if (wasEntryDeletedInThisTransaction(quotation)) {
        continue;
      }
      if (!deleteEntry(user,quotation,originalChildrenAction,isAdmin,deletedEntryIds,errors)) {
        return false;
      }
    }
  }
  return true;
}

public boolean deleteEntry ( User user , Entry entry , String childrenAction , boolean isAdmin , List < String > deletedEntryIds , Errors errors ) { String originalChildrenAction = childrenAction ; if ( entry == null ) { Errors . add ( errors , errorMessages . errorEntryIsNull ( ) ) ; return false ; } if ( user == null ) { Errors . add ( errors , errorMessages . errorUserIsNull ( ) ) ; return false ; } if ( childrenAction != null && ! childrenAction . equals ( "delete" ) && ! childrenAction . equals ( "orphan" ) && ! childrenAction . equals ( "parent" ) ) { Errors . add ( errors , errorMessages . errorChildrenActionInvalid ( ) ) ; return false ; } if ( ! canUserModifyEntry ( user , entry , isAdmin ) ) { Errors . add ( errors , errorMessages . errorUserIsNotEntitledToDelete ( ) ) ; return false ; } final Entry parent = getEntryById ( entry . getParentId ( ) ) ; if ( parent == null && childrenAction != null && childrenAction . equals ( "parent" ) ) { if ( entry . isSource ( ) || entry . isQuotation ( ) ) { childrenAction = "delete" ; } else { Errors . add ( errors , errorMessages . errorChildrenActionMayNotBeParentIfTheDeletedEntryHasNoParent ( ) ) ; return false ; } } boolean doNotUpdateSiblings = false ; if ( childrenAction != null && childrenAction . equals ( "parent" ) ) { reparentChildren ( entry , parent ) ; doNotUpdateSiblings = true ; } if ( parent != null ) { removeEntryFromParent ( entry , parent , doNotUpdateSiblings ) ; } for ( Object objectChild : getEntriesByParentId ( entry . getId ( ) ) ) { Entry child = ( Entry ) objectChild ; if ( childrenAction == null || childrenAction . equals ( "delete" ) ) { if ( ! deleteEntry ( user , child , childrenAction , isAdmin , deletedEntryIds , errors ) ) { return false ; } } else if ( childrenAction . equals ( "orphan" ) ) { child . setParentId ( null ) ; child . setNextSiblingId ( null ) ; child . setPreviousSiblingId ( null ) ; } else if ( childrenAction . equals ( "parent" ) ) { child . setParentId ( parent . getId ( ) ) ; } } if ( deletedEntryIds != null ) { deletedEntryIds . add ( entry . getId ( ) ) ; } db . removeEntry ( entry ) ; if ( entry . isNotebook ( ) ) { Entry rootEntry = getEntryById ( entry . getRootId ( ) ) ; return deleteEntry ( user , rootEntry , "delete" , isAdmin , deletedEntryIds , errors ) ; } else if ( entry . isSource ( ) ) { for ( Object objectQuotation : getEntriesBySourceId ( entry . getId ( ) , 0 , Integer . MAX_VALUE ) ) { Entry quotation = ( Entry ) objectQuotation ; if ( wasEntryDeletedInThisTransaction ( quotation ) ) { continue ; } if ( ! deleteEntry ( user , quotation , originalChildrenAction , isAdmin , deletedEntryIds , errors ) ) { return false ; } } } return true ; }
api method . delete an entry entry .
