Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
e2d2dd18
Commit
e2d2dd18
authored
Nov 12, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stub ofseperate databases
parent
2e7589af
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
11 deletions
+71
-11
CTFApplication.java
.../java/com/telephoners/krakyournet/ctf/CTFApplication.java
+0
-2
DataConnector.java
...a/com/telephoners/krakyournet/ctf/core/DataConnector.java
+35
-0
DatabaseNameProvider.java
...elephoners/krakyournet/ctf/core/DatabaseNameProvider.java
+25
-0
ApplicationModule.java
...elephoners/krakyournet/ctf/modules/ApplicationModule.java
+6
-5
Repository.java
.../telephoners/krakyournet/ctf/repositories/Repository.java
+5
-4
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/CTFApplication.java
View file @
e2d2dd18
...
...
@@ -22,7 +22,6 @@ import io.dropwizard.auth.AuthValueFactoryProvider;
import
io.dropwizard.jersey.setup.JerseyEnvironment
;
import
io.dropwizard.setup.Bootstrap
;
import
io.dropwizard.setup.Environment
;
import
org.ektorp.CouchDbConnector
;
import
org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature
;
import
java.io.IOException
;
...
...
@@ -73,7 +72,6 @@ public class CTFApplication extends Application<ApplicationConfiguration>
{
injector
=
createInjector
(
applicationConfiguration
);
CouchDbConnector
connector
=
injector
.
getInstance
(
CouchDbConnector
.
class
);
Team
team
=
new
Team
();
team
.
setName
(
"asdf"
);
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/core/DataConnector.java
0 → 100644
View file @
e2d2dd18
package
com
.
telephoners
.
krakyournet
.
ctf
.
core
;
import
com.google.inject.Inject
;
import
org.ektorp.CouchDbConnector
;
import
org.ektorp.CouchDbInstance
;
import
org.ektorp.impl.StdCouchDbConnector
;
import
org.ektorp.support.CouchDbDocument
;
import
javax.inject.Singleton
;
@Singleton
public
class
DataConnector
<
T
extends
CouchDbDocument
>
{
private
final
CouchDbConnector
connector
;
@Inject
public
DataConnector
(
final
CouchDbInstance
databaseInstance
,
final
DatabaseNameProvider
<
T
>
databaseNameProvider
)
{
//todo: temporary
String
databaseName
=
databaseNameProvider
.
get
();
// databaseInstance.deleteDatabase(databaseName);
final
StdCouchDbConnector
connector
=
new
StdCouchDbConnector
(
databaseName
,
databaseInstance
);
//todo: to configuration
connector
.
createDatabaseIfNotExists
();
//todo: as task while application start (configurable)
this
.
connector
=
connector
;
}
//todo: name
public
CouchDbConnector
getConnector
()
{
return
connector
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/core/DatabaseNameProvider.java
0 → 100644
View file @
e2d2dd18
package
com
.
telephoners
.
krakyournet
.
ctf
.
core
;
import
com.google.inject.Inject
;
import
org.ektorp.support.CouchDbDocument
;
public
class
DatabaseNameProvider
<
T
extends
CouchDbDocument
>
{
private
Class
<
T
>
type
;
@Inject
public
DatabaseNameProvider
(
final
Class
<
T
>
type
)
{
this
.
type
=
type
;
}
public
String
get
()
{
return
String
.
format
(
"%s_database"
,
formatName
(
type
.
getTypeName
()));
}
private
String
formatName
(
final
String
className
)
{
return
className
.
replace
(
"."
,
"_"
);
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/modules/ApplicationModule.java
View file @
e2d2dd18
...
...
@@ -6,11 +6,9 @@ import com.google.inject.TypeLiteral;
import
com.telephoners.krakyournet.ctf.beans.Team
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.core.ApplicationConfiguration
;
import
org.ektorp.CouchDbConnector
;
import
org.ektorp.CouchDbInstance
;
import
org.ektorp.http.HttpClient
;
import
org.ektorp.http.StdHttpClient
;
import
org.ektorp.impl.StdCouchDbConnector
;
import
org.ektorp.impl.StdCouchDbInstance
;
import
java.net.MalformedURLException
;
...
...
@@ -34,16 +32,19 @@ public class ApplicationModule extends AbstractModule
bind
(
new
TypeLiteral
<
Class
<
Team
>>(){}).
toInstance
(
Team
.
class
);
}
@Provides
//todo: reuqires seperate connectors for each repository
// @Provides
//todo: remove
//todo: hide behind interface
public
CouchDbConnector
provideDatastore
(
final
CouchDbInstance
databaseInstance
)
/*
public CouchDbConnector provideDatastore(final CouchDbInstance databaseInstance)
{
databaseInstance.deleteDatabase("database"); //todo: temp
final StdCouchDbConnector database = new StdCouchDbConnector("database", databaseInstance); //todo: to configuration
database.createDatabaseIfNotExists();
//todo: as task while application start (configurable)
return database;
}
}
*/
@Provides
public
CouchDbInstance
provideDatabaseInstance
(
final
HttpClient
httpClient
)
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/Repository.java
View file @
e2d2dd18
package
com
.
telephoners
.
krakyournet
.
ctf
.
repositories
;
import
com.google.inject.Inject
;
import
org.ektorp.CouchDbConnector
;
import
com.google.inject.Singleton
;
import
com.telephoners.krakyournet.ctf.core.DataConnector
;
import
org.ektorp.support.CouchDbDocument
;
import
org.ektorp.support.CouchDbRepositorySupport
;
//
@Singleton
@Singleton
public
class
Repository
<
T
extends
CouchDbDocument
>
extends
CouchDbRepositorySupport
<
T
>
{
@Inject
public
Repository
(
final
Class
<
T
>
type
,
final
CouchDbConnector
connector
)
public
Repository
(
final
Class
<
T
>
type
,
final
DataConnector
<
T
>
connector
)
{
super
(
type
,
connector
);
super
(
type
,
connector
.
getConnector
()
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment