-
Notifications
You must be signed in to change notification settings - Fork 95
Add direct endpoint api #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 168 | ||
| 144 |
This file contains hidden or 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
65 changes: 65 additions & 0 deletions
65
...cloud/android/lib/resources/directediting/DirectEditingCreateFileRemoteOperationTest.java
This file contains hidden or 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,65 @@ | ||
| /* Nextcloud Android Library is available under MIT license | ||
| * | ||
| * @author Tobias Kaminsky | ||
| * Copyright (C) 2019 Tobias Kaminsky | ||
| * Copyright (C) 2019 Nextcloud GmbH | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
| * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| package com.nextcloud.android.lib.resources.directediting; | ||
|
|
||
| import com.owncloud.android.AbstractIT; | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class DirectEditingCreateFileRemoteOperationTest extends AbstractIT { | ||
| @Test | ||
| public void createEmptyFile() { | ||
| RemoteOperationResult result = new DirectEditingCreateFileRemoteOperation("/test.md", | ||
| "text", | ||
| "textdocument") | ||
| .execute(client); | ||
| assertTrue(result.isSuccess()); | ||
|
|
||
| String url = (String) result.getSingleData(); | ||
|
|
||
| assertFalse(url.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| public void createFileFromTemplate() { | ||
| RemoteOperationResult result = new DirectEditingCreateFileRemoteOperation("/test.md", | ||
| "text", | ||
| "textdocument", | ||
| "1") | ||
| .execute(client); | ||
| assertTrue(result.isSuccess()); | ||
|
|
||
| String url = (String) result.getSingleData(); | ||
|
|
||
| assertFalse(url.isEmpty()); | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
...id/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperationTest.java
This file contains hidden or 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,53 @@ | ||
| /* Nextcloud Android Library is available under MIT license | ||
| * | ||
| * @author Tobias Kaminsky | ||
| * Copyright (C) 2019 Tobias Kaminsky | ||
| * Copyright (C) 2019 Nextcloud GmbH | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
| * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| package com.nextcloud.android.lib.resources.directediting; | ||
|
|
||
| import com.owncloud.android.AbstractIT; | ||
| import com.owncloud.android.lib.common.TemplateList; | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class DirectEditingObtainListOfTemplatesRemoteOperationTest extends AbstractIT { | ||
|
|
||
| @Test | ||
| public void testGetAll() { | ||
| RemoteOperationResult result = new DirectEditingObtainListOfTemplatesRemoteOperation("text", | ||
| "textdocument") | ||
| .execute(client); | ||
| assertTrue(result.isSuccess()); | ||
|
|
||
| TemplateList templateList = (TemplateList) result.getSingleData(); | ||
|
|
||
| assertEquals("Empty file", templateList.templates.get("empty").title); | ||
| assertEquals("md", templateList.templates.get("empty").extension); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
...nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperationTest.java
This file contains hidden or 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,51 @@ | ||
| /* | ||
| * | ||
| * Nextcloud Android client application | ||
| * | ||
| * @author Tobias Kaminsky | ||
| * Copyright (C) 2019 Tobias Kaminsky | ||
| * Copyright (C) 2019 Nextcloud GmbH | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero 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 Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| package com.nextcloud.android.lib.resources.directediting; | ||
|
|
||
| import com.owncloud.android.AbstractIT; | ||
| import com.owncloud.android.lib.common.DirectEditing; | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class DirectEditingObtainRemoteOperationTest extends AbstractIT { | ||
|
|
||
| @Test | ||
| public void testGetAll() { | ||
| RemoteOperationResult result = new DirectEditingObtainRemoteOperation().execute(client); | ||
| assertTrue(result.isSuccess()); | ||
|
|
||
| DirectEditing directEditing = (DirectEditing) result.getSingleData(); | ||
|
|
||
| assertEquals("Nextcloud Text", directEditing.editors.get("text").name); | ||
| assertEquals("text/plain", directEditing.editors.get("text").optionalMimetypes.get(0)); | ||
AndyScherzinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| assertEquals("New text document", directEditing.creators.get("textdocument").name); | ||
| assertFalse(directEditing.creators.get("textdocument").templates); | ||
AndyScherzinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
63 changes: 63 additions & 0 deletions
63
...xtcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperationTest.java
This file contains hidden or 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,63 @@ | ||
| /* Nextcloud Android Library is available under MIT license | ||
| * | ||
| * @author Tobias Kaminsky | ||
| * Copyright (C) 2019 Tobias Kaminsky | ||
| * Copyright (C) 2019 Nextcloud GmbH | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
| * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| package com.nextcloud.android.lib.resources.directediting; | ||
|
|
||
| import com.owncloud.android.AbstractIT; | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||
| import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation; | ||
| import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation; | ||
|
|
||
| import junit.framework.TestCase; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class DirectEditingOpenFileRemoteOperationTest extends AbstractIT { | ||
| @Test | ||
| public void createFileFromTemplate() throws IOException { | ||
| // create file | ||
| String filePath = createFile("text"); | ||
| String remotePath = "/text.md"; | ||
| TestCase.assertTrue(new UploadFileRemoteOperation(filePath, remotePath, "text/markdown", "123") | ||
| .execute(client).isSuccess()); | ||
|
|
||
| TestCase.assertTrue(new ReadFileRemoteOperation(remotePath).execute(client).isSuccess()); | ||
|
|
||
| // open file | ||
| RemoteOperationResult result = new DirectEditingOpenFileRemoteOperation(remotePath, "text").execute(client); | ||
| assertTrue(result.isSuccess()); | ||
|
|
||
| String url = (String) result.getSingleData(); | ||
|
|
||
| assertFalse(url.isEmpty()); | ||
| } | ||
| } |
This file contains hidden or 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
106 changes: 106 additions & 0 deletions
106
...nextcloud/android/lib/resources/directediting/DirectEditingCreateFileRemoteOperation.java
This file contains hidden or 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,106 @@ | ||
| /* Nextcloud Android Library is available under MIT license | ||
| * | ||
| * @author Tobias Kaminsky | ||
| * Copyright (C) 2019 Tobias Kaminsky | ||
| * Copyright (C) 2019 Nextcloud GmbH | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
| * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| package com.nextcloud.android.lib.resources.directediting; | ||
|
|
||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||
| import com.owncloud.android.lib.common.operations.RemoteOperation; | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||
|
|
||
| import org.apache.commons.httpclient.HttpStatus; | ||
| import org.apache.commons.httpclient.methods.PostMethod; | ||
| import org.json.JSONObject; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
|
|
||
| /** | ||
| * Create file with direct editing api | ||
| */ | ||
|
|
||
| @AllArgsConstructor | ||
| public class DirectEditingCreateFileRemoteOperation extends RemoteOperation { | ||
| private static final String TAG = DirectEditingCreateFileRemoteOperation.class.getSimpleName(); | ||
| private static final int SYNC_READ_TIMEOUT = 40000; | ||
| private static final int SYNC_CONNECTION_TIMEOUT = 5000; | ||
| private static final String DIRECT_ENDPOINT = "/ocs/v2.php/apps/files/api/v1/directEditing/create"; | ||
|
|
||
| private static final String JSON_FORMAT = "?format=json"; | ||
|
|
||
| private String path; | ||
| private String editor; | ||
| private String creator; | ||
| private String template; | ||
|
|
||
| public DirectEditingCreateFileRemoteOperation(String path, String editor, String creator) { | ||
| this(path, editor, creator, ""); | ||
| } | ||
|
|
||
| protected RemoteOperationResult run(OwnCloudClient client) { | ||
| RemoteOperationResult result; | ||
| PostMethod postMethod = null; | ||
|
|
||
| try { | ||
| postMethod = new PostMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT); | ||
| postMethod.addParameter("path", path); | ||
| postMethod.addParameter("editorId", editor); | ||
| postMethod.addParameter("creatorId", creator); | ||
|
|
||
| if (!template.isEmpty()) { | ||
| postMethod.addParameter("templateId", template); | ||
| } | ||
|
|
||
| // remote request | ||
| postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||
|
|
||
| int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); | ||
|
|
||
| if (status == HttpStatus.SC_OK) { | ||
| String response = postMethod.getResponseBodyAsString(); | ||
|
|
||
| // Parse the response | ||
| JSONObject respJSON = new JSONObject(response); | ||
| String url = (String) respJSON.getJSONObject("ocs").getJSONObject("data").get("url"); | ||
|
|
||
| result = new RemoteOperationResult(true, postMethod); | ||
| result.setSingleData(url); | ||
| } else { | ||
| result = new RemoteOperationResult(false, postMethod); | ||
| client.exhaustResponse(postMethod.getResponseBodyAsStream()); | ||
| } | ||
| } catch (Exception e) { | ||
| result = new RemoteOperationResult(e); | ||
| Log_OC.e(TAG, "Get all direct editing informations failed: " + result.getLogMessage(), | ||
| result.getException()); | ||
| } finally { | ||
| if (postMethod != null) { | ||
| postMethod.releaseConnection(); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.