|
1 | 1 | /* |
2 | | - * Copyright 2015 Systemic Pty Ltd |
| 2 | + * Copyright 2016 Systemic Pty Ltd |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -30,91 +30,137 @@ namespace Sif.Framework.Service.Infrastructure |
30 | 30 | public class EnvironmentService : SifService<environmentType, Environment>, IEnvironmentService |
31 | 31 | { |
32 | 32 |
|
| 33 | + private Zone CopyDefaultZone(Zone sourceZone) |
| 34 | + { |
| 35 | + Zone destinationZone = null; |
| 36 | + |
| 37 | + if (sourceZone != null) |
| 38 | + { |
| 39 | + destinationZone = new Zone { Description = sourceZone.Description, SifId = sourceZone.SifId }; |
| 40 | + |
| 41 | + if (sourceZone.Properties != null) |
| 42 | + { |
| 43 | + destinationZone.Properties = CopyProperties(sourceZone.Properties); |
| 44 | + } |
| 45 | + |
| 46 | + } |
| 47 | + |
| 48 | + return destinationZone; |
| 49 | + } |
| 50 | + |
33 | 51 | private IDictionary<InfrastructureServiceNames, InfrastructureService> CopyInfrastructureServices(IDictionary<InfrastructureServiceNames, InfrastructureService> sourceInfrastructureServices) |
34 | 52 | { |
35 | | - IDictionary<InfrastructureServiceNames, InfrastructureService> destinationInfrastructureServices = new Dictionary<InfrastructureServiceNames, InfrastructureService>(); |
| 53 | + IDictionary<InfrastructureServiceNames, InfrastructureService> destinationInfrastructureServices = null; |
36 | 54 |
|
37 | | - if (sourceInfrastructureServices != null && sourceInfrastructureServices.Count > 0) |
| 55 | + if (sourceInfrastructureServices != null) |
38 | 56 | { |
| 57 | + destinationInfrastructureServices = new Dictionary<InfrastructureServiceNames, InfrastructureService>(); |
39 | 58 |
|
40 | | - foreach (InfrastructureService sourceInfrastructureService in sourceInfrastructureServices.Values) |
| 59 | + foreach (InfrastructureServiceNames key in sourceInfrastructureServices.Keys) |
41 | 60 | { |
| 61 | + InfrastructureService sourceInfrastructureService; |
| 62 | + sourceInfrastructureServices.TryGetValue(key, out sourceInfrastructureService); |
42 | 63 | InfrastructureService destinationInfrastructureService = new InfrastructureService { Name = sourceInfrastructureService.Name, Value = sourceInfrastructureService.Value }; |
43 | | - destinationInfrastructureServices.Add(destinationInfrastructureService.Name, destinationInfrastructureService); |
| 64 | + destinationInfrastructureServices.Add(key, destinationInfrastructureService); |
44 | 65 | } |
45 | 66 |
|
46 | 67 | } |
47 | 68 |
|
48 | 69 | return destinationInfrastructureServices; |
49 | 70 | } |
50 | 71 |
|
51 | | - private IDictionary<string, Right> CopyRights(IDictionary<string, Right> sourceRights) |
| 72 | + private IDictionary<string, Property> CopyProperties(IDictionary<string, Property> sourceProperties) |
52 | 73 | { |
53 | | - IDictionary<string, Right> destinationRights = new Dictionary<string, Right>(); |
| 74 | + IDictionary<string, Property> destinationProperties = null; |
54 | 75 |
|
55 | | - if (sourceRights != null && sourceRights.Count > 0) |
| 76 | + if (sourceProperties != null) |
56 | 77 | { |
| 78 | + destinationProperties = new Dictionary<string, Property>(); |
57 | 79 |
|
58 | | - foreach (Right sourceRight in sourceRights.Values) |
| 80 | + foreach (string key in sourceProperties.Keys) |
59 | 81 | { |
60 | | - Right destinationRight = new Right { Type = sourceRight.Type, Value = sourceRight.Value }; |
61 | | - destinationRights.Add(destinationRight.Type, destinationRight); |
| 82 | + Property sourceProperty; |
| 83 | + sourceProperties.TryGetValue(key, out sourceProperty); |
| 84 | + Property destinationProperty = new Property { Name = sourceProperty.Name, Value = sourceProperty.Value }; |
| 85 | + destinationProperties.Add(key, destinationProperty); |
62 | 86 | } |
63 | 87 |
|
64 | 88 | } |
65 | 89 |
|
66 | | - return destinationRights; |
| 90 | + return destinationProperties; |
67 | 91 | } |
68 | 92 |
|
69 | | - private ICollection<Model.Infrastructure.Service> CopyServices(ICollection<Model.Infrastructure.Service> sourceServices) |
| 93 | + private IDictionary<string, ProvisionedZone> CopyProvisionedZones(IDictionary<string, ProvisionedZone> sourceProvisionedZones) |
70 | 94 | { |
71 | | - ICollection<Model.Infrastructure.Service> destinationServices = new List<Model.Infrastructure.Service>(); |
| 95 | + IDictionary<string, ProvisionedZone> destinationProvisionedZones = null; |
72 | 96 |
|
73 | | - if (sourceServices != null && sourceServices.Count > 0) |
| 97 | + if (sourceProvisionedZones != null) |
74 | 98 | { |
| 99 | + destinationProvisionedZones = new Dictionary<string, ProvisionedZone>(); |
75 | 100 |
|
76 | | - foreach (Model.Infrastructure.Service sourceService in sourceServices) |
| 101 | + foreach (string key in sourceProvisionedZones.Keys) |
77 | 102 | { |
78 | | - Model.Infrastructure.Service destinationService = new Model.Infrastructure.Service { ContextId = sourceService.ContextId, Name = sourceService.Name, Type = sourceService.Type }; |
79 | | - IDictionary<string, Right> rights = CopyRights(sourceService.Rights); |
| 103 | + ProvisionedZone sourceProvisionedZone; |
| 104 | + sourceProvisionedZones.TryGetValue(key, out sourceProvisionedZone); |
| 105 | + ProvisionedZone destinationProvisionedZone = new ProvisionedZone { SifId = sourceProvisionedZone.SifId }; |
80 | 106 |
|
81 | | - if (rights.Count > 0) |
| 107 | + if (sourceProvisionedZone.Services != null) |
82 | 108 | { |
83 | | - destinationService.Rights = rights; |
| 109 | + destinationProvisionedZone.Services = CopyServices(sourceProvisionedZone.Services); |
84 | 110 | } |
85 | 111 |
|
86 | | - destinationServices.Add(destinationService); |
| 112 | + destinationProvisionedZones.Add(key, destinationProvisionedZone); |
87 | 113 | } |
88 | 114 |
|
89 | 115 | } |
90 | 116 |
|
91 | | - return destinationServices; |
| 117 | + return destinationProvisionedZones; |
92 | 118 | } |
93 | 119 |
|
94 | | - private IDictionary<string, ProvisionedZone> CopyProvisionedZones(IDictionary<string, ProvisionedZone> sourceProvisionedZones) |
| 120 | + private IDictionary<string, Right> CopyRights(IDictionary<string, Right> sourceRights) |
95 | 121 | { |
96 | | - IDictionary<string, ProvisionedZone> destinationProvisionedZones = new Dictionary<string, ProvisionedZone>(); |
| 122 | + IDictionary<string, Right> destinationRights = null; |
97 | 123 |
|
98 | | - if (sourceProvisionedZones != null && sourceProvisionedZones.Count > 0) |
| 124 | + if (sourceRights != null) |
99 | 125 | { |
| 126 | + destinationRights = new Dictionary<string, Right>(); |
100 | 127 |
|
101 | | - foreach (ProvisionedZone sourceProvisionedZone in sourceProvisionedZones.Values) |
| 128 | + foreach (string key in sourceRights.Keys) |
102 | 129 | { |
| 130 | + Right sourceRight; |
| 131 | + sourceRights.TryGetValue(key, out sourceRight); |
| 132 | + Right destinationRight = new Right { Type = sourceRight.Type, Value = sourceRight.Value }; |
| 133 | + destinationRights.Add(key, destinationRight); |
| 134 | + } |
103 | 135 |
|
104 | | - ProvisionedZone destinationProvisionedZone = new ProvisionedZone { SifId = sourceProvisionedZone.SifId }; |
105 | | - ICollection<Model.Infrastructure.Service> services = CopyServices(sourceProvisionedZone.Services); |
| 136 | + } |
| 137 | + |
| 138 | + return destinationRights; |
| 139 | + } |
| 140 | + |
| 141 | + private ICollection<Model.Infrastructure.Service> CopyServices(ICollection<Model.Infrastructure.Service> sourceServices) |
| 142 | + { |
| 143 | + ICollection<Model.Infrastructure.Service> destinationServices = null; |
106 | 144 |
|
107 | | - if (services.Count > 0) |
| 145 | + if (sourceServices != null) |
| 146 | + { |
| 147 | + destinationServices = new List<Model.Infrastructure.Service>(); |
| 148 | + |
| 149 | + foreach (Model.Infrastructure.Service sourceService in sourceServices) |
| 150 | + { |
| 151 | + Model.Infrastructure.Service destinationService = new Model.Infrastructure.Service { ContextId = sourceService.ContextId, Name = sourceService.Name, Type = sourceService.Type }; |
| 152 | + |
| 153 | + if (sourceService.Rights != null) |
108 | 154 | { |
109 | | - destinationProvisionedZone.Services = services; |
| 155 | + destinationService.Rights = CopyRights(sourceService.Rights); |
110 | 156 | } |
111 | 157 |
|
112 | | - destinationProvisionedZones.Add(destinationProvisionedZone.SifId, destinationProvisionedZone); |
| 158 | + destinationServices.Add(destinationService); |
113 | 159 | } |
114 | 160 |
|
115 | 161 | } |
116 | 162 |
|
117 | | - return destinationProvisionedZones; |
| 163 | + return destinationServices; |
118 | 164 | } |
119 | 165 |
|
120 | 166 | public EnvironmentService() |
@@ -151,6 +197,11 @@ public override Guid Create(environmentType item) |
151 | 197 | IDictionary<string, ProvisionedZone> provisionedZones = CopyProvisionedZones(environmentRegister.ProvisionedZones); |
152 | 198 | Environment repoItem = MapperFactory.CreateInstance<environmentType, Environment>(item); |
153 | 199 |
|
| 200 | + if (environmentRegister.DefaultZone != null) |
| 201 | + { |
| 202 | + repoItem.DefaultZone = CopyDefaultZone(environmentRegister.DefaultZone); |
| 203 | + } |
| 204 | + |
154 | 205 | if (infrastructureServices.Count > 0) |
155 | 206 | { |
156 | 207 | repoItem.InfrastructureServices = CopyInfrastructureServices(environmentRegister.InfrastructureServices); |
|
0 commit comments