
com.adobe.aemds.guide.progressive.GuideProgressiveSectionInfo 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.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.json.io.JSONWriter;
import java.io.StringWriter;
import java.util.List;
/**
* Class representing a guide progressive section
*
*/
public class GuideProgressiveSectionInfo {
private String id;
private String title;
private String name;
private List fields;
private String repeatablePanelId;
private Boolean fetchedFromService = true;
private String repeatablePanelPath;
public GuideProgressiveSectionInfo() {
}
//TODO: can this be automated using reflection or jackson
/**
* Converts the given object into JSON
* @return
*/
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_TITLE).value(this.getTitle());
jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_SECTION_NAME).value(this.getName());
List fieldList = this.getFields();
JSONArray fieldJsonArray = new JSONArray();
for (int i =0 ;i < fieldList.size(); i++) {
GuideProgressiveField field = fieldList.get(i);
JSONObject obj = new JSONObject();
obj.put("id", field.getId());
obj.put("path", field.getPath());
obj.put("prefixId", field.getPrefixId());
fieldJsonArray.put(obj);
}
jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_SECTION_FIELDS).value(fieldJsonArray);
jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_REPEATABLE_PANEL_PATH).value(this.getRepeatablePanelPath());
jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_REPEATABLE_PANEL_ID).value(this.getRepeatablePanelId());
jsonWriter.key(GuideConstants.GUIDE_PROGRESSIVE_FETCHED_FROM_SERVICE).value(this.getFetchedFromService());
// this shouldn't break the existing the node class, since we always send it to client, when fetched from server
jsonWriter.key(GuideConstants.GUIDE_NODE_CLASS).value(GuideConstants.GUIDE_PROGRESSIVE_SECTION_NODE_CLASS);
jsonWriter.endObject();
} catch (JSONException ex) {
throw new GuideException(ex.getMessage(), ex);
}
return jsonStringWriter.toString();
}
public GuideProgressiveSectionInfo(String id, String title, String name, List fields, String repeatablePanelPath, String repeatablePanelId) {
this.id = id;
this.title = title;
this.fields = fields;
this.name = name;
this.repeatablePanelPath = repeatablePanelPath;
this.repeatablePanelId = repeatablePanelId;
}
public GuideProgressiveSectionInfo(String id, String title, String name, List fields, String repeatablePanelPath, String repeatablePanelId, Boolean fetchedFromService) {
this(id, title, name, fields, repeatablePanelPath, repeatablePanelId);
this.fetchedFromService = fetchedFromService;
}
public String getFetchedFromService() {
return String.valueOf(fetchedFromService);
}
public String getRepeatablePanelId() {
return repeatablePanelId;
}
public String getRepeatablePanelPath() {
return repeatablePanelPath;
}
/**
* Gets the field present inside progressive section as List of fields
* @return
*/
public List getFields() {
return fields;
}
public void setFields(List fields) {
this.fields = fields;
}
/**
* Returns the ID of the progressive section
* @return
*/
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/**
* Returns the title of the section
* @return
*/
public String getTitle() {
return title;
}
/**
* Returns the name of the progressive section
* Names of section can be changed but ID cannot be changed.
* @return
*/
public String getName(){
return name == null ? this.getId() : name;
}
public void setTitle(String title) {
this.title = title;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy