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 019/** 020 * One staged inline edit of a pet field, waiting on the Pending changes page to be applied or discarded. 021 * 022 * <h5 class='section'>Example:</h5> 023 * <p class='bjava'> 024 * PendingChange <jv>c</jv> = <jv>store</jv>.pendingChanges().stage(1, <js>"name"</js>, <js>"Sir Frisky"</js>, <js>"alice"</js>); 025 * <jc>// c.getState() == State.PENDING; the pet is unchanged until apply()</jc> 026 * <jv>store</jv>.pendingChanges().apply(<jv>c</jv>.getId(), <js>"console:alice"</js>); 027 * </p> 028 */ 029public class PendingChange { 030 031 /** Lifecycle of a staged change. */ 032 public enum State { 033 /** Staged; may be applied or discarded. */ 034 PENDING, 035 /** Written to the pet. */ 036 APPLIED, 037 /** Apply failed; may be retried. */ 038 FAILED 039 } 040 041 private long id; 042 private long petId; 043 private String field; 044 private String oldValue; 045 private String newValue; 046 private String author; 047 private String summary; 048 private String message; 049 private State state = State.PENDING; 050 051 /** @return The change id, increasing in staging order. */ 052 public long getId() { return id; } 053 054 /** 055 * @param value The change id, increasing in staging order. 056 * @return This object. 057 */ 058 public PendingChange setId(long value) { id = value; return this; } 059 060 /** @return The id of the pet the change targets. */ 061 public long getPetId() { return petId; } 062 063 /** 064 * @param value The id of the pet the change targets. 065 * @return This object. 066 */ 067 public PendingChange setPetId(long value) { petId = value; return this; } 068 069 /** @return The staged field, one of {@code "name"}, {@code "price"}, {@code "species"}, {@code "status"} or {@code "tags"}. */ 070 public String getField() { return field; } 071 072 /** 073 * @param value The staged field, one of {@code "name"}, {@code "price"}, {@code "species"}, {@code "status"} or {@code "tags"}. 074 * @return This object. 075 */ 076 public PendingChange setField(String value) { field = value; return this; } 077 078 /** @return The field value when the change was staged. */ 079 public String getOldValue() { return oldValue; } 080 081 /** 082 * @param value The field value when the change was staged. 083 * @return This object. 084 */ 085 public PendingChange setOldValue(String value) { oldValue = value; return this; } 086 087 /** @return The staged new value. */ 088 public String getNewValue() { return newValue; } 089 090 /** 091 * @param value The staged new value. 092 * @return This object. 093 */ 094 public PendingChange setNewValue(String value) { newValue = value; return this; } 095 096 /** @return The lifecycle state. */ 097 public State getState() { return state; } 098 099 /** 100 * @param value The lifecycle state. 101 * @return This object. 102 */ 103 public PendingChange setState(State value) { state = value; return this; } 104 105 /** @return Who staged the change. */ 106 public String getAuthor() { return author; } 107 108 /** 109 * @param value Who staged the change. 110 * @return This object. 111 */ 112 public PendingChange setAuthor(String value) { author = value; return this; } 113 114 /** @return A short human-readable summary of the change. */ 115 public String getSummary() { return summary; } 116 117 /** 118 * @param value A short human-readable summary of the change. 119 * @return This object. 120 */ 121 public PendingChange setSummary(String value) { summary = value; return this; } 122 123 /** @return The failure text when the state is {@code FAILED}, otherwise <jk>null</jk>. */ 124 public String getMessage() { return message; } 125 126 /** 127 * @param value The failure text when the state is {@code FAILED}, otherwise <jk>null</jk>. 128 * @return This object. 129 */ 130 public PendingChange setMessage(String value) { message = value; return this; } 131}