br.com.anteros.nextcloud.api.utils.NextcloudResponseHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Anteros-NextCloud Show documentation
Show all versions of Anteros-NextCloud Show documentation
Anteros NextCloud for Java.
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);
}
}
}