@@ -174,28 +174,38 @@ private static void addCitToApp(CertificateIssuingTemplate cit, Application appl
174174 application .certificateIssuingTemplateAliasIdMap ( citAliasIdMap );
175175 }
176176
177+ boolean updateApplication = false ;
178+
177179 //if the App doesn't contain the relation to the cit
178180 if ( !citAliasIdMap .containsKey (cit .name ()) ) {
179181 //adding the reference to the cit
180182 citAliasIdMap .put (cit .name (), cit .id ());
183+ updateApplication = true ;
184+ }
181185
182- //getting the appId because it will be used to invoke the API to update the related Application
183- String appId = application .id ();
186+ // Updating the owners list of the Application
187+ List <Application .OwnerIdsAndType > ownersList = CloudConnectorUtils .resolveUsersToCloudOwners (usersList , apiKey , cloud );
188+ if (ownersList .size () > 0 ){
189+ // application.ownerIdsAndTypes().addAll(ownersList);
190+ List <Application .OwnerIdsAndType > newList = mergeOwnersList (application .ownerIdsAndTypes (), ownersList );
191+ application .ownerIdsAndTypes (newList );
192+ updateApplication = true ;
193+ }
184194
185- //The id, companyId, fqDns and internalFqDns needs to be null in the request to update the Application,
186- //therefore these attributes are set to null
187- application .id (null );
188- application .companyId (null );
189- application .fqDns (null );
190- application .internalFqDns (null );
195+ if (updateApplication ) {
196+ //getting the appId because it will be used to invoke the API to update the related Application
197+ String appId = application .id ();
191198
192- // Updating the owners list
193- List <Application .OwnerIdsAndType > ownersList = CloudConnectorUtils .resolveUsersToCloudOwners (usersList , apiKey , cloud );
194- application .ownerIdsAndTypes (ownersList );
199+ //The id, companyId, fqDns and internalFqDns needs to be null in the request to update the Application,
200+ //therefore these attributes are set to null
201+ application .id (null );
202+ application .companyId (null );
203+ application .fqDns (null );
204+ application .internalFqDns (null );
195205
196- cloud .updateApplication (application , appId , apiKey );
197- }
198- }
206+ cloud .updateApplication (application , appId , apiKey );
207+ }
208+ }
199209
200210 private static List <Application .OwnerIdsAndType > resolveUsersToCloudOwners (String [] usersList , String apiKey , Cloud cloud ) {
201211 List <Application .OwnerIdsAndType > ownersList = new ArrayList <>();
@@ -289,6 +299,19 @@ private static String[] resolveCloudOwnersNames(String policyName, String apiKey
289299 return usersList .toArray (new String [0 ]);
290300 }
291301
302+ private static List <Application .OwnerIdsAndType > mergeOwnersList (List <Application .OwnerIdsAndType > sourceList , List <Application .OwnerIdsAndType > incomingList ) {
303+ sourceList .addAll (incomingList );
304+ Map <String , Application .OwnerIdsAndType > ownerMap = new HashMap <>();
305+
306+ for (Application .OwnerIdsAndType owner : sourceList ) {
307+ if (!ownerMap .containsKey (owner .ownerId ())){
308+ ownerMap .put (owner .ownerId (), owner );
309+ }
310+ }
311+
312+ return new ArrayList <>(ownerMap .values ());
313+ }
314+
292315 private static CertificateIssuingTemplate getPolicy (String policyName , String apiKey , Cloud cloud ) throws VCertException {
293316
294317 CloudZone zone = new CloudZone (policyName );
0 commit comments