11package com .axway .apim .api .export .impl ;
22
33import java .lang .reflect .Constructor ;
4+ import java .util .ArrayList ;
5+ import java .util .Arrays ;
6+ import java .util .HashMap ;
7+ import java .util .Iterator ;
48import java .util .List ;
9+ import java .util .Map ;
510import java .util .Scanner ;
611
712import org .slf4j .Logger ;
1217import com .axway .apim .adapter .apis .APIFilter ;
1318import com .axway .apim .adapter .apis .APIFilter .Builder ;
1419import com .axway .apim .adapter .apis .APIFilter .Builder .APIType ;
20+ import com .axway .apim .adapter .apis .APIManagerPoliciesAdapter .PolicyType ;
1521import com .axway .apim .adapter .apis .APIFilter .METHOD_TRANSLATION ;
1622import com .axway .apim .adapter .apis .APIFilter .POLICY_TRANSLATION ;
1723import com .axway .apim .api .API ;
24+ import com .axway .apim .api .export .ExportAPI ;
1825import com .axway .apim .api .export .lib .APIExportParams ;
26+ import com .axway .apim .api .model .InboundProfile ;
27+ import com .axway .apim .api .model .Organization ;
28+ import com .axway .apim .api .model .OutboundProfile ;
29+ import com .axway .apim .api .model .Policy ;
30+ import com .axway .apim .api .model .SecurityDevice ;
31+ import com .axway .apim .api .model .SecurityProfile ;
1932import com .axway .apim .lib .errorHandling .AppException ;
2033import com .axway .apim .lib .errorHandling .ErrorCode ;
2134
@@ -30,6 +43,7 @@ public abstract class APIResultHandler {
3043 public enum APIListImpl {
3144 JSON_EXPORTER (JsonAPIExporter .class ),
3245 CONSOLE_EXPORTER (ConsoleAPIExporter .class ),
46+ CSV_EXPORTER (CSVAPIExporter .class ),
3347 API_DELETE_HANDLER (DeleteAPIHandler .class ),
3448 API_UNPUBLISH_HANDLER (UnpublishAPIHandler .class );
3549
@@ -77,9 +91,11 @@ protected Builder getBaseAPIFilterBuilder() {
7791 .hasId (params .getValue ("id" ))
7892 .hasName (params .getValue ("name" ))
7993 .hasState (params .getValue ("state" ))
94+ .hasBackendBasepath (params .getValue ("backend" ))
8095 .includeCustomProperties (APIManagerAdapter .getAllConfiguredCustomProperties (CUSTOM_PROP_TYPE .api ))
8196 .translateMethods (METHOD_TRANSLATION .AS_NAME )
82- .translatePolicies (POLICY_TRANSLATION .TO_NAME );
97+ .translatePolicies (POLICY_TRANSLATION .TO_NAME )
98+ .useFEAPIDefinition (params .isUseFEAPIDefinition ());
8399 return builder ;
84100 }
85101
@@ -94,11 +110,121 @@ protected static boolean askYesNo(String question, String positive, String negat
94110 negative = negative .toUpperCase ();
95111 String answer ;
96112 do {
97- System .out .print (question );
113+ System .out .print (question + " " );
98114 answer = input .next ().trim ().toUpperCase ();
99115 } while (!answer .matches (positive ) && !answer .matches (negative ));
100116 input .close ();
101117 // Assess if we match a positive response
102118 return answer .matches (positive );
103119 }
120+
121+ protected static String getBackendPath (API api ) {
122+ ExportAPI exportAPI = new ExportAPI (api );
123+ return exportAPI .getBackendBasepath ();
124+ }
125+
126+ protected static String getUsedSecurity (API api ) {
127+ List <String > usedSecurity = new ArrayList <String >();
128+ Map <String , SecurityProfile > secProfilesMappedByName = new HashMap <String , SecurityProfile >();
129+ try {
130+ for (SecurityProfile secProfile : api .getSecurityProfiles ()) {
131+ secProfilesMappedByName .put (secProfile .getName (), secProfile );
132+ }
133+
134+ Iterator <InboundProfile > it ;
135+ it = api .getInboundProfiles ().values ().iterator ();
136+
137+ while (it .hasNext ()) {
138+ InboundProfile profile = it .next ();
139+ SecurityProfile usedSecProfile = secProfilesMappedByName .get (profile .getSecurityProfile ());
140+ for (SecurityDevice device : usedSecProfile .getDevices ()) {
141+ usedSecurity .add ("" +device .getType ());
142+ }
143+ }
144+ String result = usedSecurity .toString ().replace ("[" , "" ).replace ("]" , "" );
145+ return result ;
146+ } catch (AppException e ) {
147+ LOG .error ("Error getting security information for API" , e );
148+ return "Err" ;
149+ }
150+ }
151+
152+ protected static List <String > getUsedPolicies (API api , PolicyType type ) {
153+ return getUsedPolicies (api ).get (type );
154+ }
155+
156+ protected static Map <PolicyType , List <String >> getUsedPolicies (API api ) {
157+ Iterator <OutboundProfile > it ;
158+ Map <PolicyType , List <String >> result = new HashMap <PolicyType , List <String >>();
159+ List <String > requestPolicies = new ArrayList <String >();
160+ List <String > routingPolicies = new ArrayList <String >();
161+ List <String > responsePolicies = new ArrayList <String >();
162+ List <String > faultHandlerPolicies = new ArrayList <String >();
163+ try {
164+ it = api .getOutboundProfiles ().values ().iterator ();
165+ } catch (AppException e ) {
166+ LOG .error ("Error getting policy information for API" , e );
167+ return result ;
168+ }
169+
170+ while (it .hasNext ()) {
171+ OutboundProfile profile = it .next ();
172+ if (profile .getRouteType ().equals ("proxy" )) continue ;
173+ if (profile .getRequestPolicy ()!=null && profile .getRequestPolicy ().getName ()!=null ) {
174+ requestPolicies .add (profile .getRequestPolicy ().getName ());
175+ }
176+ if (profile .getRoutePolicy ()!=null && profile .getRoutePolicy ().getName ()!=null ) {
177+ routingPolicies .add (profile .getRoutePolicy ().getName ());
178+ }
179+ if (profile .getResponsePolicy ()!=null && profile .getResponsePolicy ().getName ()!=null ) {
180+ responsePolicies .add (profile .getResponsePolicy ().getName ());
181+ }
182+ if (profile .getFaultHandlerPolicy ()!=null && profile .getFaultHandlerPolicy ().getName ()!=null ) {
183+ faultHandlerPolicies .add (profile .getFaultHandlerPolicy ().getName ());
184+ }
185+ }
186+ result .put (PolicyType .REQUEST , requestPolicies );
187+ result .put (PolicyType .ROUTING , routingPolicies );
188+ result .put (PolicyType .RESPONSE , responsePolicies );
189+ result .put (PolicyType .FAULT_HANDLER , faultHandlerPolicies );
190+ return result ;
191+ }
192+
193+ protected static String getCustomProps (API api ) {
194+ if (api .getCustomProperties ()==null ) return "N/A" ;
195+ Iterator <String > it = api .getCustomProperties ().keySet ().iterator ();
196+ List <String > props = new ArrayList <String >();
197+ while (it .hasNext ()) {
198+ String property = it .next ();
199+ String value = api .getCustomProperties ().get (property );
200+ props .add (property + ": " + value );
201+ }
202+ return props .toString ().replace ("[" , "" ).replace ("]" , "" );
203+ }
204+
205+ protected static String getTags (API api ) {
206+ if (api .getTags ()==null ) return "None" ;
207+ Iterator <String > it = api .getTags ().keySet ().iterator ();
208+ List <String > tags = new ArrayList <String >();
209+ while (it .hasNext ()) {
210+ String tagGroup = it .next ();
211+ String [] tagValues = api .getTags ().get (tagGroup );
212+ tags .add (tagGroup + ": " + Arrays .toString (tagValues ));
213+ }
214+ return tags .toString ().replace ("[" , "" ).replace ("]" , "" );
215+ }
216+
217+ protected static List <String > getGrantedOrganizations (API api ) {
218+ List <String > grantedOrgs = new ArrayList <String >();
219+ try {
220+ if (api .getClientOrganizations ()==null ) return grantedOrgs ;
221+ for (Organization org : api .getClientOrganizations ()) {
222+ grantedOrgs .add (org .getName ());
223+ }
224+ return grantedOrgs ;
225+ } catch (Exception e ) {
226+ LOG .error ("Error getting API client organization" );
227+ return grantedOrgs ;
228+ }
229+ }
104230}
0 commit comments