com.epam.training.storefront.controllers.pages.OrganizationsController.java Source code

Java tutorial

Introduction

Here is the source code for com.epam.training.storefront.controllers.pages.OrganizationsController.java

Source

/*
 * [y] hybris Platform
 *
 * Copyright (c) 2000-2015 hybris AG
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of hybris
 * ("Confidential Information"). You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the
 * license agreement you entered into with hybris.
 * 
 *  
 */
package com.epam.training.storefront.controllers.pages;

import com.epam.training.core.data.OrganizationData;
import com.epam.training.core.facades.OrganizationFacade;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class OrganizationsController extends AbstractPageController {

    private OrganizationFacade organizationFacade;

    private static final String ORGANIZATION_DETAILS = "pages/organizations/organizationDetails";
    private static final String ORGANIZATION_LISTING = "pages/organizations/organizationListing";

    @RequestMapping(value = "/organizations", method = RequestMethod.GET)
    public String showOrganizations(final Model model) {
        final List<OrganizationData> organizations = organizationFacade.getOrganizations("organizationListFormat");
        model.addAttribute("organizations", organizations);
        return ORGANIZATION_LISTING;
    }

    @RequestMapping(value = "/organizations/{organizationName}", method = RequestMethod.GET)
    public String showOrganizationDetails(@PathVariable String organizationName, final Model model)
            throws UnsupportedEncodingException {
        organizationName = URLDecoder.decode(organizationName, "UTF-8");
        final OrganizationData organization = organizationFacade.getOrganization(organizationName,
                "organizationDetailsFormat");
        organization.setName(organization.getName());
        model.addAttribute("organization", organization);
        return ORGANIZATION_DETAILS;
    }

    @Autowired
    public void setFacade(final OrganizationFacade facade) {
        this.organizationFacade = facade;
    }

}