Search in sources :

Example 46 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.

the class PurRepository method saveDatabaseMeta.

protected void saveDatabaseMeta(final RepositoryElementInterface element, final String versionComment, Calendar versionDate) throws KettleException {
    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);
        }
    }
}
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) 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) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 47 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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);
    }
    final boolean isUpdate = (element.getObjectId() != null);
    RepositoryFile file;
    if (isUpdate) {
        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.");
        }
        // 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();
        try {
            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;
        }
        if (checkRename && isRenamed(element, file)) {
            renameKettleEntity(element, null, element.getName());
        }
    } else {
        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();
        try {
            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()));
            }
        }
    }
    // 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 48 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-metaverse by pentaho.

the class LocatorTestUtils method createFileTree.

private static RepositoryFileTree createFileTree(File root) {
    RepositoryFile repFile = new RepositoryFile(root.getPath(), root.getName(), root.isDirectory(), false, false, null, root.getAbsolutePath(), new Date(root.lastModified()), new Date(root.lastModified()), false, null, null, null, null, root.getName(), null, null, null, root.length(), "Admin", null);
    List<RepositoryFileTree> children = new ArrayList<RepositoryFileTree>();
    File[] files = root.listFiles();
    for (File file : files) {
        if (file.isHidden()) {
            continue;
        }
        if (file.isDirectory()) {
            RepositoryFileTree kid = createFileTree(file);
            children.add(kid);
        } else if (file.isFile()) {
            RepositoryFile kid = new RepositoryFile(file.getPath(), file.getName(), file.isDirectory(), false, false, null, file.getPath(), new Date(file.lastModified()), new Date(file.lastModified()), false, null, null, null, null, file.getName(), null, null, null, root.length(), "Admin", null);
            RepositoryFileTree kidTree = new RepositoryFileTree(kid, null);
            children.add(kidTree);
        }
    }
    RepositoryFileTree fileTree = new RepositoryFileTree(repFile, children);
    return fileTree;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Date(java.util.Date) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 49 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-metaverse by pentaho.

the class RepositoryLocatorTest method setUp.

@Before
public void setUp() throws Exception {
    RepositoryLocator loc = new RepositoryLocator() {

        @Override
        protected IUnifiedRepository getUnifiedRepository(IPentahoSession session) throws Exception {
            return null;
        }

        @Override
        protected Object getContents(RepositoryFile locatedItem) throws Exception {
            return null;
        }

        /**
         * Returns the locator node for this locator. The locator node is the node in the metaverse
         * that represents this locator. It is used to create a link from this locator to the documents
         * that are found by/within it.
         *
         * @return The locator node in the metaverse
         */
        @Override
        public IMetaverseNode getLocatorNode() {
            return new MetaverseNode(mock(Vertex.class));
        }

        @Override
        public URI getRootUri() {
            return null;
        }
    };
    loc.setMetaverseBuilder(metaverseBuilder);
    baseLocator = spy(loc);
    when(baseLocator.getMetaverseBuilder()).thenReturn(metaverseBuilder);
    when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(metaverseObjectFactory);
    when(metaverseObjectFactory.createDocumentObject()).thenReturn(new MetaverseDocument());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MetaverseDocument(org.pentaho.metaverse.api.MetaverseDocument) MetaverseNode(org.pentaho.metaverse.impl.MetaverseNode) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Before(org.junit.Before)

Example 50 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.

the class PentahoPlatformExporter method exportFileContent.

protected void exportFileContent(RepositoryFile exportRepositoryFile) throws IOException, ExportException {
    // get the file path
    String filePath = new File(this.path).getParent();
    if (filePath == null) {
        filePath = "/";
    }
    // send a response right away if not found
    if (exportRepositoryFile == null) {
        // todo: add to messages.properties
        throw new FileNotFoundException("JCR file not found: " + this.path);
    }
    if (exportRepositoryFile.isFolder()) {
        // Handle recursive export
        getExportManifest().getManifestInformation().setRootFolder(path.substring(0, path.lastIndexOf("/") + 1));
        // don't zip root folder without name
        if (!ClientRepositoryPaths.getRootFolderPath().equals(exportRepositoryFile.getPath())) {
            zos.putNextEntry(new ZipEntry(getFixedZipEntryName(exportRepositoryFile, filePath)));
        }
        exportDirectory(exportRepositoryFile, zos, filePath);
    } else {
        getExportManifest().getManifestInformation().setRootFolder(path.substring(0, path.lastIndexOf("/") + 1));
        exportFile(exportRepositoryFile, zos, filePath);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32