mv com/google/domain/registry google/registry

This change renames directories in preparation for the great package
rename. The repository is now in a broken state because the code
itself hasn't been updated. However this should ensure that git
correctly preserves history for each file.
This commit is contained in:
Justine Tunney 2016-05-13 18:55:08 -04:00
parent a41677aea1
commit 5012893c1d
2396 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,70 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.model.poll;
import com.google.domain.registry.model.ImmutableObject;
import org.joda.time.DateTime;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
/** Information about the message queue for the currently logged in registrar. */
public class MessageQueueInfo extends ImmutableObject {
/** The date and time that the current message was enqueued. */
@XmlElement(name = "qDate")
DateTime queueDate;
/** A human-readable message. */
String msg;
/** The number of messages currently in the queue. */
@XmlAttribute(name = "count")
Integer queueLength;
/** The id of the message currently at the head of the queue. */
@XmlAttribute(name = "id")
String messageId;
public DateTime getQueueDate() {
return queueDate;
}
public String getMsg() {
return msg;
}
public Integer getQueueLength() {
return queueLength;
}
public String getMessageId() {
return messageId;
}
public static MessageQueueInfo create(
DateTime queueDate,
String msg,
Integer queueLength,
String messageId) {
MessageQueueInfo instance = new MessageQueueInfo();
instance.queueDate = queueDate;
instance.msg = msg;
instance.queueLength = queueLength;
instance.messageId = messageId;
return instance;
}
}

View file

@ -0,0 +1,124 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.model.poll;
import com.google.common.annotations.VisibleForTesting;
import com.google.domain.registry.model.ImmutableObject;
import com.google.domain.registry.model.eppcommon.Trid;
import com.google.domain.registry.model.eppoutput.Response.ResponseData;
import com.googlecode.objectify.annotation.Embed;
import org.joda.time.DateTime;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
/** The {@link ResponseData} returned when completing a pending action on a domain. */
@XmlTransient
public abstract class PendingActionNotificationResponse
extends ImmutableObject implements ResponseData {
/** The inner name type that contains a name and the result boolean. */
@Embed
static class NameOrId extends ImmutableObject {
@XmlValue
String value;
@XmlAttribute(name = "paResult")
boolean actionResult;
}
@XmlTransient
NameOrId nameOrId;
@XmlElement(name = "paTRID")
Trid trid;
@XmlElement(name = "paDate")
DateTime processedDate;
public String getNameAsString() {
return nameOrId.value;
}
@VisibleForTesting
public Trid getTrid() {
return trid;
}
@VisibleForTesting
public boolean getActionResult() {
return nameOrId.actionResult;
}
@SuppressWarnings("unchecked")
protected <T extends PendingActionNotificationResponse> T init(
String nameOrId, boolean actionResult, Trid trid, DateTime processedDate) {
this.nameOrId = new NameOrId();
this.nameOrId.value = nameOrId;
this.nameOrId.actionResult = actionResult;
this.trid = trid;
this.processedDate = processedDate;
return (T) this;
}
/** An adapter to output the XML in response to resolving a pending command on a domain. */
@Embed
@XmlRootElement(name = "panData", namespace = "urn:ietf:params:xml:ns:domain-1.0")
@XmlType(
propOrder = {"name", "trid", "processedDate"},
namespace = "urn:ietf:params:xml:ns:domain-1.0")
public static class DomainPendingActionNotificationResponse
extends PendingActionNotificationResponse {
@XmlElement
NameOrId getName() {
return nameOrId;
}
public static DomainPendingActionNotificationResponse create(
String fullyQualifiedDomainName, boolean actionResult, Trid trid, DateTime processedDate) {
return new DomainPendingActionNotificationResponse().init(
fullyQualifiedDomainName, actionResult, trid, processedDate);
}
}
/** An adapter to output the XML in response to resolving a pending command on a contact. */
@Embed
@XmlRootElement(name = "panData", namespace = "urn:ietf:params:xml:ns:contact-1.0")
@XmlType(
propOrder = {"id", "trid", "processedDate"},
namespace = "urn:ietf:params:xml:ns:contact-1.0")
public static class ContactPendingActionNotificationResponse
extends PendingActionNotificationResponse {
@XmlElement
NameOrId getId() {
return nameOrId;
}
public static ContactPendingActionNotificationResponse create(
String contactId, boolean actionResult, Trid trid, DateTime processedDate) {
return new ContactPendingActionNotificationResponse().init(
contactId, actionResult, trid, processedDate);
}
}
}

View file

@ -0,0 +1,324 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.model.poll;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.domain.registry.util.CollectionUtils.forceEmptyToNull;
import static com.google.domain.registry.util.CollectionUtils.isNullOrEmpty;
import static com.google.domain.registry.util.CollectionUtils.nullToEmpty;
import static com.google.domain.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Converter;
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.domain.registry.model.Buildable;
import com.google.domain.registry.model.EppResource;
import com.google.domain.registry.model.ImmutableObject;
import com.google.domain.registry.model.annotations.ExternalMessagingName;
import com.google.domain.registry.model.contact.ContactResource;
import com.google.domain.registry.model.domain.DomainBase;
import com.google.domain.registry.model.domain.DomainRenewData;
import com.google.domain.registry.model.domain.launch.LaunchInfoResponseExtension;
import com.google.domain.registry.model.eppoutput.Response.ResponseData;
import com.google.domain.registry.model.eppoutput.Response.ResponseExtension;
import com.google.domain.registry.model.poll.PendingActionNotificationResponse.ContactPendingActionNotificationResponse;
import com.google.domain.registry.model.poll.PendingActionNotificationResponse.DomainPendingActionNotificationResponse;
import com.google.domain.registry.model.reporting.HistoryEntry;
import com.google.domain.registry.model.transfer.TransferData.TransferServerApproveEntity;
import com.google.domain.registry.model.transfer.TransferResponse.ContactTransferResponse;
import com.google.domain.registry.model.transfer.TransferResponse.DomainTransferResponse;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.EntitySubclass;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.Parent;
import org.joda.time.DateTime;
import java.util.List;
/** A poll message that is pending for a registrar. */
@Entity
@ExternalMessagingName("message")
public abstract class PollMessage
extends ImmutableObject implements Buildable, TransferServerApproveEntity {
public static final Converter<Key<PollMessage>, String> EXTERNAL_KEY_CONVERTER =
new PollMessageExternalKeyConverter();
/** Entity id. */
@Id
long id;
@Parent
Key<HistoryEntry> parent;
/** The registrar that this poll message will be delivered to. */
@Index
String clientId;
/** The time when the poll message should be delivered. May be in the future. */
@Index
DateTime eventTime;
/** Human readable message that will be returned with this poll message. */
String msg;
public Key<HistoryEntry> getParentKey() {
return parent;
}
public Long getId() {
return id;
}
public String getClientId() {
return clientId;
}
public DateTime getEventTime() {
return eventTime;
}
public String getMsg() {
return msg;
}
public abstract ImmutableList<ResponseData> getResponseData();
public abstract ImmutableList<ResponseExtension> getResponseExtensions();
/** Override Buildable.asBuilder() to give this method stronger typing. */
@Override
public abstract Builder<?, ?> asBuilder();
/** Builder for {@link PollMessage} because it is immutable. */
@VisibleForTesting
public abstract static class Builder<T extends PollMessage, B extends Builder<?, ?>>
extends GenericBuilder<T, B> {
protected Builder() {}
protected Builder(T instance) {
super(instance);
}
@VisibleForTesting
public B setId(Long id) {
getInstance().id = id;
return thisCastToDerived();
}
public B setClientId(String clientId) {
getInstance().clientId = clientId;
return thisCastToDerived();
}
public B setEventTime(DateTime eventTime) {
getInstance().eventTime = eventTime;
return thisCastToDerived();
}
public B setMsg(String msg) {
getInstance().msg = msg;
return thisCastToDerived();
}
public B setParent(HistoryEntry parent) {
getInstance().parent = Key.create(parent);
return thisCastToDerived();
}
public B setParentKey(Key<HistoryEntry> parentKey) {
getInstance().parent = parentKey;
return thisCastToDerived();
}
@Override
public T build() {
T instance = getInstance();
checkNotNull(instance.clientId);
checkNotNull(instance.eventTime);
checkNotNull(instance.parent);
return super.build();
}
}
/** A one-time poll message. */
@EntitySubclass(index = false)
public static class OneTime extends PollMessage {
// Response data. Objectify cannot persist a base class type, so we must have a separate field
// to hold every possible derived type of ResponseData that we might store.
List<ContactPendingActionNotificationResponse> contactPendingActionNotificationResponses;
List<ContactTransferResponse> contactTransferResponses;
List<DomainPendingActionNotificationResponse> domainPendingActionNotificationResponses;
List<DomainTransferResponse> domainTransferResponses;
// Extensions. Objectify cannot persist a base class type, so we must have a separate field
// to hold every possible derived type of ResponseExtensions that we might store.
//
// Note that we cannot store a list of LaunchInfoResponseExtension objects since it contains a
// list of embedded Mark objects, and embedded lists of lists are not allowed. This shouldn't
// matter since there's no scenario where multiple launch info response extensions are ever
// returned.
LaunchInfoResponseExtension launchInfoResponseExtension;
@Override
public Builder asBuilder() {
return new Builder(clone(this));
}
@Override
public ImmutableList<ResponseData> getResponseData() {
return new ImmutableList.Builder<ResponseData>()
.addAll(nullToEmpty(contactPendingActionNotificationResponses))
.addAll(nullToEmpty(contactTransferResponses))
.addAll(nullToEmpty(domainPendingActionNotificationResponses))
.addAll(nullToEmpty(domainTransferResponses))
.build();
}
/**
* Returns the class of the parent EppResource that this poll message is associated with,
* either DomainBase or ContactResource.
*/
public Class<? extends EppResource> getParentResourceClass() {
if (!isNullOrEmpty(domainPendingActionNotificationResponses)
|| !isNullOrEmpty(domainTransferResponses)) {
return DomainBase.class;
} else if (!isNullOrEmpty(contactPendingActionNotificationResponses)
|| !isNullOrEmpty(contactTransferResponses)) {
return ContactResource.class;
} else {
throw new IllegalStateException(String.format(
"PollMessage.OneTime %s does not correspond with an EppResource of a known type",
Key.create(this)));
}
}
@Override
public ImmutableList<ResponseExtension> getResponseExtensions() {
return (launchInfoResponseExtension == null) ? ImmutableList.<ResponseExtension>of() :
ImmutableList.<ResponseExtension>of(launchInfoResponseExtension);
}
/** A builder for {@link OneTime} since it is immutable. */
@VisibleForTesting
public static class Builder extends PollMessage.Builder<OneTime, Builder> {
public Builder() {}
private Builder(OneTime instance) {
super(instance);
}
public Builder setResponseData(ImmutableList<? extends ResponseData> responseData) {
FluentIterable<? extends ResponseData> iterable = FluentIterable.from(responseData);
getInstance().contactPendingActionNotificationResponses = forceEmptyToNull(
iterable.filter(ContactPendingActionNotificationResponse.class).toList());
getInstance().contactTransferResponses = forceEmptyToNull(
iterable.filter(ContactTransferResponse.class).toList());
getInstance().domainPendingActionNotificationResponses = forceEmptyToNull(
iterable.filter(DomainPendingActionNotificationResponse.class).toList());
getInstance().domainTransferResponses = forceEmptyToNull(
iterable.filter(DomainTransferResponse.class).toList());
return this;
}
public Builder setResponseExtensions(
ImmutableList<? extends ResponseExtension> responseExtensions) {
getInstance().launchInfoResponseExtension = FluentIterable
.from(responseExtensions)
.filter(LaunchInfoResponseExtension.class)
.first()
.orNull();
return this;
}
}
}
/** An autorenew poll message which recurs annually. */
@EntitySubclass(index = false)
public static class Autorenew extends PollMessage {
/** The target id of the autorenew event. */
String targetId;
/** The autorenew recurs annually between {@link #eventTime} and this time. */
@Index
DateTime autorenewEndTime;
public String getTargetId() {
return targetId;
}
public DateTime getAutorenewEndTime() {
return autorenewEndTime;
}
@Override
public ImmutableList<ResponseData> getResponseData() {
// Note that the event time is when the auto-renew occured, so the expiration time in the
// response should be 1 year past that, since it denotes the new expiration time.
return ImmutableList.<ResponseData>of(
DomainRenewData.create(getTargetId(), getEventTime().plusYears(1)));
}
@Override
public ImmutableList<ResponseExtension> getResponseExtensions() {
return ImmutableList.of();
}
@Override
public Builder asBuilder() {
return new Builder(clone(this));
}
/** A builder for {@link Autorenew} since it is immutable. */
@VisibleForTesting
public static class Builder extends PollMessage.Builder<Autorenew, Builder> {
public Builder() {}
private Builder(Autorenew instance) {
super(instance);
}
public Builder setTargetId(String targetId) {
getInstance().targetId = targetId;
return this;
}
public Builder setAutorenewEndTime(DateTime autorenewEndTime) {
getInstance().autorenewEndTime = autorenewEndTime;
return this;
}
@Override
public Autorenew build() {
Autorenew instance = getInstance();
instance.autorenewEndTime =
Optional.fromNullable(instance.autorenewEndTime).or(END_OF_TIME);
return super.build();
}
}
}
}

View file

@ -0,0 +1,106 @@
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.model.poll;
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.base.Converter;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableBiMap;
import com.google.domain.registry.model.EppResource;
import com.google.domain.registry.model.contact.ContactResource;
import com.google.domain.registry.model.domain.DomainBase;
import com.google.domain.registry.model.host.HostResource;
import com.google.domain.registry.model.reporting.HistoryEntry;
import com.googlecode.objectify.Key;
import java.util.List;
/**
* A converter between external key strings for PollMessages and Objectify Keys to the resource.
*
* <p>The format of the key string is A-B-C-D-E as follows:
*
* <pre>
* A = EppResource.typeId (decimal)
* B = EppResource.repoId prefix (STRING)
* C = EppResource.repoId suffix (STRING)
* D = HistoryEntry.id (decimal)
* E = PollMessage.id (decimal)
* </pre>
*/
public class PollMessageExternalKeyConverter extends Converter<Key<PollMessage>, String> {
/** An exception thrown when an external key cannot be parsed. */
public static class PollMessageExternalKeyParseException extends RuntimeException {}
/**
* A map of IDs used in external keys corresponding to which EppResource class the poll message
* belongs to.
*/
public static final ImmutableBiMap<Class<? extends EppResource>, Long> EXTERNAL_KEY_CLASS_ID_MAP =
ImmutableBiMap.<Class<? extends EppResource>, Long>of(
DomainBase.class, 1L,
ContactResource.class, 2L,
HostResource.class, 3L);
@Override
protected String doForward(Key<PollMessage> key) {
@SuppressWarnings("unchecked")
Key<EppResource> ancestorResource =
(Key<EppResource>) (Key<?>) key.getParent().getParent();
long externalKeyClassId = EXTERNAL_KEY_CLASS_ID_MAP.get(
ofy().factory().getMetadata(ancestorResource.getKind()).getEntityClass());
return String.format("%d-%s-%d-%d",
externalKeyClassId,
ancestorResource.getName(),
key.getParent().getId(),
key.getId());
}
/**
* Returns an Objectify Key to a PollMessage corresponding with the external key string.
*
* @throws PollMessageExternalKeyParseException if the external key has an invalid format.
*/
@Override
protected Key<PollMessage> doBackward(String externalKey) {
List<String> idComponents = Splitter.on('-').splitToList(externalKey);
if (idComponents.size() != 5) {
throw new PollMessageExternalKeyParseException();
}
try {
Class<?> resourceClazz =
EXTERNAL_KEY_CLASS_ID_MAP.inverse().get(Long.parseLong(idComponents.get(0)));
if (resourceClazz == null) {
throw new PollMessageExternalKeyParseException();
}
return Key.create(
Key.create(
Key.create(
null,
resourceClazz,
String.format("%s-%s", idComponents.get(1), idComponents.get(2))),
HistoryEntry.class,
Long.parseLong(idComponents.get(3))),
PollMessage.class,
Long.parseLong(idComponents.get(4)));
} catch (NumberFormatException e) {
throw new PollMessageExternalKeyParseException();
}
}
}

View file

@ -0,0 +1,31 @@
// Copyright 2016 The Domain Registry 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.
@XmlSchema(
namespace = "urn:ietf:params:xml:ns:epp-1.0",
xmlns = @XmlNs(prefix = "", namespaceURI = "urn:ietf:params:xml:ns:epp-1.0"),
elementFormDefault = XmlNsForm.QUALIFIED)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlJavaTypeAdapter(UtcDateTimeAdapter.class)
package com.google.domain.registry.model.poll;
import com.google.domain.registry.xml.UtcDateTimeAdapter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;