use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class ActivityTableMappingBuilder method reportingPeriod.
public static ActivityTableMappingBuilder reportingPeriod(Activity activity) {
ActivityTableMappingBuilder mapping = new ActivityTableMappingBuilder();
mapping.activity = activity;
mapping.baseTable = "reportingperiod";
mapping.baseFromClause = "reportingperiod base";
mapping.baseFilter = "base.deleted=0 AND base.activityId=" + activity.getId();
mapping.classId = CuidAdapter.reportingPeriodFormClass(activity.getId());
mapping.formClass = new FormClass(mapping.classId);
mapping.formClass.setLabel(activity.getName() + " Monthly Reports");
mapping.formClass.setDatabaseId(activity.getDatabaseId());
mapping.primaryKeyMapping = new PrimaryKeyMapping(CuidAdapter.MONTHLY_REPORT, "reportingPeriodId");
mapping.addSiteField();
mapping.addDateFields();
for (ActivityField indicatorField : activity.getIndicatorFields()) {
mapping.addIndicatorOrAttributeField(indicatorField);
}
sortFormClassFields(mapping.formClass, activity.getFieldsOrder());
return mapping;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class ActivityTableMappingBuilder method site.
public static ActivityTableMappingBuilder site(Activity activity) {
if (activity.getSerializedFormClass() != null) {
return newForm(activity);
}
ActivityTableMappingBuilder mapping = new ActivityTableMappingBuilder();
mapping.activity = activity;
mapping.baseTable = "site";
mapping.baseFromClause = "site base";
mapping.baseFilter = "base.deleted=0 AND base.activityId=" + activity.getId();
mapping.classId = CuidAdapter.activityFormClass(activity.getId());
mapping.formClass = new FormClass(mapping.classId);
mapping.formClass.setSchemaVersion(activity.getActivityVersion().getSchemaVersion());
mapping.formClass.setLabel(activity.getName());
mapping.formClass.setDatabaseId(activity.getDatabaseId());
mapping.primaryKeyMapping = new PrimaryKeyMapping(CuidAdapter.SITE_DOMAIN, "siteId");
if (activity.getReportingFrequency() == Activity.REPORT_ONCE) {
mapping.addDateFields();
}
mapping.addPartnerField();
mapping.addProjectField();
if (activity.hasLocationType()) {
mapping.addLocationField();
}
for (ActivityField field : activity.getAttributeAndIndicatorFields()) {
mapping.addIndicatorOrAttributeField(field);
}
mapping.addComments();
sortFormClassFields(mapping.formClass, activity.getFieldsOrder());
return mapping;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormTreeBuilder method embeddedForm.
private FormMetadata embeddedForm(FormTree.Node childNode) {
FormClass embeddedFormSchema = ((RecordFieldType) childNode.getType()).getFormClass();
long formVersion = 1L;
return FormMetadata.of(formVersion, embeddedFormSchema, FormPermissions.readonly());
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormTreePrettyPrinter method distinctFormClasses.
private List<FormClass> distinctFormClasses(List<FormTree.Node> nodes) {
Set<ResourceId> formClassIds = Sets.newHashSet();
List<FormClass> formClasses = Lists.newArrayList();
for (FormTree.Node node : nodes) {
ResourceId formClassId = node.getDefiningFormClass().getId();
if (!formClassIds.contains(formClassId)) {
formClassIds.add(formClassId);
formClasses.add(node.getDefiningFormClass());
}
}
return formClasses;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormTreePrettyPrinter method classNode.
private String classNode(List<FormClass> formClasses) {
StringBuilder sb = new StringBuilder("[");
boolean needsPipe = false;
for (FormClass formClass : formClasses) {
if (needsPipe) {
sb.append(" | ");
}
sb.append(formClass.getLabel());
needsPipe = true;
}
sb.append("]");
return sb.toString();
}
Aggregations