mirror of
https://github.com/Karaka-Management/oms-OnlineResourceWatcher.git
synced 2026-02-08 20:38:40 +00:00
Continue datamapper implementation
This commit is contained in:
parent
d57d5965b8
commit
4bd4bde749
|
|
@ -19,12 +19,17 @@
|
|||
#include "../cOMS/Hash/MeowHash.h"
|
||||
#include "../cOMS/Utils/MathUtils.h"
|
||||
#include "../cOMS/Threads/Thread.h"
|
||||
#include "../cOMS/DataStorage/Database/Mapper/DataMapperFactory.h"
|
||||
|
||||
#include "../Models/Resource.h"
|
||||
#include "../Models/ResourceMapper.h"
|
||||
#include "../Models/ResourceType.h"
|
||||
#include "../Models/ResourceStatus.h"
|
||||
|
||||
namespace Controller {
|
||||
namespace ApiController {
|
||||
static Application::ApplicationAbstract *app = NULL;
|
||||
|
||||
void printHelp(int argc, char **argv)
|
||||
{
|
||||
printf(" The Online Resource Watcher app developed by jingga checks online or local resources\n");
|
||||
|
|
@ -80,35 +85,36 @@ namespace Controller {
|
|||
meow_u128 tempHash;
|
||||
|
||||
for (i = 0; i < data->count; ++i) {
|
||||
cachedSource = Utils::FileUtils::read_file(data->resources[i]->lastVersion);
|
||||
// cachedSource = Utils::FileUtils::read_file(data->resources[i]->last_version_path);
|
||||
|
||||
tempHash = Hash::Meow::MeowHash(Hash::Meow::MeowDefaultSeed, multi[i].size, multi[i].content);
|
||||
if (hasChanged = (strcmp(Hash::Meow::MeowStringify(tempHash), data->resources[i]->lastHash) == 0)) {
|
||||
if (hasChanged = (strcmp((char *) Hash::Meow::MeowStringify(tempHash), data->resources[i]->hash) == 0)) {
|
||||
// @todo: do stuff because of change!!!
|
||||
// create website image with pdf?
|
||||
// inform users
|
||||
}
|
||||
|
||||
if (hasChanged || data->resources[i]->lastCheckedAt == NULL) {
|
||||
if (hasChanged || data->resources[i]->checked_at == 0) {
|
||||
// @todo: download references + css references (= second level)
|
||||
// @todo: probably ignore javascript references, they are not useful for static offline comparisons!?
|
||||
|
||||
data->resources[i].lastHash = Hash::Meow::MeowStringify(tempHash);
|
||||
data->resources[i].lastChangedAt = time();
|
||||
data->resources[i]->hash = (char *) Hash::Meow::MeowStringify(tempHash);
|
||||
data->resources[i]->last_version_date = time(0);
|
||||
|
||||
// @todo: store new version
|
||||
// @todo: check if older version can/needs to be removed
|
||||
|
||||
data->resources[i].lastVersion = "PATH_TO_NEWEST_VERSION";
|
||||
data->resources[i].lastVersionHash = "Hash_of_new_version";
|
||||
data->resources[i]->last_version_path = (char *) "PATH_TO_NEWEST_VERSION\0";
|
||||
data->resources[i]->hash = (char *) "Hash_of_new_version\0";
|
||||
}
|
||||
|
||||
data->resources[i].lastCheckedAt = time();
|
||||
data->resources[i]->checked_at = time(0);
|
||||
|
||||
Models::ResourceMapper::update()
|
||||
->execute($data->resources[i]);
|
||||
// @todo: update data
|
||||
//DataStorage::Database::DataMapperFactory::update(&Models::ResourceMapper)
|
||||
// ->execute(data->resources[i]);
|
||||
|
||||
Models::Resource::free_Resource(data->resources[i]);
|
||||
Models::free_Resource(data->resources[i]);
|
||||
}
|
||||
|
||||
free(data->resources);
|
||||
|
|
@ -139,14 +145,14 @@ namespace Controller {
|
|||
free(resourceIdStrings);
|
||||
} else {
|
||||
// find and load all relevant ids from the database
|
||||
resources = ResourceMapper::get()
|
||||
->where('status', ResourceStatus::ACTIVE)
|
||||
resources = (Models::Resource *) DataStorage::Database::DataMapperFactory::get(&Models::ResourceMapper)
|
||||
->where((char *) "status", (void *) Models::ResourceStatus::RESOURCE_ACTIVE)
|
||||
->execute();
|
||||
}
|
||||
|
||||
// How many resources are handled in one thread
|
||||
// This must be multiplied with the thread count for the over all concurrent max downloads
|
||||
int THREAD_SIZE = app.config["app"]["resources"]["online"]["downloads"].get<int>();
|
||||
int THREAD_SIZE = app->config["app"]["resources"]["online"]["downloads"].get<int>();
|
||||
|
||||
Models::Resource **onlineResources = (Models::Resource **) malloc(oms_min(idLength, THREAD_SIZE) * sizeof(Models::Resource *));
|
||||
Models::Resource **offlineResources = (Models::Resource **) malloc(oms_min(idLength, THREAD_SIZE) * sizeof(Models::Resource *));
|
||||
|
|
@ -156,7 +162,7 @@ namespace Controller {
|
|||
int k = 0;
|
||||
|
||||
for (i = 0; i < idLength; ++i) {
|
||||
if (resources[i].type == Models::ResourceType::ONLINE) {
|
||||
if (resources[i].type == Models::ResourceType::RESOURCE_ONLINE) {
|
||||
onlineResources[j] = &resources[i];
|
||||
|
||||
++j;
|
||||
|
|
@ -173,7 +179,7 @@ namespace Controller {
|
|||
data->count = j;
|
||||
data->simultaneous = THREAD_SIZE;
|
||||
|
||||
Threads::pool_add_work(app.pool, onlineResourceThreaded, data);
|
||||
Threads::pool_add_work(app->pool, onlineResourceThreaded, data);
|
||||
|
||||
if (i + 1 < idLength) {
|
||||
onlineResources = (Models::Resource **) malloc((oms_min(idLength - i, THREAD_SIZE)) * sizeof(Models::Resource *));
|
||||
|
|
@ -188,7 +194,7 @@ namespace Controller {
|
|||
data->count = k;
|
||||
data->simultaneous = THREAD_SIZE;
|
||||
|
||||
Threads::pool_add_work(app.pool, offlineResourceThreaded, data);
|
||||
Threads::pool_add_work(app->pool, offlineResourceThreaded, data);
|
||||
|
||||
if (i + 1 < idLength) {
|
||||
offlineResources = (Models::Resource **) malloc((oms_min(idLength - i, THREAD_SIZE)) * sizeof(Models::Resource *));
|
||||
|
|
@ -197,7 +203,7 @@ namespace Controller {
|
|||
}
|
||||
}
|
||||
|
||||
Threads::pool_wait();
|
||||
Threads::pool_wait(app->pool);
|
||||
free(resources);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Models {
|
|||
typedef struct {
|
||||
int id = 0;
|
||||
|
||||
AccountStatus status = AccountStatus::ACTIVE;
|
||||
AccountStatus status = AccountStatus::ACCOUNT_ACTIVE;
|
||||
|
||||
char *email = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
namespace Models {
|
||||
typedef enum {
|
||||
ACTIVE = 1,
|
||||
INACTIVE = 2
|
||||
ACCOUNT_ACTIVE = 1,
|
||||
ACCOUNT_INACTIVE = 2
|
||||
} AccountStatus;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ReosurceStatus.h"
|
||||
|
||||
namespace Models {
|
||||
typedef struct {
|
||||
int id = 0;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ReosurceStatus.h"
|
||||
#include "ResourceStatus.h"
|
||||
#include "Organization.h"
|
||||
#include "ResourceInfo.h"
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ namespace Models {
|
|||
typedef struct {
|
||||
unsigned long long id = 0;
|
||||
|
||||
ResourceStatus status = ResourceStatus::INACTIVE;
|
||||
ResourceStatus status = ResourceStatus::RESOURCE_INACTIVE;
|
||||
|
||||
char *uri = NULL;
|
||||
|
||||
|
|
|
|||
34
server/Models/ResourceMapper.h
Normal file
34
server/Models/ResourceMapper.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* Karaka
|
||||
*
|
||||
* @package Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
#ifndef MODELS_RESOURCE_MAPPER_H
|
||||
#define MODELS_RESOURCE_MAPPER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../cOMS/DataStorage/Database/Mapper/DataMapperTypes.h"
|
||||
#include "../cOMS/DataStorage/Database/Mapper/MapperAbstract.h"
|
||||
|
||||
namespace Models {
|
||||
static const DataStorage::Database::MapperData ResourceMapper = {
|
||||
.MEMBER_COUNT = 1,
|
||||
.MODEL_STRUCTURE = new DataStorage::Database::ModelStructure[1] {
|
||||
{.name = "id", .size = sizeof(int)}
|
||||
},
|
||||
|
||||
.COLUMN_COUNT = 2,
|
||||
.COLUMNS = new DataStorage::Database::DataMapperColumn[2] {
|
||||
{.name = "orw_resource_id", .type = DataStorage::Database::FieldType::FIELD_TYPE_INT, .internal = "title"},
|
||||
{.name = "orw_resource_status", .type = DataStorage::Database::FieldType::FIELD_TYPE_INT, .internal = "status"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
namespace Models {
|
||||
typedef enum {
|
||||
ACTIVE = 1,
|
||||
INACTIVE = 2
|
||||
RESOURCE_ACTIVE = 1,
|
||||
RESOURCE_INACTIVE = 2
|
||||
} ResourceStatus;
|
||||
}
|
||||
|
||||
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
namespace Models {
|
||||
typedef enum {
|
||||
ONLINE = 1,
|
||||
OFFLINE = 2
|
||||
RESOURCE_ONLINE = 1,
|
||||
RESOURCE_OFFLINE = 2
|
||||
} ResourceType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@
|
|||
#include "Controller/ApiController.h"
|
||||
#include "Controller/InstallController.h"
|
||||
#include "cOMS/Router/Router.h"
|
||||
#include "cOMS/Application/ApplicationAbstract.h"
|
||||
|
||||
Router::Router generate_routes()
|
||||
Router::Router generate_routes(Application::ApplicationAbstract *app)
|
||||
{
|
||||
Controller::ApiController::app = app;
|
||||
|
||||
Router::Router router = Router::create_router(4);
|
||||
|
||||
Router::set(&router, "^.*?\\-h *.*$", (void *) &Controller::ApiController::printHelp);
|
||||
|
|
|
|||
42
server/bin/CMakeCache.txt
Executable file → Normal file
42
server/bin/CMakeCache.txt
Executable file → Normal file
|
|
@ -53,6 +53,32 @@ CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
|
|||
//Flags used by the CXX compiler during RELWITHDEBINFO builds.
|
||||
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
|
||||
|
||||
//C compiler
|
||||
CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc
|
||||
|
||||
//A wrapper around 'ar' adding the appropriate '--plugin' option
|
||||
// for the GCC compiler
|
||||
CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-11
|
||||
|
||||
//A wrapper around 'ranlib' adding the appropriate '--plugin' option
|
||||
// for the GCC compiler
|
||||
CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-11
|
||||
|
||||
//Flags used by the C compiler during all build types.
|
||||
CMAKE_C_FLAGS:STRING=
|
||||
|
||||
//Flags used by the C compiler during DEBUG builds.
|
||||
CMAKE_C_FLAGS_DEBUG:STRING=-g
|
||||
|
||||
//Flags used by the C compiler during MINSIZEREL builds.
|
||||
CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
|
||||
|
||||
//Flags used by the C compiler during RELEASE builds.
|
||||
CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
|
||||
|
||||
//Flags used by the C compiler during RELWITHDEBINFO builds.
|
||||
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
|
||||
|
||||
//Path to a program.
|
||||
CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND
|
||||
|
||||
|
|
@ -267,6 +293,22 @@ CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
|||
CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_C_COMPILER
|
||||
CMAKE_C_COMPILER-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_C_COMPILER_AR
|
||||
CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB
|
||||
CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_C_FLAGS
|
||||
CMAKE_C_FLAGS-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG
|
||||
CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL
|
||||
CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE
|
||||
CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO
|
||||
CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
|
||||
//ADVANCED property for variable: CMAKE_DLLTOOL
|
||||
CMAKE_DLLTOOL-ADVANCED:INTERNAL=1
|
||||
//Path to cache edit program executable.
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
Subproject commit 593fbc9f892206b7b5edd89aa68ead793272ba4d
|
||||
Subproject commit bc465ff0a8ea45ccb42b06fb7edb050bfa523791
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
#include "cOMS/Utils/OSWrapper.h"
|
||||
#include "cOMS/Router/Router.h"
|
||||
#include "cOMS/Threads/Thread.h"
|
||||
#include "cOMS/Application/ApplicationAbstract.h"
|
||||
|
||||
#include "Routes.h"
|
||||
|
||||
|
|
@ -24,13 +25,7 @@
|
|||
#define OMS_DEMO false
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
DataStorage::Database::ConnectionAbstract *db;
|
||||
nlohmann::json config;
|
||||
Threads::ThreadPool *pool;
|
||||
} App;
|
||||
|
||||
App app = {0};
|
||||
Application::ApplicationAbstract app = {0};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
|
@ -91,7 +86,7 @@ int main(int argc, char **argv)
|
|||
/* --------------- Handle request --------------- */
|
||||
|
||||
// Handle routes
|
||||
Router::Router router = generate_routes();
|
||||
Router::Router router = generate_routes(&app);
|
||||
Router::RouterFunc ptr = Router::match_route(&router, arg);
|
||||
|
||||
// No endpoint found
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user