google-nomulus/java/google/registry/model/domain/launch/LaunchPhase.java
guyben 24799b394d Allow the same LaunchPhase to be used for both start-date and end-date sunrise
Also changed the name of "verifyRegistryStateAllowsLaunchFlows" to "verifyRegistryStateAllowsApplicationFlows", because there are now launch flows that don't use applications (start-date sunrise).

Finally, added a test to showcase the "super-user" power that EPPs with Anchor Tenants have. There's no change in behavior in that regard in this CL - we just add a test to make it explicit.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=187517199
2018-03-06 19:12:56 -05:00

145 lines
5.6 KiB
Java

// Copyright 2017 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.domain.launch;
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import static google.registry.util.TypeUtils.getTypesafeEnumMapping;
import static java.util.Objects.hash;
import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.annotation.Embed;
import google.registry.model.ImmutableObject;
import java.util.Map.Entry;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
/**
* The launch phase of the TLD being addressed by this command.
*
* <p>The launch phase refers to the various stages that a TLD goes through before entering general
* availability. The various phases are described below (in order that they usually occur).
*
* <p>Each phase is connected to the TldState in which it can be used (see DomainFlowUtils). Sending
* an EPP with the wrong launch phase for the current TldState will result in an error. However, we
* don't actually check the launch phase *exists*.
*
* <p>We usually check for the information *inside* a launch phase (e.g. the signed mark for the
* domain) and return an error if that is missing - which would also check that the phase exists.
* But if we bypass the need for that information (e.g., an Anchor Tenant doesn't need a signed
* mark), then we never actually test the phase exists.
*
* <p>This means an Anchor Tenant has some weird peculiarities: It doesn't need to specify the
* phase. It *can* specify the phase, but not give any of the phase's information (e.g. - signed
* marks), in which case we accept even a wrong phase. But if it *does* give a signed mark as well -
* we will return an error if it's the wrong phase (or if the marks are invalid) even though we
* didn't require them.
*
* <p>This is OK (?) because the Anchor Tenants field is set internally and manually.. The person
* who sets it is the one that needs to make sure the domain isn't a trademark and that the fields
* are correct.
*/
@Embed
public class LaunchPhase extends ImmutableObject {
/**
* The phase during which trademark holders can submit registrations or applications with
* trademark information that can be validated by the server.
*
* This phase works for both start-date and end-data sunrise.
*
* TODO(b/74006379): maybe make this work for sunrush phase?
*/
public static final LaunchPhase SUNRISE = create("sunrise", null);
/**
* A post-Sunrise phase when non-trademark holders are allowed to register domain names with steps
* taken to address a large volume of initial registrations.
*/
public static final LaunchPhase LANDRUSH = create("landrush", null);
/** A combined sunrise/landrush phase. */
public static final LaunchPhase SUNRUSH = create("sunrise", "landrush");
/**
* The Trademark Claims phase, as defined in the TMCH Functional Specification, in which a Claims
* Notice must be displayed to a prospective registrant of a domain name that matches trademarks.
*/
public static final LaunchPhase CLAIMS = create("claims", null);
/** A post-launch phase that is also referred to as "steady state". */
public static final LaunchPhase OPEN = create("open", null);
/** A custom server launch phase that is defined using the "name" attribute. */
public static final LaunchPhase CUSTOM = create("custom", null);
private static final ImmutableMap<String, LaunchPhase> LAUNCH_PHASES = initEnumMapping();
/**
* Returns a map of the static final fields to their values, case-converted.
*/
private static ImmutableMap<String, LaunchPhase> initEnumMapping() {
ImmutableMap.Builder<String, LaunchPhase> builder = new ImmutableMap.Builder<>();
for (Entry<String, LaunchPhase> entry : getTypesafeEnumMapping(LaunchPhase.class).entrySet()) {
builder.put(UPPER_UNDERSCORE.to(LOWER_CAMEL, entry.getKey()), entry.getValue());
}
return builder.build();
}
/** Private create function for the typesafe enum pattern. */
public static LaunchPhase create(String phase, String subphase) {
LaunchPhase instance = new LaunchPhase();
instance.phase = phase;
instance.subphase = subphase;
return instance;
}
@XmlValue
String phase;
/**
* Holds the name of a custom phase if the main phase is "custom", or a sub-phase for all other
* values.
*/
@XmlAttribute(name = "name")
String subphase;
public String getPhase() {
return phase;
}
public String getSubphase() {
return subphase;
}
public static LaunchPhase fromValue(String value) {
return LAUNCH_PHASES.get(value);
}
/** A special equals implementation that only considers the string value. */
@Override
public boolean equals(Object other) {
return other instanceof LaunchPhase
&& Objects.equals(phase, ((LaunchPhase) other).phase)
&& Objects.equals(subphase, ((LaunchPhase) other).subphase);
}
/** A special hashCode implementation that only considers the string value. */
@Override
public int hashCode() {
return hash(phase, subphase);
}
}