use of org.activityinfo.store.mysql.mapping.TableMappingBuilder in project activityinfo by bedatadriven.
the class CountryTable method getMapping.
@Override
public TableMapping getMapping(QueryExecutor executor, ResourceId formId) throws SQLException {
FormField nameField = new FormField(NAME_FIELD_ID);
nameField.setCode("label");
nameField.setLabel(I18N.CONSTANTS.name());
nameField.setType(TextType.SIMPLE);
FormField isoField = new FormField(CODE_FIELD_ID);
isoField.setCode("code");
isoField.setLabel(I18N.CONSTANTS.codeFieldLabel());
isoField.setType(TextType.SIMPLE);
FormField boundaryField = new FormField(BOUNDARY_FIELD_ID);
boundaryField.setCode("boundary");
boundaryField.setLabel(I18N.CONSTANTS.boundaries());
boundaryField.setType(GeoAreaType.INSTANCE);
// TODO: polygons
TableMappingBuilder mapping = TableMappingBuilder.newMapping(FORM_CLASS_ID, TABLE_NAME);
mapping.setFormLabel("Country");
mapping.setPrimaryKeyMapping(CuidAdapter.COUNTRY_DOMAIN, "countryId");
mapping.setDatabaseId(GeodbFolder.GEODB_ID);
mapping.addTextField(nameField, "name");
mapping.addTextField(isoField, "iso2");
mapping.addGeoAreaField(boundaryField);
return mapping.build();
}
use of org.activityinfo.store.mysql.mapping.TableMappingBuilder in project activityinfo by bedatadriven.
the class PartnerTable method getMapping.
private TableMapping getMapping(ResourceId formId) throws SQLException {
int databaseId = CuidAdapter.getLegacyIdFromCuid(formId);
TableMappingBuilder mapping = TableMappingBuilder.newMapping(formId, "partner");
mapping.setFormLabel("Partner");
mapping.setDatabaseId(CuidAdapter.databaseId(databaseId));
mapping.setPrimaryKeyMapping(CuidAdapter.PARTNER_DOMAIN, "partnerId");
mapping.setFromClause("partnerindatabase pd LEFT JOIN partner base ON (pd.partnerId=base.partnerId)");
mapping.setBaseFilter("pd.databaseId=" + databaseId);
mapping.setVersion(databaseVersionMap.getSchemaVersion(databaseId));
// Schema is static
mapping.setSchemaVersion(1L);
FormField nameField = new FormField(field(formId, NAME_FIELD)).setRequired(true).setLabel("Name").setCode("label").setKey(true).setType(TextType.SIMPLE);
mapping.addTextField(nameField, "name");
FormField fullNameField = new FormField(field(formId, FULL_NAME_FIELD)).setLabel("Full Name").setRequired(false).setType(TextType.SIMPLE);
mapping.addTextField(fullNameField, "FullName");
return mapping.build();
}
use of org.activityinfo.store.mysql.mapping.TableMappingBuilder in project activityinfo by bedatadriven.
the class ProjectTable method getMapping.
@Override
public TableMapping getMapping(QueryExecutor executor, ResourceId formId) throws SQLException {
int databaseId = CuidAdapter.getLegacyIdFromCuid(formId);
TableMappingBuilder mapping = TableMappingBuilder.newMapping(formId, "partner");
mapping.setFormLabel("Project");
mapping.setDatabaseId(CuidAdapter.databaseId(databaseId));
mapping.setPrimaryKeyMapping(CuidAdapter.PROJECT_DOMAIN, "projectId");
mapping.setFromClause("project base");
mapping.setBaseFilter("dateDeleted IS NULL AND databaseId=" + databaseId);
mapping.setDeleteMethod(DeleteMethod.SOFT_BY_DATE);
mapping.setVersion(databaseVersionMap.getSchemaVersion(databaseId));
// Schema is static
mapping.setSchemaVersion(1L);
FormField nameField = new FormField(field(formId, NAME_FIELD)).setRequired(true).setLabel("Name").setCode("label").setKey(true).setType(TextType.SIMPLE);
mapping.addTextField(nameField, "name");
FormField fullNameField = new FormField(field(formId, FULL_NAME_FIELD)).setLabel("Description").setRequired(false).setType(TextType.SIMPLE);
mapping.addTextField(fullNameField, "description");
return mapping.build();
}
use of org.activityinfo.store.mysql.mapping.TableMappingBuilder in project activityinfo by bedatadriven.
the class DatabaseTargetForm method buildMapping.
public TableMapping buildMapping() {
ResourceId classId = getFormClassId();
TableMappingBuilder mapping = TableMappingBuilder.newMapping(classId, "target");
mapping.setFormLabel(databaseName + " Targets");
mapping.setFromClause("target base");
mapping.setBaseFilter("databaseId = " + databaseId);
mapping.setDatabaseId(CuidAdapter.databaseId(databaseId));
mapping.setPrimaryKeyMapping(CuidAdapter.TARGET_INSTANCE_DOMAIN, "TargetId");
mapping.setSchemaVersion(schemaVersion);
FormField nameField = new FormField(CuidAdapter.field(classId, CuidAdapter.NAME_FIELD));
nameField.setCode("name");
nameField.setLabel(I18N.CONSTANTS.name());
nameField.setType(TextType.SIMPLE);
nameField.setRequired(true);
FormField startDateField = new FormField(CuidAdapter.field(classId, CuidAdapter.START_DATE_FIELD));
startDateField.setLabel(I18N.CONSTANTS.startDate());
startDateField.setCode("fromDate");
startDateField.setType(LocalDateType.INSTANCE);
FormField endDateField = new FormField(CuidAdapter.field(classId, CuidAdapter.END_DATE_FIELD));
endDateField.setLabel(I18N.CONSTANTS.endDate());
endDateField.setCode("toDate");
endDateField.setType(LocalDateType.INSTANCE);
ResourceId partnerFormId = CuidAdapter.partnerFormId(databaseId);
ResourceId projectFormId = CuidAdapter.projectFormClass(databaseId);
FormField partnerField = new FormField(CuidAdapter.field(classId, CuidAdapter.PARTNER_FIELD));
partnerField.setLabel(I18N.CONSTANTS.partner());
partnerField.setCode("partner");
partnerField.setType(ReferenceType.single(partnerFormId));
FormField projectField = new FormField(CuidAdapter.field(classId, CuidAdapter.PROJECT_FIELD));
projectField.setLabel(I18N.CONSTANTS.project());
projectField.setCode("project");
projectField.setType(ReferenceType.single(projectFormId));
mapping.addTextField(nameField, "name");
mapping.addDateField(startDateField, "date1");
mapping.addDateField(endDateField, "date2");
mapping.addReferenceField(partnerField, partnerFormId, CuidAdapter.PARTNER_DOMAIN, "partnerId");
mapping.addReferenceField(projectField, projectFormId, CuidAdapter.PROJECT_DOMAIN, "projectId");
for (FormField indicatorField : indicatorFields) {
mapping.addUnmappedField(indicatorField);
}
return mapping.build();
}
Aggregations