Search in sources :

Example 21 with RepositoryDirectoryInterface

use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.

the class KettleFileRepository method getTransformationNames.

@Override
public String[] getTransformationNames(ObjectId id_directory, boolean includeDeleted) throws KettleException {
    try {
        List<String> list = new ArrayList<String>();
        RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface directory = tree.findDirectory(id_directory);
        String folderName = calcDirectoryName(directory);
        FileObject folder = KettleVFS.getFileObject(folderName);
        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    String name = child.getName().getBaseName();
                    if (name.endsWith(EXT_TRANSFORMATION)) {
                        String transName = name.substring(0, name.length() - 4);
                        list.add(transName);
                    }
                }
            }
        }
        return list.toArray(new String[list.size()]);
    } catch (Exception e) {
        throw new KettleException("Unable to get list of transformations names in folder with id : " + id_directory, e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Example 22 with RepositoryDirectoryInterface

use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.

the class JobDialog method addJobTab.

private void addJobTab() {
    // ////////////////////////
    // START OF JOB TAB///
    // /
    wJobTab = new CTabItem(wTabFolder, SWT.NONE);
    wJobTab.setText(BaseMessages.getString(PKG, "JobDialog.JobTab.Label"));
    Composite wJobComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wJobComp);
    FormLayout transLayout = new FormLayout();
    transLayout.marginWidth = Const.MARGIN;
    transLayout.marginHeight = Const.MARGIN;
    wJobComp.setLayout(transLayout);
    // Jobname:
    wlJobname = new Label(wJobComp, SWT.RIGHT);
    wlJobname.setText(BaseMessages.getString(PKG, "JobDialog.JobName.Label"));
    props.setLook(wlJobname);
    fdlJobname = new FormData();
    fdlJobname.left = new FormAttachment(0, 0);
    fdlJobname.right = new FormAttachment(middle, -margin);
    fdlJobname.top = new FormAttachment(0, margin);
    wlJobname.setLayoutData(fdlJobname);
    wJobname = new Text(wJobComp, rep == null ? SWT.SINGLE | SWT.LEFT | SWT.BORDER : SWT.SINGLE | SWT.LEFT | SWT.BORDER | SWT.READ_ONLY);
    wJobname.setEnabled(rep == null);
    props.setLook(wJobname);
    wJobname.addModifyListener(lsMod);
    fdJobname = new FormData();
    fdJobname.left = new FormAttachment(middle, 0);
    fdJobname.top = new FormAttachment(0, margin);
    fdJobname.right = new FormAttachment(100, 0);
    wJobname.setLayoutData(fdJobname);
    // JobFilename:
    wlJobFilename = new Label(wJobComp, SWT.RIGHT);
    wlJobFilename.setText(BaseMessages.getString(PKG, "JobDialog.JobFilename.Label"));
    props.setLook(wlJobFilename);
    fdlJobFilename = new FormData();
    fdlJobFilename.left = new FormAttachment(0, 0);
    fdlJobFilename.right = new FormAttachment(middle, -margin);
    fdlJobFilename.top = new FormAttachment(wJobname, margin);
    wlJobFilename.setLayoutData(fdlJobFilename);
    wJobFilename = new Text(wJobComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wJobFilename);
    wJobFilename.addModifyListener(lsMod);
    fdJobFilename = new FormData();
    fdJobFilename.left = new FormAttachment(middle, 0);
    fdJobFilename.top = new FormAttachment(wJobname, margin);
    fdJobFilename.right = new FormAttachment(100, 0);
    wJobFilename.setLayoutData(fdJobFilename);
    wJobFilename.setEditable(false);
    wJobFilename.setBackground(GUIResource.getInstance().getColorLightGray());
    // Job description:
    Label wlJobdescription = new Label(wJobComp, SWT.RIGHT);
    wlJobdescription.setText(BaseMessages.getString(PKG, "JobDialog.Jobdescription.Label"));
    props.setLook(wlJobdescription);
    FormData fdlJobdescription = new FormData();
    fdlJobdescription.left = new FormAttachment(0, 0);
    fdlJobdescription.right = new FormAttachment(middle, -margin);
    fdlJobdescription.top = new FormAttachment(wJobFilename, margin);
    wlJobdescription.setLayoutData(fdlJobdescription);
    wJobdescription = new Text(wJobComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wJobdescription);
    wJobdescription.addModifyListener(lsMod);
    FormData fdJobdescription = new FormData();
    fdJobdescription.left = new FormAttachment(middle, 0);
    fdJobdescription.top = new FormAttachment(wJobFilename, margin);
    fdJobdescription.right = new FormAttachment(100, 0);
    wJobdescription.setLayoutData(fdJobdescription);
    // Transformation Extended description
    wlExtendeddescription = new Label(wJobComp, SWT.RIGHT);
    wlExtendeddescription.setText(BaseMessages.getString(PKG, "JobDialog.Extendeddescription.Label"));
    props.setLook(wlExtendeddescription);
    fdlExtendeddescription = new FormData();
    fdlExtendeddescription.left = new FormAttachment(0, 0);
    fdlExtendeddescription.top = new FormAttachment(wJobdescription, margin);
    fdlExtendeddescription.right = new FormAttachment(middle, -margin);
    wlExtendeddescription.setLayoutData(fdlExtendeddescription);
    wExtendeddescription = new Text(wJobComp, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    props.setLook(wExtendeddescription, Props.WIDGET_STYLE_FIXED);
    wExtendeddescription.addModifyListener(lsMod);
    fdExtendeddescription = new FormData();
    fdExtendeddescription.left = new FormAttachment(middle, 0);
    fdExtendeddescription.top = new FormAttachment(wJobdescription, margin);
    fdExtendeddescription.right = new FormAttachment(100, 0);
    fdExtendeddescription.bottom = new FormAttachment(50, -margin);
    wExtendeddescription.setLayoutData(fdExtendeddescription);
    // Trans Status
    wlJobstatus = new Label(wJobComp, SWT.RIGHT);
    wlJobstatus.setText(BaseMessages.getString(PKG, "JobDialog.Jobstatus.Label"));
    props.setLook(wlJobstatus);
    fdlJobstatus = new FormData();
    fdlJobstatus.left = new FormAttachment(0, 0);
    fdlJobstatus.right = new FormAttachment(middle, 0);
    fdlJobstatus.top = new FormAttachment(wExtendeddescription, margin * 2);
    wlJobstatus.setLayoutData(fdlJobstatus);
    wJobstatus = new CCombo(wJobComp, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
    wJobstatus.add(BaseMessages.getString(PKG, "JobDialog.Draft_Jobstatus.Label"));
    wJobstatus.add(BaseMessages.getString(PKG, "JobDialog.Production_Jobstatus.Label"));
    wJobstatus.add("");
    // +1: starts at -1
    wJobstatus.select(-1);
    props.setLook(wJobstatus);
    fdJobstatus = new FormData();
    fdJobstatus.left = new FormAttachment(middle, 0);
    fdJobstatus.top = new FormAttachment(wExtendeddescription, margin * 2);
    fdJobstatus.right = new FormAttachment(100, 0);
    wJobstatus.setLayoutData(fdJobstatus);
    // Job version:
    Label wlJobversion = new Label(wJobComp, SWT.RIGHT);
    wlJobversion.setText(BaseMessages.getString(PKG, "JobDialog.Jobversion.Label"));
    props.setLook(wlJobversion);
    FormData fdlJobversion = new FormData();
    fdlJobversion.left = new FormAttachment(0, 0);
    fdlJobversion.right = new FormAttachment(middle, -margin);
    fdlJobversion.top = new FormAttachment(wJobstatus, margin);
    wlJobversion.setLayoutData(fdlJobversion);
    wJobversion = new Text(wJobComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wJobversion);
    wJobversion.addModifyListener(lsMod);
    FormData fdJobversion = new FormData();
    fdJobversion.left = new FormAttachment(middle, 0);
    fdJobversion.top = new FormAttachment(wJobstatus, margin);
    fdJobversion.right = new FormAttachment(100, 0);
    wJobversion.setLayoutData(fdJobversion);
    // Directory:
    wlDirectory = new Label(wJobComp, SWT.RIGHT);
    wlDirectory.setText(BaseMessages.getString(PKG, "JobDialog.Directory.Label"));
    props.setLook(wlDirectory);
    fdlDirectory = new FormData();
    fdlDirectory.left = new FormAttachment(0, 0);
    fdlDirectory.right = new FormAttachment(middle, -margin);
    fdlDirectory.top = new FormAttachment(wJobversion, margin);
    wlDirectory.setLayoutData(fdlDirectory);
    wbDirectory = new Button(wJobComp, SWT.PUSH);
    wbDirectory.setToolTipText(BaseMessages.getString(PKG, "JobDialog.SelectJobFolderFolder.Tooltip"));
    wbDirectory.setImage(GUIResource.getInstance().getImageArrow());
    props.setLook(wbDirectory);
    fdbDirectory = new FormData();
    fdbDirectory.top = new FormAttachment(wJobversion, 0);
    fdbDirectory.right = new FormAttachment(100, 0);
    wbDirectory.setLayoutData(fdbDirectory);
    wbDirectory.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent arg0) {
            RepositoryDirectoryInterface directoryFrom = jobMeta.getRepositoryDirectory();
            RepositoryDirectoryInterface rd = RepositoryDirectoryUI.chooseDirectory(shell, rep, directoryFrom);
            if (rd == null) {
                return;
            }
            // We need to change this in the repository as well!!
            // We do this when the user pressed OK
            newDirectory = rd;
            wDirectory.setText(rd.getPath());
        }
    });
    wDirectory = new Text(wJobComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDirectory);
    wDirectory.setToolTipText(BaseMessages.getString(PKG, "JobDialog.Directory.Tooltip"));
    wDirectory.setEditable(false);
    wDirectory.setEnabled(false);
    fdDirectory = new FormData();
    fdDirectory.top = new FormAttachment(wJobversion, margin);
    fdDirectory.left = new FormAttachment(middle, 0);
    fdDirectory.right = new FormAttachment(wbDirectory, 0);
    wDirectory.setLayoutData(fdDirectory);
    // Create User:
    Label wlCreateUser = new Label(wJobComp, SWT.RIGHT);
    wlCreateUser.setText(BaseMessages.getString(PKG, "JobDialog.CreateUser.Label"));
    props.setLook(wlCreateUser);
    FormData fdlCreateUser = new FormData();
    fdlCreateUser.left = new FormAttachment(0, 0);
    fdlCreateUser.right = new FormAttachment(middle, -margin);
    fdlCreateUser.top = new FormAttachment(wDirectory, margin);
    wlCreateUser.setLayoutData(fdlCreateUser);
    wCreateUser = new Text(wJobComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCreateUser);
    wCreateUser.setEditable(false);
    wCreateUser.addModifyListener(lsMod);
    FormData fdCreateUser = new FormData();
    fdCreateUser.left = new FormAttachment(middle, 0);
    fdCreateUser.top = new FormAttachment(wDirectory, margin);
    fdCreateUser.right = new FormAttachment(100, 0);
    wCreateUser.setLayoutData(fdCreateUser);
    // Created Date:
    Label wlCreateDate = new Label(wJobComp, SWT.RIGHT);
    wlCreateDate.setText(BaseMessages.getString(PKG, "JobDialog.CreateDate.Label"));
    props.setLook(wlCreateDate);
    FormData fdlCreateDate = new FormData();
    fdlCreateDate.left = new FormAttachment(0, 0);
    fdlCreateDate.right = new FormAttachment(middle, -margin);
    fdlCreateDate.top = new FormAttachment(wCreateUser, margin);
    wlCreateDate.setLayoutData(fdlCreateDate);
    wCreateDate = new Text(wJobComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wCreateDate);
    wCreateDate.setEditable(false);
    wCreateDate.addModifyListener(lsMod);
    FormData fdCreateDate = new FormData();
    fdCreateDate.left = new FormAttachment(middle, 0);
    fdCreateDate.top = new FormAttachment(wCreateUser, margin);
    fdCreateDate.right = new FormAttachment(100, 0);
    wCreateDate.setLayoutData(fdCreateDate);
    // Modified User:
    Label wlModUser = new Label(wJobComp, SWT.RIGHT);
    wlModUser.setText(BaseMessages.getString(PKG, "JobDialog.LastModifiedUser.Label"));
    props.setLook(wlModUser);
    FormData fdlModUser = new FormData();
    fdlModUser.left = new FormAttachment(0, 0);
    fdlModUser.right = new FormAttachment(middle, -margin);
    fdlModUser.top = new FormAttachment(wCreateDate, margin);
    wlModUser.setLayoutData(fdlModUser);
    wModUser = new Text(wJobComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wModUser);
    wModUser.setEditable(false);
    wModUser.addModifyListener(lsMod);
    FormData fdModUser = new FormData();
    fdModUser.left = new FormAttachment(middle, 0);
    fdModUser.top = new FormAttachment(wCreateDate, margin);
    fdModUser.right = new FormAttachment(100, 0);
    wModUser.setLayoutData(fdModUser);
    // Modified Date:
    Label wlModDate = new Label(wJobComp, SWT.RIGHT);
    wlModDate.setText(BaseMessages.getString(PKG, "JobDialog.LastModifiedDate.Label"));
    props.setLook(wlModDate);
    FormData fdlModDate = new FormData();
    fdlModDate.left = new FormAttachment(0, 0);
    fdlModDate.right = new FormAttachment(middle, -margin);
    fdlModDate.top = new FormAttachment(wModUser, margin);
    wlModDate.setLayoutData(fdlModDate);
    wModDate = new Text(wJobComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wModDate);
    wModDate.setEditable(false);
    wModDate.addModifyListener(lsMod);
    FormData fdModDate = new FormData();
    fdModDate.left = new FormAttachment(middle, 0);
    fdModDate.top = new FormAttachment(wModUser, margin);
    fdModDate.right = new FormAttachment(100, 0);
    wModDate.setLayoutData(fdModDate);
    FormData fdJobComp = new FormData();
    fdJobComp.left = new FormAttachment(0, 0);
    fdJobComp.top = new FormAttachment(0, 0);
    fdJobComp.right = new FormAttachment(100, 0);
    fdJobComp.bottom = new FormAttachment(100, 0);
    wJobComp.setLayoutData(fdJobComp);
    wJobTab.setControl(wJobComp);
// ///////////////////////////////////////////////////////////
// / END OF JOB TAB
// ///////////////////////////////////////////////////////////
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) CCombo(org.eclipse.swt.custom.CCombo) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) CTabItem(org.eclipse.swt.custom.CTabItem) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 23 with RepositoryDirectoryInterface

use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.

the class Import method main.

public static void main(String[] a) throws KettleException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    KettleEnvironment.init();
    Props.init(Props.TYPE_PROPERTIES_SPOON);
    List<String> args = pickupCmdArguments(a);
    StringBuilder optionRepname, optionUsername, optionPassword, optionDirname;
    StringBuilder optionLimitDir, optionFilename, optionRules, optionComment;
    StringBuilder optionReplace, optionContinueOnError, optionVersion, optionFileDir, optionNoRules;
    CommandLineOption[] options = new CommandLineOption[] { // 
    createOption("rep", "Import.CmdLine.RepName", optionRepname = new StringBuilder()), createOption("user", "Import.CmdLine.RepUsername", optionUsername = new StringBuilder()), createOption("pass", "Import.CmdLine.RepPassword", optionPassword = new StringBuilder()), createOption("dir", "Import.CmdLine.RepDir", optionDirname = new StringBuilder()), createOption("limitdir", "Import.CmdLine.LimitDir", optionLimitDir = new StringBuilder()), createOption("file", "Import.CmdLine.File", optionFilename = new StringBuilder()), createOption("filedir", "Import.CmdLine.FileDir", optionFileDir = new StringBuilder()), createOption("rules", "Import.CmdLine.RulesFile", optionRules = new StringBuilder()), createOption("norules", "Import.CmdLine.NoRules", optionNoRules = new StringBuilder(), true, false), createOption("comment", "Import.CmdLine.Comment", optionComment = new StringBuilder(), false, false), createOption("replace", "Import.CmdLine.Replace", optionReplace = new StringBuilder(), true, false), createOption("coe", "Import.CmdLine.ContinueOnError", optionContinueOnError = new StringBuilder(), true, false), createOption("version", "Import.CmdLine.Version", optionVersion = new StringBuilder(), true, false), new CommandLineOption("", BaseMessages.getString(PKG, "Import.CmdLine.ExtraFiles"), new StringBuilder(), false, true, true) };
    if (args.isEmpty()) {
        CommandLineOption.printUsage(options);
        exitJVM(9);
    }
    final LogChannelInterface log = new LogChannel(STRING_IMPORT);
    CommandLineOption.parseArguments(args, options, log);
    // The arguments that are still left in args are in fact filenames that need to be imported.
    // This list is otherwise empty.
    // To that we add the normal filename option
    // 
    List<String> filenames = new ArrayList<String>(args);
    if (!Utils.isEmpty(optionFilename)) {
        filenames.add(optionFilename.toString());
    }
    String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
    String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
    String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);
    if (!Utils.isEmpty(kettleRepname)) {
        optionRepname = new StringBuilder(kettleRepname);
    }
    if (!Utils.isEmpty(kettleUsername)) {
        optionUsername = new StringBuilder(kettleUsername);
    }
    if (!Utils.isEmpty(kettlePassword)) {
        optionPassword = new StringBuilder(kettlePassword);
    }
    if (!Utils.isEmpty(optionVersion)) {
        BuildVersion buildVersion = BuildVersion.getInstance();
        log.logBasic(BaseMessages.getString(PKG, "Import.Log.KettleVersion", buildVersion.getVersion(), buildVersion.getRevision(), buildVersion.getBuildDate()));
        if (a.length == 1) {
            exitJVM(6);
        }
    }
    // 
    if (Utils.isEmpty(optionRepname)) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.NoRepProvided"));
        exitJVM(1);
    }
    if (Utils.isEmpty(filenames)) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.NoExportFileProvided"));
        exitJVM(1);
    }
    if (Utils.isEmpty(optionDirname)) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.NoRepositoryDirectoryProvided"));
        exitJVM(1);
    }
    if (Utils.isEmpty(optionRules) && Utils.isEmpty(optionNoRules) && !"Y".equalsIgnoreCase(optionNoRules.toString())) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.NoRulesFileProvided"));
        exitJVM(1);
    }
    // Load the rules file!
    // 
    ImportRules importRules = new ImportRules();
    String rulesFile = optionRules.toString();
    if (!Utils.isEmpty(rulesFile)) {
        try {
            Document document = XMLHandler.loadXMLFile(rulesFile);
            Node rulesNode = XMLHandler.getSubNode(document, ImportRules.XML_TAG);
            importRules.loadXML(rulesNode);
            log.logMinimal(BaseMessages.getString(PKG, "Import.Log.RulesLoaded", rulesFile, Integer.toString(importRules.getRules().size())));
            for (ImportRuleInterface rule : importRules.getRules()) {
                log.logBasic(" - " + rule.toString());
            }
        } catch (KettleException e) {
            log.logError(BaseMessages.getString(PKG, "Import.Log.ExceptionLoadingRules", rulesFile), e);
            exitJVM(7);
        }
    }
    // Get the list of limiting source directories
    // 
    List<String> limitDirs;
    if (!Utils.isEmpty(optionLimitDir)) {
        String[] directories = optionLimitDir.toString().split(",");
        limitDirs = Arrays.asList(directories);
    } else {
        limitDirs = Collections.emptyList();
    }
    // Find the repository metadata...
    // 
    RepositoriesMeta repsinfo = new RepositoriesMeta();
    repsinfo.getLog().setLogLevel(log.getLogLevel());
    try {
        repsinfo.readData();
    } catch (Exception e) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.UnableToLoadRepositoryInformation"), e);
        exitJVM(1);
    }
    RepositoryMeta repositoryMeta = repsinfo.findRepository(optionRepname.toString());
    if (repositoryMeta == null) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.RepositoryCouldNotBeFound", optionRepname.toString()));
        exitJVM(1);
    }
    if (Utils.isEmpty(optionRepname)) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.NoRepProvided"));
        exitJVM(1);
    }
    // Load the repository object as a plugin...
    // 
    Repository repository = null;
    try {
        repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
        repository.init(repositoryMeta);
        repository.getLog().setLogLevel(log.getLogLevel());
    } catch (Exception e) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.UnableToLoadOrInitializeRepository"));
        exitJVM(1);
    }
    try {
        repository.connect(optionUsername != null ? optionUsername.toString() : null, optionPassword != null ? optionPassword.toString() : null);
    } catch (KettleException ke) {
        log.logError(ke.getMessage());
        exitJVM(1);
    } catch (Exception e) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.UnableToConnectToRepository"));
        exitJVM(1);
    }
    final boolean replace = Utils.isEmpty(optionReplace) ? false : ValueMetaString.convertStringToBoolean(optionReplace.toString());
    final boolean continueOnError = Utils.isEmpty(optionContinueOnError) ? false : ValueMetaString.convertStringToBoolean(optionContinueOnError.toString());
    // Start the import!
    // 
    log.logMinimal(BaseMessages.getString(PKG, "Import.Log.Starting"));
    Date start, stop;
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
    start = new Date();
    int returnCode = 0;
    if (ROOT_DIRECTORY.equals(optionDirname.toString())) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.TargetDirectoryIsRootDirectory"));
        exitJVM(1);
    }
    try {
        RepositoryDirectoryInterface tree = repository.loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface targetDirectory = tree.findDirectory(optionDirname.toString());
        if (targetDirectory == null) {
            log.logError(BaseMessages.getString(PKG, "Import.Error.UnableToFindTargetDirectoryInRepository", optionDirname.toString()));
            exitJVM(1);
        }
        // Perform the actual import
        IRepositoryImporter importer = repository.getImporter();
        importer.setImportRules(importRules);
        if (!limitDirs.isEmpty()) {
            if (importer instanceof CanLimitDirs) {
                ((CanLimitDirs) importer).setLimitDirs(limitDirs);
            } else {
                throw new KettleException(BaseMessages.getString(PKG, "Import.CouldntLimitDirs", importer.getClass().getCanonicalName()));
            }
        }
        RepositoryImportFeedbackInterface feedbackInterface = new ImportFeedback(log, continueOnError, replace, reader);
        // Import files in a certain directory
        importer.importAll(feedbackInterface, optionFileDir.toString(), filenames.toArray(new String[filenames.size()]), targetDirectory, replace, continueOnError, optionComment.toString());
        // If the importer has exceptions, then our return code is 2
        List<Exception> exceptions = importer.getExceptions();
        if (exceptions != null && !exceptions.isEmpty()) {
            log.logError(BaseMessages.getString(PKG, "Import.Error.UnexpectedErrorDuringImport"), exceptions.get(0));
            returnCode = 2;
        }
    } catch (Exception e) {
        log.logError(BaseMessages.getString(PKG, "Import.Error.UnexpectedErrorDuringImport"), e);
        exitJVM(2);
    }
    log.logMinimal(BaseMessages.getString(PKG, "Import.Log.Finished"));
    stop = new Date();
    String begin = df.format(start);
    String end = df.format(stop);
    log.logMinimal(BaseMessages.getString(PKG, "Import.Log.StartStop", begin, end));
    long seconds = (stop.getTime() - start.getTime()) / 1000;
    if (seconds <= 60) {
        log.logMinimal(BaseMessages.getString(PKG, "Import.Log.ProcessEndAfter", String.valueOf(seconds)));
    } else if (seconds <= 60 * 60) {
        int min = (int) (seconds / 60);
        int rem = (int) (seconds % 60);
        log.logMinimal(BaseMessages.getString(PKG, "Import.Log.ProcessEndAfterLong", String.valueOf(min), String.valueOf(rem), String.valueOf(seconds)));
    } else if (seconds <= 60 * 60 * 24) {
        int rem;
        int hour = (int) (seconds / (60 * 60));
        rem = (int) (seconds % (60 * 60));
        int min = rem / 60;
        rem = rem % 60;
        log.logMinimal(BaseMessages.getString(PKG, "Import.Log.ProcessEndAfterLonger", String.valueOf(hour), String.valueOf(min), String.valueOf(rem), String.valueOf(seconds)));
    } else {
        int rem;
        int days = (int) (seconds / (60 * 60 * 24));
        rem = (int) (seconds % (60 * 60 * 24));
        int hour = rem / (60 * 60);
        rem = rem % (60 * 60);
        int min = rem / 60;
        rem = rem % 60;
        log.logMinimal(BaseMessages.getString(PKG, "Import.Log.ProcessEndAfterLongest", String.valueOf(days), String.valueOf(hour), String.valueOf(min), String.valueOf(rem), String.valueOf(seconds)));
    }
    exitJVM(returnCode);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) CanLimitDirs(org.pentaho.di.repository.CanLimitDirs) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Document(org.w3c.dom.Document) RepositoryImportFeedbackInterface(org.pentaho.di.repository.RepositoryImportFeedbackInterface) CommandLineOption(org.pentaho.di.pan.CommandLineOption) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) BuildVersion(org.pentaho.di.version.BuildVersion) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) InputStreamReader(java.io.InputStreamReader) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) LogChannel(org.pentaho.di.core.logging.LogChannel) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) Date(java.util.Date) IRepositoryImporter(org.pentaho.di.repository.IRepositoryImporter) Repository(org.pentaho.di.repository.Repository) BufferedReader(java.io.BufferedReader) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) SimpleDateFormat(java.text.SimpleDateFormat)

Example 24 with RepositoryDirectoryInterface

use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.

the class PurRepository_MoveAndRename_IT method moveAndRename_FailsIfANameConflictOccurs.

private void moveAndRename_FailsIfANameConflictOccurs(Assistant assistant) throws Exception {
    final String fileName = "moveAndRename_FailsIfANameConflictOccurs";
    final String renamed = fileName + "_renamed";
    AbstractMeta meta = assistant.createNew();
    AbstractMeta anotherMeta = assistant.createNew();
    RepositoryDirectoryInterface directory = getPublicDir();
    assistant.save(meta, fileName, directory);
    RepositoryDirectoryInterface destFolder = getDirInsidePublic(fileName);
    assistant.save(anotherMeta, renamed, destFolder);
    assistant.rename(meta, destFolder, renamed);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) AbstractMeta(org.pentaho.di.base.AbstractMeta)

Example 25 with RepositoryDirectoryInterface

use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.

the class PurRepository_MoveAndRename_IT method moveAndRename_Successfully.

private void moveAndRename_Successfully(Assistant assistant) throws Exception {
    final String fileName = "moveAndRename_Successfully";
    final String renamed = fileName + "_renamed";
    AbstractMeta meta = assistant.createNew();
    assistant.save(meta, fileName, getPublicDir());
    RepositoryDirectoryInterface destFolder = getDirInsidePublic(fileName);
    assertNotNull(destFolder);
    assistant.rename(meta, destFolder, renamed);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) AbstractMeta(org.pentaho.di.base.AbstractMeta)

Aggregations

RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)163 KettleException (org.pentaho.di.core.exception.KettleException)68 Test (org.junit.Test)32 TransMeta (org.pentaho.di.trans.TransMeta)30 ObjectId (org.pentaho.di.repository.ObjectId)27 JobMeta (org.pentaho.di.job.JobMeta)23 Repository (org.pentaho.di.repository.Repository)22 ArrayList (java.util.ArrayList)17 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)17 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)15 IOException (java.io.IOException)14 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)13 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)11 RepositoryObject (org.pentaho.di.repository.RepositoryObject)11 FileObject (org.apache.commons.vfs2.FileObject)10 List (java.util.List)8 TreeItem (org.eclipse.swt.widgets.TreeItem)8 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 Date (java.util.Date)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7