Search in sources :

Example 1 with HasOverwritePrompter

use of org.pentaho.di.core.gui.HasOverwritePrompter in project pentaho-kettle by pentaho.

the class RepositoryImporter method importAll.

@Override
public synchronized void importAll(RepositoryImportFeedbackInterface feedback, String fileDirectory, String[] filenames, RepositoryDirectoryInterface baseDirectory, boolean overwrite, boolean continueOnError, String versionComment) {
    this.baseDirectory = baseDirectory;
    this.overwrite = overwrite;
    this.continueOnError = continueOnError;
    this.versionComment = versionComment;
    String importPathCompatibility = System.getProperty(Const.KETTLE_COMPATIBILITY_IMPORT_PATH_ADDITION_ON_VARIABLES, "N");
    this.needToCheckPathForVariables = "N".equalsIgnoreCase(importPathCompatibility);
    askReplace = Props.getInstance().askAboutReplacingDatabaseConnections();
    if (askReplace) {
        if (feedback instanceof HasOverwritePrompter) {
            Props.getInstance().setProperty(IMPORT_ASK_ABOUT_REPLACE_CS, "Y");
            Props.getInstance().setProperty(IMPORT_ASK_ABOUT_REPLACE_DB, "Y");
            Props.getInstance().setProperty(IMPORT_ASK_ABOUT_REPLACE_PS, "Y");
            Props.getInstance().setProperty(IMPORT_ASK_ABOUT_REPLACE_SS, "Y");
            this.overwritePrompter = ((HasOverwritePrompter) feedback).getOverwritePrompter();
        } else {
            this.overwritePrompter = new OverwritePrompter() {

                @Override
                public boolean overwritePrompt(String arg0, String arg1, String arg2) {
                    throw new RuntimeException(BaseMessages.getString(PKG, "RepositoryImporter.CannotPrompt.Label"));
                }
            };
        }
    } else {
        final boolean replaceExisting = Props.getInstance().replaceExistingDatabaseConnections();
        this.overwritePrompter = new OverwritePrompter() {

            @Override
            public boolean overwritePrompt(String arg0, String arg1, String arg2) {
                return replaceExisting;
            }
        };
    }
    referencingObjects = new ArrayList<RepositoryObject>();
    feedback.setLabel(BaseMessages.getString(PKG, "RepositoryImporter.ImportXML.Label"));
    try {
        loadSharedObjects();
        RepositoryImportLocation.setRepositoryImportLocation(baseDirectory);
        for (int ii = 0; ii < filenames.length; ++ii) {
            final String filename = (!Utils.isEmpty(fileDirectory)) ? fileDirectory + Const.FILE_SEPARATOR + filenames[ii] : filenames[ii];
            if (log.isBasic()) {
                log.logBasic("Import objects from XML file [" + filename + "]");
            }
            feedback.addLog(BaseMessages.getString(PKG, "RepositoryImporter.WhichFile.Log", filename));
            // To where?
            feedback.setLabel(BaseMessages.getString(PKG, "RepositoryImporter.WhichDir.Label"));
            // 
            try {
                RepositoryExportSaxParser parser = new RepositoryExportSaxParser(filename, feedback);
                parser.parse(this);
            } catch (Exception e) {
                addException(e);
                feedback.showError(BaseMessages.getString(PKG, "RepositoryImporter.ErrorGeneral.Title"), BaseMessages.getString(PKG, "RepositoryImporter.ErrorGeneral.Message"), e);
            }
        }
        // Correct those jobs and transformations that contain references to other objects.
        for (RepositoryObject repoObject : referencingObjects) {
            switch(repoObject.getObjectType()) {
                case TRANSFORMATION:
                    TransMeta transMeta = rep.loadTransformation(repoObject.getObjectId(), null);
                    saveTransformationToRepo(transMeta, feedback);
                    break;
                case JOB:
                    JobMeta jobMeta = rep.loadJob(repoObject.getObjectId(), null);
                    saveJobToRepo(jobMeta, feedback);
                    break;
                default:
                    throw new KettleException(BaseMessages.getString(PKG, "RepositoryImporter.ErrorDetectFileType"));
            }
        }
        feedback.addLog(BaseMessages.getString(PKG, "RepositoryImporter.ImportFinished.Log"));
    } catch (Exception e) {
        addException(e);
        feedback.showError(BaseMessages.getString(PKG, "RepositoryImporter.ErrorGeneral.Title"), BaseMessages.getString(PKG, "RepositoryImporter.ErrorGeneral.Message"), e);
    } finally {
        // set the repository import location to null when done!
        RepositoryImportLocation.setRepositoryImportLocation(null);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) OverwritePrompter(org.pentaho.di.core.gui.OverwritePrompter) HasOverwritePrompter(org.pentaho.di.core.gui.HasOverwritePrompter) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) LookupReferencesException(org.pentaho.di.core.exception.LookupReferencesException) SAXParseException(org.xml.sax.SAXParseException) HasOverwritePrompter(org.pentaho.di.core.gui.HasOverwritePrompter)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)1 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 LookupReferencesException (org.pentaho.di.core.exception.LookupReferencesException)1 HasOverwritePrompter (org.pentaho.di.core.gui.HasOverwritePrompter)1 OverwritePrompter (org.pentaho.di.core.gui.OverwritePrompter)1 JobMeta (org.pentaho.di.job.JobMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 SAXParseException (org.xml.sax.SAXParseException)1