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

com.arm.mbed.cloud.sdk.security.adapters.CertificateIssuerConfigAdapter Maven / Gradle / Ivy

Go to download

The Pelion Cloud SDK (formerly known as Mbed Cloud SDK) provides a simplified interface to the Pelion Cloud APIs by exposing functionality using conventions and paradigms familiar to Java developers.

There is a newer version: 2.5.0
Show newest version
package com.arm.mbed.cloud.sdk.security.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.internal.externalca.model.CertificateIssuerConfigListResponse;
import com.arm.mbed.cloud.sdk.internal.externalca.model.CertificateIssuerConfigRequest;
import com.arm.mbed.cloud.sdk.internal.externalca.model.CertificateIssuerConfigResponse;
import com.arm.mbed.cloud.sdk.internal.externalca.model.CreateCertificateIssuerConfig;
import com.arm.mbed.cloud.sdk.security.model.CertificateIssuerConfig;

@Preamble(description = "Adapter for certificate issuer config")
@Internal
public final class CertificateIssuerConfigAdapter {
    /**
     * Constructor.
     */
    private CertificateIssuerConfigAdapter() {
        super();
        // Nothing to do
    }

    /**
     * Maps a certificate issuer config.
     * 
     * @param toBeMapped
     *            response to be mapped.
     * @return mapped certificate issuer config.
     */
    public static CertificateIssuerConfig map(CertificateIssuerConfigResponse toBeMapped) {
        if (toBeMapped == null) {
            return null;
        }
        final CertificateIssuerConfig finalIssuerConfig = new CertificateIssuerConfig();
        finalIssuerConfig.setId(toBeMapped.getId());
        finalIssuerConfig.setCertificateIssuerId(toBeMapped.getCertificateIssuerId());
        finalIssuerConfig.setCreatedAt(TranslationUtils.toDate(toBeMapped.getCreatedAt()));
        finalIssuerConfig.setCertificateReference(toBeMapped.getReference());
        finalIssuerConfig.setUpdatedAt(TranslationUtils.toDate(toBeMapped.getUpdatedAt()));
        return finalIssuerConfig;
    }

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

            @Override
            public CertificateIssuerConfig map(CertificateIssuerConfigResponse toBeMapped) {
                return CertificateIssuerConfigAdapter.map(toBeMapped);
            }
        };
    }

    /**
     * Maps a certificate issuer config for creation.
     * 
     * @param finalCertificateIssuerConfig
     *            issuer config
     * @return mapped request body.
     */
    public static CreateCertificateIssuerConfig reverseAddMap(CertificateIssuerConfig finalCertificateIssuerConfig) {
        if (finalCertificateIssuerConfig == null) {
            return null;
        }

        final CreateCertificateIssuerConfig addedIssuerConfig = new CreateCertificateIssuerConfig();
        addedIssuerConfig.setCertificateIssuerId(finalCertificateIssuerConfig.getCertificateIssuerId());
        addedIssuerConfig.setReference(finalCertificateIssuerConfig.getCertificateReference());
        return addedIssuerConfig;
    }

    /**
     * Maps a certificate issuer config for update.
     * 
     * @param finalCertificateIssuerConfig
     *            issuer config
     * @return mapped request body.
     */
    public static CertificateIssuerConfigRequest
           reverseUpdateMap(CertificateIssuerConfig finalCertificateIssuerConfig) {
        if (finalCertificateIssuerConfig == null) {
            return null;
        }

        final CertificateIssuerConfigRequest updatedIssuerConfig = new CertificateIssuerConfigRequest();
        updatedIssuerConfig.setCertificateIssuerId(finalCertificateIssuerConfig.getCertificateIssuerId());
        return updatedIssuerConfig;
    }

    /**
     * Maps a list of certificate issuer configurations.
     *
     * @param list
     *            list of certificate issuer configurations.
     * @return list of certificate issuer configurations.
     */
    public static ListResponse mapList(CertificateIssuerConfigListResponse list) {

        final CertificateIssuerConfigListResponse finalList = list;
        final RespList respList = new RespList() {

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

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

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

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

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

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

            @Override
            public String getContinuationMarker() {
                return null;
            }

        };
        return GenericAdapter.mapList(respList, CertificateIssuerConfigAdapter.getMapper());
    }

    /**
     * Gets a list mapper.
     * 
     * @return a list mapper.
     */
    public static Mapper> getListMapper() {
        return new Mapper>() {

            @Override
            public ListResponse map(CertificateIssuerConfigListResponse toBeMapped) {
                return CertificateIssuerConfigAdapter.mapList(toBeMapped);
            }
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy