@Override
  public void doProcess(
      PublishedChangeSet changeSet, Map<String, String> parameters, PublishingTarget target)
      throws PublishingException {
    String root = target.getParameter(FileUploadServlet.CONFIG_ROOT);
    String contentFolder = target.getParameter(FileUploadServlet.CONFIG_CONTENT_FOLDER);
    String siteId =
        (!StringUtils.isEmpty(siteName)) ? siteName : parameters.get(FileUploadServlet.PARAM_SITE);

    root += "/" + contentFolder;

    if (StringUtils.isNotBlank(siteId)) {
      root = root.replaceAll(FileUploadServlet.CONFIG_MULTI_TENANCY_VARIABLE, siteId);
    }

    List<String> createdFiles = changeSet.getCreatedFiles();
    List<String> updatedFiles = changeSet.getUpdatedFiles();
    List<String> deletedFiles = changeSet.getDeletedFiles();

    if (CollectionUtils.isNotEmpty(createdFiles)) {
      update(siteId, root, createdFiles, false);
    }
    if (CollectionUtils.isNotEmpty(updatedFiles)) {
      update(siteId, root, updatedFiles, false);
    }
    if (CollectionUtils.isNotEmpty(deletedFiles)) {
      update(siteId, root, deletedFiles, true);
    }

    searchService.commit();
  }
 private void processFiles(String siteId, String root, List<String> fileList, boolean isDelete)
     throws IOException {
   for (String filePath : fileList) {
     if (logger.isDebugEnabled()) {
       logger.debug(String.format("Processing file %s for site %s", filePath, siteId));
     }
     File file = new File(root + filePath);
     String updateIndexPath = filePath;
     Map<String, String> externalProperties = null;
     boolean searchIndexUpdate = false;
     if (!isDelete) {
       if (isMetadataFile(filePath)) {
         if (logger.isDebugEnabled()) {
           logger.debug("Metadata processing started.");
         }
         SAXReader reader = new SAXReader();
         try {
           Document document = reader.read(file);
           updateIndexPath = getAttachmentPath(document);
           if (StringUtils.isNotBlank(updateIndexPath)) {
             if (logger.isDebugEnabled()) {
               logger.debug("Extracting properties.");
             }
             externalProperties = parseMetadataFile(document);
             file = new File(root + updateIndexPath);
             if (!file.exists()) {
               File dir = file.getParentFile();
               dir.mkdirs();
               file.createNewFile();
             }
             searchIndexUpdate = true;
           }
         } catch (DocumentException e) {
           logger.error(
               String.format("Error while opening xml file %s for site %s", filePath, siteId), e);
         }
         if (logger.isDebugEnabled()) {
           logger.debug("Metadata processing finished.");
         }
       } else if (isAttachmentFile(filePath)) {
         searchIndexUpdate = true;
       }
     }
     if (searchIndexUpdate) {
       if (isDelete) {
         searchService.delete(siteId, updateIndexPath);
       } else {
         if (logger.isDebugEnabled()) {
           logger.debug(
               String.format(
                   "Sending search update request for file %s [%s] for site %s",
                   updateIndexPath, filePath, siteId));
         }
         searchService.partialDocumentUpdate(siteId, updateIndexPath, file, externalProperties);
       }
     }
     searchService.commit();
   }
 }