Exemplo n.º 1
0
  /*
   * Retrieves the table description and returns the table status as a string.
   */
  public static String getTestTableStatus() {

    try {
      /*AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager
      .ddb();*/
      AmazonDynamoDBClient ddb = LoginActivity.clientManager.ddb();
      DescribeTableRequest request =
          new DescribeTableRequest().withTableName(PropertyLoader.getInstance().getTestTableName());
      DescribeTableResult result = ddb.describeTable(request);

      String status = result.getTable().getTableStatus();
      return status == null ? "" : status;

    } catch (ResourceNotFoundException e) {
    } catch (AmazonServiceException ex) {
      LoginActivity.clientManager.wipeCredentialsOnAuthError(ex);
    }

    return "";
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws Exception {
    init();

    try {
      String violationsTable = "violations-table";
      String citationsTable = "citations-table";
      String warrantsTable = "warrants-table";
      String contactsTable = "contacts-table";
      String notificationsTable = "notifications-table";

      // VIOLATIONS TABLE
      //
      //

      // Create violationsTable if it does not exist yet
      if (Tables.doesTableExist(dynamoDB, violationsTable)) {
        System.out.println("Table " + violationsTable + " is already ACTIVE");
      } else {
        // Create a table with a primary hash key named 'name', which holds a string
        CreateTableRequest createTableRequest =
            new CreateTableRequest()
                .withTableName(violationsTable)
                .withKeySchema(
                    new KeySchemaElement()
                        .withAttributeName("citation_number")
                        .withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName("citation_number")
                        .withAttributeType(ScalarAttributeType.N))
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(25L)
                        .withWriteCapacityUnits(25L));
        TableDescription createdTableDescription =
            dynamoDB.createTable(createTableRequest).getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        System.out.println("Waiting for " + violationsTable + " to become ACTIVE...");
        Tables.awaitTableToBecomeActive(dynamoDB, violationsTable);
      }

      // Describe our new table
      DescribeTableRequest describeTableRequest =
          new DescribeTableRequest().withTableName(violationsTable);
      TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
      System.out.println("Table Description: " + tableDescription);

      // CITATIONS TABLE
      //
      //
      // Create citationsTable if it does not exist yet
      if (Tables.doesTableExist(dynamoDB, citationsTable)) {
        System.out.println("Table " + citationsTable + " is already ACTIVE");
      } else {
        // Create a table with a primary hash key named 'name', which holds a string
        /*
                        GlobalSecondaryIndex _firstLast = new GlobalSecondaryIndex()
                            .withIndexName("first_last")
                            .withProvisionedThroughput(new ProvisionedThroughput()
                                .withReadCapacityUnits((long) 10)
                                .withWriteCapacityUnits((long) 1))
                                .withProjection(new Projection().withProjectionType(ProjectionType.ALL));

                        GlobalSecondaryIndex _firstLastDOB = new GlobalSecondaryIndex()
                            .withIndexName("first_last_dob")
                            .withProvisionedThroughput(new ProvisionedThroughput()
                                .withReadCapacityUnits((long) 10)
                                .withWriteCapacityUnits((long) 1))
                                .withProjection(new Projection().withProjectionType(ProjectionType.ALL));
        */
        CreateTableRequest createTableRequest =
            new CreateTableRequest()
                .withTableName(citationsTable)
                .withKeySchema(
                    new KeySchemaElement()
                        .withAttributeName("first_last")
                        .withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName("first_last")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(25L)
                        .withWriteCapacityUnits(25L));
        // .withGlobalSecondaryIndexes(_firstLast, _firstLastDOB);
        TableDescription createdTableDescription =
            dynamoDB.createTable(createTableRequest).getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        System.out.println("Waiting for " + citationsTable + " to become ACTIVE...");
        Tables.awaitTableToBecomeActive(dynamoDB, citationsTable);
      }

      // Describe our new table
      describeTableRequest = new DescribeTableRequest().withTableName(citationsTable);
      tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
      System.out.println("Table Description: " + tableDescription);

      // WARRANTS TABLE
      //
      //
      // Create warrantsTable if it does not exist yet
      if (Tables.doesTableExist(dynamoDB, warrantsTable)) {
        System.out.println("Table " + warrantsTable + " is already ACTIVE");
      } else {
        /*
                        GlobalSecondaryIndex _firstLastDOB = new GlobalSecondaryIndex()
                            .withIndexName("first_last_dob")
                            .withProvisionedThroughput(new ProvisionedThroughput()
                                .withReadCapacityUnits((long) 10)
                                .withWriteCapacityUnits((long) 1))
                                .withProjection(new Projection().withProjectionType(ProjectionType.ALL));
        */
        // Create a table with a primary hash key named 'name', which holds a string
        CreateTableRequest createTableRequest =
            new CreateTableRequest()
                .withTableName(warrantsTable)
                .withKeySchema(
                    new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName("id")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(25L)
                        .withWriteCapacityUnits(25L));
        // .withGlobalSecondaryIndexes(_firstLastDOB);
        TableDescription createdTableDescription =
            dynamoDB.createTable(createTableRequest).getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        System.out.println("Waiting for " + warrantsTable + " to become ACTIVE...");
        Tables.awaitTableToBecomeActive(dynamoDB, warrantsTable);
      }

      // Describe our new table
      describeTableRequest = new DescribeTableRequest().withTableName(warrantsTable);
      tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
      System.out.println("Table Description: " + tableDescription);

      // CONTACTS TABLE
      //
      //

      // Create violationsTable if it does not exist yet
      if (Tables.doesTableExist(dynamoDB, contactsTable)) {
        System.out.println("Table " + contactsTable + " is already ACTIVE");
      } else {
        // Create a table with a primary hash key named 'name', which holds a string
        CreateTableRequest createTableRequest =
            new CreateTableRequest()
                .withTableName(contactsTable)
                .withKeySchema(
                    new KeySchemaElement()
                        .withAttributeName("first_last")
                        .withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName("first_last")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(25L)
                        .withWriteCapacityUnits(25L));
        TableDescription createdTableDescription =
            dynamoDB.createTable(createTableRequest).getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        System.out.println("Waiting for " + contactsTable + " to become ACTIVE...");
        Tables.awaitTableToBecomeActive(dynamoDB, contactsTable);
      }

      // Describe our new table
      describeTableRequest = new DescribeTableRequest().withTableName(violationsTable);
      tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
      System.out.println("Table Description: " + tableDescription);

      ssnHashMap = new HashMap<>();
      saltHashMap = new HashMap<>();
      hashedssnHashMap = new HashMap<>();

      ssnList = new ArrayList<>();

      for (int i = 1010001; i < 1200001; i++) {
        SocialSecurityNumber ssn = new SocialSecurityNumber(i);
        String ssnString = ssn.toString();
        ssnList.add(ssnString);
      }
      /*
      for (String str : ssnList) {
          System.out.println("SSN: " + str);
      }
      */

      // oneTimeAddViolations();
      // oneTimeAddCitations();
      oneTimeAddWarrants();
      // oneTimeAddContacts();

    } catch (AmazonServiceException ase) {
      System.out.println(
          "Caught an AmazonServiceException, which means your request made it "
              + "to AWS, but was rejected with an error response for some reason.");
      System.out.println("Error Message:    " + ase.getMessage());
      System.out.println("HTTP Status Code: " + ase.getStatusCode());
      System.out.println("AWS Error Code:   " + ase.getErrorCode());
      System.out.println("Error Type:       " + ase.getErrorType());
      System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
      System.out.println(
          "Caught an AmazonClientException, which means the client encountered "
              + "a serious internal problem while trying to communicate with AWS, "
              + "such as not being able to access the network.");
      System.out.println("Error Message: " + ace.getMessage());
    }
  }