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

base.jee.api.model.AuditLogEntry Maven / Gradle / Ivy

Go to download

A collection of basic java utility classes that provide basic features for a standalone/simple JEE application. Backed by a Cassandra, MySQL, or SQLite database, it provides, web page templates, user and group management, and a searchable online audit log of all user activity.

There is a newer version: 1.5.4
Show newest version
/*
 This is free and unencumbered software released into the public domain.

 Anyone is free to copy, modify, publish, use, compile, sell, or
 distribute this software, either in source code form or as a compiled
 binary, for any purpose, commercial or non-commercial, and by any
 means.

 In jurisdictions that recognize copyright laws, the author or authors
 of this software dedicate any and all copyright interest in the
 software to the public domain. We make this dedication for the benefit
 of the public at large and to the detriment of our heirs and
 successors. We intend this dedication to be an overt act of
 relinquishment in perpetuity of all present and future rights to this
 software under copyright law.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
package base.jee.api.model;

import java.util.Date;
import java.util.UUID;

import base.QueryResult;
import base.json.Json;

/**
 * Audit log entry translated for display to the end user.
 */
public class AuditLogEntry implements QueryResult {

	private UUID uuid;
	private Date date;
	private String level;
	private UUID personUuid;
	private String displayName;
	private String message;
	private String ip;

	public AuditLogEntry(Date date, String level, UUID personUuid, String firstName, String lastName, String message, String ip) {
		this(null, date, level, personUuid, firstName, lastName, message, ip);
	}

	public AuditLogEntry(UUID uuid, Date date, String level, UUID personUuid, String firstName, String lastName, String message, String ip) {
		this.date = date;
		this.level = level;
		this.personUuid = personUuid;
		this.message = message;
		if (firstName == null && lastName == null) {
			displayName = "";
		} else {
			if (firstName == null && lastName != null) {
				displayName = lastName;
			} else {
				if (firstName != null && lastName == null) {
					displayName = firstName;
				} else {
					displayName = firstName + " " + lastName;
				}
			}
		}
		this.ip = ip;
	}

	public UUID getUuid() {
		return uuid;
	}

	public void setUuid(UUID uuid) {
		this.uuid = uuid;
	}

	public Date getDate() {
		return date;
	}

	public String getLevel() {
		return level;
	}

	public String getDisplayName() {
		return displayName;
	}

	public String getMessage() {
		return message;
	}

	public String getIp() {
		return ip;
	}

	public String toString() {
		return toJson();
	}

	public void setPersonUuid(UUID personUuid) {
		this.personUuid = personUuid;
	}

	public UUID getPersonUuid() {
		return personUuid;
	}

	public String toJson() {
		return "{" +
				(uuid != null?"\"uuid\"":"\"" + uuid + "\"") +
				"\"date\":" + Json.toDateTime(date) + "," +
				"\"level\":\"" + Json.escape(level) + "\"," +
				"\"display_name\":\"" + Json.escape(displayName) + "\"," +
				"\"message\":\"" + message + "\"," +
				"\"ip\":\"" + ip + "\"" +
				"}";
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy