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");
}
}
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");
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations