コード例 #1
0
  /**
   * Converts a given ConnectionProvider into a DTO used for marshaling.
   *
   * @param connectionProvider The ConnectionProvider to be converted.
   * @param showAuthTypes boolean value that specifies whether details about supported
   *     authentication types are included
   * @return ConnectionProviderResponseDTO that represents the ConnectionProvider
   */
  public static ConnectionProviderResponseDTO toDTO(
      ConnectionProvider connectionProvider, boolean showAuthTypes) {
    ConnectionProviderResponseDTO providerDTO = new ConnectionProviderResponseDTO();
    providerDTO.displayName = connectionProvider.getDisplayName();
    providerDTO.id = connectionProvider.getId();
    providerDTO.type = connectionProvider.getType();

    if (showAuthTypes) {
      addAuthTypesToConnectionProvidersResponseDTO(connectionProvider, providerDTO);
    }

    return providerDTO;
  }
コード例 #2
0
 private static void addAuthTypesToConnectionProvidersResponseDTO(
     ConnectionProvider connectionProvider, ConnectionProviderResponseDTO providerDTO) {
   // TODO: (@W) This needs some serious refactoring
   List<AuthTypeResponseDTO> authTypeResponseDTOList = new ArrayList<>();
   for (AuthType supportedAuthType : connectionProvider.getSupportedAuthTypes()) {
     AuthTypeResponseDTO.Builder authTypeDTOBuilder = new AuthTypeResponseDTO.Builder();
     authTypeDTOBuilder.type(supportedAuthType.toString());
     if (supportedAuthType.equals(AuthType.USERNAME_PASSWORD)) {
       authTypeDTOBuilder.usernameLabel(connectionProvider.getUsernameLabel());
       authTypeDTOBuilder.passwordLabel(connectionProvider.getPasswordLabel());
     }
     if (supportedAuthType.equals(AuthType.OAUTH)) {
       authTypeDTOBuilder.oauthEndpoint(
           String.format(OAUTH_ENDPOINT_PATTERN, connectionProvider.getId()));
       authTypeDTOBuilder.commandLabel("Connect to " + connectionProvider.getDisplayName());
     }
     authTypeResponseDTOList.add(authTypeDTOBuilder.build());
   }
   AuthTypeResponsesDTO authTypeResponsesDTO = new AuthTypeResponsesDTO();
   authTypeResponsesDTO.setAuthTypes(authTypeResponseDTOList);
   providerDTO.authTypes = authTypeResponsesDTO;
 }