google-nomulus/java/google/registry/rdap/RdapSearchResults.java
mountford ff1ab08302 Add RDAP metric class
The code to use this class will come in future CLs, to avoid a huge CL.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175162557
2017-11-21 18:20:26 -05:00

74 lines
2.7 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.rdap;
import static google.registry.rdap.RdapIcannStandardInformation.POSSIBLY_INCOMPLETE_NOTICES;
import static google.registry.rdap.RdapIcannStandardInformation.TRUNCATION_NOTICES;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
/**
* Holds domain, nameserver and entity search results.
*
* <p>We need to know not only the list of things we found, but also whether the result set was
* truncated to the limit. If it is, we must add the ICANN-mandated notice to that effect.
*/
@AutoValue
abstract class RdapSearchResults {
enum IncompletenessWarningType {
/** Result set is complete. */
COMPLETE,
/** Result set has been limited to the maximum size. */
TRUNCATED,
/**
* Result set might be missing data because the first step of a two-step query returned a data
* set that was limited in size.
*/
MIGHT_BE_INCOMPLETE
}
static RdapSearchResults create(ImmutableList<ImmutableMap<String, Object>> jsonList) {
return create(jsonList, IncompletenessWarningType.COMPLETE);
}
static RdapSearchResults create(
ImmutableList<ImmutableMap<String, Object>> jsonList,
IncompletenessWarningType incompletenessWarningType) {
return new AutoValue_RdapSearchResults(jsonList, incompletenessWarningType);
}
/** List of JSON result object representations. */
abstract ImmutableList<ImmutableMap<String, Object>> jsonList();
/** Type of warning to display regarding possible incomplete data. */
abstract IncompletenessWarningType incompletenessWarningType();
/** Convenience method to get the appropriate warnings for the incompleteness warning type. */
ImmutableList<ImmutableMap<String, Object>> getIncompletenessWarnings() {
if (incompletenessWarningType() == IncompletenessWarningType.TRUNCATED) {
return TRUNCATION_NOTICES;
}
if (incompletenessWarningType() == IncompletenessWarningType.MIGHT_BE_INCOMPLETE) {
return POSSIBLY_INCOMPLETE_NOTICES;
}
return ImmutableList.of();
}
}