Search in sources :

Example 56 with Organization

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();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 57 with Organization

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;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResultSet(java.sql.ResultSet) Gson(com.google.gson.Gson) PreparedStatement(java.sql.PreparedStatement) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 58 with Organization

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) ApplicationInfo(org.wso2.carbon.apimgt.api.model.ApplicationInfo) PreparedStatement(java.sql.PreparedStatement)

Example 59 with Organization

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;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResultSet(java.sql.ResultSet) Gson(com.google.gson.Gson) PreparedStatement(java.sql.PreparedStatement) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 60 with Organization

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;
}
Also used : Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Application(org.wso2.carbon.apimgt.api.model.Application) Timestamp(java.sql.Timestamp)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)304 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)106 API (org.wso2.carbon.apimgt.api.model.API)100 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)89 ArrayList (java.util.ArrayList)79 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)72 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)70 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)65 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)64 IOException (java.io.IOException)61 Registry (org.wso2.carbon.registry.core.Registry)58 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)57 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)56 HashMap (java.util.HashMap)54 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)53 Resource (org.wso2.carbon.registry.core.Resource)51 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)49 JSONObject (org.json.simple.JSONObject)45 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)44 URISyntaxException (java.net.URISyntaxException)42