use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class SelectDialog method updateMatch.
private void updateMatch(int matchedIndex) {
ResourceId fromId = keyFields.getForm(fromSide).getRowId(fromIndex);
ResourceId toId = keyFields.getForm(fromSide.opposite()).getRowId(matchedIndex);
InstanceMatch newMatch;
if (fromSide == MatchSide.SOURCE) {
newMatch = new InstanceMatch(fromId, toId);
} else {
newMatch = new InstanceMatch(toId, fromId);
}
viewModel.getModel().getInstanceMatchSet().add(newMatch);
setVisible(false);
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class ActivityInfoClientAsyncImpl method getFormTree.
@Override
public Promise<FormTree> getFormTree(final ResourceId formId) {
return get(formUrl(formId) + "/tree", jsonElement -> {
JsonValue root = jsonElement;
JsonValue forms = root.get("forms");
final Map<ResourceId, FormClass> formMap = new HashMap<>();
for (Map.Entry<String, JsonValue> entry : forms.entrySet()) {
FormClass formClass = FormClass.fromJson(entry.getValue());
formMap.put(formClass.getId(), formClass);
}
FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {
@Override
public FormClass getFormClass(ResourceId formId1) {
FormClass formClass = formMap.get(formId1);
assert formClass != null;
return formClass;
}
});
return builder.queryTree(formId);
});
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class LookupKeySet method addLevels.
private LookupKey addLevels(FormClass formClass) {
ResourceId formId = formClass.getId();
if (formMap.containsKey(formId)) {
return formMap.get(formId);
}
// if serial number is present, we use that exclusively.
Optional<FormField> serialNumberField = findSerialNumberField(formClass);
if (serialNumberField.isPresent()) {
LookupKey lookupKey = serialNumberLevel(formClass, serialNumberField.get());
lookupKeys.add(lookupKey);
return lookupKey;
}
LookupKey parentKey = null;
String parentFieldId = null;
// If there is a reference key, then we climb the reference tree recursively.
Optional<FormField> referenceKey = findReferenceKey(formClass);
if (referenceKey.isPresent()) {
ReferenceType referenceType = (ReferenceType) referenceKey.get().getType();
ResourceId referencedFormId = Iterables.getOnlyElement(referenceType.getRange());
FormClass referencedFormClass = formTree.getFormClass(referencedFormId);
parentMap.put(formId, referencedFormId);
parentKey = addLevels(referencedFormClass);
parentFieldId = referenceKey.get().getId().asString();
}
// Now check for text key fields
for (FormField formField : formClass.getFields()) {
if (isTextLikeKey(formField)) {
LookupKey lookupKey = textKeyLevel(formClass, parentKey, parentFieldId, formField);
lookupKeys.add(lookupKey);
parentKey = lookupKey;
parentFieldId = null;
}
}
// If there is really no other key fields, then use the autogenerated id as a key
if (parentKey == null) {
parentKey = idLevel(formClass);
lookupKeys.add(parentKey);
}
formMap.put(formId, parentKey);
return parentKey;
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class FormTree method parentTree.
public FormTree parentTree() {
FormClass rootFormClass = getRootFormClass();
assert rootFormClass.isSubForm();
ResourceId parentFormId = rootFormClass.getParentFormId().get();
return subTree(parentFormId);
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class FormTreeBuilder method queryTree.
public FormTree queryTree(ResourceId rootFormId) {
FormTree tree = new FormTree(rootFormId);
FormMetadata root = metadataProvider.getFormMetadata(rootFormId);
if (root.isDeleted()) {
tree.setRootState(FormTree.State.DELETED);
return tree;
}
if (!root.isVisible()) {
tree.setRootState(FormTree.State.FORBIDDEN);
return tree;
}
FormClass rootSchema = root.getSchema();
List<ResourceId> stack = Lists.newArrayList(rootFormId);
Optional<FormField> parentField = rootSchema.getParentField();
if (parentField.isPresent()) {
if (!stack.contains(parentField.get().getId())) {
tree.addFormMetadata(root);
FormTree.Node node = tree.addRootField(root, parentField.get());
fetchChildren(stack, tree, node, rootSchema.getParentFormId().asSet());
}
}
// Add fields defined by this FormClass
for (FormField field : rootSchema.getFields()) {
tree.addFormMetadata(root);
FormTree.Node node = tree.addRootField(root, field);
if (node.isReference()) {
fetchChildren(stack, tree, node, node.getRange());
} else if (field.getType() instanceof RecordFieldType) {
addChildren(stack, tree, node, embeddedForm(node));
}
}
return tree;
}
Aggregations