Skip to content

Commit 13bae72

Browse files
committed
Remove directory viewing functionality
1 parent 8e12c2f commit 13bae72

File tree

4 files changed

+2
-224
lines changed

4 files changed

+2
-224
lines changed

src/main/java/org/commonwl/view/workflow/WorkflowService.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.commonwl.view.graphviz.GraphVizService;
2929
import org.commonwl.view.researchobject.ROBundleFactory;
3030
import org.commonwl.view.researchobject.ROBundleNotFoundException;
31-
import org.eclipse.egit.github.core.RepositoryContents;
3231
import org.eclipse.jgit.api.Git;
3332
import org.eclipse.jgit.api.errors.GitAPIException;
3433
import org.eclipse.jgit.api.errors.RefNotFoundException;
@@ -43,10 +42,8 @@
4342
import java.io.File;
4443
import java.io.IOException;
4544
import java.nio.file.Path;
46-
import java.util.ArrayList;
4745
import java.util.Calendar;
4846
import java.util.Date;
49-
import java.util.List;
5047

5148
@Service
5249
public class WorkflowService {
@@ -118,30 +115,6 @@ public QueuedWorkflow getQueuedWorkflow(String id) {
118115
return queuedWorkflowRepository.findOne(id);
119116
}
120117

121-
/**
122-
* Get a list of workflows from a directory in Github
123-
* @param githubInfo Github information for the workflow
124-
* @return The list of workflow names
125-
*/
126-
public List<WorkflowOverview> getWorkflowsFromDirectory(GitDetails githubInfo) throws IOException {
127-
List<WorkflowOverview> workflowsInDir = new ArrayList<>();
128-
for (RepositoryContents content : githubService.getContents(githubInfo)) {
129-
int eIndex = content.getName().lastIndexOf('.') + 1;
130-
if (eIndex > 0) {
131-
String extension = content.getName().substring(eIndex);
132-
if (extension.equals("cwl")) {
133-
GitDetails githubFile = new GitDetails(githubInfo.getRepoUrl(),
134-
githubInfo.getBranch(), content.getPath(), githubInfo.getType());
135-
WorkflowOverview overview = cwlService.getWorkflowOverview(githubFile);
136-
if (overview != null) {
137-
workflowsInDir.add(overview);
138-
}
139-
}
140-
}
141-
}
142-
return workflowsInDir;
143-
}
144-
145118
/**
146119
* Get a queued workflow from the database
147120
* @param githubInfo Github information for the workflow
@@ -241,9 +214,10 @@ public File getROBundle(GitDetails gitDetails) throws ROBundleNotFoundException
241214
* @return A queued workflow model
242215
* @throws GitAPIException Git errors
243216
* @throws CWLValidationException cwltool errors
217+
* @throws IOException Other file handling exceptions
244218
*/
245219
public QueuedWorkflow createQueuedWorkflow(GitDetails gitInfo)
246-
throws GitAPIException, CWLValidationException {
220+
throws GitAPIException, CWLValidationException, IOException {
247221

248222
QueuedWorkflow queuedWorkflow = new QueuedWorkflow();
249223

src/main/resources/templates/selectworkflow.html

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/test/java/org/commonwl/view/workflow/WorkflowControllerTest.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
3737
import org.springframework.web.servlet.view.InternalResourceViewResolver;
3838

39-
import java.io.IOException;
40-
import java.util.ArrayList;
41-
import java.util.Arrays;
42-
43-
import static org.hamcrest.Matchers.*;
4439
import static org.hamcrest.core.Is.is;
4540
import static org.mockito.Matchers.anyObject;
4641
import static org.mockito.Matchers.anyString;
@@ -203,73 +198,6 @@ public void directWorkflowURL() throws Exception {
203198

204199
}
205200

206-
/**
207-
* Displaying directories of workflows
208-
*/
209-
@Test
210-
public void directDirectoryURL() throws Exception {
211-
212-
// Workflow overviews for testing
213-
WorkflowOverview overview1 = new WorkflowOverview("workflow1.cwl", "label1", "doc1");
214-
WorkflowOverview overview2 = new WorkflowOverview("workflow2.cwl", "label2", "doc2");
215-
216-
// Mock service to return these overviews
217-
WorkflowService mockWorkflowService = Mockito.mock(WorkflowService.class);
218-
when(mockWorkflowService.getWorkflowsFromDirectory(anyObject()))
219-
.thenReturn(new ArrayList<>())
220-
.thenReturn(new ArrayList<>(Arrays.asList(overview1)))
221-
.thenReturn(new ArrayList<>(Arrays.asList(overview1, overview2)))
222-
.thenReturn(new ArrayList<>(Arrays.asList(overview1, overview2)))
223-
.thenThrow(new IOException("Error getting contents"));
224-
225-
// Mock controller/MVC
226-
WorkflowController workflowController = new WorkflowController(
227-
Mockito.mock(WorkflowFormValidator.class),
228-
mockWorkflowService,
229-
Mockito.mock(GraphVizService.class));
230-
MockMvc mockMvc = MockMvcBuilders
231-
.standaloneSetup(workflowController)
232-
.build();
233-
234-
// No workflows in directory, redirect with errors
235-
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within"))
236-
.andExpect(status().isFound())
237-
.andExpect(flash().attributeExists("errors"))
238-
.andExpect(redirectedUrl("/?url=https://github.com/owner/reponame/tree/branch/path/within"));
239-
240-
// 1 workflow in directory, redirect to it
241-
mockMvc.perform(get("/workflows/github.com/common-workflow-language/workflows/tree/master/workflows/lobSTR"))
242-
.andExpect(status().isFound())
243-
.andExpect(redirectedUrl("/workflows/github.com/common-workflow-language/workflows/tree/master/workflows/lobSTR/workflow1.cwl"));
244-
245-
// Multiple workflows in directory, show list
246-
mockMvc.perform(get("/workflows/github.com/common-workflow-language/workflows/tree/visu/workflows/scidap"))
247-
.andExpect(status().isOk())
248-
.andExpect(view().name("selectworkflow"))
249-
.andExpect(model().attribute("githubDetails", allOf(
250-
hasProperty("owner", is("common-workflow-language")),
251-
hasProperty("repoName", is("workflows")),
252-
hasProperty("branch", is("visu")),
253-
hasProperty("path", is("workflows/scidap"))
254-
)))
255-
.andExpect(model().attribute("workflowOverviews",
256-
containsInAnyOrder(overview1, overview2)));
257-
258-
// Workflows at the base of a repository
259-
mockMvc.perform(get("/workflows/github.com/genome/arvados_trial/tree/master"))
260-
.andExpect(status().isOk())
261-
.andExpect(view().name("selectworkflow"))
262-
.andExpect(model().attribute("githubDetails",
263-
hasProperty("path", is("/"))));
264-
265-
// Error getting contents of Github directory, redirect with errors
266-
mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within"))
267-
.andExpect(status().isFound())
268-
.andExpect(flash().attributeExists("errors"))
269-
.andExpect(redirectedUrl("/?url=https://github.com/owner/reponame/tree/branch/path/within"));
270-
271-
}
272-
273201
/**
274202
* Endpoint for downloading RO bundle for a workflow
275203
*/

src/test/java/org/commonwl/view/workflow/WorkflowServiceTest.java

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,16 @@
2525
import org.commonwl.view.github.GitService;
2626
import org.commonwl.view.graphviz.GraphVizService;
2727
import org.commonwl.view.researchobject.ROBundleFactory;
28-
import org.eclipse.egit.github.core.RepositoryContents;
2928
import org.junit.Rule;
3029
import org.junit.Test;
3130
import org.junit.rules.TemporaryFolder;
3231
import org.mockito.Mockito;
33-
import org.mockito.invocation.InvocationOnMock;
34-
import org.mockito.stubbing.Answer;
3532

3633
import java.io.File;
37-
import java.util.ArrayList;
3834
import java.util.Date;
3935
import java.util.HashMap;
40-
import java.util.List;
4136

4237
import static org.junit.Assert.assertEquals;
43-
import static org.junit.Assert.assertTrue;
4438
import static org.mockito.Matchers.anyObject;
4539
import static org.mockito.Matchers.anyString;
4640
import static org.mockito.Mockito.when;
@@ -53,69 +47,6 @@ public class WorkflowServiceTest {
5347
@Rule
5448
public TemporaryFolder roBundleFolder = new TemporaryFolder();
5549

56-
/**
57-
* Getting a list of workflow overviews from a directory
58-
*/
59-
@Test
60-
public void getWorkflowsFromDirectory() throws Exception {
61-
62-
// Mock Github service redirecting content query to the filesystem
63-
GitService mockGithubService = Mockito.mock(GitService.class);
64-
Answer contentsAnswer = new Answer<List<RepositoryContents>>() {
65-
@Override
66-
public List<RepositoryContents> answer(InvocationOnMock invocation) throws Throwable {
67-
List<RepositoryContents> returnList = new ArrayList<>();
68-
69-
// Add all files from lobstr-v1 directory
70-
File[] fileList = new File("src/test/resources/cwl/lobstr-v1/").listFiles();
71-
for (File thisFile : fileList) {
72-
RepositoryContents contentsEntry = new RepositoryContents();
73-
if (thisFile.isFile()) {
74-
contentsEntry.setType(GitService.TYPE_FILE);
75-
contentsEntry.setSize(100);
76-
contentsEntry.setName(thisFile.getName());
77-
contentsEntry.setPath("workflows/lobSTR/" + thisFile.getName());
78-
returnList.add(contentsEntry);
79-
}
80-
}
81-
82-
return returnList;
83-
}
84-
};
85-
when(mockGithubService.getContents(anyObject())).thenAnswer(contentsAnswer);
86-
87-
// Mock CWL service which returns simple overview once simulating 1 workflow found
88-
CWLService mockCWLService = Mockito.mock(CWLService.class);
89-
when(mockCWLService.getWorkflowOverview(anyObject()))
90-
.thenReturn(new WorkflowOverview("workflow.cwl", "label", "doc"))
91-
.thenReturn(new WorkflowOverview("workflow2.cwl", "label2", "doc2"))
92-
.thenReturn(null);
93-
94-
// Create service under test
95-
WorkflowService testWorkflowService = new WorkflowService(
96-
mockGithubService, mockCWLService,
97-
Mockito.mock(WorkflowRepository.class),
98-
Mockito.mock(QueuedWorkflowRepository.class),
99-
Mockito.mock(ROBundleFactory.class),
100-
Mockito.mock(GraphVizService.class),
101-
Mockito.mock(CWLToolRunner.class), 1);
102-
103-
// Get a list of workflows from the directory
104-
List<WorkflowOverview> list = testWorkflowService.getWorkflowsFromDirectory(
105-
Mockito.mock(GitDetails.class));
106-
107-
// 1 workflow should be found
108-
assertTrue(list.size() == 2);
109-
assertEquals("workflow.cwl", list.get(0).getFileName());
110-
assertEquals("label", list.get(0).getLabel());
111-
assertEquals("doc", list.get(0).getDoc());
112-
113-
assertEquals("workflow2.cwl", list.get(1).getFileName());
114-
assertEquals("label2", list.get(1).getLabel());
115-
assertEquals("doc2", list.get(1).getDoc());
116-
117-
}
118-
11950
/**
12051
* Getting a workflow when cache has expired
12152
* And a new workflow needs to be created

0 commit comments

Comments
 (0)