diff --git a/src/main/java/org/aarboard/nextcloud/api/NextcloudConnector.java b/src/main/java/org/aarboard/nextcloud/api/NextcloudConnector.java index 3594e75..d5b10ba 100644 --- a/src/main/java/org/aarboard/nextcloud/api/NextcloudConnector.java +++ b/src/main/java/org/aarboard/nextcloud/api/NextcloudConnector.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; + +import org.aarboard.nextcloud.api.config.ConfigConnector; import org.aarboard.nextcloud.api.filesharing.FilesharingConnector; import org.aarboard.nextcloud.api.filesharing.Share; import org.aarboard.nextcloud.api.filesharing.SharePermissions; @@ -48,6 +50,7 @@ public class NextcloudConnector { private final ServerConfig _serverConfig; private final ProvisionConnector pc; private final FilesharingConnector fc; + private final ConfigConnector cc; private final Folders fd; private final Files fl; @@ -64,6 +67,7 @@ public NextcloudConnector(String serverName, boolean useHTTPS, int port, String _serverConfig= new ServerConfig(serverName, useHTTPS, port, userName, password); pc= new ProvisionConnector(_serverConfig); fc= new FilesharingConnector(_serverConfig); + cc= new ConfigConnector(_serverConfig); fd= new Folders(_serverConfig); fl= new Files(_serverConfig); } @@ -84,6 +88,7 @@ public NextcloudConnector(String serviceUrl, String userName, String password){ } pc = new ProvisionConnector(_serverConfig); fc = new FilesharingConnector(_serverConfig); + cc= new ConfigConnector(_serverConfig); fd = new Folders(_serverConfig); fl = new Files(_serverConfig); } catch (MalformedURLException e) { @@ -953,4 +958,75 @@ public void downloadFolder(String remotepath, String downloadpath) throws IOExce { fd.downloadFolder(remotepath, downloadpath); } + + /** + * App-Configuration: Get all apps available for configuration + * @return + */ + public List getAppConfigApps() + { + return cc.getAppConfigApps(); + } + + /** + * App-Configuration: Get all keys available for an app + * @param appConfigApp an app name as returned by {@link #getAppConfigApps()} + * @return + */ + public List getAppConfigAppKeys(String appConfigApp) + { + return cc.getAppConfigAppKeys(appConfigApp); + } + + /** + * App-Configuration: Get a key value for an app configuration + * @param appConfigApp an app name as returned by {@link #getAppConfigApps()} + * @param appConfigAppKey a key name as returned by {@link #getAppConfigAppKeys(String)} + * @return + */ + public String getAppConfigAppKeyValue(String appConfigApp, String appConfigAppKey) + { + return cc.getAppConfigAppKeyValue(appConfigApp, appConfigAppKey); + } + + + public String getAppConfigAppKeyValue(String appConfigAppKeyPath) + { + return cc.getAppConfigAppKeyValue(appConfigAppKeyPath); + } + + /** + * App-Configuration: Edit a key value for an app configuration + * @param appConfigApp an app name as returned by {@link #getAppConfigApps()} + * @param appConfigAppKey a key name as returned by {@link #getAppConfigAppKeys(String)} + * @param value the value to set + * @return + */ + public boolean editAppConfigAppKeyValue(String appConfigApp, String appConfigAppKey, Object value) + { + return cc.editAppConfigAppKeyValue(appConfigApp, appConfigAppKey, value); + } + + /** + * + * @param appConfigAppKeyPath + * the full appConfigAppKeyPath combining appConfigApp and appConfigAppKey with "/" + * @param value + * the value to set + * @return + */ + public boolean editAppConfigAppKeyValue(String appConfigAppKeyPath, Object value){ + return cc.editAppConfigAppKeyValue(appConfigAppKeyPath, value); + } + + /** + * App-Configuration: Delete a key of an app configuration + * @param appConfigApp an app name as returned by {@link #getAppConfigApps()} + * @param appConfigAppkey a key name as returned by {@link #getAppConfigAppKeys(String)} + * @return + */ + public boolean deleteAppConfigAppKeyEntry(String appConfigApp, String appConfigAppkey) + { + return cc.deleteAppConfigAppKeyEntry(appConfigApp, appConfigAppkey); + } } diff --git a/src/main/java/org/aarboard/nextcloud/api/config/AppConfigAppKeyValueAnswer.java b/src/main/java/org/aarboard/nextcloud/api/config/AppConfigAppKeyValueAnswer.java new file mode 100644 index 0000000..5fbace2 --- /dev/null +++ b/src/main/java/org/aarboard/nextcloud/api/config/AppConfigAppKeyValueAnswer.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 Marco Descher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.aarboard.nextcloud.api.config; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.aarboard.nextcloud.api.utils.XMLAnswer; + +@XmlRootElement(name = "ocs") +public class AppConfigAppKeyValueAnswer extends XMLAnswer { + private Data data; + + public String getAppConfigAppKeyValue(){ + return data.getAppConfigAppKeyValue; + } + + @XmlAccessorType(XmlAccessType.FIELD) + private static final class Data { + @XmlElement(name = "data") + private String getAppConfigAppKeyValue; + } +} diff --git a/src/main/java/org/aarboard/nextcloud/api/config/AppConfigAppsAnswer.java b/src/main/java/org/aarboard/nextcloud/api/config/AppConfigAppsAnswer.java new file mode 100644 index 0000000..c877bfa --- /dev/null +++ b/src/main/java/org/aarboard/nextcloud/api/config/AppConfigAppsAnswer.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2020 Marco Descher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.aarboard.nextcloud.api.config; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import org.aarboard.nextcloud.api.utils.XMLAnswer; + +@XmlRootElement(name = "ocs") +public class AppConfigAppsAnswer extends XMLAnswer +{ + private Data data; + + public List getAppConfigApps() + { + return data.appConfigApps; + } + + @XmlAccessorType(XmlAccessType.FIELD) + private static final class Data + { + @XmlElementWrapper(name = "data") + @XmlElement(name = "element") + private List appConfigApps; + } +} diff --git a/src/main/java/org/aarboard/nextcloud/api/config/ConfigConnector.java b/src/main/java/org/aarboard/nextcloud/api/config/ConfigConnector.java new file mode 100644 index 0000000..7d289fb --- /dev/null +++ b/src/main/java/org/aarboard/nextcloud/api/config/ConfigConnector.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2020 Marco Descher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.aarboard.nextcloud.api.config; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.aarboard.nextcloud.api.ServerConfig; +import org.aarboard.nextcloud.api.utils.ConnectorCommon; +import org.aarboard.nextcloud.api.utils.NextcloudResponseHelper; +import org.aarboard.nextcloud.api.utils.XMLAnswerParser; +import org.apache.http.NameValuePair; +import org.apache.http.message.BasicNameValuePair; + +public class ConfigConnector { + + private final static String CONFIG_PART = "ocs/v2.php/apps/provisioning_api/api/v1/config/"; + + private final ConnectorCommon connectorCommon; + + public ConfigConnector(ServerConfig serverConfig){ + this.connectorCommon = new ConnectorCommon(serverConfig); + } + + public List getAppConfigApps(){ + return NextcloudResponseHelper.getAndWrapException(getAppConfigAppsAsync()) + .getAppConfigApps(); + } + + private CompletableFuture getAppConfigAppsAsync(){ + return connectorCommon.executeGet(CONFIG_PART + "apps", Collections.emptyList(), + XMLAnswerParser.getInstance(AppConfigAppsAnswer.class)); + } + + public List getAppConfigAppKeys(String appConfigApp){ + return NextcloudResponseHelper.getAndWrapException(getAppConfigAppsAsync(appConfigApp)) + .getAppConfigApps(); + } + + private CompletableFuture getAppConfigAppsAsync(String appConfigApp){ + return connectorCommon.executeGet(CONFIG_PART + "apps/" + appConfigApp, + Collections.emptyList(), XMLAnswerParser.getInstance(AppConfigAppsAnswer.class)); + } + + public String getAppConfigAppKeyValue(String appConfigApp, String appConfigAppKey){ + return NextcloudResponseHelper + .getAndWrapException(getAppConfigAppsKeyAsync(appConfigApp + "/" + appConfigAppKey)) + .getAppConfigAppKeyValue(); + } + + public String getAppConfigAppKeyValue(String appConfigAppKeyPath){ + return NextcloudResponseHelper + .getAndWrapException(getAppConfigAppsKeyAsync(appConfigAppKeyPath)) + .getAppConfigAppKeyValue(); + } + + private CompletableFuture getAppConfigAppsKeyAsync( + String appConfigAppKeyPath){ + return connectorCommon.executeGet(CONFIG_PART + "apps/" + appConfigAppKeyPath, + Collections.emptyList(), XMLAnswerParser.getInstance(AppConfigAppKeyValueAnswer.class)); + } + + public boolean editAppConfigAppKeyValue(String appConfigApp, String appConfigAppKey, + Object value){ + return NextcloudResponseHelper.isStatusCodeOkay( + editAppConfigAppKeyValueAsync(appConfigApp + "/" + appConfigAppKey, value)); + } + + public boolean editAppConfigAppKeyValue(String appConfigAppKeyPath, Object value){ + return NextcloudResponseHelper + .isStatusCodeOkay(editAppConfigAppKeyValueAsync(appConfigAppKeyPath, value)); + } + + public CompletableFuture editAppConfigAppKeyValueAsync( + String appConfigAppKeyPath, Object value){ + List postParams = new LinkedList<>(); + postParams.add(new BasicNameValuePair("value", value.toString())); + return connectorCommon.executePost(CONFIG_PART + "apps/" + appConfigAppKeyPath, postParams, + XMLAnswerParser.getInstance(AppConfigAppKeyValueAnswer.class)); + } + + public boolean deleteAppConfigAppKeyEntry(String appConfigApp, String appConfigAppkey){ + throw new UnsupportedOperationException(); + } + +}