Search in sources :

Example 1 with CertificateListOptions

use of com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions in project mbed-cloud-sdk-java by ARMmbed.

the class Certificates method listCertificates.

/**
 * Lists all certificates according to filter options.
 * <p>
 * Note: This method returns only partially complete certificate objects.
 * <p>
 * In order to see the full information about a particular certificate, use {@link #getCertificate(String)} instead.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     CertificateListOptions options = new CertificateListOptions();
 *     String ownerId = "015f4ac587f500000000000100100249";
 *     options.setOwnerIdFilter(ownerId);
 *     options.setTypeFilter(CertificateType.DEVELOPER);
 *
 *     ListResponse<Certificate> certificates = certificateApi.listCertificates(options);
 *     for (Certificate certificate : certificates) {
 *         System.out.println("Certificate name: " + certificate.getName());
 *         System.out.println("Certificate server URI: " + certificate.getServerUri());
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param options
 *            filter options.
 * @return The list of certificates corresponding to filter options (One page).
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public ListResponse<Certificate> listCertificates(@Nullable CertificateListOptions options) throws MbedCloudException {
    final CertificateListOptions finalOptions = (options == null) ? new CertificateListOptions() : options;
    final String serviceEq = finalOptions.getTypeFilter() == CertificateType.DEVELOPER ? CertificateType.BOOTSTRAP.toString() : finalOptions.encodeSingleEqualFilter(CertificateListOptions.TYPE_FILTER);
    return CloudCaller.call(this, "listCertificates()", CertificateAdapter.getListMapper(), new CloudCall<TrustedCertificateRespList>() {

        @Override
        public Call<TrustedCertificateRespList> call() {
            return endpoint.getAccountDeveloper().getAllCertificates(finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString(), finalOptions.encodeInclude(), finalOptions.encodeSingleEqualFilter(CertificateListOptions.NAME_FILTER), serviceEq, TranslationUtils.convertToInteger(finalOptions.encodeSingleEqualFilter(CertificateListOptions.EXPIRES_FILTER), null), finalOptions.getExecutionModeFilter(), finalOptions.getExecutionModeNotEqualFilter(), finalOptions.encodeSingleEqualFilter(CertificateListOptions.OWNER_ID_FILTER), finalOptions.getEnrollmentFilter(), finalOptions.encodeSingleLikeFilter(CertificateListOptions.ISSUER_FILTER), finalOptions.encodeSingleLikeFilter(CertificateListOptions.SUBJECT_FILTER));
        }
    });
}
Also used : CertificateListOptions(com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) TrustedCertificateRespList(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 2 with CertificateListOptions

use of com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions in project mbed-cloud-sdk-java by ARMmbed.

the class CertificatesExamples method listCertificates.

/**
 * Lists the first 5 certificates.
 */
@SuppressWarnings("boxing")
@Example
public void listCertificates() {
    ConnectionOptions config = Configuration.get();
    Certificates api = new Certificates(config);
    try {
        // Defining query options.
        CertificateListOptions options = new CertificateListOptions();
        options.setLimit(5);
        // Listing certificates.
        Paginator<Certificate> certificates = api.listAllCertificates(options);
        for (Certificate certificate : certificates) {
            log("Certificate", certificate);
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : CertificateListOptions(com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions) Certificates(com.arm.mbed.cloud.sdk.Certificates) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) Certificate(com.arm.mbed.cloud.sdk.certificates.model.Certificate) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 3 with CertificateListOptions

use of com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions in project mbed-cloud-sdk-java by ARMmbed.

the class TestAllListOptions method testCertificateListOptionsClone.

@Test
public void testCertificateListOptionsClone() {
    CertificateListOptions opt1 = new CertificateListOptions();
    opt1.addEqualFilter("field1", Integer.valueOf(3));
    opt1.includeTotalCount();
    opt1.setLimit(Integer.valueOf(2));
    CertificateListOptions opt2 = new CertificateListOptions();
    assertNotEquals(opt2, opt1);
    assertNotSame(opt2, opt1);
    opt2 = opt1.clone();
    assertEquals(opt2, opt1);
    assertNotSame(opt2, opt1);
}
Also used : CertificateListOptions(com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions) Test(org.junit.Test)

Aggregations

CertificateListOptions (com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions)3 Certificates (com.arm.mbed.cloud.sdk.Certificates)1 API (com.arm.mbed.cloud.sdk.annotations.API)1 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)1 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)1 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)1 ConnectionOptions (com.arm.mbed.cloud.sdk.common.ConnectionOptions)1 MbedCloudException (com.arm.mbed.cloud.sdk.common.MbedCloudException)1 TrustedCertificateRespList (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList)1 Test (org.junit.Test)1 Call (retrofit2.Call)1 AbstractExample (utils.AbstractExample)1 Example (utils.Example)1