TransientMessageService.java

/*
 * Copyright 2021 Global Crop Diversity Trust
 *
 * 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.gringlobal.service;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

import javax.validation.constraints.NotNull;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

/**
 * The Interface TransientMessageService.
 */
public interface TransientMessageService {

	/**
	 * Log message and store it in memory.
	 *
	 * @param key the identifier of the message type
	 * @param message the message to log and store
	 * @param args the args
	 * @return stored message
	 */
	TransientMessage addAdminAlert(@NotNull String key, @NotNull String message, Object... args);

	/**
	 * Get current stored admin alerts.
	 *
	 * @param page the page
	 * @return list of admin alerts
	 */
	Page<TransientMessage> listAdminAlerts(Pageable page);

	/**
	 * Delete alert by UUID
	 *
	 * @param alertUuid the UUID
	 * @return deleted alert
	 */
	TransientMessage removeAdminAlert(@NotNull UUID alertUuid);


	static class TransientMessage implements Serializable {
		private static final long serialVersionUID = -8901495841846579473L;
		public final UUID uuid = UUID.randomUUID();
		public int count = 1;
		public String key;
		public String message;
		public Date timestamp;

		public TransientMessage() {
		}

		public TransientMessage(String key, String message, Date timestamp) {
			this.key = key;
			this.message = message;
			this.timestamp = timestamp;
		}
	}

}