Code cleanup in webapp publisher

4.x.x
mharindu 9 years ago
parent 6f8bb64e1c
commit 6db9b21623

@ -30,7 +30,16 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface Permission {
/**
* Represents the scope name.
* @return Returns scope name.
*/
String scope();
/**
* Represents the associated permissions.
* @return Returns list of permissions.
*/
String[] permissions();
}

@ -107,8 +107,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
List<Scope> scopes = new ArrayList<>();
for (URITemplate uriTemplate : api.getUriTemplates()) {
JsonObject authType = new JsonObject();
authType.addProperty("x-auth-type", "Application%20%26%20Application%20User");
JsonObject response = new JsonObject();
response.addProperty("200", "");
@ -148,7 +146,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
swaggerDefinition.addProperty("swagger", "2.0");
swaggerDefinition.add("info", info);
// adding scopes to definition
// adding scopes to swagger definition
if (!api.getScopes().isEmpty()) {
Gson gson = new Gson();
JsonElement element = gson.toJsonTree(api.getScopes(), new TypeToken<Set<Scope>>() {
@ -162,6 +160,9 @@ public class APIPublisherServiceImpl implements APIPublisherService {
swaggerDefinition.add("x-wso2-security", wso2Security);
}
}
if (log.isDebugEnabled()) {
log.debug("API swagger definition: " + swaggerDefinition.toString());
}
return swaggerDefinition.toString();
}
@ -193,4 +194,5 @@ public class APIPublisherServiceImpl implements APIPublisherService {
log.debug("End of publishing the batch of APIs");
}
}
}

@ -42,14 +42,10 @@ public class APIPublisherUtil {
public static final String API_VERSION_PARAM = "{version}";
public static final String API_PUBLISH_ENVIRONMENT = "Production and Sandbox";
private static final String API_CONFIG_DEFAULT_VERSION = "1.0.0";
private static final String PARAM_MANAGED_API_NAME = "managed-api-name";
private static final String PARAM_MANAGED_API_VERSION = "managed-api-version";
private static final String PARAM_MANAGED_API_CONTEXT = "managed-api-context";
private static final String PARAM_MANAGED_API_ENDPOINT = "managed-api-endpoint";
private static final String PARAM_MANAGED_API_OWNER = "managed-api-owner";
private static final String PARAM_MANAGED_API_TRANSPORTS = "managed-api-transports";
private static final String PARAM_MANAGED_API_IS_SECURED = "managed-api-isSecured";
private static final String PARAM_MANAGED_API_APPLICATION = "managed-api-application";
private static final String PARAM_SHARED_WITH_ALL_TENANTS = "isSharedWithAllTenants";
private static final String PARAM_PROVIDER_TENANT_DOMAIN = "providerTenantDomain";
@ -125,16 +121,22 @@ public class APIPublisherUtil {
if (scope != null) {
if (apiScopes.get(scope.getKey()) == null) {
apiScopes.put(scope.getKey(), scope);
} else {
// this has to be done because of the use of pass by reference
// where same object reference of scope should be available for both
// api scope and uri template scope
template.setScope(apiScopes.get(scope.getKey()));
}
}
}
Set<Scope> scopes = new HashSet<>(apiScopes.values());
api.setScopes(scopes);
// this has to be done because of the use of pass by reference
// where same object reference of scope should be available for both
// api scope and uri template scope
for (Scope scope : scopes) {
for (URITemplate template : uriTemplates) {
if (scope.getKey().equals(template.getScope().getKey())) {
template.setScope(scope);
}
}
}
api.setUriTemplates(uriTemplates);
}
return api;
@ -202,12 +204,13 @@ public class APIPublisherUtil {
* Build the API Configuration to be passed to APIM, from a given list of URL templates
*
* @param servletContext
* @param apiDef
* @return
*/
public static APIConfig buildApiConfig(ServletContext servletContext, APIResourceConfiguration apidef) {
public static APIConfig buildApiConfig(ServletContext servletContext, APIResourceConfiguration apiDef) {
APIConfig apiConfig = new APIConfig();
String name = apidef.getName();
String name = apiDef.getName();
if (name == null || name.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("API Name not set in @API Annotation");
@ -216,7 +219,7 @@ public class APIPublisherUtil {
}
apiConfig.setName(name);
String version = apidef.getVersion();
String version = apiDef.getVersion();
if (version == null || version.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("'API Version not set in @API Annotation'");
@ -226,7 +229,7 @@ public class APIPublisherUtil {
apiConfig.setVersion(version);
String context = apidef.getContext();
String context = apiDef.getContext();
if (context == null || context.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("'API Context not set in @API Annotation'");
@ -235,7 +238,7 @@ public class APIPublisherUtil {
}
apiConfig.setContext(context);
String[] tags = apidef.getTags();
String[] tags = apiDef.getTags();
if (tags == null || tags.length == 0) {
if (log.isDebugEnabled()) {
log.debug("'API tag not set in @API Annotation'");
@ -300,8 +303,8 @@ public class APIPublisherUtil {
&& Boolean.parseBoolean(sharingValueParam));
apiConfig.setSharedWithAllTenants(isSharedWithAllTenants);
Set<URITemplate> uriTemplates = new LinkedHashSet<URITemplate>();
for (APIResource apiResource : apidef.getResources()) {
Set<URITemplate> uriTemplates = new LinkedHashSet<>();
for (APIResource apiResource : apiDef.getResources()) {
URITemplate template = new URITemplate();
template.setAuthType(apiResource.getAuthType());
template.setHTTPVerb(apiResource.getHttpVerb());

@ -125,7 +125,6 @@ public class AnnotationUtil {
.class.getName());
Annotation apiAnno = clazz.getAnnotation(apiClazz);
List<APIResource> resourceList;
if (apiAnno != null) {

Loading…
Cancel
Save