use of org.apache.hop.projects.project.Project in project hop by apache.
the class ProjectsGuiPlugin method addNewProject.
@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_PROJECT_ADD, toolTip = "i18n::HopGui.Toolbar.Project.Add.Tooltip", image = "project-add.svg")
public void addNewProject() {
HopGui hopGui = HopGui.getInstance();
IVariables variables = hopGui.getVariables();
try {
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
String standardProjectsFolder = variables.resolve(config.getStandardProjectsFolder());
String defaultProjectConfigFilename = variables.resolve(config.getDefaultProjectConfigFile());
ProjectConfig projectConfig = new ProjectConfig("", standardProjectsFolder, defaultProjectConfigFilename);
Project project = new Project();
project.setParentProjectName(config.getStandardParentProject());
ProjectDialog projectDialog = new ProjectDialog(hopGui.getShell(), project, projectConfig, variables, false);
String projectName = projectDialog.open();
if (projectName != null) {
config.addProjectConfig(projectConfig);
HopConfig.getInstance().saveToFile();
// Save the project-config.json file as well in the project itself
//
FileObject configFile = HopVfs.getFileObject(projectConfig.getActualProjectConfigFilename(variables));
if (!configFile.exists()) {
// Create the empty configuration file if it does not exists
project.saveToFile();
} else {
// If projects exists load configuration
MessageBox box = new MessageBox(hopGui.getShell(), SWT.ICON_QUESTION | SWT.OK);
box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.ProjectExists.Dialog.Header"));
box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.ProjectExists.Dialog.Message"));
box.open();
project.readFromFile();
}
refreshProjectsList();
selectProjectInList(projectName);
enableHopGuiProject(projectName, project, null);
// Now see if these project contains any local run configurations.
// If not we can add those automatically
//
// First pipeline
//
IHopMetadataSerializer<PipelineRunConfiguration> prcSerializer = hopGui.getMetadataProvider().getSerializer(PipelineRunConfiguration.class);
List<PipelineRunConfiguration> pipelineRunConfigs = prcSerializer.loadAll();
boolean localFound = false;
for (PipelineRunConfiguration pipelineRunConfig : pipelineRunConfigs) {
if (pipelineRunConfig.getEngineRunConfiguration() instanceof LocalPipelineRunConfiguration) {
localFound = true;
}
}
if (!localFound) {
PipelineExecutionConfigurationDialog.createLocalPipelineConfiguration(hopGui.getShell(), prcSerializer);
}
// Then the local workflow runconfig
//
IHopMetadataSerializer<WorkflowRunConfiguration> wrcSerializer = hopGui.getMetadataProvider().getSerializer(WorkflowRunConfiguration.class);
localFound = false;
List<WorkflowRunConfiguration> workflowRunConfigs = wrcSerializer.loadAll();
for (WorkflowRunConfiguration workflowRunConfig : workflowRunConfigs) {
if (workflowRunConfig.getEngineRunConfiguration() instanceof LocalWorkflowRunConfiguration) {
localFound = true;
}
}
if (!localFound) {
MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfig.Dialog.Header"));
box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfig.Dialog.Message"));
int anwser = box.open();
if ((anwser & SWT.YES) != 0) {
LocalWorkflowRunConfiguration localWorkflowRunConfiguration = new LocalWorkflowRunConfiguration();
localWorkflowRunConfiguration.setEnginePluginId("Local");
WorkflowRunConfiguration local = new WorkflowRunConfiguration("local", BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfigDescription.Text"), localWorkflowRunConfiguration);
wrcSerializer.save(local);
}
}
// Ask to put the project in a lifecycle environment
//
MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Header"));
box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Message1") + Const.CR + BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Message2"));
int anwser = box.open();
if ((anwser & SWT.YES) != 0) {
addNewEnvironment();
}
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddProject.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddProject.Error.Dialog.Message"), e);
}
}
use of org.apache.hop.projects.project.Project in project hop by apache.
the class ProjectsGuiPlugin method addNewEnvironment.
@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_ENVIRONMENT_ADD, toolTip = "i18n::HopGui.Toolbar.Environment.Add.Tooltip", image = "environment-add.svg")
public void addNewEnvironment() {
HopGui hopGui = HopGui.getInstance();
try {
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
// The default is the active project
String projectName = getProjectsCombo().getText();
LifecycleEnvironment environment = new LifecycleEnvironment(null, "", projectName, new ArrayList<>());
LifecycleEnvironmentDialog dialog = new LifecycleEnvironmentDialog(hopGui.getShell(), environment, hopGui.getVariables());
String environmentName = dialog.open();
if (environmentName != null) {
config.addEnvironment(environment);
ProjectsConfigSingleton.saveConfig();
refreshEnvironmentsList();
selectEnvironmentInList(environmentName);
ProjectConfig projectConfig = config.findProjectConfig(projectName);
if (projectConfig != null) {
Project project = projectConfig.loadProject(hopGui.getVariables());
enableHopGuiProject(projectName, project, environment);
}
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddEnvironment.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddEnvironment.Error.Dialog.Message"), e);
}
}
use of org.apache.hop.projects.project.Project in project hop by apache.
the class ProjectsGuiPlugin method selectProject.
@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_PROJECT_COMBO, type = GuiToolbarElementType.COMBO, comboValuesMethod = "getProjectsList", extraWidth = 200, toolTip = "i18n::HopGui.Toolbar.ProjectsList.Tooltip")
public void selectProject() {
HopGui hopGui = HopGui.getInstance();
Combo combo = getProjectsCombo();
if (combo == null) {
return;
}
String projectName = combo.getText();
if (StringUtils.isEmpty(projectName)) {
return;
}
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
ProjectConfig projectConfig = config.findProjectConfig(projectName);
// What is the last used environment?
//
LifecycleEnvironment environment = null;
//
try {
List<AuditEvent> environmentAuditEvents = AuditManager.findEvents(ProjectsUtil.STRING_PROJECTS_AUDIT_GROUP, ProjectsUtil.STRING_ENVIRONMENT_AUDIT_TYPE, "open", 100, true);
for (AuditEvent auditEvent : environmentAuditEvents) {
String environmentName = auditEvent.getName();
if (StringUtils.isNotEmpty(environmentName)) {
environment = config.findEnvironment(environmentName);
//
if (projectName.equals(environment.getProjectName())) {
// We found what we've been looking for
break;
} else {
// The project doesn't to the last selected environment
// Since we selected the project it is the driver of the selection.
// Keep looking.
//
environment = null;
}
}
}
} catch (Exception e) {
LogChannel.UI.logError("Error reading the last used environment from the audit logs", e);
}
//
if (environment == null) {
List<LifecycleEnvironment> environments = config.findEnvironmentsOfProject(projectName);
if (!environments.isEmpty()) {
environment = environments.get(0);
}
}
try {
Project project = projectConfig.loadProject(hopGui.getVariables());
if (project != null) {
enableHopGuiProject(projectName, project, environment);
} else {
hopGui.getLog().logError("Unable to find project '" + projectName + "'");
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.ChangeProject.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.ChangeProject.Error.Dialog.Message", projectName), e);
}
}
use of org.apache.hop.projects.project.Project in project hop by apache.
the class ProjectsGuiPlugin method menuProjectExport.
@GuiMenuElement(root = HopGui.ID_MAIN_MENU, id = ID_MAIN_MENU_PROJECT_EXPORT, label = "i18n::HopGui.FileMenu.Project.Export.Label", image = "export.svg", parentId = HopGui.ID_MAIN_MENU_FILE, separator = false)
public void menuProjectExport() {
HopGui hopGui = HopGui.getInstance();
Shell shell = hopGui.getShell();
String zipFilename = BaseDialog.presentFileDialog(true, shell, new String[] { "*.zip", "*.*" }, new String[] { "Zip files (*.zip)", "All Files (*.*)" }, true);
if (zipFilename == null) {
return;
}
Combo combo = getProjectsCombo();
if (combo == null) {
return;
}
String projectName = combo.getText();
if (StringUtils.isEmpty(projectName)) {
return;
}
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
ProjectConfig projectConfig = config.findProjectConfig(projectName);
String projectHome = projectConfig.getProjectHome();
try {
IRunnableWithProgress op = monitor -> {
try {
monitor.setTaskName(BaseMessages.getString(PKG, "ProjectGuiPlugin.ZipDirectory.Taskname.Text"));
OutputStream outputStream = HopVfs.getOutputStream(zipFilename, false);
ZipOutputStream zos = new ZipOutputStream(outputStream);
FileObject projectDirectory = HopVfs.getFileObject(projectHome);
String projectHomeFolder = HopVfs.getFileObject(projectHome).getParent().getName().getURI();
zipFile(projectDirectory, projectDirectory.getName().getURI(), zos, projectHomeFolder);
zos.close();
outputStream.close();
monitor.done();
} catch (Exception e) {
throw new InvocationTargetException(e, "Error zipping project: " + e.getMessage());
}
};
ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
pmd.run(false, op);
GuiResource.getInstance().toClipboard(zipFilename);
MessageBox box = new MessageBox(shell, SWT.CLOSE | SWT.ICON_INFORMATION);
box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.ZipDirectory.Dialog.Header"));
box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.ZipDirectory.Dialog.Message1", zipFilename) + Const.CR + BaseMessages.getString(PKG, "ProjectGuiPlugin.ZipDirectory.Dialog.Message2"));
box.open();
} catch (Exception e) {
new ErrorDialog(HopGui.getInstance().getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.ZipDirectory.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.ZipDirectory.Error.Dialog.Message"), e);
}
}
use of org.apache.hop.projects.project.Project in project hop by apache.
the class ProjectsOptionPlugin method handleOption.
@Override
public boolean handleOption(ILogChannel log, IHasHopMetadataProvider hasHopMetadataProvider, IVariables variables) throws HopException {
config = ProjectsConfigSingleton.getConfig();
projectConfig = null;
configurationFiles = new ArrayList<>();
projectName = projectOption;
environmentName = environmentOption;
//
if (StringUtils.isEmpty(environmentName)) {
environmentName = config.getDefaultEnvironment();
}
//
if (config.isEnvironmentMandatory() && StringUtils.isEmpty(environmentName)) {
throw new HopException("Use of an environment is configured to be mandatory and none was specified.");
}
//
if (StringUtils.isEmpty(projectName)) {
projectName = config.getDefaultProject();
}
//
if (config.isProjectMandatory() && StringUtils.isEmpty(projectName)) {
throw new HopException("Use of a project is configured to be mandatory and none was specified.");
}
if (StringUtils.isNotEmpty(environmentName)) {
// The environment contains extra configuration options we need to pass along...
//
environment = config.findEnvironment(environmentName);
if (environment == null) {
throw new HopException("Unable to find lifecycle environment '" + environmentName + "'");
}
projectName = environment.getProjectName();
if (StringUtils.isEmpty(projectName)) {
throw new HopException("Lifecycle environment '" + environmentOption + "' is not referencing a project.");
}
projectConfig = config.findProjectConfig(projectName);
if (projectConfig == null) {
throw new HopException("Unable to find project '" + projectName + "' referenced in environment '" + environmentName);
}
configurationFiles.addAll(environment.getConfigurationFiles());
log.logBasic("Referencing environment '" + environmentOption + "' for project " + projectName + "' in " + environment.getPurpose());
} else if (StringUtils.isNotEmpty(projectName)) {
// Simply reference the project directly without extra configuration files...
//
projectConfig = config.findProjectConfig(projectName);
if (projectConfig == null) {
throw new HopException("Unable to find project '" + projectName + "'");
}
projectName = projectConfig.getProjectName();
} else {
log.logDebug("No project or environment referenced.");
return false;
}
try {
Project project = projectConfig.loadProject(variables);
log.logBasic("Enabling project '" + projectName + "'");
if (project == null) {
throw new HopException("Project '" + projectName + "' couldn't be found");
}
// Now we just enable this project
//
ProjectsUtil.enableProject(log, projectName, project, variables, configurationFiles, environmentName, hasHopMetadataProvider);
return true;
} catch (Exception e) {
throw new HopException("Error enabling project '" + projectName + "'", e);
}
}
Aggregations