Subversion Repositories SmartDukaan

Rev

Rev 2768 | 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;
36
    private String            saholicURL;
37
    private String            searchQuery;
38
    private String            pageTitle;
39
    private String            metaKeywords;
40
    private String            metaDescription;
41
 
42
    // Index page
43
    public String index() {
44
        return "index";
45
    }
46
 
2838 mandeep.dh 47
    // Display page for a single specialPage
2768 mandeep.dh 48
    public String show() {
49
        return "show";
50
    }
51
 
52
    /**
2838 mandeep.dh 53
     * Handles creation of a new special page
2768 mandeep.dh 54
     */
55
    public String create() throws Exception {
2838 mandeep.dh 56
        long id = CreationUtils.getNewSpecialPageId();
2768 mandeep.dh 57
        if (displayName == null) {
58
            addActionError("Display Name cannot be empty");
59
            return "index";
60
        }
61
 
2838 mandeep.dh 62
        SpecialPage specialPage = new SpecialPage(id, displayName);
63
        specialPage.setDescription(description);
64
        specialPage.setPrimeURL(primeURL);
65
        specialPage.setSaholicURL(saholicURL);
66
        specialPage.setPageTitle(pageTitle);
67
        specialPage.setMetaDescription(metaDescription);
68
        specialPage.setMetaKeywords(metaKeywords);
69
        specialPage.setSearchQuery(searchQuery);
2768 mandeep.dh 70
 
2838 mandeep.dh 71
        log.info(specialPage);
72
        CreationUtils.storeSpecialPage(specialPage);
2768 mandeep.dh 73
        return "index";
74
    }
75
 
76
    /**
2838 mandeep.dh 77
     * Used in index view to display all special pages
2768 mandeep.dh 78
     */
2838 mandeep.dh 79
    public Map<Long, SpecialPage> getSpecialPages() throws Exception {
80
        return CreationUtils.getSpecialPages();
2768 mandeep.dh 81
    }
82
 
83
    /**
2838 mandeep.dh 84
     * Used in UI to display other attributes given special page Id
2768 mandeep.dh 85
     */
2838 mandeep.dh 86
    public SpecialPage getSpecialPage() throws Exception {
87
        return CreationUtils.getSpecialPage(Long.parseLong(id));
2768 mandeep.dh 88
    }
89
 
90
    public String edit() {
91
        return "edit";
92
    }
93
 
94
    public String editNew() {
95
        return "editNew";
96
    }
97
 
98
    /**
99
     * Delete is not supported yet. Index is refreshed on its call
100
     */
101
    public String destroy() {
102
        return "index";
103
    }
104
 
105
    /**
2838 mandeep.dh 106
     * Handles updates done on special page through UI
2768 mandeep.dh 107
     */
108
    public String update() throws Exception {
2838 mandeep.dh 109
        SpecialPage specialPage = CreationUtils.getSpecialPage(Long.parseLong(id));
110
        specialPage.setDisplayName(displayName);
111
        specialPage.setDescription(description);
112
        specialPage.setPrimeURL(primeURL);
113
        specialPage.setSaholicURL(saholicURL);
114
        specialPage.setPageTitle(pageTitle);
115
        specialPage.setMetaDescription(metaDescription);
116
        specialPage.setMetaKeywords(metaKeywords);
117
        specialPage.setSearchQuery(searchQuery);
2768 mandeep.dh 118
 
2838 mandeep.dh 119
        CreationUtils.storeSpecialPage(specialPage);
2768 mandeep.dh 120
        return "index";
121
    }
122
 
123
    public String getSearchQuery(List<String> searchQuery) {
124
        return StringUtils.join(searchQuery, ",");
125
    }
126
 
127
    public String getId() {
128
        return id;
129
    }
130
 
131
    public void setId(String id) {
132
        this.id = id;
133
    }
134
 
135
    public String getDisplayName() {
136
        return displayName;
137
    }
138
 
139
    public void setDisplayName(String displayName) {
140
        this.displayName = displayName;
141
    }
142
 
143
    public String getPrimeURL() {
144
        return primeURL;
145
    }
146
 
147
    public void setPrimeURL(String primeURL) {
148
        this.primeURL = primeURL;
149
    }
150
 
151
    public String getSaholicURL() {
152
        return saholicURL;
153
    }
154
 
155
    public void setSaholicURL(String saholicURL) {
156
        this.saholicURL = saholicURL;
157
    }
158
 
159
    public String getSearchQuery() {
160
        return searchQuery;
161
    }
162
 
163
    public void setSearchQuery(String searchQuery) {
164
        this.searchQuery = searchQuery;
165
    }
166
 
167
    public String getDescription() {
168
        return description;
169
    }
170
 
171
    public void setDescription(String description) {
172
        this.description = description;
173
    }
174
 
175
    public String getPageTitle() {
176
        return pageTitle;
177
    }
178
 
179
    public void setPageTitle(String pageTitle) {
180
        this.pageTitle = pageTitle;
181
    }
182
 
183
    public String getMetaKeywords() {
184
        return metaKeywords;
185
    }
186
 
187
    public void setMetaKeywords(String metaKeywords) {
188
        this.metaKeywords = metaKeywords;
189
    }
190
 
191
    public String getMetaDescription() {
192
        return metaDescription;
193
    }
194
 
195
    public void setMetaDescription(String metaDescription) {
196
        this.metaDescription = metaDescription;
197
    }
198
}