Search in sources :

Example 16 with RepositoryFile

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

the class PurRepositoryMetaStore method createElementType.

// The element types
@Override
public void createElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    RepositoryFile namespaceFile = validateNamespace(namespace);
    IMetaStoreElementType existingType = getElementTypeByName(namespace, elementType.getName());
    if (existingType != null) {
        throw new MetaStoreElementTypeExistsException(Collections.singletonList(existingType), "Can not create element type with id '" + elementType.getId() + "' because it already exists");
    }
    RepositoryFile elementTypeFile = new RepositoryFile.Builder(elementType.getName()).folder(true).versioned(false).build();
    RepositoryFile folder = pur.createFolder(namespaceFile.getId(), elementTypeFile, null);
    elementType.setId(folder.getId().toString());
    // In this folder there is a hidden file which contains the description
    // and the other future properties of the element type
    // 
    RepositoryFile detailsFile = new RepositoryFile.Builder(ELEMENT_TYPE_DETAILS_FILENAME).folder(false).title(ELEMENT_TYPE_DETAILS_FILENAME).description(elementType.getDescription()).hidden(true).build();
    DataNode dataNode = getElementTypeDataNode(elementType);
    pur.createFile(folder.getId(), detailsFile, new NodeRepositoryFileData(dataNode), null);
    elementType.setMetaStoreName(getName());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 17 with RepositoryFile

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

the class PurRepositoryMetaStore method getElements.

@Override
public List<IMetaStoreElement> getElements(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    List<IMetaStoreElement> elements = new ArrayList<IMetaStoreElement>();
    RepositoryFile typeFolder = validateElementTypeRepositoryFolder(namespace, elementType);
    List<RepositoryFile> children = getChildren(typeFolder.getId());
    removeHiddenFilesFromList(children);
    for (RepositoryFile child : children) {
        IMetaStoreElement element = getElement(namespace, elementType, child.getId().toString());
        elements.add(element);
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 18 with RepositoryFile

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

the class PurRepositoryMetaStore method getMetaStoreFolders.

private String getMetaStoreFolders(StringBuilder builder, RepositoryFile folder, int level) {
    String spaces = Const.rightPad(" ", level * 2);
    builder.append(spaces);
    if (folder.isFolder()) {
        builder.append("/");
    }
    builder.append(folder.getName()).append(Const.CR);
    for (RepositoryFile file : getChildren(folder.getId())) {
        getMetaStoreFolders(builder, file, level + 1);
    }
    return builder.toString();
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 19 with RepositoryFile

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

the class PurRepositoryMetaStore method getElementIds.

@Override
public List<String> getElementIds(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    RepositoryFile folder = validateElementTypeRepositoryFolder(namespace, elementType);
    List<RepositoryFile> children = getChildren(folder.getId());
    removeHiddenFilesFromList(children);
    List<String> ids = new ArrayList<String>();
    for (RepositoryFile child : children) {
        ids.add(child.getId().toString());
    }
    return ids;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 20 with RepositoryFile

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

the class PurRepositoryMetaStore method createElement.

// The elements
public void createElement(String namespace, IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException {
    RepositoryFile elementTypeFolder = validateElementTypeRepositoryFolder(namespace, elementType);
    RepositoryFile elementFile = new RepositoryFile.Builder(PurRepository.checkAndSanitize(element.getName())).title(element.getName()).versioned(false).build();
    DataNode elementDataNode = new DataNode(PurRepository.checkAndSanitize(element.getName()));
    elementToDataNode(element, elementDataNode);
    RepositoryFile createdFile = pur.createFile(elementTypeFolder.getId(), elementFile, new NodeRepositoryFileData(elementDataNode), null);
    element.setId(createdFile.getId().toString());
    // Verify existence.
    if (pur.getFileById(createdFile.getId()) == null) {
        throw new RuntimeException("Unable to verify creation of element '" + element.getName() + "' in folder: " + elementTypeFolder.getPath());
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

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