diff --git a/.drone.yml b/.drone.yml index 78d15d6d36..f9641fc4d4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -100,6 +100,8 @@ services: - su www-data -c "php /var/www/html/occ group:adduser users user2" - su www-data -c "git clone -b master https://github.com/nextcloud/activity.git /var/www/html/apps/activity/" - su www-data -c "php /var/www/html/occ app:enable activity" + - su www-data -c "git clone -b master https://github.com/nextcloud/text.git /var/www/html/apps/text/" + - su www-data -c "php /var/www/html/occ app:enable text" - /run.sh trigger: diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index a3090d211b..a29644e57e 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -168 \ No newline at end of file +144 diff --git a/scripts/analysis/spotbugs-filter.xml b/scripts/analysis/spotbugs-filter.xml index 4d3a675f7a..03401b3e2a 100644 --- a/scripts/analysis/spotbugs-filter.xml +++ b/scripts/analysis/spotbugs-filter.xml @@ -8,8 +8,11 @@ + + + - + diff --git a/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingCreateFileRemoteOperationTest.java b/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingCreateFileRemoteOperationTest.java new file mode 100644 index 0000000000..640496fc29 --- /dev/null +++ b/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingCreateFileRemoteOperationTest.java @@ -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()); + } +} diff --git a/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperationTest.java b/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperationTest.java new file mode 100644 index 0000000000..1692a1c66e --- /dev/null +++ b/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperationTest.java @@ -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); + } +} diff --git a/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperationTest.java b/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperationTest.java new file mode 100644 index 0000000000..e805c2fefc --- /dev/null +++ b/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperationTest.java @@ -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 . + * + */ + +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)); + + assertEquals("New text document", directEditing.creators.get("textdocument").name); + assertFalse(directEditing.creators.get("textdocument").templates); + } +} diff --git a/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperationTest.java b/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperationTest.java new file mode 100644 index 0000000000..134f44e852 --- /dev/null +++ b/src/androidTest/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperationTest.java @@ -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()); + } +} diff --git a/src/androidTest/java/com/owncloud/android/GetCapabilitiesTest.java b/src/androidTest/java/com/owncloud/android/GetCapabilitiesTest.java index 0d904c819d..d66ded700d 100644 --- a/src/androidTest/java/com/owncloud/android/GetCapabilitiesTest.java +++ b/src/androidTest/java/com/owncloud/android/GetCapabilitiesTest.java @@ -53,6 +53,9 @@ public void testGetRemoteCapabilitiesOperation() { OCCapability capability = (OCCapability) result.getData().get(0); Assert.assertSame(capability.getRichDocuments(), CapabilityBooleanType.FALSE); + + Assert.assertFalse(capability.getDirectEditingEtag().isEmpty()); + // TODO assert basic capabilities } } diff --git a/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingCreateFileRemoteOperation.java b/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingCreateFileRemoteOperation.java new file mode 100644 index 0000000000..e776eb99e1 --- /dev/null +++ b/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingCreateFileRemoteOperation.java @@ -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; + } +} diff --git a/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperation.java b/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperation.java new file mode 100644 index 0000000000..8a37cf9360 --- /dev/null +++ b/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperation.java @@ -0,0 +1,94 @@ +/* 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.google.gson.reflect.TypeToken; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.TemplateList; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.ocs.ServerResponse; +import com.owncloud.android.lib.resources.OCSRemoteOperation; + +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; + +import lombok.AllArgsConstructor; + +/** + * Get templates for an editor + */ + +@AllArgsConstructor +public class DirectEditingObtainListOfTemplatesRemoteOperation extends OCSRemoteOperation { + private static final String TAG = DirectEditingObtainListOfTemplatesRemoteOperation.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/templates/"; + + private static final String JSON_FORMAT = "?format=json"; + + private String editor; + private String template; + + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result; + GetMethod getMethod = null; + + try { + getMethod = new GetMethod(client.getBaseUri() + DIRECT_ENDPOINT + editor + "/" + template + JSON_FORMAT); + + // remote request + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + + int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + + if (status == HttpStatus.SC_OK) { + TemplateList templateList = getServerResponse(getMethod, + new TypeToken>() { + }) + .getOcs().getData(); + + result = new RemoteOperationResult(true, getMethod); + result.setSingleData(templateList); + } else { + result = new RemoteOperationResult(false, getMethod); + client.exhaustResponse(getMethod.getResponseBodyAsStream()); + } + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Get all direct editing informations failed: " + result.getLogMessage(), + result.getException()); + } finally { + if (getMethod != null) { + getMethod.releaseConnection(); + } + } + return result; + } +} diff --git a/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperation.java b/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperation.java new file mode 100644 index 0000000000..699d064e60 --- /dev/null +++ b/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperation.java @@ -0,0 +1,84 @@ +/* + * + */ + +package com.nextcloud.android.lib.resources.directediting; + +import com.google.gson.reflect.TypeToken; +import com.owncloud.android.lib.common.DirectEditing; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.ocs.ServerResponse; +import com.owncloud.android.lib.resources.OCSRemoteOperation; + +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; + +/** + * Get all editor details from direct editing + */ + +public class DirectEditingObtainRemoteOperation extends OCSRemoteOperation { + private static final String TAG = DirectEditingObtainRemoteOperation.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"; + + private static final String JSON_FORMAT = "?format=json"; + + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result; + GetMethod getMethod = null; + + try { + getMethod = new GetMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT); + + // remote request + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + + int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + + if (status == HttpStatus.SC_OK) { + DirectEditing directEditing = getServerResponse(getMethod, + new TypeToken>() { + }) + .getOcs().getData(); + + result = new RemoteOperationResult(true, getMethod); + result.setSingleData(directEditing); + } else { + result = new RemoteOperationResult(false, getMethod); + client.exhaustResponse(getMethod.getResponseBodyAsStream()); + } + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Get all direct editing informations failed: " + result.getLogMessage(), + result.getException()); + } finally { + if (getMethod != null) { + getMethod.releaseConnection(); + } + } + return result; + } +} diff --git a/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperation.java b/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperation.java new file mode 100644 index 0000000000..b987556903 --- /dev/null +++ b/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingOpenFileRemoteOperation.java @@ -0,0 +1,95 @@ +/* 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; + +/** + * open file for direct editing + */ + +@AllArgsConstructor +public class DirectEditingOpenFileRemoteOperation extends RemoteOperation { + private static final String TAG = DirectEditingOpenFileRemoteOperation.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/open"; + + private static final String JSON_FORMAT = "?format=json"; + + private String filePath; + private String editor; + + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result; + PostMethod postMethod = null; + + try { + postMethod = new PostMethod(client.getBaseUri() + DIRECT_ENDPOINT + JSON_FORMAT); + postMethod.addParameter("path", filePath); + postMethod.addParameter("editorId", editor); + + // 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; + } +} diff --git a/src/main/java/com/owncloud/android/lib/common/Creator.java b/src/main/java/com/owncloud/android/lib/common/Creator.java new file mode 100644 index 0000000000..2bdc9898df --- /dev/null +++ b/src/main/java/com/owncloud/android/lib/common/Creator.java @@ -0,0 +1,90 @@ +/* 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.owncloud.android.lib.common; + +import android.os.Parcel; +import android.os.Parcelable; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * Creator of direct editing data model + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class Creator implements Parcelable { + public String id; + public String editor; + public String name; + public String extension; + public String mimetype; + public boolean templates; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(android.os.Parcel dest, int flags) { + dest.writeString(id); + dest.writeString(editor); + dest.writeString(name); + dest.writeString(extension); + dest.writeString(mimetype); + dest.writeInt(templates ? 1 : 0); + } + + private Creator(Parcel read) { + id = read.readString(); + editor = read.readString(); + name = read.readString(); + extension = read.readString(); + mimetype = read.readString(); + templates = read.readInt() != 0; + } + + public static final Creator CREATOR = + new Creator() { + + @Override + public com.owncloud.android.lib.common.Creator createFromParcel(android.os.Parcel source) { + return new com.owncloud.android.lib.common.Creator(source); + } + + @Override + public com.owncloud.android.lib.common.Creator[] newArray(int size) { + return new com.owncloud.android.lib.common.Creator[size]; + } + }; +} diff --git a/src/main/java/com/owncloud/android/lib/common/DirectEditing.java b/src/main/java/com/owncloud/android/lib/common/DirectEditing.java new file mode 100644 index 0000000000..0d47825475 --- /dev/null +++ b/src/main/java/com/owncloud/android/lib/common/DirectEditing.java @@ -0,0 +1,51 @@ +/* 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.owncloud.android.lib.common; + +import org.parceler.Parcel; + +import java.util.HashMap; +import java.util.Map; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * Direct editing data model + */ +@Parcel +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class DirectEditing { + public Map editors = new HashMap<>(); + public Map creators = new HashMap<>(); +} diff --git a/src/main/java/com/owncloud/android/lib/common/Editor.java b/src/main/java/com/owncloud/android/lib/common/Editor.java new file mode 100644 index 0000000000..010c03e405 --- /dev/null +++ b/src/main/java/com/owncloud/android/lib/common/Editor.java @@ -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.owncloud.android.lib.common; + +import org.parceler.Parcel; + +import java.util.ArrayList; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * Editor for direct editing data model + */ +@Parcel +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class Editor { + public String id; + public String name; + public ArrayList mimetypes; + public ArrayList optionalMimetypes; + public boolean secure; +} diff --git a/src/main/java/com/owncloud/android/lib/common/Template.java b/src/main/java/com/owncloud/android/lib/common/Template.java new file mode 100644 index 0000000000..5982b783c7 --- /dev/null +++ b/src/main/java/com/owncloud/android/lib/common/Template.java @@ -0,0 +1,50 @@ +/* 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.owncloud.android.lib.common; + +import org.parceler.Parcel; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * Template for direct editing data model + */ +@Parcel +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class Template { + public String id; + public String extension; + public String title; + public String preview; +} diff --git a/src/main/java/com/owncloud/android/lib/common/TemplateList.java b/src/main/java/com/owncloud/android/lib/common/TemplateList.java new file mode 100644 index 0000000000..8a78bbf558 --- /dev/null +++ b/src/main/java/com/owncloud/android/lib/common/TemplateList.java @@ -0,0 +1,55 @@ +/* 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.owncloud.android.lib.common; + +import org.parceler.Parcel; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * List of templates data model + */ +@Parcel +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class TemplateList { + public Map templates = new HashMap<>(); + + public ArrayList