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

br.com.anteros.nextcloud.api.utils.NextcloudResponseHelper Maven / Gradle / Ivy

There is a newer version: 1.0.16
Show newest version
package br.com.anteros.nextcloud.api.utils;

import java.util.concurrent.CompletableFuture;

import br.com.anteros.nextcloud.api.exception.NextcloudApiException;
import br.com.anteros.nextcloud.api.exception.NextcloudOperationFailedException;

public class NextcloudResponseHelper
{
    public static final int NC_OK= 100; // Nextcloud OK message

    private NextcloudResponseHelper() {
    }

    public static  A getAndCheckStatus(CompletableFuture answer)
    {
        A xmlanswer = getAndWrapException(answer);
        if(isStatusCodeOkay(xmlanswer))
        {
            return xmlanswer;
        }
        throw new NextcloudOperationFailedException(xmlanswer.getStatusCode(), xmlanswer.getMessage());
    }

    public static  boolean isStatusCodeOkay(CompletableFuture answer)
    {
        return isStatusCodeOkay(getAndWrapException(answer));
    }

    public static  boolean isStatusCodeOkay(XMLAnswer answer)
    {
        return answer.getStatusCode() == NC_OK;
    }

    public static  A getAndWrapException(CompletableFuture answer)
    {
        try {
            return answer.get();
        } catch (Exception e) {
            throw new NextcloudApiException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy