Search in sources :

Example 46 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class RecordTest method testRootEntityCanBeReplaced.

@Test
public void testRootEntityCanBeReplaced() {
    TestFixture fixture = survey(rootEntityDef("plot"));
    Record record = new Record(fixture.survey, null, "plot");
    EntityDefinition rootEntityDef = fixture.survey.getSchema().getRootEntityDefinition("plot");
    Entity rootEntity = new Entity(rootEntityDef);
    record.replaceRootEntity(rootEntity);
    assertSame(rootEntity, record.getRootEntity());
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) TestFixture(org.openforis.idm.testfixture.TestFixture) Test(org.junit.Test)

Example 47 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class AttributeVM method generateEntityAlias.

@Command
public void generateEntityAlias() {
    AttributeDefinitionFormObject<?> fo = (AttributeDefinitionFormObject<?>) formObject;
    String referencedAttributePath = fo.getReferencedAttributePath();
    EntityDefinition sourceDef = editedItem.getParentEntityDefinition();
    String aliasName = sourceDef + "_alias";
    NodeDefinition referencedAttributeDef = editedItem.getDefinitionByPath(referencedAttributePath);
    EntityDefinition parentDef = referencedAttributeDef.getNearestAncestorMultipleEntity();
    if (parentDef.containsChildDefinition(aliasName)) {
        MessageUtil.showError("survey.schema.attribute.generate_entity_alias.error.alias_already_existing", aliasName, parentDef.getName());
    } else {
        EntityDefinition aliasDef = schemaUpdater.generateAlias(sourceDef, editedItem.getName(), parentDef, referencedAttributeDef.getName());
        ((CollectSurvey) aliasDef.getSurvey()).getUIOptions().setLayout(aliasDef, Layout.TABLE);
        aliasDef.rename(aliasName);
        dispatchSchemaChangedCommand();
        MessageUtil.showInfo("survey.schema.attribute.generate_entity_alias.generation_successfull", aliasName, parentDef.getName());
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinitionFormObject(org.openforis.collect.designer.form.AttributeDefinitionFormObject) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 48 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class CodeAttributeVM method openParentAttributeSelector.

@Command
public void openParentAttributeSelector(@ContextParam(ContextType.BINDER) final Binder binder) {
    String title = Labels.getLabel("survey.schema.attribute.code.select_parent_for_node", new String[] { editedItem.getName() });
    final Collection<CodeAttributeDefinition> assignableParentAttributes = editedItem.getAssignableParentCodeAttributeDefinitions();
    if (assignableParentAttributes.isEmpty()) {
        MessageUtil.showWarning("survey.schema.attribute.code.no_assignable_parent_available");
    } else {
        CodeAttributeDefinition parentCodeAttributeDefinition = ((CodeAttributeDefinitionFormObject) formObject).getParentCodeAttributeDefinition();
        Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

            @Override
            public boolean evaluate(SurveyObject item) {
                return item instanceof UITab || item instanceof EntityDefinition || item instanceof CodeAttributeDefinition && assignableParentAttributes.contains(item);
            }
        };
        Predicate<SurveyObject> disabledNodePredicate = new Predicate<SurveyObject>() {

            @Override
            public boolean evaluate(SurveyObject item) {
                return !(item instanceof CodeAttributeDefinition);
            }
        };
        final Window parentSelectorPopUp = SchemaTreePopUpVM.openPopup(title, editedItem.getRootEntity(), null, includedNodePredicate, false, false, disabledNodePredicate, null, parentCodeAttributeDefinition, true);
        parentSelectorPopUp.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

            public void onEvent(NodeSelectedEvent event) throws Exception {
                CodeAttributeDefinition parentAttrDefn = (CodeAttributeDefinition) event.getSelectedItem();
                CodeAttributeDefinitionFormObject fo = (CodeAttributeDefinitionFormObject) formObject;
                fo.setParentCodeAttributeDefinition(parentAttrDefn);
                String hierarchicalLevel = getHierarchicalLevelName(parentAttrDefn);
                fo.setHierarchicalLevel(hierarchicalLevel);
                notifyChange("formObject");
                dispatchApplyChangesCommand(binder);
                notifyChange("dependentCodePaths");
                closePopUp(parentSelectorPopUp);
            }
        });
    }
}
Also used : Window(org.zkoss.zul.Window) CodeAttributeDefinitionFormObject(org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject) NodeSelectedEvent(org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent) Predicate(org.openforis.collect.designer.util.Predicate) UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) Command(org.zkoss.bind.annotation.Command) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 49 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class CodeListsVM method getReferences.

protected List<NodeDefinition> getReferences(CodeList item) {
    List<NodeDefinition> references = new ArrayList<NodeDefinition>();
    Schema schema = survey.getSchema();
    List<EntityDefinition> rootEntities = schema.getRootEntityDefinitions();
    Stack<NodeDefinition> stack = new Stack<NodeDefinition>();
    stack.addAll(rootEntities);
    while (!stack.isEmpty()) {
        NodeDefinition defn = stack.pop();
        if (defn instanceof EntityDefinition) {
            stack.addAll(((EntityDefinition) defn).getChildDefinitions());
        } else if (defn instanceof CodeAttributeDefinition) {
            CodeList list = ((CodeAttributeDefinition) defn).getList();
            if (list.equals(item)) {
                references.add(defn);
            }
        }
        ;
    }
    return references;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList) Stack(java.util.Stack)

Example 50 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.

the class RecordController method loadRecordSummaries.

@RequestMapping(value = "survey/{surveyId}/data/records/summary", method = GET)
@ResponseBody
public Map<String, Object> loadRecordSummaries(@PathVariable("surveyId") int surveyId, @Valid RecordSummarySearchParameters params) {
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
    User user = loadUser(params.getUserId(), params.getUsername());
    Map<String, Object> result = new HashMap<String, Object>();
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDefinition = params.getRootEntityName() == null ? schema.getFirstRootEntityDefinition() : schema.getRootEntityDefinition(params.getRootEntityName());
    RecordFilter filter = createRecordFilter(survey, user, userGroupManager, rootEntityDefinition.getId(), false);
    filter.setKeyValues(params.getKeyValues());
    filter.setCaseSensitiveKeyValues(params.isCaseSensitiveKeyValues());
    if (CollectionUtils.isEmpty(filter.getQualifiers())) {
        // filter by qualifiers only if not already done by user group qualifiers
        filter.setQualifiers(params.getQualifierValues());
    }
    filter.setSummaryValues(params.getSummaryValues());
    if (filter.getOwnerIds() == null && params.getOwnerIds() != null && params.getOwnerIds().length > 0) {
        filter.setOwnerIds(Arrays.asList(params.getOwnerIds()));
    }
    filter.setOffset(params.getOffset());
    filter.setMaxNumberOfRecords(params.getMaxNumberOfRows());
    // load summaries
    List<CollectRecordSummary> summaries = params.isFullSummary() ? recordManager.loadFullSummaries(filter, params.getSortFields()) : recordManager.loadSummaries(filter, params.getSortFields());
    result.put("records", toProxies(summaries));
    // count total records
    int count = recordManager.countRecords(filter);
    result.put("count", count);
    if (params.isIncludeOwners()) {
        Set<User> owners = recordManager.loadDistinctOwners(createRecordFilter(survey, user, userGroupManager, rootEntityDefinition.getId(), false));
        Set<BasicUserProxy> ownerProxies = Proxies.fromSet(owners, BasicUserProxy.class);
        result.put("owners", ownerProxies);
    }
    return result;
}
Also used : User(org.openforis.collect.model.User) HashMap(java.util.HashMap) Schema(org.openforis.idm.metamodel.Schema) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) BasicUserProxy(org.openforis.collect.model.proxy.BasicUserProxy) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9