com.arm.mbed.cloud.sdk.update.adapters.CampaignDeviceStateAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mbed-cloud-sdk Show documentation
Show all versions of mbed-cloud-sdk Show documentation
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.
package com.arm.mbed.cloud.sdk.update.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.updateservice.model.CampaignDeviceMetadata;
import com.arm.mbed.cloud.sdk.internal.updateservice.model.CampaignDeviceMetadata.DeploymentStateEnum;
import com.arm.mbed.cloud.sdk.internal.updateservice.model.CampaignDeviceMetadataPage;
import com.arm.mbed.cloud.sdk.update.model.CampaignDeviceState;
import com.arm.mbed.cloud.sdk.update.model.DeviceState;
@Preamble(description = "Adapter for campaign device state model")
@Internal
public final class CampaignDeviceStateAdapter {
private CampaignDeviceStateAdapter() {
super();
}
/**
* Maps metadata.
*
* @param metadata
* campaign metadata
* @return campaign state
*/
public static CampaignDeviceState map(CampaignDeviceMetadata metadata) {
if (metadata == null) {
return null;
}
return new CampaignDeviceState(metadata.getId(), metadata.getDeviceId(), metadata.getCampaign(),
toDeviceState(metadata.getDeploymentState()), metadata.getName(), metadata.getDescription(),
TranslationUtils.toDate(metadata.getCreatedAt()), TranslationUtils.toDate(metadata.getUpdatedAt()),
metadata.getMechanism(), TranslationUtils.toUrl(metadata.getMechanismUrl()));
}
/**
* Gets mapper.
*
* @return mapper.
*/
public static Mapper getMapper() {
return new Mapper() {
@Override
public CampaignDeviceState map(CampaignDeviceMetadata toBeMapped) {
return CampaignDeviceStateAdapter.map(toBeMapped);
}
};
}
/**
* Maps list of campaign metadata.
*
* @param list
* metadata page
* @return list of campaign metadata
*/
public static ListResponse mapList(CampaignDeviceMetadataPage list) {
final CampaignDeviceMetadataPage deviceList = list;
final RespList respList = new RespList() {
@Override
public Boolean getHasMore() {
return (deviceList == null) ? null : deviceList.isHasMore();
}
@Override
public Integer getTotalCount() {
return (deviceList == null) ? null : deviceList.getTotalCount();
}
@Override
public String getAfter() {
return (deviceList == null) ? null : deviceList.getAfter();
}
@Override
public Integer getLimit() {
return (deviceList == null) ? null : deviceList.getLimit();
}
@Override
public String getOrder() {
return (deviceList == null) ? null : deviceList.getOrder().toString();
}
@Override
public String getContinuationMarker() {
return null;
}
@Override
public List getData() {
return (deviceList == null) ? null : deviceList.getData();
}
};
return GenericAdapter.mapList(respList, getMapper());
}
/**
* Gets list mapper.
*
* @return list mapper
*/
public static Mapper> getListMapper() {
return new Mapper>() {
@Override
public ListResponse map(CampaignDeviceMetadataPage toBeMapped) {
return CampaignDeviceStateAdapter.mapList(toBeMapped);
}
};
}
private static DeviceState toDeviceState(DeploymentStateEnum state) {
if (state == null) {
return DeviceState.getUnknownEnum();
}
switch (state) {
case DEPLOYED:
return DeviceState.DEPLOYED;
case FAILED_CONNECTOR_CHANNEL_UPDATE:
return DeviceState.FAILED_CONNECTOR_CHANNEL_UPDATE;
case MANIFESTREMOVED:
return DeviceState.MANIFEST_REMOVED;
case PENDING:
return DeviceState.PENDING;
case UPDATED_CONNECTOR_CHANNEL:
return DeviceState.UPDATED_CONNECTOR_CHANNEL;
case DEREGISTERED:
return DeviceState.DEREGISTERED;
default:
break;
}
return DeviceState.getUnknownEnum();
}
}