Android Open Source - openhds-tablet Converter






From Project

Back to project page openhds-tablet.

License

The source code is released under:

OPENHDS PLATFORM OPENSOURCE LICENSE AGREEMENT Copyright (c) 2013 University of Southern Maine. All rights reserved. Redistribution and use in source and binary forms, with or without mo...

If you think the Android project openhds-tablet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.openhds.mobile;
//from  w  w  w  . j a va  2s  .  c o m
import java.util.ArrayList;
import java.util.List;

import org.openhds.mobile.model.Form;
import org.openhds.mobile.model.FieldWorker;
import org.openhds.mobile.model.Individual;
import org.openhds.mobile.model.Location;
import org.openhds.mobile.model.LocationHierarchy;
import org.openhds.mobile.model.Relationship;
import org.openhds.mobile.model.Round;
import org.openhds.mobile.model.SocialGroup;

import android.database.Cursor;

/**
 * Converts a cursor into a corresponding model class or a list of model class
 */
public class Converter {
  
    public static Form toForms(Cursor cursor) {
      Form form = new Form();

        if (cursor!=null) {
          populateForm(cursor, form);
        }

        cursor.close();

        return form;
    }

    private static void populateForm(Cursor cursor, Form form) {
        form.setName(cursor.getString(cursor.getColumnIndex(OpenHDS.Forms.COLUMN_FORM_NAME)));
        form.setGender(cursor.getString(cursor.getColumnIndex(OpenHDS.Forms.COLUMN_FORM_GENDER)));
        
    }

    public static Individual toIndividual(Cursor cursor) {
        Individual individual = new Individual();

        if (cursor.moveToNext()) {
            populateIndividual(cursor, individual);
        }

        cursor.close();

        return individual;
    }

    private static void populateIndividual(Cursor cursor, Individual individual) {
        individual.setCurrentResidence(cursor.getString(cursor.getColumnIndex(OpenHDS.Individuals.COLUMN_INDIVIDUAL_RESIDENCE)));
        individual.setDob(cursor.getString(cursor.getColumnIndex(OpenHDS.Individuals.COLUMN_INDIVIDUAL_DOB)));
        individual.setExtId(cursor.getString(cursor.getColumnIndex(OpenHDS.Individuals.COLUMN_INDIVIDUAL_EXTID)));
        individual.setFather(cursor.getString(cursor.getColumnIndex(OpenHDS.Individuals.COLUMN_INDIVIDUAL_FATHER)));
        individual.setFirstName(cursor.getString(cursor.getColumnIndex(OpenHDS.Individuals.COLUMN_INDIVIDUAL_FIRSTNAME)));
        individual.setGender(cursor.getString(cursor.getColumnIndex(OpenHDS.Individuals.COLUMN_INDIVIDUAL_GENDER)));
        individual.setLastName(cursor.getString(cursor.getColumnIndex(OpenHDS.Individuals.COLUMN_INDIVIDUAL_LASTNAME)));
        individual.setMother(cursor.getString(cursor.getColumnIndex(OpenHDS.Individuals.COLUMN_INDIVIDUAL_MOTHER)));
    }

    public static Location toLocation(Cursor cursor) {
        Location location = new Location();

        if (cursor.moveToNext()) {
            populateLocation(cursor, location);
        }

        cursor.close();

        return location;
    }

    private static void populateLocation(Cursor cursor, Location location) {
        location.setExtId(cursor.getString(cursor.getColumnIndex(OpenHDS.Locations.COLUMN_LOCATION_EXTID)));
        location.setHierarchy(cursor.getString(cursor.getColumnIndex(OpenHDS.Locations.COLUMN_LOCATION_HIERARCHY)));
        location.setLatitude(cursor.getString(cursor.getColumnIndex(OpenHDS.Locations.COLUMN_LOCATION_LATITUDE)));
        location.setLongitude(cursor.getString(cursor.getColumnIndex(OpenHDS.Locations.COLUMN_LOCATION_LONGITUDE)));
        location.setName(cursor.getString(cursor.getColumnIndex(OpenHDS.Locations.COLUMN_LOCATION_NAME)));
    }

    public static LocationHierarchy toHierarhcy(Cursor cursor, boolean close) {
        LocationHierarchy hierarchy = new LocationHierarchy();

        if (cursor.moveToNext()) {
            populateHierarchy(cursor, hierarchy);
        }

        if (close) {
            cursor.close();
        }

        return hierarchy;
    }

    public static LocationHierarchy convertToHierarchy(Cursor cursor) {
        LocationHierarchy hierarchy = new LocationHierarchy();
        populateHierarchy(cursor, hierarchy);
        return hierarchy;
    }

    private static void populateHierarchy(Cursor cursor, LocationHierarchy hierarchy) {
        hierarchy.setExtId(cursor.getString(cursor.getColumnIndex(OpenHDS.HierarchyItems.COLUMN_HIERARCHY_EXTID)));
        hierarchy.setLevel(cursor.getString(cursor.getColumnIndex(OpenHDS.HierarchyItems.COLUMN_HIERARCHY_LEVEL)));
        hierarchy.setName(cursor.getString(cursor.getColumnIndex(OpenHDS.HierarchyItems.COLUMN_HIERARCHY_NAME)));
        hierarchy.setParent(cursor.getString(cursor.getColumnIndex(OpenHDS.HierarchyItems.COLUMN_HIERARCHY_PARENT)));
    }

    public static FieldWorker toFieldWorker(Cursor cursor) {
        FieldWorker fw = new FieldWorker();

        if (cursor.moveToNext()) {
            fw.setExtId(cursor.getString(cursor.getColumnIndex(OpenHDS.FieldWorkers.COLUMN_FIELDWORKER_EXTID)));
            fw.setFirstName(cursor.getString(cursor.getColumnIndex(OpenHDS.FieldWorkers.COLUMN_FIELDWORKER_FIRSTNAME)));
            fw.setLastName(cursor.getString(cursor.getColumnIndex(OpenHDS.FieldWorkers.COLUMN_FIELDWORKER_LASTNAME)));
            fw.setPassword(cursor.getString(cursor.getColumnIndex(OpenHDS.FieldWorkers.COLUMN_FIELDWORKER_PASSWORD)));
        }

        cursor.close();

        return fw;
    }

    public static SocialGroup toSocialGroup(Cursor cursor) {
        SocialGroup sg = new SocialGroup();

        if (cursor.moveToNext()) {
            populateSocialGroup(cursor, sg);
        }

        cursor.close();

        return sg;
    }

    private static void populateSocialGroup(Cursor cursor, SocialGroup sg) {
        sg.setExtId(cursor.getString(cursor.getColumnIndex(OpenHDS.SocialGroups.COLUMN_SOCIALGROUP_EXTID)));
        sg.setGroupHead(cursor.getString(cursor.getColumnIndex(OpenHDS.SocialGroups.COLUMN_SOCIALGROUP_GROUPHEAD)));
        sg.setGroupName(cursor.getString(cursor.getColumnIndex(OpenHDS.SocialGroups.COLUMN_SOCIALGROUP_GROUPNAME)));
    }

    public static List<SocialGroup> toSocialGroupList(Cursor cursor) {
        List<SocialGroup> socialGroups = new ArrayList<SocialGroup>();

        while (cursor.moveToNext()) {
            SocialGroup sg = new SocialGroup();
            populateSocialGroup(cursor, sg);
            socialGroups.add(sg);
        }

        cursor.close();

        return socialGroups;
    }

    public static List<LocationHierarchy> toHierarchyList(Cursor cursor) {
        List<LocationHierarchy> hierarchys = new ArrayList<LocationHierarchy>();

        while (cursor.moveToNext()) {
            LocationHierarchy hierarchy = new LocationHierarchy();
            populateHierarchy(cursor, hierarchy);
            hierarchys.add(hierarchy);
        }

        cursor.close();

        return hierarchys;
    }

    public static List<Location> toLocationList(Cursor cursor) {
        List<Location> locations = new ArrayList<Location>();

        while (cursor.moveToNext()) {
            Location location = new Location();
            populateLocation(cursor, location);
            locations.add(location);
        }

        cursor.close();

        return locations;
    }

    public static List<Individual> toIndividualList(Cursor cursor) {
        List<Individual> individuals = new ArrayList<Individual>();

        while (cursor.moveToNext()) {
            Individual individual = new Individual();
            populateIndividual(cursor, individual);
            individuals.add(individual);
        }

        cursor.close();

        return individuals;
    }

    public static List<Round> toRoundList(Cursor cursor) {
        List<Round> rounds = new ArrayList<Round>();

        while (cursor.moveToNext()) {
            Round round = new Round();
            round.setEndDate(cursor.getString(cursor.getColumnIndex(OpenHDS.Rounds.COLUMN_ROUND_ENDDATE)));
            round.setRoundNumber(cursor.getString(cursor.getColumnIndex(OpenHDS.Rounds.COLUMN_ROUND_NUMBER)));
            round.setStartDate(cursor.getString(cursor.getColumnIndex(OpenHDS.Rounds.COLUMN_ROUND_STARTDATE)));
            rounds.add(round);
        }

        cursor.close();

        return rounds;
    }

    public static List<Relationship> toRelationshipList(Cursor cursor) {
        List<Relationship> relationships = new ArrayList<Relationship>();

        while (cursor.moveToNext()) {
            Relationship rel = new Relationship();
            rel.setIndividualA(cursor.getString(cursor
                    .getColumnIndex(OpenHDS.Relationships.COLUMN_RELATIONSHIP_INDIVIDUAL_A)));
            rel.setIndividualB(cursor.getString(cursor
                    .getColumnIndex(OpenHDS.Relationships.COLUMN_RELATIONSHIP_INDIVIDUAL_B)));
            rel.setStartDate(cursor.getString(cursor
                    .getColumnIndex(OpenHDS.Relationships.COLUMN_RELATIONSHIP_STARTDATE)));

            relationships.add(rel);
        }

        cursor.close();

        return relationships;
    }

    public static List<Relationship> toRelationshipListSwapped(Cursor cursor) {
        List<Relationship> relationships = new ArrayList<Relationship>();

        while (cursor.moveToNext()) {
            Relationship rel = new Relationship();
            rel.setIndividualA(cursor.getString(cursor
                    .getColumnIndex(OpenHDS.Relationships.COLUMN_RELATIONSHIP_INDIVIDUAL_B)));
            rel.setIndividualB(cursor.getString(cursor
                    .getColumnIndex(OpenHDS.Relationships.COLUMN_RELATIONSHIP_INDIVIDUAL_A)));
            rel.setStartDate(cursor.getString(cursor
                    .getColumnIndex(OpenHDS.Relationships.COLUMN_RELATIONSHIP_STARTDATE)));

            relationships.add(rel);
        }

        cursor.close();

        return relationships;
    }

    public static Round convertToRound(Cursor cursor) {
      Round round = new Round();
      if (cursor.getPosition()==-1){
        cursor.moveToNext();
      }
        round.setEndDate(cursor.getString(cursor.getColumnIndex(OpenHDS.Rounds.COLUMN_ROUND_ENDDATE)));
        round.setRoundNumber(cursor.getString(cursor.getColumnIndex(OpenHDS.Rounds.COLUMN_ROUND_NUMBER)));
        round.setStartDate(cursor.getString(cursor.getColumnIndex(OpenHDS.Rounds.COLUMN_ROUND_STARTDATE)));
    

        return round;
    }

    public static Location convertToLocation(Cursor cursor) {
        Location location = new Location();
        populateLocation(cursor, location);

        return location;
    }

    public static Individual convertToIndividual(Cursor cursor) {
        Individual individual = new Individual();
        populateIndividual(cursor, individual);

        return individual;
    }

    public static SocialGroup convertToSocialGroup(Cursor cursor) {
        SocialGroup sg = new SocialGroup();
        populateSocialGroup(cursor, sg);
        return sg;
    }
}




Java Source Code List

org.openhds.mobile.BadXmlException.java
org.openhds.mobile.Converter.java
org.openhds.mobile.FieldWorkerProvider.java
org.openhds.mobile.FormsProviderAPI.java
org.openhds.mobile.InstanceProviderAPI.java
org.openhds.mobile.OpenHDS.java
org.openhds.mobile.Queries.java
org.openhds.mobile.activity.AbstractActivity.java
org.openhds.mobile.activity.FieldWorkerLoginActivity.java
org.openhds.mobile.activity.FilterActivity.java
org.openhds.mobile.activity.FilterFormActivity.java
org.openhds.mobile.activity.FilterLocationActivity.java
org.openhds.mobile.activity.FilterVisitActivity.java
org.openhds.mobile.activity.FormListActivity.java
org.openhds.mobile.activity.FormViewActivity.java
org.openhds.mobile.activity.OpeningActivity.java
org.openhds.mobile.activity.ServerPreferencesActivity.java
org.openhds.mobile.activity.ShowMapActivity.java
org.openhds.mobile.activity.SupervisorLoginActivity.java
org.openhds.mobile.activity.SupervisorMainActivity.java
org.openhds.mobile.activity.SyncDatabaseActivity.java
org.openhds.mobile.activity.UpdateActivity.java
org.openhds.mobile.adapter.AdapterContent.java
org.openhds.mobile.adapter.MapAdapter.java
org.openhds.mobile.database.DatabaseAdapter.java
org.openhds.mobile.database.DeathUpdate.java
org.openhds.mobile.database.ExternalInMigrationUpdate.java
org.openhds.mobile.database.HouseholdUpdate.java
org.openhds.mobile.database.InternalInMigrationUpdate.java
org.openhds.mobile.database.LocationUpdate.java
org.openhds.mobile.database.MembershipUpdate.java
org.openhds.mobile.database.OutMigrationUpdate.java
org.openhds.mobile.database.PregnancyOutcomeUpdate.java
org.openhds.mobile.database.RelationshipUpdate.java
org.openhds.mobile.database.Updatable.java
org.openhds.mobile.database.VisitUpdate.java
org.openhds.mobile.fragment.EventFragment.java
org.openhds.mobile.fragment.ProgressFragment.java
org.openhds.mobile.fragment.SelectionFilterFragment.java
org.openhds.mobile.fragment.SelectionFilterLocFragment.java
org.openhds.mobile.fragment.SelectionFormFragment.java
org.openhds.mobile.fragment.SelectionFragment.java
org.openhds.mobile.fragment.ValueFormFragment.java
org.openhds.mobile.fragment.ValueFragment.java
org.openhds.mobile.fragment.ValueLocFragment.java
org.openhds.mobile.listener.CollectEntitiesListener.java
org.openhds.mobile.listener.OdkFormLoadListener.java
org.openhds.mobile.listener.RetrieveFieldWorkersListener.java
org.openhds.mobile.listener.TaskCompleteListener.java
org.openhds.mobile.listener.ValueSelectedListener.java
org.openhds.mobile.model.Child.java
org.openhds.mobile.model.FieldWorker.java
org.openhds.mobile.model.FilledForm.java
org.openhds.mobile.model.FilledParams.java
org.openhds.mobile.model.FormFiller.java
org.openhds.mobile.model.FormSubmissionRecord.java
org.openhds.mobile.model.FormXmlReader.java
org.openhds.mobile.model.Form.java
org.openhds.mobile.model.HierarchySelection.java
org.openhds.mobile.model.Individual.java
org.openhds.mobile.model.LocationHierarchy.java
org.openhds.mobile.model.LocationVisit.java
org.openhds.mobile.model.Location.java
org.openhds.mobile.model.Membership.java
org.openhds.mobile.model.PregnancyObservationUpdate.java
org.openhds.mobile.model.PregnancyOutcome.java
org.openhds.mobile.model.Relationship.java
org.openhds.mobile.model.Result.java
org.openhds.mobile.model.Round.java
org.openhds.mobile.model.SocialGroup.java
org.openhds.mobile.model.StateMachine.java
org.openhds.mobile.model.Supervisor.java
org.openhds.mobile.model.UpdateEvent.java
org.openhds.mobile.model.UpdateParams.java
org.openhds.mobile.model.UpdateStatus.java
org.openhds.mobile.model.Visit.java
org.openhds.mobile.provider.OpenHDSProvider.java
org.openhds.mobile.task.AbstractHttpTask.java
org.openhds.mobile.task.AuthenticateTask.java
org.openhds.mobile.task.DownloadFormsTask.java
org.openhds.mobile.task.FieldWorkerLoginTask.java
org.openhds.mobile.task.OdkFormLoadTask.java
org.openhds.mobile.task.OdkGeneratedFormLoadTask.java
org.openhds.mobile.task.SupervisorLoginTask.java
org.openhds.mobile.task.SyncEntitiesTask.java
org.openhds.mobile.task.SyncFormsTask.java
org.openhds.mobile.utilities.L.java
org.openhds.mobile.utilities.Logg.java
org.openhds.mobile.utilities.UrlUtils.java