mirror of
https://github.com/google/nomulus
synced 2026-09-12 11:06:29 +00:00
Allow multiple threat types in the Spec11ThreatMatch table (#650)
* Update to generic Spec11ThreatMatch table * Fix SQL syntax * Make changes to the schema and add a test for null and empty threatTypes * Fix a small typo * Change the exception thrown with illegal arguments Change the import for isNullOrEmpty * Fix import for checkArgument * Added a threat to test multiple threat types
This commit is contained in:
+21
-18
@@ -14,18 +14,20 @@
|
||||
|
||||
package google.registry.model.reporting;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static google.registry.util.CollectionUtils.isNullOrEmpty;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.model.Buildable;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.schema.replay.DatastoreEntity;
|
||||
import google.registry.schema.replay.SqlEntity;
|
||||
import google.registry.util.DomainNameUtils;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
@@ -36,11 +38,11 @@ import org.joda.time.LocalDate;
|
||||
@Entity
|
||||
@Table(
|
||||
indexes = {
|
||||
@Index(name = "safebrowsing_threat_registrar_id_idx", columnList = "registrarId"),
|
||||
@Index(name = "safebrowsing_threat_tld_idx", columnList = "tld"),
|
||||
@Index(name = "safebrowsing_threat_check_date_idx", columnList = "checkDate")
|
||||
@Index(name = "spec11threatmatch_registrar_id_idx", columnList = "registrarId"),
|
||||
@Index(name = "spec11threatmatch_tld_idx", columnList = "tld"),
|
||||
@Index(name = "spec11threatmatch_check_date_idx", columnList = "checkDate")
|
||||
})
|
||||
public class SafeBrowsingThreat extends ImmutableObject implements Buildable, SqlEntity {
|
||||
public class Spec11ThreatMatch extends ImmutableObject implements Buildable, SqlEntity {
|
||||
|
||||
/** The type of threat detected. */
|
||||
public enum ThreatType {
|
||||
@@ -60,10 +62,9 @@ public class SafeBrowsingThreat extends ImmutableObject implements Buildable, Sq
|
||||
@Column(nullable = false)
|
||||
String domainName;
|
||||
|
||||
/** The type of threat detected. */
|
||||
/** The types of threat detected. */
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
ThreatType threatType;
|
||||
Set<ThreatType> threatTypes;
|
||||
|
||||
/** Primary key of the domain table and unique identifier for all EPP resources. */
|
||||
@Column(nullable = false)
|
||||
@@ -89,8 +90,8 @@ public class SafeBrowsingThreat extends ImmutableObject implements Buildable, Sq
|
||||
return domainName;
|
||||
}
|
||||
|
||||
public ThreatType getThreatType() {
|
||||
return threatType;
|
||||
public ImmutableSet<ThreatType> getThreatTypes() {
|
||||
return ImmutableSet.copyOf(threatTypes);
|
||||
}
|
||||
|
||||
public String getDomainRepoId() {
|
||||
@@ -119,18 +120,18 @@ public class SafeBrowsingThreat extends ImmutableObject implements Buildable, Sq
|
||||
return new Builder(clone(this));
|
||||
}
|
||||
|
||||
/** A builder for constructing {@link SafeBrowsingThreat}, since it is immutable. */
|
||||
public static class Builder extends Buildable.Builder<SafeBrowsingThreat> {
|
||||
/** A builder for constructing {@link Spec11ThreatMatch}, since it is immutable. */
|
||||
public static class Builder extends Buildable.Builder<Spec11ThreatMatch> {
|
||||
public Builder() {}
|
||||
|
||||
private Builder(SafeBrowsingThreat instance) {
|
||||
private Builder(Spec11ThreatMatch instance) {
|
||||
super(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SafeBrowsingThreat build() {
|
||||
public Spec11ThreatMatch build() {
|
||||
checkArgumentNotNull(getInstance().domainName, "Domain name cannot be null");
|
||||
checkArgumentNotNull(getInstance().threatType, "Threat type cannot be null");
|
||||
checkArgumentNotNull(getInstance().threatTypes, "Threat types cannot be null");
|
||||
checkArgumentNotNull(getInstance().domainRepoId, "Repo ID cannot be null");
|
||||
checkArgumentNotNull(getInstance().registrarId, "Registrar ID cannot be null");
|
||||
checkArgumentNotNull(getInstance().checkDate, "Check date cannot be null");
|
||||
@@ -145,8 +146,10 @@ public class SafeBrowsingThreat extends ImmutableObject implements Buildable, Sq
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setThreatType(ThreatType threatType) {
|
||||
getInstance().threatType = threatType;
|
||||
public Builder setThreatTypes(ImmutableSet<ThreatType> threatTypes) {
|
||||
checkArgument(!isNullOrEmpty(threatTypes), "threatTypes cannot be null or empty.");
|
||||
|
||||
getInstance().threatTypes = threatTypes;
|
||||
return this;
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// Copyright 2020 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.persistence.converter;
|
||||
|
||||
import google.registry.model.reporting.Spec11ThreatMatch.ThreatType;
|
||||
import javax.persistence.AttributeConverter;
|
||||
import javax.persistence.Converter;
|
||||
|
||||
/** JPA {@link AttributeConverter} for storing/retrieving {@code Set}. */
|
||||
@Converter(autoApply = true)
|
||||
public class Spec11ThreatMatchThreatTypeSetConverter extends StringSetConverterBase<ThreatType> {
|
||||
|
||||
@Override
|
||||
String toString(ThreatType element) {
|
||||
return element.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
ThreatType fromString(String value) {
|
||||
return ThreatType.valueOf(value);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
<class>google.registry.model.host.HostResource</class>
|
||||
<class>google.registry.model.registrar.Registrar</class>
|
||||
<class>google.registry.model.registrar.RegistrarContact</class>
|
||||
<class>google.registry.model.reporting.SafeBrowsingThreat</class>
|
||||
<class>google.registry.model.reporting.Spec11ThreatMatch</class>
|
||||
<class>google.registry.schema.domain.RegistryLock</class>
|
||||
<class>google.registry.schema.tmch.ClaimsList</class>
|
||||
<class>google.registry.schema.cursor.Cursor</class>
|
||||
@@ -56,6 +56,7 @@
|
||||
<class>google.registry.persistence.converter.LocalDateConverter</class>
|
||||
<class>google.registry.persistence.converter.PostalInfoChoiceListConverter</class>
|
||||
<class>google.registry.persistence.converter.RegistrarPocSetConverter</class>
|
||||
<class>google.registry.persistence.converter.Spec11ThreatMatchThreatTypeSetConverter</class>
|
||||
<class>google.registry.persistence.converter.StatusValueSetConverter</class>
|
||||
<class>google.registry.persistence.converter.StringListConverter</class>
|
||||
<class>google.registry.persistence.converter.StringSetConverter</class>
|
||||
|
||||
Reference in New Issue
Block a user