Search in sources :

Example 1 with ObjectNotFoundException

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

the class BiPlatformRepositoryClientNavigationService method getObjectElement.

private Element getObjectElement(String path) throws ObjectNotFoundException {
    // 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;
    int tokenCount = tokenizer.countTokens();
    for (int idx = 0; idx < tokenCount - 1; idx++) {
        folderName = tokenizer.nextToken();
        // $NON-NLS-1$
        sb.append("/file[@isDirectory='true' and @name='").append(folderName).append(// $NON-NLS-1$
        "']");
    }
    if (tokenizer.hasMoreTokens()) {
        folderName = tokenizer.nextToken();
        // $NON-NLS-1$
        sb.append("/file[@name='").append(folderName).append(// $NON-NLS-1$
        "']");
    }
    String xPath = sb.toString();
    Element element = (Element) doc.selectSingleNode(xPath);
    if (element == null) {
        throw new ObjectNotFoundException();
    }
    return element;
}
Also used : StringTokenizer(java.util.StringTokenizer) Element(org.dom4j.Element) ObjectNotFoundException(org.pentaho.commons.util.repository.exception.ObjectNotFoundException) PropertyString(org.pentaho.commons.util.repository.type.PropertyString)

Example 2 with ObjectNotFoundException

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

the class BiPlatformRepositoryClientNavigationServiceTest method testObjectParent.

@Test
public void testObjectParent() {
    mLog.info("testObjectParent..");
    // CASE 1: Provide a wrong key for the original BI platform repository
    try {
        navService.getObjectParent("WRONG_REPOSITORY_ID", "objectId", "filter", false, false);
    } catch (Exception exe) {
        assertTrue(exe instanceof InvalidArgumentException);
    }
    // CASE 2: Provide a right key, but document is null
    try {
        cmisObjects = navService.getObjectParent(BiPlatformRepositoryClient.PLATFORMORIG, "/admin/training/sales_data.csv", "filter", false, false);
    } catch (Exception exe) {
        assertTrue("Should have thrown NPE here, as lNavService doc is null", true);
    }
    // CASE 3: the document is empty
    try {
        navService.setDoc(mockDocument);
        cmisObjects = navService.getObjectParent(BiPlatformRepositoryClient.PLATFORMORIG, "/admin/training/sales_data.csv", "filter", false, false);
    } catch (Exception exe) {
        assertTrue(exe instanceof ObjectNotFoundException);
    }
    // CASE 4: now the document has valid contents
    try {
        navService.setDoc(document);
        cmisObjects = navService.getObjectParent(BiPlatformRepositoryClient.PLATFORMORIG, "/admin/sales_data.csv", "filter", false, false);
        assertTrue(cmisObjects != null);
        assertTrue(cmisObjects.get(0).getProperties() != null);
        CmisObject lCmisObject = cmisObjects.get(0);
        assertTrue(CmisObject.OBJECT_TYPE_FOLDER.equals(lCmisObject.findStringProperty(PropertiesBase.OBJECTTYPEID, null)));
    } catch (Exception exe) {
        assertTrue("Shouldn't throw exception here", false);
        mLog.error("Problem testing testObjectParent() - Fails Unit Test");
    }
}
Also used : InvalidArgumentException(org.pentaho.commons.util.repository.exception.InvalidArgumentException) ObjectNotFoundException(org.pentaho.commons.util.repository.exception.ObjectNotFoundException) 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)

Aggregations

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