SecretDAO { public List<SecretSeriesAndContent> getSecretsByName(List<String> names) { checkArgument(!names.isEmpty()); SecretContentDAO secretContentDAO = secretContentDAOFactory.using(dslContext.configuration()); SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(dslContext.configuration()); List<SecretSeries> multipleSeries = secretSeriesDAO.getMultipleSecretSeriesByName(names); List<SecretSeriesAndContent> ret = new ArrayList<SecretSeriesAndContent>(); for (SecretSeries series : multipleSeries) { if (series.currentVersion().isPresent()) { long secretContentId = series.currentVersion().get(); Optional<SecretContent> secretContent = secretContentDAO.getSecretContentById(secretContentId); if (secretContent.isPresent()) { ret.add(SecretSeriesAndContent.of(series, secretContent.get())); } else { throw new NotFoundException("Secret not found."); } } } return ret; } SecretDAO(DSLContext dslContext, SecretContentDAOFactory secretContentDAOFactory,
      SecretSeriesDAOFactory secretSeriesDAOFactory, ContentCryptographer cryptographer); @VisibleForTesting long createSecret(String name, String encryptedSecret, String hmac,
      String creator, Map<String, String> metadata, long expiry, String description,
      @Nullable String type, @Nullable Map<String, String> generationOptions); @VisibleForTesting long createOrUpdateSecret(String name, String encryptedSecret, String hmac, String creator,
      Map<String, String> metadata, long expiry, String description, @Nullable String type,
      @Nullable Map<String, String> generationOptions); @VisibleForTesting long partialUpdateSecret(String name, String creator,
      PartialUpdateSecretRequestV2 request); boolean setExpiration(String name, Instant expiration); Optional<SecretSeriesAndContent> getSecretById(long secretId); Optional<SecretSeriesAndContent> getSecretByName(String name); List<SecretSeriesAndContent> getSecretsByName(List<String> names); ImmutableList<SecretSeriesAndContent> getSecrets(@Nullable Long expireMaxTime,
      @Nullable Group group, @Nullable Long expireMinTime, @Nullable String minName,
      @Nullable Integer limit); ImmutableList<SimpleEntry<Long, String>> getSecretsNameOnly(); ImmutableList<SecretSeriesAndContent> getSecretsBatched(int idx, int num,
      boolean newestFirst); Optional<ImmutableList<SanitizedSecret>> getSecretVersionsByName(String name,
      int versionIdx, int numVersions); void setCurrentSecretVersionByName(String name, long versionId, String updater); void deleteSecretsByName(String name); int countDeletedSecrets(); int countSecretsDeletedBeforeDate(DateTime deleteBefore); void dangerPermanentlyRemoveSecretsDeletedBeforeDate(DateTime deletedBefore,
      int sleepMillis);  }
@Test public void getSecretsByName() { List<String> secrets = List.of(secret1.series().name(), secret2b.series().name()); List<SecretSeriesAndContent> response = secretDAO.getSecretsByName(secrets); assertThat(response.size()).isEqualTo(2); assertThat(response).contains(secret1); assertThat(response).contains(secret2b); }
@Test public void getNonExistantSecretsByName() { List<String> secrets = List.of("notasecret", "alsonotasecret"); List<SecretSeriesAndContent> response = secretDAO.getSecretsByName(secrets); assertThat(response.size()).isEqualTo(0); }
@Test public void getDuplicateSecretsByName() { List<String> secrets = List.of(secret1.series().name(), secret2b.series().name(), secret1.series().name()); List<SecretSeriesAndContent> response = secretDAO.getSecretsByName(secrets); assertThat(response.size()).isEqualTo(2); assertThat(response).contains(secret1); assertThat(response).contains(secret2b); }