Search in sources :

Example 86 with EntityDefinition

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

the class SurveyEditVM method exportCeCsvDataImportTemplate.

@Command
public void exportCeCsvDataImportTemplate() throws IOException {
    CSVDataExportJob job = jobManager.createJob(CSVDataExportJob.class);
    job.setOutputFile(File.createTempFile("ce-data-import-template-" + survey.getName(), ".csv"));
    RecordFilter recordFilter = new RecordFilter(survey);
    EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
    recordFilter.setRootEntityId(rootEntityDef.getId());
    CSVDataExportParameters parameters = new CSVDataExportParameters();
    parameters.setRecordFilter(recordFilter);
    parameters.setEntityId(rootEntityDef.getId());
    parameters.setAlwaysGenerateZipFile(false);
    parameters.setIncludeEnumeratedEntities(true);
    job.setParameters(parameters);
    jobManager.start(job, false);
    if (job.isCompleted()) {
        File outputFile = job.getOutputFile();
        String dateStr = Dates.formatLocalDateTime(new Date());
        String fileName = String.format(DATA_IMPORT_TEMPLATE_FILE_NAME_PATTERN, survey.getName(), dateStr, "csv");
        String contentType = URLConnection.guessContentTypeFromName(fileName);
        FileInputStream is = new FileInputStream(outputFile);
        Filedownload.save(is, contentType, fileName);
    } else {
        throw new RuntimeException("Error generating the CSV data export template: " + job.getErrorMessage(), job.getLastException());
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) File(java.io.File) RecordFilter(org.openforis.collect.model.RecordFilter) Date(java.util.Date) FileInputStream(java.io.FileInputStream) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 87 with EntityDefinition

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

the class SchemaVM method refreshNodeForm.

protected void refreshNodeForm() {
    nodeFormInclude.setSrc(null);
    if (editedNode != null) {
        nodeFormInclude.setDynamicProperty("parentEntity", editedNodeParentEntity);
        nodeFormInclude.setDynamicProperty("item", editedNode);
        nodeFormInclude.setDynamicProperty("newItem", newNode);
        String nodeNameTextboxPath;
        String location;
        if (editedNode instanceof UITab) {
            location = Resources.Component.TAB.getLocation();
            nodeNameTextboxPath = TAB_NAME_LABEL_PATH;
        } else if (editedNode instanceof EntityDefinition) {
            location = Resources.Component.ENTITY.getLocation();
            nodeNameTextboxPath = ENTITY_NAME_TEXTBOX_PATH;
        } else {
            AttributeType attributeType = AttributeType.valueOf((AttributeDefinition) editedNode);
            String locationFormat = Resources.Component.ATTRIBUTE.getLocation();
            String attributeTypeShort = attributeType.name().toLowerCase(Locale.ENGLISH);
            location = MessageFormat.format(locationFormat, attributeTypeShort);
            nodeNameTextboxPath = ATTRIBUTE_NAME_TEXTBOX_PATH;
        }
        nodeFormInclude.setSrc(location);
        // set focus on name textbox
        Textbox nodeNameTextbox = (Textbox) Path.getComponent(nodeFormInclude.getSpaceOwner(), nodeNameTextboxPath);
        nodeNameTextbox.setFocus(true);
    }
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeType(org.openforis.collect.designer.metamodel.AttributeType) Textbox(org.zkoss.zul.Textbox) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 88 with EntityDefinition

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

the class SchemaVM method duplicateEditedNodeInto.

private void duplicateEditedNodeInto(NodeDefinition node, SurveyObject parent) {
    NodeDefinition clone = survey.getSchema().cloneDefinition(node);
    EntityDefinition parentEntity = determineRelatedEntity(parent);
    clone.setName(createDuplicateNodeName(node, parentEntity));
    editedNode = clone;
    changeEditedNodeParent(parent, true);
    editNode(false, parentEntity, editedNode);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 89 with EntityDefinition

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

the class SchemaVM method performRemoveNode.

protected void performRemoveNode(NodeDefinition nodeDefn) {
    EntityDefinition parentDefn = (EntityDefinition) nodeDefn.getParentDefinition();
    if (parentDefn == null) {
        // root entity
        UIOptions uiOpts = survey.getUIOptions();
        UITabSet tabSet = uiOpts.getAssignedRootTabSet((EntityDefinition) nodeDefn);
        uiOpts.removeTabSet(tabSet);
        Schema schema = nodeDefn.getSchema();
        String nodeName = nodeDefn.getName();
        schema.removeRootEntityDefinition(nodeName);
        selectedRootEntity = null;
        rootTabSet = null;
        notifyChange("selectedRootEntity", "rootEntities");
        refreshTreeModel();
    } else {
        if (treeModel != null) {
            treeModel.removeSelectedNode();
            notifyChange("treeModel");
        }
        parentDefn.removeChildDefinition(nodeDefn);
    }
    survey.refreshSurveyDependencies();
    resetEditingStatus();
    dispatchCurrentFormValidatedCommand(true);
    dispatchSurveyChangedCommand();
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) UITabSet(org.openforis.collect.metamodel.ui.UITabSet) Schema(org.openforis.idm.metamodel.Schema)

Example 90 with EntityDefinition

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

the class SchemaVM method performSelectNode.

protected void performSelectNode(Binder binder, SchemaNodeData data) {
    selectedTreeNode = data;
    treeModel.select(data);
    SurveyObject surveyObject = data.getSurveyObject();
    EntityDefinition parentDefn = treeModel.getNearestParentEntityDefinition(surveyObject);
    editNode(binder, false, parentDefn, surveyObject);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject)

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