Merge "InvalidRoleException-junits"
[portal.git] / portal-FE-common / src / app / pages / account-onboarding / account-add-details / account-add-details.component.ts
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38
39 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
40 import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
41 import { BasicAuthAccountService } from 'src/app/shared/services';
42 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
43
44 @Component({
45   selector: 'app-account-add-details',
46   templateUrl: './account-add-details.component.html',
47   styleUrls: ['./account-add-details.component.scss']
48 })
49 export class AccountAddDetailsComponent implements OnInit {
50
51   result: any;
52   isEditMode: boolean = false;
53   dupliateName: boolean = false;
54   emptyAccountName: boolean = false;
55   emptyAccountUsername: boolean = false;
56   passwordMatched: boolean = false;
57
58   @Input() accountOnboarding: any;
59   @Output() passEntry: EventEmitter<any> = new EventEmitter();
60
61   constructor(public basicAuthAccountService: BasicAuthAccountService, public activeModal: NgbActiveModal, public ngbModal: NgbModal) { }
62
63   ngOnInit() {
64     this.passwordMatched = true;
65     this.dupliateName = false;
66     this.emptyAccountName = false;
67     this.emptyAccountUsername = false;
68   
69     if(this.accountOnboarding.applicationName){
70       this.isEditMode = true;
71     }else{
72       this.isEditMode = false;
73       this.accountOnboarding.isActive = true;
74       this.accountOnboarding.endpointList = [];
75     }
76     //console.log("IsEditMode in Add account Dialog :: ",this.isEditMode)
77
78   }
79
80   addEndpoint(){
81     const modalRef = this.ngbModal.open(ConfirmationModalComponent);
82     modalRef.componentInstance.title = "";
83     modalRef.componentInstance.message = 'Please add the roles to this Username/MechId through AAF Screen';
84     modalRef.result.then((result) => { }, (resut) => {return;});
85
86     /*this.accountOnboarding.endpointList.push({
87       valid: true
88     });*/
89   }
90
91   //Add Or Update Account.
92   saveChanges(){
93     var isValid = true;
94     //console.log("saveChanges called Account Onboarding");
95
96     if(this.accountOnboarding.applicationName == ''
97       || this.accountOnboarding.applicationName == undefined){
98       this.emptyAccountName = true;
99         isValid = false;
100       }
101     
102     if(this.accountOnboarding.username == ''
103       || this.accountOnboarding.username == undefined){
104       this.emptyAccountUsername = true;
105           isValid = false;
106     }
107     
108     if(this.dupliateName == true){
109           isValid = false;
110     }
111
112     if(this.dupliateName == true){
113       isValid = false;
114     }
115  
116     if(this.accountOnboarding.password != this.accountOnboarding.repassword){
117         this.passwordMatched =  false;
118         isValid = false;
119     }
120     //console.log("isValid....",isValid)
121     if(!isValid)
122       return;
123     
124     var active = 'N';
125     if(this.accountOnboarding.isActive == true)
126       active = 'Y';
127
128     var newAccount = {
129       applicationName: this.accountOnboarding.applicationName,
130       username: this.accountOnboarding.username,
131       password: this.accountOnboarding.password,
132       endpoints: this.accountOnboarding.endpoints,
133       isActive: active
134     };
135
136     if(this.isEditMode){
137       var message = "Are you sure you want to change '" + this.accountOnboarding.applicationName + "'?"
138       this.basicAuthAccountService.updateAccount(this.accountOnboarding.id, newAccount)
139         .subscribe( _data => {
140           this.result = _data;
141           //console.log("updateAccount response :: ",this.result);
142           this.passEntry.emit(this.result);
143           this.ngbModal.dismissAll();
144         }, error => {
145           console.log(error);
146       });
147     }else{
148       this.basicAuthAccountService.createAccount(newAccount)
149         .subscribe( _data => {
150           this.result = _data;
151           //console.log("createAccount response :: ",this.result);
152           this.passEntry.emit(this.result);
153           this.ngbModal.dismissAll();
154         }, error => {
155           console.log(error);
156       });
157     }
158   }
159 }