Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merger #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1200-jdbc41</version>
</dependency>
</dependencies>



<build>
<plugins>
<plugin>
Expand Down
52 changes: 39 additions & 13 deletions src/main/java/org/openshift/InsultGenerator.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
package org.openshift;

import java.util.Random;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class InsultGenerator {
public String generateInsult() {
String words[][] = {{"Artless", "Bawdy", "Beslubbering"}, {"Base-court", "Bat-fowling", "Beef-witted"}, {"Apple-john", "Baggage", "Barnacle"}};
String vowels = "AEIOU";
String article = "an";
String firstAdjective = words[0][new Random().nextInt(words[0].length)];
String secondAdjective = words[1][new Random().nextInt(words[1].length)];
String noun = words[2][new Random().nextInt(words[2].length)];
if (vowels.indexOf(firstAdjective.charAt(0)) == -1) {
article = "a";
}
return String.format("Thou art %s %s %s %s!", article, firstAdjective, secondAdjective, noun);
}
public String generateInsult() {
String vowels = "AEIOU";
String article = "an";
String theInsult = "";


try {
String databaseURL = "jdbc:postgresql://";
databaseURL += System.getenv("POSTGRESQL_SERVICE_HOST");
databaseURL += "/" + System.getenv("POSTGRESQL_DATABASE");

String username = System.getenv("POSTGRESQL_USER");
String password = System.getenv("PGPASSWORD");
Connection connection = DriverManager.getConnection(databaseURL, username,
password);

if (connection != null) {
String SQL = "select a.string AS first, b.string AS second, c.string AS noun
from short_adjective a , long_adjective b, noun c ORDER BY random() limit 1";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
while (rs.next()) {
if (vowels.indexOf(rs.getString("first").charAt(0)) == -1) {
article = "a";
}
theInsult = String.format("Thou art %s %s %s %s!", article,
rs.getString("first"), rs.getString("second"), rs.getString("noun"));
}
rs.close();
connection.close();
}
} catch (Exception e) {
return "Database connection problem!";
}
return theInsult;
}
}