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());
}
Aggregations