private void updateEncodingPresets(Resource configResource, S7Config s7Config, String typeHandle)
      throws RepositoryException {

    // Get the presets from S7 and store them on the node
    //
    List<Scene7PropertySet> propertySets = scene7Service.getPropertySets(typeHandle, s7Config);

    String path = configResource.getPath() + "/" + Scene7PresetsService.REL_PATH_ENCODING_PRESETS;
    Node node = prepNode(configResource.getResourceResolver(), path);
    Node presetNode;
    int i = 0;
    for (Scene7PropertySet propertySet : propertySets) {
      String handle = propertySet.getSetHandle();
      String nodeName = getNodeName(handle);
      if (StringUtils.isNotBlank(nodeName)) {
        presetNode = node.addNode(nodeName);
        presetNode.setProperty("handle", handle);
        Map<String, String> properties = propertySet.getProperties();
        for (String key : properties.keySet()) {
          String value = properties.get(key);
          key = StringUtils.uncapitalize(key);
          presetNode.setProperty(key, value);
        }
      }
    }
  }
  private void updateViewerPresets(Resource configResource, S7Config s7Config)
      throws RepositoryException {

    // Get the presets from S7 and store them on the node
    //
    List<Scene7Asset> assets =
        scene7Service.searchAssets(
            s7Config.getBasePath(),
            Boolean.TRUE,
            Boolean.TRUE,
            new String[] {"ViewerPreset"},
            null,
            new String[] {
              "assetArray/items/assetHandle",
              "assetArray/items/type",
              "assetArray/items/name",
              "assetArray/items/viewerPresetInfo"
            },
            null,
            s7Config);

    if (assets.size() > 0) {
      String path = configResource.getPath() + "/" + Scene7PresetsService.REL_PATH_VIEWER_PRESETS;

      Node node = prepNode(configResource.getResourceResolver(), path);
      int i = 0;
      for (Scene7Asset asset : assets) {
        String name = asset.getName();
        String type = asset.getViewerPresetType();

        Node presetNode = node.addNode("preset" + i);
        presetNode.setProperty("name", name);
        presetNode.setProperty("type", (type != null ? type : ""));
        presetNode.setProperty("config", s7Config.getBasePath() + name);

        Map<String, String> viewerPresetConfigurationSettings =
            asset.getViewerPresetConfigurationSettings();
        if (viewerPresetConfigurationSettings != null
            && !viewerPresetConfigurationSettings.isEmpty()) {
          presetNode = presetNode.addNode("settings");
          for (Entry<String, String> entry : viewerPresetConfigurationSettings.entrySet()) {
            String settingName = entry.getKey();
            String value = entry.getValue();
            if (settingName != null && value != null) {
              presetNode.setProperty(settingName, value);
            }
          }
        }
        i++;
      }
    }
  }
  @Override
  public boolean updateEncodingPresets(Resource configResource) {
    try {
      S7Config s7Config = s7configResolver.getS7Config(configResource.getParent().getPath());
      S7Config sharedConfig = s7configResolver.getSharedS7Config(s7Config);

      String typeHandle = scene7Service.getVideoEncoderPresetTypeHandle(s7Config);

      updateEncodingPresets(configResource, s7Config, typeHandle); // custom presets
      Resource shared = configResource.getParent().getParent();
      updateEncodingPresets(shared, sharedConfig, typeHandle); // shared presets

      Session session = configResource.getResourceResolver().adaptTo(Session.class);
      session.save();

      return true;
    } catch (RepositoryException e) {
      LOG.error(e.getMessage(), e);
    }
    return false;
  }