Subversion Repositories SmartDukaan

Rev

Rev 3358 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2768 mandeep.dh 1
package in.shop2020.creation.controllers;
2
 
2838 mandeep.dh 3
import in.shop2020.metamodel.core.SpecialPage;
2768 mandeep.dh 4
import in.shop2020.metamodel.util.CreationUtils;
5
 
6
import java.util.List;
7
import java.util.Map;
8
 
9
import org.apache.commons.lang.StringUtils;
10
import org.apache.juli.logging.Log;
11
import org.apache.juli.logging.LogFactory;
12
import org.apache.struts2.convention.annotation.InterceptorRef;
13
import org.apache.struts2.convention.annotation.InterceptorRefs;
14
import org.apache.struts2.convention.annotation.Result;
15
import org.apache.struts2.convention.annotation.Results;
16
 
17
/**
2838 mandeep.dh 18
 * Action class for special page in CMS. Delete operation is not supported.
2768 mandeep.dh 19
 *
20
 * @author mandeep
21
 */
22
@InterceptorRefs({ @InterceptorRef("myDefault"), @InterceptorRef("login") })
23
@Results({
24
        @Result(name = "success", type = "redirectAction", params = {
2838 mandeep.dh 25
                "actionName", "special-page" }),
2768 mandeep.dh 26
        @Result(name = "redirect", location = "${url}", type = "redirect") })
2838 mandeep.dh 27
public class SpecialPageController extends BaseController {
2768 mandeep.dh 28
    private static final long serialVersionUID = 1L;
2838 mandeep.dh 29
    private static Log        log              = LogFactory.getLog(SpecialPageController.class);
2768 mandeep.dh 30
 
2838 mandeep.dh 31
    // Special page attributes set by Struts2
2768 mandeep.dh 32
    private String            id;
33
    private String            displayName;
34
    private String            description;
35
    private String            primeURL;
6520 amit.gupta 36
    private Long 			   pageType;//Solr Search 0, Tag Search 1
2768 mandeep.dh 37
    private String            saholicURL;
38
    private String            searchQuery;
39
    private String            pageTitle;
40
    private String            metaKeywords;
41
    private String            metaDescription;
42
 
43
    // Index page
44
    public String index() {
45
        return "index";
46
    }
47
 
2838 mandeep.dh 48
    // Display page for a single specialPage
2768 mandeep.dh 49
    public String show() {
50
        return "show";
51
    }
52
 
53
    /**
2838 mandeep.dh 54
     * Handles creation of a new special page
2768 mandeep.dh 55
     */
56
    public String create() throws Exception {
2838 mandeep.dh 57
        long id = CreationUtils.getNewSpecialPageId();
2768 mandeep.dh 58
        if (displayName == null) {
59
            addActionError("Display Name cannot be empty");
60
            return "index";
61
        }
62
 
2838 mandeep.dh 63
        SpecialPage specialPage = new SpecialPage(id, displayName);
64
        specialPage.setDescription(description);
65
        specialPage.setPrimeURL(primeURL);
66
        specialPage.setSaholicURL(saholicURL);
67
        specialPage.setPageTitle(pageTitle);
68
        specialPage.setMetaDescription(metaDescription);
69
        specialPage.setMetaKeywords(metaKeywords);
70
        specialPage.setSearchQuery(searchQuery);
6520 amit.gupta 71
        specialPage.setPageType(pageType);
2768 mandeep.dh 72
 
2838 mandeep.dh 73
        log.info(specialPage);
74
        CreationUtils.storeSpecialPage(specialPage);
2768 mandeep.dh 75
        return "index";
76
    }
77
 
78
    /**
2838 mandeep.dh 79
     * Used in index view to display all special pages
2768 mandeep.dh 80
     */
2838 mandeep.dh 81
    public Map<Long, SpecialPage> getSpecialPages() throws Exception {
82
        return CreationUtils.getSpecialPages();
2768 mandeep.dh 83
    }
84
 
85
    /**
2838 mandeep.dh 86
     * Used in UI to display other attributes given special page Id
2768 mandeep.dh 87
     */
2838 mandeep.dh 88
    public SpecialPage getSpecialPage() throws Exception {
89
        return CreationUtils.getSpecialPage(Long.parseLong(id));
2768 mandeep.dh 90
    }
91
 
92
    public String edit() {
93
        return "edit";
94
    }
95
 
96
    public String editNew() {
97
        return "editNew";
98
    }
99
 
100
    /**
3358 rajveer 101
     * Handles deletion of a special page
2768 mandeep.dh 102
     */
103
    public String destroy() {
3358 rajveer 104
    	long spacialPageID = Long.parseLong(this.getId());
105
    	CreationUtils.deleteSpecialPage(spacialPageID);
2768 mandeep.dh 106
        return "index";
107
    }
108
 
109
    /**
2838 mandeep.dh 110
     * Handles updates done on special page through UI
2768 mandeep.dh 111
     */
112
    public String update() throws Exception {
2838 mandeep.dh 113
        SpecialPage specialPage = CreationUtils.getSpecialPage(Long.parseLong(id));
114
        specialPage.setDisplayName(displayName);
115
        specialPage.setDescription(description);
116
        specialPage.setPrimeURL(primeURL);
117
        specialPage.setSaholicURL(saholicURL);
118
        specialPage.setPageTitle(pageTitle);
119
        specialPage.setMetaDescription(metaDescription);
120
        specialPage.setMetaKeywords(metaKeywords);
121
        specialPage.setSearchQuery(searchQuery);
2768 mandeep.dh 122
 
2838 mandeep.dh 123
        CreationUtils.storeSpecialPage(specialPage);
2768 mandeep.dh 124
        return "index";
125
    }
126
 
127
    public String getSearchQuery(List<String> searchQuery) {
128
        return StringUtils.join(searchQuery, ",");
129
    }
130
 
131
    public String getId() {
132
        return id;
133
    }
134
 
135
    public void setId(String id) {
136
        this.id = id;
137
    }
138
 
139
    public String getDisplayName() {
140
        return displayName;
141
    }
142
 
143
    public void setDisplayName(String displayName) {
144
        this.displayName = displayName;
145
    }
146
 
147
    public String getPrimeURL() {
148
        return primeURL;
149
    }
150
 
151
    public void setPrimeURL(String primeURL) {
152
        this.primeURL = primeURL;
153
    }
154
 
155
    public String getSaholicURL() {
156
        return saholicURL;
157
    }
158
 
159
    public void setSaholicURL(String saholicURL) {
160
        this.saholicURL = saholicURL;
161
    }
162
 
163
    public String getSearchQuery() {
164
        return searchQuery;
165
    }
166
 
167
    public void setSearchQuery(String searchQuery) {
168
        this.searchQuery = searchQuery;
169
    }
170
 
171
    public String getDescription() {
172
        return description;
173
    }
174
 
175
    public void setDescription(String description) {
176
        this.description = description;
177
    }
178
 
179
    public String getPageTitle() {
180
        return pageTitle;
181
    }
182
 
183
    public void setPageTitle(String pageTitle) {
184
        this.pageTitle = pageTitle;
185
    }
186
 
187
    public String getMetaKeywords() {
188
        return metaKeywords;
189
    }
190
 
191
    public void setMetaKeywords(String metaKeywords) {
192
        this.metaKeywords = metaKeywords;
193
    }
194
 
195
    public String getMetaDescription() {
196
        return metaDescription;
197
    }
198
 
199
    public void setMetaDescription(String metaDescription) {
200
        this.metaDescription = metaDescription;
201
    }
6520 amit.gupta 202
 
203
	public void setPageType(Long pageType) {
204
		this.pageType = pageType;
205
	}
206
 
207
	public Long getPageType() {
208
		return pageType;
209
	}
2768 mandeep.dh 210
}