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

com.marvelution.jira.plugins.sonar.DefaultSonarPropertyManagerImpl Maven / Gradle / Ivy

/*
 * Licensed to Marvelution under one or more contributor license 
 * agreements.  See the NOTICE file distributed with this work 
 * for additional information regarding copyright ownership.
 * Marvelution licenses this file to you 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.jira.plugins.sonar;

import java.util.HashMap;

import com.marvelution.jira.plugins.sonar.service.SonarPropertyManager;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.module.propertyset.PropertySetManager;

/**
 * Default {@link SonarPropertyManager} implementation
 * 
 * @author Mark Rekveld
 */
public class DefaultSonarPropertyManagerImpl implements SonarPropertyManager {

	private static final long PROPERTIES_ID = 3;

	private static DefaultSonarPropertyManagerImpl propertiesManager;

	private PropertySet propertySet;

	/**
	 * Hidden constructor which loads the property set
	 */
	public DefaultSonarPropertyManagerImpl() {
		loadPropertySet();
	}

	/**
	 * Singleton retriever
	 * 
	 * @return the singleton {@link DefaultHudsonPropertyManagerImpl}
	 */
	public static DefaultSonarPropertyManagerImpl getInstance() {
		if (propertiesManager == null) {
			propertiesManager = new DefaultSonarPropertyManagerImpl();
		}
		return propertiesManager;
	}

	/**
	 * Only useful for mocking out the PropertiesManager
	 * 
	 * @param propertiesManager the {@link DefaultSonarPropertyManagerImpl}
	 */
	public static void setPropertiesManager(DefaultSonarPropertyManagerImpl propertiesManager) {
		DefaultSonarPropertyManagerImpl.propertiesManager = propertiesManager;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public PropertySet getPropertySet() {
		return propertySet;
	}

	/**
	 * Refresh the properties from the database
	 */
	public void refresh() {
		loadPropertySet();
	}

	/**
	 * Locate PropertySet using PropertyStore for this sequenceName/sequenceId mapping.
	 */
	@SuppressWarnings("unchecked")
	protected void loadPropertySet() {
		final HashMap psArgs = new HashMap();
		psArgs.put("delegator.name", "default");
		psArgs.put("entityName", "SonarServerProperties");
		psArgs.put("entityId", new Long(PROPERTIES_ID));
		propertySet = PropertySetManager.getInstance("ofbiz", psArgs);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy