-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
2f0e7fd
commit 6d99b5c
Showing
12 changed files
with
282 additions
and
163 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
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,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; | ||
} | ||
} |
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,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; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
public class ResShareList extends ResStatus | ||
{ | ||
public SharedFile[] sharedFiles; | ||
public File[] sharedFiles; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.