/**
   * Removes unwanted aspects
   *
   * @param nodeService
   * @param nodeRef
   */
  protected void cleanDisposableItem(NodeService nodeService, NodeRef nodeRef) {
    // Remove unwanted aspects
    for (QName aspect : unwantedAspects) {
      if (nodeService.hasAspect(nodeRef, aspect)) {
        nodeService.removeAspect(nodeRef, aspect);
      }
    }

    // remove the current disposition action (if there is one)
    DispositionAction dispositionAction = dispositionService.getNextDispositionAction(nodeRef);
    if (dispositionAction != null) {
      nodeService.deleteNode(dispositionAction.getNodeRef());
    }
  }
  public void onCopyComplete(
      QName classRef,
      NodeRef sourceNodeRef,
      NodeRef targetNodeRef,
      boolean copyToNewNode,
      Map<NodeRef, NodeRef> copyMap) {
    Set<NodeRef> workingCopyNodeRefs = TransactionalResourceHelper.getSet(KEY_WORKING_COPIES);
    if (!workingCopyNodeRefs.contains(sourceNodeRef)) {
      // This is not one of the nodes that needs to have discussions copied over
      return;
    }

    // First check that the source node has forums
    NodeRef sourceForumNodeRef = getForum(sourceNodeRef);
    if (sourceForumNodeRef == null) {
      // Missing!  Clean the source node up!
      nodeService.removeAspect(sourceNodeRef, ForumModel.ASPECT_DISCUSSABLE);
      return;
    }

    // The aspect may or may not exist on the target node
    if (!nodeService.hasAspect(targetNodeRef, ForumModel.ASPECT_DISCUSSABLE)) {
      // Add the aspect
      nodeService.addAspect(targetNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
    }
    // Get the forum node
    NodeRef targetForumNodeRef = getForum(targetNodeRef);
    // Merge the forum topics
    List<ChildAssociationRef> topicAssocRefs =
        nodeService.getChildAssocs(
            sourceForumNodeRef, Collections.singleton(ForumModel.TYPE_TOPIC));
    int copied = 0;
    for (ChildAssociationRef topicAssocRef : topicAssocRefs) {
      NodeRef topicNodeRef = topicAssocRef.getChildRef();
      try {
        // work out the name for the copied topic
        String topicName;
        String topicNodeName =
            nodeService.getProperty(topicNodeRef, ContentModel.PROP_NAME).toString();
        Serializable labelProp =
            nodeService.getProperty(targetNodeRef, ContentModel.PROP_VERSION_LABEL);
        if (labelProp == null) {
          SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss");
          topicName = topicNodeName + " - " + dateFormat.format(new Date());
        } else {
          topicName = topicNodeName + " (" + labelProp.toString() + ")";
        }

        if (fileFolderService.searchSimple(targetForumNodeRef, topicName) != null) {
          // A topic with that name already exists
          continue;
        }
        fileFolderService.copy(topicNodeRef, targetForumNodeRef, topicName);
        copied++;
      } catch (FileExistsException e) {
        // We checked for this, so this is a concurrency condition
        throw new ConcurrencyFailureException("Target topic exists: " + e.getMessage(), e);
      } catch (FileNotFoundException e) {
        // The node was there, but now it's gone
        throw new ConcurrencyFailureException("Forum was deleted: " + e.getMessage(), e);
      }
    }
  }