Skip to content

Commit 6b1382a

Browse files
committed
Added MongoStorageHandler
1 parent 433db82 commit 6b1382a

File tree

8 files changed

+151
-73
lines changed

8 files changed

+151
-73
lines changed

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build
2-
on: [push]
2+
on: [ push ]
33
jobs:
44
publish:
55
runs-on: ubuntu-latest

CODE_OF_CONDUCT.md

+43-69
Original file line numberDiff line numberDiff line change
@@ -2,124 +2,98 @@
22

33
## Our Pledge
44

5-
We as members, contributors, and leaders pledge to make participation in our
6-
community a harassment-free experience for everyone, regardless of age, body
7-
size, visible or invisible disability, ethnicity, sex characteristics, gender
8-
identity and expression, level of experience, education, socio-economic status,
9-
nationality, personal appearance, race, religion, or sexual identity
10-
and orientation.
5+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for
6+
everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity
7+
and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion,
8+
or sexual identity and orientation.
119

12-
We pledge to act and interact in ways that contribute to an open, welcoming,
13-
diverse, inclusive, and healthy community.
10+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
1411

1512
## Our Standards
1613

17-
Examples of behavior that contributes to a positive environment for our
18-
community include:
14+
Examples of behavior that contributes to a positive environment for our community include:
1915

2016
* Demonstrating empathy and kindness toward other people
2117
* Being respectful of differing opinions, viewpoints, and experiences
2218
* Giving and gracefully accepting constructive feedback
23-
* Accepting responsibility and apologizing to those affected by our mistakes,
24-
and learning from the experience
25-
* Focusing on what is best not just for us as individuals, but for the
26-
overall community
19+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
20+
* Focusing on what is best not just for us as individuals, but for the overall community
2721

2822
Examples of unacceptable behavior include:
2923

30-
* The use of sexualized language or imagery, and sexual attention or
31-
advances of any kind
24+
* The use of sexualized language or imagery, and sexual attention or advances of any kind
3225
* Trolling, insulting or derogatory comments, and personal or political attacks
3326
* Public or private harassment
34-
* Publishing others' private information, such as a physical or email
35-
address, without their explicit permission
36-
* Other conduct which could reasonably be considered inappropriate in a
37-
professional setting
27+
* Publishing others' private information, such as a physical or email address, without their explicit permission
28+
* Other conduct which could reasonably be considered inappropriate in a professional setting
3829

3930
## Enforcement Responsibilities
4031

41-
Community leaders are responsible for clarifying and enforcing our standards of
42-
acceptable behavior and will take appropriate and fair corrective action in
43-
response to any behavior that they deem inappropriate, threatening, offensive,
32+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take
33+
appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive,
4434
or harmful.
4535

46-
Community leaders have the right and responsibility to remove, edit, or reject
47-
comments, commits, code, wiki edits, issues, and other contributions that are
48-
not aligned to this Code of Conduct, and will communicate reasons for moderation
49-
decisions when appropriate.
36+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits,
37+
issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for
38+
moderation decisions when appropriate.
5039

5140
## Scope
5241

53-
This Code of Conduct applies within all community spaces, and also applies when
54-
an individual is officially representing the community in public spaces.
55-
Examples of representing our community include using an official e-mail address,
56-
posting via an official social media account, or acting as an appointed
57-
representative at an online or offline event.
42+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing
43+
the community in public spaces. Examples of representing our community include using an official e-mail address, posting
44+
via an official social media account, or acting as an appointed representative at an online or offline event.
5845

5946
## Enforcement
6047

61-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62-
reported to the community leaders responsible for enforcement at
63-
64-
All complaints will be reviewed and investigated promptly and fairly.
48+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible
49+
for enforcement at [email protected]. All complaints will be reviewed and investigated promptly and fairly.
6550

66-
All community leaders are obligated to respect the privacy and security of the
67-
reporter of any incident.
51+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
6852

6953
## Enforcement Guidelines
7054

71-
Community leaders will follow these Community Impact Guidelines in determining
72-
the consequences for any action they deem in violation of this Code of Conduct:
55+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem
56+
in violation of this Code of Conduct:
7357

7458
### 1. Correction
7559

76-
**Community Impact**: Use of inappropriate language or other behavior deemed
77-
unprofessional or unwelcome in the community.
60+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the
61+
community.
7862

79-
**Consequence**: A private, written warning from community leaders, providing
80-
clarity around the nature of the violation and an explanation of why the
81-
behavior was inappropriate. A public apology may be requested.
63+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation
64+
and an explanation of why the behavior was inappropriate. A public apology may be requested.
8265

8366
### 2. Warning
8467

85-
**Community Impact**: A violation through a single incident or series
86-
of actions.
68+
**Community Impact**: A violation through a single incident or series of actions.
8769

88-
**Consequence**: A warning with consequences for continued behavior. No
89-
interaction with the people involved, including unsolicited interaction with
90-
those enforcing the Code of Conduct, for a specified period of time. This
91-
includes avoiding interactions in community spaces as well as external channels
92-
like social media. Violating these terms may lead to a temporary or
93-
permanent ban.
70+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including
71+
unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding
72+
interactions in community spaces as well as external channels like social media. Violating these terms may lead to a
73+
temporary or permanent ban.
9474

9575
### 3. Temporary Ban
9676

97-
**Community Impact**: A serious violation of community standards, including
98-
sustained inappropriate behavior.
77+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
9978

100-
**Consequence**: A temporary ban from any sort of interaction or public
101-
communication with the community for a specified period of time. No public or
102-
private interaction with the people involved, including unsolicited interaction
103-
with those enforcing the Code of Conduct, is allowed during this period.
104-
Violating these terms may lead to a permanent ban.
79+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified
80+
period of time. No public or private interaction with the people involved, including unsolicited interaction with those
81+
enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
10582

10683
### 4. Permanent Ban
10784

108-
**Community Impact**: Demonstrating a pattern of violation of community
109-
standards, including sustained inappropriate behavior, harassment of an
110-
individual, or aggression toward or disparagement of classes of individuals.
85+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate
86+
behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
11187

112-
**Consequence**: A permanent ban from any sort of public interaction within
113-
the community.
88+
**Consequence**: A permanent ban from any sort of public interaction within the community.
11489

11590
## Attribution
11691

117-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118-
version 2.0, available at
92+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at
11993
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
12094

121-
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122-
enforcement ladder](https://github.com/mozilla/diversity).
95+
Community Impact Guidelines were inspired
96+
by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
12397

12498
[homepage]: https://www.contributor-covenant.org
12599

application/src/main/java/com/noahhusby/lib/application/config/Config.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
package com.noahhusby.lib.application.config;
2222

2323
import com.noahhusby.lib.application.config.provider.ConfigurationProvider;
24-
import com.noahhusby.lib.application.config.provider.JsonConfigurationProvider;
2524
import com.noahhusby.lib.application.config.provider.HoconConfigurationProvider;
25+
import com.noahhusby.lib.application.config.provider.JsonConfigurationProvider;
2626
import com.noahhusby.lib.application.config.provider.YamlConfigurationProvider;
2727
import lombok.AllArgsConstructor;
2828
import lombok.Getter;

application/src/main/java/com/noahhusby/lib/application/config/provider/HoconConfigurationProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private void writeProperties(BufferedWriter writer, Map<String, Property> proper
116116
}
117117
writer.write(indent + "]\n");
118118
} else {
119-
if(property.getValue().getValue() instanceof String) {
119+
if (property.getValue().getValue() instanceof String) {
120120
writer.write(indent + property.getKey() + " = \"" + property.getValue().getValue() + "\"\n\n");
121121
} else {
122122
writer.write(indent + property.getKey() + " = " + property.getValue().getValue() + "\n\n");

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ allprojects {
3131
mysqlVersion = "8.0.27"
3232
hikariVersion = "4.0.3"
3333
lombokVersion = "1.18.22"
34+
mongoVersion = "3.12.10"
3435
}
3536

3637
group "com.noahhusby.lib"

data/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ dependencies {
2323
compileOnly "com.google.code.gson:gson:$gsonVersion"
2424
compileOnly "com.google.guava:guava:$guavaVersion"
2525
compileOnly "com.zaxxer:HikariCP:$hikariVersion"
26+
compileOnly "org.mongodb:mongo-java-driver:$mongoVersion"
2627
}

data/src/main/java/com/noahhusby/lib/data/sql/Credentials.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MIT License
33
*
4-
* Copyright 2020-2021 noahhusby
4+
* Copyright 2020-2022 noahhusby
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
77
* files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright 2020-2021 noahhusby
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
7+
* files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
8+
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
9+
* is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
16+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
*
19+
*/
20+
21+
package com.noahhusby.lib.data.storage.handlers;
22+
23+
import com.google.gson.JsonArray;
24+
import com.google.gson.JsonObject;
25+
import com.mongodb.client.FindIterable;
26+
import com.mongodb.client.MongoCollection;
27+
import com.mongodb.client.model.changestream.ChangeStreamDocument;
28+
import com.mongodb.client.model.changestream.OperationType;
29+
import com.noahhusby.lib.data.storage.StorageUtil;
30+
import com.noahhusby.lib.data.storage.compare.ComparatorAction;
31+
import com.noahhusby.lib.data.storage.compare.CompareResult;
32+
import lombok.Getter;
33+
import lombok.RequiredArgsConstructor;
34+
import org.bson.Document;
35+
36+
import java.util.Map;
37+
import java.util.function.Consumer;
38+
39+
@RequiredArgsConstructor
40+
public class MongoStorageHandler extends StorageHandler {
41+
@Getter
42+
private final MongoCollection<Document> collection;
43+
44+
@Override
45+
public void save(CompareResult result) {
46+
try {
47+
if (result.isCleared()) {
48+
collection.deleteMany(new Document());
49+
}
50+
51+
for (Map.Entry<JsonObject, ComparatorAction> r : result.getComparedOutput().entrySet()) {
52+
JsonObject object = r.getKey();
53+
if (r.getValue() == ComparatorAction.REMOVE) {
54+
collection.deleteOne(new Document("_id", object.get(result.getKey()).getAsString()));
55+
}
56+
57+
if (r.getValue() == ComparatorAction.ADD) {
58+
Document document = Document.parse(StorageUtil.gson.toJson(object));
59+
if (result.getKey() != null) {
60+
document.append("_id", document.get(result.getKey()));
61+
}
62+
collection.insertOne(document);
63+
}
64+
65+
if (r.getValue() == ComparatorAction.UPDATE) {
66+
Document document = Document.parse(StorageUtil.gson.toJson(object));
67+
collection.replaceOne(new Document("_id", document.get(result.getKey())), document);
68+
}
69+
}
70+
71+
} catch (Exception e) {
72+
e.printStackTrace();
73+
}
74+
}
75+
76+
@Override
77+
public JsonArray load() {
78+
FindIterable<Document> documents = collection.find();
79+
JsonArray array = new JsonArray();
80+
for (Document document : documents) {
81+
array.add(StorageUtil.gson.toJsonTree(document));
82+
}
83+
return array;
84+
}
85+
86+
public void enableEventUpdates() {
87+
collection.watch().forEach((Consumer<? super ChangeStreamDocument<Document>>) x -> {
88+
if (x.getOperationType() == OperationType.INSERT || x.getOperationType() == OperationType.REPLACE || x.getOperationType() == OperationType.DELETE) {
89+
load();
90+
}
91+
});
92+
}
93+
94+
@Override
95+
public boolean isAvailable() {
96+
return true;
97+
}
98+
99+
@Override
100+
public void close() {
101+
}
102+
}

0 commit comments

Comments
 (0)