Skip to content

Commit

Permalink
Support for application configuration API a-schild#33
Browse files Browse the repository at this point in the history
  • Loading branch information
col-panic committed May 11, 2020
1 parent dbb6086 commit 92429e8
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/main/java/org/aarboard/nextcloud/api/NextcloudConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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<String> 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<String> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String> getAppConfigApps()
{
return data.appConfigApps;
}

@XmlAccessorType(XmlAccessType.FIELD)
private static final class Data
{
@XmlElementWrapper(name = "data")
@XmlElement(name = "element")
private List<String> appConfigApps;
}
}
102 changes: 102 additions & 0 deletions src/main/java/org/aarboard/nextcloud/api/config/ConfigConnector.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String> getAppConfigApps(){
return NextcloudResponseHelper.getAndWrapException(getAppConfigAppsAsync())
.getAppConfigApps();
}

private CompletableFuture<AppConfigAppsAnswer> getAppConfigAppsAsync(){
return connectorCommon.executeGet(CONFIG_PART + "apps", Collections.emptyList(),
XMLAnswerParser.getInstance(AppConfigAppsAnswer.class));
}

public List<String> getAppConfigAppKeys(String appConfigApp){
return NextcloudResponseHelper.getAndWrapException(getAppConfigAppsAsync(appConfigApp))
.getAppConfigApps();
}

private CompletableFuture<AppConfigAppsAnswer> 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<AppConfigAppKeyValueAnswer> 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<AppConfigAppKeyValueAnswer> editAppConfigAppKeyValueAsync(
String appConfigAppKeyPath, Object value){
List<NameValuePair> 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();
}

}

0 comments on commit 92429e8

Please sign in to comment.