All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arm.mbed.cloud.sdk.enrollment.adapters.EnrollmentAdapter Maven / Gradle / Ivy

package com.arm.mbed.cloud.sdk.enrollment.adapters;

import java.util.List;

import com.arm.mbed.cloud.sdk.annotations.Internal;
import com.arm.mbed.cloud.sdk.annotations.Preamble;
import com.arm.mbed.cloud.sdk.common.GenericAdapter;
import com.arm.mbed.cloud.sdk.common.GenericAdapter.Mapper;
import com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList;
import com.arm.mbed.cloud.sdk.common.TranslationUtils;
import com.arm.mbed.cloud.sdk.common.listing.ListResponse;
import com.arm.mbed.cloud.sdk.enrollment.model.EnrollmentClaim;
import com.arm.mbed.cloud.sdk.lowlevel.pelionclouddevicemanagement.model.EnrollmentIdentities;
import com.arm.mbed.cloud.sdk.lowlevel.pelionclouddevicemanagement.model.EnrollmentIdentity;

@Preamble(description = "Adapter for enrollment claim model")
@Internal
public final class EnrollmentAdapter {

    private EnrollmentAdapter() {
        super();
    }

    /**
     * Maps an enrolment claim.
     *
     * @param enrollmentClaim
     *            enrollment claim
     * @return mapped claim
     */
    public static EnrollmentClaim map(EnrollmentIdentity enrollmentClaim) {
        if (enrollmentClaim == null) {
            return null;
        }
        final EnrollmentClaim claim = new EnrollmentClaim(enrollmentClaim.getId(),
                                                          TranslationUtils.toDate(enrollmentClaim.getCreatedAt()),
                                                          TranslationUtils.toDate(enrollmentClaim.getClaimedAt()),
                                                          TranslationUtils.toDate(enrollmentClaim.getExpiresAt()),
                                                          enrollmentClaim.getAccountId(),
                                                          enrollmentClaim.getEnrolledDeviceId());
        claim.setClaimId(enrollmentClaim.getEnrollmentIdentity());
        return claim;
    }

    /**
     * Gets mapper.
     *
     * @return a mapper
     */
    public static Mapper getMapper() {
        return new Mapper() {

            @Override
            public EnrollmentClaim map(EnrollmentIdentity toBeMapped) {
                return EnrollmentAdapter.map(toBeMapped);
            }

        };
    }

    /**
     * Maps a list of enrollment identities.
     *
     * @param list
     *            enrollment identities (page).
     * @return a list of enrollment identities
     */
    public static ListResponse mapList(EnrollmentIdentities list) {
        final EnrollmentIdentities enrollmentList = list;
        final RespList respList = new RespList() {

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

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

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

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

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

            @Override
            public List getData() {
                return (enrollmentList == null) ? null : enrollmentList.getData();
            }

            @Override
            public String getContinuationMarker() {
                return null;
            }
        };
        return GenericAdapter.mapList(respList, getMapper());
    }

    /**
     * Gets list mapper.
     *
     * @return list mapper
     */
    public static Mapper> getListMapper() {
        return new Mapper>() {
            @Override
            public ListResponse map(EnrollmentIdentities toBeMapped) {
                return mapList(toBeMapped);
            }

        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy