Search in sources :

Example 1 with ChangedFlagInterface

use of org.pentaho.di.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.

the class KettleFileRepository method save.

public void save(RepositoryElementInterface repositoryElement, String versionComment, ProgressMonitorListener monitor, ObjectId parentId, boolean used) throws KettleException {
    try {
        if (!(repositoryElement instanceof XMLInterface) && !(repositoryElement instanceof SharedObjectInterface)) {
            throw new KettleException("Class [" + repositoryElement.getClass().getName() + "] needs to implement the XML Interface in order to save it to disk");
        }
        if (!Utils.isEmpty(versionComment)) {
            insertLogEntry("Save repository element : " + repositoryElement.toString() + " : " + versionComment);
        }
        ObjectId objectId = new StringObjectId(calcObjectId(repositoryElement));
        FileObject fileObject = getFileObject(repositoryElement);
        String xml = ((XMLInterface) repositoryElement).getXML();
        OutputStream os = KettleVFS.getOutputStream(fileObject, false);
        os.write(xml.getBytes(Const.XML_ENCODING));
        os.close();
        if (repositoryElement instanceof ChangedFlagInterface) {
            ((ChangedFlagInterface) repositoryElement).clearChanged();
        }
        // 
        if (repositoryElement.getObjectId() != null && !repositoryElement.getObjectId().equals(objectId)) {
            delObject(repositoryElement.getObjectId());
        }
        repositoryElement.setObjectId(objectId);
        // 
        if (repositoryElement instanceof TransMeta) {
            ((TransMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
        }
        if (repositoryElement instanceof JobMeta) {
            ((JobMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
        }
    } catch (Exception e) {
        throw new KettleException("Unable to save repository element [" + repositoryElement + "] to XML file : " + calcFilename(repositoryElement), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ChangedFlagInterface(org.pentaho.di.core.changed.ChangedFlagInterface) OutputStream(java.io.OutputStream) TransMeta(org.pentaho.di.trans.TransMeta) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) FileObject(org.apache.commons.vfs2.FileObject) XMLInterface(org.pentaho.di.core.xml.XMLInterface) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 2 with ChangedFlagInterface

use of org.pentaho.di.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.

the class PurRepository method saveTransOrJob.

protected void saveTransOrJob(ISharedObjectsTransformer objectTransformer, RepositoryElementInterface element, String versionComment, Calendar versionDate, boolean saveSharedObjects, boolean checkLock, boolean checkRename, boolean loadRevision, boolean checkDeleted) throws KettleException {
    if (Import.ROOT_DIRECTORY.equals(element.getRepositoryDirectory().toString())) {
        // We don't have possibility to read this file via UI
        throw new KettleException(BaseMessages.getString(PKG, "PurRepository.fileCannotBeSavedInRootDirectory", element.getName() + element.getRepositoryElementType().getExtension()));
    }
    if (saveSharedObjects) {
        objectTransformer.saveSharedObjects(element, versionComment);
    }
    ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.BeforeSaveToRepository.id, element);
    final boolean isUpdate = (element.getObjectId() != null);
    RepositoryFile file = null;
    if (isUpdate) {
        readWriteLock.readLock().lock();
        try {
            ObjectId id = element.getObjectId();
            file = pur.getFileById(id.getId());
            if (checkLock && file.isLocked() && !unifiedRepositoryLockService.canUnlockFileById(id)) {
                throw new KettleException("File is currently locked by another user for editing");
            }
            if (checkDeleted && isInTrash(file)) {
                // absolutely awful to have UI references in this class :(
                throw new KettleException("File is in the Trash. Use Save As.");
            }
        } finally {
            readWriteLock.readLock().unlock();
        }
        readWriteLock.writeLock().lock();
        try {
            // update title and description
            file = new RepositoryFile.Builder(file).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).createdDate(versionDate != null ? versionDate.getTime() : new Date()).description(RepositoryFile.DEFAULT_LOCALE, Const.NVL(element.getDescription(), "")).build();
            file = pur.updateFile(file, new NodeRepositoryFileData(objectTransformer.elementToDataNode(element)), versionComment);
        } catch (SOAPFaultException e) {
            if (e.getMessage().contains(UnifiedRepositoryUpdateFileException.PREFIX)) {
                throw new KettleException(BaseMessages.getString(PKG, "PurRepository.fileUpdateException", file.getName()));
            }
            throw e;
        } finally {
            readWriteLock.writeLock().unlock();
        }
        if (checkRename && isRenamed(element, file)) {
            renameKettleEntity(element, null, element.getName());
        }
    } else {
        readWriteLock.writeLock().lock();
        try {
            file = new RepositoryFile.Builder(checkAndSanitize(element.getName() + element.getRepositoryElementType().getExtension())).versioned(true).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).createdDate(versionDate != null ? versionDate.getTime() : new Date()).description(RepositoryFile.DEFAULT_LOCALE, Const.NVL(element.getDescription(), "")).build();
            file = pur.createFile(element.getRepositoryDirectory().getObjectId().getId(), file, new NodeRepositoryFileData(objectTransformer.elementToDataNode(element)), versionComment);
        } catch (SOAPFaultException e) {
            if (e.getMessage().contains(UnifiedRepositoryCreateFileException.PREFIX)) {
                throw new KettleException(BaseMessages.getString(PKG, "PurRepository.fileCreateException", file.getName()));
            }
        } finally {
            readWriteLock.writeLock().unlock();
        }
    }
    // side effects
    ObjectId objectId = new StringObjectId(file.getId().toString());
    element.setObjectId(objectId);
    if (loadRevision) {
        element.setObjectRevision(getObjectRevision(objectId, null));
    }
    if (element instanceof ChangedFlagInterface) {
        ((ChangedFlagInterface) element).clearChanged();
    }
    if (element.getRepositoryElementType() == RepositoryObjectType.TRANSFORMATION) {
        TransMeta transMeta = loadTransformation(objectId, null);
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransImportAfterSaveToRepo.id, transMeta);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ChangedFlagInterface(org.pentaho.di.core.changed.ChangedFlagInterface) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) TransMeta(org.pentaho.di.trans.TransMeta) EETransMeta(org.pentaho.di.repository.pur.model.EETransMeta) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) StringObjectId(org.pentaho.di.repository.StringObjectId) Date(java.util.Date)

Example 3 with ChangedFlagInterface

use of org.pentaho.di.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.

the class PurRepository method saveDatabaseMeta.

protected void saveDatabaseMeta(final RepositoryElementInterface element, final String versionComment, Calendar versionDate) throws KettleException {
    readWriteLock.writeLock().lock();
    try {
        // 
        if (element.getObjectId() == null) {
            element.setObjectId(getDatabaseID(element.getName()));
        }
        boolean isUpdate = element.getObjectId() != null;
        RepositoryFile file = null;
        if (isUpdate) {
            file = pur.getFileById(element.getObjectId().getId());
            // update title
            final String title = ((DatabaseMeta) element).getDisplayName();
            Date modifiedDate = null;
            if (versionDate != null && versionDate.getTime() != null) {
                modifiedDate = versionDate.getTime();
            } else {
                modifiedDate = new Date();
            }
            file = new RepositoryFile.Builder(file).title(RepositoryFile.DEFAULT_LOCALE, title).lastModificationDate(modifiedDate).build();
            renameIfNecessary(element, file);
            file = pur.updateFile(file, new NodeRepositoryFileData(databaseMetaTransformer.elementToDataNode(element)), versionComment);
        } else {
            Date createdDate = null;
            if (versionDate != null && versionDate.getTime() != null) {
                createdDate = versionDate.getTime();
            } else {
                createdDate = new Date();
            }
            file = new RepositoryFile.Builder(checkAndSanitize(RepositoryFilenameUtils.escape(element.getName(), pur.getReservedChars()) + RepositoryObjectType.DATABASE.getExtension())).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).createdDate(createdDate).versioned(VERSION_SHARED_OBJECTS).build();
            file = pur.createFile(getDatabaseMetaParentFolderId(), file, new NodeRepositoryFileData(databaseMetaTransformer.elementToDataNode(element)), versionComment);
        }
        // side effects
        ObjectId objectId = new StringObjectId(file.getId().toString());
        element.setObjectId(objectId);
        element.setObjectRevision(getObjectRevision(objectId, null));
        if (element instanceof ChangedFlagInterface) {
            ((ChangedFlagInterface) element).clearChanged();
        }
        updateSharedObjectCache(element);
    } catch (Exception e) {
        // determine if there is an "access denied" issue and throw a nicer error message.
        if (e.getMessage().indexOf("access denied") >= 0) {
            throw new KettleException(BaseMessages.getString(PKG, "PurRepository.ERROR_0004_DATABASE_UPDATE_ACCESS_DENIED", element.getName()), e);
        }
    } finally {
        readWriteLock.writeLock().unlock();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ChangedFlagInterface(org.pentaho.di.core.changed.ChangedFlagInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) Date(java.util.Date) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) URISyntaxException(java.net.URISyntaxException) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 4 with ChangedFlagInterface

use of org.pentaho.di.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.

the class Spoon method setShellText.

public void setShellText() {
    if (shell.isDisposed()) {
        return;
    }
    String filename = null;
    String name = null;
    String version = null;
    ChangedFlagInterface changed = null;
    boolean versioningEnabled = true;
    AbstractMeta meta = getActiveJob() != null ? getActiveJob() : getActiveTransformation();
    if (meta != null) {
        changed = meta;
        filename = meta.getFilename();
        name = meta.getName();
        version = meta.getObjectRevision() == null ? null : meta.getObjectRevision().getName();
        try {
            versioningEnabled = isVersionEnabled(rep, meta);
        } catch (KettleRepositoryLostException krle) {
            handleRepositoryLost(krle);
        }
    }
    String text = "";
    if (rep != null) {
        text += APP_TITLE + " - [" + getRepositoryName() + "] ";
    } else {
        text += APP_TITLE + " - ";
    }
    if (Utils.isEmpty(name)) {
        if (!Utils.isEmpty(filename)) {
            text += filename;
        } else {
            String tab = getActiveTabText();
            if (!Utils.isEmpty(tab)) {
                text += tab;
            } else {
                // "[no name]"
                text += BaseMessages.getString(PKG, "Spoon.Various.NoName");
            }
        }
    } else {
        text += name;
    }
    if (versioningEnabled && !Utils.isEmpty(version)) {
        text += " v" + version;
    }
    if (changed != null && changed.hasChanged()) {
        text += " " + BaseMessages.getString(PKG, "Spoon.Various.Changed");
    }
    shell.setText(text);
    markTabsChanged(false);
}
Also used : ChangedFlagInterface(org.pentaho.di.core.changed.ChangedFlagInterface) AbstractMeta(org.pentaho.di.base.AbstractMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException)

Example 5 with ChangedFlagInterface

use of org.pentaho.di.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.

the class PurRepository method saveRepositoryElement.

protected void saveRepositoryElement(RepositoryElementInterface element, String versionComment, ITransformer transformer, Serializable elementsFolderId) throws KettleException {
    boolean isUpdate = (element.getObjectId() != null);
    RepositoryFile file;
    readWriteLock.writeLock().lock();
    try {
        if (isUpdate) {
            file = pur.getFileById(element.getObjectId().getId());
            // update title & description
            file = new RepositoryFile.Builder(file).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).description(RepositoryFile.DEFAULT_LOCALE, Const.NVL(element.getDescription(), "")).build();
            // first rename, it is safe as only a name is changed, but not a path
            renameIfNecessary(element, file);
            file = pur.updateFile(file, new NodeRepositoryFileData(transformer.elementToDataNode(element)), versionComment);
        } else {
            file = new RepositoryFile.Builder(checkAndSanitize(element.getName() + element.getRepositoryElementType().getExtension())).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).description(RepositoryFile.DEFAULT_LOCALE, Const.NVL(element.getDescription(), "")).versioned(VERSION_SHARED_OBJECTS).build();
            file = pur.createFile(elementsFolderId, file, new NodeRepositoryFileData(transformer.elementToDataNode(element)), versionComment);
        }
    } finally {
        readWriteLock.writeLock().unlock();
    }
    // side effects
    ObjectId objectId = new StringObjectId(file.getId().toString());
    element.setObjectId(objectId);
    element.setObjectRevision(getObjectRevision(objectId, null));
    if (element instanceof ChangedFlagInterface) {
        ((ChangedFlagInterface) element).clearChanged();
    }
    updateSharedObjectCache(element);
}
Also used : StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ChangedFlagInterface(org.pentaho.di.core.changed.ChangedFlagInterface) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId)

Aggregations

ChangedFlagInterface (org.pentaho.di.core.changed.ChangedFlagInterface)5 ObjectId (org.pentaho.di.repository.ObjectId)4 StringObjectId (org.pentaho.di.repository.StringObjectId)4 KettleException (org.pentaho.di.core.exception.KettleException)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)3 Date (java.util.Date)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 TransMeta (org.pentaho.di.trans.TransMeta)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URISyntaxException (java.net.URISyntaxException)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 AbstractMeta (org.pentaho.di.base.AbstractMeta)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)1 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1