use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class AppPlaceHistoryMapper method getPlace.
@Override
public Place getPlace(String token) {
String[] parts = token.split("/");
if (parts[0].equals("table")) {
return new TablePlace(ResourceId.valueOf(parts[1]));
} else if (parts[0].equals("analysis")) {
if (parts.length > 1) {
return new AnalysisPlace(parts[1]);
} else {
return new AnalysisPlace(ResourceId.generateCuid());
}
} else if (parts[0].equals("record")) {
ResourceId formId = ResourceId.valueOf(parts[1]);
ResourceId recordId = ResourceId.valueOf(parts[2]);
return new RecordPlace(formId, recordId);
} else if (parts[0].equals("catalog")) {
Optional<String> parentId = Optional.absent();
if (parts.length > 1) {
parentId = Optional.of(parts[1]);
}
return new CatalogPlace(parentId);
} else {
return null;
}
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class FormForest method collectReferenced.
private void collectReferenced(FormTree tree, Iterable<FormTree.Node> parentFields, Set<ResourceId> visited, List<FormClass> list) {
for (FormTree.Node parentField : parentFields) {
if (parentField.getType() instanceof ReferenceType) {
for (ResourceId formId : parentField.getRange()) {
if (!visited.contains(formId)) {
visited.add(formId);
// depth first...
collectReferenced(tree, parentField.getChildren(formId), visited, list);
// now ourselves
list.add(tree.getFormClass(formId));
}
}
}
}
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class PermissionFilters method getReferenceBaseFilter.
/**
* Returns a filter for records referenced by the given field.
*/
public Optional<FormulaNode> getReferenceBaseFilter(ResourceId fieldId) {
FormulaNode filter = fieldFilters.get(fieldId);
if (filter == null) {
return Optional.absent();
}
SymbolNode fieldExpr = new SymbolNode(fieldId);
return Optional.of(filter.transform(x -> {
if (x.equals(fieldExpr)) {
return new SymbolNode(ColumnModel.ID_SYMBOL);
} else {
return x;
}
}));
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class SubFormViewModelBuilder method computeActiveSubRecord.
private RecordRef computeActiveSubRecord(RecordRef parentRecordRef, FormInputModel inputModel) {
// Has the user chosen a specific period?
Optional<RecordRef> activeSubRecord = inputModel.getActiveSubRecord(fieldId);
if (activeSubRecord.isPresent()) {
return activeSubRecord.get();
}
// Otherwise choose the active record based on the user's previous choices
// or the current date
PeriodValue activePeriod = subFormKind.getPeriodType().containingDate(memory.getLastUsedDate());
ResourceId recordId = ResourceId.periodSubRecordId(parentRecordRef, activePeriod);
return new RecordRef(subFormId, recordId);
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class KeySelectionSet method normalize.
/**
* When we have overlapping hierarchies, we don't include all complete selections as
* the value for the field.
*
* For example, given a reference field that includes [PROVINCE, TERRITORY] in the range, we will
* have two {@link KeySelection} for each of the forms in this range. Their key trees look like this:
*
* <pre>
*
* PROVINCE TERRITORY
*
* k0: Province.Name k0: Province.Name
* ^
* |
* k1: Territory.Name
*
* </pre>
*
* Once the user has selected both the Province.Name (k0) and the Territory.Name (k1), then we have a valid
* selection for both forms.
*
* However, in this case, we don't want to store _both_ the territory _and_ the province as this not really
* the user's intent. We exclude the province selection because it is implied by the territory selection.
*/
private Set<RecordRef> normalize(List<Optional<RecordRef>> refs) {
// Build a map from referenced form id -> selection
Map<ResourceId, RecordRef> selectionMap = new HashMap<>();
for (int i = 0; i < selections.size(); i++) {
if (refs.get(i).isPresent()) {
selectionMap.put(selections.get(i).getFormId(), refs.get(i).get());
}
}
List<ResourceId> selectedFormIds = Lists.newArrayList(selectionMap.keySet());
// Now remove redundant parents
for (ResourceId formId : selectedFormIds) {
for (ResourceId ancestorFormId : lookupKeySet.getAncestorForms(formId)) {
selectionMap.remove(ancestorFormId);
}
}
return new HashSet<>(selectionMap.values());
}
Aggregations