Search in sources :

Example 1 with Address

use of com.google.api.services.people.v1.model.Address in project GNS by MobilityFirst.

the class AWSEC2 method describeElasticIPs.

/**
   *
   * @param ec2
   */
public static void describeElasticIPs(AmazonEC2 ec2) {
    StringBuilder output = new StringBuilder();
    String prefix = currentTab + "Elastic IPs: ";
    DescribeAddressesResult describeAddressesResult = ec2.describeAddresses();
    for (Address address : describeAddressesResult.getAddresses()) {
        output.append(prefix);
        prefix = ", ";
        output.append(address.getPublicIp());
    }
    System.out.println(output);
}
Also used : Address(com.amazonaws.services.ec2.model.Address) DescribeAddressesResult(com.amazonaws.services.ec2.model.DescribeAddressesResult)

Example 2 with Address

use of com.google.api.services.people.v1.model.Address in project BachelorPraktikum by lucasbuschlinger.

the class GooglePlaces method fetchOwnAddresses.

// /**
// * Setter for the query keyword search params.
// * @param keywordSearchParams valid search params that will be appended to the query
// */
// public void setKeywordSearchParams(final String[] keywordSearchParams) {
// for (String param : keywordSearchParams) {
// keywordSearch = keywordSearch + " OR (" + param.toLowerCase() + ")";
// }
// }
// 
// /**
// * Searches the context with the previously set keyword search params
// * and the given location (latitude, longitude) and radius (accuracy).
// * @param latitude a valid latitude
// * @param longitude a valid longitude
// * @param accuracy a radius in meters
// * @return The name of the result if there was a place found with the given query params, otherwise "AWAY"
// */
// public String keywordSearch(final double latitude, final double longitude, final int accuracy) {
// try {
// PlacesSearchResult[] results = PlacesApi
// .nearbySearchQuery(context, new LatLng(latitude, longitude))
// .radius(accuracy)
// .keyword(keywordSearch)
// .await().results;
// if (results.length == 1) {
// return results[0].name;
// } else {
// for (PlacesSearchResult sr : results) {
// boolean isPolitical = false;
// for (String st : sr.types) {
// if (st.equals("political")) {
// isPolitical = true;
// }
// }
// 
// if (!isPolitical) {
// return sr.name;
// }
// }
// }
// } catch (ApiException | InterruptedException | IOException e) {
// e.printStackTrace();
// }
// 
// return "AWAY";
// }
/**
 * Retrieves the own addresses of the current user.
 */
public void fetchOwnAddresses() {
    if (context != null) {
        Person me = GooglePeople.getInstance().getProfile();
        if (me.getAddresses() != null) {
            for (Address res : me.getAddresses()) {
                String name = res.getFormattedType();
                List<Address> address = Arrays.asList(res);
                ownAddresses.add(new Contact(name, address));
            }
        }
    }
}
Also used : Address(com.google.api.services.people.v1.model.Address) Person(com.google.api.services.people.v1.model.Person) Contact(de.opendiabetes.vault.plugin.importer.googlecrawler.models.Contact)

Example 3 with Address

use of com.google.api.services.people.v1.model.Address in project data-transfer-project by google.

the class VCardToGoogleContactConverterTest method testConversionToGoogleAddresses.

@Test
public void testConversionToGoogleAddresses() {
    // Set up vCard with a primary address and a secondary address
    String primaryStreet = "221B Baker St";
    String primaryLocality = "London";
    ezvcard.property.Address primaryAddress = new ezvcard.property.Address();
    primaryAddress.setStreetAddress(primaryStreet);
    primaryAddress.setLocality(primaryLocality);
    primaryAddress.setPref(VCARD_PRIMARY_PREF);
    String altStreet = "42 Wallaby Way";
    String altLocality = "Sydney";
    ezvcard.property.Address altAddress = new ezvcard.property.Address();
    altAddress.setStreetAddress(altStreet);
    altAddress.setLocality(altLocality);
    altAddress.setPref(VCARD_PRIMARY_PREF + 1);
    // Add addresses to vCard.  Order shouldn't matter.
    VCard vCard = defaultVCard;
    vCard.addAddress(primaryAddress);
    vCard.addAddress(altAddress);
    // Run test
    Person person = VCardToGoogleContactConverter.convert(vCard);
    // Check results
    // Check correct number of addresses
    assertThat(person.getAddresses().size()).isEqualTo(2);
    // Check primary address
    List<Address> actualPrimaryAddresses = person.getAddresses().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualPrimaryAddressStreets = getValuesFromFields(actualPrimaryAddresses, Address::getStreetAddress);
    assertThat(actualPrimaryAddressStreets).containsExactly(primaryStreet);
    // Check secondary address
    List<Address> actualSecondaryAddresses = person.getAddresses().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualSecondaryAddressStreets = getValuesFromFields(actualSecondaryAddresses, Address::getStreetAddress);
    assertThat(actualSecondaryAddressStreets).containsExactly(altStreet);
}
Also used : VCard(ezvcard.VCard) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Telephone(ezvcard.property.Telephone) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.SOURCE_PARAM_NAME_TYPE) Test(org.junit.Test) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Truth.assertThat(com.google.common.truth.Truth.assertThat) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StructuredName(ezvcard.property.StructuredName) Pair(com.google.gdata.util.common.base.Pair) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) CONTACT_SOURCE_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.CONTACT_SOURCE_TYPE) Nullable(com.google.gdata.util.common.base.Nullable) Address(com.google.api.services.people.v1.model.Address) Email(ezvcard.property.Email) Name(com.google.api.services.people.v1.model.Name) Collections(java.util.Collections) Before(org.junit.Before) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Address(com.google.api.services.people.v1.model.Address) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) Test(org.junit.Test)

Example 4 with Address

use of com.google.api.services.people.v1.model.Address in project photon-model by vmware.

the class AWSSubnetTaskServiceTest method testCreateSubnetWithOutboundAccess.

@Test
public void testCreateSubnetWithOutboundAccess() throws Throwable {
    // provision a "public" subnet first
    SubnetState publicSubnetState = provisionSubnet(AWS_NON_EXISTING_PUBLIC_SUBNET_NAME, AWS_NON_EXISTING_PUBLIC_SUBNET_CIDR, null);
    assertNotNull(publicSubnetState.id);
    assertEquals(LifecycleState.READY, publicSubnetState.lifecycleState);
    SubnetState subnetState = provisionSubnet(AWS_NON_EXISTING_SUBNET_NAME, AWS_NON_EXISTING_SUBNET_CIDR, publicSubnetState.documentSelfLink);
    assertNotNull(subnetState.id);
    assertEquals(LifecycleState.READY, subnetState.lifecycleState);
    if (!this.isMock) {
        // Verify that the subnet was created.
        DescribeSubnetsRequest describeRequest = new DescribeSubnetsRequest().withSubnetIds(Collections.singletonList(subnetState.id));
        List<Subnet> subnets = this.client.describeSubnets(describeRequest).getSubnets();
        assertNotNull(subnets);
        assertEquals(1, subnets.size());
        // Verify that a NAT gateway was created
        assertNotNull(subnetState.customProperties);
        String natGatewayId = subnetState.customProperties.get(AWS_NAT_GATEWAY_ID);
        String routeTableId = subnetState.customProperties.get(AWS_ROUTE_TABLE_ID);
        String allocationId = subnetState.customProperties.get(AWS_ELASTIC_IP_ALLOCATION_ID);
        assertNotNull(natGatewayId);
        assertNotNull(routeTableId);
        assertNotNull(allocationId);
        DescribeNatGatewaysRequest describeNatGatewaysRequest = new DescribeNatGatewaysRequest().withNatGatewayIds(Collections.singletonList(natGatewayId));
        List<NatGateway> natGateways = this.client.describeNatGateways(describeNatGatewaysRequest).getNatGateways();
        assertNotNull(natGateways);
        assertEquals(1, natGateways.size());
        NatGateway natGateway = natGateways.get(0);
        assertEquals(publicSubnetState.id, natGateway.getSubnetId());
        assertNotNull(natGateway.getNatGatewayAddresses());
        assertEquals(1, natGateway.getNatGatewayAddresses().size());
        assertEquals(allocationId, natGateway.getNatGatewayAddresses().get(0).getAllocationId());
        assertEquals("available", natGateways.get(0).getState());
        // verify that a route table was created
        DescribeRouteTablesRequest describeRouteTablesRequest = new DescribeRouteTablesRequest().withRouteTableIds(Collections.singletonList(routeTableId));
        List<RouteTable> routeTables = this.client.describeRouteTables(describeRouteTablesRequest).getRouteTables();
        assertNotNull(routeTables);
        assertEquals(1, routeTables.size());
        RouteTable routeTable = routeTables.get(0);
        assertNotNull(routeTable.getAssociations());
        assertEquals(1, routeTable.getAssociations().size());
        assertEquals(subnetState.id, routeTable.getAssociations().get(0).getSubnetId());
        assertNotNull(routeTable.getRoutes());
        assertEquals(2, routeTable.getRoutes().size());
        boolean hasRouteToNatGateway = false;
        for (Route route : routeTable.getRoutes()) {
            if (route.getDestinationCidrBlock().equals("0.0.0.0/0") && route.getNatGatewayId() != null && route.getNatGatewayId().equals(natGatewayId)) {
                hasRouteToNatGateway = true;
                break;
            }
        }
        assertTrue(hasRouteToNatGateway);
        // Verify that an IP address allocation was created
        DescribeAddressesRequest describeAddressesRequest = new DescribeAddressesRequest().withAllocationIds(Collections.singletonList(allocationId));
        List<Address> addresses = this.client.describeAddresses(describeAddressesRequest).getAddresses();
        assertNotNull(addresses);
        assertEquals(1, addresses.size());
    }
    // delete the subnet
    kickOffSubnetProvision(InstanceRequestType.DELETE, subnetState, TaskStage.FINISHED);
    if (!this.isMock) {
        // Verify that the subnet was deleted.
        DescribeSubnetsRequest describeRequest = new DescribeSubnetsRequest().withSubnetIds(Collections.singletonList(subnetState.id));
        try {
            this.client.describeSubnets(describeRequest).getSubnets();
            fail("Subnet should not exist in AWS.");
        } catch (AmazonEC2Exception ex) {
            assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ex.getStatusCode());
        }
        // Verify that the NAT gateway was deleted
        String natGatewayId = subnetState.customProperties.get(AWS_NAT_GATEWAY_ID);
        String routeTableId = subnetState.customProperties.get(AWS_ROUTE_TABLE_ID);
        String allocationId = subnetState.customProperties.get(AWS_ELASTIC_IP_ALLOCATION_ID);
        DescribeNatGatewaysRequest describeNatGatewaysRequest = new DescribeNatGatewaysRequest().withNatGatewayIds(Collections.singletonList(natGatewayId));
        List<NatGateway> natGateways = this.client.describeNatGateways(describeNatGatewaysRequest).getNatGateways();
        assertNotNull(natGateways);
        assertEquals(1, natGateways.size());
        assertEquals("deleted", natGateways.get(0).getState());
        // Verify that the route table was deleted
        DescribeRouteTablesRequest describeRouteTablesRequest = new DescribeRouteTablesRequest().withRouteTableIds(Collections.singletonList(routeTableId));
        try {
            this.client.describeRouteTables(describeRouteTablesRequest).getRouteTables();
            fail("Route table should not exist in AWS.");
        } catch (AmazonEC2Exception ex) {
            assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ex.getStatusCode());
        }
        DescribeAddressesRequest describeAddressesRequest = new DescribeAddressesRequest().withAllocationIds(Collections.singletonList(allocationId));
        try {
            this.client.describeAddresses(describeAddressesRequest).getAddresses();
            fail("IP address allocation should not exist in AWS.");
        } catch (AmazonEC2Exception ex) {
            assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ex.getStatusCode());
        }
    }
}
Also used : Address(com.amazonaws.services.ec2.model.Address) DescribeNatGatewaysRequest(com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest) DescribeAddressesRequest(com.amazonaws.services.ec2.model.DescribeAddressesRequest) NatGateway(com.amazonaws.services.ec2.model.NatGateway) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) RouteTable(com.amazonaws.services.ec2.model.RouteTable) DescribeRouteTablesRequest(com.amazonaws.services.ec2.model.DescribeRouteTablesRequest) Subnet(com.amazonaws.services.ec2.model.Subnet) Route(com.amazonaws.services.ec2.model.Route) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 5 with Address

use of com.google.api.services.people.v1.model.Address in project aws-doc-sdk-examples by awsdocs.

the class DescribeAddresses method main.

public static void main(String[] args) {
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
    DescribeAddressesResult response = ec2.describeAddresses();
    for (Address address : response.getAddresses()) {
        System.out.printf("Found address with public IP %s, " + "domain %s, " + "allocation id %s " + "and NIC id %s", address.getPublicIp(), address.getDomain(), address.getAllocationId(), address.getNetworkInterfaceId());
    }
}
Also used : Address(com.amazonaws.services.ec2.model.Address) DescribeAddressesResult(com.amazonaws.services.ec2.model.DescribeAddressesResult) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2)

Aggregations

Address (com.amazonaws.services.ec2.model.Address)7 Person (com.google.api.services.people.v1.model.Person)7 DescribeAddressesResult (com.amazonaws.services.ec2.model.DescribeAddressesResult)5 VCard (ezvcard.VCard)5 Test (org.junit.Test)5 DescribeAddressesRequest (com.amazonaws.services.ec2.model.DescribeAddressesRequest)4 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)4 Address (org.hl7.fhir.dstu3.model.Address)4 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)3 Address (com.google.api.services.people.v1.model.Address)3 AssociateAddressRequest (com.amazonaws.services.ec2.model.AssociateAddressRequest)2 DisassociateAddressRequest (com.amazonaws.services.ec2.model.DisassociateAddressRequest)2 Name (com.google.api.services.people.v1.model.Name)2 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Nullable (com.google.gdata.util.common.base.Nullable)2 Pair (com.google.gdata.util.common.base.Pair)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)2 Contact (de.opendiabetes.vault.plugin.importer.googlecrawler.models.Contact)2 Address (ezvcard.property.Address)2