123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package com.rthoni.intellij.codefromds.dbo;
-
- import com.intellij.database.model.DasTable;
- import com.intellij.database.psi.DbDataSource;
- import com.intellij.database.util.DasUtil;
- import org.json.JSONObject;
-
- import java.io.File;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Vector;
- import java.util.stream.Collectors;
-
- /**
- * Created by robin on 11/15/16.
- */
- public class GenerateOptions {
-
- public GenerateOptions(DbDataSource source) {
- _modelsPath = source.getProject().getBasePath() + File.separator + "Models";
- _dataSourceTemplatePath = source.getProject().getBasePath() + File.separator + "Templates" + File.separator + "DataSource.twig";
- _modelsTemplatePath = source.getProject().getBasePath() + File.separator + "Templates" + File.separator + "Models.twig";
- _configPath = source.getProject().getBasePath() + File.separator + "code-from-ds.json";
- _selection = new DataSourceSelection(source);
- _selection.setSource(source);
- final List<? extends DasTable> tables = DasUtil.getTables(source).toList();
- List<TableSelection> tableSelections = new Vector<>();
- for (DasTable table : tables) {
- TableSelection tableSelection = new TableSelection();
- tableSelection.setTable(table);
- tableSelection.setColumns(DasUtil.getColumns(table).toList().stream().map(c -> {
- ColumnSelection selection = new ColumnSelection();
- selection.setColumn(c);
- selection.setSelected(true);
- return selection;
- }).collect(Collectors.toList()));
- tableSelections.add(tableSelection);
- }
- _selection.setTables(tableSelections);
- }
-
- private DataSourceSelection _selection;
-
- private String _modelsPath;
-
- private String _dataSourceTemplatePath;
-
- private String _modelsTemplatePath;
-
- private String _configPath;
-
- public HashMap<String, Object> toMap()
- {
- HashMap<String, Object> map = new HashMap<>();
-
- map.put("modelsPath", _modelsPath);
- map.put("dataSourceTemplatePath", _dataSourceTemplatePath);
- map.put("modelsTemplatePath", _modelsTemplatePath);
- map.put("selection", _selection == null ? null : new JSONObject(_selection.toMap()));
-
- return map;
- }
-
- public void fromJson(JSONObject json)
- {
- _modelsPath = json.getString("modelsPath");
- _dataSourceTemplatePath = json.getString("dataSourceTemplatePath");
- _modelsTemplatePath = json.getString("modelsTemplatePath");
- _selection.fromJson(json.getJSONObject("selection"));
- }
-
- public DataSourceSelection getSelection() {
- return _selection;
- }
-
- public void setSelection(DataSourceSelection selection) {
- _selection = selection;
- }
-
- public String getModelsPath() {
- return _modelsPath;
- }
-
- public void setModelsPath(String modelsPath) {
- _modelsPath = modelsPath;
- }
-
- public String getDataSourceTemplatePath() {
- return _dataSourceTemplatePath;
- }
-
- public void setDataSourceTemplatePath(String dataSourceTemplatePath) {
- _dataSourceTemplatePath = dataSourceTemplatePath;
- }
-
- public String getModelsTemplatePath() {
- return _modelsTemplatePath;
- }
-
- public void setModelsTemplatePath(String modelsTemplatePath) {
- _modelsTemplatePath = modelsTemplatePath;
- }
-
- public String getConfigPath() {
- return _configPath;
- }
-
- public void setConfigPath(String configPath) {
- _configPath = configPath;
- }
- }
|