Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Addresses comments on PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
alokmenghrajani committed Apr 17, 2015
1 parent 82bec7c commit 7d81588
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions server/src/main/java/keywhiz/service/daos/ClientDAO.java
Expand Up @@ -16,7 +16,7 @@

package keywhiz.service.daos;

import java.util.HashSet;
import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -50,28 +50,25 @@ public long createClient(String name, String user, Optional<String> description)
}

public void deleteClient(Client client) {
ClientsRecord r = dslContext.fetchOne(CLIENTS, CLIENTS.ID.eq(Math.toIntExact(client.getId())));
r.delete();
dslContext.delete(CLIENTS).where(CLIENTS.ID.eq(Math.toIntExact(client.getId()))).execute();
}

public Optional<Client> getClient(String name) {
ClientsRecord r = dslContext.fetchOne(CLIENTS, CLIENTS.NAME.eq(name));
if (r != null) {
return Optional.of(r.map(new ClientMapper()));
}
return Optional.empty();
return Optional.ofNullable(r).map(
(rec) -> rec.map(new ClientMapper()));
}

public Optional<Client> getClientById(long id) {
ClientsRecord r = dslContext.fetchOne(CLIENTS, CLIENTS.ID.eq((int)id));
ClientsRecord r = dslContext.fetchOne(CLIENTS, CLIENTS.ID.eq(Math.toIntExact(id)));
if (r != null) {
return Optional.of(r.map(new ClientMapper()));
}
return Optional.empty();
}

public Set<Client> getClients() {
public ImmutableSet<Client> getClients() {
List<Client> r = dslContext.select().from(CLIENTS).fetch().map(new ClientMapper());
return new HashSet<>(r);
return ImmutableSet.copyOf(r);
}
}
Expand Up @@ -63,7 +63,7 @@ public class ClientsResourceTest {
Client client1 = new Client(1, "client", "1st client", now, "test", now, "test", true, false);
Client client2 = new Client(2, "client2", "2nd client", now, "test", now, "test", true, false);

when(clientDAO.getClients()).thenReturn(Sets.newHashSet(client1, client2));
when(clientDAO.getClients()).thenReturn(ImmutableSet.of(client1, client2));

List<Client> response = resource.listClients(user);
assertThat(response).containsOnly(client1, client2);
Expand Down

0 comments on commit 7d81588

Please sign in to comment.