Subversion Repositories SmartDukaan

Rev

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

package in.shop2020.creation.controllers;

import in.shop2020.metamodel.core.Brand;
import in.shop2020.metamodel.util.CreationUtils;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

/**
 * Action class for brand page in CMS. Delete operation is not supported.
 *
 * @author mandeep
 */
@InterceptorRefs({ @InterceptorRef("myDefault"), @InterceptorRef("login") })
@Results({
        @Result(name = "success", type = "redirectAction", params = {
                "actionName", "brand" }),
        @Result(name = "redirect", location = "${url}", type = "redirect") })
public class BrandController extends BaseController {
    private static final long serialVersionUID = 1L;
    private static Log        log              = LogFactory.getLog(BrandController.class);

    // Brand attributes set by Struts2
    private String            id;
    private String            displayName;
    private String            description;
    private String            primeURL;
    private String            saholicURL;
    private String            searchQuery;
    private String            pageTitle;
    private String            metaKeywords;
    private String            metaDescription;

    // Index page
    public String index() {
        return "index";
    }

    // Display page for a single brand
    public String show() {
        return "show";
    }

    /**
     * Handles creation of a new brand
     */
    public String create() throws Exception {
        long id = CreationUtils.getNewBrandId();
        if (displayName == null) {
            addActionError("Display Name cannot be empty");
            return "index";
        }

        Brand brand = new Brand(id, displayName);
        brand.setDescription(description);
        brand.setPrimeURL(primeURL);
        brand.setSaholicURL(saholicURL);
        brand.setPageTitle(pageTitle);
        brand.setMetaDescription(metaDescription);
        brand.setMetaKeywords(metaKeywords);
        brand.setSearchQuery(searchQuery);

        log.info(brand);
        CreationUtils.storeBrand(brand);
        return "index";
    }

    /**
     * Used in index view to display all brands
     */
    public Map<Long, Brand> getBrands() throws Exception {
        return CreationUtils.getBrands();
    }

    /**
     * Used in UI to display other attributes given brand Id
     */
    public Brand getBrand() throws Exception {
        return CreationUtils.getBrand(Long.parseLong(id));
    }

    public String edit() {
        return "edit";
    }

    public String editNew() {
        return "editNew";
    }

    /**
     * Delete is not supported yet. Index is refreshed on its call
     */
    public String destroy() {
        return "index";
    }

    /**
     * Handles updates done on brand through UI
     */
    public String update() throws Exception {
        Brand brand = CreationUtils.getBrand(Long.parseLong(id));
        brand.setDisplayName(displayName);
        brand.setDescription(description);
        brand.setPrimeURL(primeURL);
        brand.setSaholicURL(saholicURL);
        brand.setPageTitle(pageTitle);
        brand.setMetaDescription(metaDescription);
        brand.setMetaKeywords(metaKeywords);
        brand.setSearchQuery(searchQuery);

        CreationUtils.storeBrand(brand);
        return "index";
    }

    public String getSearchQuery(List<String> searchQuery) {
        return StringUtils.join(searchQuery, ",");
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public String getPrimeURL() {
        return primeURL;
    }

    public void setPrimeURL(String primeURL) {
        this.primeURL = primeURL;
    }

    public String getSaholicURL() {
        return saholicURL;
    }

    public void setSaholicURL(String saholicURL) {
        this.saholicURL = saholicURL;
    }

    public String getSearchQuery() {
        return searchQuery;
    }

    public void setSearchQuery(String searchQuery) {
        this.searchQuery = searchQuery;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getPageTitle() {
        return pageTitle;
    }

    public void setPageTitle(String pageTitle) {
        this.pageTitle = pageTitle;
    }

    public String getMetaKeywords() {
        return metaKeywords;
    }

    public void setMetaKeywords(String metaKeywords) {
        this.metaKeywords = metaKeywords;
    }

    public String getMetaDescription() {
        return metaDescription;
    }

    public void setMetaDescription(String metaDescription) {
        this.metaDescription = metaDescription;
    }
}