Search in sources :

Example 11 with Nullable

use of com.arm.mbed.cloud.sdk.annotations.Nullable in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagement method updateUser.

/**
 * Updates a user.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     User user = new User();
 *     String userId = "015f4ac587f500000000000100109294";
 *     user.setId(userId);
 *     user.setEmail("javaSDK@arm.com");
 *     user.setUsername("javaSDK");
 *     user.setFullName("New JavaSDK");
 *
 *     User newUser = accountManagementApi.updateUser(user);
 *     System.out.println("New User name: " + newUser.getFullName());
 *     assert userId == newUser.getId();
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param user
 *            User to update.
 * @return updated user.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public User updateUser(@NonNull User user) throws MbedCloudException {
    checkNotNull(user, TAG_USER);
    checkNotNull(user.getId(), TAG_USER_UUID);
    // checkModelValidity(user, TAG_USER);
    User updatedUser = null;
    if (user.hasEmailBeenUpdated()) {
        updatedUser = user;
    } else {
        updatedUser = user.clone();
        updatedUser.setEmail(null);
    }
    final User finalUser = updatedUser;
    return CloudCaller.call(this, "updateUser()", UserAdapter.getMapper(), new CloudCall<UserInfoResp>() {

        @Override
        public Call<UserInfoResp> call() {
            return endpoint.getAdmin().updateUser(finalUser.getId(), UserAdapter.reverseMapUpdate(finalUser));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) UserInfoResp(com.arm.mbed.cloud.sdk.internal.iam.model.UserInfoResp) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 12 with Nullable

use of com.arm.mbed.cloud.sdk.annotations.Nullable in project mbed-cloud-sdk-java by ARMmbed.

the class Connect method createResourceSubscriptionObserver.

/**
 * Creates an observer for resource subscriptions.
 * <p>
 * Note: for more information about observers @see <a href="http://reactivex.io/">Reactive X</a> or
 * <a href="https://github.com/ReactiveX/RxJava">RxJava</a> *
 * <p>
 * Example:
 *
 * <pre>
 * {
 * {@code String resourcePath = "/3200/0/5501";
 *     String deviceId = "015f4ac587f500000000000100100249";
 *     Resource resource = new Resource(deviceId, path);
 *     connectApi.createResourceSubscriptionObserver(resource, BackpressureStrategy.BUFFER)
 *                   .subscribe(System.out::println);
 *     connectApi.addResourceSubscription(resource);
 * }
 * </pre>
 *
 * @param resource
 *            resource to subscribe to.
 * @param strategy
 *            backpressure strategy to apply @see {@link BackpressureStrategy}
 * @return Observable which can be subscribed to. @see {@link Flowable}
 * @throws MbedCloudException
 *             if an error occurred in the process.
 */
@API
@Nullable
public Flowable<NotificationMessageValue> createResourceSubscriptionObserver(@NonNull Resource resource, @Nullable @DefaultValue("BUFFER") BackpressureStrategy strategy) throws MbedCloudException {
    checkNotNull(resource, TAG_RESOURCE);
    checkModelValidity(resource, TAG_RESOURCE);
    final BackpressureStrategy finalStrategy = (strategy == null) ? BackpressureStrategy.BUFFER : strategy;
    return handlersStore.createResourceSubscriptionObserver(resource, finalStrategy);
}
Also used : BackpressureStrategy(io.reactivex.BackpressureStrategy) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 13 with Nullable

use of com.arm.mbed.cloud.sdk.annotations.Nullable in project mbed-cloud-sdk-java by ARMmbed.

the class Connect method listSubscriptions.

/**
 * Lists all subscriptions.
 * <p>
 * Warning: Please note that this operation is potentially really expensive and hence, use wisely.
 * <p>
 * It could be slow for large numbers of connected devices.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *
 *     List<String> subscriptions = connectApi.listSubscriptions();
 *     for (Subscription subscription : subscriptions) {
 *         System.out.println("subscription: " + subscription);
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @return list of subscriptions
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public List<Subscription> listSubscriptions() throws MbedCloudException {
    logger.logWarn("listSubscriptions() could be slow for large numbers of connected devices.");
    final List<Subscription> subscriptions = new LinkedList<>();
    // The following is a workaround until there is a Mbed Cloud endpoint providing such an action.
    final Paginator<Device> connectedDevices = listAllConnectedDevices(null);
    if (connectedDevices != null) {
        for (final Device connectedDevice : connectedDevices) {
            final List<String> deviceSubscriptions = listDeviceSubscriptions(connectedDevice);
            if (deviceSubscriptions != null) {
                subscriptions.add(new Subscription(connectedDevice.getId(), deviceSubscriptions));
            }
        }
    }
    return subscriptions.isEmpty() ? null : subscriptions;
}
Also used : Device(com.arm.mbed.cloud.sdk.devicedirectory.model.Device) Subscription(com.arm.mbed.cloud.sdk.connect.model.Subscription) LinkedList(java.util.LinkedList) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 14 with Nullable

use of com.arm.mbed.cloud.sdk.annotations.Nullable in project mbed-cloud-sdk-java by ARMmbed.

the class Connect method listMetrics.

/**
 * Lists metrics.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Calendar startDate = GregorianCalendar(2017,10,30,10,20,56);
 *     Calendar endDate = GregorianCalendar(2017,11,31,10,20,56);
 *
 *     MetricsStartEndListOptions listOptions = new MetricsStartEndListOptions();
 *     listOptions.setStart(startDate.getTime());
 *     listOptions.setEnd(endDate.getTime());
 *     listOptions.setInterval(new TimePeriod(360)); //Once an hour
 *
 *     ListResponse<Metric> metrics = connectApi.listMetrics(listOptions);
 *     //Iterates over a page
 *     for (Metric metric : metrics.getData()) {
 *         System.out.println("Time: " + dateFormat.format(metric.getTimestamp()));
 *         System.out.println("Successful bootstraps: " + metric.getSuccessfulBootstraps());
 *         System.out.println("Successful api calls: " + metric.getSuccessfulApiCalls());
 *         System.out.println("");
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param options
 *            metrics options.
 * @param <T>
 *            Type of metrics list options
 * @return list of metrics for the corresponding options.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public <T extends AbstractMetricsListOptions> ListResponse<Metric> listMetrics(@NonNull T options) throws MbedCloudException {
    checkNotNull(options, TAG_METRIC_OPTIONS);
    final T finalOptions = options;
    final Date finalStart = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getStart() : null;
    final Date finalEnd = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getEnd() : null;
    final String finalPeriod = options instanceof MetricsPeriodListOptions ? ((MetricsPeriodListOptions) options).getPeriod().toString() : null;
    return CloudCaller.call(this, "listMetrics()", MetricAdapter.getListMapper(), new CloudCall<SuccessfulResponse>() {

        @Override
        public Call<SuccessfulResponse> call() {
            return endpoint.getStatistic().v3MetricsGet(MetricAdapter.mapIncludes(finalOptions.getInclude()), finalOptions.getInterval().toString(), TranslationUtils.toLocalDate(finalStart), TranslationUtils.toLocalDate(finalEnd), finalPeriod, finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString());
        }
    });
}
Also used : SuccessfulResponse(com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse) Call(retrofit2.Call) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) MetricsPeriodListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsPeriodListOptions) MetricsStartEndListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions) Date(java.util.Date) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 15 with Nullable

use of com.arm.mbed.cloud.sdk.annotations.Nullable in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagement method listGroupApiKeys.

/**
 * Lists API keys of a group.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String groupId = "015f4ac587f500000000000100109294";
 *     ListOptions options = new ListOptions();
 *     options.setLimit(10);
 *
 *     ListResponse<ApiKey> apiKeys = accountManagementApi.listGroupApiKeys(groupId, options);
 *     for (ApiKey apiKey : apiKeys) {
 *         System.out.println("ApiKey: " + apiKey.getKey());
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param groupId
 *            The group ID of the group.
 * @param options
 *            filter options.
 * @return The list of API keys corresponding to groupId and filter options (One page).
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public ListResponse<ApiKey> listGroupApiKeys(@NonNull String groupId, @Nullable ListOptions options) throws MbedCloudException {
    checkNotNull(groupId, TAG_GROUP_ID);
    final ListOptions finalOptions = (options == null) ? new ListOptions() : options;
    final String finalGroupId = groupId;
    return CloudCaller.call(this, "listGroupApiKeys()", ApiKeyAdapter.getListMapper(), new CloudCall<ApiKeyInfoRespList>() {

        @Override
        public Call<ApiKeyInfoRespList> call() {
            return endpoint.getDeveloper().getApiKeysOfGroup(finalGroupId, finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString(), finalOptions.encodeInclude());
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) ApiKeyInfoRespList(com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoRespList) GroupListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions) ListOptions(com.arm.mbed.cloud.sdk.common.listing.ListOptions) UserListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions) ApiKeyListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Aggregations

API (com.arm.mbed.cloud.sdk.annotations.API)23 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)23 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)19 Call (retrofit2.Call)19 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)3 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)3 TrustedCertificateResp (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp)3 ApiKeyListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions)2 GroupListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions)2 UserListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions)2 ListOptions (com.arm.mbed.cloud.sdk.common.listing.ListOptions)2 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)2 Query (com.arm.mbed.cloud.sdk.devicedirectory.model.Query)2 DeviceData (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData)2 DeviceQuery (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery)2 LinkedList (java.util.LinkedList)2 Account (com.arm.mbed.cloud.sdk.accountmanagement.model.Account)1 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)1 User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)1 CertificateListOptions (com.arm.mbed.cloud.sdk.certificates.model.CertificateListOptions)1