-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from col-panic/master
Support for application configuration API #33
- Loading branch information
Showing
4 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/aarboard/nextcloud/api/config/AppConfigAppKeyValueAnswer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/aarboard/nextcloud/api/config/AppConfigAppsAnswer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
102
src/main/java/org/aarboard/nextcloud/api/config/ConfigConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |