/*
* Copyright (c) 2011 Lockheed Martin Corporation
*
* 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 org.eurekastreams.server.action.execution.notification;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eurekastreams.server.domain.NotificationType;
import org.eurekastreams.server.domain.PropertyHashMap;
import org.eurekastreams.server.domain.PropertyMap;
/**
* The notifications generated by a given event.
*/
public class NotificationBatch
{
/** List of recipients to receive each type of notification. */
private final Map<NotificationType, Collection<Long>> recipients = // \n
new HashMap<NotificationType, Collection<Long>>();
/** The properties of the notification. */
private final PropertyMap<Object> properties = new PropertyHashMap<Object>();
/**
* Constructor.
*/
public NotificationBatch()
{
}
/**
* Constructor.
*
* @param type
* Type of notification.
* @param recipientId
* Recipient.
*/
public NotificationBatch(final NotificationType type, final long recipientId)
{
setRecipient(type, recipientId);
}
/**
* Constructor.
*
* @param type
* Type of notification.
* @param recipientIds
* Recipients.
*/
public NotificationBatch(final NotificationType type, final Collection<Long> recipientIds)
{
recipients.put(type, recipientIds);
}
/**
* @return the recipients
*/
public Map<NotificationType, Collection<Long>> getRecipients()
{
return recipients;
}
/**
* @return the properties
*/
public PropertyMap<Object> getProperties()
{
return properties;
}
/**
* Convenience method which sets a single recipient.
*
* @param type
* Type of notification.
* @param recipientId
* Recipient.
*/
public void setRecipient(final NotificationType type, final long recipientId)
{
recipients.put(type, Collections.singletonList(recipientId));
}
/**
* Convenience method which sets a property with an actual value.
*
* @param key
* Name of property.
* @param value
* Value of property.
*/
public void setProperty(final String key, final Object value)
{
properties.put(key, value);
}
/**
* Convenience method which sets a property with a placeholder value.
*
* @param key
* Name of property.
* @param type
* The type of the property.
* @param identity
* The identity of the property.
*/
public void setProperty(final String key, final Class type, final Serializable identity)
{
properties.put(key, type, identity);
}
/**
* Convenience method to cause two keys to point to the same property.
*
* @param aliasKey
* New key.
* @param originalKey
* Existing key.
*/
public void setPropertyAlias(final String aliasKey, final String originalKey)
{
properties.putAlias(aliasKey, originalKey);
}
}