|
@@ -2,25 +2,34 @@ package com.armstrongconsulting.acprotasks;
|
2
|
2
|
|
3
|
3
|
import org.jetbrains.annotations.NotNull;
|
4
|
4
|
import org.jetbrains.annotations.Nullable;
|
|
5
|
+import org.slf4j.Logger;
|
|
6
|
+import org.slf4j.LoggerFactory;
|
5
|
7
|
|
|
8
|
+import com.armstrongconsulting.acprotasks.client.AcproConnector;
|
6
|
9
|
import com.intellij.openapi.progress.ProgressIndicator;
|
7
|
10
|
import com.intellij.tasks.Task;
|
8
|
11
|
import com.intellij.tasks.TaskRepositoryType;
|
9
|
12
|
import com.intellij.tasks.impl.BaseRepository;
|
10
|
13
|
import com.intellij.util.xmlb.annotations.Tag;
|
11
|
14
|
|
|
15
|
+import feign.FeignException;
|
|
16
|
+
|
12
|
17
|
@Tag(AcproRepositoryType.NAME)
|
13
|
18
|
public class AcproRepository extends BaseRepository
|
14
|
19
|
{
|
|
20
|
+ private final Logger logger = LoggerFactory.getLogger(AcproRepository.class);
|
|
21
|
+
|
|
22
|
+ private String apiKey = null;
|
15
|
23
|
|
16
|
24
|
public AcproRepository(TaskRepositoryType type)
|
17
|
25
|
{
|
18
|
26
|
super(type);
|
19
|
27
|
}
|
20
|
28
|
|
21
|
|
- public AcproRepository(BaseRepository other)
|
|
29
|
+ public AcproRepository(AcproRepository other)
|
22
|
30
|
{
|
23
|
31
|
super(other);
|
|
32
|
+ this.apiKey = other.apiKey;
|
24
|
33
|
}
|
25
|
34
|
|
26
|
35
|
public AcproRepository()
|
|
@@ -30,7 +39,7 @@ public class AcproRepository extends BaseRepository
|
30
|
39
|
@Override
|
31
|
40
|
public @Nullable Task findTask(@NotNull String id) throws Exception
|
32
|
41
|
{
|
33
|
|
- return new AcproTask();
|
|
42
|
+ return null;
|
34
|
43
|
}
|
35
|
44
|
|
36
|
45
|
@Override
|
|
@@ -40,18 +49,55 @@ public class AcproRepository extends BaseRepository
|
40
|
49
|
}
|
41
|
50
|
|
42
|
51
|
@Override
|
43
|
|
- public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed)
|
44
|
|
- throws Exception
|
|
52
|
+ public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed,
|
|
53
|
+ @NotNull ProgressIndicator cancelled) throws Exception
|
45
|
54
|
{
|
46
|
|
- System.out.println("Searching for issues (1): " + query);
|
47
|
|
- return new Task[]{new AcproTask()};
|
|
55
|
+ if (apiKey == null)
|
|
56
|
+ {
|
|
57
|
+ apiKey = AcproConnector.getClient(getUrl()).getApiKey(getUsername(), getPassword(), 28800);
|
|
58
|
+ }
|
|
59
|
+ return AcproConnector.getClient(getUrl()).getItems(query, offset, limit, apiKey).stream().peek(a -> logger.warn(a.toString())).map(AcproTask::new)
|
|
60
|
+ .toArray(AcproTask[]::new);
|
48
|
61
|
}
|
49
|
62
|
|
50
|
63
|
@Override
|
51
|
|
- public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed,
|
52
|
|
- @NotNull ProgressIndicator cancelled) throws Exception
|
|
64
|
+ public @Nullable CancellableConnection createCancellableConnection()
|
|
65
|
+ {
|
|
66
|
+ return new CancellableConnection()
|
|
67
|
+ {
|
|
68
|
+ @Override
|
|
69
|
+ protected void doTest() throws Exception
|
|
70
|
+ {
|
|
71
|
+ try
|
|
72
|
+ {
|
|
73
|
+ if (apiKey != null)
|
|
74
|
+ {
|
|
75
|
+ return;
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ apiKey = AcproConnector.getClient(getUrl()).getApiKey(getUsername(), getPassword(), 28800);
|
|
79
|
+ }
|
|
80
|
+ catch (FeignException.Unauthorized e)
|
|
81
|
+ {
|
|
82
|
+ throw new RuntimeException("Wrong username or password");
|
|
83
|
+ }
|
|
84
|
+ catch (FeignException.FeignClientException e)
|
|
85
|
+ {
|
|
86
|
+ throw new RuntimeException("Connection failed");
|
|
87
|
+ }
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ @Override
|
|
91
|
+ public void cancel()
|
|
92
|
+ {
|
|
93
|
+ // not cancellable
|
|
94
|
+ }
|
|
95
|
+ };
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ @Override
|
|
99
|
+ public void initializeRepository()
|
53
|
100
|
{
|
54
|
|
- System.out.println("Searching for issues (2): " + query);
|
55
|
|
- return new Task[]{new AcproTask()};
|
|
101
|
+ logger.info("Initialize repository");
|
56
|
102
|
}
|
57
|
103
|
}
|