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

com.adobe.aemds.guide.progressive.GuideProgressiveCompletionInfo Maven / Gradle / Ivy

/************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 * Copyright 2014 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.progressive;

import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.utils.GuideConstants;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;

import javax.annotation.Resource;
import java.io.StringWriter;

public class GuideProgressiveCompletionInfo {
    private String completionTitle;
    private String completionBeforeMessage;
    private String completionAfterMessage;
    private String completionScript;
    private String completionButtonText;
    private String completionFailureScript;
    private String completionSuccessScript;
    private Boolean fetchedFromService = true;

    //every progressive data capture can have only one completion section so one id across instances
    public static final String id = "completion";

    public GuideProgressiveCompletionInfo() {
    }

    //TODO: can this be automated using reflection or jackson
    public String convertToJSON() {
        StringWriter jsonStringWriter = new StringWriter();
        JSONWriter jsonWriter = new JSONWriter(jsonStringWriter);
        try {
            jsonWriter.object();
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_SECTION_ID).value(this.getId());
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_SECTION_NAME).value(this.getName());
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_COMPLETION_BUTTON_TEXT).value(this.getCompletionButtonText());
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_COMPLETION_SCRIPT).value(this.getCompletionScript());
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_COMPLETION_TITLE).value(this.getCompletionTitle());
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_COMPLETION_BEFORE_MESSAGE).value(this.getCompletionBeforeMessage());
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_COMPLETION_AFTER_MESSAGE).value(this.getCompletionAfterMessage());
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_COMPLETION_FAILURE_SCRIPT).value(this.getCompletionFailureScript());
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_COMPLETION_SUCCESS_SCRIPT).value(this.getCompletionSuccessScript());
            // This parameter is used to purely check if it prefill usecase or not
            // todo: There can be a better way, as of now passing this
            jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_FETCHED_FROM_SERVICE).value(this.getFetchedFromService());
            jsonWriter.key(GuideConstants.GUIDE_NODE_CLASS).value(GuideConstants.GUIDE_PROGRESSIVE_COMPLETION_SECTION_NODE_CLASS);
            jsonWriter.endObject();
        } catch (JSONException ex) {
            throw new GuideException(ex.getMessage(), ex);
        }
        return jsonStringWriter.toString();
    }

    public GuideProgressiveCompletionInfo(String completionTitle,
                                          String completionBeforeMessage,
                                          String completionAfterMessage,
                                          String completionScript,
                                          String completionButtonText,
                                          String completionSuccessScript,
                                          String completionFailureScript) {
        this.completionTitle = completionTitle;
        this.completionBeforeMessage = completionBeforeMessage;
        this.completionAfterMessage = completionAfterMessage;
        this.completionScript = completionScript;
        this.completionButtonText = completionButtonText;
        this.completionSuccessScript = completionSuccessScript;
        this.completionFailureScript = completionFailureScript;
    }

    public GuideProgressiveCompletionInfo(String completionTitle,
                                          String completionBeforeMessage,
                                          String completionAfterMessage,
                                          String completionScript,
                                          String completionButtonText,
                                          String completionSuccessScript,
                                          String completionFailureScript,
                                          Boolean fetchedFromService) {
        this(completionTitle, completionBeforeMessage, completionAfterMessage, completionScript,completionButtonText,completionSuccessScript,completionFailureScript);
        this.fetchedFromService =  fetchedFromService;
    }

    public String getFetchedFromService() {
        return String.valueOf(fetchedFromService);
    }

    public String getCompletionBeforeMessage() {
        return completionBeforeMessage;
    }

    public void setCompletionBeforeMessage(String completionBeforeMessage) {
        this.completionBeforeMessage = completionBeforeMessage;
    }

    public String getCompletionFailureScript() {
        return completionFailureScript;
    }

    public void setCompletionFailureScript(String completionFailureScript) {
        this.completionFailureScript = completionFailureScript;
    }

    public String getCompletionSuccessScript() {
        return completionSuccessScript;
    }

    public void setCompletionSuccessScript(String completionSuccessFunction) {
        this.completionSuccessScript= completionSuccessFunction;
    }

    public String getCompletionAfterMessage() {
        return completionAfterMessage;
    }

    public void setCompletionAfterMessage(String completionAfterMessage) {
        this.completionAfterMessage = completionAfterMessage;
    }

    public String getCompletionTitle() {
        return completionTitle;
    }

    public void setCompletionTitle(String completionTitle) {
        this.completionTitle = completionTitle;
    }

    public String getCompletionScript() {
        return completionScript;
    }

    public void setCompletionScript(String completionScript) {
        this.completionScript = completionScript;
    }

    public String getCompletionButtonText() {
        return completionButtonText;
    }

    public void setCompletionButtonText(String completionButtonText) {
        this.completionButtonText = completionButtonText;
    }

    public String getId() {
        return GuideProgressiveCompletionInfo.id;
    }

    public String getName() {
        return GuideProgressiveCompletionInfo.id;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy