use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class CloneDatabaseHandler method copyReference.
/**
* Copies a reference, changing references to forms within the source database
* to the cloned forms in the target database.
*/
private ResourceId copyReference(ResourceId sourceFormId) {
switch(sourceFormId.getDomain()) {
// Reference the NEW database's partner form
case CuidAdapter.PARTNER_FORM_CLASS_DOMAIN:
ResourceId partnerId = CuidAdapter.partnerFormId(targetDb.getId());
typeIdMapping.put(sourceFormId, partnerId);
return partnerId;
// Reference the NEW database's project form
case CuidAdapter.PROJECT_CLASS_DOMAIN:
ResourceId projectId = CuidAdapter.projectFormClass(targetDb.getId());
typeIdMapping.put(sourceFormId, projectId);
return projectId;
// the reference to point to the clone of that form
case CuidAdapter.ACTIVITY_DOMAIN:
int sourceActivityId = CuidAdapter.getLegacyIdFromCuid(sourceFormId);
Activity targetActivity = this.activityMapping.get(sourceActivityId);
if (targetActivity != null) {
return CuidAdapter.activityFormClass(targetActivity.getId());
} else {
// reference as-is
return sourceFormId;
}
// could be an administrative level form, then don't change the reference at all.
default:
return sourceFormId;
}
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class CloneDatabaseHandler method copyFormClass.
private FormClass copyFormClass(final ResourceId sourceFormId, final ResourceId targetFormId) {
FormClass sourceFormClass = formCatalog.get().getFormClass(sourceFormId);
FormClass targetFormClass = new FormClass(targetFormId);
if (sourceFormClass.isSubForm()) {
targetFormClass.setSubFormKind(sourceFormClass.getSubFormKind());
ResourceId targetParentFormId = this.typeIdMapping.get(sourceFormClass.getParentFormId().get());
if (targetParentFormId == null) {
LOGGER.severe(String.format("Parent (%s) of subform (%s) was not copied", sourceFormClass.getParentFormId(), sourceFormId));
throw new IllegalStateException("Parent form has not been copied!");
}
targetFormClass.setParentFormId(targetParentFormId);
}
targetFormClass.setLabel(sourceFormClass.getLabel());
targetFormClass.setDescription(sourceFormClass.getDescription());
targetFormClass.setDatabaseId(CuidAdapter.databaseId(targetDb.getId()));
Map<FormElement, FormElement> sourceIdToTargetFormElementMapping = Maps.newHashMap();
copyFormElements(sourceFormClass, targetFormClass, sourceFormClass.getId(), targetFormClass.getId(), sourceIdToTargetFormElementMapping);
correctRelevanceConditions(targetFormClass, sourceIdToTargetFormElementMapping);
return targetFormClass;
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class LocationFieldBinding method buildAdminBindings.
private void buildAdminBindings(FormClass locationForm, FormTree formTree, int adminFieldIndex) {
Optional<FormField> potentialAdminField = locationForm.getFieldIfPresent(CuidAdapter.field(locationForm.getId(), adminFieldIndex));
if (potentialAdminField.isPresent()) {
FormField adminField = potentialAdminField.get();
Iterator<ResourceId> adminLevelRange = getRange(adminField);
while (adminLevelRange.hasNext()) {
ResourceId adminLevelId = adminLevelRange.next();
buildLocationBindings(formTree.getFormClass(adminLevelId), formTree);
}
}
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class XFormBuilder method createLocationElements.
private void createLocationElements(FormField field, Body body) {
ResourceId locationRef = extractLocationReference(field);
if (locationRef != null) {
body.addElement(createPresentationElement(locationName(field)));
body.addElement(createPresentationElement(gps(field)));
}
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class ResourceLocatorSyncImpl method getReferenceChoices.
@Override
public List<ReferenceChoice> getReferenceChoices(Collection<ResourceId> range) {
ResourceId formId = Iterables.getOnlyElement(range);
QueryModel queryModel = new QueryModel(formId);
queryModel.selectResourceId().as("id");
queryModel.selectExpr("label").as("label");
ColumnSetBuilder builder = new ColumnSetBuilder(catalog.get(), new NullFormSupervisor());
ColumnSet columnSet = builder.build(queryModel);
ColumnView id = columnSet.getColumnView("id");
ColumnView label = columnSet.getColumnView("label");
List<ReferenceChoice> choices = Lists.newArrayList();
for (int i = 0; i < columnSet.getNumRows(); i++) {
ResourceId choiceId = ResourceId.valueOf(id.getString(i));
String choiceLabel = label.getString(i);
choices.add(new ReferenceChoice(new RecordRef(formId, choiceId), choiceLabel));
}
return choices;
}
Aggregations