Search in sources :

Example 1 with AccountEmail

use of org.killbill.billing.account.api.AccountEmail in project killbill by killbill.

the class AccountResource method getEmails.

/*
     * *************************     EMAILS     *****************************
     */
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + EMAILS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an account emails", response = AccountEmailJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied") })
public Response getEmails(@PathParam(ID_PARAM_NAME) final String id, @javax.ws.rs.core.Context final HttpServletRequest request) {
    final UUID accountId = UUID.fromString(id);
    final List<AccountEmail> emails = accountUserApi.getEmails(accountId, context.createContext(request));
    final List<AccountEmailJson> emailsJson = new ArrayList<AccountEmailJson>();
    for (final AccountEmail email : emails) {
        emailsJson.add(new AccountEmailJson(email.getAccountId().toString(), email.getEmail()));
    }
    return Response.status(Status.OK).entity(emailsJson).build();
}
Also used : AccountEmailJson(org.killbill.billing.jaxrs.json.AccountEmailJson) AccountEmail(org.killbill.billing.account.api.AccountEmail) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with AccountEmail

use of org.killbill.billing.account.api.AccountEmail in project killbill by killbill.

the class TestAccountDao method testAddRemoveAccountEmail.

@Test(groups = "slow", description = "Test Account DAO: add and remove email")
public void testAddRemoveAccountEmail() throws AccountApiException {
    final UUID accountId = UUID.randomUUID();
    // Add a new e-mail
    final AccountEmail email = new DefaultAccountEmail(accountId, "test@gmail.com");
    accountDao.addEmail(new AccountEmailModelDao(email), internalCallContext);
    final List<AccountEmailModelDao> accountEmails = accountDao.getEmailsByAccountId(accountId, internalCallContext);
    Assert.assertEquals(accountEmails.size(), 1);
    Assert.assertEquals(accountEmails.get(0).getAccountId(), accountId);
    Assert.assertEquals(accountEmails.get(0).getEmail(), email.getEmail());
    // Verify audits
    final List<AuditLog> auditLogsForAccountEmail = auditDao.getAuditLogsForId(TableName.ACCOUNT_EMAIL, email.getId(), AuditLevel.FULL, internalCallContext);
    Assert.assertEquals(auditLogsForAccountEmail.size(), 1);
    Assert.assertEquals(auditLogsForAccountEmail.get(0).getChangeType(), ChangeType.INSERT);
    // Delete the e-mail
    accountDao.removeEmail(new AccountEmailModelDao(email), internalCallContext);
    Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 0);
}
Also used : DefaultAccountEmail(org.killbill.billing.account.api.DefaultAccountEmail) AccountEmail(org.killbill.billing.account.api.AccountEmail) DefaultAccountEmail(org.killbill.billing.account.api.DefaultAccountEmail) UUID(java.util.UUID) AuditLog(org.killbill.billing.util.audit.AuditLog) Test(org.testng.annotations.Test)

Example 3 with AccountEmail

use of org.killbill.billing.account.api.AccountEmail in project killbill by killbill.

the class DefaultAccountInternalApi method getEmails.

@Override
public List<AccountEmail> getEmails(final UUID accountId, final InternalTenantContext context) {
    final List<AccountEmailModelDao> childrenAccountsModelDao = accountDao.getEmailsByAccountId(accountId, context);
    final List<AccountEmail> emails = new LinkedList<AccountEmail>();
    for (final AccountEmailModelDao emailsModelDao : childrenAccountsModelDao) {
        emails.add(new DefaultAccountEmail(emailsModelDao));
    }
    return emails;
}
Also used : DefaultAccountEmail(org.killbill.billing.account.api.DefaultAccountEmail) AccountEmailModelDao(org.killbill.billing.account.dao.AccountEmailModelDao) AccountEmail(org.killbill.billing.account.api.AccountEmail) DefaultAccountEmail(org.killbill.billing.account.api.DefaultAccountEmail) LinkedList(java.util.LinkedList)

Example 4 with AccountEmail

use of org.killbill.billing.account.api.AccountEmail in project killbill by killbill.

the class DefaultAccountUserApi method getEmails.

@Override
public List<AccountEmail> getEmails(final UUID accountId, final TenantContext context) {
    final List<AccountEmailModelDao> childrenAccountsModelDao = accountDao.getEmailsByAccountId(accountId, internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(context));
    final List<AccountEmail> emails = new LinkedList<AccountEmail>();
    for (final AccountEmailModelDao emailsModelDao : childrenAccountsModelDao) {
        emails.add(new DefaultAccountEmail(emailsModelDao));
    }
    return emails;
}
Also used : DefaultAccountEmail(org.killbill.billing.account.api.DefaultAccountEmail) AccountEmailModelDao(org.killbill.billing.account.dao.AccountEmailModelDao) AccountEmail(org.killbill.billing.account.api.AccountEmail) DefaultAccountEmail(org.killbill.billing.account.api.DefaultAccountEmail) LinkedList(java.util.LinkedList)

Example 5 with AccountEmail

use of org.killbill.billing.account.api.AccountEmail in project killbill by killbill.

the class TestAccountEmailJson method testToAccountEmail.

@Test(groups = "fast")
public void testToAccountEmail() throws Exception {
    final UUID accountId = UUID.randomUUID();
    final String email = UUID.randomUUID().toString();
    final AccountEmailJson accountEmailJson = new AccountEmailJson(accountId, email);
    Assert.assertEquals(accountEmailJson.getAccountId(), accountId);
    Assert.assertEquals(accountEmailJson.getEmail(), email);
    final AccountEmail accountEmail = accountEmailJson.toAccountEmail(UUID.randomUUID());
    Assert.assertEquals(accountEmail.getAccountId(), accountId);
    Assert.assertEquals(accountEmail.getEmail(), email);
}
Also used : AccountEmail(org.killbill.billing.account.api.AccountEmail) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

AccountEmail (org.killbill.billing.account.api.AccountEmail)14 UUID (java.util.UUID)8 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 DefaultAccountEmail (org.killbill.billing.account.api.DefaultAccountEmail)6 TimedResource (org.killbill.commons.metrics.TimedResource)6 Test (org.testng.annotations.Test)5 AccountEmailJson (org.killbill.billing.jaxrs.json.AccountEmailJson)4 ArrayList (java.util.ArrayList)3 Predicate (com.google.common.base.Predicate)2 LinkedList (java.util.LinkedList)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 AccountEmailModelDao (org.killbill.billing.account.dao.AccountEmailModelDao)2 AuditLog (org.killbill.billing.util.audit.AuditLog)2 CallContext (org.killbill.billing.util.callcontext.CallContext)2