use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiFileDAOImpl method updateAPI.
/**
* @see ApiDAO#updateAPI(String apiID, API substituteAPI)
*/
@Override
public void updateAPI(String apiID, API substituteAPI) throws APIMgtDAOException {
API oldAPI = getAPI(apiID);
if (oldAPI == null) {
String errorMsg = "Error while updating API. Unable to find API with Id: " + apiID;
log.error(errorMsg);
throw new APIMgtDAOException(errorMsg, ExceptionCodes.API_NOT_FOUND);
}
// set immutable properties from old API
API updatedAPI = new API.APIBuilder(substituteAPI).id(apiID).provider(oldAPI.getProvider()).name(oldAPI.getName()).version(oldAPI.getVersion()).context(oldAPI.getContext()).createdTime(oldAPI.getCreatedTime()).createdBy(oldAPI.getCreatedBy()).lifecycleInstanceId(oldAPI.getLifecycleInstanceId()).lifeCycleStatus(oldAPI.getLifeCycleStatus()).copiedFromApiId(oldAPI.getCopiedFromApiId()).build();
// Adding the API override the existing files.
addAPI(updatedAPI);
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiFileDAOImpl method getAPIs.
/**
* @see ApiDAO#getAPIs(Set, String)
*/
@Override
public List<API> getAPIs(Set<String> roles, String user) throws APIMgtDAOException {
File[] files = new File(storagePath).listFiles();
List<API> apiList = new ArrayList<>();
final FilenameFilter filenameFilter = (dir, name) -> (name.endsWith(APIMgtConstants.APIFileUtilConstants.JSON_EXTENSION) && name.contains(APIMgtConstants.APIFileUtilConstants.API_DEFINITION_FILE_PREFIX) && !dir.isHidden());
if (files != null) {
for (File file : files) {
apiList.add((API) fetchObject(file, FileApi.class, filenameFilter));
}
}
apiList.removeIf(Objects::isNull);
return apiList;
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class ApiFileDAOImpl method addAPI.
/**
* @see ApiDAO#addAPI(API api)
*/
@Override
public void addAPI(API api) throws APIMgtDAOException {
// Save API definition
FileApi fileApi = new FileApi(api);
String apiExportDirectory = APIFileUtils.getAPIBaseDirectory(storagePath, fileApi);
APIFileUtils.createDirectory(apiExportDirectory);
APIFileUtils.exportApiDefinitionToFileSystem(fileApi, apiExportDirectory);
// Export gateway config to file system
APIFileUtils.exportGatewayConfigToFileSystem(api.getGatewayConfig(), api, apiExportDirectory);
// Export swagger definition to file system.
APIFileUtils.exportSwaggerDefinitionToFileSystem(api.getApiDefinition(), api, apiExportDirectory);
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO in project carbon-apimgt by wso2.
the class DAOFactory method getApiDAO.
public static ApiDAO getApiDAO() throws APIMgtDAOException {
ApiDAO apiDAO = null;
if (System.getProperty(EDITOR_MODE) != null) {
String filePath;
if ((filePath = System.getProperty(EDITOR_SAVE_PATH)) != null) {
apiDAO = new ApiFileDAOImpl(filePath);
return apiDAO;
} else {
throw new APIMgtDAOException("Editor archive storage path not provided", ExceptionCodes.APIM_DAO_EXCEPTION);
}
}
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL)) {
apiDAO = new ApiDAOImpl(new MysqlSQLStatements());
} else if (driverName.contains(H2)) {
apiDAO = new ApiDAOImpl(new H2SQLStatements());
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
apiDAO = new ApiDAOImpl(new MssqlSQLStatements());
} else if (driverName.contains(POSTGRE)) {
apiDAO = new ApiDAOImpl(new PostgresSQLStatements());
} else if (driverName.contains(ORACLE)) {
apiDAO = new ApiDAOImpl(new OracleSQLStatements());
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting ApiDAO", e);
}
setup();
return apiDAO;
}
use of org.wso2.carbon.apimgt.core.dao.ApiDAO 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);
}
}
}
Aggregations