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

Feat: Added image questions #233

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions questiongenerator/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import model.AnswerCategory;
import repositories.GeneralRepositoryStorer;
import templates.BallonDOrQuestion;
import templates.CountryCapitalQuestion;
import templates.VideogamesPublisherQuestion;
import templates.*;

public class Main {



public static void main(String[] args) {

GeneralRepositoryStorer.editConstraints();

// TEXT
if(GeneralRepositoryStorer.doesntExist(AnswerCategory.CAPITAL_CITY)) {
new CountryCapitalQuestion("en");
Expand All @@ -23,10 +26,8 @@ public static void main(String[] args) {
}


/*
// IMAGES

if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM.toString())) {
if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM)) {
new StadiumQuestion("en");
new StadiumQuestion("es");
}
Expand All @@ -35,7 +36,6 @@ public static void main(String[] args) {
new PaintingQuestion("en");
new PaintingQuestion("es");
}
*/


/*
Expand Down
1 change: 1 addition & 0 deletions questiongenerator/src/main/java/model/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@Entity
@Table(name = "questions")
public class Question implements Storable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
public class GeneralRepositoryStorer {

public static final String LINKCONCAT = "#* &%";

public void saveAll(List<Storable> storableList) {
EntityManagerFactory emf = Jpa.getEntityManagerFactory();
EntityManager entityManager = emf.createEntityManager();
Expand All @@ -40,7 +42,26 @@ public static boolean doesntExist(AnswerCategory category) {
Jpa.close();

return count == 0;
}

public static void editConstraints() {
EntityManagerFactory emf = Jpa.getEntityManagerFactory();
EntityManager entityManager = emf.createEntityManager();

entityManager.getTransaction().begin();


// Drop constraint "answers_category_check" from table "answers" if exists
entityManager.createNativeQuery("ALTER TABLE answers DROP CONSTRAINT IF EXISTS answers_category_check").executeUpdate();
// Drop constraint "questions_question_category_check" from table "questions" if exists
entityManager.createNativeQuery("ALTER TABLE questions DROP CONSTRAINT IF EXISTS questions_question_category_check").executeUpdate();


entityManager.getTransaction().commit();

entityManager.close();
Jpa.close();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import model.*;
import org.json.JSONObject;
import repositories.GeneralRepositoryStorer;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -62,9 +63,9 @@ public void processResults() {
answers.add(a);

if (langCode.equals("es"))
questions.add(new Question(a, "¿Cuál es este cuadro? " + imageLink, QuestionCategory.ART, QuestionType.IMAGE));
questions.add(new Question(a, "¿Cuál es este cuadro?" + GeneralRepositoryStorer.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE));
else
questions.add(new Question(a, "Which painting is this? " + imageLink, QuestionCategory.ART, QuestionType.IMAGE));
questions.add(new Question(a, "Which painting is this?" + GeneralRepositoryStorer.LINKCONCAT + imageLink, QuestionCategory.ART, QuestionType.IMAGE));
}

repository.saveAll(new ArrayList<>(answers));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import model.*;
import org.json.JSONObject;
import repositories.GeneralRepositoryStorer;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -55,9 +56,9 @@ public void processResults() {
answers.add(a);

if (langCode.equals("es"))
questions.add(new Question(a, "¿Cuál es este estadio? " + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE));
questions.add(new Question(a, "¿Cuál es este estadio?" + GeneralRepositoryStorer.LINKCONCAT + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE));
else
questions.add(new Question(a, "Which stadium is this? " + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE));
questions.add(new Question(a, "Which stadium is this?" + GeneralRepositoryStorer.LINKCONCAT + imageLink, QuestionCategory.SPORTS, QuestionType.IMAGE));
}

repository.saveAll(new ArrayList<>(answers));
Expand Down