Subversion Repositories SmartDukaan

Rev

Rev 2768 | Rev 3358 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2768 Rev 2838
Line 1... Line 1...
1
package in.shop2020.creation.controllers;
1
package in.shop2020.creation.controllers;
2
 
2
 
3
import in.shop2020.metamodel.core.Brand;
3
import in.shop2020.metamodel.core.SpecialPage;
4
import in.shop2020.metamodel.util.CreationUtils;
4
import in.shop2020.metamodel.util.CreationUtils;
5
 
5
 
6
import java.util.List;
6
import java.util.List;
7
import java.util.Map;
7
import java.util.Map;
8
 
8
 
Line 13... Line 13...
13
import org.apache.struts2.convention.annotation.InterceptorRefs;
13
import org.apache.struts2.convention.annotation.InterceptorRefs;
14
import org.apache.struts2.convention.annotation.Result;
14
import org.apache.struts2.convention.annotation.Result;
15
import org.apache.struts2.convention.annotation.Results;
15
import org.apache.struts2.convention.annotation.Results;
16
 
16
 
17
/**
17
/**
18
 * Action class for brand page in CMS. Delete operation is not supported.
18
 * Action class for special page in CMS. Delete operation is not supported.
19
 *
19
 *
20
 * @author mandeep
20
 * @author mandeep
21
 */
21
 */
22
@InterceptorRefs({ @InterceptorRef("myDefault"), @InterceptorRef("login") })
22
@InterceptorRefs({ @InterceptorRef("myDefault"), @InterceptorRef("login") })
23
@Results({
23
@Results({
24
        @Result(name = "success", type = "redirectAction", params = {
24
        @Result(name = "success", type = "redirectAction", params = {
25
                "actionName", "brand" }),
25
                "actionName", "special-page" }),
26
        @Result(name = "redirect", location = "${url}", type = "redirect") })
26
        @Result(name = "redirect", location = "${url}", type = "redirect") })
27
public class BrandController extends BaseController {
27
public class SpecialPageController extends BaseController {
28
    private static final long serialVersionUID = 1L;
28
    private static final long serialVersionUID = 1L;
29
    private static Log        log              = LogFactory.getLog(BrandController.class);
29
    private static Log        log              = LogFactory.getLog(SpecialPageController.class);
30
 
30
 
31
    // Brand attributes set by Struts2
31
    // Special page attributes set by Struts2
32
    private String            id;
32
    private String            id;
33
    private String            displayName;
33
    private String            displayName;
34
    private String            description;
34
    private String            description;
35
    private String            primeURL;
35
    private String            primeURL;
36
    private String            saholicURL;
36
    private String            saholicURL;
Line 42... Line 42...
42
    // Index page
42
    // Index page
43
    public String index() {
43
    public String index() {
44
        return "index";
44
        return "index";
45
    }
45
    }
46
 
46
 
47
    // Display page for a single brand
47
    // Display page for a single specialPage
48
    public String show() {
48
    public String show() {
49
        return "show";
49
        return "show";
50
    }
50
    }
51
 
51
 
52
    /**
52
    /**
53
     * Handles creation of a new brand
53
     * Handles creation of a new special page
54
     */
54
     */
55
    public String create() throws Exception {
55
    public String create() throws Exception {
56
        long id = CreationUtils.getNewBrandId();
56
        long id = CreationUtils.getNewSpecialPageId();
57
        if (displayName == null) {
57
        if (displayName == null) {
58
            addActionError("Display Name cannot be empty");
58
            addActionError("Display Name cannot be empty");
59
            return "index";
59
            return "index";
60
        }
60
        }
61
 
61
 
62
        Brand brand = new Brand(id, displayName);
62
        SpecialPage specialPage = new SpecialPage(id, displayName);
63
        brand.setDescription(description);
63
        specialPage.setDescription(description);
64
        brand.setPrimeURL(primeURL);
64
        specialPage.setPrimeURL(primeURL);
65
        brand.setSaholicURL(saholicURL);
65
        specialPage.setSaholicURL(saholicURL);
66
        brand.setPageTitle(pageTitle);
66
        specialPage.setPageTitle(pageTitle);
67
        brand.setMetaDescription(metaDescription);
67
        specialPage.setMetaDescription(metaDescription);
68
        brand.setMetaKeywords(metaKeywords);
68
        specialPage.setMetaKeywords(metaKeywords);
69
        brand.setSearchQuery(searchQuery);
69
        specialPage.setSearchQuery(searchQuery);
70
 
70
 
71
        log.info(brand);
71
        log.info(specialPage);
72
        CreationUtils.storeBrand(brand);
72
        CreationUtils.storeSpecialPage(specialPage);
73
        return "index";
73
        return "index";
74
    }
74
    }
75
 
75
 
76
    /**
76
    /**
77
     * Used in index view to display all brands
77
     * Used in index view to display all special pages
78
     */
78
     */
79
    public Map<Long, Brand> getBrands() throws Exception {
79
    public Map<Long, SpecialPage> getSpecialPages() throws Exception {
80
        return CreationUtils.getBrands();
80
        return CreationUtils.getSpecialPages();
81
    }
81
    }
82
 
82
 
83
    /**
83
    /**
84
     * Used in UI to display other attributes given brand Id
84
     * Used in UI to display other attributes given special page Id
85
     */
85
     */
86
    public Brand getBrand() throws Exception {
86
    public SpecialPage getSpecialPage() throws Exception {
87
        return CreationUtils.getBrand(Long.parseLong(id));
87
        return CreationUtils.getSpecialPage(Long.parseLong(id));
88
    }
88
    }
89
 
89
 
90
    public String edit() {
90
    public String edit() {
91
        return "edit";
91
        return "edit";
92
    }
92
    }
Line 101... Line 101...
101
    public String destroy() {
101
    public String destroy() {
102
        return "index";
102
        return "index";
103
    }
103
    }
104
 
104
 
105
    /**
105
    /**
106
     * Handles updates done on brand through UI
106
     * Handles updates done on special page through UI
107
     */
107
     */
108
    public String update() throws Exception {
108
    public String update() throws Exception {
109
        Brand brand = CreationUtils.getBrand(Long.parseLong(id));
109
        SpecialPage specialPage = CreationUtils.getSpecialPage(Long.parseLong(id));
110
        brand.setDisplayName(displayName);
110
        specialPage.setDisplayName(displayName);
111
        brand.setDescription(description);
111
        specialPage.setDescription(description);
112
        brand.setPrimeURL(primeURL);
112
        specialPage.setPrimeURL(primeURL);
113
        brand.setSaholicURL(saholicURL);
113
        specialPage.setSaholicURL(saholicURL);
114
        brand.setPageTitle(pageTitle);
114
        specialPage.setPageTitle(pageTitle);
115
        brand.setMetaDescription(metaDescription);
115
        specialPage.setMetaDescription(metaDescription);
116
        brand.setMetaKeywords(metaKeywords);
116
        specialPage.setMetaKeywords(metaKeywords);
117
        brand.setSearchQuery(searchQuery);
117
        specialPage.setSearchQuery(searchQuery);
118
 
118
 
119
        CreationUtils.storeBrand(brand);
119
        CreationUtils.storeSpecialPage(specialPage);
120
        return "index";
120
        return "index";
121
    }
121
    }
122
 
122
 
123
    public String getSearchQuery(List<String> searchQuery) {
123
    public String getSearchQuery(List<String> searchQuery) {
124
        return StringUtils.join(searchQuery, ",");
124
        return StringUtils.join(searchQuery, ",");