All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.aemds.guide.utils.JSONCreationOptions Maven / Gradle / Ivy

/*
 * **********************************************************************
 *  ADOBE CONFIDENTIAL
 *  __________________
 *
 *  Copyright 2015 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 *  NOTICE:  All information contained herein is, and remains
 *  the property of Adobe Systems Incorporated and its suppliers,
 *  if any.  The intellectual and technical concepts contained
 *  herein are proprietary to Adobe Systems Incorporated and its
 *  suppliers and may be covered by U.S. and Foreign Patents,
 *  patents in process, and are protected by trade secret or copyright law.
 *  Dissemination of this information or reproduction of this material
 *  is strictly forbidden unless prior written permission is obtained
 *  from Adobe Systems Incorporated.
 *  **********************************************************************
 */

package com.adobe.aemds.guide.utils;

import com.adobe.aemds.guide.model.SignerResource;
import com.adobe.aemds.guide.transformer.api.ResourcePropertyTransformer;
import com.day.cq.i18n.I18n;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.mozilla.javascript.Scriptable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * @pad.exclude Exclude from Published API.
 */
public class JSONCreationOptions {

    private Logger logger = LoggerFactory.getLogger(JSONCreationOptions.class);

    private boolean includeJcrPath;
    private I18n i18n;
    private boolean includeFragmentJson;
    private SlingHttpServletRequest request;
    private String dataRef;
    private String pagePath;
    private String formContainerPath;
    /**
     * This is false in case of creating dictionaries and is
     * true when rendering adaptive form.
     */
    private boolean contextNeeded;
    /**
     * Form Resource is guide container resource
     */
    private Resource formResource;

    /**
     * Signer resource, is the 'configure sign' settings for guide container
     * It is direct child of guide container, namely signerInfo
     */
    private SignerResource signerResource;

    /**
     * Prefill service parameter map.
     * This parameter map is extra payload which is made available to the prefill service
     */
    private Map prefillServiceParams;

    /**
     * webChannel variable assignments map
     */
    private Map webVariableAssignments;

    private ResourcePropertyTransformer transformer;
    private String data;

    private Locale locale;

    public Map adobeSignNameIndexMap;
    public Map somMap;

    private Map treeJsonMap = new HashMap<>();
    private Scriptable rulesScriptsScope;

    /**
     * The map used to store bindRef to corresponding AF name. This helps us in finding out the AF field
     * bound to the specific schema specifically to the FDM field.
     */
    private Map bindRefToAFNameMap;

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    public boolean getContextNeeded() {
        return this.contextNeeded;
    }

    private void setSignerResource() {
        if (this.formResource != null) {
            Resource guideContainerResource = this.formResource;
            //check if its page otherwise it is guideContainer resource.
            if (GuideConstants.RT_PAGE.equals(formResource.getResourceType()) ||
                    GuideConstants.RT_PAGE.equals(formResource.getResourceSuperType())) {
                guideContainerResource = formResource.getChild(GuideConstants.JCR_CONTENT_NODENAME + "/" +
                        GuideConstants.GUIDECONTAINER_NODENAME);
            }
            Boolean isAdobeSignEnabled = Boolean.valueOf(guideContainerResource.getValueMap().get(GuideConstants.USE_SIGNED_PDF, ""));
            if (isAdobeSignEnabled) {
                Resource signerInfoResource = guideContainerResource.getChild(GuideConstants.SIGNER_INFO_RESOURCE);
                if (signerInfoResource != null) {
                    this.signerResource = signerInfoResource.adaptTo(SignerResource.class);
                }
            }
        }
    }

    public JSONCreationOptions() {
        this.contextNeeded = false;
    }

    public JSONCreationOptions(I18n i18n, boolean includeJcrPath,
                               boolean includeFragmentJson, Locale locale,
                               Resource formResource) {
        this.includeJcrPath = includeJcrPath;
        this.i18n = i18n;
        this.includeFragmentJson = includeFragmentJson;
        this.locale = locale;
        this.formResource = formResource;
        this.contextNeeded = true;
        this.setSignerResource();
    }

    public void setTransformer(ResourcePropertyTransformer transformer) {
        this.transformer = transformer;
    }

    public JSONCreationOptions setI18n(I18n i18n) {
        this.i18n = i18n;
        return this;
    }

    public I18n getI18n() {
        return i18n;
    }

    public boolean isIncludeJcrPath() {
        return includeJcrPath;
    }

    public boolean isIncludeFragmentJson() {
        return includeFragmentJson;
    }

    public void setIncludeFragmentJson(boolean includeFragmentJson) {
        this.includeFragmentJson = includeFragmentJson;
    }

    public Resource getFormResource() {
        return formResource;
    }

    public void setFormResource(Resource formResource) {
        this.formResource = formResource;
        this.setSignerResource();
    }

    public String getFormResourceProperty(String propertyName) {
        String propertyValue = "";
        if (this.formResource != null) {
            ValueMap resourceProps = ResourceUtil.getValueMap(this.formResource);
            propertyValue = resourceProps.get(propertyName, "");
        }
        return propertyValue;
    }

    public ResourcePropertyTransformer getTransformer() {
        return transformer;
    }

    public String getDataRef() {
        return dataRef;
    }

    public JSONCreationOptions setDataRef(String dataRef) {
        this.dataRef = dataRef;
        return this;
    }

    public String getPagePath() {
        return pagePath;
    }

    public JSONCreationOptions setPagePath(String pagePath) {
        this.pagePath = pagePath;
        return this;
    }

    public Map getBindRefToAFNameMap() {
        return bindRefToAFNameMap;
    }

    public void setBindRefToAFNameMap(Map bindRefToAFNameMap) {
        this.bindRefToAFNameMap = bindRefToAFNameMap;
    }

    public String getFormContainerPath() {
        return formContainerPath;
    }

    public JSONCreationOptions setFormContainerPath(String formContainerPath) {
        this.formContainerPath = formContainerPath;
        return this;
    }

    public String getData() {
        return data;
    }

    public JSONCreationOptions setData(String data) {
        this.data = data;
        return this;
    }

    /**
     * get the rhino scope initialized with objects
     * required to generate scripts from rules
     *
     * @return
     */
    public Scriptable getRulesScriptsScope() {
        return rulesScriptsScope;
    }

    /**
     * Set scope initialized with objects required to generate
     * scripts from rules
     *
     * @param rulesScriptsScope
     * @return
     */
    public JSONCreationOptions setRulesScriptsScope(Scriptable rulesScriptsScope) {
        this.rulesScriptsScope = rulesScriptsScope;
        return this;
    }

    /**
     * Gets the expression editor tree json
     * this is required to initialize expression editor
     * scope/context before generating scripts
     *
     * @return
     */
    public Map getExpTreeJsonMap() {
        return this.treeJsonMap != null ? this.treeJsonMap : new HashMap();
    }

    /**
     * Set the expression editor tree json
     * this is require to initialize expression editor
     * scope/context before generating scripts
     *
     * @param treeJsonMap
     * @return
     */
    public JSONCreationOptions setExpTreeJsonMap(Map treeJsonMap) {
        this.treeJsonMap = treeJsonMap;
        return this;
    }

    /**
     * Gets the guideContainer signer information in form of SignerResource
     *
     * @return SignerResource
     */
    public SignerResource getSignerResource() {
        return this.signerResource;
    }

    /**
     * Gets the index in case adobe sign field has a duplicate name.
     *
     * @param name
     * @return index, in case there is repetition in name
     */
    public Integer getAdobeSignFieldNameIndex(String name) {
        Integer index = null;
        if (adobeSignNameIndexMap == null) {
            adobeSignNameIndexMap = new HashMap();
        }
        if (adobeSignNameIndexMap.containsKey(name)) {
            index = adobeSignNameIndexMap.get(name) + 1;
            // update index of the name
            adobeSignNameIndexMap.put(name, index);
            // add indexed name, to check for duplication too
            adobeSignNameIndexMap.put(name + index, 0);
        } else {
            // add name, to check for duplication
            adobeSignNameIndexMap.put(name, 0);
        }
        return index;
    }

    public Integer getSOMIndex(String som) {
        Integer index = 0;
        if (somMap == null) {
            somMap = new HashMap();
        }
        if (somMap.containsKey(som)) {
            index = somMap.get(som) + 1;
        }
        // update index of the som
        somMap.put(som, index);
        return index;
    }

    public Map getPrefillServiceParams() {
        return prefillServiceParams;
    }

    public void setPrefillServiceParams(Map prefillServiceParams) {
        this.prefillServiceParams = prefillServiceParams;
    }

    public SlingHttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(SlingHttpServletRequest request) {
        this.request = request;
    }

    public Map getWebVariableAssignments() {
        return webVariableAssignments;
    }

    public void setWebVariableAssignments(Map webVariableAssignments) {
        this.webVariableAssignments = webVariableAssignments;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy