List of usage examples for org.joda.time DateTime plus
public DateTime plus(ReadablePeriod period)
From source file:google.registry.flows.domain.DomainCreateFlow.java
License:Open Source License
private OneTime createOneTimeBillingEvent(Registry registry, boolean isAnchorTenant, int years, FeesAndCredits feesAndCredits, HistoryEntry historyEntry, DateTime now) { return new BillingEvent.OneTime.Builder().setReason(Reason.CREATE).setTargetId(targetId) .setClientId(clientId).setPeriodYears(years).setCost(feesAndCredits.getCreateCost()) .setEventTime(now)/*from w w w . ja va 2s .c om*/ .setBillingTime(now.plus(isAnchorTenant ? registry.getAnchorTenantAddGracePeriodLength() : registry.getAddGracePeriodLength())) .setFlags(isAnchorTenant ? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT) : ImmutableSet.<BillingEvent.Flag>of()) .setParent(historyEntry).build(); }
From source file:google.registry.flows.domain.DomainDeleteFlow.java
License:Open Source License
@Override public final EppResponse run() throws EppException { extensionManager.register(MetadataExtension.class, SecDnsCreateExtension.class); customLogic.beforeValidation();//from ww w . j a v a 2 s .com extensionManager.validate(); validateClientIsLoggedIn(clientId); DateTime now = ofy().getTransactionTime(); // Loads the target resource if it exists DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now); Registry registry = Registry.get(existingDomain.getTld()); verifyDeleteAllowed(existingDomain, registry, now); customLogic .afterValidation(AfterValidationParameters.newBuilder().setExistingDomain(existingDomain).build()); ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>(); HistoryEntry historyEntry = buildHistoryEntry(existingDomain, now); Builder builder = existingDomain.getStatusValues().contains(StatusValue.PENDING_TRANSFER) ? ResourceFlowUtils.<DomainResource, DomainResource.Builder>resolvePendingTransfer(existingDomain, TransferStatus.SERVER_CANCELLED, now) : existingDomain.asBuilder(); builder.setDeletionTime(now).setStatusValues(null); // If the domain is in the Add Grace Period, we delete it immediately, which is already // reflected in the builder we just prepared. Otherwise we give it a PENDING_DELETE status. if (!existingDomain.getGracePeriodStatuses().contains(GracePeriodStatus.ADD)) { // By default, this should be 30 days of grace, and 5 days of pending delete. DateTime deletionTime = now.plus(registry.getRedemptionGracePeriodLength()) .plus(registry.getPendingDeleteLength()); PollMessage.OneTime deletePollMessage = createDeletePollMessage(existingDomain, historyEntry, deletionTime); entitiesToSave.add(deletePollMessage); builder.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)).setDeletionTime(deletionTime) // Clear out all old grace periods and add REDEMPTION, which does not include a key to a // billing event because there isn't one for a domain delete. .setGracePeriods( ImmutableSet.of(GracePeriod.createWithoutBillingEvent(GracePeriodStatus.REDEMPTION, now.plus(registry.getRedemptionGracePeriodLength()), clientId))) .setDeletePollMessage(Key.create(deletePollMessage)); } DomainResource newDomain = builder.build(); updateForeignKeyIndexDeletionTime(newDomain); handlePendingTransferOnDelete(existingDomain, newDomain, now, historyEntry); // Close the autorenew billing event and poll message. This may delete the poll message. updateAutorenewRecurrenceEndTime(existingDomain, now); // If there's a pending transfer, the gaining client's autorenew billing // event and poll message will already have been deleted in // ResourceDeleteFlow since it's listed in serverApproveEntities. dnsQueue.addDomainRefreshTask(existingDomain.getFullyQualifiedDomainName()); // Cancel any grace periods that were still active. for (GracePeriod gracePeriod : existingDomain.getGracePeriods()) { // No cancellation is written if the grace period was not for a billable event. if (gracePeriod.hasBillingEvent()) { entitiesToSave.add(BillingEvent.Cancellation.forGracePeriod(gracePeriod, historyEntry, targetId)); } } entitiesToSave.add(newDomain, historyEntry); EntityChanges entityChanges = customLogic.beforeSave(BeforeSaveParameters.newBuilder() .setExistingDomain(existingDomain).setNewDomain(newDomain).setHistoryEntry(historyEntry) .setEntityChanges(EntityChanges.newBuilder().setSaves(entitiesToSave.build()).build()).build()); persistEntityChanges(entityChanges); BeforeResponseReturnData responseData = customLogic.beforeResponse(BeforeResponseParameters.newBuilder() .setResultCode(newDomain.getDeletionTime().isAfter(now) ? SUCCESS_WITH_ACTION_PENDING : SUCCESS) .setResponseExtensions(getResponseExtensions(existingDomain, now)).build()); return responseBuilder.setResultFromCode(responseData.resultCode()) .setExtensions(responseData.responseExtensions()).build(); }
From source file:google.registry.flows.domain.DomainRenewFlow.java
License:Open Source License
private OneTime createRenewBillingEvent(String tld, Money renewCost, int years, HistoryEntry historyEntry, DateTime now) { return new BillingEvent.OneTime.Builder().setReason(Reason.RENEW).setTargetId(targetId) .setClientId(clientId).setPeriodYears(years).setCost(renewCost).setEventTime(now) .setBillingTime(now.plus(Registry.get(tld).getRenewGracePeriodLength())).setParent(historyEntry) .build();/*w w w . java 2 s. c om*/ }
From source file:google.registry.flows.domain.DomainTransferApproveFlow.java
License:Open Source License
/** * <p>The logic in this flow, which handles client approvals, very closely parallels the logic in * {@link DomainResource#cloneProjectedAtTime} which handles implicit server approvals. *///from w ww.j ava 2 s.co m @Override public final EppResponse run() throws EppException { extensionManager.register(MetadataExtension.class); extensionManager.validate(); validateClientIsLoggedIn(clientId); DateTime now = ofy().getTransactionTime(); DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now); verifyOptionalAuthInfo(authInfo, existingDomain); verifyHasPendingTransfer(existingDomain); verifyResourceOwnership(clientId, existingDomain); String tld = existingDomain.getTld(); checkAllowedAccessToTld(clientId, tld); TransferData transferData = existingDomain.getTransferData(); String gainingClientId = transferData.getGainingClientId(); HistoryEntry historyEntry = historyBuilder.setType(HistoryEntry.Type.DOMAIN_TRANSFER_APPROVE) .setModificationTime(now).setOtherClientId(gainingClientId).setParent(Key.create(existingDomain)) .build(); int extraYears = transferData.getExtendedRegistrationYears(); // Bill for the transfer. BillingEvent.OneTime billingEvent = new BillingEvent.OneTime.Builder().setReason(Reason.TRANSFER) .setTargetId(targetId).setClientId(gainingClientId).setPeriodYears(extraYears) .setCost(getDomainRenewCost(targetId, transferData.getTransferRequestTime(), extraYears)) .setEventTime(now).setBillingTime(now.plus(Registry.get(tld).getTransferGracePeriodLength())) .setParent(historyEntry).build(); // If we are within an autorenew grace period, cancel the autorenew billing event and reduce // the number of years to extend the registration by one. GracePeriod autorenewGrace = getOnlyElement( filter(existingDomain.getGracePeriods(), new Predicate<GracePeriod>() { @Override public boolean apply(GracePeriod gracePeriod) { return GracePeriodStatus.AUTO_RENEW.equals(gracePeriod.getType()); } }), null); if (autorenewGrace != null) { extraYears--; ofy().save().entity(BillingEvent.Cancellation.forGracePeriod(autorenewGrace, historyEntry, targetId)); } // Close the old autorenew event and poll message at the transfer time (aka now). This may end // up deleting the poll message. updateAutorenewRecurrenceEndTime(existingDomain, now); DateTime newExpirationTime = extendRegistrationWithCap(now, existingDomain.getRegistrationExpirationTime(), extraYears); // Create a new autorenew event starting at the expiration time. BillingEvent.Recurring autorenewEvent = new BillingEvent.Recurring.Builder().setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)).setTargetId(targetId).setClientId(gainingClientId) .setEventTime(newExpirationTime).setRecurrenceEndTime(END_OF_TIME).setParent(historyEntry).build(); // Create a new autorenew poll message. PollMessage.Autorenew gainingClientAutorenewPollMessage = new PollMessage.Autorenew.Builder() .setTargetId(targetId).setClientId(gainingClientId).setEventTime(newExpirationTime) .setAutorenewEndTime(END_OF_TIME).setMsg("Domain was auto-renewed.").setParent(historyEntry) .build(); DomainResource newDomain = approvePendingTransfer(existingDomain, TransferStatus.CLIENT_APPROVED, now) .asBuilder().setRegistrationExpirationTime(newExpirationTime) .setAutorenewBillingEvent(Key.create(autorenewEvent)) .setAutorenewPollMessage(Key.create(gainingClientAutorenewPollMessage)) // Remove all the old grace periods and add a new one for the transfer. .setGracePeriods( ImmutableSet.of(GracePeriod.forBillingEvent(GracePeriodStatus.TRANSFER, billingEvent))) .build(); // Create a poll message for the gaining client. PollMessage gainingClientPollMessage = createGainingTransferPollMessage(targetId, newDomain.getTransferData(), newExpirationTime, historyEntry); ofy().save().<ImmutableObject>entities(newDomain, historyEntry, billingEvent, autorenewEvent, gainingClientPollMessage, gainingClientAutorenewPollMessage); // Delete the billing event and poll messages that were written in case the transfer would have // been implicitly server approved. ofy().delete().keys(existingDomain.getTransferData().getServerApproveEntities()); return responseBuilder.setResData(createTransferResponse(targetId, newDomain.getTransferData(), newDomain.getRegistrationExpirationTime())).build(); }
From source file:google.registry.flows.domain.DomainTransferRequestFlow.java
License:Open Source License
@Override public final EppResponse run() throws EppException { extensionManager.register(FeeTransferCommandExtension.class, MetadataExtension.class); extensionManager.validate();//from ww w . j av a 2 s.co m validateClientIsLoggedIn(gainingClientId); Period period = ((Transfer) resourceCommand).getPeriod(); int years = period.getValue(); DateTime now = ofy().getTransactionTime(); DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now); verifyTransferAllowed(existingDomain, period, now); String tld = existingDomain.getTld(); Registry registry = Registry.get(tld); // An optional extension from the client specifying what they think the transfer should cost. FeeTransferCommandExtension feeTransfer = eppInput.getSingleExtension(FeeTransferCommandExtension.class); FeesAndCredits feesAndCredits = pricingLogic.getTransferPrice(registry, targetId, now, years); validateFeeChallenge(targetId, tld, now, feeTransfer, feesAndCredits); HistoryEntry historyEntry = buildHistory(period, existingDomain, now); DateTime automaticTransferTime = now.plus(registry.getAutomaticTransferLength()); // The new expiration time if there is a server approval. DateTime serverApproveNewExpirationTime = extendRegistrationWithCap(automaticTransferTime, existingDomain.getRegistrationExpirationTime(), years); // Create speculative entities in anticipation of an automatic server approval. ImmutableSet<TransferServerApproveEntity> serverApproveEntities = createTransferServerApproveEntities( automaticTransferTime, serverApproveNewExpirationTime, historyEntry, existingDomain, feesAndCredits.getTotalCost(), years, now); // Create the transfer data that represents the pending transfer. TransferData pendingTransferData = createPendingTransferData( createTransferDataBuilder(existingDomain, automaticTransferTime, years, now), serverApproveEntities); // Create a poll message to notify the losing registrar that a transfer was requested. PollMessage requestPollMessage = createLosingTransferPollMessage(targetId, pendingTransferData, serverApproveNewExpirationTime, historyEntry).asBuilder().setEventTime(now).build(); // End the old autorenew event and poll message at the implicit transfer time. This may delete // the poll message if it has no events left. Note that if the automatic transfer succeeds, then // cloneProjectedAtTime() will replace these old autorenew entities with the server approve ones // that we've created in this flow and stored in pendingTransferData. updateAutorenewRecurrenceEndTime(existingDomain, automaticTransferTime); DomainResource newDomain = existingDomain.asBuilder().setTransferData(pendingTransferData) .addStatusValue(StatusValue.PENDING_TRANSFER).build(); ofy().save().entities(new ImmutableSet.Builder<>().add(newDomain, historyEntry, requestPollMessage) .addAll(serverApproveEntities).build()).now(); return responseBuilder.setResultFromCode(SUCCESS_WITH_ACTION_PENDING) .setResData(createResponse(period, existingDomain, newDomain, now)) .setExtensions(createResponseExtensions(feesAndCredits, feeTransfer)).build(); }
From source file:google.registry.flows.domain.DomainTransferRequestFlow.java
License:Open Source License
private BillingEvent.OneTime createTransferBillingEvent(DateTime automaticTransferTime, HistoryEntry historyEntry, Registry registry, Money transferCost, int years) { return new BillingEvent.OneTime.Builder().setReason(Reason.TRANSFER).setTargetId(targetId) .setClientId(gainingClientId).setCost(transferCost).setPeriodYears(years) .setEventTime(automaticTransferTime) .setBillingTime(automaticTransferTime.plus(registry.getTransferGracePeriodLength())) .setParent(historyEntry).build(); }
From source file:google.registry.flows.domain.DomainTransferRequestFlow.java
License:Open Source License
/** * Creates an optional autorenew cancellation if one would apply to the server-approved transfer. * * <p>If there will be an autorenew between now and the automatic transfer time, and if the * autorenew grace period length is long enough that the domain will still be within it at the * automatic transfer time, then the transfer will subsume the autorenew and we need to write out * a cancellation for it./* w w w. j a v a2 s .c o m*/ */ // TODO(b/19430703): the above logic is incomplete; it doesn't handle a grace period that started // before the transfer was requested and continues through the automatic transfer time. private Optional<BillingEvent.Cancellation> createOptionalAutorenewCancellation(DateTime automaticTransferTime, HistoryEntry historyEntry, DomainResource existingDomain) { Registry registry = Registry.get(existingDomain.getTld()); DateTime oldExpirationTime = existingDomain.getRegistrationExpirationTime(); Duration autoRenewGracePeriodLength = registry.getAutoRenewGracePeriodLength(); if (automaticTransferTime.isAfter(oldExpirationTime) && automaticTransferTime.isBefore(oldExpirationTime.plus(autoRenewGracePeriodLength))) { return Optional.of(new BillingEvent.Cancellation.Builder().setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)).setTargetId(targetId) .setClientId(existingDomain.getCurrentSponsorClientId()).setEventTime(automaticTransferTime) .setBillingTime(existingDomain.getRegistrationExpirationTime() .plus(registry.getAutoRenewGracePeriodLength())) .setRecurringEventKey(existingDomain.getAutorenewBillingEvent()).setParent(historyEntry) .build()); } return Optional.absent(); }
From source file:google.registry.flows.domain.DomainTransferUtils.java
License:Open Source License
private static BillingEvent.OneTime createTransferBillingEvent(DateTime automaticTransferTime, HistoryEntry historyEntry, String targetId, String gainingClientId, Registry registry, Money transferCost, int years) { return new BillingEvent.OneTime.Builder().setReason(Reason.TRANSFER).setTargetId(targetId) .setClientId(gainingClientId).setCost(transferCost).setPeriodYears(years) .setEventTime(automaticTransferTime) .setBillingTime(automaticTransferTime.plus(registry.getTransferGracePeriodLength())) .setParent(historyEntry).build(); }
From source file:google.registry.flows.domain.DomainUpdateFlow.java
License:Open Source License
private BillingEvent.OneTime createBillingEventForSunrushConversion(DomainResource existingDomain, HistoryEntry historyEntry, GracePeriod sunrushAddGracePeriod, DateTime now) { // Compute the expiration time of the add grace period. We will not allow it to be after the // sunrush add grace period expiration time (i.e. you can't get extra add grace period by // setting a nameserver). DateTime addGracePeriodExpirationTime = earliestOf( now.plus(Registry.get(existingDomain.getTld()).getAddGracePeriodLength()), sunrushAddGracePeriod.getExpirationTime()); // Create a new billing event for the add grace period. Note that we do this even if it would // occur at the same time as the sunrush add grace period, as the event time will differ // between them. BillingEvent.OneTime originalAddEvent = ofy().load().key(sunrushAddGracePeriod.getOneTimeBillingEvent()) .now();/*www. ja v a2s. c o m*/ return new BillingEvent.OneTime.Builder().setReason(Reason.CREATE).setTargetId(targetId) .setFlags(originalAddEvent.getFlags()).setClientId(sunrushAddGracePeriod.getClientId()) .setCost(originalAddEvent.getCost()).setPeriodYears(originalAddEvent.getPeriodYears()) .setEventTime(now).setBillingTime(addGracePeriodExpirationTime).setParent(historyEntry).build(); }
From source file:google.registry.model.domain.DomainResource.java
License:Open Source License
/** * The logic in this method, which handles implicit server approval of transfers, very closely * parallels the logic in {@code DomainTransferApproveFlow} which handles explicit client * approvals.//from w ww. j a va 2 s. c o m */ @Override public DomainResource cloneProjectedAtTime(final DateTime now) { TransferData transferData = getTransferData(); DateTime transferExpirationTime = transferData.getPendingTransferExpirationTime(); // If there's a pending transfer that has expired, handle it. if (TransferStatus.PENDING.equals(transferData.getTransferStatus()) && isBeforeOrAt(transferExpirationTime, now)) { // Project until just before the transfer time. This will handle the case of an autorenew // before the transfer was even requested or during the request period. // If the transfer time is precisely the moment that the domain expires, there will not be an // autorenew billing event (since we end the recurrence at transfer time and recurrences are // exclusive of their ending), and we can just proceed with the transfer. DomainResource domainAtTransferTime = cloneProjectedAtTime(transferExpirationTime.minusMillis(1)); // If we are within an autorenew grace period, the transfer will subsume the autorenew. There // will already be a cancellation written in advance by the transfer request flow, so we don't // need to worry about billing, but we do need to reduce the number of years added to the // expiration time by one to account for the year added by the autorenew. int extraYears = transferData.getExtendedRegistrationYears(); if (domainAtTransferTime.getGracePeriodStatuses().contains(GracePeriodStatus.AUTO_RENEW)) { extraYears--; } // Set the expiration, autorenew events, and grace period for the transfer. (Transfer ends // all other graces). Builder builder = domainAtTransferTime.asBuilder() // Extend the registration by the correct number of years from the expiration time that // was current on the domain right before the transfer, capped at 10 years from the // moment of the transfer. .setRegistrationExpirationTime(extendRegistrationWithCap(transferExpirationTime, domainAtTransferTime.getRegistrationExpirationTime(), extraYears)) // Set the speculatively-written new autorenew events as the domain's autorenew events. .setAutorenewBillingEvent(transferData.getServerApproveAutorenewEvent()) .setAutorenewPollMessage(transferData.getServerApproveAutorenewPollMessage()) // Set the grace period using a key to the prescheduled transfer billing event. Not using // GracePeriod.forBillingEvent() here in order to avoid the actual datastore fetch. .setGracePeriods(ImmutableSet.of(GracePeriod.create(GracePeriodStatus.TRANSFER, transferExpirationTime.plus(Registry.get(getTld()).getTransferGracePeriodLength()), transferData.getGainingClientId(), transferData.getServerApproveBillingEvent()))); // Set all remaining transfer properties. setAutomaticTransferSuccessProperties(builder, transferData); // Finish projecting to now. return builder.build().cloneProjectedAtTime(now); } // There is no transfer. Do any necessary autorenews. Builder builder = asBuilder(); if (isBeforeOrAt(registrationExpirationTime, now)) { // Autorenew by the number of years between the old expiration time and now. DateTime lastAutorenewTime = leapSafeAddYears(registrationExpirationTime, new Interval(registrationExpirationTime, now).toPeriod().getYears()); DateTime newExpirationTime = lastAutorenewTime.plusYears(1); builder.setRegistrationExpirationTime(newExpirationTime) .addGracePeriod(GracePeriod.createForRecurring(GracePeriodStatus.AUTO_RENEW, lastAutorenewTime.plus(Registry.get(getTld()).getAutoRenewGracePeriodLength()), getCurrentSponsorClientId(), autorenewBillingEvent)); } // Remove any grace periods that have expired. DomainResource almostBuilt = builder.build(); builder = almostBuilt.asBuilder(); for (GracePeriod gracePeriod : almostBuilt.getGracePeriods()) { if (isBeforeOrAt(gracePeriod.getExpirationTime(), now)) { builder.removeGracePeriod(gracePeriod); } } // Handle common properties like setting or unsetting linked status. This also handles the // general case of pending transfers for other resource types, but since we've always handled // a pending transfer by this point that's a no-op for domains. projectResourceOntoBuilderAtTime(almostBuilt, builder, now); return builder.build(); }