All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.j2bugzilla.rpc.GetProduct Maven / Gradle / Ivy

/*
 * Copyright 2011 Thomas Golden
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.j2bugzilla.rpc;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.j2bugzilla.base.BugzillaMethod;
import com.j2bugzilla.base.Product;

/**
 * The {@code GetProduct} class provides access to information on {@link Product Products} active in a particular
 * Bugzilla installation.
 * 
 * @author Tom
 *
 */
public class GetProduct implements BugzillaMethod {

	/**
	 * The method Bugzilla will execute via XML-RPC
	 */
	private static final String METHOD_NAME = "Product.get";
	
	private Map params = new HashMap();
	
	private Map hash = Collections.emptyMap();
	
	/**
	 * Creates a new {@link GetProduct}, which can be used to retrieve the {@link Product} associated with the
	 * specified ID number.
	 * @param id A unique integer ID.
	 */
	public GetProduct(int id) {
		params.put("ids", new Integer[] { id });
	}
	
	/**
	 * Returns the product found in the Bugzilla installation matching the provided name or ID.
	 * @return A new {@link Product}, or null if there are no results to return.
	 */
	public Product getProduct() {
		Object products = hash.get("products");
		if(products == null) { return null; }
		
		Object[] arr = (Object[])products;
		if(arr.length == 0) { return null; }
		
		@SuppressWarnings("unchecked")//Cast to form specified by webservice
		Map prodMap = (Map)arr[0];
		Product product = new Product((Integer)prodMap.get("id"), (String)prodMap.get("name"));
		String desc = (String)prodMap.get("description");
		product.setDescription(desc);
		
		return product;
	}
	
	@Override
	public void setResultMap(Map hash) {
		this.hash = hash;
	}

	@Override
	public Map getParameterMap() {
		return Collections.unmodifiableMap(params);
	}

	@Override
	public String getMethodName() {
		return METHOD_NAME;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy