com.gleo.plugins.hexiagon.portlet.countries.action.ActivateCountryMVCActionCommand.java Source code

Java tutorial

Introduction

Here is the source code for com.gleo.plugins.hexiagon.portlet.countries.action.ActivateCountryMVCActionCommand.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.gleo.plugins.hexiagon.portlet.countries.action;

import com.gleo.plugins.hexiagon.constants.PortletKeys;
import com.gleo.plugins.hexiagon.service.ExtCountryServiceUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Country;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.ParamUtil;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.osgi.service.component.annotations.Component;

/**
 * @author guillaumelenoir
 *
 */
@Component(property = { "javax.portlet.name=" + PortletKeys.HEXIAGON_COUNTRY_CONFIGURATION,
        "mvc.command.name=activateCountry" }, service = MVCActionCommand.class)
public class ActivateCountryMVCActionCommand extends BaseMVCActionCommand {

    /**
     * ActivateCountryMVCRenderCommand Logger.
     */
    protected static Log LOGGER = LogFactoryUtil.getLog(ActivateCountryMVCActionCommand.class);

    @Override
    protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
        long countryId = ParamUtil.getLong(actionRequest, "countryId");
        boolean isActive = ParamUtil.getBoolean(actionRequest, "isActive");

        try {
            Country country = ExtCountryServiceUtil.setActive(countryId, !isActive);
            SessionMessages.add(actionRequest, "country-updated-active");
            LOGGER.debug(country);
        } catch (Exception e) {
            LOGGER.error(e);
            SessionErrors.add(actionRequest, "country-error");
        }
    }
}