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

com.github.kmbulebu.nicknack.providers.pushover.PushOverProvider Maven / Gradle / Ivy

There is a newer version: 0.0.7
Show newest version
package com.github.kmbulebu.nicknack.providers.pushover;


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

import org.apache.commons.configuration.Configuration;

import com.github.kmbulebu.nicknack.core.actions.Action;
import com.github.kmbulebu.nicknack.core.actions.ActionDefinition;
import com.github.kmbulebu.nicknack.core.actions.ActionFailureException;
import com.github.kmbulebu.nicknack.core.actions.ActionParameterException;
import com.github.kmbulebu.nicknack.core.events.EventDefinition;
import com.github.kmbulebu.nicknack.core.providers.OnEventListener;
import com.github.kmbulebu.nicknack.core.providers.Provider;

public class PushOverProvider implements Provider {
	
	public static final UUID PROVIDER_UUID = UUID.fromString("ec72c198-1ee8-4fd6-be0c-c10fd365f95a");
	
	private final Map actionDefinitions = new HashMap<>();

	@Override
	public UUID getUuid() {
		return PROVIDER_UUID;
	}

	@Override
	public String getName() {
		return "PushOver";
	}

	@Override
	public String getAuthor() {
		return "NickNack";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override	
	public Collection getEventDefinitions() {
		return Collections.emptyList();
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public Collection getActionDefinitions() {
		return (Collection) actionDefinitions.values();
	}

	@Override
	public Map getAttributeDefinitionValues(UUID eventDefinitionUuid, UUID attributeDefinitionUuid) {
		return null;
	}

	@Override
	public void run(Action action) throws ActionFailureException, ActionParameterException {
		// Look it up.
		final AbstractPushMessageActionDefinition actionDef = actionDefinitions.get(action.getAppliesToActionDefinition());
		if (actionDef == null) {
			throw new ActionFailureException("Action is not provided by the PushOver provider. Please open a bug.");
		}
		
		actionDef.run(action);
	}

	@Override
	public void init(Configuration configuration, OnEventListener onEventListener) throws Exception {
		actionDefinitions.put(PushMessageActionDefinition.DEF_UUID, new PushMessageActionDefinition());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy