14
14
15
15
import * as fs from "fs" ;
16
16
import * as vscode from "vscode" ;
17
- import { loadDepFile , DependenciesDesc } from "./DependencyService" ;
18
- import { DEPENDENCIES_FOLDER , PROCESS_DOWNLOAD_ERROR_MSG } from "../constants" ;
19
- import { CopybookFix } from "./CopybookFix" ;
17
+ import { DEPENDENCIES_FOLDER , PROCESS_DOWNLOAD_ERROR_MSG , SETTINGS_SECTION , PATHS_LOCAL_KEY } from "../constants" ;
20
18
import { CopybooksPathGenerator , createDatasetPath , createCopybookPath , checkWorkspace } from "./CopybooksPathGenerator" ;
19
+ import { Prioritizer } from "./Prioritizer" ;
20
+ import { CopybookFix } from "./CopybookFix" ;
21
21
import { CopybookProfile , DownloadQueue } from "./DownloadQueue" ;
22
+ import { loadDepFile , DependenciesDesc } from "./DependencyService" ;
22
23
import { ProfileService } from "./ProfileService" ;
23
24
import { ZoweApi } from "./ZoweApi" ;
24
25
@@ -29,7 +30,8 @@ export class CopybooksDownloader implements vscode.Disposable {
29
30
private resolver : CopybookFix ,
30
31
private zoweApi : ZoweApi ,
31
32
private profileService : ProfileService ,
32
- private pathGenerator : CopybooksPathGenerator ) { }
33
+ private pathGenerator : CopybooksPathGenerator ,
34
+ private prioritizer : Prioritizer ) { }
33
35
34
36
public async redownloadDependencies ( message : string = "Redownload dependencies requested." ) {
35
37
( await vscode . workspace . findFiles ( DEPENDENCIES_FOLDER + "/**/*.dep" ) ) . forEach ( dep => {
@@ -39,9 +41,9 @@ export class CopybooksDownloader implements vscode.Disposable {
39
41
40
42
/**
41
43
* @param copybooks array of copybooks names to download
44
+ * @param programName analyzed COBOL file
42
45
*/
43
46
async downloadCopybooks ( copybooks : string [ ] , programName : string ) : Promise < void > {
44
- // TODO do it right
45
47
const profile : string = await this . profileService . getProfile ( programName ) ;
46
48
if ( ! profile ) {
47
49
return ;
@@ -54,22 +56,25 @@ export class CopybooksDownloader implements vscode.Disposable {
54
56
return ;
55
57
}
56
58
const depDesc : DependenciesDesc = loadDepFile ( depFileUri ) ;
59
+
60
+ // TODO: REMOVE PROFILE OR ADD IT AFTER LOCAL CHECK
57
61
const profile : string = await this . profileService . getProfile ( depDesc . programName ) ;
58
62
if ( ! profile ) {
59
63
return ;
60
64
}
61
65
62
- const missingCopybooks : string [ ] = await this . listMissingCopybooks ( depDesc . copybooks , profile ) ;
66
+ this . prioritizer . checkCopybooksPresentLocal ( depDesc . copybooks ,
67
+ vscode . workspace . getConfiguration ( SETTINGS_SECTION ) . get ( PATHS_LOCAL_KEY ) ) ;
68
+ const notLocalCpy : string [ ] = this . prioritizer . getNotLocalCpy ( ) ;
69
+ const localCpyExists : boolean = this . prioritizer . getLocalCpyURI ( ) . length > 0 ;
63
70
64
- if ( ! message . length ) {
65
- missingCopybooks . forEach ( copybook => this . queue . push ( copybook , profile ) ) ;
66
- } else if ( missingCopybooks . length > 0 ) {
67
- this . resolver . fixMissingDownloads ( message , missingCopybooks , profile , {
68
- hasPaths : ( await this . pathGenerator . listDatasets ( ) ) . length > 0 ,
69
- hasProfiles : Object . keys ( await this . profileService . listProfiles ( ) ) . length > 1 ,
70
- } ) ;
71
+ // message to be displayed should be adjusted according to the requirments
72
+ if ( localCpyExists ) {
73
+ // we can use the logic from continueDownloadFromMF in order to ask user if would like to use Zowe or no - TBD
74
+ this . notifyUserIfCopyNotLocal ( "Some copybooks are not present locally" , notLocalCpy . length > 0 ) ;
75
+ } else {
76
+ this . continueDownloadFromMF ( notLocalCpy , depDesc . programName , message ) ;
71
77
}
72
-
73
78
}
74
79
75
80
public async start ( ) {
@@ -121,6 +126,50 @@ export class CopybooksDownloader implements vscode.Disposable {
121
126
this . queue . stop ( ) ;
122
127
}
123
128
129
+ /**
130
+ * This method pushes missingCopybooks into the queue to be downloaded from MF
131
+ * @param message message to be displayed
132
+ * @param missingCopybooks copybooks which are not presented locally
133
+ * @param profile Zowe connection profile
134
+ */
135
+ private async resolveMissingCopybooksFromMF ( message : string , missingCopybooks : string [ ] , profile : string ) {
136
+ if ( ! message . length ) {
137
+ missingCopybooks . forEach ( copybook => this . queue . push ( copybook , profile ) ) ;
138
+ } else if ( missingCopybooks . length > 0 ) {
139
+ this . resolver . fixMissingDownloads ( message , missingCopybooks , profile , {
140
+ hasPaths : ( await this . pathGenerator . listDatasets ( ) ) . length > 0 ,
141
+ hasProfiles : Object . keys ( await this . profileService . listProfiles ( ) ) . length > 1 ,
142
+ } ) ;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * @param title message to be displayed
148
+ * @param cpyNotLocal check if there are any copybooks unresolved locally
149
+ */
150
+ private notifyUserIfCopyNotLocal ( title : string , cpyNotLocal : boolean ) {
151
+ if ( cpyNotLocal ) { vscode . window . showErrorMessage ( title ) ; }
152
+ }
153
+
154
+ /**
155
+ * This method is implemented in order to create a smooth transition from local analyze to MF download
156
+ * @param notLocalCpy copybooks not present in local workspace
157
+ * @param programName analyzed COBOL file
158
+ * @param message message to be displayed
159
+ */
160
+ private async continueDownloadFromMF ( notLocalCpy : string [ ] , programName : string , message : string ) {
161
+ const action = await vscode . window . showErrorMessage ( "Do you wanna use Zowe?" ,
162
+ "Yes" , "Never" ) ;
163
+ if ( action === "Yes" ) {
164
+ const profile : string = await this . profileService . getProfile ( programName ) ;
165
+ if ( ! profile ) {
166
+ return ;
167
+ }
168
+ const missingCopybooks : string [ ] = await this . listMissingCopybooks ( notLocalCpy , profile ) ;
169
+ this . resolveMissingCopybooksFromMF ( message , missingCopybooks , profile ) ;
170
+ }
171
+ }
172
+
124
173
private async fetchCopybook ( dataset : string , copybookProfile : CopybookProfile ) : Promise < boolean > {
125
174
let members : string [ ] = [ ] ;
126
175
try {
0 commit comments