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());
}
}
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);
}
}
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);
}
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();
}
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);
}
Aggregations