Skip to content

Commit 63cd593

Browse files
authored
Merge pull request #10 from Sandro642/feature/clean/serial
Feature/clean/serial
2 parents d515296 + 39ad215 commit 63cd593

11 files changed

Lines changed: 77 additions & 22 deletions

File tree

.github/workflows/work-jar.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ name: Publish JAR to GitHub Pages
22
on:
33
push:
44
branches:
5-
- main
65
- feature/hook
6+
- feature/serializer
7+
- feature/clean/serial
78
permissions:
89
contents: write
910
pages: write

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ plugins {
55
id("maven-publish") // Plugin pour la publication
66
}
77

8+
89
group = "fr.sandro642.github"
9-
version = "0.1.3.8-SNAPSHOT" // Version de votre projet
10+
version = "0.1.3.17.1-SNAPSHOT" // Version de votre projet
11+
1012

1113
// Ajoutez cette tâche à votre build.gradle.kts
1214
tasks.register("printVersion") {

readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ Bienvenue dans **ConnectorAPI** : la passerelle universelle pour connecter, auto
44
Et si vous pensiez que les API étaient compliquées, détrompez-vous ! Avec ConnectorAPI, c’est comme jouer avec des Lego : simple, intuitif et puissant.
55

66
---
7+
8+
```java
9+
Stable Version : 0.1.2
10+
```
11+
12+
---
13+
714
```java
815
Support Lib 23 | Future 24
916

@@ -14,6 +21,14 @@ Hook -----------------------|
1421
```
1522
---
1623

24+
Changelog :
25+
26+
```java
27+
- [0.1.3.9-SNAPSHOT] : Ajout de la sérialisation des données pour une compatibilisation parfaite des données avec les HOOK.
28+
```
29+
30+
---
31+
1732
## 🌟 Pourquoi ConnectorAPI ?
1833

1934
Imaginez une API qui ne se contente pas de relier des services, mais qui devient le chef d’orchestre de vos intégrations. ConnectorAPI est conçu pour :

src/main/java/fr/sandro642/github/ConnectorAPI.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ public static void initialize(ResourceType resourceType) {
3636
// Génère le template si nécessaire
3737
yamlUtils.generateTemplateIfNotExists(resourceType);
3838

39-
storeAndRetrieve.store.put(storeAndRetrieve.FILE_LOCATION_KEY, resourceType.getPath());
39+
if (resourceType == ResourceType.MC_RESOURCES) {
40+
storeAndRetrieve.store.put(storeAndRetrieve.FILE_LOCATION_KEY, MCSupport().getPluginPath());
41+
} else {
42+
storeAndRetrieve.store.put(storeAndRetrieve.FILE_LOCATION_KEY, resourceType.getPath());
43+
}
4044

4145
// Charge l'URL depuis le fichier YAML
4246
String baseUrl = yamlUtils.getURL();

src/main/java/fr/sandro642/github/api/ApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ApiClient {
3030
* Constructeur de ApiClient qui initialise WebClient avec l'URL de base.
3131
*/
3232
public ApiClient() {
33-
String baseUrl = (String) ConnectorAPI.StoreAndRetrieve().get(ConnectorAPI.StoreAndRetrieve().URL_KEY);
33+
String baseUrl = (String) ConnectorAPI.StoreAndRetrieve().store.get(ConnectorAPI.StoreAndRetrieve().URL_KEY);
3434

3535
if (baseUrl == null) {
3636
throw new RuntimeException("URL de base non trouvée. Assurez-vous d'avoir initialisé ConnectorAPI. ");

src/main/java/fr/sandro642/github/hook/MCSupport.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ private MCSupport() {
3636
*/
3737
public boolean isMCProject() {
3838
try {
39+
3940
String fileLocation = (String) fr.sandro642.github.ConnectorAPI.StoreAndRetrieve().store.get(fr.sandro642.github.ConnectorAPI.StoreAndRetrieve().FILE_LOCATION_KEY);
4041
return fileLocation != null && fileLocation.contains(fr.sandro642.github.jobs.misc.ResourceType.MC_RESOURCES.getPath());
4142
} catch (Exception e) {
@@ -57,13 +58,8 @@ public Plugin setPluginVariable(Plugin plugin) {
5758
if (plugin == null) {
5859
throw new IllegalArgumentException("Plugin cannot be null.");
5960
}
60-
61-
//if (isMCProject()) {
6261
this.pluginSingleton = plugin;
6362
return this.pluginSingleton;
64-
//} else {
65-
// throw new IllegalStateException("This method can only be called in a Minecraft project.");
66-
//}
6763
}
6864

6965
/**
@@ -74,9 +70,6 @@ public Plugin setPluginVariable(Plugin plugin) {
7470
* @throws IllegalStateException Si la méthode n'est pas appelée dans un projet Minecraft ou si le plugin n'est pas initialisé.
7571
*/
7672
public String getPluginPath() {
77-
//if (!isMCProject()) {
78-
//throw new IllegalStateException("This method can only be called in a Minecraft project.");
79-
//}
8073

8174
if (pluginSingleton == null) {
8275
throw new IllegalStateException("Plugin variable is not set. Please call setPluginVariable first.");

src/main/java/fr/sandro642/github/jobs/JobGetInfos.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import fr.sandro642.github.api.ApiClient;
55
import fr.sandro642.github.api.ApiResponse;
66
import fr.sandro642.github.jobs.misc.MethodType;
7-
import fr.sandro642.github.jobs.misc.ResourceType;
87
import fr.sandro642.github.jobs.misc.VersionType;
98
import fr.sandro642.github.utils.YamlUtils;
109

@@ -30,7 +29,6 @@ public class JobGetInfos {
3029

3130
/**
3231
* Constructeur de JobGetInfos qui initialise ApiClient et YamlUtils.
33-
* Utilise ResourceType.MAIN_RESOURCES pour le type de ressource par défaut.
3432
*/
3533
public JobGetInfos() {
3634
this.apiClient = new ApiClient();
@@ -169,6 +167,7 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Str
169167
*/
170168
public ApiResponse<Void> getResponse() {
171169
try {
170+
172171
String route = (String) ConnectorAPI.StoreAndRetrieve().store.get("currentRoute");
173172
MethodType method = (MethodType) ConnectorAPI.StoreAndRetrieve().store.get("currentMethod");
174173
Map<String, Object> body = (Map<String, Object>) ConnectorAPI.StoreAndRetrieve().store.get("currentBody");

src/main/java/fr/sandro642/github/utils/StoreAndRetrieve.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.sandro642.github.utils;
22

3-
import java.util.concurrent.ConcurrentHashMap;
4-
import java.util.Map;
3+
import java.util.HashMap;
54

65
/**
76
* StoreAndRetrieve est une classe utilitaire pour stocker et récupérer des valeurs associées à des clés.
@@ -22,7 +21,7 @@ public class StoreAndRetrieve {
2221
*/
2322
public final String URL_KEY = "baseUrl";
2423
public final String FILE_LOCATION_KEY = "fileLocation";
25-
public final Map<String, Object> store = new ConcurrentHashMap<>();
24+
public final HashMap<String, Object> store = new HashMap<>();
2625

2726
/**
2827
* Ajoute une valeur à la map avec la clé spécifiée.

src/main/java/fr/sandro642/github/utils/YamlUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class YamlUtils {
2727
* @return l'URL de base définie dans le fichier YAML, ou null si une erreur se produit
2828
*/
2929
public String getURL() {
30+
//HashMap<String, Object> storeLoad = ConnectorAPI.HookManager().loadData("store_and_retrieve.yml");
31+
3032
String yamlFilePath = ConnectorAPI.StoreAndRetrieve().store.get(ConnectorAPI.StoreAndRetrieve().FILE_LOCATION_KEY) + "/infos.yml";
3133

3234
try (InputStream inputStream = Files.newInputStream(Paths.get(yamlFilePath))) {
@@ -44,6 +46,8 @@ public String getURL() {
4446
* @return
4547
*/
4648
public String getRoute(String routeName) {
49+
//HashMap<String, Object> storeLoad = ConnectorAPI.HookManager().loadData("store_and_retrieve.yml");
50+
4751
String yamlFilePath = ConnectorAPI.StoreAndRetrieve().store.get(ConnectorAPI.StoreAndRetrieve().FILE_LOCATION_KEY) + "/infos.yml";
4852

4953
try (InputStream inputStream = Files.newInputStream(Paths.get(yamlFilePath))) {

src/test/java/fr/sandro642/github/test/Main.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import fr.sandro642.github.jobs.misc.VersionType;
99
import org.junit.jupiter.api.Test;
1010

11+
import java.util.HashMap;
12+
1113
/**
1214
* Main est une classe de test pour vérifier la création du fichier YML et pleins d'autres fonctionnalités de la librairie.
1315
* @author Sandro642
@@ -22,14 +24,16 @@ public void getUrl() {
2224
ConnectorAPI.initialize(ResourceType.TEST_RESOURCES);
2325

2426
System.out.println(ConnectorAPI.YamlUtils().getURL());
25-
26-
27-
2827
}
2928

3029
@Test
3130
public void outGetURL() {
32-
System.out.println(ConnectorAPI.StoreAndRetrieve().store.get(ConnectorAPI.StoreAndRetrieve().URL_KEY));
31+
HashMap<String, Object> data = ConnectorAPI.HookManager().loadData("store_and_retrieve.yml");
32+
33+
34+
//System.out.println(data.get(ConnectorAPI.StoreAndRetrieve().URL_KEY));
35+
36+
System.out.println(ConnectorAPI.YamlUtils().getURL());
3337
}
3438

3539
@Test
@@ -41,7 +45,7 @@ public void getRoute() {
4145

4246
public static void main(String[] args) {
4347
// Initialisation du ConnectorAPI
44-
ConnectorAPI.initialize(ResourceType.TEST_RESOURCES);
48+
//ConnectorAPI.initialize(ResourceType.TEST_RESOURCES);
4549

4650
try {
4751
// Exemple d'utilisation comme demandé
@@ -69,4 +73,30 @@ public static void main(String[] args) {
6973
}
7074
}
7175

76+
@Test
77+
public void saveDataMap() {
78+
HashMap<String, Object> data = new HashMap<>();
79+
80+
data.put("version", "1.0.0");
81+
data.put("status", "ok");
82+
83+
ConnectorAPI.HookManager().saveData(data, "test_map.yml");
84+
}
85+
86+
@Test
87+
public void loadDataMap() {
88+
HashMap<String, Object> data = ConnectorAPI.HookManager().loadData("test_map.yml");
89+
90+
System.out.println("data version: " + data.get("version"));
91+
}
92+
93+
@Test
94+
public void resetDataMap() {
95+
HashMap<String, Object> data = ConnectorAPI.HookManager().loadData("test_map.yml");
96+
97+
data.clear();
98+
99+
ConnectorAPI.HookManager().saveData(data, "test_map.yml");
100+
}
101+
72102
}

0 commit comments

Comments
 (0)