-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Java classes for console history objects
This also creates base classes for the objects contained within the history classes, e.g. RegistrarBase. This is the same way that objects stored in the HistoryEntry subclasses have base classes, e.g. DomainBase.
- Loading branch information
Showing
81 changed files
with
2,838 additions
and
1,672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
core/src/main/java/google/registry/model/console/ConsoleEppActionHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2024 The Nomulus Authors. All Rights Reserved. | ||
// | ||
// 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 google.registry.model.console; | ||
|
||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; | ||
|
||
import google.registry.model.reporting.HistoryEntry; | ||
import google.registry.model.reporting.HistoryEntry.HistoryEntryId; | ||
import google.registry.persistence.VKey; | ||
import javax.persistence.Access; | ||
import javax.persistence.AccessType; | ||
import javax.persistence.AttributeOverride; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Index; | ||
import javax.persistence.Table; | ||
|
||
/** | ||
* A persisted history object representing an EPP action via the console. | ||
* | ||
* <p>In addition to the generic history fields (time, URL, etc.) we also persist a reference to the | ||
* history entry so that we can refer to it if necessary. | ||
*/ | ||
@Access(AccessType.FIELD) | ||
@Entity | ||
@Table( | ||
indexes = { | ||
@Index(columnList = "historyActingUser"), | ||
@Index(columnList = "repoId"), | ||
@Index(columnList = "revisionId") | ||
}) | ||
public class ConsoleEppActionHistory extends ConsoleUpdateHistory { | ||
Check failure Code scanning / CodeQL No clone method Error
No clone method, yet implements Cloneable.
|
||
|
||
@AttributeOverride(name = "repoId", column = @Column(nullable = false)) | ||
HistoryEntryId historyEntryId; | ||
|
||
@Column(nullable = false) | ||
Class<? extends HistoryEntry> historyEntryClass; | ||
|
||
public HistoryEntryId getHistoryEntryId() { | ||
return historyEntryId; | ||
} | ||
|
||
public Class<? extends HistoryEntry> getHistoryEntryClass() { | ||
return historyEntryClass; | ||
} | ||
|
||
/** Creates a {@link VKey} instance for this entity. */ | ||
@Override | ||
public VKey<ConsoleEppActionHistory> createVKey() { | ||
return VKey.create(ConsoleEppActionHistory.class, getRevisionId()); | ||
} | ||
|
||
@Override | ||
public Builder asBuilder() { | ||
return new Builder(clone(this)); | ||
} | ||
|
||
/** Builder for the immutable UserUpdateHistory. */ | ||
public static class Builder | ||
extends ConsoleUpdateHistory.Builder<ConsoleEppActionHistory, Builder> { | ||
|
||
public Builder() {} | ||
|
||
public Builder(ConsoleEppActionHistory instance) { | ||
super(instance); | ||
} | ||
|
||
@Override | ||
public ConsoleEppActionHistory build() { | ||
checkArgumentNotNull(getInstance().historyEntryId, "History entry ID must be specified"); | ||
checkArgumentNotNull( | ||
getInstance().historyEntryClass, "History entry class must be specified"); | ||
return super.build(); | ||
} | ||
|
||
public Builder setHistoryEntryId(HistoryEntryId historyEntryId) { | ||
getInstance().historyEntryId = historyEntryId; | ||
return this; | ||
} | ||
|
||
public Builder setHistoryEntryClass(Class<? extends HistoryEntry> historyEntryClass) { | ||
getInstance().historyEntryClass = historyEntryClass; | ||
return this; | ||
} | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
core/src/main/java/google/registry/model/console/ConsoleUpdateHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// Copyright 2024 The Nomulus Authors. All Rights Reserved. | ||
// | ||
// 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 google.registry.model.console; | ||
|
||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; | ||
|
||
import google.registry.model.Buildable; | ||
import google.registry.model.ImmutableObject; | ||
import google.registry.model.annotations.IdAllocation; | ||
import javax.persistence.Access; | ||
import javax.persistence.AccessType; | ||
import javax.persistence.Column; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.MappedSuperclass; | ||
import org.joda.time.DateTime; | ||
|
||
/** | ||
* A record of a resource that was updated through the console. | ||
* | ||
* <p>This abstract class has several subclasses that (mostly) include the modified resource itself | ||
* so that the entire object history is persisted to SQL. | ||
*/ | ||
@Access(AccessType.FIELD) | ||
@MappedSuperclass | ||
public abstract class ConsoleUpdateHistory extends ImmutableObject implements Buildable { | ||
|
||
public enum Type { | ||
EPP_ACTION, | ||
POC_CREATE, | ||
POC_UPDATE, | ||
POC_DELETE, | ||
REGISTRAR_UPDATE, | ||
USER_CREATE, | ||
USER_DELETE, | ||
USER_UPDATE | ||
} | ||
|
||
/** Autogenerated ID of this event. */ | ||
@Id | ||
@IdAllocation | ||
@Column(nullable = false, name = "historyRevisionId") | ||
protected Long revisionId; | ||
|
||
/** The user that performed the modification. */ | ||
@JoinColumn(name = "historyActingUser", referencedColumnName = "emailAddress") | ||
@ManyToOne | ||
User actingUser; | ||
|
||
/** The URL of the action that was used to make the modification. */ | ||
@Column(nullable = false, name = "historyUrl") | ||
String url; | ||
|
||
/** The HTTP method (e.g. POST, PUT) used to make this modification. */ | ||
@Column(nullable = false, name = "historyMethod") | ||
String method; | ||
|
||
/** The raw body of the request that was used to make this modification. */ | ||
@Column(name = "historyRequestBody") | ||
String requestBody; | ||
|
||
/** The time at which the modification was mode. */ | ||
@Column(nullable = false, name = "historyDateTime") | ||
DateTime dateTime; | ||
|
||
/** The type of modification. */ | ||
@Column(nullable = false, name = "historyType") | ||
@Enumerated(EnumType.STRING) | ||
Type type; | ||
|
||
public long getRevisionId() { | ||
// For some reason, Hibernate throws NPE during some initialization phases if we don't deal with | ||
// the null case. Setting the id to 0L when it is null should be fine because 0L for primitive | ||
// type is considered as null for wrapper class in the Hibernate context. | ||
return revisionId == null ? 0L : revisionId; | ||
} | ||
|
||
public User getActingUser() { | ||
return actingUser; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getMethod() { | ||
return method; | ||
} | ||
|
||
public String getRequestBody() { | ||
return requestBody; | ||
} | ||
|
||
public DateTime getDateTime() { | ||
return dateTime; | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public abstract Builder<? extends ConsoleUpdateHistory, ?> asBuilder(); | ||
|
||
/** Builder for the immutable ConsoleUpdateHistory. */ | ||
public abstract static class Builder< | ||
T extends ConsoleUpdateHistory, B extends ConsoleUpdateHistory.Builder<?, ?>> | ||
extends GenericBuilder<T, B> { | ||
|
||
protected Builder() {} | ||
|
||
protected Builder(T instance) { | ||
super(instance); | ||
} | ||
|
||
@Override | ||
public T build() { | ||
checkArgumentNotNull(getInstance().actingUser, "Acting user must be specified"); | ||
checkArgumentNotNull(getInstance().url, "URL must be specified"); | ||
checkArgumentNotNull(getInstance().method, "HTTP method must be specified"); | ||
checkArgumentNotNull(getInstance().dateTime, "dateTime must be specified"); | ||
checkArgumentNotNull(getInstance().type, "Console History type must be specified"); | ||
return super.build(); | ||
} | ||
|
||
public B setActingUser(User actingUser) { | ||
getInstance().actingUser = actingUser; | ||
return thisCastToDerived(); | ||
} | ||
|
||
public B setUrl(String url) { | ||
getInstance().url = url; | ||
return thisCastToDerived(); | ||
} | ||
|
||
public B setMethod(String method) { | ||
getInstance().method = method; | ||
return thisCastToDerived(); | ||
} | ||
|
||
public B setRequestBody(String requestBody) { | ||
getInstance().requestBody = requestBody; | ||
return thisCastToDerived(); | ||
} | ||
|
||
public B setDateTime(DateTime dateTime) { | ||
getInstance().dateTime = dateTime; | ||
return thisCastToDerived(); | ||
} | ||
|
||
public B setType(Type type) { | ||
getInstance().type = type; | ||
return thisCastToDerived(); | ||
} | ||
} | ||
} |
Oops, something went wrong.