Skip to content

Commit

Permalink
Merge pull request #194 from owncloud/show_reshares
Browse files Browse the repository at this point in the history
Show reshares
  • Loading branch information
davigonz committed Aug 9, 2018
2 parents 8e357d7 + d4908e4 commit 9ab1b40
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
* @author David González Verdugo
* Copyright (C) 2018 ownCloud 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
Expand All @@ -26,14 +27,16 @@

package com.owncloud.android.lib.resources.shares;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import android.net.Uri;

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 java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand Down Expand Up @@ -187,14 +190,18 @@ public void setGetShareDetails(boolean set) {

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
int status = -1;
RemoteOperationResult result;
int status;

PostMethod post = null;

try {
Uri requestUri = client.getBaseUri();
Uri.Builder uriBuilder = requestUri.buildUpon();
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);

// Post Method
post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
post = new PostMethod(uriBuilder.build().toString());

post.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* ownCloud Android Library is available under MIT license
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
* @author David González Verdugo
* Copyright (C) 2018 ownCloud 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
Expand All @@ -25,6 +26,8 @@

package com.owncloud.android.lib.resources.shares;

import android.net.Uri;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand Down Expand Up @@ -59,7 +62,12 @@ protected RemoteOperationResult run(OwnCloudClient client) {

// Get the response
try {
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId));
Uri requestUri = client.getBaseUri();
Uri.Builder uriBuilder = requestUri.buildUpon();
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
uriBuilder.appendEncodedPath(Long.toString(mRemoteId));

get = new GetMethod(uriBuilder.build().toString());
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

status = client.executeMethod(get);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
*
* @author masensio
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
* @author David González Verdugo
* Copyright (C) 2018 ownCloud 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
Expand Down Expand Up @@ -112,7 +113,7 @@ public GetRemoteShareesOperation(String searchString, int page, int perPage) {

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
RemoteOperationResult result;
int status;
GetMethod get = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
* @author David González Verdugo
* Copyright (C) 2018 ownCloud 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
Expand All @@ -26,15 +27,17 @@

package com.owncloud.android.lib.resources.shares;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import android.net.Uri;

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.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;

/**
* Provide a list shares for a specific file.
* The input is the full path of the desired file.
Expand Down Expand Up @@ -71,14 +74,18 @@ public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares,

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
int status = -1;
RemoteOperationResult result;
int status;

GetMethod get = null;

try {
Uri requestUri = client.getBaseUri();
Uri.Builder uriBuilder = requestUri.buildUpon();
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);

// Get Method
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
get = new GetMethod(uriBuilder.build().toString());

// Add Parameters to Get Method
get.setQueryString(new NameValuePair[]{
Expand Down Expand Up @@ -125,5 +132,4 @@ protected RemoteOperationResult run(OwnCloudClient client) {
private boolean isSuccess(int status) {
return (status == HttpStatus.SC_OK);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@

package com.owncloud.android.lib.resources.shares;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import android.net.Uri;

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.GetMethod;

/**
* Get the data from the server about ALL the known shares owned by the requester.
*/
Expand All @@ -56,7 +58,11 @@ protected RemoteOperationResult run(OwnCloudClient client) {

// Get the response
try {
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
Uri requestUri = client.getBaseUri();
Uri.Builder uriBuilder = requestUri.buildUpon();
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);

get = new GetMethod(uriBuilder.build().toString());
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
status = client.executeMethod(get);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
* @author David González Verdugo
* Copyright (C) 2018 ownCloud 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
Expand All @@ -26,14 +27,16 @@

package com.owncloud.android.lib.resources.shares;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
import android.net.Uri;

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.jackrabbit.webdav.client.methods.DeleteMethod;

/**
* Remove a share
*/
Expand All @@ -57,14 +60,18 @@ public RemoveRemoteShareOperation(int remoteShareId) {

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
int status = -1;
RemoteOperationResult result;
int status;

DeleteMethod delete = null;

try {
String id = "/" + String.valueOf(mRemoteShareId);
delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id);
Uri requestUri = client.getBaseUri();
Uri.Builder uriBuilder = requestUri.buildUpon();
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
uriBuilder.appendEncodedPath(String.valueOf(mRemoteShareId));

delete = new DeleteMethod(uriBuilder.build().toString());

delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

Expand All @@ -79,7 +86,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
);
result = parser.parse(response);

Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage());
Log_OC.d(TAG, "Unshare " + mRemoteShareId + ": " + result.getLogMessage());

} else {
result = new RemoteOperationResult(false, delete);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* ownCloud Android Library is available under MIT license
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
* @author David González Verdugo
* Copyright (C) 2018 ownCloud 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
Expand Down Expand Up @@ -70,7 +71,7 @@ public RemoteOperationResult parse(String serverResponse) {
return new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
}

RemoteOperationResult result = null;
RemoteOperationResult result;
ArrayList<Object> resultData = new ArrayList<Object>();

try {
Expand Down
8 changes: 4 additions & 4 deletions src/com/owncloud/android/lib/resources/shares/ShareUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2018 ownCloud 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
Expand Down Expand Up @@ -30,13 +30,14 @@
* Contains Constants for Share Operation
*
* @author masensio
* @author David González Verdugo
*
*/

public class ShareUtils {

// OCS Route
public static final String SHARING_API_PATH ="/ocs/v1.php/apps/files_sharing/api/v1/shares";
public static final String SHARING_API_PATH ="ocs/v2.php/apps/files_sharing/api/v1/shares";

// String to build the link with the token of a share:
public static final String SHARING_LINK_PATH_BEFORE_VERSION_8 = "/public.php?service=files&t=";
Expand All @@ -49,5 +50,4 @@ public static String getSharingLinkPath(OwnCloudVersion version){
return SHARING_LINK_PATH_BEFORE_VERSION_8;
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2018 ownCloud 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
Expand Down Expand Up @@ -41,7 +41,7 @@
/**
* Parser for Share API Response
* @author masensio
*
* @author David González Verdugo
*/

public class ShareXMLParser {
Expand Down Expand Up @@ -82,7 +82,7 @@ public class ShareXMLParser {

private static final String TYPE_FOLDER = "folder";

private static final int SUCCESS = 100;
private static final int SUCCESS = 200;
private static final int ERROR_WRONG_PARAMETER = 400;
private static final int ERROR_FORBIDDEN = 403;
private static final int ERROR_NOT_FOUND = 404;
Expand Down Expand Up @@ -172,7 +172,7 @@ public ArrayList<OCShare> parseXMLResponse(InputStream is) throws XmlPullParserE
*/
private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException,
IOException {
ArrayList<OCShare> shares = new ArrayList<OCShare>();
ArrayList<OCShare> shares = new ArrayList<>();
parser.require(XmlPullParser.START_TAG, ns , NODE_OCS);
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
Expand All @@ -190,8 +190,6 @@ private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserEx

}
return shares;


}

/**
Expand Down Expand Up @@ -439,5 +437,4 @@ private void skip(XmlPullParser parser) throws XmlPullParserException, IOExcepti
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
try {
Uri requestUri = client.getBaseUri();
Uri.Builder uriBuilder = requestUri.buildUpon();
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1));
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH);
uriBuilder.appendEncodedPath(Long.toString(mRemoteId));
uriString = uriBuilder.build().toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {


// OCS Routes
private static final String OCS_ROUTE = "ocs/v1.php/cloud/capabilities";
private static final String OCS_ROUTE = "ocs/v2.php/cloud/capabilities";

// Arguments - names
private static final String PARAM_FORMAT = "format";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
private static final String TAG = GetRemoteUserInfoOperation.class.getSimpleName();

// OCS Route
private static final String OCS_ROUTE = "/ocs/v1.php/cloud/user?format=json";
private static final String OCS_ROUTE = "/ocs/v2.php/cloud/user?format=json";

// JSON Node names
private static final String NODE_OCS = "ocs";
Expand Down Expand Up @@ -125,5 +125,4 @@ public static class UserInfo {
public String mDisplayName = "";
public String mEmail = "";
}

}
}

0 comments on commit 9ab1b40

Please sign in to comment.