Search in sources :

Example 1 with PropertyString

use of org.pentaho.commons.util.repository.type.PropertyString in project pentaho-platform by pentaho.

the class BiPlatformRepositoryClientNavigationService method createCmisObjectFromElement.

private CmisObject createCmisObjectFromElement(Element element, int depth) {
    CmisObject object = new CmisObjectImpl();
    CmisProperties properties = new CmisProperties();
    List<CmisProperty> propList = properties.getProperties();
    // is this a folder or a file?
    boolean isDirectory = false;
    // $NON-NLS-1$
    Attribute attr = element.attribute("isDirectory");
    if (attr != null) {
        // $NON-NLS-1$
        isDirectory = "true".equalsIgnoreCase(attr.getText());
    }
    // set the base properties
    String objectId = getObjectId(element);
    Calendar lastModifiedDate = getLastModifiedDate(element);
    String name = getName(element);
    String localizedName = getLocalizedName(element);
    String extension = getExtension(element);
    boolean visible = getVisible(element);
    propList.add(new PropertyId(PropertiesBase.OBJECTID, objectId));
    propList.add(new PropertyDateTime(PropertiesBase.LASTMODIFICATIONDATE, lastModifiedDate));
    if (isDirectory) {
        propList.add(new PropertyString(PropertiesBase.OBJECTTYPEID, CmisObject.OBJECT_TYPE_FOLDER));
    } else {
        propList.add(new PropertyString(PropertiesBase.OBJECTTYPEID, extension));
        propList.add(new PropertyBoolean(PropertiesDocument.CONTENTSTREAMALLOWED, true));
    }
    propList.add(new PropertyString(CmisObject.NAME, name));
    propList.add(new PropertyString(CmisObject.LOCALIZEDNAME, localizedName));
    propList.add(new PropertyBoolean(CmisObject.VISIBLE, visible));
    object.setProperties(properties);
    return object;
}
Also used : CmisObjectImpl(org.pentaho.commons.util.repository.type.CmisObjectImpl) PropertyString(org.pentaho.commons.util.repository.type.PropertyString) PropertyBoolean(org.pentaho.commons.util.repository.type.PropertyBoolean) Attribute(org.dom4j.Attribute) Calendar(java.util.Calendar) CmisProperties(org.pentaho.commons.util.repository.type.CmisProperties) CmisProperty(org.pentaho.commons.util.repository.type.CmisProperty) PropertyString(org.pentaho.commons.util.repository.type.PropertyString) PropertyId(org.pentaho.commons.util.repository.type.PropertyId) CmisObject(org.pentaho.commons.util.repository.type.CmisObject) PropertyDateTime(org.pentaho.commons.util.repository.type.PropertyDateTime)

Example 2 with PropertyString

use of org.pentaho.commons.util.repository.type.PropertyString in project pentaho-platform by pentaho.

the class BiPlatformRepositoryClientNavigationServiceTest method testGetRepositoryPath.

@Test
public void testGetRepositoryPath() {
    mLog.info("testGetRepositoryPath..");
    // Following line throws NPE
    // lNavService.getRepositoryPath(cmisObject);
    // CASE 1: Set object type id to folder
    cmisObject.getProperties().getProperties().add(new PropertyId(PropertiesBase.OBJECTID, "repository"));
    cmisObject.getProperties().getProperties().add(new PropertyString(PropertiesBase.OBJECTTYPEID, CmisObject.OBJECT_TYPE_FOLDER));
    String path = navService.getRepositoryPath(cmisObject);
    assertTrue("repository".equals(path));
    // CASE 2: Object type id is null and object id is not null
    cmisObject.setProperties(new CmisProperties());
    cmisObject.getProperties().getProperties().add(new PropertyId(PropertiesBase.OBJECTID, "/admin/pat"));
    cmisObject.getProperties().getProperties().add(new PropertyString(PropertiesBase.OBJECTTYPEID, null));
    path = navService.getRepositoryPath(cmisObject);
    assertTrue("Repository path as expected", "/admin".equals(path));
    // CASE 3: Object type id is null and object id is not null
    cmisObject.setProperties(new CmisProperties());
    cmisObject.getProperties().getProperties().add(new PropertyId(PropertiesBase.OBJECTID, "repository"));
    cmisObject.getProperties().getProperties().add(new PropertyString(PropertiesBase.OBJECTTYPEID, null));
    path = navService.getRepositoryPath(cmisObject);
    assertTrue("Repository path as expected", "".equals(path));
}
Also used : PropertyString(org.pentaho.commons.util.repository.type.PropertyString) CmisProperties(org.pentaho.commons.util.repository.type.CmisProperties) PropertyString(org.pentaho.commons.util.repository.type.PropertyString) PropertyId(org.pentaho.commons.util.repository.type.PropertyId) Test(org.junit.Test)

Example 3 with PropertyString

use of org.pentaho.commons.util.repository.type.PropertyString 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 4 with PropertyString

use of org.pentaho.commons.util.repository.type.PropertyString in project pentaho-platform by pentaho.

the class BiPlatformRepositoryClientNavigationServiceTest method testGetRepositoryFilename.

@Test
public void testGetRepositoryFilename() {
    mLog.info("testGetRepositoryFilename..");
    // Following line throws NPE
    // lNavService.getRepositoryFilename(null);
    cmisObject.getProperties().getProperties().add(new PropertyString(CmisObject.NAME, "UNIT_TEST"));
    String filename = navService.getRepositoryFilename(cmisObject);
    assertTrue("UNIT_TEST".equals(filename));
    cmisObject.getProperties().getProperties().add(new PropertyString(PropertiesBase.OBJECTTYPEID, CmisObject.OBJECT_TYPE_FOLDER));
    filename = navService.getRepositoryFilename(cmisObject);
    assertTrue("Repository filename as expected", "".equals(filename));
}
Also used : PropertyString(org.pentaho.commons.util.repository.type.PropertyString) PropertyString(org.pentaho.commons.util.repository.type.PropertyString) Test(org.junit.Test)

Aggregations

PropertyString (org.pentaho.commons.util.repository.type.PropertyString)4 Test (org.junit.Test)3 CmisProperties (org.pentaho.commons.util.repository.type.CmisProperties)2 PropertyId (org.pentaho.commons.util.repository.type.PropertyId)2 Calendar (java.util.Calendar)1 Attribute (org.dom4j.Attribute)1 FolderNotValidException (org.pentaho.commons.util.repository.exception.FolderNotValidException)1 InvalidArgumentException (org.pentaho.commons.util.repository.exception.InvalidArgumentException)1 ObjectNotFoundException (org.pentaho.commons.util.repository.exception.ObjectNotFoundException)1 OperationNotSupportedException (org.pentaho.commons.util.repository.exception.OperationNotSupportedException)1 CmisObject (org.pentaho.commons.util.repository.type.CmisObject)1 CmisObjectImpl (org.pentaho.commons.util.repository.type.CmisObjectImpl)1 CmisProperty (org.pentaho.commons.util.repository.type.CmisProperty)1 PropertyBoolean (org.pentaho.commons.util.repository.type.PropertyBoolean)1 PropertyDateTime (org.pentaho.commons.util.repository.type.PropertyDateTime)1 TypesOfFileableObjects (org.pentaho.commons.util.repository.type.TypesOfFileableObjects)1