2424import com .ctrip .framework .apollo .openapi .model .OpenAppDTO ;
2525import com .ctrip .framework .apollo .openapi .model .OpenCreateAppDTO ;
2626import com .ctrip .framework .apollo .openapi .model .OpenEnvClusterDTO ;
27- import com .ctrip .framework .apollo .openapi .model .MultiResponseEntity ;
2827import com .ctrip .framework .apollo .openapi .model .OpenEnvClusterInfo ;
29- import com .ctrip .framework .apollo .openapi .model .RichResponseEntity ;
28+ import com .ctrip .framework .apollo .openapi .model .OpenMissEnvDTO ;
3029import com .ctrip .framework .apollo .openapi .util .OpenApiModelConverters ;
3130import com .ctrip .framework .apollo .portal .component .PortalSettings ;
31+ import com .ctrip .framework .apollo .portal .component .UserIdentityContextHolder ;
3232import com .ctrip .framework .apollo .portal .entity .model .AppModel ;
3333import com .ctrip .framework .apollo .portal .environment .Env ;
3434import com .ctrip .framework .apollo .portal .listener .AppDeletionEvent ;
@@ -83,17 +83,17 @@ private App convert(OpenAppDTO dto) {
8383 * @see com.ctrip.framework.apollo.portal.controller.AppController#create(AppModel)
8484 */
8585 @ Override
86- public void createApp (OpenCreateAppDTO req ) {
86+ public OpenAppDTO createApp (OpenCreateAppDTO req ) {
8787 App app = convert (req .getApp ());
88- List <String > admins = req .getAdmins ();
88+ Set <String > admins = req .getAdmins ();
8989 if (admins == null ) {
90- admins = Collections .emptyList ();
90+ admins = Collections .emptySet ();
9191 }
92- appService .createAppAndAddRolePermission (app , new HashSet <>( admins ));
92+ return OpenApiModelConverters . fromApp ( appService .createAppAndAddRolePermission (app , admins ));
9393 }
9494
9595 @ Override
96- public List <OpenEnvClusterDTO > getEnvClusterInfo (String appId ) {
96+ public List <OpenEnvClusterDTO > getEnvClusters (String appId ) {
9797 List <OpenEnvClusterDTO > envClusters = new LinkedList <>();
9898
9999 List <Env > envs = portalSettings .getActiveEnvs ();
@@ -134,6 +134,7 @@ public List<OpenAppDTO> getAuthorizedApps() {
134134
135135 /**
136136 * Updating Application Information - Using OpenAPI DTOs
137+ *
137138 * @param openAppDTO OpenAPI application DTO
138139 */
139140 @ Override
@@ -145,11 +146,12 @@ public void updateApp(OpenAppDTO openAppDTO) {
145146
146147 /**
147148 * Get the current user's app list (paginated)
149+ *
148150 * @param page Pagination parameter
149151 * @return App list
150152 */
151153 @ Override
152- public List <OpenAppDTO > getAppsBySelf (Set <String > appIds , Integer page , Integer size ) {
154+ public List <OpenAppDTO > getAppsWithPageAndSize (Set <String > appIds , Integer page , Integer size ) {
153155 int pageIndex = page == null ? 0 : page ;
154156 int pageSize = (size == null || size <= 0 ) ? 20 : size ;
155157 Pageable pageable = Pageable .ofSize (pageSize ).withPage (pageIndex );
@@ -163,12 +165,12 @@ public List<OpenAppDTO> getAppsBySelf(Set<String> appIds, Integer page, Integer
163165
164166 /**
165167 * Create an application in a specified environment
168+ *
166169 * @param env Environment
167170 * @param app Application information
168- * @param operator Operator
169171 */
170172 @ Override
171- public void createAppInEnv (String env , OpenAppDTO app , String operator ) {
173+ public void createAppInEnv (String env , OpenAppDTO app ) {
172174 if (env == null ) {
173175 throw BadRequestException .invalidEnvFormat ("null" );
174176 }
@@ -179,14 +181,16 @@ public void createAppInEnv(String env, OpenAppDTO app, String operator) {
179181 throw BadRequestException .invalidEnvFormat (env );
180182 }
181183 App appEntity = convert (app );
182- appService .createAppInRemote (envEnum , appEntity );
184+ appService .createAppInRemoteNew (envEnum , appEntity );
183185
184186 roleInitializationService .initNamespaceSpecificEnvRoles (appEntity .getAppId (),
185- ConfigConsts .NAMESPACE_APPLICATION , env , operator );
187+ ConfigConsts .NAMESPACE_APPLICATION , env ,
188+ UserIdentityContextHolder .getOperator ().getUserId ());
186189 }
187190
188191 /**
189192 * Delete an application
193+ *
190194 * @param appId application ID
191195 * @return the deleted application
192196 */
@@ -199,56 +203,57 @@ public OpenAppDTO deleteApp(String appId) {
199203
200204 /**
201205 * Find missing environments
206+ *
202207 * @param appId application ID
203208 * @return list of missing environments
204209 */
205- public MultiResponseEntity findMissEnvs (String appId ) {
206- List <RichResponseEntity > entities = new ArrayList <>();
207- MultiResponseEntity response = new MultiResponseEntity ( HttpStatus . OK . value (), entities );
210+ public List < OpenMissEnvDTO > findMissEnvs (String appId ) {
211+ List <OpenMissEnvDTO > missEnvs = new ArrayList <>();
212+
208213 for (Env env : portalSettings .getActiveEnvs ()) {
209214 try {
210215 appService .load (env , appId );
211216 } catch (Exception e ) {
212- RichResponseEntity entity ;
217+ OpenMissEnvDTO missEnv = new OpenMissEnvDTO () ;
213218 if (e instanceof HttpClientErrorException
214219 && ((HttpClientErrorException ) e ).getStatusCode () == HttpStatus .NOT_FOUND ) {
215- entity = new RichResponseEntity ( HttpStatus . OK . value (), HttpStatus .OK .getReasonPhrase ());
216- entity . setBody (env .toString ());
220+ missEnv . setCode ( HttpStatus .OK .value ());
221+ missEnv . setMessage (env .toString ());
217222 } else {
218- entity = new RichResponseEntity (HttpStatus .INTERNAL_SERVER_ERROR .value (),
219- "load env:" + env .getName () + " cluster error." + e .getMessage ());
223+ missEnv .setCode (HttpStatus .INTERNAL_SERVER_ERROR .value ());
224+ missEnv .setMessage (
225+ String .format ("load appId:%s from env %s error." , appId , env ) + e .getMessage ());
220226 }
221- response . addEntitiesItem ( entity );
227+ missEnvs . add ( missEnv );
222228 }
223229 }
224- return response ;
230+ return missEnvs ;
225231 }
226232
227233 /**
228234 * Find AppNavTree
235+ *
229236 * @param appId
230237 * @return list of EnvClusterInfos
231238 */
232239 @ Override
233- public MultiResponseEntity getAppNavTree (String appId ) {
234- List <RichResponseEntity > entities = new ArrayList <>();
235- MultiResponseEntity response = new MultiResponseEntity (HttpStatus .OK .value (), entities );
240+ public List <OpenEnvClusterInfo > getEnvClusterInfos (String appId ) {
241+ List <OpenEnvClusterInfo > envClusterInfos = new ArrayList <>();
236242 List <Env > envs = portalSettings .getActiveEnvs ();
237243 for (Env env : envs ) {
238244 try {
239245 OpenEnvClusterInfo openEnvClusterInfo =
240246 OpenApiModelConverters .fromEnvClusterInfo (appService .createEnvNavNode (env , appId ));
241- RichResponseEntity entity =
242- new RichResponseEntity (HttpStatus .OK .value (), HttpStatus .OK .getReasonPhrase ());
243- entity .setBody (openEnvClusterInfo );
244- response .addEntitiesItem (entity );
247+ openEnvClusterInfo .setCode (HttpStatus .OK .value ());
248+ envClusterInfos .add (openEnvClusterInfo );
245249 } catch (Exception e ) {
246- logger .warn ("Failed to load env {} navigation for app {}" , env , appId , e );
247- RichResponseEntity entity = new RichResponseEntity (HttpStatus .INTERNAL_SERVER_ERROR .value (),
248- "load env:" + env .getName () + " cluster error." + e .getMessage ());
249- response .addEntitiesItem (entity );
250+ OpenEnvClusterInfo envClusterInfo = new OpenEnvClusterInfo ();
251+ envClusterInfo .setCode (HttpStatus .INTERNAL_SERVER_ERROR .value ());
252+ envClusterInfo .setEnv (env .getName ());
253+ envClusterInfo .setMessage ("load env:" + env .getName () + " cluster error." + e .getMessage ());
254+ envClusterInfos .add (envClusterInfo );
250255 }
251256 }
252- return response ;
257+ return envClusterInfos ;
253258 }
254259}
0 commit comments