@@ -75,7 +75,18 @@ public void saveAPILocally(ObjectMapper mapper, ExportAPI exportAPI, String conf
7575 }
7676
7777 storePrivateCerts (localFolder , exportAPI .getAuthenticationProfiles ());
78+ updateMapperFilter (mapper );
79+ writeContent (mapper , exportAPI , localFolder , configFile );
80+ LOG .info ("Successfully exported API: {} into folder: {}" , exportAPI .getName (), localFolder .getAbsolutePath ());
81+ if (!APIManagerAdapter .getInstance ().hasAdminAccount ()) {
82+ LOG .warn ("Export has been done with an Org-Admin account only. Export is restricted by the following: " );
83+ LOG .warn ("- No Quotas has been exported for the API" );
84+ LOG .warn ("- No Client-Organizations" );
85+ LOG .warn ("- Only subscribed applications from the Org-Admins organization" );
86+ }
87+ }
7888
89+ public void updateMapperFilter (ObjectMapper mapper ) {
7990 mapper .registerModule (new SimpleModule ().setSerializerModifier (new APIExportSerializerModifier ()));
8091 mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
8192 FilterProvider filters = new SimpleFilterProvider ()
@@ -85,14 +96,21 @@ public void saveAPILocally(ObjectMapper mapper, ExportAPI exportAPI, String conf
8596 SimpleBeanPropertyFilter .serializeAllExcept ("apiMethodId" ))
8697 .setDefaultFilter (SimpleBeanPropertyFilter .serializeAllExcept ());
8798 mapper .setFilterProvider (filters );
88- writeContent (mapper , exportAPI , localFolder , configFile );
89- LOG .info ("Successfully exported API: {} into folder: {}" , exportAPI .getName (), localFolder .getAbsolutePath ());
90- if (!APIManagerAdapter .getInstance ().hasAdminAccount ()) {
91- LOG .warn ("Export has been done with an Org-Admin account only. Export is restricted by the following: " );
92- LOG .warn ("- No Quotas has been exported for the API" );
93- LOG .warn ("- No Client-Organizations" );
94- LOG .warn ("- Only subscribed applications from the Org-Admins organization" );
99+ }
100+
101+ public void writeToConsole (ObjectMapper mapper , List <ExportAPI > exportAPI ) throws AppException {
102+ if (exportAPI == null || exportAPI .isEmpty ()) return ;
103+ try {
104+ mapper .enable (SerializationFeature .INDENT_OUTPUT );
105+ if (exportAPI .size () == 1 )
106+ mapper .writeValue (System .out , exportAPI .get (0 ));
107+ else
108+ mapper .writeValue (System .out , exportAPI );
109+ } catch (IOException e ) {
110+ throw new AppException ("Problem in writing JSON / Yaml data" , ErrorCode .UNXPECTED_ERROR , e );
111+
95112 }
113+
96114 }
97115
98116 private String getVHost (ExportAPI exportAPI ) throws AppException {
@@ -146,6 +164,7 @@ private void storePrivateCerts(File localFolder, List<AuthenticationProfile> aut
146164 }
147165 }
148166
167+
149168 public void writeSpec (APISpecification apiDef , ExportAPI exportAPI , File localFolder ) throws AppException {
150169 String targetFile = null ;
151170 try {
@@ -174,12 +193,11 @@ public void writeSpec(APISpecification apiDef, ExportAPI exportAPI, File localFo
174193 }
175194
176195
196+
177197 public void writeContent (ObjectMapper mapper , ExportAPI exportAPI , File localFolder , String configFile ) throws AppException {
178198 try {
179- mapper .enable (SerializationFeature .INDENT_OUTPUT );
180- if (EnvironmentProperties .PRINT_CONFIG_CONSOLE ) {
181- mapper .writeValue (System .out , exportAPI );
182- } else {
199+ if (!EnvironmentProperties .PRINT_CONFIG_CONSOLE ) {
200+ mapper .enable (SerializationFeature .INDENT_OUTPUT );
183201 mapper .writeValue (new File (localFolder .getCanonicalPath () + configFile ), exportAPI );
184202 }
185203 } catch (Exception e ) {
0 commit comments