Search in sources :

Example 1 with FormAttributeGroup

use of org.activityinfo.server.endpoint.odk.SiteFormData.FormAttributeGroup in project activityinfo by bedatadriven.

the class FormSubmissionResource method createSite.

private void createSite(SiteFormData data, SchemaDTO schemaDTO, ActivityDTO activity) {
    final SiteDTO site = new SiteDTO();
    site.setId(new KeyGenerator().generateInt());
    site.setActivityId(data.getActivity());
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        site.setReportingPeriodId(new KeyGenerator().generateInt());
    }
    // set activitymodel
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        site.setDate1(data.getDate1());
        site.setDate2(data.getDate2());
    }
    site.setPartner(schemaDTO.getPartnerById(data.getPartner()));
    // set comments
    site.setComments(data.getComments());
    // set attributes
    for (FormAttributeGroup formAttributeGroup : data.getAttributegroups()) {
        AttributeGroupDTO attributeGroup = activity.getAttributeGroupById(formAttributeGroup.getId());
        for (Integer attributeId : attributeGroup.getAttributeIds()) {
            site.setAttributeValue(attributeId, formAttributeGroup.isSelected(attributeId));
        }
    }
    // set indicators
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        for (FormIndicator formIndicator : data.getIndicators()) {
            site.setIndicatorValue(formIndicator.getId(), formIndicator.getDoubleValue());
        }
    }
    // create command(s)
    CreateSite cmd = new CreateSite(site);
    cmd.setNestedCommand(createCreateLocationCommand(data, schemaDTO, activity));
    // save
    CreateResult createResult = dispatcher.execute(cmd);
    // create sitehistory entry
    siteHistoryProcessor.process(cmd, getUser().getId(), createResult.getNewId());
}
Also used : FormAttributeGroup(org.activityinfo.server.endpoint.odk.SiteFormData.FormAttributeGroup) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) FormIndicator(org.activityinfo.server.endpoint.odk.SiteFormData.FormIndicator) CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) CreateSite(org.activityinfo.shared.command.CreateSite)

Aggregations

KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)1 FormAttributeGroup (org.activityinfo.server.endpoint.odk.SiteFormData.FormAttributeGroup)1 FormIndicator (org.activityinfo.server.endpoint.odk.SiteFormData.FormIndicator)1 CreateSite (org.activityinfo.shared.command.CreateSite)1 CreateResult (org.activityinfo.shared.command.result.CreateResult)1 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)1 SiteDTO (org.activityinfo.shared.dto.SiteDTO)1