diff --git a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java index 873dba34923825c3aacdbb90759a5fc3fabae3a2..b936cdd35a7dadb97ca7d1d95a2a0167d00527b8 100644 --- a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java @@ -13,12 +13,10 @@ import eu.hbp.mip.controllers.retrofit.RetrofitClientInstance; import eu.hbp.mip.dto.ErrorResponse; import eu.hbp.mip.dto.GalaxyWorkflowResult; import eu.hbp.mip.dto.PostWorkflowToGalaxyDtoResponse; -import eu.hbp.mip.helpers.LogHelper; import eu.hbp.mip.model.*; import eu.hbp.mip.repositories.ExperimentRepository; import eu.hbp.mip.repositories.ModelRepository; import eu.hbp.mip.utils.HTTPUtil; -import eu.hbp.mip.utils.JWTUtil; import eu.hbp.mip.utils.UserActionLogging; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -300,7 +298,7 @@ public class ExperimentApi { } } - if(!resultFound) { // If there is no visible result + if (!resultFound) { // If there is no visible result UserActionLogging.LogAction("Get workflow experiment", "No visible result"); experiment.setResult(new ErrorResponse("The workflow has no visible result.", "500").toString()); experiment.setHasError(true); @@ -333,7 +331,7 @@ public class ExperimentApi { } } - if(!failedJobFound) { // If there is no visible failed job + if (!failedJobFound) { // If there is no visible failed job UserActionLogging.LogAction("Get workflow experiment", "No failed result"); experiment.setResult(new ErrorResponse("The workflow has no failed result.", "500").toString()); experiment.setHasError(true); @@ -477,20 +475,20 @@ public class ExperimentApi { /** * @param jobId the id of the workflow job that failed - * @return the error that was produced or null if an error occurred + * @return the error that was produced or null if an error occurred */ - public String getWorkflowJobError(String jobId){ + public String getWorkflowJobError(String jobId) { UserActionLogging.LogAction("Get workflow job error", " jobId : " + jobId); RetroFitGalaxyClients service = RetrofitClientInstance.getRetrofitInstance().create(RetroFitGalaxyClients.class); - Call<Object> callError = service.getErrorMessageOfWorkflowFromGalaxy(jobId,galaxyApiKey); + Call<Object> callError = service.getErrorMessageOfWorkflowFromGalaxy(jobId, galaxyApiKey); String fullError = null; String returnError = null; try { Response<Object> response = callError.execute(); - if(response.code() >= 400){ - UserActionLogging.LogAction("Get workflow job error","Response code: " + if (response.code() >= 400) { + UserActionLogging.LogAction("Get workflow job error", "Response code: " + response.code() + " with body: " + (response.errorBody() != null ? response.errorBody().string() : " ")); return null; } @@ -500,19 +498,19 @@ public class ExperimentApi { JsonElement jsonElement = new JsonParser().parse(jsonString); JsonObject rootObject = jsonElement.getAsJsonObject(); fullError = rootObject.get("stderr").getAsString(); - UserActionLogging.LogAction("Get workflow job error","Error: " + fullError); + UserActionLogging.LogAction("Get workflow job error", "Error: " + fullError); String[] arrOfStr = fullError.split("ValueError", 0); - String specError = arrOfStr[arrOfStr.length-1]; + String specError = arrOfStr[arrOfStr.length - 1]; returnError = specError.substring(1); - UserActionLogging.LogAction("Get workflow job error","Parsed Error: " + returnError); + UserActionLogging.LogAction("Get workflow job error", "Parsed Error: " + returnError); } catch (IOException e) { - UserActionLogging.LogAction("Get workflow job error","Exception: " + e.getMessage()); + UserActionLogging.LogAction("Get workflow job error", "Exception: " + e.getMessage()); return null; } - UserActionLogging.LogAction("Get workflow job error","Completed successfully!"); + UserActionLogging.LogAction("Get workflow job error", "Completed successfully!"); return returnError; } diff --git a/src/main/java/eu/hbp/mip/controllers/GalaxyAPI.java b/src/main/java/eu/hbp/mip/controllers/GalaxyAPI.java deleted file mode 100644 index 41c8a6576b4277658c58ec4e4d2b5afcc0f66359..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/controllers/GalaxyAPI.java +++ /dev/null @@ -1,485 +0,0 @@ -package eu.hbp.mip.controllers; - -import com.github.jmchilton.blend4j.galaxy.GalaxyInstance; -import com.github.jmchilton.blend4j.galaxy.GalaxyInstanceFactory; -import com.github.jmchilton.blend4j.galaxy.WorkflowsClient; -import com.github.jmchilton.blend4j.galaxy.beans.Workflow; -import com.github.jmchilton.blend4j.galaxy.beans.WorkflowDetails; -import com.github.jmchilton.blend4j.galaxy.beans.WorkflowInputDefinition; -import com.google.gson.*; -import eu.hbp.mip.controllers.retrofit.RetroFitGalaxyClients; -import eu.hbp.mip.controllers.retrofit.RetrofitClientInstance; -import eu.hbp.mip.dto.ErrorResponse; -import eu.hbp.mip.dto.GalaxyWorkflowResult; -import eu.hbp.mip.dto.PostWorkflowToGalaxyDtoResponse; -import eu.hbp.mip.dto.StringDtoResponse; -import eu.hbp.mip.helpers.LogHelper; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.web.bind.annotation.*; -import retrofit2.Call; -import retrofit2.Response; - -import java.io.IOException; -import java.util.*; - -@RestController -@RequestMapping("/galaxyApi/") -class GalaxyAPI { - - private static final Logger logger = LoggerFactory.getLogger(GalaxyAPI.class); - - //The galaxy URL - private final String url = "123"; - - //The galaxy ApiKey - private final String apiKey = "123;"; - - /** - * Test if integration works. - * - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.GET, value = "getTestIntegration", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getTestIntegration(@AuthenticationPrincipal UserDetails userDetails){ - logger.info(LogHelper.logUser(userDetails) + "Get Test Integration called"); - return ResponseEntity.ok(new StringDtoResponse("success")); - } - - /** - * Get Galaxy Reverse Proxy basic access token. - * - * @return Return a @{@link ResponseEntity} with the token. - */ - @RequestMapping(method = RequestMethod.GET, value = "getGalaxyBasicAccessToken", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getGalaxyBasicAccessToken(@AuthenticationPrincipal UserDetails userDetails){ - logger.info(LogHelper.logUser(userDetails) + "Get Galaxy Basic Access Token called"); - String username = "admin"; - String password = "passwrod"; - - String stringEncoded = Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); - logger.info(LogHelper.logUser(userDetails) + "Get Galaxy Basic Access Token completed"); - return ResponseEntity.ok(username + ":" + password); - // return ResponseEntity.ok(new StringDtoResponse(stringEncoded)); - } - - /** - * Get all the workflows with few details. - * - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.GET, value = "getWorkflows", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getWorkflows(@AuthenticationPrincipal UserDetails userDetails) { - logger.info(LogHelper.logUser(userDetails) + "Get workflows called"); - - final GalaxyInstance instance = GalaxyInstanceFactory.get(url, apiKey); - final WorkflowsClient workflowsClient = instance.getWorkflowsClient(); - - ArrayList<Workflow> workflowArrayList = new ArrayList<>(); - workflowArrayList.addAll(workflowsClient.getWorkflows()); - logger.info(LogHelper.logUser(userDetails) + "Get workflows completed"); - - return ResponseEntity.ok(workflowArrayList); - } - - /** - * Get details for a specific workflow. - * - * @param id : The id as @{@link String} for the specific workflow. - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.GET, value = "/getDetailWorkflow/{id}", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getDetailWorkflow(@AuthenticationPrincipal UserDetails userDetails, @PathVariable String id) { - logger.info(LogHelper.logUser(userDetails) + "Get detail workflow called"); - - final GalaxyInstance instance = GalaxyInstanceFactory.get(url, apiKey); - final WorkflowsClient workflowsClient = instance.getWorkflowsClient(); - - Workflow matchingWorkflow = null; - for(Workflow workflow : workflowsClient.getWorkflows()) { - if(workflow.getId().equals(id)) { - matchingWorkflow = workflow; - } - } - if(matchingWorkflow == null){ - logger.error(LogHelper.logUser(userDetails) + "Get detail workflow could not find workflow with id : " + id); - return ResponseEntity.notFound().build(); - } - final WorkflowDetails workflowDetails = workflowsClient.showWorkflow(matchingWorkflow.getId()); - logger.info(LogHelper.logUser(userDetails) + "Get detail workflow completed"); - - return ResponseEntity.ok(workflowDetails); - } - - /** - * Get all the workflows with details. - * - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.GET, value = "getAllWorkflowWithDetails", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getAllWorkflowWithDetails(@AuthenticationPrincipal UserDetails userDetails) { - logger.info(LogHelper.logUser(userDetails) + "Get all workflow with details called"); - - final GalaxyInstance instance = GalaxyInstanceFactory.get(url, apiKey); - final WorkflowsClient workflowsClient = instance.getWorkflowsClient(); - - List<Workflow> workflowList = new ArrayList<Workflow>(); - for(Workflow workflow : workflowsClient.getWorkflows()) { - workflowList.add(workflow); - } - - List<WorkflowDetails> workflowDetailsList = new ArrayList<>(); - for(Workflow workflow : workflowList){ - workflowDetailsList.add(workflowsClient.showWorkflow(workflow.getId())); - } - logger.info(LogHelper.logUser(userDetails) + "Get all workflow with details completed"); - - return ResponseEntity.ok(workflowDetailsList); - } - - /** - * Invoke a workflow. - * - * @param id : The id as @{@link String} of the workflow. - * @param httpEntity : The @{@link HttpEntity} to get the body of the request which is the parameter of the workflow. - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.POST, value = "/runWorkflow/{id}", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity runWorkflow(@AuthenticationPrincipal UserDetails userDetails, @PathVariable String id, HttpEntity<String> httpEntity) { - logger.info(LogHelper.logUser(userDetails) + "Run workflow called"); - - //In order to parse Json with undefined number of value/key - String json = httpEntity.getBody(); - JSONObject jObject = null; - try { - jObject = new JSONObject(json); - } catch (JSONException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot parse JSON", e); - } - Map<String,String> allJsonParams = new HashMap<String,String>(); - Iterator iter = jObject.keys(); - while(iter.hasNext()){ - String key = (String)iter.next(); - String value = null; - try { - value = jObject.getString(key); - } catch (JSONException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot parse JSON", e); - } - logger.info(LogHelper.logUser(userDetails) + "Put to map: " + key + " : " + value); - allJsonParams.put(key,value); - } - final GalaxyInstance instance = GalaxyInstanceFactory.get(url, apiKey); - final WorkflowsClient workflowsClient = instance.getWorkflowsClient(); - - Workflow matchingWorkflow = null; - for(Workflow workflow : workflowsClient.getWorkflows()) { - if(workflow.getId().equals(id)) { - matchingWorkflow = workflow; - } - } - if(matchingWorkflow == null){ - logger.error(LogHelper.logUser(userDetails) + "Run workflow could not find workflow with id : " + id + " ,in order to get missing input parameters"); - return ResponseEntity.notFound().build(); - } - final WorkflowDetails workflowDetails = workflowsClient.showWorkflow(matchingWorkflow.getId()); - for (Map.Entry<String, WorkflowInputDefinition> entry : workflowDetails.getInputs().entrySet()) { - if(!(allJsonParams.containsKey(entry.getValue().getUuid()))) { - logger.warn("Find extra value with label:" + entry.getValue().getLabel() + ", and uuid:" + entry.getValue().getUuid() + ", that is mandatory to run the workflow. The uuid will be automate add it with empty value in the parameters to run the workflow."); - allJsonParams.put(entry.getValue().getUuid(), ""); - } - } - - //// - - StringBuffer stringBuffer = new StringBuffer("{\n" + - "\t\"inputs\": {\n"); - for (Map.Entry<String, String> entry : allJsonParams.entrySet()) { - stringBuffer.append("\t\t\"" + entry.getKey() + "\" " + " : \"" + entry.getValue() + "\",\n"); - logger.debug(LogHelper.logUser(userDetails) + entry.getKey() + "/" + entry.getValue()); - } - //Remove Last Comma - stringBuffer.deleteCharAt(stringBuffer.length() - 2); - stringBuffer.append("\t}\n"); - stringBuffer.append("}"); - logger.info(LogHelper.logUser(userDetails) + stringBuffer.toString()); - - JsonObject jsonObject = new JsonParser().parse(stringBuffer.toString()).getAsJsonObject(); - - RetroFitGalaxyClients service = RetrofitClientInstance.getRetrofitInstance().create(RetroFitGalaxyClients.class); - Call<PostWorkflowToGalaxyDtoResponse> call = service.postWorkflowToGalaxy(id, apiKey, jsonObject); - - PostWorkflowToGalaxyDtoResponse postWorkflowToGalaxyDtoResponse = null; - try { - Response<PostWorkflowToGalaxyDtoResponse> response = call.execute(); - if(response.code() >= 400){ - //Value are read it from streams. - Integer codeErr = response.code(); - String msgErr = response.errorBody().string(); - logger.error(LogHelper.logUser(userDetails) + "Resonse code: " + codeErr + "" + " with body: " + msgErr); - logger.info("---" + msgErr); - JSONObject jObjectError = null; - try { - jObjectError = new JSONObject(msgErr); - } catch (JSONException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot parse Error JSON", e); - } - logger.info(jObjectError.toString()); - String errMsg = jObjectError.get("err_msg").toString(); - String errCode = jObjectError.get("err_code").toString(); - - response.errorBody(); - return ResponseEntity - .status(HttpStatus.BAD_REQUEST) - .body(new ErrorResponse(errMsg,errCode)); - } - postWorkflowToGalaxyDtoResponse = response.body(); - logger.info(LogHelper.logUser(userDetails) + "----" + response.body() + "----" + response.code()); - } catch (IOException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot make the call to Galaxy API", e); - return ResponseEntity - .status(HttpStatus.BAD_REQUEST) - .body(new ErrorResponse("An error has been occurred","99")); - } catch (JSONException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot find field in Error Json", e); - return ResponseEntity - .status(HttpStatus.BAD_REQUEST) - .body(new ErrorResponse("An error has been occurred","99")); - } - logger.info(LogHelper.logUser(userDetails) + "Run workflow completed"); - - return ResponseEntity.ok(postWorkflowToGalaxyDtoResponse); - } - - /** - * Get the status of a specific workflow. - * - * @param id : The id as @{@link String} of the workflow. - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.GET, value = "/getWorkflowStatus/{id}", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getWorkflowStatus(@AuthenticationPrincipal UserDetails userDetails, @PathVariable String id) { - logger.info(LogHelper.logUser(userDetails) + "Get workflow status called"); - - RetroFitGalaxyClients service = RetrofitClientInstance.getRetrofitInstance().create(RetroFitGalaxyClients.class); - Call<Object> call = service.getWorkflowStatusFromGalaxy(id,apiKey); - - String jsonString = null; - try { - Response<Object> response = call.execute(); - if(response.code() >= 400){ - logger.error(LogHelper.logUser(userDetails) + "Resonse code: " + response.code() + "" + " with body: " + response.errorBody().string()); - return ResponseEntity.badRequest().build(); - } - jsonString = new Gson().toJson(response.body()); - logger.info(LogHelper.logUser(userDetails) + jsonString); - - logger.info(LogHelper.logUser(userDetails) + "----" + response.body() + "----" + response.code()); - } catch (IOException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot make the call to Galaxy API", e); - } - logger.info(LogHelper.logUser(userDetails) + "Get workflow status completed"); - - return ResponseEntity.ok(jsonString); - } - - /** - * Get the status of a multiple workflows. - * @param httpEntity : The @{@link HttpEntity} to get the body of the request which is the workflow ID. - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.GET, value = "/getMultipleWorkflowStatus", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getMultipleWorkflowStatus(@AuthenticationPrincipal UserDetails userDetails, HttpEntity<String> httpEntity) { - logger.info(LogHelper.logUser(userDetails) + "Get Multiple workflow status called"); - - //In order to parse Json with undefined number of value/key - String json = httpEntity.getBody(); - JSONObject jObject = null; - try { - jObject = new JSONObject(json); - } catch (JSONException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot parse JSON", e); - } - Map<String,String> allJsonParams = new HashMap<String,String>(); - Iterator iter = jObject.keys(); - - while(iter.hasNext()){ - String key = (String)iter.next(); - String value = null; - try { - value = jObject.getString(key); - System.out.println(key + ":" + value); - } catch (JSONException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot parse JSON", e); - } - logger.info(LogHelper.logUser(userDetails) + "Put to map: " + key + " : " + value); - allJsonParams.put(key,value); - } - - StringBuffer stringBuffer = new StringBuffer(); - for (Map.Entry<String, String> entry : allJsonParams.entrySet()) { - RetroFitGalaxyClients service = RetrofitClientInstance.getRetrofitInstance().create(RetroFitGalaxyClients.class); - Call<Object> call = service.getWorkflowStatusFromGalaxy(entry.getValue(),apiKey); - - String jsonString = null; - try { - Response<Object> response = call.execute(); - if(response.code() >= 400){ - logger.error(LogHelper.logUser(userDetails) + "Resonse code: " + response.code() + "" + " with body: " + response.errorBody().string()); - return ResponseEntity.badRequest().build(); - } - jsonString = new Gson().toJson(response.body()); - logger.info(LogHelper.logUser(userDetails) + jsonString); - stringBuffer.append(jsonString + ","); - logger.info(LogHelper.logUser(userDetails) + "----" + response.body() + "----" + response.code()); - } catch (IOException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot make the call to Galaxy API", e); - } - } - stringBuffer.deleteCharAt(stringBuffer.length() - 1); - logger.info(LogHelper.logUser(userDetails) + "Get Multiple workflow status completed"); - return ResponseEntity.ok(stringBuffer.toString()); - } - - /** - * Get the result of a specific workflow. - * - * @param id : The id as @{@link String} of the workflow. - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.GET, value = "/getWorkflowResults/{id}", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getWorkflowResults(@AuthenticationPrincipal UserDetails userDetails, @PathVariable String id) { - logger.info(LogHelper.logUser(userDetails) + "Get workflow results called"); - - RetroFitGalaxyClients service = RetrofitClientInstance.getRetrofitInstance().create(RetroFitGalaxyClients.class); - Call<List<GalaxyWorkflowResult>> call = service.getWorkflowResultsFromGalaxy(id,apiKey); - - List<GalaxyWorkflowResult> workflowGalaxyDtoResponsesList = null; - try { - Response<List<GalaxyWorkflowResult>> response = call.execute(); - if(response.code() >= 400){ - logger.error(LogHelper.logUser(userDetails) + "Resonse code: " + response.code() + "" + " with body: " + response.errorBody().string()); - return ResponseEntity.badRequest().build(); - } - workflowGalaxyDtoResponsesList = response.body(); - } catch (IOException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot make the call to Galaxy API", e); - } - logger.info(LogHelper.logUser(userDetails) + "Get workflow results completed"); - - return ResponseEntity.ok(workflowGalaxyDtoResponsesList); - } - - /** - * Get the result body of a specific workflow. - * - * @param id : The id as @{@link String} of the workflow. - * @param contentId : The content id as @{@link String}. - * @return Return a @{@link ResponseEntity}. - */ - @RequestMapping(method = RequestMethod.GET, value = "/getWorkflowResultsBody/{id}/contents/{contentId}", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getWorkflowResultsBody(@AuthenticationPrincipal UserDetails userDetails, @PathVariable String id, @PathVariable String contentId) { - logger.info(LogHelper.logUser(userDetails) + "Get workflow results body called"); - - RetroFitGalaxyClients service = RetrofitClientInstance.getRetrofitInstance().create(RetroFitGalaxyClients.class); - Call<Object> call = service.getWorkflowResultsBodyFromGalaxy(id,contentId,apiKey); - - String jsonString = null; - try { - Response<Object> response = call.execute(); - if(response.code() >= 400){ - logger.error(LogHelper.logUser(userDetails) + "Resonse code: " + response.code() + "" + " with body: " + response.errorBody().string()); - return ResponseEntity.badRequest().build(); - } - jsonString = new Gson().toJson(response.body()); - logger.info(LogHelper.logUser(userDetails) + "----" + response.body() + "----" + response.code()); - } catch (IOException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot make the call to Galaxy API", e); - } - logger.info(LogHelper.logUser(userDetails) + "Get workflow results body completed"); - - return ResponseEntity.ok(jsonString); - } - - @RequestMapping(method = RequestMethod.GET, value = "getErrorMessageOfWorkflow/{id}", produces = "application/json") - @ResponseStatus(value = HttpStatus.OK) - public ResponseEntity getErrorMessageOfWorkflow(@AuthenticationPrincipal UserDetails userDetails, @PathVariable String id) { - logger.info(LogHelper.logUser(userDetails) + "Get error message of workflow called"); - - RetroFitGalaxyClients service = RetrofitClientInstance.getRetrofitInstance().create(RetroFitGalaxyClients.class); - Call<Object> call = service.getWorkflowStatusFromGalaxy(id,apiKey); - String errorState = null; - try { - Response<Object> response = call.execute(); - if(response.code() >= 400){ - logger.error(LogHelper.logUser(userDetails) + "Resonse code: " + response.code() + "" + " with body: " + response.errorBody().string()); - return ResponseEntity.badRequest().build(); - } - JsonParser parser = new JsonParser(); - String jsonString = new Gson().toJson(response.body()); - JsonElement jsonElement = parser.parse(jsonString); - JsonObject rootObject = jsonElement.getAsJsonObject(); - String state = rootObject.get("state").getAsString(); - if(state.equals("error")){ - JsonArray arrayOfErrors = rootObject.get("state_ids").getAsJsonObject().get("error").getAsJsonArray(); - errorState = arrayOfErrors.get(0).getAsString(); - }else{ - logger.warn("Unknown state of the workflow."); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } - - logger.info(LogHelper.logUser(userDetails) + jsonString); - - logger.info(LogHelper.logUser(userDetails) + "----" + response.body() + "----" + response.code()); - } catch (IOException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot make the call to Galaxy API", e); - } - - Call<Object> callError = service.getErrorMessageOfWorkflowFromGalaxy(errorState,apiKey); - - String fullError = null; - String returnError = null; - try { - Response<Object> response = callError.execute(); - if(response.code() >= 400){ - logger.error(LogHelper.logUser(userDetails) + "Resonse code: " + response.code() + "" + " with body: " + response.errorBody().string()); - return ResponseEntity.badRequest().build(); - } - JsonParser parser = new JsonParser(); - String jsonString = new Gson().toJson(response.body()); - System.out.println(jsonString); - JsonElement jsonElement = parser.parse(jsonString); - JsonObject rootObject = jsonElement.getAsJsonObject(); - fullError = rootObject.get("stderr").getAsString(); - String[] arrOfStr = fullError.split("ValueError", 0); - String specError = arrOfStr[arrOfStr.length-1]; - returnError = specError.substring(1); - - System.out.println(fullError); - logger.info(LogHelper.logUser(userDetails) + "----" + response.body() + "----" + response.code()); - } catch (IOException e) { - logger.error(LogHelper.logUser(userDetails) + "Cannot make the call to Galaxy API", e); - } - - logger.info(LogHelper.logUser(userDetails) + "Get error message of workflow completed"); - - return ResponseEntity.ok(returnError); - } -} \ No newline at end of file diff --git a/src/main/java/eu/hbp/mip/controllers/MethodsApi.java b/src/main/java/eu/hbp/mip/controllers/MethodsApi.java index f8995bf7ba319c2b38e1d84ee79cd1ff04db84c6..bbae570a584151e1c2cfbfe16df074bac6a30342 100644 --- a/src/main/java/eu/hbp/mip/controllers/MethodsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/MethodsApi.java @@ -64,10 +64,7 @@ public class MethodsApi { final GalaxyInstance instance = GalaxyInstanceFactory.get(galaxyUrl, galaxyApiKey); final WorkflowsClient workflowsClient = instance.getWorkflowsClient(); - List<Workflow> workflowList = new ArrayList<>(); - for(Workflow workflow : workflowsClient.getWorkflows()) { - workflowList.add(workflow); - } + List<Workflow> workflowList = new ArrayList<>(workflowsClient.getWorkflows()); List<WorkflowDetails> workflowDetailsList = new ArrayList<>(); for(Workflow workflow : workflowList){ diff --git a/src/main/java/eu/hbp/mip/dto/JwtResponse.java b/src/main/java/eu/hbp/mip/dto/JwtResponse.java deleted file mode 100644 index 2007a8f60bd08331860138bbe178b6b5a4cc7a4b..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/dto/JwtResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Developed by Kechagias Konstantinos. - * Copyright (c) 2019. MIT License - */ - -package eu.hbp.mip.dto; - -public class JwtResponse { - private String token; - private String type = "Bearer"; - - public JwtResponse(String accessToken) { - this.token = accessToken; - } - - public String getAccessToken() { - return token; - } - - public void setAccessToken(String accessToken) { - this.token = accessToken; - } - - public String getTokenType() { - return type; - } - - public void setTokenType(String tokenType) { - this.type = tokenType; - } -} \ No newline at end of file diff --git a/src/main/java/eu/hbp/mip/dto/LoginDto.java b/src/main/java/eu/hbp/mip/dto/LoginDto.java deleted file mode 100644 index 5fada1e1f0118bd940e8f58d286dd74cdf3b3762..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/dto/LoginDto.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Developed by Kechagias Konstantinos. - * Copyright (c) 2019. MIT License - */ - -package eu.hbp.mip.dto; - -import org.hibernate.validator.constraints.NotBlank; - -import javax.validation.constraints.Size; - -public class LoginDto { - @NotBlank - @Size(min=3, max = 60) - private String username; - - @NotBlank - @Size(min = 6, max = 40) - private String password; - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } -} diff --git a/src/main/java/eu/hbp/mip/dto/SignUpDto.java b/src/main/java/eu/hbp/mip/dto/SignUpDto.java deleted file mode 100644 index c7129853cea70e5fd8cec23b6c8a77b2438c43c8..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/dto/SignUpDto.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Developed by Kechagias Konstantinos. - * Copyright (c) 2019. MIT License - */ - -package eu.hbp.mip.dto; - -import org.hibernate.validator.constraints.Email; -import org.hibernate.validator.constraints.NotBlank; - -import javax.validation.constraints.Size; -import java.util.Set; - -public class SignUpDto { - @NotBlank - @Size(min = 3, max = 50) - private String name; - - @NotBlank - @Size(min = 3, max = 50) - private String username; - - @NotBlank - @Size(max = 60) - @Email - private String email; - - private Set<String> role; - - @NotBlank - @Size(min = 6, max = 40) - private String password; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public Set<String> getRole() { - return this.role; - } - - public void setRole(Set<String> role) { - this.role = role; - } -} diff --git a/src/main/java/eu/hbp/mip/dto/StringDtoResponse.java b/src/main/java/eu/hbp/mip/dto/StringDtoResponse.java deleted file mode 100644 index ce5eb9700eccf31807d9a5884e1b9d39d8578602..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/dto/StringDtoResponse.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Developed by Kechagias Konstantinos. - * Copyright (c) 2019. MIT License - */ - -package eu.hbp.mip.dto; - -public class StringDtoResponse { - - private String response; - - public StringDtoResponse() { - } - - public StringDtoResponse(String response) { - this.response = response; - } - - public String getResponse() { - return response; - } - - public void setResponse(String response) { - this.response = response; - } -}