ModelContentPackageFile.java

  1. /*
  2.  * #%L
  3.  * wcm.io
  4.  * %%
  5.  * Copyright (C) 2020 wcm.io
  6.  * %%
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *      http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  * #L%
  19.  */
  20. package io.wcm.devops.conga.plugins.aem.maven.model;

  21. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_GROUP;
  22. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_NAME;
  23. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_PACKAGE_TYPE;
  24. import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_VERSION;

  25. import java.io.File;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.Objects;

  29. import org.jetbrains.annotations.Nullable;

  30. import io.wcm.devops.conga.plugins.aem.postprocessor.ContentPackagePropertiesPostProcessor;

  31. /**
  32.  * Represents a content package file generated or referenced by CONGA.
  33.  */
  34. public final class ModelContentPackageFile extends AbstractInstallableFile implements ContentPackageFile {

  35.   private final Boolean install;
  36.   private final Boolean force;
  37.   private final Boolean recursive;
  38.   private final Integer delayAfterInstallSec;
  39.   private final Integer httpSocketTimeoutSec;

  40.   private final String name;
  41.   private final String group;
  42.   private final String version;
  43.   private final String packageType;

  44.   /**
  45.    * @param file Content package file
  46.    * @param fileData File data
  47.    * @param variants Variants
  48.    */
  49.   @SuppressWarnings("unchecked")
  50.   public ModelContentPackageFile(File file, Map<String, Object> fileData, List<String> variants) {
  51.     super(file, variants);

  52.     this.install = (Boolean)fileData.get("install");
  53.     this.force = (Boolean)fileData.get("force");
  54.     this.recursive = (Boolean)fileData.get("recursive");
  55.     this.delayAfterInstallSec = (Integer)fileData.get("delayAfterInstallSec");
  56.     this.httpSocketTimeoutSec = (Integer)fileData.get("httpSocketTimeoutSec");

  57.     Map<String, Object> contentPackageProperties = (Map<String, Object>)fileData.get(
  58.         ContentPackagePropertiesPostProcessor.MODEL_OPTIONS_PROPERTY);
  59.     if (contentPackageProperties == null) {
  60.       throw new IllegalArgumentException(ContentPackagePropertiesPostProcessor.MODEL_OPTIONS_PROPERTY + " missing.");
  61.     }
  62.     this.name = Objects.toString(contentPackageProperties.get(NAME_NAME), null);
  63.     this.group = Objects.toString(contentPackageProperties.get(NAME_GROUP), null);
  64.     this.version = Objects.toString(contentPackageProperties.get(NAME_VERSION), null);
  65.     this.packageType = Objects.toString(contentPackageProperties.get(NAME_PACKAGE_TYPE), null);
  66.   }

  67.   public Boolean getInstall() {
  68.     return this.install;
  69.   }

  70.   @Nullable
  71.   public Boolean getForce() {
  72.     return this.force;
  73.   }

  74.   @Nullable
  75.   public Boolean getRecursive() {
  76.     return this.recursive;
  77.   }

  78.   @Nullable
  79.   public Integer getDelayAfterInstallSec() {
  80.     return this.delayAfterInstallSec;
  81.   }

  82.   @Nullable
  83.   public Integer getHttpSocketTimeoutSec() {
  84.     return this.httpSocketTimeoutSec;
  85.   }

  86.   @Override
  87.   public String getName() {
  88.     return this.name;
  89.   }

  90.   @Override
  91.   public String getGroup() {
  92.     return this.group;
  93.   }

  94.   @Override
  95.   public String getVersion() {
  96.     return this.version;
  97.   }

  98.   @Override
  99.   public String getPackageType() {
  100.     return this.packageType;
  101.   }

  102. }