Search in sources :

Example 66 with ObjectId

use of org.pentaho.di.repository.ObjectId 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 67 with ObjectId

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

the class LazyUnifiedRepositoryDirectory method getDirectoryIDs.

@Override
public ObjectId[] getDirectoryIDs() {
    List<RepositoryFile> children = this.getAllURChildrenFiles();
    ObjectId[] objectIds = new ObjectId[children.size()];
    for (int i = 0; i < children.size(); i++) {
        objectIds[i] = new StringObjectId(children.get(i).getId().toString());
    }
    return objectIds;
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 68 with ObjectId

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

the class PurRepositoryAttribute method getAttributeDatabaseMeta.

public DatabaseMeta getAttributeDatabaseMeta(String code) {
    DataProperty property = dataNode.getProperty(code);
    if (property == null || Utils.isEmpty(property.getString())) {
        return null;
    }
    ObjectId id = new StringObjectId(property.getString());
    return DatabaseMeta.findDatabase(databases, id);
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 69 with ObjectId

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

the class RepositoryDirectoryUI method chooseDirectory.

public static RepositoryDirectoryInterface chooseDirectory(Shell shell, Repository rep, RepositoryDirectoryInterface directoryFrom) {
    if (rep == null) {
        return null;
    }
    if (directoryFrom == null) {
        try {
            directoryFrom = rep.getUserHomeDirectory();
        } catch (KettleException ex) {
            directoryFrom = new RepositoryDirectory();
        }
    }
    ObjectId idDirectoryFrom = directoryFrom.getObjectId();
    SelectDirectoryDialog sdd = new SelectDirectoryDialog(shell, SWT.NONE, rep);
    // PDI-13867: root dir and its direct subdirectories are restricted.
    HashSet<String> restrictedPaths = new HashSet<String>();
    restrictedPaths.add(directoryFrom.findRoot().getPath());
    restrictedPaths.add("/home");
    sdd.setRestrictedPaths(restrictedPaths);
    // TODO: expand and select directoryFrom in the dialog.
    RepositoryDirectoryInterface rd = sdd.open();
    if (rd == null || idDirectoryFrom == rd.getObjectId()) {
        return null;
    }
    return rd;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ObjectId(org.pentaho.di.repository.ObjectId) SelectDirectoryDialog(org.pentaho.di.ui.repository.dialog.SelectDirectoryDialog) HashSet(java.util.HashSet)

Example 70 with ObjectId

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

the class RepositoryExplorerDialog method newCluster.

public void newCluster() {
    try {
        ClusterSchema cluster = new ClusterSchema();
        ClusterSchemaDialog dd = new ClusterSchemaDialog(shell, cluster, rep.getSlaveServers());
        if (dd.open()) {
            // See if this slave server already exists...
            ObjectId idCluster = rep.getClusterID(cluster.getName());
            if (idCluster == null) {
                rep.insertLogEntry("Creating new cluster '" + cluster.getName() + "'");
                rep.save(cluster, Const.VERSION_COMMENT_INITIAL_VERSION, null);
            } else {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Create.AlreadyExists.Message"));
                mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Create.AlreadyExists.Title"));
                mb.open();
            }
            // Refresh tree...
            refreshTree();
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Create.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Create.UnexpectedError.Message"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ObjectId(org.pentaho.di.repository.ObjectId) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ClusterSchema(org.pentaho.di.cluster.ClusterSchema) ClusterSchemaDialog(org.pentaho.di.ui.cluster.dialog.ClusterSchemaDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

ObjectId (org.pentaho.di.repository.ObjectId)233 KettleException (org.pentaho.di.core.exception.KettleException)94 LongObjectId (org.pentaho.di.repository.LongObjectId)76 StringObjectId (org.pentaho.di.repository.StringObjectId)76 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)49 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)38 Test (org.junit.Test)37 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)37 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)34 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)33 ArrayList (java.util.ArrayList)30 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)29 MessageBox (org.eclipse.swt.widgets.MessageBox)26 Repository (org.pentaho.di.repository.Repository)18 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)18 SlaveServer (org.pentaho.di.cluster.SlaveServer)15 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)14 PartitionSchema (org.pentaho.di.partition.PartitionSchema)14 Matchers.anyString (org.mockito.Matchers.anyString)13 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)13