@@ -17,16 +17,16 @@ import { ConfigurationService } from '../../configuration/configuration.service'
17
17
import { ApplicationManagementService } from '../../core/service/application-management.service' ;
18
18
import { NgRedux } from '@angular-redux/store' ;
19
19
import { Router } from '@angular/router' ;
20
- import { LoggerService } from '../../core/service/logger.service' ;
21
20
import { AppState } from '../../store/app-state.model' ;
22
21
import { DeploymentCompletionService } from '../../core/service/deployment-completion.service' ;
23
22
import { RepositoryService } from '../../core/service/repository.service' ;
24
23
import { Path } from '../../core/path' ;
25
24
import { GrowlActions } from '../../core/growl/growl-actions' ;
26
25
import { CsarUploadReference } from '../../core/model/csar-upload-request.model' ;
27
- import { HttpClient , HttpResponse } from '@angular/common/http' ;
26
+ import { HttpClient , HttpHeaders , HttpResponse } from '@angular/common/http' ;
28
27
import { Observable , of } from 'rxjs' ;
29
28
import { MarketplaceApplication } from '../../core/model/marketplace-application.model' ;
29
+ import { LoggerService } from '../../core/service/logger.service' ;
30
30
31
31
@Component ( {
32
32
selector : 'opentosca-application-upload' ,
@@ -41,20 +41,20 @@ export class ApplicationUploadComponent implements OnInit {
41
41
@Output ( ) completionRequest = new EventEmitter ( ) ;
42
42
public deploymentInProgress = false ;
43
43
public fileSelected = false ;
44
- public showUploadProgressLabel = false ;
45
44
public postURL = new Path ( this . adminService . getContainerUrl ( ) )
46
45
. append ( 'csars' )
47
46
. toString ( ) ;
48
- public bytesUploaded = 0 ;
49
- public bytesTotal = 0 ;
47
+
48
+ public applyEnrichment = false ;
49
+
50
50
public linkToWineryResourceForCompletion : string ;
51
51
public appToComplete : MarketplaceApplication ;
52
52
public showCompletionDialog = false ;
53
53
public initializeCompletionComponent = false ;
54
54
55
55
// temporary data derived from the user input for the url upload
56
56
public tempData = {
57
- cur : new CsarUploadReference ( null , null ) ,
57
+ cur : new CsarUploadReference ( null , null , null ) ,
58
58
validURL : false ,
59
59
validName : false
60
60
} ;
@@ -97,22 +97,36 @@ export class ApplicationUploadComponent implements OnInit {
97
97
onClear ( ) : void {
98
98
this . fileSelected = false ;
99
99
this . deploymentInProgress = false ;
100
+ this . applyEnrichment = false ;
100
101
}
101
102
102
103
/**
103
- * Handler for upload progress of file upload component.
104
+ * Handler for file upload.
105
+ * @param event: upload event triggered when upload button is clicked
104
106
*/
105
- onUploadProgress ( event : ProgressEvent ) : void {
106
- this . bytesUploaded = event . loaded ;
107
- this . bytesTotal = event . total ;
108
- this . deploymentInProgress = this . bytesUploaded === this . bytesTotal ;
107
+ handleUpload ( event : any , form : any ) : void {
108
+ this . deploymentInProgress = true ;
109
+ const fileToUpload = event . files [ 0 ] ;
110
+ const formData : FormData = new FormData ( ) ;
111
+ formData . append ( 'enrichment' , JSON . stringify ( this . applyEnrichment ) ) ;
112
+ formData . append ( 'file' , fileToUpload , fileToUpload . name ) ;
113
+ const headers = new HttpHeaders ( ) ;
114
+ this . handleCSARUpload ( formData , headers ) . subscribe (
115
+ data => this . onUploadFinished ( data ) ,
116
+ error => this . onUploadError ( event , error , form )
117
+ ) ;
118
+ }
119
+
120
+ handleCSARUpload ( formData , headers ) : Observable < Object > {
121
+ return this . http . post ( this . postURL , formData , { headers : headers } ) ;
109
122
}
110
123
111
124
/**
112
125
* Handler for upload finished event of file upload component.
113
126
* This handler is called when the XHR request returns, i.e., when deployment in container is done.
114
127
*/
115
128
onUploadFinished ( event ) : void {
129
+ this . deploymentInProgress = false ;
116
130
// This is called when XHR request returns
117
131
this . ngRedux . dispatch ( GrowlActions . addGrowl (
118
132
{
@@ -129,14 +143,16 @@ export class ApplicationUploadComponent implements OnInit {
129
143
* Handler for emitted errors of file upload component.
130
144
* If topology completion is required this is caught within this handler.
131
145
*/
132
- onUploadError ( event ) : void {
133
- switch ( event . error . status ) {
146
+ onUploadError ( event , error , form ) : void {
147
+ form . clear ( ) ;
148
+ this . resetUploadStats ( ) ;
149
+ const fileExtension = '.csar' ;
150
+ switch ( error . status ) {
134
151
case 406 :
135
- const response = event . error . error ;
136
- this . linkToWineryResourceForCompletion = response [ 'Location' ] ;
152
+ this . linkToWineryResourceForCompletion = error . error . Location ;
137
153
const fileName = event . files [ 0 ] . name ;
138
- const csarName = fileName . substr ( 0 , fileName . length - 5 ) ;
139
- const csarID = fileName . lastIndexOf ( '.csar' ) ;
154
+ const csarName = fileName . substr ( 0 , fileName . length - fileExtension . length ) ;
155
+ const csarID = fileName . lastIndexOf ( fileExtension ) ;
140
156
this . deploymentService . getAppFromCompletionHandlerWinery ( this . linkToWineryResourceForCompletion , csarID ,
141
157
csarName ) . then ( app => {
142
158
this . appToComplete = app ;
@@ -175,6 +191,7 @@ export class ApplicationUploadComponent implements OnInit {
175
191
const postURL = new Path ( this . adminService . getContainerUrl ( ) )
176
192
. append ( 'csars' )
177
193
. toString ( ) ;
194
+
178
195
this . repositoryManagementService . installApplication ( this . tempData . cur , postURL )
179
196
. toPromise ( )
180
197
. then ( ( ) => {
@@ -212,6 +229,7 @@ export class ApplicationUploadComponent implements OnInit {
212
229
*/
213
230
resetUploadStats ( ) : void {
214
231
this . deploymentInProgress = false ;
232
+ this . applyEnrichment = false ;
215
233
this . tempData . cur . url = null ;
216
234
this . tempData . cur . name = null ;
217
235
this . tempData . validURL = false ;
@@ -226,6 +244,10 @@ export class ApplicationUploadComponent implements OnInit {
226
244
this . tempData . cur . name = name ;
227
245
}
228
246
247
+ applyEnrichmentChange ( ) : void {
248
+ this . tempData . cur . enrich = JSON . stringify ( this . applyEnrichment ) ;
249
+ }
250
+
229
251
urlValidityChange ( validity : boolean ) : void {
230
252
this . tempData . validURL = validity ;
231
253
}
@@ -275,11 +297,10 @@ export class ApplicationUploadComponent implements OnInit {
275
297
detail : `The completion process was successful, app "${ app . displayName } " is now getting installed in container.`
276
298
}
277
299
) ) ;
278
- // Todo: Container should check itself if the app already exists and respond appropriately
279
300
const postURL = new Path ( this . adminService . getContainerUrl ( ) )
280
301
. append ( 'csars' )
281
302
. toString ( ) ;
282
- const completedApp = new CsarUploadReference ( app . csarURL , app . csarName ) ;
303
+ const completedApp = new CsarUploadReference ( app . csarURL , app . csarName , JSON . stringify ( this . applyEnrichment ) ) ;
283
304
this . repoService . installApplication ( completedApp , postURL )
284
305
. subscribe ( ( ) => {
285
306
this . ngRedux . dispatch ( GrowlActions . addGrowl (
0 commit comments