-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into beacon_comm
- Loading branch information
Showing
34 changed files
with
634 additions
and
527 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,70 @@ | ||
package telraam; | ||
|
||
import telraam.database.Database; | ||
import io.dropwizard.Application; | ||
import io.dropwizard.jdbi3.JdbiFactory; | ||
import io.dropwizard.jdbi3.bundles.JdbiExceptionsBundle; | ||
import io.dropwizard.setup.Bootstrap; | ||
import io.dropwizard.setup.Environment; | ||
import org.jdbi.v3.core.Jdbi; | ||
import telraam.api.BatonResource; | ||
import telraam.api.HelloworldResource; | ||
import telraam.database.daos.BatonDAO; | ||
import telraam.database.models.Baton; | ||
import telraam.database.models.Id; | ||
import telraam.healthchecks.TemplateHealthCheck; | ||
|
||
import java.sql.Connection; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
|
||
public class App { | ||
|
||
public class App extends Application<AppConfiguration> { | ||
private static Logger logger = Logger.getLogger(App.class.getName()); | ||
|
||
public static void main(String[] args) { | ||
logger.log(Level.INFO, "Main method"); | ||
Connection conn = Database.getInstance().getDataAccessContext().getConnection(); | ||
public static void main(String[] args) throws Exception { | ||
new App().run(args); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "hello-world"; | ||
} | ||
|
||
@Override | ||
public void initialize(Bootstrap<AppConfiguration> bootstrap) { | ||
// nothing to do yet | ||
bootstrap.addBundle(new JdbiExceptionsBundle()); | ||
} | ||
|
||
/** | ||
* Temporary test method | ||
*/ | ||
public String greeting() { | ||
@Override | ||
public void run(AppConfiguration configuration, Environment environment) throws Exception { | ||
// Add database | ||
final JdbiFactory factory = new JdbiFactory(); | ||
final Jdbi database = factory.build(environment, configuration.getDataSourceFactory(), "postgresql"); | ||
|
||
final BatonDAO dao = database.onDemand(BatonDAO.class); | ||
Id id = dao.insert(new Baton("Heto")); | ||
|
||
// TODO By default everything should be logged to stdout (see dropwizard logging docs) but it isn't | ||
List<Baton> batons = dao.listBatons(); | ||
if(logger.isLoggable(Level.INFO)) { | ||
logger.info("Baton testing information"); | ||
logger.info(batons.stream().map(Baton::getName).collect(Collectors.joining(" : "))); | ||
logger.info(String.valueOf(dao.findBatonById(id.getId()))); | ||
} | ||
|
||
// Add api resources | ||
final HelloworldResource resource = new HelloworldResource( | ||
configuration.getTemplate(), | ||
configuration.getDefaultName() | ||
); | ||
environment.jersey().register(resource); | ||
environment.jersey().register(new BatonResource(database.onDemand(BatonDAO.class))); | ||
|
||
return "test"; | ||
// Register healthcheck | ||
// environment.healthChecks().register("database", new DatabaseHealthCheck(database)); | ||
environment.healthChecks().register("template", new TemplateHealthCheck(configuration.getTemplate())); | ||
logger.warning("TEST LOG"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package telraam; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.dropwizard.Configuration; | ||
import io.dropwizard.db.DataSourceFactory; | ||
import telraam.api.responses.Template; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
|
||
public class AppConfiguration extends Configuration { | ||
@NotNull | ||
private String template; | ||
|
||
@NotNull | ||
private String defaultName = "Stranger"; | ||
|
||
@JsonProperty | ||
public String getTemplate() { | ||
return template; | ||
} | ||
|
||
@JsonProperty | ||
public void setTemplate(String template) { | ||
this.template = template; | ||
} | ||
|
||
public Template buildTemplate() { | ||
return new Template(template, defaultName); | ||
} | ||
|
||
@JsonProperty | ||
public String getDefaultName() { | ||
return defaultName; | ||
} | ||
|
||
@JsonProperty | ||
public void setDefaultName(String name) { | ||
this.defaultName = name; | ||
} | ||
|
||
@Valid | ||
@NotNull | ||
private DataSourceFactory database = new DataSourceFactory(); | ||
|
||
@JsonProperty("database") | ||
public void setDataSourceFactory(DataSourceFactory factory) { | ||
this.database = factory; | ||
} | ||
|
||
@JsonProperty("database") | ||
public DataSourceFactory getDataSourceFactory() { | ||
return database; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.