Search in sources :

Example 1 with Resource

use of org.wso2.carbon.registry.core.Resource in project jaggery by wso2.

the class RegistryHostObject method jsFunction_newResource.

public static Scriptable jsFunction_newResource(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
    RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
    if (arguments.length == 0) {
        if (registryHostObject.registry != null) {
            try {
                Resource resource = registryHostObject.registry.newResource();
                ResourceHostObject rho = (ResourceHostObject) cx.newObject(registryHostObject, "Resource", new Object[] { resource });
                return rho;
            } catch (RegistryException e) {
                throw new ScriptException("Error occurred while creating a new Resource", e);
            }
        } else {
            throw new ScriptException("Registry has not initialized");
        }
    } else {
        throw new ScriptException("newResource() Method doesn't accept arguments");
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 2 with Resource

use of org.wso2.carbon.registry.core.Resource in project jaggery by wso2.

the class RegistryHostObject method jsFunction_get.

public static Scriptable jsFunction_get(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
    RegistryHostObject rho = (RegistryHostObject) thisObj;
    if (arguments.length == 1) {
        if (arguments[0] instanceof String) {
            try {
                Scriptable hostObject;
                Resource resource = rho.registry.get((String) arguments[0]);
                if (resource instanceof Collection) {
                    hostObject = cx.newObject(rho, "Collection", new Object[] { resource });
                } else {
                    hostObject = cx.newObject(rho, "Resource", new Object[] { resource });
                }
                return hostObject;
            } catch (RegistryException e) {
                throw new ScriptException("Registry error occurred while executing get() operation", e);
            }
        } else {
            throw new ScriptException("Path argument of method get() should be a string");
        }
    } else if (arguments.length == 3) {
        if (arguments[0] instanceof String && arguments[1] instanceof Number && arguments[2] instanceof Number) {
            try {
                Collection collection = rho.registry.get((String) arguments[0], ((Number) arguments[1]).intValue(), ((Number) arguments[2]).intValue());
                CollectionHostObject cho = (CollectionHostObject) cx.newObject(rho, "Collection", new Object[] { collection });
                return cho;
            } catch (RegistryException e) {
                throw new ScriptException("Registry error occurred while executing get() operation", e);
            }
        } else {
            throw new ScriptException("Invalid argument types for get() method");
        }
    } else {
        throw new ScriptException("Invalid no. of arguments for get() method");
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 3 with Resource

use of org.wso2.carbon.registry.core.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 4 with Resource

use of org.wso2.carbon.registry.core.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 5 with Resource

use of org.wso2.carbon.registry.core.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)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)111 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)102 HashMap (java.util.HashMap)91 Test (org.testng.annotations.Test)64 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)59 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)56 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)53 BJSON (org.ballerinalang.model.values.BJSON)46 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)38 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)29 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)27 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)24 CharonException (org.wso2.charon3.core.exceptions.CharonException)24 IOException (java.io.IOException)23 Map (java.util.Map)20 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)20 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)17 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)17 ArrayList (java.util.ArrayList)15 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)15