Skip to content

Commit 26610fb

Browse files
committed
initial project import
0 parents  commit 26610fb

File tree

472 files changed

+37854
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

472 files changed

+37854
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.iml
2+
.idea/
3+
target/
4+
.settings/
5+
.classpath
6+
.project
7+
.externalToolBuilders/

LICENSE.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The MIT License (MIT)
2+
=====================
3+
4+
Copyright © `2016` `Ben Romberg`
5+
6+
Permission is hereby granted, free of charge, to any person
7+
obtaining a copy of this software and associated documentation
8+
files (the “Software”), to deal in the Software without
9+
restriction, including without limitation the rights to use,
10+
copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
OTHER DEALINGS IN THE SOFTWARE.

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Installation notes:
2+
3+
* adjust `configuration.example` as instructed in the file and rename it to `configuration.json`
4+
* install Maven and build the project using `mvn clean package`
5+
* copy `cordonbleu-main-0.0.1-SNAPSHOT.jar` from `cordonbleu-main/target` into this folder
6+
* install MongoDB
7+
* run `run.sh`
8+
* view `http://localhost:8080/`
9+
10+
Development notes:
11+
12+
* install node + npm
13+
* `cd` to `cordonbleu-main`
14+
* `npm install`
15+
* `npm install webpack -g`
16+
* `webpack --watch` will auto-compile everything under `src/main/resources/webpack` and bundle it into `target/classes/static/js/bundle.js` which is referenced in `index.html`
17+
* start the `CordonBleuApplication` dropwizard server using `server src/test/resources/config-test.json` as arguments
18+
19+
Now you can develop, all changes in `src/main/resources/webpack` will be bundled automatically upon file-save. `CordonBleuApplication` needs to be restarted if backend changes are made though.
20+
21+
SASS features used:
22+
23+
* Variables: Declare using `$var: 123px;` just like you would usually declare a CSS property.
24+
* Calculations: Combined with variables, you can calculate CSS properties, e.g. `top: $navbarHeight + 3px;`.
25+
26+
ES6 features used:
27+
28+
* Arrow functions: Same semantics as in Java just with `=>` instead of `->`. The `this` variable is not affected in contrast to `function`s and keeps its scope, which is very handy in most scenarios.
29+
* Just like in Java, singular expressions don't need to be wrapped by `{}` and `return` can be omitted. If you want to return an object as a singular expression, wrap it with `()`.
30+
* Spread operator `...array` to expand an array into the arguments of a function.
31+
32+
ES6 features that sound useful (but haven't been used yet):
33+
34+
* Using `const` and `let` instead of `var`.
35+
* Appending `,` to the last element of an array or object. It's allowed by ES6 and is easier to refactor this way.
36+
* Using backticks ``` to reference variables within strings. Quit using `+` for string concatenation.
37+
* Default parameter values.
38+
* Code Style guidelines for ES6 with some interesting ideas: https://github.com/elierotenberg/coding-styles/blob/master/es6.md

configuration.example

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// this is a dropwizard service configuration, details see http://www.dropwizard.io/0.8.2/docs/manual/configuration.html
2+
// remove all "comments", adjust values appropriately and rename this file to configuration.json
3+
{
4+
"server": {
5+
"type": "simple",
6+
"rootPath": "/api/*",
7+
"applicationContextPath": "/",
8+
"adminContextPath": "/admin",
9+
"connector": {
10+
"type": "http",
11+
"port": 8080
12+
}
13+
},
14+
"codeRepositoryFolder": "/path/to/code-repository", // needs to be changed to an existing path
15+
"mongoUrl": "mongodb://localhost:27017/", // needs to point to a running MongoDB instance
16+
"highlightingTimeoutInMilliseconds": 1000, // increase if many commits don't get highlighted
17+
"commitNotificationConsiderationAmount": 100, // increase if you need the notifications to consider more commits
18+
"emailServer": {
19+
"host": "smtp.server", // change email settings
20+
"port": 587,
21+
"username": "smtp_user",
22+
"password": "smtp_password",
23+
"rootPath": "http://example.com" // the web url that will be used in emails
24+
},
25+
"sshPrivateKeyPassword": "something-entirely-random" // private keys will be encrypted using this password,
26+
// so they're not available in "plain-text" in the database
27+
}

cordonbleu-data/pom.xml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.benromberg.cordonbleu</groupId>
6+
<artifactId>cordonbleu-parent</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<relativePath>../cordonbleu-parent/pom.xml</relativePath>
9+
</parent>
10+
<artifactId>cordonbleu-data</artifactId>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.mongodb</groupId>
15+
<artifactId>mongo-java-driver</artifactId>
16+
<version>3.2.0</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.mongojack</groupId>
20+
<artifactId>mongojack</artifactId>
21+
<version>2.6.0</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.github.mongobee</groupId>
25+
<artifactId>mongobee</artifactId>
26+
<version>0.11</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.google.guava</groupId>
30+
<artifactId>guava</artifactId>
31+
<version>18.0</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>com.fasterxml.jackson.datatype</groupId>
36+
<artifactId>jackson-datatype-jdk8</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.fasterxml.jackson.module</groupId>
40+
<artifactId>jackson-module-parameter-names</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>com.benromberg.cordonbleu</groupId>
45+
<artifactId>cordonbleu-util</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.benromberg.cordonbleu</groupId>
49+
<artifactId>cordonbleu-util</artifactId>
50+
<type>test-jar</type>
51+
<scope>test</scope>
52+
</dependency>
53+
</dependencies>
54+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.benromberg.cordonbleu.data.dao;
2+
3+
import static com.benromberg.cordonbleu.util.ExceptionUtil.convertException;
4+
5+
import java.util.Optional;
6+
import java.util.concurrent.TimeUnit;
7+
8+
import org.mongojack.DBQuery.Query;
9+
import org.mongojack.DBUpdate;
10+
11+
import com.benromberg.cordonbleu.data.model.Entity;
12+
import com.benromberg.cordonbleu.data.util.jackson.CustomModule;
13+
import com.benromberg.cordonbleu.data.validation.Validation;
14+
import com.google.common.cache.Cache;
15+
import com.google.common.cache.CacheBuilder;
16+
17+
public class CacheDao<I, E extends Entity<I>> extends MongoDao<I, E> {
18+
private final Cache<I, Optional<E>> cache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build();
19+
20+
public CacheDao(DatabaseWithMigration database, Class<I> idClass, Class<E> elementClass, String collectionName,
21+
Validation<? super E> validation) {
22+
super(database, idClass, elementClass, collectionName, new CustomModule(), validation);
23+
}
24+
25+
public CacheDao(DatabaseWithMigration database, Class<I> idClass, Class<E> elementClass, String collectionName,
26+
CustomModule customModule) {
27+
super(database, idClass, elementClass, collectionName, customModule);
28+
}
29+
30+
public CacheDao(DatabaseWithMigration database, Class<I> idClass, Class<E> elementClass, String collectionName,
31+
CustomModule customModule, Validation<? super E> validation) {
32+
super(database, idClass, elementClass, collectionName, customModule, validation);
33+
}
34+
35+
@Override
36+
public Optional<E> findById(I id) {
37+
return convertException(() -> cache.get(id, () -> super.findById(id)));
38+
}
39+
40+
@Override
41+
public void insert(E element) {
42+
super.insert(element);
43+
cache.invalidate(element.getId());
44+
}
45+
46+
@Override
47+
protected Optional<E> update(Query find, DBUpdate.Builder update) {
48+
Optional<E> changed = super.update(find, update);
49+
if (changed.isPresent()) {
50+
cache.put(changed.get().getId(), changed);
51+
}
52+
return changed;
53+
}
54+
55+
@Override
56+
protected Optional<E> update(I id, DBUpdate.Builder update) {
57+
Optional<E> changed = super.update(id, update);
58+
cache.put(id, changed);
59+
return changed;
60+
}
61+
62+
@Override
63+
public boolean remove(I id) {
64+
boolean hasRemoved = super.remove(id);
65+
cache.invalidate(id);
66+
return hasRemoved;
67+
}
68+
69+
public void invalidate(I id) {
70+
cache.invalidate(id);
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.benromberg.cordonbleu.data.dao;
2+
3+
import static com.benromberg.cordonbleu.data.util.jackson.CaseInsensitiveUniqueValue.uniqueProperty;
4+
import static java.util.Arrays.asList;
5+
import com.benromberg.cordonbleu.util.CollectionUtil;
6+
7+
import java.util.List;
8+
import java.util.Optional;
9+
10+
import javax.inject.Inject;
11+
import javax.inject.Singleton;
12+
13+
import org.mongojack.DBQuery;
14+
import org.mongojack.DBQuery.Query;
15+
import org.mongojack.DBUpdate;
16+
17+
import com.benromberg.cordonbleu.data.model.CodeRepositoryMetadata;
18+
import com.benromberg.cordonbleu.data.model.NamedEntity;
19+
import com.benromberg.cordonbleu.data.model.RepositoryFlag;
20+
import com.benromberg.cordonbleu.data.model.Team;
21+
import com.benromberg.cordonbleu.data.util.jackson.CustomModule;
22+
import com.benromberg.cordonbleu.data.validation.NameValidation;
23+
24+
@Singleton
25+
public class CodeRepositoryMetadataDao extends CacheDao<String, CodeRepositoryMetadata> {
26+
@Inject
27+
public CodeRepositoryMetadataDao(DatabaseWithMigration db, NameValidation<NamedEntity> validation, TeamDao teamDao) {
28+
super(db, String.class, CodeRepositoryMetadata.class, "codeRepositoryMetadata", createCustomModule(teamDao),
29+
validation);
30+
createUniqueIndex(uniqueProperty(CodeRepositoryMetadata.NAME_PROPERTY), CodeRepositoryMetadata.TEAM_PROPERTY);
31+
}
32+
33+
private static CustomModule createCustomModule(TeamDao teamDao) {
34+
CustomModule customModule = new CustomModule();
35+
customModule.addSerializer(Team.class, new EntitySerializer<>());
36+
customModule.addDeserializer(Team.class, new EntityDeserializer<>(teamDao));
37+
return customModule;
38+
}
39+
40+
public List<CodeRepositoryMetadata> findByIds(List<String> ids) {
41+
return find(DBQuery.in(ID_PROPERTY, ids)).toArray();
42+
}
43+
44+
public List<CodeRepositoryMetadata> findActive() {
45+
return findByFlag(RepositoryFlag.REMOVE_ON_NEXT_UPDATE, false);
46+
}
47+
48+
private List<CodeRepositoryMetadata> findAndSortByName(Query query) {
49+
return CollectionUtil.sortCaseInsensitive(find(query).toArray(), CodeRepositoryMetadata::getName);
50+
}
51+
52+
public Optional<CodeRepositoryMetadata> updateFlag(String repositoryId, RepositoryFlag flag, boolean flagValue) {
53+
if (flagValue) {
54+
return update(repositoryId, DBUpdate.push(CodeRepositoryMetadata.FLAGS_PROPERTY, flag));
55+
}
56+
return update(repositoryId, DBUpdate.pull(CodeRepositoryMetadata.FLAGS_PROPERTY, flag));
57+
}
58+
59+
public List<CodeRepositoryMetadata> findByFlag(RepositoryFlag flag, boolean flagValue) {
60+
return findAndSortByName(queryByFlag(flag, flagValue));
61+
}
62+
63+
private Query queryByFlag(RepositoryFlag flag, boolean flagValue) {
64+
Query query = DBQuery.is(CodeRepositoryMetadata.FLAGS_PROPERTY, asList(flag));
65+
if (!flagValue) {
66+
query = DBQuery.nor(query);
67+
}
68+
return query;
69+
}
70+
71+
public List<CodeRepositoryMetadata> findByTeam(Team team) {
72+
Query activeQuery = queryByFlag(RepositoryFlag.REMOVE_ON_NEXT_UPDATE, false);
73+
return findAndSortByName(activeQuery.is(CodeRepositoryMetadata.TEAM_PROPERTY, team));
74+
}
75+
}

0 commit comments

Comments
 (0)