Skip to content

Commit f449b92

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/org/javawebstack/framework/WebApplication.java # src/main/java/org/javawebstack/framework/module/Module.java
2 parents 8839398 + 44294c0 commit f449b92

22 files changed

+224
-192
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*.iml
22
.idea
3-
target
3+
target
4+
5+
# IntelliJ Linux bug
6+
.fuse_*

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,8 @@ public class User extends Model {
9999

100100
- Docs: https://javawebstack.org/framework/
101101
- Example Project https://github.com/javawebstack/
102+
103+
## Community
104+
### JWS Modules
105+
- [JWS-GraphQL](https://github.com/x7airworker/JWS-GraphQL)
106+
### Projects built with JWS

src/main/java/org/javawebstack/framework/WebApplication.java

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public abstract class WebApplication {
4141
private final Map<String, Seeder> seeders = new HashMap<>();
4242
private final I18N translation = new I18N();
4343

44-
public WebApplication(){
44+
public WebApplication() {
4545
injector = new SimpleInjector();
4646
injector.setInstance(Injector.class, injector);
4747
injector.setInstance(Faker.class, faker);
@@ -60,27 +60,27 @@ public WebApplication(){
6060
injector.setInstance(Crypt.class, crypt);
6161

6262
modules.forEach(m -> m.setupConfig(this, config));
63-
if(config.get("database.driver", "none").equalsIgnoreCase("sqlite")){
63+
if (config.get("database.driver", "none").equalsIgnoreCase("sqlite")) {
6464
sql = new SQLite(config.get("database.file", "db.sqlite"));
65-
}else if(config.get("database.driver", "none").equalsIgnoreCase("mysql")){
65+
} else if (config.get("database.driver", "none").equalsIgnoreCase("mysql")) {
6666
sql = new MySQL(
6767
config.get("database.host", "localhost"),
6868
config.getInt("database.port", 3306),
6969
config.get("database.name", "app"),
7070
config.get("database.user", "root"),
7171
config.get("database.password", "")
7272
);
73-
}else{
73+
} else {
7474
sql = null;
7575
}
76-
if(sql != null){
76+
if (sql != null) {
7777
try {
78-
for(Module m : modules)
78+
for (Module m : modules)
7979
m.beforeSetupModels(this, sql);
8080
setupModels(sql);
81-
for(Module m : modules)
81+
for (Module m : modules)
8282
m.setupModels(this, sql);
83-
}catch (ORMConfigurationException ex){
83+
} catch (ORMConfigurationException ex) {
8484
ex.printStackTrace();
8585
}
8686
}
@@ -97,9 +97,9 @@ public WebApplication(){
9797
injector.inject(this);
9898
server.beforeInterceptor(new CORSPolicy(config.get("http.server.cors", "*")));
9999
server.beforeInterceptor(new MultipartPolicy(config.get("http.server.tmp", null)));
100-
if(config.isEnabled("http.server.json", true))
100+
if (config.isEnabled("http.server.json", true))
101101
server.responseTransformer(new JsonResponseTransformer().ignoreStrings());
102-
if(sql != null)
102+
if (sql != null)
103103
server.routeParamTransformer(modelBindParamTransformer);
104104
modules.forEach(m -> m.beforeSetupServer(this, server));
105105
setupServer(server);
@@ -128,62 +128,63 @@ public WebApplication(){
128128
);
129129
}
130130

131-
public Map<String, Seeder> getSeeders(){
131+
public Map<String, Seeder> getSeeders() {
132132
return seeders;
133133
}
134134

135-
public void addTranslation(Locale locale, ClassLoader classLoader, String resource){
136-
if(!resource.endsWith(".json"))
135+
public void addTranslation(Locale locale, ClassLoader classLoader, String resource) {
136+
if (!resource.endsWith(".json"))
137137
resource += ".json";
138138
try {
139139
AbstractElement element = AbstractElement.fromJson(IO.readTextResource(classLoader, resource));
140-
if(element.isObject())
140+
if (element.isObject())
141141
translation.add(locale, element.object());
142-
if(element.isArray())
142+
if (element.isArray())
143143
translation.add(locale, element.array());
144-
} catch (IOException ignored) {}
144+
} catch (IOException ignored) {
145+
}
145146
}
146147

147-
public void addTranslation(Locale locale, String resource){
148+
public void addTranslation(Locale locale, String resource) {
148149
addTranslation(locale, ClassLoader.getSystemClassLoader(), resource);
149150
}
150151

151-
public WebApplication addModule(Module module){
152+
public WebApplication addModule(Module module) {
152153
modules.add(module);
153154
return this;
154155
}
155156

156-
public WebApplication setModelBindTransformer(ModelBindTransformer transformer){
157+
public WebApplication setModelBindTransformer(ModelBindTransformer transformer) {
157158
modelBindParamTransformer.setTransformer(transformer);
158159
return this;
159160
}
160161

161-
public WebApplication setAccessorAttribName(String name){
162+
public WebApplication setAccessorAttribName(String name) {
162163
modelBindParamTransformer.setAccessorAttribName(name);
163164
return this;
164165
}
165166

166-
public void addSeeder(String name, Seeder... seeder){
167-
if(seeder.length == 0)
167+
public void addSeeder(String name, Seeder... seeder) {
168+
if (seeder.length == 0)
168169
return;
169-
for(Seeder seed : seeder)
170+
for (Seeder seed : seeder)
170171
injector.inject(seed);
171-
if(seeder.length > 1){
172+
if (seeder.length > 1) {
172173
addSeeder(name, new MergedSeeder(seeder));
173174
return;
174175
}
175176
seeders.put(name, seeder[0]);
176177
}
177178

178-
public Seeder getSeeder(String name){
179+
public Seeder getSeeder(String name) {
179180
return seeders.get(name);
180181
}
181182

182-
public Logger getLogger(){
183+
public Logger getLogger() {
183184
return logger;
184185
}
185186

186-
public void setLogger(Logger logger){
187+
public void setLogger(Logger logger) {
187188
this.logger = logger;
188189
}
189190

@@ -203,33 +204,37 @@ public Config getConfig() {
203204
return config;
204205
}
205206

206-
public Crypt getCrypt(){
207+
public Crypt getCrypt() {
207208
return crypt;
208209
}
209210

210-
public I18N getTranslation(){
211+
public I18N getTranslation() {
211212
return translation;
212213
}
213214

214-
protected void setupModules(){}
215+
protected void setupModules() {
216+
}
217+
215218
protected abstract void setupConfig(Config config);
216219
protected void setupInjection(Injector injector){}
217220
protected void setupSeeding(){}
218221
protected abstract void setupModels(SQL sql) throws ORMConfigurationException;
222+
219223
protected abstract void setupServer(HTTPServer server);
224+
220225
protected abstract void setupCommands(CommandSystem system);
221226

222-
public void run(String[] args){
223-
if(args == null)
227+
public void run(String[] args) {
228+
if (args == null)
224229
args = new String[]{"start"};
225230
try {
226231
commandSystem.run(args);
227-
}catch (Throwable t){
232+
} catch (Throwable t) {
228233
t.printStackTrace();
229234
}
230235
}
231236

232-
public void start(){
237+
public void start() {
233238
server.start();
234239
server.join();
235240
}

src/main/java/org/javawebstack/framework/bind/ModelBind.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
@Retention(RetentionPolicy.RUNTIME)
1010
public @interface ModelBind {
1111
String value();
12+
1213
String field() default "";
1314
}

src/main/java/org/javawebstack/framework/bind/ModelBindParamTransformer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ public class ModelBindParamTransformer extends DefaultRouteParamTransformer {
1212
private ModelBindTransformer transformer;
1313
private String accessorAttribName;
1414

15-
public ModelBindParamTransformer(){
15+
public ModelBindParamTransformer() {
1616
super();
1717
this.transformer = (exchange, repo, fieldName, source) -> repo.accessible(accessorAttribName == null ? null : exchange.attrib(accessorAttribName)).where(fieldName, source).first();
18-
for(Class<? extends Model> model : ORM.getModels()){
18+
for (Class<? extends Model> model : ORM.getModels()) {
1919
ModelBind[] binds = model.getDeclaredAnnotationsByType(ModelBind.class);
20-
if(binds.length == 0)
20+
if (binds.length == 0)
2121
continue;
2222
Repo<?> repo = Repo.get(model);
2323
String fieldName = binds[0].field().length() > 0 ? binds[0].field() : repo.getInfo().getIdField();
2424
Class<?> fieldType = repo.getInfo().getField(fieldName).getType();
2525
String parent = "string";
26-
if(fieldType.equals(UUID.class))
26+
if (fieldType.equals(UUID.class))
2727
parent = "uuid";
28-
if(fieldType.equals(Integer.class))
28+
if (fieldType.equals(Integer.class))
2929
parent = "i+";
30-
if(fieldType.equals(Long.class))
30+
if (fieldType.equals(Long.class))
3131
parent = "l+";
3232
extend(parent, binds[0].value(), (exchange, source) -> transformer.transform(exchange, repo, fieldName, source));
3333
}
3434
}
3535

36-
public void setTransformer(ModelBindTransformer transformer){
36+
public void setTransformer(ModelBindTransformer transformer) {
3737
this.transformer = transformer;
3838
}
3939

src/main/java/org/javawebstack/framework/command/CryptDecryptCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CryptDecryptCommand implements Command {
1515
Crypt crypt;
1616

1717
public CommandResult execute(CommandSystem commandSystem, List<String> args, Map<String, List<String>> params) {
18-
if(params.containsKey("l")){
18+
if (params.containsKey("l")) {
1919
System.out.println(crypt.decryptLaravel(args.size() > 0 ? args.get(0) : ""));
2020
return CommandResult.success();
2121
}

src/main/java/org/javawebstack/framework/command/CryptEncryptCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CryptEncryptCommand implements Command {
1515
Crypt crypt;
1616

1717
public CommandResult execute(CommandSystem commandSystem, List<String> args, Map<String, List<String>> params) {
18-
if(params.containsKey("l")){
18+
if (params.containsKey("l")) {
1919
System.out.println(crypt.encryptLaravel(args.size() > 0 ? args.get(0) : ""));
2020
return CommandResult.success();
2121
}

src/main/java/org/javawebstack/framework/command/DBMigrateCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public class DBMigrateCommand implements Command {
1616
private WebApplication app;
1717

1818
public CommandResult execute(CommandSystem commandSystem, List<String> args, Map<String, List<String>> params) {
19-
if(params.containsKey("a")){
20-
if(params.containsKey("d")){
19+
if (params.containsKey("a")) {
20+
if (params.containsKey("d")) {
2121
ORM.autoDrop();
2222
System.out.println("Dropped all tables!");
2323
return CommandResult.success();
2424
}
2525
ORM.autoMigrate(params.containsKey("f"));
26-
if(params.containsKey("s"))
26+
if (params.containsKey("s"))
2727
app.getSeeder("all").seed();
2828
System.out.println("Auto-Migration successful!");
2929
return CommandResult.success();

src/main/java/org/javawebstack/framework/command/DBSeedCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class DBSeedCommand implements Command {
1515
private WebApplication application;
1616

1717
public CommandResult execute(CommandSystem commandSystem, List<String> args, Map<String, List<String>> params) {
18-
if(args.size() == 0)
18+
if (args.size() == 0)
1919
return CommandResult.syntax("db seed [...seeds]");
20-
for(String name : args)
20+
for (String name : args)
2121
application.getSeeder(name).seed();
2222
System.out.println("Seeding done!");
2323
return CommandResult.success();

src/main/java/org/javawebstack/framework/command/GenerateKeyCommand.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ public CommandResult execute(CommandSystem commandSystem, List<String> args, Map
2020
lines = new String[0];
2121
}
2222
boolean found = false;
23-
for(int i=0; i<lines.length; i++){
24-
if(lines[i].startsWith("CRYPT_KEY=")){
25-
if(lines[i].length() > 10 && !params.containsKey("f"))
23+
for (int i = 0; i < lines.length; i++) {
24+
if (lines[i].startsWith("CRYPT_KEY=")) {
25+
if (lines[i].length() > 10 && !params.containsKey("f"))
2626
return CommandResult.error("You already have a key. You might loose all your encrypted data if you regenerate it! Use -f to do it anyway.");
2727
lines[i] = "CRYPT_KEY=" + Crypt.generateKey();
2828
found = true;
2929
break;
3030
}
3131
}
32-
if(!found){
32+
if (!found) {
3333
String[] newLines = new String[lines.length + 3];
3434
System.arraycopy(lines, 0, newLines, 0, lines.length);
35-
newLines[newLines.length-3] = "";
36-
newLines[newLines.length-2] = "# Encryption Key";
37-
newLines[newLines.length-1] = "CRYPT_KEY=" + Crypt.generateKey();
35+
newLines[newLines.length - 3] = "";
36+
newLines[newLines.length - 2] = "# Encryption Key";
37+
newLines[newLines.length - 1] = "CRYPT_KEY=" + Crypt.generateKey();
3838
lines = newLines;
3939
}
4040
try {

0 commit comments

Comments
 (0)