Skip to content

Commit

Permalink
cli:getObjectAsJSON completo #TASK-5160
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfeSanahuja committed Nov 2, 2023
1 parent e4962c8 commit 5226ae7
Show file tree
Hide file tree
Showing 79 changed files with 166 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023-10-27 OpenCB
* Copyright 2015-2023-11-02 OpenCB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023-10-27 OpenCB
* Copyright 2015-2023-11-02 OpenCB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
public class AnalysisAlignmentCommandExecutor extends OpencgaCommandExecutor {

public String categoryName = "analysisAlignment";
public String categoryName = "alignment";
public AnalysisAlignmentCommandOptions analysisAlignmentCommandOptions;

public AnalysisAlignmentCommandExecutor(AnalysisAlignmentCommandOptions analysisAlignmentCommandOptions) throws CatalogAuthenticationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
*/
public class AnalysisClinicalCommandExecutor extends OpencgaCommandExecutor {

public String categoryName = "analysisClinical";
public String categoryName = "clinical";
public AnalysisClinicalCommandOptions analysisClinicalCommandOptions;

public AnalysisClinicalCommandExecutor(AnalysisClinicalCommandOptions analysisClinicalCommandOptions) throws CatalogAuthenticationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
*/
public class AnalysisVariantCommandExecutor extends OpencgaCommandExecutor {

public String categoryName = "analysisVariant";
public String categoryName = "variant";
public AnalysisVariantCommandOptions analysisVariantCommandOptions;

public AnalysisVariantCommandExecutor(AnalysisVariantCommandOptions analysisVariantCommandOptions) throws CatalogAuthenticationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public class DiseasePanelsCommandExecutor extends OpencgaCommandExecutor {

public String categoryName = "diseasePanels";
public String categoryName = "panels";
public DiseasePanelsCommandOptions diseasePanelsCommandOptions;

public DiseasePanelsCommandExecutor(DiseasePanelsCommandOptions diseasePanelsCommandOptions) throws CatalogAuthenticationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,34 +225,97 @@ public OpencgaCommandExecutor setOpenCGAClient(OpenCGAClient openCGAClient) {
}

public String getObjectAsJSON(String objectCategory, String objectPath) throws Exception {
String jsonInString = "";
String jsonInString = "\n";
try {
ObjectMap queryParams = new ObjectMap();
queryParams.putIfNotEmpty("category", String.valueOf(objectCategory));
queryParams.putIfNotEmpty("category", objectCategory);
RestResponse<List> response = openCGAClient.getMetaClient().api(queryParams);
ObjectMapper jsonObjectMapper = new ObjectMapper();
for (List list : response.getResponses().get(0).getResults()) {
List<RestCategory> categories = jsonObjectMapper.convertValue(list, new TypeReference<List<RestCategory>>() {});
for (RestCategory category : categories) {
for (RestEndpoint endpoint: category.getEndpoints()){
if(objectPath.equals(endpoint.getPath())){
for (RestParameter parameter:endpoint.getParameters()){
for (RestEndpoint endpoint : category.getEndpoints()) {
if (objectPath.equals(endpoint.getPath())) {
boolean enc = false;
for (RestParameter parameter : endpoint.getParameters()) {
//jsonInString += parameter.getName()+":"+parameter.getAllowedValues()+"\n";
jsonInString += parameter.toString()+"\n";
if (parameter.getData() != null) {
enc = true;
jsonInString += printBody(parameter.getData(), "");
}
}
if (!enc) {
jsonInString += "No model available";
}
//
}
}
}
}
// jsonInString = DataModelsUtils.dataModelToJsonString(o.getClass());
}
} catch (Exception e) {
jsonInString = "Data model not found.";
CommandLineUtils.error(e);
}
return jsonInString;
}

private String printBody(List<RestParameter> data, String tabs) {
String res = "";
res += "{\n";
String tab = " " + tabs;
for (RestParameter parameter : data) {
if (parameter.getData() == null) {
res += printParameter(parameter, tab);
} else {
res += tab + parameter.getName() + "\"" + ": [" + printBody(parameter.getData(), tab) + "],\n";
}
}
res += tabs + "}";
return res;

}

private String printParameter(RestParameter parameter, String tab) {

return tab + "\"" + parameter.getName() + "\"" + ":" + printParameterValue(parameter) + ",\n";
}

private String printParameterValue(RestParameter parameter) {

if(!StringUtils.isEmpty(parameter.getAllowedValues())){
return parameter.getAllowedValues().replace(" ", "|");
}
switch (parameter.getType()) {
case "Boolean":
case "java.lang.Boolean":
return "false";
case "Long":
case "Float":
case "Double":
case "Integer":
case "int":
case "double":
case "float":
case "long":
return "0";
case "List":
return "[\"\"]";
case "Date":
return "\"dd/mm/yyyy\"";
case "Map":
return "{\"key\": \"value\"}";
case "String":
return "\"\"";
default:
return "\"-\"";
}
}

private boolean isNumeric(String type) {

return "int".equals(type) || "Long".equals(type) || "Float".equals(type) || "double".equals(type);
}

public RestResponse<AuthenticationResponse> saveSession(String user, AuthenticationResponse response) throws ClientException, IOException {
RestResponse<AuthenticationResponse> res = new RestResponse<>();
if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
*/
public class OperationsVariantStorageCommandExecutor extends OpencgaCommandExecutor {

public String categoryName = "operationsVariantStorage";
public String categoryName = "operation";
public OperationsVariantStorageCommandOptions operationsVariantStorageCommandOptions;

public OperationsVariantStorageCommandExecutor(OperationsVariantStorageCommandOptions operationsVariantStorageCommandOptions) throws CatalogAuthenticationException {
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/Admin-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/Alignment-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
14 changes: 7 additions & 7 deletions opencga-client/src/main/R/R/AllGenerics.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# ##############################################################################
## UserClient
setGeneric("userClient", function(OpencgaR, user, filterId, users, endpointName, params=NULL, ...)
setGeneric("userClient", function(OpencgaR, filterId, user, users, endpointName, params=NULL, ...)
standardGeneric("userClient"))

# ##############################################################################
## ProjectClient
setGeneric("projectClient", function(OpencgaR, projects, project, endpointName, params=NULL, ...)
setGeneric("projectClient", function(OpencgaR, project, projects, endpointName, params=NULL, ...)
standardGeneric("projectClient"))

# ##############################################################################
## StudyClient
setGeneric("studyClient", function(OpencgaR, templateId, variableSet, study, group, studies, members, endpointName, params=NULL, ...)
setGeneric("studyClient", function(OpencgaR, group, members, studies, study, templateId, variableSet, endpointName, params=NULL, ...)
standardGeneric("studyClient"))

# ##############################################################################
## FileClient
setGeneric("fileClient", function(OpencgaR, files, file, folder, annotationSet, members, endpointName, params=NULL, ...)
setGeneric("fileClient", function(OpencgaR, files, file, members, annotationSet, folder, endpointName, params=NULL, ...)
standardGeneric("fileClient"))

# ##############################################################################
Expand All @@ -25,7 +25,7 @@ setGeneric("jobClient", function(OpencgaR, jobs, members, job, endpointName, par

# ##############################################################################
## SampleClient
setGeneric("sampleClient", function(OpencgaR, sample, samples, members, annotationSet, endpointName, params=NULL, ...)
setGeneric("sampleClient", function(OpencgaR, samples, members, sample, annotationSet, endpointName, params=NULL, ...)
standardGeneric("sampleClient"))

# ##############################################################################
Expand All @@ -35,7 +35,7 @@ setGeneric("individualClient", function(OpencgaR, individual, members, individua

# ##############################################################################
## FamilyClient
setGeneric("familyClient", function(OpencgaR, annotationSet, members, family, families, endpointName, params=NULL, ...)
setGeneric("familyClient", function(OpencgaR, members, family, families, annotationSet, endpointName, params=NULL, ...)
standardGeneric("familyClient"))

# ##############################################################################
Expand All @@ -60,7 +60,7 @@ setGeneric("variantClient", function(OpencgaR, endpointName, params=NULL, ...)

# ##############################################################################
## ClinicalClient
setGeneric("clinicalClient", function(OpencgaR, clinicalAnalysis, clinicalAnalyses, interpretations, members, interpretation, endpointName, params=NULL, ...)
setGeneric("clinicalClient", function(OpencgaR, clinicalAnalysis, members, interpretation, interpretations, clinicalAnalyses, endpointName, params=NULL, ...)
standardGeneric("clinicalClient"))

# ##############################################################################
Expand Down
4 changes: 2 additions & 2 deletions opencga-client/src/main/R/R/Clinical-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down Expand Up @@ -58,7 +58,7 @@
#' [*]: Required parameter
#' @export

setMethod("clinicalClient", "OpencgaR", function(OpencgaR, clinicalAnalysis, clinicalAnalyses, interpretations, members, interpretation, endpointName, params=NULL, ...) {
setMethod("clinicalClient", "OpencgaR", function(OpencgaR, clinicalAnalysis, members, interpretation, interpretations, clinicalAnalyses, endpointName, params=NULL, ...) {
switch(endpointName,

#' @section Endpoint /{apiVersion}/analysis/clinical/acl/{members}/update:
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/Cohort-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
4 changes: 2 additions & 2 deletions opencga-client/src/main/R/R/Family-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down Expand Up @@ -38,7 +38,7 @@
#' [*]: Required parameter
#' @export

setMethod("familyClient", "OpencgaR", function(OpencgaR, annotationSet, members, family, families, endpointName, params=NULL, ...) {
setMethod("familyClient", "OpencgaR", function(OpencgaR, members, family, families, annotationSet, endpointName, params=NULL, ...) {
switch(endpointName,

#' @section Endpoint /{apiVersion}/families/acl/{members}/update:
Expand Down
4 changes: 2 additions & 2 deletions opencga-client/src/main/R/R/File-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down Expand Up @@ -54,7 +54,7 @@
#' [*]: Required parameter
#' @export

setMethod("fileClient", "OpencgaR", function(OpencgaR, files, file, folder, annotationSet, members, endpointName, params=NULL, ...) {
setMethod("fileClient", "OpencgaR", function(OpencgaR, files, file, members, annotationSet, folder, endpointName, params=NULL, ...) {
switch(endpointName,

#' @section Endpoint /{apiVersion}/files/acl/{members}/update:
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/GA4GH-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/Individual-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/Job-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/Meta-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/Operation-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion opencga-client/src/main/R/R/Panel-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down
4 changes: 2 additions & 2 deletions opencga-client/src/main/R/R/Project-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down Expand Up @@ -34,7 +34,7 @@
#' [*]: Required parameter
#' @export

setMethod("projectClient", "OpencgaR", function(OpencgaR, projects, project, endpointName, params=NULL, ...) {
setMethod("projectClient", "OpencgaR", function(OpencgaR, project, projects, endpointName, params=NULL, ...) {
switch(endpointName,

#' @section Endpoint /{apiVersion}/projects/create:
Expand Down
4 changes: 2 additions & 2 deletions opencga-client/src/main/R/R/Sample-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: AUTOGENERATED CODE
#
# This code was generated by a tool.
# Autogenerated on: 2023-10-27
# Autogenerated on: 2023-11-02
#
# Manual changes to this file may cause unexpected behavior in your application.
# Manual changes to this file will be overwritten if the code is regenerated.
Expand Down Expand Up @@ -39,7 +39,7 @@
#' [*]: Required parameter
#' @export

setMethod("sampleClient", "OpencgaR", function(OpencgaR, sample, samples, members, annotationSet, endpointName, params=NULL, ...) {
setMethod("sampleClient", "OpencgaR", function(OpencgaR, samples, members, sample, annotationSet, endpointName, params=NULL, ...) {
switch(endpointName,

#' @section Endpoint /{apiVersion}/samples/acl/{members}/update:
Expand Down
Loading

0 comments on commit 5226ae7

Please sign in to comment.