@Override
  public List<CopyToEnvironmentItem> processMandatoryDependencies(
      CopyToEnvironmentItem item, List<String> pathsToDeploy, Set<String> missingDependenciesPaths)
      throws DeploymentException {
    List<CopyToEnvironmentItem> mandatoryDependencies = new ArrayList<CopyToEnvironmentItem>();
    String site = item.getSite();
    String path = item.getPath();
    if (item.getAction() == CopyToEnvironmentItem.Action.NEW
        || item.getAction() == CopyToEnvironmentItem.Action.MOVE) {
      String helpPath = path.replace("/" + _indexFile, "");
      int idx = helpPath.lastIndexOf("/");
      String parentPath = helpPath.substring(0, idx) + "/" + _indexFile;
      if (_contentRepository.isNew(site, parentPath)
          || _contentRepository.isRenamed(site, parentPath)) {
        String parentFullPath = _contentRepository.getFullPath(site, parentPath);
        if (!missingDependenciesPaths.contains(parentFullPath)
            && !pathsToDeploy.contains(parentFullPath)) {
          try {
            _deploymentDAL.cancelWorkflow(site, parentPath);
          } catch (DeploymentDALException e) {
            LOGGER.error(
                "Error while canceling workflow for path {0}, site {1}", e, site, parentPath);
          }
          missingDependenciesPaths.add(parentFullPath);
          CopyToEnvironmentItem parentItem = createMissingItem(site, parentPath, item);
          processItem(parentItem);
          mandatoryDependencies.add(parentItem);
          mandatoryDependencies.addAll(
              processMandatoryDependencies(parentItem, pathsToDeploy, missingDependenciesPaths));
        }
      }

      List<String> dependentPaths = _contentRepository.getDependentPaths(site, path);
      for (String dependentPath : dependentPaths) {
        if (_contentRepository.isNew(site, dependentPath)
            || _contentRepository.isRenamed(site, dependentPath)) {
          String dependentFullPath = _contentRepository.getFullPath(site, dependentPath);
          if (!missingDependenciesPaths.contains(dependentFullPath)
              && !pathsToDeploy.contains(dependentFullPath)) {
            try {
              _deploymentDAL.cancelWorkflow(site, dependentPath);
            } catch (DeploymentDALException e) {
              LOGGER.error(
                  "Error while canceling workflow for path {0}, site {1}", e, site, dependentPath);
            }
            missingDependenciesPaths.add(dependentFullPath);
            CopyToEnvironmentItem dependentItem = createMissingItem(site, dependentPath, item);
            processItem(dependentItem);
            mandatoryDependencies.add(dependentItem);
            mandatoryDependencies.addAll(
                processMandatoryDependencies(
                    dependentItem, pathsToDeploy, missingDependenciesPaths));
          }
        }
      }
    }

    return mandatoryDependencies;
  }
 @Override
 public void processItem(CopyToEnvironmentItem item) throws DeploymentException {
   String liveEnvironment = _contentRepository.getLiveEnvironmentName(item.getSite());
   boolean isLive = false;
   if (StringUtils.isNotEmpty(liveEnvironment)) {
     if (liveEnvironment.equals(item.getEnvironment())) {
       isLive = true;
     }
   } else if (LIVE_ENVIRONMENT.equalsIgnoreCase(item.getEnvironment())
       || PRODUCTION_ENVIRONMENT.equalsIgnoreCase(item.getEnvironment())) {
     isLive = true;
   }
   if (item.getAction() == CopyToEnvironmentItem.Action.DELETE) {
     if (item.getOldPath() != null && item.getOldPath().length() > 0) {
       _contentRepository.deleteContent(item.getSite(), item.getEnvironment(), item.getOldPath());
       _contentRepository.clearRenamed(item.getSite(), item.getPath());
     }
     _contentRepository.deleteContent(item.getSite(), item.getEnvironment(), item.getPath());
     if (isLive) {
       _contentRepository.deleteContent(item);
     }
   } else {
     _contentRepository.setSystemProcessing(item.getSite(), item.getPath(), true);
     if (isLive) {
       if (!_importModeEnabled) {
         _contentRepository.createNewVersion(
             item.getSite(), item.getPath(), item.getSubmissionComment(), true);
       } else {
         LOGGER.debug(
             "Import mode is ON. Create new version is skipped for [{0}] site \"{1}\"",
             item.getPath(), item.getSite());
       }
     }
     if (item.getAction() == CopyToEnvironmentItem.Action.MOVE) {
       if (item.getOldPath() != null && item.getOldPath().length() > 0) {
         _contentRepository.deleteContent(
             item.getSite(), item.getEnvironment(), item.getOldPath());
         if (isLive) {
           _contentRepository.clearRenamed(item.getSite(), item.getPath());
         }
       }
     }
     _contentRepository.copyToEnvironment(item.getSite(), item.getEnvironment(), item.getPath());
     if (isLive) {
       _contentRepository.stateTransition(
           item.getSite(), item.getPath(), TransitionEvent.DEPLOYMENT);
     }
     _contentRepository.setSystemProcessing(item.getSite(), item.getPath(), false);
   }
 }