Search in sources :

Example 1 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.

the class ApiDAOImpl method addDocumentInfo.

/**
 * Add artifact resource meta data to an API
 *
 * @param apiId        UUID of API
 * @param documentInfo {@link DocumentInfo}
 * @throws APIMgtDAOException if error occurs while accessing data layer
 */
@Override
public void addDocumentInfo(String apiId, DocumentInfo documentInfo) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            ApiResourceDAO.addResourceWithoutValue(connection, apiId, documentInfo.getId(), ResourceCategory.DOC);
            DocMetaDataDAO.addDocumentInfo(connection, documentInfo);
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 2 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.

the class ApiDAOImpl method updateDocumentInfo.

/**
 * Add artifact resource meta data to an API
 *
 * @param apiId        UUID of API
 * @param documentInfo {@link DocumentInfo}
 * @param updatedBy    user who performs the action
 * @throws APIMgtDAOException if error occurs while accessing data layer
 */
@Override
public void updateDocumentInfo(String apiId, DocumentInfo documentInfo, String updatedBy) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            DocMetaDataDAO.updateDocInfo(connection, documentInfo, updatedBy);
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 3 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.

the class EntityDAO method getLastUpdatedTimeOfResourceByName.

/**
 * Returns the last access time of the given entity identified by the NAME field.
 *
 * @param resourceTableName Table name of the entity
 * @param name value in the NAME field of the entity
 * @return Last access time of the requested resource
 * @throws APIMgtDAOException
 */
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
static String getLastUpdatedTimeOfResourceByName(String resourceTableName, String name) throws APIMgtDAOException {
    final String query = "SELECT LAST_UPDATED_TIME FROM " + resourceTableName + " WHERE NAME = ?";
    String lastUpdatedTime = null;
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, name);
        try (ResultSet rs = statement.executeQuery()) {
            if (rs.next()) {
                lastUpdatedTime = rs.getString("LAST_UPDATED_TIME");
            }
        }
        return lastUpdatedTime;
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error while retrieving last access time from table : " + resourceTableName + " and entity " + name, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method setApiResourceBuilderProperties.

/**
 * Extract properties in Operation entry and assign them to api resource builder properties.
 *
 * @param operationEntry     Map entry to be extracted properties
 * @param uriTemplateBuilder Uri template builder to assign related properties
 * @param resourcePath       resource path
 * @return APIResource.Builder object
 */
private APIResource.Builder setApiResourceBuilderProperties(Map.Entry<HttpMethod, Operation> operationEntry, UriTemplate.UriTemplateBuilder uriTemplateBuilder, String resourcePath) {
    Operation operation = operationEntry.getValue();
    APIResource.Builder apiResourceBuilder = new APIResource.Builder();
    List<String> producesList = operation.getProduces();
    if (producesList != null) {
        String produceSeparatedString = "\"";
        produceSeparatedString += String.join("\",\"", producesList) + "\"";
        apiResourceBuilder.produces(produceSeparatedString);
    }
    List<String> consumesList = operation.getConsumes();
    if (consumesList != null) {
        String consumesSeparatedString = "\"";
        consumesSeparatedString += String.join("\",\"", consumesList) + "\"";
        apiResourceBuilder.consumes(consumesSeparatedString);
    }
    if (operation.getOperationId() != null) {
        uriTemplateBuilder.templateId(operation.getOperationId());
    } else {
        uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(resourcePath, operationEntry.getKey().name()));
    }
    uriTemplateBuilder.httpVerb(operationEntry.getKey().name());
    apiResourceBuilder.uriTemplate(uriTemplateBuilder.build());
    return apiResourceBuilder;
}
Also used : APIResource(org.wso2.carbon.apimgt.core.models.APIResource) Operation(io.swagger.models.Operation)

Example 5 with Resource

use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.

the class APIExecutor method execute.

/**
 * This method will be called when the invoke() method of the default lifecycle implementation is called.
 * Execution logic should reside in this method since the default lifecycle implementation will determine
 * the execution output by looking at the output of this method.
 *
 * @param resource     The resource in which the lifecycle state is changed.
 * @param currentState Current lifecycle state.
 * @param targetState  The target lifecycle state.
 * @throws LifecycleException If exception occurs while running the executor.
 */
@Override
public void execute(Object resource, String currentState, String targetState) throws LifecycleException {
    API api = (API) resource;
    if (!currentState.equals(targetState)) {
        // todo:This place need to write how to handle Gateway publishing
        try {
            ApiDAO apiDAO = DAOFactory.getApiDAO();
            apiDAO.changeLifeCycleStatus(api.getId(), targetState);
        } catch (APIMgtDAOException e) {
            throw new LifecycleException("Couldn't create APIPublisher from user", e);
        }
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) LifecycleException(org.wso2.carbon.lcm.core.exception.LifecycleException) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO)

Aggregations

Resource (org.wso2.carbon.registry.core.Resource)335 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)263 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)224 HashMap (java.util.HashMap)196 ArrayList (java.util.ArrayList)162 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)153 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)142 Test (org.testng.annotations.Test)130 Registry (org.wso2.carbon.registry.core.Registry)119 Test (org.junit.Test)115 IOException (java.io.IOException)112 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)111 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)109 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)90 Map (java.util.Map)86 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)86 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)79 InputStream (java.io.InputStream)77 Collection (org.wso2.carbon.registry.core.Collection)77 API (org.wso2.carbon.apimgt.api.model.API)73