Search in sources :

Example 1 with AuditConfig

use of org.odk.collect.android.formentry.audit.AuditConfig in project collect by getodk.

the class BackgroundLocationManager method startLocationRequests.

private void startLocationRequests() {
    if (helper.currentFormAuditsLocation() && helper.isBackgroundLocationPreferenceEnabled() && helper.arePlayServicesAvailable() && helper.isAndroidLocationPermissionGranted()) {
        AuditConfig auditConfig = helper.getCurrentFormAuditConfig();
        locationClient.setListener(this);
        locationClient.setPriority(auditConfig.getLocationPriority());
        locationClient.setUpdateIntervals(auditConfig.getLocationMinInterval(), auditConfig.getLocationMinInterval());
        locationClient.start();
        currentState = BackgroundLocationState.RECEIVING_LOCATIONS;
    }
}
Also used : AuditConfig(org.odk.collect.android.formentry.audit.AuditConfig)

Example 2 with AuditConfig

use of org.odk.collect.android.formentry.audit.AuditConfig in project collect by opendatakit.

the class FormController method getSubmissionMetadata.

/**
 * Get the OpenRosa required metadata of the portion of the form beng submitted
 */
public InstanceMetadata getSubmissionMetadata() {
    FormDef formDef = formEntryController.getModel().getForm();
    TreeElement rootElement = formDef.getInstance().getRoot();
    TreeElement trueSubmissionElement;
    // Determine the information about the submission...
    SubmissionProfile p = formDef.getSubmissionProfile();
    if (p == null || p.getRef() == null) {
        trueSubmissionElement = rootElement;
    } else {
        IDataReference ref = p.getRef();
        trueSubmissionElement = formDef.getInstance().resolveReference(ref);
        // resolveReference returns null if the reference is to the root element...
        if (trueSubmissionElement == null) {
            trueSubmissionElement = rootElement;
        }
    }
    // and find the depth-first meta block in this...
    TreeElement e = findDepthFirst(trueSubmissionElement, "meta");
    String instanceId = null;
    String instanceName = null;
    AuditConfig auditConfig = null;
    if (e != null) {
        List<TreeElement> v;
        // instance id...
        v = e.getChildrenWithName(INSTANCE_ID);
        if (v.size() == 1) {
            IAnswerData sa = v.get(0).getValue();
            if (sa != null) {
                instanceId = sa.getDisplayText();
            }
        }
        // instance name...
        v = e.getChildrenWithName(INSTANCE_NAME);
        if (v.size() == 1) {
            IAnswerData sa = v.get(0).getValue();
            if (sa != null) {
                instanceName = sa.getDisplayText();
            }
        }
        // timing element...
        v = e.getChildrenWithName(AUDIT);
        if (v.size() == 1) {
            TreeElement auditElement = v.get(0);
            String locationPriority = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-priority");
            String locationMinInterval = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-min-interval");
            String locationMaxAge = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-max-age");
            boolean isTrackingChangesEnabled = Boolean.parseBoolean(auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "track-changes"));
            boolean isIdentifyUserEnabled = Boolean.parseBoolean(auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "identify-user"));
            String trackChangesReason = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "track-changes-reasons");
            auditConfig = new AuditConfig.Builder().setMode(locationPriority).setLocationMinInterval(locationMinInterval).setLocationMaxAge(locationMaxAge).setIsTrackingChangesEnabled(isTrackingChangesEnabled).setIsIdentifyUserEnabled(isIdentifyUserEnabled).setIsTrackChangesReasonEnabled(trackChangesReason != null && trackChangesReason.equals("on-form-edit")).createAuditConfig();
            IAnswerData answerData = new StringData();
            answerData.setValue(AUDIT_FILE_NAME);
            auditElement.setValue(answerData);
        }
    }
    return new InstanceMetadata(instanceId, instanceName, auditConfig);
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) FormDef(org.javarosa.core.model.FormDef) IDataReference(org.javarosa.core.model.IDataReference) SubmissionProfile(org.javarosa.core.model.SubmissionProfile) StringData(org.javarosa.core.model.data.StringData) AuditConfig(org.odk.collect.android.formentry.audit.AuditConfig) TreeElement(org.javarosa.core.model.instance.TreeElement)

Example 3 with AuditConfig

use of org.odk.collect.android.formentry.audit.AuditConfig in project collect by opendatakit.

the class BackgroundLocationManager method startLocationRequests.

private void startLocationRequests() {
    if (helper.currentFormAuditsLocation() && helper.isBackgroundLocationPreferenceEnabled() && helper.arePlayServicesAvailable() && helper.isAndroidLocationPermissionGranted()) {
        AuditConfig auditConfig = helper.getCurrentFormAuditConfig();
        locationClient.setListener(this);
        locationClient.setPriority(auditConfig.getLocationPriority());
        locationClient.setUpdateIntervals(auditConfig.getLocationMinInterval(), auditConfig.getLocationMinInterval());
        locationClient.start();
        currentState = BackgroundLocationState.RECEIVING_LOCATIONS;
    }
}
Also used : AuditConfig(org.odk.collect.android.formentry.audit.AuditConfig)

Example 4 with AuditConfig

use of org.odk.collect.android.formentry.audit.AuditConfig in project collect by getodk.

the class FormController method getSubmissionMetadata.

/**
 * Get the OpenRosa required metadata of the portion of the form beng submitted
 */
public InstanceMetadata getSubmissionMetadata() {
    FormDef formDef = formEntryController.getModel().getForm();
    TreeElement rootElement = formDef.getInstance().getRoot();
    TreeElement trueSubmissionElement;
    // Determine the information about the submission...
    SubmissionProfile p = formDef.getSubmissionProfile();
    if (p == null || p.getRef() == null) {
        trueSubmissionElement = rootElement;
    } else {
        IDataReference ref = p.getRef();
        trueSubmissionElement = formDef.getInstance().resolveReference(ref);
        // resolveReference returns null if the reference is to the root element...
        if (trueSubmissionElement == null) {
            trueSubmissionElement = rootElement;
        }
    }
    // and find the depth-first meta block in this...
    TreeElement e = findDepthFirst(trueSubmissionElement, "meta");
    String instanceId = null;
    String instanceName = null;
    AuditConfig auditConfig = null;
    if (e != null) {
        List<TreeElement> v;
        // instance id...
        v = e.getChildrenWithName(INSTANCE_ID);
        if (v.size() == 1) {
            IAnswerData sa = v.get(0).getValue();
            if (sa != null) {
                instanceId = sa.getDisplayText();
            }
        }
        // instance name...
        v = e.getChildrenWithName(INSTANCE_NAME);
        if (v.size() == 1) {
            IAnswerData sa = v.get(0).getValue();
            if (sa != null) {
                instanceName = sa.getDisplayText();
            }
        }
        // timing element...
        v = e.getChildrenWithName(AUDIT);
        if (v.size() == 1) {
            TreeElement auditElement = v.get(0);
            String locationPriority = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-priority");
            String locationMinInterval = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-min-interval");
            String locationMaxAge = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-max-age");
            boolean isTrackingChangesEnabled = Boolean.parseBoolean(auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "track-changes"));
            boolean isIdentifyUserEnabled = Boolean.parseBoolean(auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "identify-user"));
            String trackChangesReason = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "track-changes-reasons");
            auditConfig = new AuditConfig.Builder().setMode(locationPriority).setLocationMinInterval(locationMinInterval).setLocationMaxAge(locationMaxAge).setIsTrackingChangesEnabled(isTrackingChangesEnabled).setIsIdentifyUserEnabled(isIdentifyUserEnabled).setIsTrackChangesReasonEnabled(trackChangesReason != null && trackChangesReason.equals("on-form-edit")).createAuditConfig();
            IAnswerData answerData = new StringData();
            answerData.setValue(AUDIT_FILE_NAME);
            auditElement.setValue(answerData);
        }
    }
    return new InstanceMetadata(instanceId, instanceName, auditConfig);
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) FormDef(org.javarosa.core.model.FormDef) IDataReference(org.javarosa.core.model.IDataReference) SubmissionProfile(org.javarosa.core.model.SubmissionProfile) StringData(org.javarosa.core.model.data.StringData) AuditConfig(org.odk.collect.android.formentry.audit.AuditConfig) TreeElement(org.javarosa.core.model.instance.TreeElement)

Aggregations

AuditConfig (org.odk.collect.android.formentry.audit.AuditConfig)4 FormDef (org.javarosa.core.model.FormDef)2 IDataReference (org.javarosa.core.model.IDataReference)2 SubmissionProfile (org.javarosa.core.model.SubmissionProfile)2 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 StringData (org.javarosa.core.model.data.StringData)2 TreeElement (org.javarosa.core.model.instance.TreeElement)2