jp.primecloud.auto.ui.data.ComponentParameterContainer.java Source code

Java tutorial

Introduction

Here is the source code for jp.primecloud.auto.ui.data.ComponentParameterContainer.java

Source

/*
 * Copyright 2014 by SCSK Corporation.
 * 
 * This file is part of PrimeCloud Controller(TM).
 * 
 * PrimeCloud Controller(TM) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 * 
 * PrimeCloud Controller(TM) 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with PrimeCloud Controller(TM). If not, see <http://www.gnu.org/licenses/>.
 */
package jp.primecloud.auto.ui.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;

import jp.primecloud.auto.component.apache.ApacheConstants;
import jp.primecloud.auto.component.geronimo.GeronimoConstants;
import jp.primecloud.auto.component.mysql.MySQLConstants;
import jp.primecloud.auto.component.prjserver.PrjserverConstants;
import jp.primecloud.auto.component.tomcat.TomcatConstants;
import jp.primecloud.auto.entity.crud.ComponentConfig;
import jp.primecloud.auto.entity.crud.ComponentType;
import jp.primecloud.auto.entity.crud.InstanceConfig;
import jp.primecloud.auto.process.ComponentConstants;
import jp.primecloud.auto.service.dto.ComponentDto;
import jp.primecloud.auto.service.dto.InstanceDto;
import jp.primecloud.auto.ui.util.ViewProperties;
import com.vaadin.data.util.BeanItemContainer;

/**
 * <p>
 * TODO: 
 * </p>
 *
 */
@SuppressWarnings("serial")
public class ComponentParameterContainer extends BeanItemContainer<ComponentParameter> implements Serializable {

    /**
     * Natural property order for Farm bean. Used in tables and forms.
     */
    public static final Object[] NATURAL_COL_ORDER = new Object[] { "kind", "name", "value" };

    /**
     * "Human readable" captions for properties in same order as in
     * NATURAL_COL_ORDER.
     */
    public static final String[] COL_HEADERS_ENGLISH = new String[] { "kind", "name", "value" };

    public ComponentParameterContainer(ComponentDto componentDto, Collection<InstanceDto> instanceDtos) {
        super(ComponentParameter.class);

        ComponentType componentType = componentDto.getComponentType();

        List<ComponentParameter> parameters = new ArrayList<ComponentParameter>();

        // 
        String diskSize = null;
        for (ComponentConfig config : componentDto.getComponentConfigs()) {
            if (ComponentConstants.CONFIG_NAME_DISK_SIZE.equals(config.getConfigName())) {
                diskSize = config.getConfigValue();
            }
        }
        if (StringUtils.isNotEmpty(diskSize)) {
            String mountPoint = null;
            if (MySQLConstants.COMPONENT_TYPE_NAME.equals(componentType.getComponentTypeName())) {
                mountPoint = "/mnt/db";
            } else if (TomcatConstants.COMPONENT_TYPE_NAME.equals(componentType.getComponentTypeName())) {
                mountPoint = "/mnt/ap";
            } else if (GeronimoConstants.COMPONENT_TYPE_NAME.equals(componentType.getComponentTypeName())) {
                mountPoint = "/mnt/ap";
            } else if (ApacheConstants.COMPONENT_TYPE_NAME.equals(componentType.getComponentTypeName())) {
                mountPoint = "/mnt/web";
            } else if (PrjserverConstants.COMPONENT_TYPE_NAME.equals(componentType.getComponentTypeName())) {
                mountPoint = "/mnt/data01";
            }

            String captionDisk = ViewProperties.getCaption("param.disk");
            parameters.add(new ComponentParameter(captionDisk, ViewProperties.getCaption("param.disk.size"),
                    diskSize + ViewProperties.getCaption("param.disk.gb")));
            parameters.add(new ComponentParameter(captionDisk, ViewProperties.getCaption("param.disk.mountpoint"),
                    mountPoint));
        }

        // MySQL
        if (MySQLConstants.COMPONENT_TYPE_NAME.equals(componentType.getComponentTypeName())) {
            // Master
            Long masterInstanceNo = null;
            for (InstanceConfig config : componentDto.getInstanceConfigs()) {
                if (MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO.equals(config.getConfigName())) {
                    if (StringUtils.isEmpty(config.getConfigValue())) {
                        masterInstanceNo = config.getInstanceNo();
                        break;
                    }
                }
            }
            InstanceDto masterInstance = null;
            if (masterInstanceNo != null) {
                for (InstanceDto instance : instanceDtos) {
                    if (masterInstanceNo.equals(instance.getInstance().getInstanceNo())) {
                        masterInstance = instance;
                        break;
                    }
                }
            }
            String master = masterInstance != null ? masterInstance.getInstance().getFqdn() : "";
            String captionMysql = ViewProperties.getCaption("param.mysql");
            parameters.add(
                    new ComponentParameter(captionMysql, ViewProperties.getCaption("param.mysql.master"), master));

            // phpMyAdmin
            boolean phpMyAdmin = false;
            for (ComponentConfig config : componentDto.getComponentConfigs()) {
                if (MySQLConstants.CONFIG_NAME_PHP_MY_ADMIN.equals(config.getConfigName())) {
                    phpMyAdmin = BooleanUtils.toBoolean(config.getConfigValue());
                }
            }
            String usePhpMyAdmin = phpMyAdmin ? ViewProperties.getCaption("param.phpmyadmin.enable")
                    : ViewProperties.getCaption("param.phpmyadmin.disable");
            parameters.add(new ComponentParameter(captionMysql, ViewProperties.getCaption("param.phpmyadmin"),
                    usePhpMyAdmin));
        }

        for (ComponentParameter parameter : parameters) {
            addItem(parameter);
        }
    }

}