use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method updateQuestionOption.
public static void updateQuestionOption(Context context, boolean updateCSV) throws IOException {
if (updateCSV) {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_OPTIONS_CSV);
}
List<QuestionOption> questionOptions = QuestionOption.listAll();
HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
HashMap<Long, Question> questionsIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
HashMap<Long, Option> optionsIds = RelationsIdCsvDB.getOptionIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < questionOptions.size()) {
PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, questionOptions.get(i)).save();
} else {
QuestionOption questionOption = PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, null);
questionOption.insert();
}
i++;
}
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method updateQuestionRelation.
public static void updateQuestionRelation(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_RELATIONS_CSV);
List<QuestionRelation> questionRelations = QuestionRelation.listAll();
HashMap<Long, Question> questionIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_RELATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
boolean added = false;
if (i < questionRelations.size()) {
populateQuestionRelation(line, questionIds, questionRelations.get(i)).save();
} else {
QuestionRelation questionRelation = populateQuestionRelation(line, questionIds, null);
questionRelation.insert();
}
i++;
}
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getQuestionRelationIdRelationCsvDB.
static HashMap<Long, QuestionRelation> getQuestionRelationIdRelationCsvDB(Context context) throws IOException {
HashMap<Long, QuestionRelation> questionRelationsFK = new HashMap<>();
List<QuestionRelation> questionRelations = QuestionRelation.listAll();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_RELATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < questionRelations.size() && i < csvIds.size(); i++) {
questionRelationsFK.put(csvIds.get(i), questionRelations.get(i));
}
return questionRelationsFK;
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getAnswerFKRelationCsvDB.
static HashMap<Long, Answer> getAnswerFKRelationCsvDB(Context context) throws IOException {
HashMap<Long, Answer> answerFK = new HashMap<>();
List<Answer> answers = Answer.getAllAnswers();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.ANSWERS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < answers.size() && i < csvIds.size(); i++) {
answerFK.put(csvIds.get(i), answers.get(i));
}
return answerFK;
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getMatchIdRelationCsvDB.
static HashMap<Long, Match> getMatchIdRelationCsvDB(Context context) throws IOException {
HashMap<Long, Match> matchesFK = new HashMap<>();
List<Match> matches = Match.listAll();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.MATCHES)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < matches.size() && i < csvIds.size(); i++) {
matchesFK.put(csvIds.get(i), matches.get(i));
}
return matchesFK;
}
Aggregations