use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getTreatmentIdRelationCsvDB.
static HashMap<Long, Treatment> getTreatmentIdRelationCsvDB(Context context) throws IOException {
HashMap<Long, Treatment> treatmentFK = new HashMap<>();
List<Treatment> treatments = Treatment.getAllTreatments();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TREATMENT_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < treatments.size() && i < csvIds.size(); i++) {
treatmentFK.put(csvIds.get(i), treatments.get(i));
}
return treatmentFK;
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getQuestionIdRelationCsvDB.
static HashMap<Long, Question> getQuestionIdRelationCsvDB(Context context) throws IOException {
HashMap<Long, Question> questionFK = new HashMap<>();
List<Question> questions = Question.getAllQuestions();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < questions.size() && i < csvIds.size(); i++) {
questionFK.put(csvIds.get(i), questions.get(i));
}
return questionFK;
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getOptionAttributeIdRelationCsvDB.
static HashMap<Long, OptionAttribute> getOptionAttributeIdRelationCsvDB(Context context) throws IOException {
HashMap<Long, OptionAttribute> optionAttributeFK = new HashMap<>();
List<OptionAttribute> optionAttributes = OptionAttribute.getAllOptionAttributes();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.OPTION_ATTRIBUTES_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < optionAttributes.size() && i < csvIds.size(); i++) {
optionAttributeFK.put(csvIds.get(i), optionAttributes.get(i));
}
return optionAttributeFK;
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getStringKeyIdRelationCsvDB.
static HashMap<Long, StringKey> getStringKeyIdRelationCsvDB(Context context) throws IOException {
HashMap<Long, StringKey> stringKeyFK = new HashMap<>();
List<StringKey> stringKeys = StringKey.getAllStringKeys();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.STRING_KEY_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < stringKeys.size() && i < csvIds.size(); i++) {
stringKeyFK.put(csvIds.get(i), stringKeys.get(i));
}
return stringKeyFK;
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class UpdateDB method updateOrganisations.
/**
* Method to update organisations from csvs.
*
* @param context Needed to open the csvs.
* @param updateCSV
* @throws IOException If there is a problem opening the csv.
*/
public static void updateOrganisations(Context context, boolean updateCSV) throws IOException {
if (updateCSV) {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.ORGANISATIONS_CSV);
}
List<Organisation> organisations = Organisation.getAllOrganisations();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.ORGANISATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < organisations.size()) {
PopulateRow.populateOrganisations(line, organisations.get(i)).save();
} else {
PopulateRow.populateOrganisations(line, null).insert();
}
i++;
}
}
Aggregations