use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class EnvironmentsApiServiceImpl method environmentsEnvironmentIdPut.
/**
* Update gateway environment
*
* @param environmentId environment ID
* @param body environment to be updated
* @param messageContext message context
* @return updated environment
* @throws APIManagementException if failed to update
*/
public Response environmentsEnvironmentIdPut(String environmentId, EnvironmentDTO body, MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
body.setId(environmentId);
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Environment env = EnvironmentMappingUtil.fromEnvDtoToEnv(body);
apiAdmin.updateEnvironment(organization, env);
URI location = null;
try {
location = new URI(RestApiConstants.RESOURCE_PATH_ENVIRONMENT + "/" + environmentId);
} catch (URISyntaxException e) {
String errorMessage = "Error while updating Environment : " + environmentId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return Response.ok(location).entity(body).build();
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurationByName.
private KeyManagerConfigurationDTO getKeyManagerConfigurationByName(Connection connection, String organization, String name) throws SQLException, IOException {
final String query = "SELECT * FROM AM_KEY_MANAGER WHERE NAME = ? AND ORGANIZATION = ?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, name);
preparedStatement.setString(2, organization);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
String uuid = resultSet.getString("UUID");
keyManagerConfigurationDTO.setUuid(uuid);
keyManagerConfigurationDTO.setName(resultSet.getString("NAME"));
keyManagerConfigurationDTO.setDisplayName(resultSet.getString("DISPLAY_NAME"));
keyManagerConfigurationDTO.setDescription(resultSet.getString("DESCRIPTION"));
keyManagerConfigurationDTO.setType(resultSet.getString("TYPE"));
keyManagerConfigurationDTO.setEnabled(resultSet.getBoolean("ENABLED"));
keyManagerConfigurationDTO.setOrganization(organization);
keyManagerConfigurationDTO.setTokenType(resultSet.getString("TOKEN_TYPE"));
keyManagerConfigurationDTO.setExternalReferenceId(resultSet.getString("EXTERNAL_REFERENCE_ID"));
try (InputStream configuration = resultSet.getBinaryStream("CONFIGURATION")) {
String configurationContent = IOUtils.toString(configuration);
Map map = new Gson().fromJson(configurationContent, Map.class);
keyManagerConfigurationDTO.setAdditionalProperties(map);
}
return keyManagerConfigurationDTO;
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getLightweightApplicationByConsumerKey.
public ApplicationInfo getLightweightApplicationByConsumerKey(String consumerKey) throws APIManagementException {
Connection connection = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
try {
connection = APIMgtDBUtil.getConnection();
String query = SQLConstants.GET_APPLICATION_INFO_BY_CK;
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, consumerKey);
rs = prepStmt.executeQuery();
if (rs.next()) {
ApplicationInfo applicationInfo = new ApplicationInfo();
applicationInfo.setName(rs.getString("NAME"));
applicationInfo.setUuid(rs.getString("UUID"));
applicationInfo.setOrganizationId(rs.getString("ORGANIZATION"));
applicationInfo.setOwner(rs.getString("OWNER"));
return applicationInfo;
}
} catch (SQLException e) {
handleException("Error while obtaining organisation of the application for client id " + consumerKey, e);
} finally {
APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
}
return null;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getKeyManagerConfigurationByUUID.
private KeyManagerConfigurationDTO getKeyManagerConfigurationByUUID(Connection connection, String uuid) throws SQLException, IOException {
final String query = "SELECT * FROM AM_KEY_MANAGER WHERE UUID = ?";
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, uuid);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();
keyManagerConfigurationDTO.setUuid(resultSet.getString("UUID"));
keyManagerConfigurationDTO.setName(resultSet.getString("NAME"));
keyManagerConfigurationDTO.setDisplayName(resultSet.getString("DISPLAY_NAME"));
keyManagerConfigurationDTO.setDescription(resultSet.getString("DESCRIPTION"));
keyManagerConfigurationDTO.setType(resultSet.getString("TYPE"));
keyManagerConfigurationDTO.setEnabled(resultSet.getBoolean("ENABLED"));
keyManagerConfigurationDTO.setOrganization(resultSet.getString("ORGANIZATION"));
keyManagerConfigurationDTO.setTokenType(resultSet.getString("TOKEN_TYPE"));
keyManagerConfigurationDTO.setExternalReferenceId(resultSet.getString("EXTERNAL_REFERENCE_ID"));
try (InputStream configuration = resultSet.getBinaryStream("CONFIGURATION")) {
String configurationContent = IOUtils.toString(configuration);
Map map = new Gson().fromJson(configurationContent, Map.class);
keyManagerConfigurationDTO.setAdditionalProperties(map);
}
return keyManagerConfigurationDTO;
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.persistence.dto.Organization in project carbon-apimgt by wso2.
the class ApiMgtDAO method getApplicationByUUID.
/**
* Retrieves the Application which is corresponding to the given UUID String
*
* @param uuid UUID of Application
* @return
* @throws APIManagementException
*/
public Application getApplicationByUUID(String uuid) throws APIManagementException {
Connection connection = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
int applicationId = 0;
Application application = null;
try {
connection = APIMgtDBUtil.getConnection();
String query = SQLConstants.GET_APPLICATION_BY_UUID_SQL;
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, uuid);
rs = prepStmt.executeQuery();
if (rs.next()) {
String applicationName = rs.getString("NAME");
String subscriberId = rs.getString("SUBSCRIBER_ID");
String subscriberName = rs.getString("USER_ID");
Subscriber subscriber = new Subscriber(subscriberName);
subscriber.setId(Integer.parseInt(subscriberId));
application = new Application(applicationName, subscriber);
application.setDescription(rs.getString("DESCRIPTION"));
application.setStatus(rs.getString("APPLICATION_STATUS"));
application.setCallbackUrl(rs.getString("CALLBACK_URL"));
applicationId = rs.getInt("APPLICATION_ID");
application.setId(applicationId);
application.setGroupId(rs.getString("GROUP_ID"));
application.setUUID(rs.getString("UUID"));
application.setTier(rs.getString("APPLICATION_TIER"));
application.setTokenType(rs.getString("TOKEN_TYPE"));
application.setOwner(rs.getString("CREATED_BY"));
application.setOrganization(rs.getString("ORGANIZATION"));
subscriber.setId(rs.getInt("SUBSCRIBER_ID"));
if (multiGroupAppSharingEnabled) {
if (application.getGroupId() == null || application.getGroupId().isEmpty()) {
application.setGroupId(getGroupId(connection, application.getId()));
}
}
Timestamp createdTime = rs.getTimestamp("CREATED_TIME");
application.setCreatedTime(createdTime == null ? null : String.valueOf(createdTime.getTime()));
try {
Timestamp updated_time = rs.getTimestamp("UPDATED_TIME");
application.setLastUpdatedTime(updated_time == null ? null : String.valueOf(updated_time.getTime()));
} catch (SQLException e) {
// fixing Timestamp issue with default value '0000-00-00 00:00:00'for existing applications created
application.setLastUpdatedTime(application.getCreatedTime());
}
}
// Get custom attributes of application
if (application != null) {
Map<String, String> applicationAttributes = getApplicationAttributes(connection, applicationId);
application.setApplicationAttributes(applicationAttributes);
}
} catch (SQLException e) {
handleException("Error while obtaining details of the Application : " + uuid, e);
} finally {
APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
}
return application;
}
Aggregations