Skip to content

Commit

Permalink
Feat: list shared (#82)
Browse files Browse the repository at this point in the history
* feat: init feat list shared

* feat: advance in feat, iterating array of sharefiles

* fix: format

* feat: adding get shared list in py client

* refactor: generating array of files

* feat: adding changes in feat and tests

* fix: updating file of services where is createFileArray method

* fix: format

* refactor: move all related to share tests to ITShareManagement

* fix: adding missing auth, typo and unnecesary field

* fix: format
  • Loading branch information
SilviaPabon authored Oct 20, 2023
1 parent 2f0e7fd commit 6d99b5c
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 163 deletions.
21 changes: 2 additions & 19 deletions app/src/main/java/gateway/controller/CtrlFileList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gateway.config.Config;
import gateway.services.ServiceAuth;
import gateway.services.UtilsFiles;
import gateway.soap.request.ReqFileList;
import gateway.soap.response.File;
import gateway.soap.response.ResFileList;
Expand Down Expand Up @@ -54,25 +55,7 @@ public static ResFileList file_list (ReqFileList args)
if (resFileList.code == 200) {
// If the response code is 200, process the received files
JSONArray filesArray = responseBody.getJSONArray ("files");
File[] files = new File[filesArray.length ()];

for (int i = 0; i < filesArray.length (); i++) {
// Process each file in the response JSON
JSONObject fileObject = filesArray.getJSONObject (i);

// Create a File object and assign it the file information
File file = new File ();

file.uuid = UUID.fromString (fileObject.getString ("uuid"));
file.name = fileObject.getString ("fileName");
file.extension = fileObject.isNull ("fileExtension")
? null
: fileObject.getString ("fileExtension");
file.isFile = fileObject.getString ("fileType").equals ("archive");
file.size = fileObject.getInt ("fileSize");

files[i] = file;
}
File[] files = UtilsFiles.createFileArray (filesArray);

resFileList.files = files;
resFileList.error = false;
Expand Down
66 changes: 66 additions & 0 deletions app/src/main/java/gateway/controller/CtrlShareList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package gateway.controller;

import gateway.config.Config;
import gateway.services.ServiceAuth;
import gateway.services.UtilsFiles;
import gateway.soap.request.Authorization;
import gateway.soap.response.File;
import gateway.soap.response.ResShareList;
import gateway.soap.response.ResStatus;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject;

public class CtrlShareList
{
public static ResShareList share_list (Authorization authorization)
{
ResShareList resShareList = new ResShareList ();

ResStatus resAuth = ServiceAuth.authenticate (authorization.token);
if (resAuth.error) {
return ResStatus.downCast (ResShareList.class, resAuth);
}

// obtain uuid from user
UUID userUUID = UUID.fromString (ServiceAuth.tokenGetClaim (authorization.token, "uuid"));

String url = Config.getMetadataBaseUrl () + "/files/shared_with_me/" + userUUID;

try {

HttpResponse<String> response = HttpClient.newHttpClient ().send (
HttpRequest.newBuilder ().uri (URI.create (url)).GET ().build (),
HttpResponse.BodyHandlers.ofString ());

// Response
JSONObject responseBody = new JSONObject (response.body ());
resShareList.code = response.statusCode ();

if (resShareList.code == 200) {
// If the response code is 200, process the received files
JSONArray shareFilesArray = responseBody.getJSONArray ("files");
File[] shareFiles = UtilsFiles.createFileArray (shareFilesArray);

resShareList.error = false;
resShareList.sharedFiles = shareFiles;
resShareList.msg = "Ok. The directory was listed.";
} else {
resShareList.error = true;
resShareList.msg = responseBody.getString ("message");
}

} catch (Exception e) {
e.printStackTrace ();
resShareList.code = 500;
resShareList.error = true;
resShareList.msg = "Internal error, try again later";
}

return resShareList;
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/gateway/services/UtilsFiles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gateway.services;

import gateway.soap.response.File;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject;

public class UtilsFiles
{
public static File[] createFileArray (JSONArray jsonArray)
{
File[] files = new File[jsonArray.length ()];

for (int i = 0; i < jsonArray.length (); i++) {
JSONObject fileObject = jsonArray.getJSONObject (i);
File file = new File ();

file.uuid = UUID.fromString (fileObject.getString ("uuid"));
file.name = fileObject.getString ("fileName");
file.extension =
fileObject.isNull ("fileExtension") ? null : fileObject.getString ("fileExtension");
file.isFile = fileObject.getString ("fileType").equals ("archive");
file.size = fileObject.getInt ("fileSize");

files[i] = file;
}

return files;
}
}
5 changes: 4 additions & 1 deletion app/src/main/java/gateway/soap/ServiceImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@

@WebMethod public ResStatus unshare_file (ReqShareRemove args) { return null; }

@WebMethod public ResShareList share_list (Authorization auth) { return null; }
@WebMethod public ResShareList share_list (Authorization auth)
{
return CtrlShareList.share_list (auth);
}

@WebMethod public ResShareListWithWho share_list_with_who (ReqFile args)
{
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/gateway/soap/response/ResShareList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class ResShareList extends ResStatus
{
public SharedFile[] sharedFiles;
public File[] sharedFiles;
}
6 changes: 0 additions & 6 deletions app/src/main/java/gateway/soap/response/SharedFile.java

This file was deleted.

63 changes: 0 additions & 63 deletions app/src/test/java/gateway/ITShareFile.java

This file was deleted.

73 changes: 0 additions & 73 deletions app/src/test/java/gateway/ITShareListWhitWho.java

This file was deleted.

Loading

0 comments on commit 6d99b5c

Please sign in to comment.