com.memority.toolkit.inwebo.api.DeviceStatus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit-inwebo-api Show documentation
Show all versions of toolkit-inwebo-api Show documentation
This artifact provides the API classes that are necessary when interacting with the InWebo service in Memority configuration Rules.
The newest version!
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Toolkit API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.toolkit.inwebo.api;
import java.util.Arrays;
/**
* InWebo device status.
* Value in InWebo API is a number.
*/
public enum DeviceStatus {
ACTIVE(0),
LOCKED(1),
PIN_LOCKED(2);
private long apiValue;
DeviceStatus(long apiValue) {
this.apiValue = apiValue;
}
public static DeviceStatus getFromApiValue(long apiValue) {
if (apiValue > PIN_LOCKED.getApiValue()) {
// InWebo introduced "3" as a possible value with an obscure bit of documentation:
// "For some state properties, the value may be 3. It is a mask, meaning that it is a 1 + 2 → 3 = (1) device locked + (2)pin locked)"
// If it means "the device is locked and the user is pin locked" we can probably reduce the status to a pin lock as before.
// See https://docs.inwebo.com/documentation/user-management-with-soap-api
return PIN_LOCKED;
}
return Arrays.stream(DeviceStatus.values())
.filter(v -> v.apiValue == apiValue)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(String.format("Cannot match inwebo device status from unknown API value '%s'", apiValue)));
}
public long getApiValue() {
return apiValue;
}
}