use of com.microsoft.azure.sdk.iot.provisioning.service.Query in project azure-iot-sdk-java by Azure.
the class ServiceEnrollmentGroupSample method main.
public static void main(String[] args) throws ProvisioningServiceClientException {
System.out.println("Starting sample...");
/*
* Create the device collection.
*/
String enrollmentGroupId = "enrollmentgroupid-" + UUID.randomUUID();
// *********************************** Create a Provisioning Service Client ************************************
ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
// *************************************** Create a new enrollmentGroup ****************************************
System.out.println("\nCreate a new enrollmentGroup...");
Attestation attestation = X509Attestation.createFromRootCertificates(PUBLIC_KEY_CERTIFICATE_STRING);
EnrollmentGroup enrollmentGroup = new EnrollmentGroup(enrollmentGroupId, attestation);
// Optional parameter.
enrollmentGroup.setIotHubHostNameFinal(IOTHUB_HOST_NAME);
// Optional parameter.
enrollmentGroup.setProvisioningStatusFinal(ProvisioningStatus.ENABLED);
System.out.println("\nAdd new enrollmentGroup...");
EnrollmentGroup enrollmentGroupResult = provisioningServiceClient.createOrUpdateEnrollmentGroup(enrollmentGroup);
System.out.println("\nEnrollmentGroup created with success...");
System.out.println(enrollmentGroupResult);
// **************************************** Get info of enrollmentGroup ****************************************
System.out.println("\nGet the enrollmentGroup information...");
EnrollmentGroup getResult = provisioningServiceClient.getEnrollmentGroup(enrollmentGroupId);
System.out.println(getResult);
// *************************************** Query info of enrollmentGroup ***************************************
System.out.println("\nCreate a query for the enrollmentGroups...");
QuerySpecification querySpecification = new QuerySpecificationBuilder("*", QuerySpecificationBuilder.FromType.ENROLLMENT_GROUPS).createSqlQuery();
Query query = provisioningServiceClient.createEnrollmentGroupQuery(querySpecification);
while (query.hasNext()) {
System.out.println("\nQuery the next enrollmentGroups...");
QueryResult queryResult = query.next();
System.out.println(queryResult);
}
// ************************************** Delete info of enrollmentGroup ***************************************
System.out.println("\nDelete the enrollmentGroup...");
provisioningServiceClient.deleteEnrollmentGroup(enrollmentGroupId);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.Query in project azure-iot-sdk-java by Azure.
the class ServiceEnrollmentSample method main.
public static void main(String[] args) throws ProvisioningServiceClientException {
System.out.println("Starting sample...");
// *********************************** Create a Provisioning Service Client ************************************
ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
// ******************************** Create a new individualEnrollment config **********************************
System.out.println("\nCreate a new individualEnrollment...");
Attestation attestation = new TpmAttestation(TPM_ENDORSEMENT_KEY);
IndividualEnrollment individualEnrollment = new IndividualEnrollment(REGISTRATION_ID, attestation);
// The following parameters are optional. Remove it if you don't need.
individualEnrollment.setDeviceIdFinal(DEVICE_ID);
individualEnrollment.setIotHubHostNameFinal(IOTHUB_HOST_NAME);
individualEnrollment.setProvisioningStatusFinal(PROVISIONING_STATUS);
// ************************************ Create the individualEnrollment *************************************
System.out.println("\nAdd new individualEnrollment...");
IndividualEnrollment individualEnrollmentResult = provisioningServiceClient.createOrUpdateIndividualEnrollment(individualEnrollment);
System.out.println("\nIndividualEnrollment created with success...");
System.out.println(individualEnrollmentResult);
// ************************************* Get info of individualEnrollment *************************************
System.out.println("\nGet the individualEnrollment information...");
IndividualEnrollment getResult = provisioningServiceClient.getIndividualEnrollment(REGISTRATION_ID);
System.out.println(getResult);
// ************************************ Query info of individualEnrollment ************************************
System.out.println("\nCreate a query for enrollments...");
QuerySpecification querySpecification = new QuerySpecificationBuilder("*", QuerySpecificationBuilder.FromType.ENROLLMENTS).createSqlQuery();
Query query = provisioningServiceClient.createIndividualEnrollmentQuery(querySpecification);
while (query.hasNext()) {
System.out.println("\nQuery the next enrollments...");
QueryResult queryResult = query.next();
System.out.println(queryResult);
}
// *********************************** Delete info of individualEnrollment ************************************
System.out.println("\nDelete the individualEnrollment...");
provisioningServiceClient.deleteIndividualEnrollment(REGISTRATION_ID);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.Query in project azure-iot-sdk-java by Azure.
the class ServiceBulkOperationSample method main.
public static void main(String[] args) throws ProvisioningServiceClientException {
System.out.println("Starting sample...");
// *********************************** Create a Provisioning Service Client ************************************
ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.createFromConnectionString(PROVISIONING_CONNECTION_STRING);
// ******************************** Create a new bulk of individual enrollment *********************************
System.out.println("\nCreate a new set of individualEnrollments...");
List<IndividualEnrollment> individualEnrollments = new LinkedList<>();
for (Map.Entry<String, String> device : DEVICE_MAP.entrySet()) {
Attestation attestation = new TpmAttestation(device.getValue());
String registrationId = device.getKey();
System.out.println(" Add " + registrationId);
IndividualEnrollment individualEnrollment = new IndividualEnrollment(registrationId, attestation);
individualEnrollments.add(individualEnrollment);
}
System.out.println("\nRun the bulk operation to create the individualEnrollments...");
BulkEnrollmentOperationResult bulkOperationResult = provisioningServiceClient.runBulkEnrollmentOperation(BulkOperationMode.CREATE, individualEnrollments);
System.out.println("Result of the Create bulk enrollment...");
System.out.println(bulkOperationResult);
// ************************************ Get info of individualEnrollments *************************************
for (IndividualEnrollment individualEnrollment : individualEnrollments) {
String registrationId = individualEnrollment.getRegistrationId();
System.out.println("\nGet the individualEnrollment information for " + registrationId + ":");
IndividualEnrollment getResult = provisioningServiceClient.getIndividualEnrollment(registrationId);
System.out.println(getResult);
}
// ************************************ Query info of individualEnrollments ***********************************
System.out.println("\nCreate a query for individualEnrollments...");
QuerySpecification querySpecification = new QuerySpecificationBuilder("*", QuerySpecificationBuilder.FromType.ENROLLMENTS).createSqlQuery();
Query query = provisioningServiceClient.createIndividualEnrollmentQuery(querySpecification, QUERY_PAGE_SIZE);
while (query.hasNext()) {
System.out.println("\nQuery the next individualEnrollments...");
QueryResult queryResult = query.next();
System.out.println(queryResult);
}
// ********************************** Delete bulk of individualEnrollments ************************************
System.out.println("\nDelete the set of individualEnrollments...");
bulkOperationResult = provisioningServiceClient.runBulkEnrollmentOperation(BulkOperationMode.DELETE, individualEnrollments);
System.out.println(bulkOperationResult);
}
Aggregations