use of org.wso2.carbon.apimgt.api.model.Provider in project charon by wso2.
the class JSONEncoder method buildServiceProviderConfigJsonBody.
/*
* Build the service provider config json representation
* @param config
* @return
*/
public String buildServiceProviderConfigJsonBody(HashMap<String, Object> config) throws JSONException {
JSONObject rootObject = new JSONObject();
JSONObject bulkObject = new JSONObject();
bulkObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.SUPPORTED, config.get(SCIMConfigConstants.BULK));
bulkObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.MAX_OPERATIONS, config.get(SCIMConfigConstants.MAX_OPERATIONS));
bulkObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.MAX_PAYLOAD_SIZE, config.get(SCIMConfigConstants.MAX_PAYLOAD_SIZE));
JSONObject filterObject = new JSONObject();
filterObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.SUPPORTED, config.get(SCIMConfigConstants.FILTER));
filterObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.MAX_RESULTS, config.get(SCIMConfigConstants.MAX_RESULTS));
JSONObject patchObject = new JSONObject();
patchObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.SUPPORTED, config.get(SCIMConfigConstants.PATCH));
JSONObject sortObject = new JSONObject();
sortObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.SUPPORTED, config.get(SCIMConfigConstants.SORT));
JSONObject etagObject = new JSONObject();
etagObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.SUPPORTED, config.get(SCIMConfigConstants.ETAG));
JSONObject changePasswordObject = new JSONObject();
changePasswordObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.SUPPORTED, config.get(SCIMConfigConstants.CHNAGE_PASSWORD));
JSONArray authenticationSchemesArray = new JSONArray();
ArrayList<Object[]> values = (ArrayList<Object[]>) config.get(SCIMConfigConstants.AUTHENTICATION_SCHEMES);
for (int i = 0; i < values.size(); i++) {
JSONObject authenticationSchemeObject = new JSONObject();
Object[] value = values.get(i);
authenticationSchemeObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.NAME, value[0]);
authenticationSchemeObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.DESCRIPTION, value[1]);
authenticationSchemeObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.SPEC_URI, value[2]);
authenticationSchemeObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.DOCUMENTATION_URI, value[3]);
authenticationSchemeObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.TYPE, value[4]);
authenticationSchemeObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.PRIMARY, value[5]);
authenticationSchemesArray.put(authenticationSchemeObject);
}
rootObject.put(SCIMConstants.CommonSchemaConstants.SCHEMAS, new JSONArray().put(SCIMConstants.SERVICE_PROVIDER_CONFIG_SCHEMA_URI));
rootObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.DOCUMENTATION_URI, config.get(SCIMConfigConstants.DOCUMENTATION_URL));
rootObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.BULK, bulkObject);
rootObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.FILTER, filterObject);
rootObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.PATCH, patchObject);
rootObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.CHANGE_PASSWORD, changePasswordObject);
rootObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.SORT, sortObject);
rootObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.ETAG, etagObject);
rootObject.put(SCIMConstants.ServiceProviderConfigSchemaConstants.AUTHENTICATION_SCHEMAS, authenticationSchemesArray);
return rootObject.toString();
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAllEnvironments.
/**
* Returns the Environments List for the TenantId.
*
* @param tenantDomain The tenant domain.
* @return List of Environments.
*/
public List<Environment> getAllEnvironments(String tenantDomain) throws APIManagementException {
List<Environment> envList = new ArrayList<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_ENVIRONMENT_BY_ORGANIZATION_SQL)) {
prepStmt.setString(1, tenantDomain);
try (ResultSet rs = prepStmt.executeQuery()) {
while (rs.next()) {
Integer id = rs.getInt("ID");
String uuid = rs.getString("UUID");
String name = rs.getString("NAME");
String displayName = rs.getString("DISPLAY_NAME");
String description = rs.getString("DESCRIPTION");
String provider = rs.getString("PROVIDER");
Environment env = new Environment();
env.setId(id);
env.setUuid(uuid);
env.setName(name);
env.setDisplayName(displayName);
env.setDescription(description);
env.setProvider(provider);
env.setVhosts(getVhostGatewayEnvironments(connection, id));
envList.add(env);
}
}
} catch (SQLException e) {
handleException("Failed to get Environments in tenant domain: " + tenantDomain, e);
}
return envList;
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class ApiMgtDAO method getEnvironment.
/**
* Returns the Environment for the uuid in the tenant domain.
*
* @param tenantDomain the tenant domain to look environment
* @param uuid UUID of the environment
* @return Gateway environment with given UUID
*/
public Environment getEnvironment(String tenantDomain, String uuid) throws APIManagementException {
Environment env = null;
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_ENVIRONMENT_BY_ORGANIZATION_AND_UUID_SQL)) {
prepStmt.setString(1, tenantDomain);
prepStmt.setString(2, uuid);
try (ResultSet rs = prepStmt.executeQuery()) {
if (rs.next()) {
Integer id = rs.getInt("ID");
String name = rs.getString("NAME");
String displayName = rs.getString("DISPLAY_NAME");
String description = rs.getString("DESCRIPTION");
String provider = rs.getString("PROVIDER");
env = new Environment();
env.setId(id);
env.setUuid(uuid);
env.setName(name);
env.setDisplayName(displayName);
env.setDescription(description);
env.setProvider(provider);
env.setVhosts(getVhostGatewayEnvironments(connection, id));
}
}
} catch (SQLException e) {
handleException("Failed to get Environment in tenant domain:" + tenantDomain, e);
}
return env;
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAllAPIUsageByProvider.
/**
* @param providerName Name of the provider
* @return UserApplicationAPIUsage of given provider
* @throws org.wso2.carbon.apimgt.api.APIManagementException if failed to get
* UserApplicationAPIUsage for given provider
*/
public UserApplicationAPIUsage[] getAllAPIUsageByProvider(String providerName) throws APIManagementException {
Connection connection = null;
PreparedStatement ps = null;
ResultSet result = null;
try {
String sqlQuery = SQLConstants.GET_APP_API_USAGE_BY_PROVIDER_SQL;
connection = APIMgtDBUtil.getConnection();
ps = connection.prepareStatement(sqlQuery);
ps.setString(1, APIUtil.replaceEmailDomainBack(providerName));
result = ps.executeQuery();
Map<String, UserApplicationAPIUsage> userApplicationUsages = new TreeMap<String, UserApplicationAPIUsage>();
while (result.next()) {
int subId = result.getInt("SUBSCRIPTION_ID");
String userId = result.getString("USER_ID");
String application = result.getString("APPNAME");
int appId = result.getInt("APPLICATION_ID");
String subStatus = result.getString("SUB_STATUS");
String subsCreateState = result.getString("SUBS_CREATE_STATE");
String key = userId + "::" + application;
UserApplicationAPIUsage usage = userApplicationUsages.get(key);
if (usage == null) {
usage = new UserApplicationAPIUsage();
usage.setUserId(userId);
usage.setApplicationName(application);
usage.setAppId(appId);
userApplicationUsages.put(key, usage);
}
APIIdentifier apiId = new APIIdentifier(result.getString("API_PROVIDER"), result.getString("API_NAME"), result.getString("API_VERSION"));
SubscribedAPI apiSubscription = new SubscribedAPI(new Subscriber(userId), apiId);
apiSubscription.setSubStatus(subStatus);
apiSubscription.setSubCreatedStatus(subsCreateState);
apiSubscription.setUUID(result.getString("SUB_UUID"));
apiSubscription.setTier(new Tier(result.getString("SUB_TIER_ID")));
Application applicationObj = new Application(result.getString("APP_UUID"));
apiSubscription.setApplication(applicationObj);
usage.addApiSubscriptions(apiSubscription);
}
return userApplicationUsages.values().toArray(new UserApplicationAPIUsage[userApplicationUsages.size()]);
} catch (SQLException e) {
handleException("Failed to find API Usage for :" + providerName, e);
return null;
} finally {
APIMgtDBUtil.closeAllConnections(ps, connection, result);
}
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAPIInfoByUUID.
/**
* Retrieve basic information about the given API by the UUID quering only from AM_API
*
* @param apiId UUID of the API
* @return basic information about the API
* @throws APIManagementException error while getting the API information from AM_API
*/
public APIInfo getAPIInfoByUUID(String apiId) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection()) {
APIRevision apiRevision = getRevisionByRevisionUUID(connection, apiId);
String sql = SQLConstants.RETRIEVE_API_INFO_FROM_UUID;
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
if (apiRevision != null) {
preparedStatement.setString(1, apiRevision.getApiUUID());
} else {
preparedStatement.setString(1, apiId);
}
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
APIInfo.Builder apiInfoBuilder = new APIInfo.Builder();
apiInfoBuilder = apiInfoBuilder.id(resultSet.getString("API_UUID")).name(resultSet.getString("API_NAME")).version(resultSet.getString("API_VERSION")).provider(resultSet.getString("API_PROVIDER")).context(resultSet.getString("CONTEXT")).contextTemplate(resultSet.getString("CONTEXT_TEMPLATE")).status(APIUtil.getApiStatus(resultSet.getString("STATUS"))).apiType(resultSet.getString("API_TYPE")).createdBy(resultSet.getString("CREATED_BY")).createdTime(resultSet.getString("CREATED_TIME")).updatedBy(resultSet.getString("UPDATED_BY")).updatedTime(resultSet.getString("UPDATED_TIME")).revisionsCreated(resultSet.getInt("REVISIONS_CREATED")).isRevision(apiRevision != null);
if (apiRevision != null) {
apiInfoBuilder = apiInfoBuilder.apiTier(getAPILevelTier(connection, apiRevision.getApiUUID(), apiId));
} else {
apiInfoBuilder = apiInfoBuilder.apiTier(resultSet.getString("API_TIER"));
}
return apiInfoBuilder.build();
}
}
}
} catch (SQLException e) {
throw new APIManagementException("Error while retrieving apimgt connection", e, ExceptionCodes.INTERNAL_ERROR);
}
return null;
}
Aggregations