Search in sources :

Example 1 with TrustedCertificateRespList

use of com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList 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 TrustedCertificateRespList

use of com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList in project mbed-cloud-sdk-java by ARMmbed.

the class CertificateAdapter method mapList.

/**
 * Maps list of certificates.
 *
 * @param list
 *            certificate list to map.
 * @return a list of mapped certificates.
 */
public static ListResponse<Certificate> mapList(TrustedCertificateRespList list) {
    final TrustedCertificateRespList certificateList = list;
    final RespList<TrustedCertificateResp> respList = new RespList<TrustedCertificateResp>() {

        @Override
        public Boolean getHasMore() {
            return (certificateList == null) ? null : certificateList.isHasMore();
        }

        @Override
        public Integer getTotalCount() {
            return (certificateList == null) ? null : certificateList.getTotalCount();
        }

        @Override
        public String getAfter() {
            return (certificateList == null) ? null : certificateList.getAfter();
        }

        @Override
        public Integer getLimit() {
            return (certificateList == null) ? null : certificateList.getLimit();
        }

        @Override
        public String getOrder() {
            return (certificateList == null) ? null : certificateList.getOrder().toString();
        }

        @Override
        public List<TrustedCertificateResp> getData() {
            return (certificateList == null) ? null : certificateList.getData();
        }
    };
    return GenericAdapter.mapList(respList, getMapper());
}
Also used : TrustedCertificateRespList(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList) TrustedCertificateResp(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp) TrustedCertificateRespList(com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList) RespList(com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)

Aggregations

TrustedCertificateRespList (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateRespList)2 API (com.arm.mbed.cloud.sdk.annotations.API)1 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)1 CertificateListOptions (com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions)1 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)1 RespList (com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)1 TrustedCertificateResp (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp)1 Call (retrofit2.Call)1