Skip to content

Commit 892182f

Browse files
author
Mark Robinson
committed
Simple logging functionality
1 parent b4a8b52 commit 892182f

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

src/main/java/org/commonwl/viewer/domain/ROBundle.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.commonwl.viewer.services.GitHubService;
2727
import org.eclipse.egit.github.core.RepositoryContents;
2828
import org.eclipse.egit.github.core.User;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
2931

3032
import java.io.IOException;
3133
import java.net.URI;
@@ -40,6 +42,8 @@
4042
*/
4143
public class ROBundle {
4244

45+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
46+
4347
private GitHubService githubService;
4448

4549
private Bundle bundle;
@@ -87,7 +91,7 @@ public ROBundle(GitHubService githubService, GithubDetails githubInfo,
8791
manifest.setAuthoredBy(authorList);
8892

8993
} catch (URISyntaxException ex) {
90-
System.out.println("Incorrect URI Syntax");
94+
logger.error(ex.getMessage());
9195
}
9296

9397
// Make a directory in the RO bundle to store the files

src/main/java/org/commonwl/viewer/services/ROBundleFactory.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import org.commonwl.viewer.domain.GithubDetails;
2323
import org.commonwl.viewer.domain.ROBundle;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
2426
import org.springframework.beans.factory.annotation.Value;
2527
import org.springframework.scheduling.annotation.Async;
2628
import org.springframework.scheduling.annotation.EnableAsync;
@@ -38,6 +40,8 @@
3840
@EnableAsync
3941
public class ROBundleFactory {
4042

43+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
44+
4145
@Value("${applicationName}")
4246
private String applicationName;
4347
@Value("${applicationURL}")
@@ -53,8 +57,10 @@ public class ROBundleFactory {
5357
@Async
5458
void workflowROFromGithub(GitHubService githubService, GithubDetails githubInfo) throws IOException {
5559
// TODO: Add the bundle link to the page when it is finished being created
60+
logger.info("Creating Research Object Bundle");
5661
ROBundle bundle = new ROBundle(githubService, githubInfo,
5762
applicationName, applicationURL);
5863
bundle.saveToTempFile();
64+
logger.info("Successfully saved Research Object Bundle");
5965
}
60-
}
66+
}

src/main/java/org/commonwl/viewer/services/WorkflowFactory.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.commonwl.viewer.domain.CWLCollection;
2323
import org.commonwl.viewer.domain.GithubDetails;
2424
import org.commonwl.viewer.domain.Workflow;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2527
import org.springframework.beans.factory.annotation.Autowired;
2628
import org.springframework.stereotype.Service;
2729

@@ -31,6 +33,8 @@
3133
@Service
3234
public class WorkflowFactory {
3335

36+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
37+
3438
private final GitHubService githubService;
3539
private final ROBundleFactory ROBundleFactory;
3640
private final WorkflowRepository workflowRepository;
@@ -60,10 +64,6 @@ public Workflow workflowFromGithub(String githubURL) {
6064
// Set up CWL utility to collect the documents
6165
CWLCollection cwlFiles = new CWLCollection(githubService, githubInfo);
6266

63-
// Create a new research object bundle from Github details
64-
// This is Async so cannot just call constructor, needs intermediate as per Spring framework
65-
ROBundleFactory.workflowROFromGithub(githubService, githubInfo);
66-
6767
// Get the workflow model
6868
Workflow workflowModel = cwlFiles.getWorkflow();
6969
if (workflowModel != null) {
@@ -72,19 +72,25 @@ public Workflow workflowFromGithub(String githubURL) {
7272
workflowModel.setRetrievedFrom(githubInfo);
7373

7474
// Save to the MongoDB database
75+
logger.info("Storing workflow in DB");
7576
workflowRepository.save(workflowModel);
7677

78+
// Create a new research object bundle from Github details
79+
// This is Async so cannot just call constructor, needs intermediate as per Spring framework
80+
ROBundleFactory.workflowROFromGithub(githubService, githubInfo);
81+
7782
// Return this model to be displayed
7883
return workflowModel;
7984

8085
} else {
81-
System.out.println("Error: no workflow could be found");
86+
logger.error("No workflow could be found");
8287
}
8388
} catch (IOException ex) {
84-
System.out.println("Error: " + ex.getMessage());
89+
logger.error(ex.getMessage());
8590
}
8691
} else {
87-
System.out.println("Error should never happen, already passed validation");
92+
// TODO: Refactor validator so this redundant step can be removed?
93+
logger.error("Error should never happen, already passed URL validation");
8894
}
8995

9096
return null;

src/main/java/org/commonwl/viewer/services/WorkflowFormValidator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.commonwl.viewer.domain.GithubDetails;
2323
import org.eclipse.egit.github.core.RepositoryContents;
2424
import org.commonwl.viewer.domain.WorkflowForm;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2527
import org.springframework.beans.factory.annotation.Autowired;
2628
import org.springframework.stereotype.Component;
2729
import org.springframework.validation.Errors;
@@ -37,6 +39,8 @@
3739
@Component
3840
public class WorkflowFormValidator implements Validator {
3941

42+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
43+
4044
/**
4145
* Github API service
4246
*/
@@ -89,16 +93,21 @@ public void validate(Object obj, Errors e) {
8993
}
9094
if (!foundCWL) {
9195
// The URL does not contain any .cwl files
96+
logger.error("No .cwl files found at Github URL");
9297
e.rejectValue("githubURL", "githubURL.missingWorkflow");
9398
}
9499
} catch (IOException ex) {
95100
// Given repository/branch/path does not exist or API error occured
101+
logger.error(ex.getMessage());
96102
e.rejectValue("githubURL", "githubURL.apiError");
97103
}
98104
} else {
99105
// The Github URL is not valid
106+
logger.error("The Github URL is not valid");
100107
e.rejectValue("githubURL", "githubURL.invalid");
101108
}
109+
} else {
110+
logger.error("Github URL is empty");
102111
}
103112
}
104113
}

src/main/java/org/commonwl/viewer/web/WorkflowController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,23 @@
2323
import org.commonwl.viewer.domain.WorkflowForm;
2424
import org.commonwl.viewer.services.WorkflowFactory;
2525
import org.commonwl.viewer.services.WorkflowFormValidator;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2628
import org.springframework.beans.factory.annotation.Autowired;
2729
import org.springframework.stereotype.Controller;
2830
import org.springframework.validation.BindingResult;
31+
import org.springframework.validation.ObjectError;
2932
import org.springframework.web.bind.annotation.PostMapping;
3033
import org.springframework.web.servlet.ModelAndView;
3134

3235
import javax.validation.Valid;
36+
import java.util.List;
3337

3438
@Controller
3539
public class WorkflowController {
3640

41+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
42+
3743
private final WorkflowFormValidator workflowFormValidator;
3844
private final WorkflowFactory workflowFactory;
3945

@@ -56,6 +62,8 @@ public WorkflowController(WorkflowFormValidator workflowFormValidator, WorkflowF
5662
*/
5763
@PostMapping("/")
5864
public ModelAndView newWorkflowFromGithubURL(@Valid WorkflowForm workflowForm, BindingResult bindingResult) {
65+
logger.info("Processing new workflow from Github: \"" + workflowForm.getGithubURL() + "\"");
66+
5967
// Run validator which checks the github URL is valid
6068
workflowFormValidator.validate(workflowForm, bindingResult);
6169

0 commit comments

Comments
 (0)