123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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 com.intellij.openapi.project.Project;
- import com.rthoni.intellij.codefromds.business.Helper;
- import org.json.JSONObject;
-
- import java.io.File;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- 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) {
- _modelsRelativePath = "Models";
- _dataSourceTemplateRelativePath = "Templates" + File.separator + "DataSource.twig";
- _modelsTemplateRelativePath = "Templates" + File.separator + "Models.twig";
- _configAbsolutePath = source.getProject().getBasePath() + File.separator + "code-from-ds.json";
- _filesExtension = "cs";
- _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 _modelsRelativePath;
-
- private String _dataSourceTemplateRelativePath;
-
- private String _modelsTemplateRelativePath;
-
- private String _configAbsolutePath;
-
- private String _filesExtension;
-
- public HashMap<String, Object> toMap()
- {
- HashMap<String, Object> map = new HashMap<>();
-
- map.put("modelsRelativePath", _modelsRelativePath);
- map.put("dataSourceTemplateRelativePath", _dataSourceTemplateRelativePath);
- map.put("modelsTemplateRelativePath", _modelsTemplateRelativePath);
- map.put("filesExtension", _filesExtension);
- map.put("selection", _selection == null ? null : new JSONObject(_selection.toMap()));
-
- return map;
- }
-
- public void fromJson(JSONObject json)
- {
- _modelsRelativePath = Helper.getJsonString(json, "modelsRelativePath");
- _dataSourceTemplateRelativePath = Helper.getJsonString(json, "dataSourceTemplateRelativePath");
- _modelsTemplateRelativePath = Helper.getJsonString(json, "modelsTemplateRelativePath");
- _filesExtension = Helper.getJsonString(json, "filesExtension");
- _selection.fromJson(json.getJSONObject("selection"));
- }
-
- public DataSourceSelection getSelection() {
- return _selection;
- }
-
- public void setSelection(DataSourceSelection selection) {
- _selection = selection;
- }
-
- public String getModelsRelativePath() {
- return _modelsRelativePath;
- }
-
- public void setModelsRelativePath(String modelsRelativePath) {
- _modelsRelativePath = modelsRelativePath;
- }
-
- public String getDataSourceTemplateRelativePath() {
- return _dataSourceTemplateRelativePath;
- }
-
- public void setDataSourceTemplateRelativePath(String dataSourceTemplateRelativePath) {
- _dataSourceTemplateRelativePath = dataSourceTemplateRelativePath;
- }
-
- public String getModelsTemplateRelativePath() {
- return _modelsTemplateRelativePath;
- }
-
- public void setModelsTemplateRelativePath(String modelsTemplateRelativePath) {
- _modelsTemplateRelativePath = modelsTemplateRelativePath;
- }
-
- public String getConfigAbsolutePath() {
- return _configAbsolutePath;
- }
-
- public void setConfigAbsolutePath(String configAbsolutePath) {
- _configAbsolutePath = configAbsolutePath;
- }
-
- public String getFilesExtension() {
- return _filesExtension;
- }
-
- public void setFilesExtension(String filesExtension) {
- _filesExtension = filesExtension;
- }
- }
|