Subversion Repositories SmartDukaan

Rev

Rev 2838 | Rev 6520 | 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
    /**
3358 rajveer 99
     * Handles deletion of a special page
2768 mandeep.dh 100
     */
101
    public String destroy() {
3358 rajveer 102
    	long spacialPageID = Long.parseLong(this.getId());
103
    	CreationUtils.deleteSpecialPage(spacialPageID);
2768 mandeep.dh 104
        return "index";
105
    }
106
 
107
    /**
2838 mandeep.dh 108
     * Handles updates done on special page through UI
2768 mandeep.dh 109
     */
110
    public String update() throws Exception {
2838 mandeep.dh 111
        SpecialPage specialPage = CreationUtils.getSpecialPage(Long.parseLong(id));
112
        specialPage.setDisplayName(displayName);
113
        specialPage.setDescription(description);
114
        specialPage.setPrimeURL(primeURL);
115
        specialPage.setSaholicURL(saholicURL);
116
        specialPage.setPageTitle(pageTitle);
117
        specialPage.setMetaDescription(metaDescription);
118
        specialPage.setMetaKeywords(metaKeywords);
119
        specialPage.setSearchQuery(searchQuery);
2768 mandeep.dh 120
 
2838 mandeep.dh 121
        CreationUtils.storeSpecialPage(specialPage);
2768 mandeep.dh 122
        return "index";
123
    }
124
 
125
    public String getSearchQuery(List<String> searchQuery) {
126
        return StringUtils.join(searchQuery, ",");
127
    }
128
 
129
    public String getId() {
130
        return id;
131
    }
132
 
133
    public void setId(String id) {
134
        this.id = id;
135
    }
136
 
137
    public String getDisplayName() {
138
        return displayName;
139
    }
140
 
141
    public void setDisplayName(String displayName) {
142
        this.displayName = displayName;
143
    }
144
 
145
    public String getPrimeURL() {
146
        return primeURL;
147
    }
148
 
149
    public void setPrimeURL(String primeURL) {
150
        this.primeURL = primeURL;
151
    }
152
 
153
    public String getSaholicURL() {
154
        return saholicURL;
155
    }
156
 
157
    public void setSaholicURL(String saholicURL) {
158
        this.saholicURL = saholicURL;
159
    }
160
 
161
    public String getSearchQuery() {
162
        return searchQuery;
163
    }
164
 
165
    public void setSearchQuery(String searchQuery) {
166
        this.searchQuery = searchQuery;
167
    }
168
 
169
    public String getDescription() {
170
        return description;
171
    }
172
 
173
    public void setDescription(String description) {
174
        this.description = description;
175
    }
176
 
177
    public String getPageTitle() {
178
        return pageTitle;
179
    }
180
 
181
    public void setPageTitle(String pageTitle) {
182
        this.pageTitle = pageTitle;
183
    }
184
 
185
    public String getMetaKeywords() {
186
        return metaKeywords;
187
    }
188
 
189
    public void setMetaKeywords(String metaKeywords) {
190
        this.metaKeywords = metaKeywords;
191
    }
192
 
193
    public String getMetaDescription() {
194
        return metaDescription;
195
    }
196
 
197
    public void setMetaDescription(String metaDescription) {
198
        this.metaDescription = metaDescription;
199
    }
200
}