001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.petstore.service;
018
019import java.time.*;
020
021/**
022 * One audit-trail record: who changed which petstore entity, how, and when.
023 *
024 * <p>
025 * {@link PetStore} appends one entry for every successful create, update or delete, whether it came from the
026 * {@code /petstore} API (actor {@code "api"}) or from the console (actor {@code "console:<user>"}).  Failed mutations
027 * append nothing.  The Audit console page lists these entries.
028 *
029 * <h5 class='section'>Example:</h5>
030 * <p class='bjava'>
031 *    PetStore <jv>store</jv> = <jk>new</jk> PetStore();
032 *    <jv>store</jv>.createPet(<jk>new</jk> Pet().setName(<js>"Rex"</js>), <js>"console:alice"</js>);
033 *    AuditEntry <jv>e</jv> = <jv>store</jv>.getAudit().get(0);
034 *    <jc>// e.getEntity() = "Pet", e.getAction() = "CREATE", e.getDetail() = "Rex"</jc>
035 * </p>
036 */
037public class AuditEntry {
038
039   private long id;
040   private Instant at;
041   private String actor;
042   private String entity;
043   private String entityId;
044   private String action;
045   private String detail;
046
047   /** @return The audit id, increasing in insertion order. */
048   public long getId() { return id; }
049
050   /**
051    * @param value The audit id.
052    * @return This object.
053    */
054   public AuditEntry setId(long value) { id = value; return this; }
055
056   /** @return When the mutation happened, from the store's {@link Clock}. */
057   public Instant getAt() { return at; }
058
059   /**
060    * @param value The timestamp.
061    * @return This object.
062    */
063   public AuditEntry setAt(Instant value) { at = value; return this; }
064
065   /** @return Who made the change, e.g. {@code "api"} or {@code "console:alice"}. */
066   public String getActor() { return actor; }
067
068   /**
069    * @param value The actor.
070    * @return This object.
071    */
072   public AuditEntry setActor(String value) { actor = value; return this; }
073
074   /** @return The entity kind: {@code "Pet"}, {@code "Order"}, {@code "User"} or {@code "Change"}. */
075   public String getEntity() { return entity; }
076
077   /**
078    * @param value The entity kind.
079    * @return This object.
080    */
081   public AuditEntry setEntity(String value) { entity = value; return this; }
082
083   /** @return The entity id (pet/order id, or username). */
084   public String getEntityId() { return entityId; }
085
086   /**
087    * @param value The entity id.
088    * @return This object.
089    */
090   public AuditEntry setEntityId(String value) { entityId = value; return this; }
091
092   /** @return The action, e.g. {@code "CREATE"}, {@code "UPDATE"}, {@code "DELETE"}. */
093   public String getAction() { return action; }
094
095   /**
096    * @param value The action.
097    * @return This object.
098    */
099   public AuditEntry setAction(String value) { action = value; return this; }
100
101   /** @return A short human-readable detail (pet name, username, ...), or <jk>null</jk>. */
102   public String getDetail() { return detail; }
103
104   /**
105    * @param value The detail.
106    * @return This object.
107    */
108   public AuditEntry setDetail(String value) { detail = value; return this; }
109}