/*
* Embedded Jopr Project
* Copyright (C) 2006-2009 Red Hat, Inc.
* All rights reserved.
*
* This program 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 program 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.jboss.on.embedded.ui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementData;
import org.rhq.core.domain.measurement.MeasurementDefinition;
import org.rhq.core.domain.resource.ResourceType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.on.embedded.bean.MeasurementDisplay;
import org.jboss.on.embedded.bean.MeasurementUtils;
import org.jboss.on.embedded.bean.ResourceListItem;
/**
* Retrieves all the data for the Metric tab
*
* @author Jessica Sant
*/
@Name("metricAction")
public class MetricAction
{
@In
private transient FacesMessages facesMessages;
/**
* the resource being displayed on the metric tab
*/
@Out(required = false)
private ResourceListItem resource;
/**
* this resource's resource type
*/
@Out(required = false)
private ResourceType resourceType;
/**
* map of measurement definition names to the actual measurement definition
*/
@Out(required = false)
private Map<String, MeasurementDefinition> measurementDefinitionMap;
/**
* a list of all categories that have measurements
*/
@Out(required = false)
private List<String> measurementCategoryList;
/**
* map of measurement categories to MeasurementDisplay objects
*/
@Out(required = false)
private Map<String, List<MeasurementDisplay>> measurementDisplayMap;
/**
* list of all traits for this resource
*/
@Out(required = false)
private List<Map<String, MeasurementDisplay>> traitDisplayList;
@In(create = true)
private CommonActionUtil commonActionUtil;
/**
* the list of all the tabs that will be disabled on the page
*/
@Out(required = false)
private List<String> disabledTabs;
public String view()
{
resource = commonActionUtil.getCurrentResourceListItem();
resourceType = resource.getResource().getResourceType();
measurementDisplayMap = new HashMap<String, List<MeasurementDisplay>>();
MeasurementUtils measurementUtils = new MeasurementUtils(resource);
measurementDefinitionMap = measurementUtils.getMeasurementDefinitionMap();
List<MeasurementData> measurementDataList = measurementUtils.loadMeasurementData(null, DataType.MEASUREMENT);
measurementCategoryList = measurementUtils.loadCategoryList(measurementDefinitionMap,
measurementDataList, measurementDisplayMap);
List<MeasurementData> traitDataList = measurementUtils.loadMeasurementData(null, DataType.TRAIT);
if (traitDataList != null)
{
traitDisplayList = new ArrayList<Map<String, MeasurementDisplay>>();
String[] columnNames = new String[]{"a", "b"};
int columnCount = 0;
Map<String, MeasurementDisplay> currentMap = new HashMap<String, MeasurementDisplay>();
// split all the traits into 3 columns so it can be displayed correctly in the UI
for (MeasurementData traitData : traitDataList)
{
if (columnCount % columnNames.length == 0)
{
currentMap = new HashMap<String, MeasurementDisplay>();
traitDisplayList.add(currentMap);
}
currentMap.put(columnNames[columnCount % columnNames.length],
measurementUtils.createMeasurementDisplay(traitData, measurementDefinitionMap.get(traitData.getName())));
columnCount++;
}
}
return FacesOutcomes.SUCCESS;
}
}