Search in sources :

Example 1 with FolderNotValidException

use of org.pentaho.commons.util.repository.exception.FolderNotValidException in project pentaho-platform by pentaho.

the class BiPlatformRepositoryClientNavigationServiceTest method testGetFolderParent.

@Test
public void testGetFolderParent() {
    mLog.info("testGetFolderParent..");
    // CASE 1: Provide a wrong key for the original BI platform repository
    try {
        navService.getFolderParent("WRONG_REPOSITORY_ID", "/admin/sales_data.csv", "filter", false, false, false);
    } catch (Exception exe) {
        assertTrue(exe instanceof InvalidArgumentException);
    }
    // CASE 2: Provide a right key, but the document is null
    try {
        cmisObjects = navService.getFolderParent(BiPlatformRepositoryClient.PLATFORMORIG, "/admin/sales_data.csv", "filter", false, false, false);
    } catch (Exception exe) {
        assertTrue("Should have thrown exception here", true);
    }
    // CASE 3: document is empty
    try {
        navService.setDoc(mockDocument);
        navService.getFolderParent(BiPlatformRepositoryClient.PLATFORMORIG, "/admin/sales_data.csv", "filter", false, false, false);
    } catch (Exception exe) {
        assertTrue(exe instanceof FolderNotValidException);
    }
    // CASE 4: now the document has valid contents
    try {
        navService.setDoc(document);
        cmisObjects = navService.getFolderParent(BiPlatformRepositoryClient.PLATFORMORIG, "/admin", "filter", false, false, false);
        assertTrue(cmisObjects != null);
        assertTrue(cmisObjects.get(0).getProperties() != null);
        CmisObject lCmisObject = cmisObjects.get(0);
        assertTrue("".equals(lCmisObject.findStringProperty(PropertiesBase.OBJECTTYPEID, null)));
    } catch (Exception exe) {
        assertTrue("Shouldn't throw exception here", false);
        mLog.error("Exception in testGetFolderParent() - Fails Unit Test");
    }
}
Also used : InvalidArgumentException(org.pentaho.commons.util.repository.exception.InvalidArgumentException) FolderNotValidException(org.pentaho.commons.util.repository.exception.FolderNotValidException) CmisObject(org.pentaho.commons.util.repository.type.CmisObject) OperationNotSupportedException(org.pentaho.commons.util.repository.exception.OperationNotSupportedException) InvalidArgumentException(org.pentaho.commons.util.repository.exception.InvalidArgumentException) ObjectNotFoundException(org.pentaho.commons.util.repository.exception.ObjectNotFoundException) FolderNotValidException(org.pentaho.commons.util.repository.exception.FolderNotValidException) Test(org.junit.Test)

Example 2 with FolderNotValidException

use of org.pentaho.commons.util.repository.exception.FolderNotValidException in project pentaho-platform by pentaho.

the class BiPlatformRepositoryClientNavigationServiceTest method testGetDescendants.

@Test
public void testGetDescendants() {
    mLog.info("testGetDescendants..");
    // CASE 1: Provide a wrong key for the original BI platform repository
    try {
        navService.getDescendants("WRONG_REPOSITORY_ID", "/admin", null, 0, "filter", false, false);
    } catch (Exception exe) {
        assertTrue(exe instanceof InvalidArgumentException);
    }
    // CASE 2: Provide a right key, but the document is null
    try {
        navService.getDescendants(BiPlatformRepositoryClient.PLATFORMORIG, "/admin", null, 0, "filter", false, false);
    } catch (Exception exe) {
        assertTrue("Shouldn have thrown exception here", true);
    }
    // CASE 3: document is empty
    try {
        navService.setDoc(mockDocument);
        navService.getDescendants(BiPlatformRepositoryClient.PLATFORMORIG, "/admin", null, 0, "filter", false, false);
    } catch (Exception exe) {
        assertTrue(exe instanceof FolderNotValidException);
    }
    // CASE 4: the document has valid contents
    try {
        navService.setDoc(document);
        cmisObjects = navService.getDescendants(BiPlatformRepositoryClient.PLATFORMORIG, "/admin", null, 0, "filter", false, false);
        assertTrue(cmisObjects != null);
    } catch (Exception exe) {
        assertTrue("Shouldn't throw exception here", false);
        mLog.error("Exception in testGetDescendants() - Fails Unit Test");
    }
    // CASE 5: TypesOfFileableObjects.FOLDERS
    TypesOfFileableObjects fileableFolders = new TypesOfFileableObjects(TypesOfFileableObjects.FOLDERS);
    cmisObject.getProperties().getProperties().add(new PropertyString(PropertiesBase.OBJECTTYPEID, CmisObject.OBJECT_TYPE_FOLDER));
    try {
        navService.setDoc(document);
        cmisObjects = navService.getDescendants(BiPlatformRepositoryClient.PLATFORMORIG, "/admin", fileableFolders, 1, "filter", false, false);
        assertTrue(cmisObjects != null);
    } catch (Exception exe) {
        assertTrue("Shouldn't throw exception here", false);
        mLog.error("Exception in testGetDescendants() - Fails Unit Test");
    }
    // CASE 5: TypesOfFileableObjects.DOCUMENTS
    TypesOfFileableObjects fileableDocuments = new TypesOfFileableObjects(TypesOfFileableObjects.DOCUMENTS);
    try {
        navService.setDoc(document);
        cmisObjects = navService.getDescendants(BiPlatformRepositoryClient.PLATFORMORIG, "/admin", fileableDocuments, 0, "filter", false, false);
        assertTrue(cmisObjects != null);
    } catch (Exception exe) {
        assertTrue("Shouldn't throw exception here", false);
        mLog.error("Exception in testGetDescendants() - Fails Unit Test");
    }
}
Also used : PropertyString(org.pentaho.commons.util.repository.type.PropertyString) InvalidArgumentException(org.pentaho.commons.util.repository.exception.InvalidArgumentException) FolderNotValidException(org.pentaho.commons.util.repository.exception.FolderNotValidException) OperationNotSupportedException(org.pentaho.commons.util.repository.exception.OperationNotSupportedException) InvalidArgumentException(org.pentaho.commons.util.repository.exception.InvalidArgumentException) ObjectNotFoundException(org.pentaho.commons.util.repository.exception.ObjectNotFoundException) FolderNotValidException(org.pentaho.commons.util.repository.exception.FolderNotValidException) TypesOfFileableObjects(org.pentaho.commons.util.repository.type.TypesOfFileableObjects) Test(org.junit.Test)

Example 3 with FolderNotValidException

use of org.pentaho.commons.util.repository.exception.FolderNotValidException in project pentaho-platform by pentaho.

the class BiPlatformRepositoryClientNavigationService method getFolderElement.

private Element getFolderElement(String path) throws FolderNotValidException {
    // parse out the path
    // $NON-NLS-1$
    StringTokenizer tokenizer = new StringTokenizer(path, "" + RepositoryFile.SEPARATOR);
    StringBuilder sb = new StringBuilder();
    // $NON-NLS-1$
    sb.append("/repository");
    String folderName;
    while (tokenizer.hasMoreTokens()) {
        folderName = tokenizer.nextToken();
        // $NON-NLS-1$
        sb.append("/file[@isDirectory='true' and @name='").append(folderName).append(// $NON-NLS-1$
        "']");
    }
    String xPath = sb.toString();
    Element element = (Element) doc.selectSingleNode(xPath);
    if (element == null) {
        throw new FolderNotValidException();
    }
    return element;
}
Also used : StringTokenizer(java.util.StringTokenizer) Element(org.dom4j.Element) FolderNotValidException(org.pentaho.commons.util.repository.exception.FolderNotValidException) PropertyString(org.pentaho.commons.util.repository.type.PropertyString)

Aggregations

FolderNotValidException (org.pentaho.commons.util.repository.exception.FolderNotValidException)3 Test (org.junit.Test)2 InvalidArgumentException (org.pentaho.commons.util.repository.exception.InvalidArgumentException)2 ObjectNotFoundException (org.pentaho.commons.util.repository.exception.ObjectNotFoundException)2 OperationNotSupportedException (org.pentaho.commons.util.repository.exception.OperationNotSupportedException)2 PropertyString (org.pentaho.commons.util.repository.type.PropertyString)2 StringTokenizer (java.util.StringTokenizer)1 Element (org.dom4j.Element)1 CmisObject (org.pentaho.commons.util.repository.type.CmisObject)1 TypesOfFileableObjects (org.pentaho.commons.util.repository.type.TypesOfFileableObjects)1