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

com.arm.mbed.cloud.sdk.accountmanagement.adapters.PolicyAdapter 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.accountmanagement.adapters;

import java.util.List;

import com.arm.mbed.cloud.sdk.accountmanagement.model.Policy;
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.TranslationUtils;
import com.arm.mbed.cloud.sdk.lowlevel.pelionclouddevicemanagement.model.FeaturePolicy;

@Preamble(description = "Adapter for policy model")
@Internal
public final class PolicyAdapter {

    private PolicyAdapter() {
        super();
    }

    /**
     * Maps policy objects.
     * 
     * @param featurePolicy
     *            featurePolicy.
     * @return a policy.
     */
    public static Policy map(FeaturePolicy featurePolicy) {
        if (featurePolicy == null) {
            return null;
        }
        return new Policy(featurePolicy.getAction(), featurePolicy.getResource(), featurePolicy.getFeature(),
                          TranslationUtils.toBool(featurePolicy.isAllow(), false));
    }

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

            @Override
            public Policy map(FeaturePolicy toBeMapped) {
                return PolicyAdapter.map(toBeMapped);
            }
        };
    }

    /**
     * Maps a list of policies.
     * 
     * @param list
     *            policies list
     * @return list of policies
     */
    public static List mapList(List list) {
        return GenericAdapter.mapList(list, getMapper());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy