Search in sources :

Example 31 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.

the class StreamToTransNodeConverter method convert.

public IRepositoryFileData convert(final InputStream inputStream, final String charset, final String mimeType) {
    try {
        long size = inputStream.available();
        TransMeta transMeta = new TransMeta();
        Repository repository = connectToRepository();
        Document doc = PDIImportUtil.loadXMLFrom(inputStream);
        transMeta.loadXML(doc.getDocumentElement(), repository, false);
        TransDelegate delegate = new TransDelegate(repository, this.unifiedRepository);
        saveSharedObjects(repository, transMeta);
        return new NodeRepositoryFileData(delegate.elementToDataNode(transMeta), size);
    } catch (Exception e) {
        logger.error(e);
        return null;
    }
}
Also used : Repository(org.pentaho.di.repository.Repository) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) TransDelegate(org.pentaho.di.repository.pur.TransDelegate) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) TransMeta(org.pentaho.di.trans.TransMeta) Document(org.w3c.dom.Document) KettleException(org.pentaho.di.core.exception.KettleException)

Example 32 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData 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;
    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);
    }
    // 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)

Example 33 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.

the class PurRepository method renameTransOrJob.

/**
 * Renames and optionally moves a file having {@code idObject}. If {@code newDirectory} is <tt>null</tt>, then the
 * file is just renamed. If {@code newTitle} is <tt>null</tt>, then the file should keep its name.
 * <p/>
 * Note, it is expected that the file exists
 *
 * @param idObject
 *          file's id
 * @param versionComment
 *          comment on the revision
 * @param newDirectory
 *          new folder, where to move the file; <tt>null</tt> means the file should be left in its current
 * @param newTitle
 *          new file's title (title is a name w/o extension); <tt>null</tt> means the file should keep its current
 * @param objectType
 *          file's type; {@linkplain RepositoryObjectType#TRANSFORMATION} or {@linkplain RepositoryObjectType#JOB} are
 *          expected
 * @param errorMsgKey
 *          key for the error message passed with the exception
 * @throws KettleException
 *           if file with same path exists
 */
private ObjectId renameTransOrJob(ObjectId idObject, String versionComment, RepositoryDirectoryInterface newDirectory, String newTitle, RepositoryObjectType objectType, String errorMsgKey) throws KettleException {
    RepositoryFile file = pur.getFileById(idObject.getId());
    RepositoryFile.Builder builder = new RepositoryFile.Builder(file);
    // fullName = title + extension
    String fullName;
    if (newTitle == null) {
        // keep existing file name
        fullName = file.getName();
    } else {
        // set new title
        builder.title(RepositoryFile.DEFAULT_LOCALE, newTitle).createdDate(null);
        fullName = checkAndSanitize(newTitle) + objectType.getExtension();
    }
    String absPath = calcDestAbsPath(file, newDirectory, fullName);
    // get file from destination path, should be null for rename goal
    RepositoryFile fileFromDestination = pur.getFile(absPath);
    if (fileFromDestination == null) {
        file = builder.build();
        NodeRepositoryFileData data = pur.getDataAtVersionForRead(file.getId(), null, NodeRepositoryFileData.class);
        if (newTitle != null) {
            // update file's content only if the title should be changed
            // as this action creates another revision
            pur.updateFile(file, data, versionComment);
        }
        pur.moveFile(idObject.getId(), absPath, null);
        rootRef.clearRef();
        return idObject;
    } else {
        throw new KettleException(BaseMessages.getString(PKG, errorMsgKey, file.getName(), newTitle));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 34 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.

the class PurRepository method loadClusterSchema.

@Override
public ClusterSchema loadClusterSchema(ObjectId idClusterSchema, List<SlaveServer> slaveServers, String versionId) throws KettleException {
    try {
        // We dont need to use slaveServer variable as the dataNoteToElement method finds the server from the repository
        NodeRepositoryFileData data = pur.getDataAtVersionForRead(idClusterSchema.getId(), versionId, NodeRepositoryFileData.class);
        RepositoryFile file = null;
        if (versionId != null) {
            file = pur.getFileAtVersion(idClusterSchema.getId(), versionId);
        } else {
            file = pur.getFileById(idClusterSchema.getId());
        }
        return clusterTransformer.assemble(file, data, pur.getVersionSummary(idClusterSchema.getId(), versionId));
    } catch (Exception e) {
        throw new KettleException("Unable to load cluster schema with id [" + idClusterSchema + "]", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Example 35 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.

the class PurRepository method loadPartitionSchema.

@Override
public PartitionSchema loadPartitionSchema(ObjectId partitionSchemaId, String versionId) throws KettleException {
    try {
        NodeRepositoryFileData data = pur.getDataAtVersionForRead(partitionSchemaId.getId(), versionId, NodeRepositoryFileData.class);
        RepositoryFile file = null;
        if (versionId != null) {
            file = pur.getFileAtVersion(partitionSchemaId.getId(), versionId);
        } else {
            file = pur.getFileById(partitionSchemaId.getId());
        }
        return partitionSchemaTransformer.assemble(file, data, pur.getVersionSummary(partitionSchemaId.getId(), versionId));
    } catch (Exception e) {
        throw new KettleException("Unable to load partition schema with id [" + partitionSchemaId + "]", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Aggregations

NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)46 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)36 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)22 KettleException (org.pentaho.di.core.exception.KettleException)14 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)11 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)11 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)10 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)10 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)10 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)10 Test (org.junit.Test)9 Matchers.anyString (org.mockito.Matchers.anyString)7 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)7 ITenant (org.pentaho.platform.api.mt.ITenant)6 StringObjectId (org.pentaho.di.repository.StringObjectId)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4