funifier-mcp 0.2.0 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/funifier.mdc +91 -0
- package/.github/copilot-instructions.md +83 -0
- package/AGENTS.md +97 -0
- package/README.md +247 -78
- package/datasource-funifier-docs/knowledge/guides/aggregates.md +152 -152
- package/datasource-funifier-docs/knowledge/guides/database-access.md +132 -132
- package/datasource-funifier-docs/knowledge/guides/java-entities.md +373 -373
- package/datasource-funifier-docs/knowledge/guides/java-libraries.md +330 -330
- package/datasource-funifier-docs/knowledge/guides/java-managers.md +509 -509
- package/datasource-funifier-docs/knowledge/guides/triggers-guide.md +271 -271
- package/datasource-funifier-docs/knowledge/index.md +121 -121
- package/datasource-funifier-docs/knowledge/modules/achievement.md +46 -46
- package/datasource-funifier-docs/knowledge/modules/action-log.md +88 -88
- package/datasource-funifier-docs/knowledge/modules/action.md +80 -80
- package/datasource-funifier-docs/knowledge/modules/auth.md +104 -104
- package/datasource-funifier-docs/knowledge/modules/avatar.md +28 -28
- package/datasource-funifier-docs/knowledge/modules/backup.md +40 -40
- package/datasource-funifier-docs/knowledge/modules/challenge.md +91 -91
- package/datasource-funifier-docs/knowledge/modules/compact.md +40 -40
- package/datasource-funifier-docs/knowledge/modules/competition.md +149 -149
- package/datasource-funifier-docs/knowledge/modules/crossword.md +41 -41
- package/datasource-funifier-docs/knowledge/modules/csv-data.md +30 -30
- package/datasource-funifier-docs/knowledge/modules/custom-object.md +53 -53
- package/datasource-funifier-docs/knowledge/modules/database.md +241 -241
- package/datasource-funifier-docs/knowledge/modules/folder.md +111 -111
- package/datasource-funifier-docs/knowledge/modules/kpi-formulas.md +23 -23
- package/datasource-funifier-docs/knowledge/modules/lastmile.md +45 -45
- package/datasource-funifier-docs/knowledge/modules/leaderboard.md +98 -98
- package/datasource-funifier-docs/knowledge/modules/level.md +83 -83
- package/datasource-funifier-docs/knowledge/modules/lottery.md +112 -112
- package/datasource-funifier-docs/knowledge/modules/marketplace.md +27 -27
- package/datasource-funifier-docs/knowledge/modules/mystery.md +82 -82
- package/datasource-funifier-docs/knowledge/modules/notification.md +40 -40
- package/datasource-funifier-docs/knowledge/modules/patterns.md +1096 -1096
- package/datasource-funifier-docs/knowledge/modules/player.md +101 -101
- package/datasource-funifier-docs/knowledge/modules/point.md +67 -67
- package/datasource-funifier-docs/knowledge/modules/public.md +253 -253
- package/datasource-funifier-docs/knowledge/modules/question.md +136 -136
- package/datasource-funifier-docs/knowledge/modules/quiz.md +163 -163
- package/datasource-funifier-docs/knowledge/modules/scheduler.md +58 -58
- package/datasource-funifier-docs/knowledge/modules/security.md +169 -169
- package/datasource-funifier-docs/knowledge/modules/staging.md +28 -28
- package/datasource-funifier-docs/knowledge/modules/static-repo.md +41 -41
- package/datasource-funifier-docs/knowledge/modules/story.md +42 -42
- package/datasource-funifier-docs/knowledge/modules/studio-page.md +180 -180
- package/datasource-funifier-docs/knowledge/modules/swap.md +132 -132
- package/datasource-funifier-docs/knowledge/modules/team.md +75 -75
- package/datasource-funifier-docs/knowledge/modules/trigger.md +189 -189
- package/datasource-funifier-docs/knowledge/modules/upload.md +155 -155
- package/datasource-funifier-docs/knowledge/modules/virtual-good.md +99 -99
- package/datasource-funifier-docs/knowledge/modules/webhook.md +41 -41
- package/datasource-funifier-docs/knowledge/modules/websocket.md +41 -41
- package/datasource-funifier-docs/knowledge/modules/widget.md +42 -42
- package/datasource-funifier-docs/process-gtm-saas.md +143 -143
- package/datasource-funifier-docs/process-instagram.md +88 -88
- package/datasource-funifier-docs/process.md +1826 -1826
- package/datasource-funifier-docs/readme.md +132 -132
- package/dist/cli/config-writers.js +11 -11
- package/dist/mcp/bundle.js +82 -77
- package/package.json +70 -67
- package/skills/funifier-create-aggregate/SKILL.md +126 -126
- package/skills/funifier-create-custom-page/SKILL.md +126 -126
- package/skills/funifier-create-scheduler/SKILL.md +126 -126
- package/skills/funifier-create-trigger/SKILL.md +127 -127
|
@@ -1,509 +1,509 @@
|
|
|
1
|
-
# Java Managers — Referência
|
|
2
|
-
|
|
3
|
-
Os managers são a forma principal de interagir com a plataforma Funifier dentro de **triggers**, **schedulers** e **public endpoints**. Todos estão disponíveis através do objeto `manager` (instância de `ManagerFactory`).
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Como Aceder
|
|
8
|
-
|
|
9
|
-
```java
|
|
10
|
-
// Dentro de triggers, schedulers e public endpoints:
|
|
11
|
-
manager.getPlayerManager().findById("john");
|
|
12
|
-
manager.getActionManager().track(actionLog);
|
|
13
|
-
manager.getJongoConnection().getCollection("player");
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## PlayerManager
|
|
19
|
-
|
|
20
|
-
Gestão de jogadores (CRUD, busca, atributos, roles).
|
|
21
|
-
|
|
22
|
-
```java
|
|
23
|
-
// Acesso
|
|
24
|
-
PlayerManager pm = manager.getPlayerManager();
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
| Método | Retorno | Descrição |
|
|
28
|
-
|--------|---------|-----------|
|
|
29
|
-
| `findById(String id)` | Player | Busca jogador por ID |
|
|
30
|
-
| `findByAlternativeLogin(String login)` | Player | Busca por login alternativo |
|
|
31
|
-
| `findAll()` | Iterable\<Player\> | Lista todos os jogadores |
|
|
32
|
-
| `findRandom(String match, Jongo jongo)` | Player | Jogador aleatório que corresponda ao filtro |
|
|
33
|
-
| `findTotal()` | long | Total de jogadores cadastrados |
|
|
34
|
-
| `findTotalNewUsers(Date start, Date end)` | long | Novos jogadores no período |
|
|
35
|
-
| `insert(Player player)` | void | Cria ou atualiza jogador |
|
|
36
|
-
| `delete(String userId)` | void | Remove jogador e dados relacionados |
|
|
37
|
-
| `reset(String id)` | Player | Remove e recria jogador (zera progresso) |
|
|
38
|
-
| `updateProfileImage(String player, String imageUrl)` | void | Atualiza imagem de perfil |
|
|
39
|
-
| `insertRole(String role, String player)` | Map | Atribui role ao jogador |
|
|
40
|
-
| `removeRole(String role, String player)` | Map | Remove role do jogador |
|
|
41
|
-
| `findPrincipalByUserId(String id)` | Principal | Busca principal por user ID |
|
|
42
|
-
| `findPrincipalByUserOrTeamId(String id)` | Principal | Busca principal por user ou team ID |
|
|
43
|
-
|
|
44
|
-
**Exemplos:**
|
|
45
|
-
|
|
46
|
-
```java
|
|
47
|
-
// Buscar jogador
|
|
48
|
-
Player p = manager.getPlayerManager().findById("john");
|
|
49
|
-
String name = p.name;
|
|
50
|
-
String email = p.email;
|
|
51
|
-
Map extra = p.extra; // campos customizados
|
|
52
|
-
|
|
53
|
-
// Criar jogador
|
|
54
|
-
Player newPlayer = new Player();
|
|
55
|
-
newPlayer._id = "maria";
|
|
56
|
-
newPlayer.name = "Maria Silva";
|
|
57
|
-
newPlayer.email = "maria@email.com";
|
|
58
|
-
newPlayer.extra = new HashMap();
|
|
59
|
-
newPlayer.extra.put("department", "Sales");
|
|
60
|
-
manager.getPlayerManager().insert(newPlayer);
|
|
61
|
-
|
|
62
|
-
// Contar jogadores
|
|
63
|
-
long total = manager.getPlayerManager().findTotal();
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## ActionManager
|
|
69
|
-
|
|
70
|
-
Registro e gestão de ações executadas pelos jogadores.
|
|
71
|
-
|
|
72
|
-
```java
|
|
73
|
-
ActionManager am = manager.getActionManager();
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
| Método | Retorno | Descrição |
|
|
77
|
-
|--------|---------|-----------|
|
|
78
|
-
| `track(ActionLog action)` | void | Registra ação (assíncrono) |
|
|
79
|
-
| `trackSynchonous(ActionLog action)` | List\<Achievement\> | Registra ação e retorna conquistas (síncrono) |
|
|
80
|
-
| `trackWithRestrictions(ActionLog log, String async)` | Map | Registra com validações ("sync" ou "async") |
|
|
81
|
-
| `findActionById(String id)` | Action | Busca definição de ação |
|
|
82
|
-
| `findActionByIdOrName(String idOrName)` | Action | Busca por ID ou nome |
|
|
83
|
-
| `findAllActions()` | Iterable\<Action\> | Lista todas as ações |
|
|
84
|
-
| `addAction(Action action)` | void | Cria definição de ação |
|
|
85
|
-
| `updateAction(Action action)` | void | Atualiza definição de ação |
|
|
86
|
-
| `deleteAction(String id)` | void | Remove definição de ação |
|
|
87
|
-
| `findActionLogById(String id)` | ActionLog | Busca log de ação por ID |
|
|
88
|
-
| `deleteActionLog(String id)` | void | Remove log de ação |
|
|
89
|
-
| `addLog(ActionLog action)` | void | Insere log diretamente (sem processar regras) |
|
|
90
|
-
| `countActionLogsRegisteredByUser(String userId, String typeId)` | long | Conta logs do jogador |
|
|
91
|
-
| `countActionLogsRegisteredBetweenDatesByUser(String userId, String typeId, Date start, Date end)` | long | Conta logs no período |
|
|
92
|
-
| `findLatestActionLogDateRegisteredByUser(String userId, String typeId)` | Date | Data do último log |
|
|
93
|
-
|
|
94
|
-
**Exemplos:**
|
|
95
|
-
|
|
96
|
-
```java
|
|
97
|
-
// Registrar ação (assíncrono — mais rápido)
|
|
98
|
-
ActionLog log = new ActionLog();
|
|
99
|
-
log._id = Guid.newShortGuid();
|
|
100
|
-
log.actionId = "sell";
|
|
101
|
-
log.userId = "john";
|
|
102
|
-
log.time = new Date();
|
|
103
|
-
log.attributes = new HashMap();
|
|
104
|
-
log.attributes.put("product", "book");
|
|
105
|
-
log.attributes.put("price", 120);
|
|
106
|
-
manager.getActionManager().track(log);
|
|
107
|
-
|
|
108
|
-
// Registrar ação (síncrono — retorna conquistas)
|
|
109
|
-
List<Achievement> results = manager.getActionManager().trackSynchonous(log);
|
|
110
|
-
|
|
111
|
-
// Contar ações de um jogador
|
|
112
|
-
long total = manager.getActionManager().countActionLogsRegisteredByUser("john", "sell");
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## AchievementManager
|
|
118
|
-
|
|
119
|
-
Gestão de conquistas (pontos, desafios completados, compras, níveis).
|
|
120
|
-
|
|
121
|
-
```java
|
|
122
|
-
AchievementManager achm = manager.getAchievementManager();
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
| Método | Retorno | Descrição |
|
|
126
|
-
|--------|---------|-----------|
|
|
127
|
-
| `addAchievement(Achievement achievement)` | void | Adiciona conquista manualmente |
|
|
128
|
-
| `deleteAchievement(String id)` | void | Remove conquista |
|
|
129
|
-
| `findAchievement(String id, Jongo jongo)` | Achievement | Busca conquista por ID |
|
|
130
|
-
| `findPlayerStatus(String player)` | PlayerStatus | Status completo do jogador |
|
|
131
|
-
| `updatePlayerStatus(String player, Jongo jongo)` | List\<Achievement\> | Recalcula status |
|
|
132
|
-
| `sumTotalRewards(String player, int type, String item, Jongo jongo)` | long | Soma recompensas |
|
|
133
|
-
| `sumTotalPoints(String player, Jongo jongo)` | double | Soma total de pontos |
|
|
134
|
-
| `findLatestLevelAchieved(String player, Jongo jongo)` | Level | Nível atual do jogador |
|
|
135
|
-
| `evaluateRequirements(Requirement[] all, String player)` | boolean | Verifica se cumpre requisitos |
|
|
136
|
-
| `deductRequirements(Requirement[] all, String player)` | void | Deduz requisitos (pontos, etc.) |
|
|
137
|
-
| `fireAction(ActionLog trigger)` | List\<Achievement\> | Processa ação e concede conquistas |
|
|
138
|
-
|
|
139
|
-
**Tipos de Achievement:**
|
|
140
|
-
```java
|
|
141
|
-
Achievement.TYPE_POINT = 0; // Pontos
|
|
142
|
-
Achievement.TYPE_CHALLENGE = 1; // Desafio completado
|
|
143
|
-
Achievement.TYPE_VIRTUAL_GOOD = 2; // Item comprado
|
|
144
|
-
Achievement.TYPE_LEVEL = 3; // Nível alcançado
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
**Exemplos:**
|
|
148
|
-
|
|
149
|
-
```java
|
|
150
|
-
// Dar pontos manualmente
|
|
151
|
-
Achievement a = new Achievement();
|
|
152
|
-
a._id = Guid.newShortGuid();
|
|
153
|
-
a.player = "john";
|
|
154
|
-
a.total = 50;
|
|
155
|
-
a.type = Achievement.TYPE_POINT; // 0
|
|
156
|
-
a.item = "xp";
|
|
157
|
-
a.time = new Date();
|
|
158
|
-
manager.getAchievementManager().addAchievement(a);
|
|
159
|
-
|
|
160
|
-
// Consultar saldo de pontos
|
|
161
|
-
Jongo jongo = manager.getJongoConnection();
|
|
162
|
-
long xp = manager.getAchievementManager().sumTotalRewards("john", 0, "xp", jongo);
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
---
|
|
166
|
-
|
|
167
|
-
## CatalogManager
|
|
168
|
-
|
|
169
|
-
Gestão da loja virtual (catálogos, itens, compras).
|
|
170
|
-
|
|
171
|
-
```java
|
|
172
|
-
CatalogManager cm = manager.getCatalogManager();
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
| Método | Retorno | Descrição |
|
|
176
|
-
|--------|---------|-----------|
|
|
177
|
-
| `findItemById(String id)` | CatalogItem | Busca item por ID |
|
|
178
|
-
| `findAllItems()` | Iterable\<CatalogItem\> | Lista todos os itens |
|
|
179
|
-
| `findAllItemsByCatalogId(String catalogId)` | Iterable\<CatalogItem\> | Itens de um catálogo |
|
|
180
|
-
| `addItem(CatalogItem item)` | void | Adiciona item |
|
|
181
|
-
| `updateItem(CatalogItem item)` | void | Atualiza item |
|
|
182
|
-
| `deleteItem(String id)` | void | Remove item |
|
|
183
|
-
| `purchase(Achievement purchase, boolean async)` | Map | Processa compra |
|
|
184
|
-
| `undoPurchase(String id)` | void | Estorna compra |
|
|
185
|
-
| `findMissingRequirements(String player, String item)` | List\<Requirement\> | Requisitos faltantes |
|
|
186
|
-
| `findValidRandom(String player, String q)` | CatalogItem | Item aleatório válido para o jogador |
|
|
187
|
-
| `isValid(CatalogItem item, int total, String player, Principal principal, Jongo jongo)` | boolean | Valida se jogador pode comprar |
|
|
188
|
-
|
|
189
|
-
**Exemplos:**
|
|
190
|
-
|
|
191
|
-
```java
|
|
192
|
-
// Comprar item para jogador
|
|
193
|
-
Achievement purchase = new Achievement();
|
|
194
|
-
purchase._id = Guid.newShortGuid();
|
|
195
|
-
purchase.player = "john";
|
|
196
|
-
purchase.item = "DTj7lVn"; // ID do item
|
|
197
|
-
purchase.total = 1;
|
|
198
|
-
purchase.type = Achievement.TYPE_VIRTUAL_GOOD; // 2
|
|
199
|
-
purchase.time = new Date();
|
|
200
|
-
manager.getCatalogManager().purchase(purchase, true);
|
|
201
|
-
|
|
202
|
-
// Estornar compra
|
|
203
|
-
manager.getCatalogManager().undoPurchase("achievement_id");
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
---
|
|
207
|
-
|
|
208
|
-
## ChallengeManager
|
|
209
|
-
|
|
210
|
-
Gestão de desafios e missões.
|
|
211
|
-
|
|
212
|
-
```java
|
|
213
|
-
ChallengeManager chm = manager.getChallengeManager();
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
| Método | Retorno | Descrição |
|
|
217
|
-
|--------|---------|-----------|
|
|
218
|
-
| `findById(String id)` | Challenge | Busca desafio por ID |
|
|
219
|
-
| `findAll()` | Iterable\<Challenge\> | Lista todos os desafios |
|
|
220
|
-
| `add(Challenge challenge)` | void | Cria desafio |
|
|
221
|
-
| `update(Challenge challenge)` | void | Atualiza desafio |
|
|
222
|
-
| `delete(String id)` | void | Remove desafio |
|
|
223
|
-
| `describe(Challenge challenge, String lang)` | String | Descrição em linguagem natural |
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## LevelManager
|
|
228
|
-
|
|
229
|
-
Gestão de níveis de progressão.
|
|
230
|
-
|
|
231
|
-
```java
|
|
232
|
-
LevelManager lm = manager.getLevelManager();
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
| Método | Retorno | Descrição |
|
|
236
|
-
|--------|---------|-----------|
|
|
237
|
-
| `findById(String id)` | Level | Busca nível por ID |
|
|
238
|
-
| `findAll()` | Iterable\<Level\> | Lista todos os níveis |
|
|
239
|
-
| `findConfig()` | LevelConfig | Configuração de níveis |
|
|
240
|
-
| `findCurrentByPoints(int points)` | Level | Nível atual para X pontos |
|
|
241
|
-
| `findNextByPoints(int points)` | Level | Próximo nível para X pontos |
|
|
242
|
-
| `add(Level level)` | void | Cria nível |
|
|
243
|
-
| `update(Level level)` | void | Atualiza nível |
|
|
244
|
-
| `delete(String id)` | void | Remove nível |
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
|
-
## TeamManager
|
|
249
|
-
|
|
250
|
-
Gestão de equipes e grupos.
|
|
251
|
-
|
|
252
|
-
```java
|
|
253
|
-
TeamManager tm = manager.getTeamManager();
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
| Método | Retorno | Descrição |
|
|
257
|
-
|--------|---------|-----------|
|
|
258
|
-
| `findById(String id)` | Team | Busca equipe por ID |
|
|
259
|
-
| `findAll()` | Iterable\<Team\> | Lista todas as equipes |
|
|
260
|
-
| `add(Team team)` | void | Cria equipe |
|
|
261
|
-
| `update(Team team)` | void | Atualiza equipe |
|
|
262
|
-
| `delete(String id)` | void | Remove equipe |
|
|
263
|
-
| `linkUser(Team team, String userId)` | void | Vincula jogador à equipe |
|
|
264
|
-
| `removeUsers(String[] userIds, String teamId)` | void | Remove jogadores da equipe |
|
|
265
|
-
| `findUserIdsByTeamId(String teamId)` | List\<String\> | IDs dos membros |
|
|
266
|
-
| `findTeamIdsByUserId(String userId)` | List\<String\> | Equipes do jogador |
|
|
267
|
-
| `isUserOfTeam(String userId, String teamId)` | boolean | Verifica se é membro |
|
|
268
|
-
| `findByUserId(String userId)` | Iterable\<Team\> | Equipes do jogador |
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
|
-
## PointManager
|
|
273
|
-
|
|
274
|
-
Gestão de categorias de pontos e operações de crédito/débito.
|
|
275
|
-
|
|
276
|
-
```java
|
|
277
|
-
PointManager ptm = manager.getPointManager();
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
| Método | Retorno | Descrição |
|
|
281
|
-
|--------|---------|-----------|
|
|
282
|
-
| `findById(String id)` | PointCategory | Busca categoria por ID |
|
|
283
|
-
| `findAll()` | Iterable\<PointCategory\> | Lista categorias |
|
|
284
|
-
| `add(PointCategory point)` | void | Cria categoria |
|
|
285
|
-
| `update(PointCategory point)` | void | Atualiza categoria |
|
|
286
|
-
| `delete(String id)` | void | Remove categoria |
|
|
287
|
-
| `creditPoints(String categoryId, String userId, int total)` | void | Credita pontos |
|
|
288
|
-
| `debitPoints(String categoryId, String userId, int total)` | void | Debita pontos |
|
|
289
|
-
| `transferPoints(String fromUserId, int total, String categoryId, String toUserId)` | void | Transfere pontos entre jogadores |
|
|
290
|
-
| `findByUserId(String userId)` | Iterable\<Point\> | Pontos do jogador |
|
|
291
|
-
|
|
292
|
-
**Exemplos:**
|
|
293
|
-
|
|
294
|
-
```java
|
|
295
|
-
// Creditar pontos
|
|
296
|
-
manager.getPointManager().creditPoints("xp", "john", 100);
|
|
297
|
-
|
|
298
|
-
// Transferir pontos entre jogadores
|
|
299
|
-
manager.getPointManager().transferPoints("john", 50, "coins", "maria");
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
---
|
|
303
|
-
|
|
304
|
-
## LotteryManager
|
|
305
|
-
|
|
306
|
-
Gestão de sorteios e rifas.
|
|
307
|
-
|
|
308
|
-
```java
|
|
309
|
-
LotteryManager lotm = manager.getLotteryManager();
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
| Método | Retorno | Descrição |
|
|
313
|
-
|--------|---------|-----------|
|
|
314
|
-
| `find(String id)` | Lottery | Busca sorteio por ID |
|
|
315
|
-
| `findAll()` | Iterable\<Lottery\> | Lista todos os sorteios |
|
|
316
|
-
| `insert(Lottery lottery)` | void | Cria ou atualiza sorteio |
|
|
317
|
-
| `delete(String id)` | void | Remove sorteio |
|
|
318
|
-
| `insertTicket(LotteryTicket ticket)` | void | Adiciona ticket ao sorteio |
|
|
319
|
-
| `deleteTicket(String id)` | void | Remove ticket |
|
|
320
|
-
| `execute(String id)` | Iterable\<LotteryTicket\> | Executa sorteio |
|
|
321
|
-
| `undoExecute(String id)` | void | Estorna sorteio |
|
|
322
|
-
| `findParticipants(String lottery)` | Iterable\<Participant\> | Participantes do sorteio |
|
|
323
|
-
| `checkRestrictions(String lottery, String player)` | List\<String\> | Verifica restrições |
|
|
324
|
-
|
|
325
|
-
---
|
|
326
|
-
|
|
327
|
-
## CompetitionManager
|
|
328
|
-
|
|
329
|
-
Gestão de competições entre jogadores.
|
|
330
|
-
|
|
331
|
-
```java
|
|
332
|
-
CompetitionManager comp = manager.getCompetitionManager();
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
| Método | Retorno | Descrição |
|
|
336
|
-
|--------|---------|-----------|
|
|
337
|
-
| `find(String id)` | Competition | Busca competição por ID |
|
|
338
|
-
| `insert(Competition competition)` | void | Cria ou atualiza competição |
|
|
339
|
-
| `delete(String id)` | void | Remove competição |
|
|
340
|
-
| `insertJoin(CompetitionJoin join)` | Map | Inscreve jogador |
|
|
341
|
-
| `deleteJoin(CompetitionJoin join)` | void | Remove inscrição |
|
|
342
|
-
| `execute(String id)` | List\<Achievement\> | Executa e premia vencedores |
|
|
343
|
-
| `undoExecute(String id)` | void | Estorna execução |
|
|
344
|
-
| `findLeaders(String id, String range)` | Map | Ranking da competição |
|
|
345
|
-
|
|
346
|
-
---
|
|
347
|
-
|
|
348
|
-
## MysteryBoxManager
|
|
349
|
-
|
|
350
|
-
Gestão de caixas surpresa.
|
|
351
|
-
|
|
352
|
-
```java
|
|
353
|
-
MysteryBoxManager mb = manager.getMysteryBoxManager();
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
| Método | Retorno | Descrição |
|
|
357
|
-
|--------|---------|-----------|
|
|
358
|
-
| `find(String id)` | MysteryBox | Busca caixa por ID |
|
|
359
|
-
| `findAll()` | Iterable\<MysteryBox\> | Lista todas as caixas |
|
|
360
|
-
| `insert(MysteryBox mystery)` | void | Cria ou atualiza caixa |
|
|
361
|
-
| `delete(String id)` | void | Remove caixa |
|
|
362
|
-
| `execute(String id, String player)` | MysteryResult | Abre caixa para jogador |
|
|
363
|
-
| `undoExecute(String achievementId)` | void | Estorna abertura |
|
|
364
|
-
|
|
365
|
-
---
|
|
366
|
-
|
|
367
|
-
## QuestionManager
|
|
368
|
-
|
|
369
|
-
Gestão de perguntas e respostas.
|
|
370
|
-
|
|
371
|
-
```java
|
|
372
|
-
QuestionManager qm = manager.getQuestionManager();
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
| Método | Retorno | Descrição |
|
|
376
|
-
|--------|---------|-----------|
|
|
377
|
-
| `find(String id)` | Question | Busca pergunta por ID |
|
|
378
|
-
| `insert(Question question)` | List\<String\> | Cria pergunta |
|
|
379
|
-
| `delete(String id)` | void | Remove pergunta |
|
|
380
|
-
| `insertLog(QuestionLog log, String async)` | Map | Registra resposta ("sync"/"async") |
|
|
381
|
-
| `deleteLog(String id)` | void | Remove resposta |
|
|
382
|
-
| `findRandomNotAnsweredForPlayer(String player, String q, String answered_min, String answered_max)` | Question | Pergunta aleatória não respondida |
|
|
383
|
-
|
|
384
|
-
---
|
|
385
|
-
|
|
386
|
-
## QuizManager
|
|
387
|
-
|
|
388
|
-
Gestão de questionários completos.
|
|
389
|
-
|
|
390
|
-
```java
|
|
391
|
-
QuizManager quizm = manager.getQuizManager();
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
| Método | Retorno | Descrição |
|
|
395
|
-
|--------|---------|-----------|
|
|
396
|
-
| `find(String id)` | Quiz | Busca quiz por ID |
|
|
397
|
-
| `insert(Quiz quiz)` | void | Cria ou atualiza quiz |
|
|
398
|
-
| `delete(String id)` | void | Remove quiz |
|
|
399
|
-
| `startLog(QuizLog log)` | Map | Inicia tentativa |
|
|
400
|
-
| `finishLog(String id, String async)` | Map | Finaliza e calcula pontuação |
|
|
401
|
-
| `deleteLog(String id)` | void | Remove tentativa |
|
|
402
|
-
|
|
403
|
-
---
|
|
404
|
-
|
|
405
|
-
## LeaderBoardManager
|
|
406
|
-
|
|
407
|
-
Gestão de rankings e classificações.
|
|
408
|
-
|
|
409
|
-
```java
|
|
410
|
-
LeaderBoardManager lb = manager.getLeaderBoardManager();
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
| Método | Retorno | Descrição |
|
|
414
|
-
|--------|---------|-----------|
|
|
415
|
-
| `findById(String id)` | LeaderBoard_V2 | Busca leaderboard por ID |
|
|
416
|
-
| `findAll()` | Iterable\<LeaderBoard_V2\> | Lista todos os leaderboards |
|
|
417
|
-
| `addLeaderboard(LeaderBoard_V2 board)` | void | Cria ou atualiza leaderboard |
|
|
418
|
-
| `delete(String id)` | void | Remove leaderboard |
|
|
419
|
-
|
|
420
|
-
---
|
|
421
|
-
|
|
422
|
-
## NotificationManager
|
|
423
|
-
|
|
424
|
-
Envio de notificações para jogadores.
|
|
425
|
-
|
|
426
|
-
```java
|
|
427
|
-
NotificationManager nm = manager.getNotificationManager();
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
| Método | Retorno | Descrição |
|
|
431
|
-
|--------|---------|-----------|
|
|
432
|
-
| `send(Notification notification)` | void | Envia notificação |
|
|
433
|
-
| `sendPrivate(Notification notification)` | void | Envia notificação privada |
|
|
434
|
-
| `sendPublic(Notification notification)` | void | Envia notificação pública |
|
|
435
|
-
| `receiveNotification(String userId)` | List\<Notification\> | Recebe notificações do jogador |
|
|
436
|
-
| `deleteByPlayer(String player)` | void | Remove notificações do jogador |
|
|
437
|
-
| `totalUnreadPrivateMessages(String player, String published_min, String published_max)` | long | Total de não lidas |
|
|
438
|
-
|
|
439
|
-
**Exemplos:**
|
|
440
|
-
|
|
441
|
-
```java
|
|
442
|
-
// Enviar notificação
|
|
443
|
-
Notification n = new Notification();
|
|
444
|
-
n._id = Guid.newShortGuid();
|
|
445
|
-
n.player = "john";
|
|
446
|
-
n.title = "Parabéns!";
|
|
447
|
-
n.message = "Você completou o desafio!";
|
|
448
|
-
n.time = new Date();
|
|
449
|
-
manager.getNotificationManager().send(n);
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
---
|
|
453
|
-
|
|
454
|
-
## SwapManager
|
|
455
|
-
|
|
456
|
-
Gestão de trocas entre jogadores.
|
|
457
|
-
|
|
458
|
-
```java
|
|
459
|
-
SwapManager sm = manager.getSwapManager();
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
| Método | Retorno | Descrição |
|
|
463
|
-
|--------|---------|-----------|
|
|
464
|
-
| `find(String id)` | Swap | Busca troca por ID |
|
|
465
|
-
| `insert(Swap swap, String author)` | Map | Cria oferta de troca |
|
|
466
|
-
| `delete(String id)` | Map | Remove troca |
|
|
467
|
-
| `buyerAcquire(String id, String buyer, String author, Map extra)` | Map | Comprador aceita |
|
|
468
|
-
| `sellerReceive(String id)` | Map | Vendedor recebe |
|
|
469
|
-
| `counterOfferInsert(SwapCounterOffer offer, String author)` | Map | Cria contra-oferta |
|
|
470
|
-
|
|
471
|
-
---
|
|
472
|
-
|
|
473
|
-
## Acesso Direto ao Banco (Jongo)
|
|
474
|
-
|
|
475
|
-
Além dos managers, é possível acessar o MongoDB diretamente via Jongo.
|
|
476
|
-
|
|
477
|
-
```java
|
|
478
|
-
// Obter conexão
|
|
479
|
-
Jongo jongo = manager.getJongoConnection();
|
|
480
|
-
|
|
481
|
-
// Salvar documento
|
|
482
|
-
jongo.getCollection("email__c").save(documento);
|
|
483
|
-
|
|
484
|
-
// Buscar documento
|
|
485
|
-
Object result = jongo.getCollection("player")
|
|
486
|
-
.findOne("{_id: 'john'}").as(Map.class);
|
|
487
|
-
|
|
488
|
-
// Buscar com parâmetros
|
|
489
|
-
Object result = jongo.getCollection("product__c")
|
|
490
|
-
.findOne("{_id: #}", productId).as(Object.class);
|
|
491
|
-
|
|
492
|
-
// Listar com filtro
|
|
493
|
-
Iterable<Map> items = jongo.getCollection("action_log")
|
|
494
|
-
.find("{userId: #, actionId: #}", "john", "sell")
|
|
495
|
-
.as(Map.class);
|
|
496
|
-
|
|
497
|
-
// Deletar
|
|
498
|
-
jongo.getCollection("car__c").remove("{_id: 'car001'}");
|
|
499
|
-
|
|
500
|
-
// Aggregate
|
|
501
|
-
Iterable<Map> result = jongo.getCollection("achievement")
|
|
502
|
-
.aggregate("{$match: {type: 0, item: 'xp'}}")
|
|
503
|
-
.and("{$group: {_id: '$player', total: {$sum: '$total'}}}")
|
|
504
|
-
.and("{$sort: {total: -1}}")
|
|
505
|
-
.and("{$limit: 10}")
|
|
506
|
-
.as(Map.class);
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
> **Referência completa:** consulte `guides/database-access.md` para mais detalhes sobre acesso ao banco de dados.
|
|
1
|
+
# Java Managers — Referência
|
|
2
|
+
|
|
3
|
+
Os managers são a forma principal de interagir com a plataforma Funifier dentro de **triggers**, **schedulers** e **public endpoints**. Todos estão disponíveis através do objeto `manager` (instância de `ManagerFactory`).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Como Aceder
|
|
8
|
+
|
|
9
|
+
```java
|
|
10
|
+
// Dentro de triggers, schedulers e public endpoints:
|
|
11
|
+
manager.getPlayerManager().findById("john");
|
|
12
|
+
manager.getActionManager().track(actionLog);
|
|
13
|
+
manager.getJongoConnection().getCollection("player");
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## PlayerManager
|
|
19
|
+
|
|
20
|
+
Gestão de jogadores (CRUD, busca, atributos, roles).
|
|
21
|
+
|
|
22
|
+
```java
|
|
23
|
+
// Acesso
|
|
24
|
+
PlayerManager pm = manager.getPlayerManager();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| Método | Retorno | Descrição |
|
|
28
|
+
|--------|---------|-----------|
|
|
29
|
+
| `findById(String id)` | Player | Busca jogador por ID |
|
|
30
|
+
| `findByAlternativeLogin(String login)` | Player | Busca por login alternativo |
|
|
31
|
+
| `findAll()` | Iterable\<Player\> | Lista todos os jogadores |
|
|
32
|
+
| `findRandom(String match, Jongo jongo)` | Player | Jogador aleatório que corresponda ao filtro |
|
|
33
|
+
| `findTotal()` | long | Total de jogadores cadastrados |
|
|
34
|
+
| `findTotalNewUsers(Date start, Date end)` | long | Novos jogadores no período |
|
|
35
|
+
| `insert(Player player)` | void | Cria ou atualiza jogador |
|
|
36
|
+
| `delete(String userId)` | void | Remove jogador e dados relacionados |
|
|
37
|
+
| `reset(String id)` | Player | Remove e recria jogador (zera progresso) |
|
|
38
|
+
| `updateProfileImage(String player, String imageUrl)` | void | Atualiza imagem de perfil |
|
|
39
|
+
| `insertRole(String role, String player)` | Map | Atribui role ao jogador |
|
|
40
|
+
| `removeRole(String role, String player)` | Map | Remove role do jogador |
|
|
41
|
+
| `findPrincipalByUserId(String id)` | Principal | Busca principal por user ID |
|
|
42
|
+
| `findPrincipalByUserOrTeamId(String id)` | Principal | Busca principal por user ou team ID |
|
|
43
|
+
|
|
44
|
+
**Exemplos:**
|
|
45
|
+
|
|
46
|
+
```java
|
|
47
|
+
// Buscar jogador
|
|
48
|
+
Player p = manager.getPlayerManager().findById("john");
|
|
49
|
+
String name = p.name;
|
|
50
|
+
String email = p.email;
|
|
51
|
+
Map extra = p.extra; // campos customizados
|
|
52
|
+
|
|
53
|
+
// Criar jogador
|
|
54
|
+
Player newPlayer = new Player();
|
|
55
|
+
newPlayer._id = "maria";
|
|
56
|
+
newPlayer.name = "Maria Silva";
|
|
57
|
+
newPlayer.email = "maria@email.com";
|
|
58
|
+
newPlayer.extra = new HashMap();
|
|
59
|
+
newPlayer.extra.put("department", "Sales");
|
|
60
|
+
manager.getPlayerManager().insert(newPlayer);
|
|
61
|
+
|
|
62
|
+
// Contar jogadores
|
|
63
|
+
long total = manager.getPlayerManager().findTotal();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## ActionManager
|
|
69
|
+
|
|
70
|
+
Registro e gestão de ações executadas pelos jogadores.
|
|
71
|
+
|
|
72
|
+
```java
|
|
73
|
+
ActionManager am = manager.getActionManager();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
| Método | Retorno | Descrição |
|
|
77
|
+
|--------|---------|-----------|
|
|
78
|
+
| `track(ActionLog action)` | void | Registra ação (assíncrono) |
|
|
79
|
+
| `trackSynchonous(ActionLog action)` | List\<Achievement\> | Registra ação e retorna conquistas (síncrono) |
|
|
80
|
+
| `trackWithRestrictions(ActionLog log, String async)` | Map | Registra com validações ("sync" ou "async") |
|
|
81
|
+
| `findActionById(String id)` | Action | Busca definição de ação |
|
|
82
|
+
| `findActionByIdOrName(String idOrName)` | Action | Busca por ID ou nome |
|
|
83
|
+
| `findAllActions()` | Iterable\<Action\> | Lista todas as ações |
|
|
84
|
+
| `addAction(Action action)` | void | Cria definição de ação |
|
|
85
|
+
| `updateAction(Action action)` | void | Atualiza definição de ação |
|
|
86
|
+
| `deleteAction(String id)` | void | Remove definição de ação |
|
|
87
|
+
| `findActionLogById(String id)` | ActionLog | Busca log de ação por ID |
|
|
88
|
+
| `deleteActionLog(String id)` | void | Remove log de ação |
|
|
89
|
+
| `addLog(ActionLog action)` | void | Insere log diretamente (sem processar regras) |
|
|
90
|
+
| `countActionLogsRegisteredByUser(String userId, String typeId)` | long | Conta logs do jogador |
|
|
91
|
+
| `countActionLogsRegisteredBetweenDatesByUser(String userId, String typeId, Date start, Date end)` | long | Conta logs no período |
|
|
92
|
+
| `findLatestActionLogDateRegisteredByUser(String userId, String typeId)` | Date | Data do último log |
|
|
93
|
+
|
|
94
|
+
**Exemplos:**
|
|
95
|
+
|
|
96
|
+
```java
|
|
97
|
+
// Registrar ação (assíncrono — mais rápido)
|
|
98
|
+
ActionLog log = new ActionLog();
|
|
99
|
+
log._id = Guid.newShortGuid();
|
|
100
|
+
log.actionId = "sell";
|
|
101
|
+
log.userId = "john";
|
|
102
|
+
log.time = new Date();
|
|
103
|
+
log.attributes = new HashMap();
|
|
104
|
+
log.attributes.put("product", "book");
|
|
105
|
+
log.attributes.put("price", 120);
|
|
106
|
+
manager.getActionManager().track(log);
|
|
107
|
+
|
|
108
|
+
// Registrar ação (síncrono — retorna conquistas)
|
|
109
|
+
List<Achievement> results = manager.getActionManager().trackSynchonous(log);
|
|
110
|
+
|
|
111
|
+
// Contar ações de um jogador
|
|
112
|
+
long total = manager.getActionManager().countActionLogsRegisteredByUser("john", "sell");
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## AchievementManager
|
|
118
|
+
|
|
119
|
+
Gestão de conquistas (pontos, desafios completados, compras, níveis).
|
|
120
|
+
|
|
121
|
+
```java
|
|
122
|
+
AchievementManager achm = manager.getAchievementManager();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
| Método | Retorno | Descrição |
|
|
126
|
+
|--------|---------|-----------|
|
|
127
|
+
| `addAchievement(Achievement achievement)` | void | Adiciona conquista manualmente |
|
|
128
|
+
| `deleteAchievement(String id)` | void | Remove conquista |
|
|
129
|
+
| `findAchievement(String id, Jongo jongo)` | Achievement | Busca conquista por ID |
|
|
130
|
+
| `findPlayerStatus(String player)` | PlayerStatus | Status completo do jogador |
|
|
131
|
+
| `updatePlayerStatus(String player, Jongo jongo)` | List\<Achievement\> | Recalcula status |
|
|
132
|
+
| `sumTotalRewards(String player, int type, String item, Jongo jongo)` | long | Soma recompensas |
|
|
133
|
+
| `sumTotalPoints(String player, Jongo jongo)` | double | Soma total de pontos |
|
|
134
|
+
| `findLatestLevelAchieved(String player, Jongo jongo)` | Level | Nível atual do jogador |
|
|
135
|
+
| `evaluateRequirements(Requirement[] all, String player)` | boolean | Verifica se cumpre requisitos |
|
|
136
|
+
| `deductRequirements(Requirement[] all, String player)` | void | Deduz requisitos (pontos, etc.) |
|
|
137
|
+
| `fireAction(ActionLog trigger)` | List\<Achievement\> | Processa ação e concede conquistas |
|
|
138
|
+
|
|
139
|
+
**Tipos de Achievement:**
|
|
140
|
+
```java
|
|
141
|
+
Achievement.TYPE_POINT = 0; // Pontos
|
|
142
|
+
Achievement.TYPE_CHALLENGE = 1; // Desafio completado
|
|
143
|
+
Achievement.TYPE_VIRTUAL_GOOD = 2; // Item comprado
|
|
144
|
+
Achievement.TYPE_LEVEL = 3; // Nível alcançado
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Exemplos:**
|
|
148
|
+
|
|
149
|
+
```java
|
|
150
|
+
// Dar pontos manualmente
|
|
151
|
+
Achievement a = new Achievement();
|
|
152
|
+
a._id = Guid.newShortGuid();
|
|
153
|
+
a.player = "john";
|
|
154
|
+
a.total = 50;
|
|
155
|
+
a.type = Achievement.TYPE_POINT; // 0
|
|
156
|
+
a.item = "xp";
|
|
157
|
+
a.time = new Date();
|
|
158
|
+
manager.getAchievementManager().addAchievement(a);
|
|
159
|
+
|
|
160
|
+
// Consultar saldo de pontos
|
|
161
|
+
Jongo jongo = manager.getJongoConnection();
|
|
162
|
+
long xp = manager.getAchievementManager().sumTotalRewards("john", 0, "xp", jongo);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## CatalogManager
|
|
168
|
+
|
|
169
|
+
Gestão da loja virtual (catálogos, itens, compras).
|
|
170
|
+
|
|
171
|
+
```java
|
|
172
|
+
CatalogManager cm = manager.getCatalogManager();
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
| Método | Retorno | Descrição |
|
|
176
|
+
|--------|---------|-----------|
|
|
177
|
+
| `findItemById(String id)` | CatalogItem | Busca item por ID |
|
|
178
|
+
| `findAllItems()` | Iterable\<CatalogItem\> | Lista todos os itens |
|
|
179
|
+
| `findAllItemsByCatalogId(String catalogId)` | Iterable\<CatalogItem\> | Itens de um catálogo |
|
|
180
|
+
| `addItem(CatalogItem item)` | void | Adiciona item |
|
|
181
|
+
| `updateItem(CatalogItem item)` | void | Atualiza item |
|
|
182
|
+
| `deleteItem(String id)` | void | Remove item |
|
|
183
|
+
| `purchase(Achievement purchase, boolean async)` | Map | Processa compra |
|
|
184
|
+
| `undoPurchase(String id)` | void | Estorna compra |
|
|
185
|
+
| `findMissingRequirements(String player, String item)` | List\<Requirement\> | Requisitos faltantes |
|
|
186
|
+
| `findValidRandom(String player, String q)` | CatalogItem | Item aleatório válido para o jogador |
|
|
187
|
+
| `isValid(CatalogItem item, int total, String player, Principal principal, Jongo jongo)` | boolean | Valida se jogador pode comprar |
|
|
188
|
+
|
|
189
|
+
**Exemplos:**
|
|
190
|
+
|
|
191
|
+
```java
|
|
192
|
+
// Comprar item para jogador
|
|
193
|
+
Achievement purchase = new Achievement();
|
|
194
|
+
purchase._id = Guid.newShortGuid();
|
|
195
|
+
purchase.player = "john";
|
|
196
|
+
purchase.item = "DTj7lVn"; // ID do item
|
|
197
|
+
purchase.total = 1;
|
|
198
|
+
purchase.type = Achievement.TYPE_VIRTUAL_GOOD; // 2
|
|
199
|
+
purchase.time = new Date();
|
|
200
|
+
manager.getCatalogManager().purchase(purchase, true);
|
|
201
|
+
|
|
202
|
+
// Estornar compra
|
|
203
|
+
manager.getCatalogManager().undoPurchase("achievement_id");
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## ChallengeManager
|
|
209
|
+
|
|
210
|
+
Gestão de desafios e missões.
|
|
211
|
+
|
|
212
|
+
```java
|
|
213
|
+
ChallengeManager chm = manager.getChallengeManager();
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
| Método | Retorno | Descrição |
|
|
217
|
+
|--------|---------|-----------|
|
|
218
|
+
| `findById(String id)` | Challenge | Busca desafio por ID |
|
|
219
|
+
| `findAll()` | Iterable\<Challenge\> | Lista todos os desafios |
|
|
220
|
+
| `add(Challenge challenge)` | void | Cria desafio |
|
|
221
|
+
| `update(Challenge challenge)` | void | Atualiza desafio |
|
|
222
|
+
| `delete(String id)` | void | Remove desafio |
|
|
223
|
+
| `describe(Challenge challenge, String lang)` | String | Descrição em linguagem natural |
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## LevelManager
|
|
228
|
+
|
|
229
|
+
Gestão de níveis de progressão.
|
|
230
|
+
|
|
231
|
+
```java
|
|
232
|
+
LevelManager lm = manager.getLevelManager();
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
| Método | Retorno | Descrição |
|
|
236
|
+
|--------|---------|-----------|
|
|
237
|
+
| `findById(String id)` | Level | Busca nível por ID |
|
|
238
|
+
| `findAll()` | Iterable\<Level\> | Lista todos os níveis |
|
|
239
|
+
| `findConfig()` | LevelConfig | Configuração de níveis |
|
|
240
|
+
| `findCurrentByPoints(int points)` | Level | Nível atual para X pontos |
|
|
241
|
+
| `findNextByPoints(int points)` | Level | Próximo nível para X pontos |
|
|
242
|
+
| `add(Level level)` | void | Cria nível |
|
|
243
|
+
| `update(Level level)` | void | Atualiza nível |
|
|
244
|
+
| `delete(String id)` | void | Remove nível |
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## TeamManager
|
|
249
|
+
|
|
250
|
+
Gestão de equipes e grupos.
|
|
251
|
+
|
|
252
|
+
```java
|
|
253
|
+
TeamManager tm = manager.getTeamManager();
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
| Método | Retorno | Descrição |
|
|
257
|
+
|--------|---------|-----------|
|
|
258
|
+
| `findById(String id)` | Team | Busca equipe por ID |
|
|
259
|
+
| `findAll()` | Iterable\<Team\> | Lista todas as equipes |
|
|
260
|
+
| `add(Team team)` | void | Cria equipe |
|
|
261
|
+
| `update(Team team)` | void | Atualiza equipe |
|
|
262
|
+
| `delete(String id)` | void | Remove equipe |
|
|
263
|
+
| `linkUser(Team team, String userId)` | void | Vincula jogador à equipe |
|
|
264
|
+
| `removeUsers(String[] userIds, String teamId)` | void | Remove jogadores da equipe |
|
|
265
|
+
| `findUserIdsByTeamId(String teamId)` | List\<String\> | IDs dos membros |
|
|
266
|
+
| `findTeamIdsByUserId(String userId)` | List\<String\> | Equipes do jogador |
|
|
267
|
+
| `isUserOfTeam(String userId, String teamId)` | boolean | Verifica se é membro |
|
|
268
|
+
| `findByUserId(String userId)` | Iterable\<Team\> | Equipes do jogador |
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## PointManager
|
|
273
|
+
|
|
274
|
+
Gestão de categorias de pontos e operações de crédito/débito.
|
|
275
|
+
|
|
276
|
+
```java
|
|
277
|
+
PointManager ptm = manager.getPointManager();
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
| Método | Retorno | Descrição |
|
|
281
|
+
|--------|---------|-----------|
|
|
282
|
+
| `findById(String id)` | PointCategory | Busca categoria por ID |
|
|
283
|
+
| `findAll()` | Iterable\<PointCategory\> | Lista categorias |
|
|
284
|
+
| `add(PointCategory point)` | void | Cria categoria |
|
|
285
|
+
| `update(PointCategory point)` | void | Atualiza categoria |
|
|
286
|
+
| `delete(String id)` | void | Remove categoria |
|
|
287
|
+
| `creditPoints(String categoryId, String userId, int total)` | void | Credita pontos |
|
|
288
|
+
| `debitPoints(String categoryId, String userId, int total)` | void | Debita pontos |
|
|
289
|
+
| `transferPoints(String fromUserId, int total, String categoryId, String toUserId)` | void | Transfere pontos entre jogadores |
|
|
290
|
+
| `findByUserId(String userId)` | Iterable\<Point\> | Pontos do jogador |
|
|
291
|
+
|
|
292
|
+
**Exemplos:**
|
|
293
|
+
|
|
294
|
+
```java
|
|
295
|
+
// Creditar pontos
|
|
296
|
+
manager.getPointManager().creditPoints("xp", "john", 100);
|
|
297
|
+
|
|
298
|
+
// Transferir pontos entre jogadores
|
|
299
|
+
manager.getPointManager().transferPoints("john", 50, "coins", "maria");
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## LotteryManager
|
|
305
|
+
|
|
306
|
+
Gestão de sorteios e rifas.
|
|
307
|
+
|
|
308
|
+
```java
|
|
309
|
+
LotteryManager lotm = manager.getLotteryManager();
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
| Método | Retorno | Descrição |
|
|
313
|
+
|--------|---------|-----------|
|
|
314
|
+
| `find(String id)` | Lottery | Busca sorteio por ID |
|
|
315
|
+
| `findAll()` | Iterable\<Lottery\> | Lista todos os sorteios |
|
|
316
|
+
| `insert(Lottery lottery)` | void | Cria ou atualiza sorteio |
|
|
317
|
+
| `delete(String id)` | void | Remove sorteio |
|
|
318
|
+
| `insertTicket(LotteryTicket ticket)` | void | Adiciona ticket ao sorteio |
|
|
319
|
+
| `deleteTicket(String id)` | void | Remove ticket |
|
|
320
|
+
| `execute(String id)` | Iterable\<LotteryTicket\> | Executa sorteio |
|
|
321
|
+
| `undoExecute(String id)` | void | Estorna sorteio |
|
|
322
|
+
| `findParticipants(String lottery)` | Iterable\<Participant\> | Participantes do sorteio |
|
|
323
|
+
| `checkRestrictions(String lottery, String player)` | List\<String\> | Verifica restrições |
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## CompetitionManager
|
|
328
|
+
|
|
329
|
+
Gestão de competições entre jogadores.
|
|
330
|
+
|
|
331
|
+
```java
|
|
332
|
+
CompetitionManager comp = manager.getCompetitionManager();
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
| Método | Retorno | Descrição |
|
|
336
|
+
|--------|---------|-----------|
|
|
337
|
+
| `find(String id)` | Competition | Busca competição por ID |
|
|
338
|
+
| `insert(Competition competition)` | void | Cria ou atualiza competição |
|
|
339
|
+
| `delete(String id)` | void | Remove competição |
|
|
340
|
+
| `insertJoin(CompetitionJoin join)` | Map | Inscreve jogador |
|
|
341
|
+
| `deleteJoin(CompetitionJoin join)` | void | Remove inscrição |
|
|
342
|
+
| `execute(String id)` | List\<Achievement\> | Executa e premia vencedores |
|
|
343
|
+
| `undoExecute(String id)` | void | Estorna execução |
|
|
344
|
+
| `findLeaders(String id, String range)` | Map | Ranking da competição |
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## MysteryBoxManager
|
|
349
|
+
|
|
350
|
+
Gestão de caixas surpresa.
|
|
351
|
+
|
|
352
|
+
```java
|
|
353
|
+
MysteryBoxManager mb = manager.getMysteryBoxManager();
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
| Método | Retorno | Descrição |
|
|
357
|
+
|--------|---------|-----------|
|
|
358
|
+
| `find(String id)` | MysteryBox | Busca caixa por ID |
|
|
359
|
+
| `findAll()` | Iterable\<MysteryBox\> | Lista todas as caixas |
|
|
360
|
+
| `insert(MysteryBox mystery)` | void | Cria ou atualiza caixa |
|
|
361
|
+
| `delete(String id)` | void | Remove caixa |
|
|
362
|
+
| `execute(String id, String player)` | MysteryResult | Abre caixa para jogador |
|
|
363
|
+
| `undoExecute(String achievementId)` | void | Estorna abertura |
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## QuestionManager
|
|
368
|
+
|
|
369
|
+
Gestão de perguntas e respostas.
|
|
370
|
+
|
|
371
|
+
```java
|
|
372
|
+
QuestionManager qm = manager.getQuestionManager();
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
| Método | Retorno | Descrição |
|
|
376
|
+
|--------|---------|-----------|
|
|
377
|
+
| `find(String id)` | Question | Busca pergunta por ID |
|
|
378
|
+
| `insert(Question question)` | List\<String\> | Cria pergunta |
|
|
379
|
+
| `delete(String id)` | void | Remove pergunta |
|
|
380
|
+
| `insertLog(QuestionLog log, String async)` | Map | Registra resposta ("sync"/"async") |
|
|
381
|
+
| `deleteLog(String id)` | void | Remove resposta |
|
|
382
|
+
| `findRandomNotAnsweredForPlayer(String player, String q, String answered_min, String answered_max)` | Question | Pergunta aleatória não respondida |
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## QuizManager
|
|
387
|
+
|
|
388
|
+
Gestão de questionários completos.
|
|
389
|
+
|
|
390
|
+
```java
|
|
391
|
+
QuizManager quizm = manager.getQuizManager();
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
| Método | Retorno | Descrição |
|
|
395
|
+
|--------|---------|-----------|
|
|
396
|
+
| `find(String id)` | Quiz | Busca quiz por ID |
|
|
397
|
+
| `insert(Quiz quiz)` | void | Cria ou atualiza quiz |
|
|
398
|
+
| `delete(String id)` | void | Remove quiz |
|
|
399
|
+
| `startLog(QuizLog log)` | Map | Inicia tentativa |
|
|
400
|
+
| `finishLog(String id, String async)` | Map | Finaliza e calcula pontuação |
|
|
401
|
+
| `deleteLog(String id)` | void | Remove tentativa |
|
|
402
|
+
|
|
403
|
+
---
|
|
404
|
+
|
|
405
|
+
## LeaderBoardManager
|
|
406
|
+
|
|
407
|
+
Gestão de rankings e classificações.
|
|
408
|
+
|
|
409
|
+
```java
|
|
410
|
+
LeaderBoardManager lb = manager.getLeaderBoardManager();
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
| Método | Retorno | Descrição |
|
|
414
|
+
|--------|---------|-----------|
|
|
415
|
+
| `findById(String id)` | LeaderBoard_V2 | Busca leaderboard por ID |
|
|
416
|
+
| `findAll()` | Iterable\<LeaderBoard_V2\> | Lista todos os leaderboards |
|
|
417
|
+
| `addLeaderboard(LeaderBoard_V2 board)` | void | Cria ou atualiza leaderboard |
|
|
418
|
+
| `delete(String id)` | void | Remove leaderboard |
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## NotificationManager
|
|
423
|
+
|
|
424
|
+
Envio de notificações para jogadores.
|
|
425
|
+
|
|
426
|
+
```java
|
|
427
|
+
NotificationManager nm = manager.getNotificationManager();
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
| Método | Retorno | Descrição |
|
|
431
|
+
|--------|---------|-----------|
|
|
432
|
+
| `send(Notification notification)` | void | Envia notificação |
|
|
433
|
+
| `sendPrivate(Notification notification)` | void | Envia notificação privada |
|
|
434
|
+
| `sendPublic(Notification notification)` | void | Envia notificação pública |
|
|
435
|
+
| `receiveNotification(String userId)` | List\<Notification\> | Recebe notificações do jogador |
|
|
436
|
+
| `deleteByPlayer(String player)` | void | Remove notificações do jogador |
|
|
437
|
+
| `totalUnreadPrivateMessages(String player, String published_min, String published_max)` | long | Total de não lidas |
|
|
438
|
+
|
|
439
|
+
**Exemplos:**
|
|
440
|
+
|
|
441
|
+
```java
|
|
442
|
+
// Enviar notificação
|
|
443
|
+
Notification n = new Notification();
|
|
444
|
+
n._id = Guid.newShortGuid();
|
|
445
|
+
n.player = "john";
|
|
446
|
+
n.title = "Parabéns!";
|
|
447
|
+
n.message = "Você completou o desafio!";
|
|
448
|
+
n.time = new Date();
|
|
449
|
+
manager.getNotificationManager().send(n);
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## SwapManager
|
|
455
|
+
|
|
456
|
+
Gestão de trocas entre jogadores.
|
|
457
|
+
|
|
458
|
+
```java
|
|
459
|
+
SwapManager sm = manager.getSwapManager();
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
| Método | Retorno | Descrição |
|
|
463
|
+
|--------|---------|-----------|
|
|
464
|
+
| `find(String id)` | Swap | Busca troca por ID |
|
|
465
|
+
| `insert(Swap swap, String author)` | Map | Cria oferta de troca |
|
|
466
|
+
| `delete(String id)` | Map | Remove troca |
|
|
467
|
+
| `buyerAcquire(String id, String buyer, String author, Map extra)` | Map | Comprador aceita |
|
|
468
|
+
| `sellerReceive(String id)` | Map | Vendedor recebe |
|
|
469
|
+
| `counterOfferInsert(SwapCounterOffer offer, String author)` | Map | Cria contra-oferta |
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
## Acesso Direto ao Banco (Jongo)
|
|
474
|
+
|
|
475
|
+
Além dos managers, é possível acessar o MongoDB diretamente via Jongo.
|
|
476
|
+
|
|
477
|
+
```java
|
|
478
|
+
// Obter conexão
|
|
479
|
+
Jongo jongo = manager.getJongoConnection();
|
|
480
|
+
|
|
481
|
+
// Salvar documento
|
|
482
|
+
jongo.getCollection("email__c").save(documento);
|
|
483
|
+
|
|
484
|
+
// Buscar documento
|
|
485
|
+
Object result = jongo.getCollection("player")
|
|
486
|
+
.findOne("{_id: 'john'}").as(Map.class);
|
|
487
|
+
|
|
488
|
+
// Buscar com parâmetros
|
|
489
|
+
Object result = jongo.getCollection("product__c")
|
|
490
|
+
.findOne("{_id: #}", productId).as(Object.class);
|
|
491
|
+
|
|
492
|
+
// Listar com filtro
|
|
493
|
+
Iterable<Map> items = jongo.getCollection("action_log")
|
|
494
|
+
.find("{userId: #, actionId: #}", "john", "sell")
|
|
495
|
+
.as(Map.class);
|
|
496
|
+
|
|
497
|
+
// Deletar
|
|
498
|
+
jongo.getCollection("car__c").remove("{_id: 'car001'}");
|
|
499
|
+
|
|
500
|
+
// Aggregate
|
|
501
|
+
Iterable<Map> result = jongo.getCollection("achievement")
|
|
502
|
+
.aggregate("{$match: {type: 0, item: 'xp'}}")
|
|
503
|
+
.and("{$group: {_id: '$player', total: {$sum: '$total'}}}")
|
|
504
|
+
.and("{$sort: {total: -1}}")
|
|
505
|
+
.and("{$limit: 10}")
|
|
506
|
+
.as(Map.class);
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
> **Referência completa:** consulte `guides/database-access.md` para mais detalhes sobre acesso ao banco de dados.
|