|
|
@@ -6,14 +6,15 @@ package bubble.dao.account; |
|
|
|
|
|
|
|
import bubble.dao.account.message.AccountMessageDAO; |
|
|
|
import bubble.model.account.Account; |
|
|
|
import bubble.model.account.AccountContact; |
|
|
|
import bubble.model.account.AccountPolicy; |
|
|
|
import bubble.model.account.message.AccountAction; |
|
|
|
import bubble.model.account.message.AccountMessage; |
|
|
|
import bubble.model.account.message.AccountMessageType; |
|
|
|
import bubble.model.account.message.ActionTarget; |
|
|
|
import bubble.model.cloud.BubbleNetwork; |
|
|
|
import bubble.server.BubbleConfiguration; |
|
|
|
import bubble.service.boot.SelfNodeService; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
@@ -23,32 +24,33 @@ import static java.util.concurrent.TimeUnit.SECONDS; |
|
|
|
import static org.cobbzilla.util.daemon.ZillaRuntime.die; |
|
|
|
import static org.cobbzilla.util.system.Sleep.sleep; |
|
|
|
|
|
|
|
@AllArgsConstructor @Slf4j |
|
|
|
@Slf4j |
|
|
|
public class AccountInitializer implements Runnable { |
|
|
|
|
|
|
|
public static final int MAX_ACCOUNT_INIT_RETRIES = 3; |
|
|
|
public static final long COPY_WAIT_TIME = SECONDS.toMillis(2); |
|
|
|
public static final long SEND_MESSAGE_WAIT_TIME = SECONDS.toMillis(1); |
|
|
|
|
|
|
|
private Account account; |
|
|
|
private AccountDAO accountDAO; |
|
|
|
private AccountPolicyDAO policyDAO; |
|
|
|
private AccountMessageDAO messageDAO; |
|
|
|
private SelfNodeService selfNodeService; |
|
|
|
private final Account account; |
|
|
|
private final AccountDAO accountDAO; |
|
|
|
private final AccountPolicyDAO policyDAO; |
|
|
|
private final AccountMessageDAO messageDAO; |
|
|
|
private final SelfNodeService selfNodeService; |
|
|
|
private final BubbleConfiguration configuration; |
|
|
|
|
|
|
|
private AtomicBoolean ready = new AtomicBoolean(false); |
|
|
|
private final AtomicBoolean ready = new AtomicBoolean(false); |
|
|
|
public boolean ready() { return ready.get(); } |
|
|
|
|
|
|
|
private AtomicBoolean canSendAccountMessages = new AtomicBoolean(false); |
|
|
|
private final AtomicBoolean canSendAccountMessages = new AtomicBoolean(false); |
|
|
|
public void setCanSendAccountMessages() { canSendAccountMessages.set(true); } |
|
|
|
|
|
|
|
private AtomicBoolean abort = new AtomicBoolean(false); |
|
|
|
private final AtomicBoolean abort = new AtomicBoolean(false); |
|
|
|
public void setAbort () { abort.set(true); } |
|
|
|
|
|
|
|
private AtomicBoolean completed = new AtomicBoolean(false); |
|
|
|
private final AtomicBoolean completed = new AtomicBoolean(false); |
|
|
|
public boolean completed () { return completed.get(); } |
|
|
|
|
|
|
|
private AtomicReference<Exception> error = new AtomicReference<>(); |
|
|
|
private final AtomicReference<Exception> error = new AtomicReference<>(); |
|
|
|
public Exception getError() { return error.get(); } |
|
|
|
public boolean hasError () { return getError() != null; } |
|
|
|
|
|
|
@@ -56,12 +58,14 @@ public class AccountInitializer implements Runnable { |
|
|
|
AccountDAO accountDAO, |
|
|
|
AccountPolicyDAO policyDAO, |
|
|
|
AccountMessageDAO messageDAO, |
|
|
|
SelfNodeService selfNodeService) { |
|
|
|
SelfNodeService selfNodeService, |
|
|
|
BubbleConfiguration configuration) { |
|
|
|
this.account = account; |
|
|
|
this.accountDAO = accountDAO; |
|
|
|
this.policyDAO = policyDAO; |
|
|
|
this.messageDAO = messageDAO; |
|
|
|
this.selfNodeService = selfNodeService; |
|
|
|
this.configuration = configuration; |
|
|
|
} |
|
|
|
|
|
|
|
@Override public void run() { |
|
|
@@ -88,7 +92,19 @@ public class AccountInitializer implements Runnable { |
|
|
|
} |
|
|
|
} |
|
|
|
if (!success) throw lastEx; |
|
|
|
if (account.sendWelcomeEmail()) { |
|
|
|
|
|
|
|
if (selfNodeService.getThisNetwork().local() && !configuration.testMode()) { |
|
|
|
// running locally, initial contact is always validated |
|
|
|
final String accountUuid = account.getUuid(); |
|
|
|
final AccountPolicy policy = policyDAO.findSingleByAccount(accountUuid); |
|
|
|
final AccountContact contact = policy != null && policy.hasAccountContacts() ? policy.getAccountContacts()[0] : null; |
|
|
|
if (contact == null) { |
|
|
|
die("no contact found for welcome message: account="+accountUuid); |
|
|
|
} else { |
|
|
|
policyDAO.update(policy.verifyContact(contact.getUuid())); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (account.sendWelcomeEmail()) { |
|
|
|
final BubbleNetwork thisNetwork = selfNodeService.getThisNetwork(); |
|
|
|
final String accountUuid = account.getUuid(); |
|
|
|
final AccountPolicy policy = policyDAO.findSingleByAccount(accountUuid); |
|
|
|