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

com.marvelution.jenkins.plugins.jira.store.ConsumerInfoStore Maven / Gradle / Ivy

There is a newer version: 1.5.6
Show newest version
/*
 * JIRA Plugin for Jenkins
 * Copyright (C) 2012 Marvelution
 * [email protected]
 *
 * 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.marvelution.jenkins.plugins.jira.store;

import com.google.common.collect.Maps;
import com.marvelution.jenkins.plugins.jira.model.ConsumerInfo;
import hudson.model.Hudson;

import java.io.IOException;
import java.util.Collection;
import java.util.Map;

/**
 * Store for {@link com.marvelution.jenkins.plugins.jira.model.ConsumerInfo} objects
 *
 * @author Mark Rekveld
 * @since 1.1.0
 */
public class ConsumerInfoStore extends BaseStore {

	private static transient ConsumerInfoStore STORE;
	private final Map consumers = Maps.newHashMap();

	/**
	 * Private constructor
	 */
	private ConsumerInfoStore() {
		super(Hudson.getInstance().getRootDir(), "applinks-consumer-info.xml");
	}

	/**
	 * Getter for the Store instance
	 *
	 * @return the {@link com.marvelution.jenkins.plugins.jira.store.ConsumerInfoStore}
	 * @throws java.io.IOException in case of store load errors
	 */
	public static ConsumerInfoStore getStore() throws IOException {
		if (STORE == null) {
			STORE = new ConsumerInfoStore();
			STORE.load();
		}
		return STORE;
	}

	/**
	 * Getter for all the configured Consumer Info objects
	 *
	 * @return all the configured Consumer Info objects
	 */
	public Collection getAll() {
		return consumers.values();
	}

	/**
	 * Get an {@link com.marvelution.jenkins.plugins.jira.model.ConsumerInfo} by its key
	 *
	 * @param key the Consumer Info key
	 * @return the {@link com.marvelution.jenkins.plugins.jira.model.ConsumerInfo}, may be {@code null}
	 */
	public ConsumerInfo get(final String key) {
		return consumers.get(key);
	}

	/**
	 * Add a new {@link com.marvelution.jenkins.plugins.jira.model.ConsumerInfo}
	 *
	 * @param consumerInfo the {@link com.marvelution.jenkins.plugins.jira.model.ConsumerInfo}
	 * @throws java.io.IOException in case of store save errors
	 */
	public synchronized void add(ConsumerInfo consumerInfo) throws IOException {
		consumers.put(consumerInfo.getKey(), consumerInfo);
		save();
	}

	/**
	 * Remove the {@link com.marvelution.jenkins.plugins.jira.model.ConsumerInfo} by its key
	 *
	 * @param key the consumer key to remove
	 * @throws java.io.IOException in case of store save errors
	 */
	public synchronized void remove(String key) throws IOException {
		consumers.remove(key);
		save();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy