Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3263 #3431

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assemblies/plugins/transforms/monetdbbulkloader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<description />

<properties>
<monetdb.version>3.1</monetdb.version>
<monetdb.version>3.3</monetdb.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,19 @@ public void editProject() {

try {
Project project = projectConfig.loadProject(hopGui.getVariables());
String projectFolder = projectConfig.getProjectHome();

ProjectDialog projectDialog =
new ProjectDialog(hopGui.getActiveShell(), project, projectConfig, hopGui.getVariables(), true);
if (projectDialog.open() != null) {
config.addProjectConfig(projectConfig);

// Project's home changed. Update reference in hop-config.json
if (!projectFolder.equals(projectConfig.getProjectHome())) {
// Refresh project reference in hop-config.json
HopConfig.getInstance().saveToFile();
}

if (!projectName.equals(projectConfig.getProjectName())) {
// Project got renamed
projectName = projectConfig.getProjectName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.apache.hop.projects.project;

import java.io.File;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.hop.core.Const;
Expand Down Expand Up @@ -56,10 +59,6 @@
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

import java.io.File;
import java.util.Collections;
import java.util.List;

public class ProjectDialog extends Dialog {
private static final Class<?> PKG = ProjectDialog.class; // For Translator

Expand All @@ -86,10 +85,8 @@ public class ProjectDialog extends Dialog {
private TableView wVariables;

private final IVariables variables;

private boolean needingProjectRefresh;

private final String originalName;
private final Boolean editMode;

public ProjectDialog(
Expand All @@ -108,7 +105,6 @@ public ProjectDialog(

this.variables = new Variables();
this.variables.initializeFrom(null);
this.originalName = projectConfig.getProjectName();
try {
project.modifyVariables(variables, projectConfig, Collections.emptyList(), null);
} catch (Exception e) {
Expand Down Expand Up @@ -509,15 +505,34 @@ private void ok() {
// Do some extra validations to prevent bad data ending up in the projects configuration
//

String oriProjectName = projectConfig.getProjectName();
String oriProjectHome = projectConfig.getProjectHome();

String homeFolder = wHome.getText();
boolean projectHomeFolderChanged = this.editMode && !oriProjectHome.equals(homeFolder);

if (StringUtils.isEmpty(variables.resolve(homeFolder))) {
throw new HopException("Please specify a home folder for your project");
}

// Manage changing in project's home folder
if (projectHomeFolderChanged) {
MessageBox box = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
box.setText(BaseMessages.getString(PKG, "ProjectDialog.ChangeHome.Dialog.Header"));
box.setMessage(
BaseMessages.getString(
PKG, "ProjectDialog.ChangeHome.Dialog.Message", oriProjectHome, homeFolder));
int anwser = box.open();
if ((anwser & SWT.NO) != 0) {
wHome.setText(oriProjectHome);
projectHomeFolderChanged = false;
}
}

// If the home folder doesn't exist and project is new aks if want it created
if (!HopVfs.getFileObject(variables.resolve(homeFolder)).exists() && !this.editMode) {
MessageBox box =
new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
if (!HopVfs.getFileObject(variables.resolve(homeFolder)).exists()
&& (!this.editMode || projectHomeFolderChanged)) {
MessageBox box = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
box.setText(BaseMessages.getString(PKG, "ProjectDialog.CreateHome.Dialog.Header"));
box.setMessage(
BaseMessages.getString(PKG, "ProjectDialog.CreateHome.Dialog.Message", homeFolder));
Expand All @@ -527,17 +542,6 @@ private void ok() {
}
}

// Definitely check if home folder exists or not
if (!HopVfs.getFileObject(variables.resolve(homeFolder)).exists()) {
String msgPre = "Please specify an existing home folder for your project. Folder '";
String msgPost = "' doesn't seem to exist.";
if (this.editMode) {
msgPre = "Project '" + wName.getText() + " is already existing. Changing its home directory to '";
msgPost = "' is not supported!";
}
throw new HopException(msgPre + homeFolder + msgPost);
}

// Renaming the project is not supported
String projectName = wName.getText();
if (StringUtils.isEmpty(projectName)) {
Expand All @@ -553,19 +557,18 @@ private void ok() {
}

if (wParentProject.getText() != null
&& wParentProject.getText().length() > 0
&& !wParentProject.getText().isEmpty()
&& projectName.equals(wParentProject.getText())) {
throw new HopException(
"Project '" + projectName + "' cannot be set as a parent project of itself");
}

ProjectsConfig prjsCfg = ProjectsConfigSingleton.getConfig();
List<String> prjs = prjsCfg.listProjectConfigNames();
String prevProjectName = projectConfig.getProjectName();

// Check if project name is unique otherwise force the user to change it!
if (StringUtils.isEmpty(originalName)
|| (StringUtils.isNotEmpty(originalName) && !projectName.equals(originalName))) {
if (StringUtils.isEmpty(oriProjectName)
|| (StringUtils.isNotEmpty(oriProjectName) && !projectName.equals(oriProjectName))) {
for (String prj : prjs) {
if (projectName.equals(prj)) {
throw new HopException(
Expand All @@ -575,7 +578,7 @@ private void ok() {
}

HopGui hopGui = HopGui.getInstance();
if (wParentProject.getText() != null && wParentProject.getText().length() > 0) {
if (wParentProject.getText() != null && !wParentProject.getText().isEmpty()) {

boolean parentPrjExists = ProjectsUtil.projectExists(wParentProject.getText());
if (!parentPrjExists)
Expand All @@ -596,17 +599,28 @@ private void ok() {
+ "' as parent project because we are going to create a circular reference!");
}

if (!prevProjectName.equals(projectName)) {
List<String> refs = ProjectsUtil.getParentProjectReferences(prevProjectName);
// Manage changing in project's home folder
if (this.editMode && !oriProjectName.equals(projectName)) {
MessageBox box = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
box.setText(BaseMessages.getString(PKG, "ProjectDialog.ChangeProjectName.Dialog.Header"));
box.setMessage(
BaseMessages.getString(
PKG,
"ProjectDialog.ChangeProjectName.Dialog.Message",
oriProjectName,
projectName));
int anwser = box.open();
if ((anwser & SWT.NO) != 0) {
wName.setText(oriProjectName);
}
}

// Change references to project's name if it changed
if (!oriProjectName.equals(projectName)) {
List<String> refs = ProjectsUtil.getParentProjectReferences(oriProjectName);

if (!refs.isEmpty()) {
throw new HopException(
"Project '"
+ prevProjectName
+ "' cannot cannot be renamed in '"
+ projectName
+ "' because is referenced in following projects: "
+ String.join(",", refs));
ProjectsUtil.changeParentProjectReferences(oriProjectName, projectName);
}
}

Expand Down Expand Up @@ -722,7 +736,9 @@ public boolean isNeedingProjectRefresh() {
return needingProjectRefresh;
}

/** @param needingProjectRefresh The variablesChanged to set */
/**
* @param needingProjectRefresh The variablesChanged to set
*/
public void setNeedingProjectRefresh(boolean needingProjectRefresh) {
this.needingProjectRefresh = needingProjectRefresh;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,34 @@ public static List<String> getParentProjectReferences(String projectName) throws
}
return parentProjectReferences;
}

public static List<String> changeParentProjectReferences(String currentName, String newName) throws HopException {

ProjectsConfig config = ProjectsConfigSingleton.getConfig();
List<String> prjs = config.listProjectConfigNames();

HopGui hopGui = HopGui.getInstance();
List<String> parentProjectReferences = new ArrayList<>();
ProjectConfig currentProjectConfig = config.findProjectConfig(currentName);

if (currentProjectConfig == null) {
parentProjectReferences = Collections.EMPTY_LIST;
} else {
for (String prj : prjs) {
if (!prj.equals(currentName)) {
ProjectConfig prjCfg = config.findProjectConfig(prj);
Project thePrj = prjCfg.loadProject(hopGui.getVariables());
if (thePrj != null) {
if (thePrj.getParentProjectName() != null
&& thePrj.getParentProjectName().equals(currentName)) {
thePrj.setParentProjectName(newName);
}
} else {
hopGui.getLog().logError("Unable to load project '" + prj + "' from its configuration");
}
}
}
}
return parentProjectReferences;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ ProjectDialog.FileList.PrjFiles.Text=Project Config File (*.json)
ProjectDialog.FileList.AllFiles.Text=All Files (*.*)
ProjectDialog.CreateHome.Dialog.Header=Create project''s home?
ProjectDialog.CreateHome.Dialog.Message=The project''s home folder ''{0}'' does not exist! Do you want to create it?
ProjectDialog.ChangeHome.Dialog.Header=Change project''s home?
ProjectDialog.ChangeHome.Dialog.Message=WARNING! Project''s HOME folder changed from ''{0}'' to ''{1}''!\nThis change can result to unexpected results. Are you sure you want to change it?
ProjectDialog.ChangeProjectName.Dialog.Header=Change project''s name?
ProjectDialog.ChangeProjectName.Dialog.Message=WARNING! Project''s name changed from ''{0}'' to ''{1}''! Are you sure you want to change it?



Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ ProjectGuiPlugin.WrongConfigPath.Dialog.Header=Riferimento alla radice del proge
ProjectGuiPlugin.WrongConfigPath.Dialog.Message=Il percorso al file project-config.json selezionato \u00E8 al di fuori del perimetro del progetto. Questo non \u00E8 permesso!
ProjectDialog.CreateHome.Dialog.Header=Creo la home del progetto?
ProjectDialog.CreateHome.Dialog.Message=La cartella home del progetto ''{0}'' non esiste! La vuoi creare?
ProjectDialog.ChangeHome.Dialog.Header=Modifica alla home del progetto
ProjectDialog.ChangeHome.Dialog.Message=ATTENZIONE! La cartella HOME del progetto \u00E8 stata modificata dalla precedente ''{0}'' alla corrente ''{1}''!\nIl cambiamento potrebbe generare problemi non previsti. Sei davvero sicuro di volerla modificare?
ProjectDialog.ChangeProjectName.Dialog.Header=Modifica al nome del progetto
ProjectDialog.ChangeProjectName.Dialog.Message=ATTENZIONE! il nome del progetto \u00E8 stata modificata dal precedente ''{0}'' al corrente ''{1}''! Sei sicuro di volerlo modificare?

2 changes: 1 addition & 1 deletion plugins/transforms/monetdbbulkloader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<packaging>jar</packaging>

<properties>
<monetdb-jdbc.version>3.1</monetdb-jdbc.version>
<monetdb-jdbc.version>3.3</monetdb-jdbc.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.apache.hop.pipeline.transforms.monetdbbulkloader;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.apache.hop.core.Const;
import org.apache.hop.core.SqlStatement;
import org.apache.hop.core.database.Database;
Expand All @@ -38,12 +41,9 @@
import org.apache.hop.pipeline.transform.TransformMeta;
import org.monetdb.mcl.io.BufferedMCLReader;
import org.monetdb.mcl.io.BufferedMCLWriter;
import org.monetdb.mcl.io.LineType;
import org.monetdb.mcl.net.MapiSocket;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public class MonetDbBulkLoader extends BaseTransform<MonetDbBulkLoaderMeta, MonetDbBulkLoaderData> {
private static final Class<?> PKG =
MonetDbBulkLoaderMeta.class; // for i18n purposes, needed by Translator2!!
Expand Down Expand Up @@ -99,7 +99,7 @@ public boolean execute(MonetDbBulkLoaderMeta meta) throws HopException {
data.in = mserver.getReader();
data.out = mserver.getWriter();

String error = data.in.waitForPrompt();
String error = data.in.discardRemainder();
if (error != null) {
throw new HopException("Error while connecting to MonetDB for bulk loading : " + error);
}
Expand Down Expand Up @@ -498,15 +498,15 @@ protected void writeBufferToMonetDB(DatabaseMeta dm) throws HopException {
}

// wait for the prompt
String error = data.in.waitForPrompt();
String error = data.in.discardRemainder();
if (error != null) {
throw new HopException(ERROR_LOADING_DATA + error);
}
// write an empty line, forces the flush of the stream
data.out.writeLine("");

// again...
error = data.in.waitForPrompt();
error = data.in.discardRemainder();
if (error != null) {
throw new HopException(ERROR_LOADING_DATA + error);
}
Expand All @@ -516,7 +516,7 @@ protected void writeBufferToMonetDB(DatabaseMeta dm) throws HopException {
data.out.writeLine("");

// again...
error = data.in.waitForPrompt();
error = data.in.discardRemainder();
if (error != null) {
throw new HopException(ERROR_LOADING_DATA + error);
}
Expand Down Expand Up @@ -700,7 +700,7 @@ protected static void executeSql(
BufferedMCLReader in = mserver.getReader();
BufferedMCLWriter out = mserver.getWriter();

String error = in.waitForPrompt();
String error = in.discardRemainder();
if (error != null) {
throw new Exception("ERROR waiting for input reader: " + error);
}
Expand All @@ -715,20 +715,20 @@ protected static void executeSql(

out.writeLine("");

while (in.readLine() != null) {
int type = in.getLineType();
while (in.getLine() != null) {
in.advance();
LineType type = in.getLineType();

// read till we get back to the prompt
if (type == BufferedMCLReader.PROMPT) {
if (type == LineType.PROMPT) {
break;
}

switch (type) {
case BufferedMCLReader.ERROR:
break;
case BufferedMCLReader.RESULT:
break;
default:
case ERROR:
case RESULT:
break;
default:
// unknown, header, ...
break;
}
Expand Down
Loading
Loading