Search in sources :

Example 16 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class XMLOutputMetaTest method testReadRepException.

@Test
public void testReadRepException() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    Repository rep = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    ObjectId oid = new StringObjectId("oid");
    when(rep.getStepAttributeString(oid, "encoding")).thenThrow(new RuntimeException("encoding exception"));
    try {
        xmlOutputMeta.readRep(rep, metastore, oid, Collections.singletonList(dbMeta));
    } catch (KettleException e) {
        assertEquals("encoding exception", e.getCause().getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Example 17 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class XMLOutputMetaTest method testReadRep.

@SuppressWarnings("ConstantConditions")
@Test
public void testReadRep() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    Repository rep = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    String encoding = "UTF-8";
    String namespace = "";
    String mainElement = "rows";
    String repeatElement = "row";
    String fileName = "repFileName";
    StringObjectId oid = new StringObjectId("oid");
    String fileExtension = "repxml";
    boolean servletOutput = true;
    boolean newFile = true;
    long split = 100L;
    boolean addStepNbr = false;
    boolean addDate = false;
    boolean addTime = true;
    boolean specifyFormat = true;
    boolean omitNull = false;
    String dateTimeFormat = "yyyyMMdd";
    boolean addToResult = true;
    boolean zipped = true;
    String contentType = "Element";
    String fieldName = "aField";
    String fieldElement = "field";
    String fieldType = "String";
    long fieldLength = 20L;
    long fieldPrecision = 0L;
    when(rep.getStepAttributeString(oid, "encoding")).thenReturn(encoding);
    when(rep.getStepAttributeString(oid, "name_space")).thenReturn(namespace);
    when(rep.getStepAttributeString(oid, "xml_main_element")).thenReturn(mainElement);
    when(rep.getStepAttributeString(oid, "xml_repeat_element")).thenReturn(repeatElement);
    when(rep.getStepAttributeString(oid, "file_name")).thenReturn(fileName);
    when(rep.getStepAttributeString(oid, "file_extention")).thenReturn(fileExtension);
    when(rep.getStepAttributeBoolean(oid, "file_servlet_output")).thenReturn(servletOutput);
    when(rep.getStepAttributeBoolean(oid, "do_not_open_newfile_init")).thenReturn(newFile);
    when(rep.getStepAttributeInteger(oid, "file_split")).thenReturn(split);
    when(rep.getStepAttributeBoolean(oid, "file_add_stepnr")).thenReturn(addStepNbr);
    when(rep.getStepAttributeBoolean(oid, "file_add_date")).thenReturn(addDate);
    when(rep.getStepAttributeBoolean(oid, "file_add_time")).thenReturn(addTime);
    when(rep.getStepAttributeBoolean(oid, "SpecifyFormat")).thenReturn(specifyFormat);
    when(rep.getStepAttributeBoolean(oid, "omit_null_values")).thenReturn(omitNull);
    when(rep.getStepAttributeString(oid, "date_time_format")).thenReturn(dateTimeFormat);
    when(rep.getStepAttributeBoolean(oid, "add_to_result_filenames")).thenReturn(addToResult);
    when(rep.getStepAttributeBoolean(oid, "file_zipped")).thenReturn(zipped);
    when(rep.countNrStepAttributes(oid, "field_name")).thenReturn(1);
    when(rep.getStepAttributeString(oid, 0, "field_content_type")).thenReturn(contentType);
    when(rep.getStepAttributeString(oid, 0, "field_name")).thenReturn(fieldName);
    when(rep.getStepAttributeString(oid, 0, "field_element")).thenReturn(fieldElement);
    when(rep.getStepAttributeString(oid, 0, "field_type")).thenReturn(fieldType);
    when(rep.getStepAttributeString(oid, 0, "field_format")).thenReturn(null);
    when(rep.getStepAttributeString(oid, 0, "field_currency")).thenReturn(null);
    when(rep.getStepAttributeString(oid, 0, "field_decimal")).thenReturn(null);
    when(rep.getStepAttributeString(oid, 0, "field_group")).thenReturn(null);
    when(rep.getStepAttributeString(oid, 0, "field_nullif")).thenReturn(null);
    when(rep.getStepAttributeInteger(oid, 0, "field_length")).thenReturn(fieldLength);
    when(rep.getStepAttributeInteger(oid, 0, "field_precision")).thenReturn(fieldPrecision);
    xmlOutputMeta.readRep(rep, metastore, oid, Collections.singletonList(dbMeta));
    assertEquals(fileName, xmlOutputMeta.getFileName());
    assertTrue(xmlOutputMeta.isDoNotOpenNewFileInit());
    assertTrue(xmlOutputMeta.isServletOutput());
    assertEquals(fileExtension, xmlOutputMeta.getExtension());
    assertFalse(xmlOutputMeta.isStepNrInFilename());
    assertFalse(xmlOutputMeta.isDateInFilename());
    assertTrue(xmlOutputMeta.isTimeInFilename());
    assertTrue(xmlOutputMeta.isSpecifyFormat());
    assertEquals(dateTimeFormat, xmlOutputMeta.getDateTimeFormat());
    assertTrue(xmlOutputMeta.isAddToResultFiles());
    assertTrue(xmlOutputMeta.isZipped());
    assertEquals(encoding, xmlOutputMeta.getEncoding());
    assertTrue(StringUtil.isEmpty(xmlOutputMeta.getNameSpace()));
    assertEquals(mainElement, xmlOutputMeta.getMainElement());
    assertEquals(repeatElement, xmlOutputMeta.getRepeatElement());
    assertEquals(split, xmlOutputMeta.getSplitEvery());
    assertFalse(xmlOutputMeta.isOmitNullValues());
    XMLField[] outputFields = xmlOutputMeta.getOutputFields();
    assertEquals(1, outputFields.length);
    assertEquals(fieldName, outputFields[0].getFieldName());
    assertEquals(XMLField.ContentType.Element, outputFields[0].getContentType());
    assertEquals(fieldElement, outputFields[0].getElementName());
    assertEquals(fieldLength, outputFields[0].getLength());
    assertEquals(fieldPrecision, outputFields[0].getPrecision());
    Mockito.reset(rep, metastore);
    StringObjectId transid = new StringObjectId("transid");
    xmlOutputMeta.saveRep(rep, metastore, transid, oid);
    verify(rep).saveStepAttribute(transid, oid, "encoding", encoding);
    verify(rep).saveStepAttribute(transid, oid, "name_space", namespace);
    verify(rep).saveStepAttribute(transid, oid, "xml_main_element", mainElement);
    verify(rep).saveStepAttribute(transid, oid, "xml_repeat_element", repeatElement);
    verify(rep).saveStepAttribute(transid, oid, "file_name", fileName);
    verify(rep).saveStepAttribute(transid, oid, "file_extention", fileExtension);
    verify(rep).saveStepAttribute(transid, oid, "file_servlet_output", servletOutput);
    verify(rep).saveStepAttribute(transid, oid, "do_not_open_newfile_init", newFile);
    verify(rep).saveStepAttribute(transid, oid, "file_split", split);
    verify(rep).saveStepAttribute(transid, oid, "file_add_stepnr", addStepNbr);
    verify(rep).saveStepAttribute(transid, oid, "file_add_date", addDate);
    verify(rep).saveStepAttribute(transid, oid, "file_add_time", addTime);
    verify(rep).saveStepAttribute(transid, oid, "SpecifyFormat", specifyFormat);
    verify(rep).saveStepAttribute(transid, oid, "omit_null_values", omitNull);
    verify(rep).saveStepAttribute(transid, oid, "date_time_format", dateTimeFormat);
    verify(rep).saveStepAttribute(transid, oid, "add_to_result_filenames", addToResult);
    verify(rep).saveStepAttribute(transid, oid, "file_zipped", zipped);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_content_type", contentType);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_name", fieldName);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_element", fieldElement);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_type", fieldType);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_format", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_currency", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_decimal", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_group", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_nullif", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_length", fieldLength);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_precision", fieldPrecision);
    Mockito.verifyNoMoreInteractions(rep, metastore);
}
Also used : Repository(org.pentaho.di.repository.Repository) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Example 18 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class DatabaseMetaStoreUtil method loadDatabaseMetaFromDatabaseElement.

public static DatabaseMeta loadDatabaseMetaFromDatabaseElement(IMetaStore metaStore, IMetaStoreElement element) throws KettlePluginException {
    DatabaseMeta databaseMeta = new DatabaseMeta();
    PluginRegistry pluginRegistry = PluginRegistry.getInstance();
    // Load the appropriate database plugin (database interface)
    // 
    String pluginId = getChildString(element, MetaStoreConst.DB_ATTR_ID_PLUGIN_ID);
    String driverClassName = getChildString(element, MetaStoreConst.DB_ATTR_DRIVER_CLASS);
    if (Utils.isEmpty(pluginId) && Utils.isEmpty(driverClassName)) {
        throw new KettlePluginException("The attributes 'plugin_id' and 'driver_class' can't be both empty");
    }
    if (Utils.isEmpty(pluginId)) {
        // Determine pluginId using the plugin registry.
        // 
        List<PluginInterface> plugins = pluginRegistry.getPlugins(DatabasePluginType.class);
        for (PluginInterface plugin : plugins) {
            DatabaseInterface databaseInterface = (DatabaseInterface) pluginRegistry.loadClass(plugin);
            if (driverClassName.equalsIgnoreCase(databaseInterface.getDriverClass())) {
                pluginId = plugin.getIds()[0];
            }
        }
    }
    if (Utils.isEmpty(pluginId)) {
        throw new KettlePluginException("The 'plugin_id' attribute could not be determined using 'driver_class' value '" + driverClassName + "'");
    }
    // Look for the plugin
    // 
    PluginInterface plugin = PluginRegistry.getInstance().getPlugin(DatabasePluginType.class, pluginId);
    DatabaseInterface databaseInterface = (DatabaseInterface) PluginRegistry.getInstance().loadClass(plugin);
    databaseInterface.setPluginId(pluginId);
    databaseMeta.setDatabaseInterface(databaseInterface);
    databaseMeta.setObjectId(new StringObjectId(element.getId()));
    databaseMeta.setName(element.getName());
    databaseMeta.setDescription(getChildString(element, MetaStoreConst.DB_ATTR_ID_DESCRIPTION));
    String accessTypeString = getChildString(element, MetaStoreConst.DB_ATTR_ID_ACCESS_TYPE);
    if (Utils.isEmpty(accessTypeString)) {
        accessTypeString = DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_NATIVE);
    }
    databaseMeta.setAccessType(DatabaseMeta.getAccessType(accessTypeString));
    databaseMeta.setHostname(getChildString(element, MetaStoreConst.DB_ATTR_ID_HOSTNAME));
    databaseMeta.setDBPort(getChildString(element, MetaStoreConst.DB_ATTR_ID_PORT));
    databaseMeta.setDBName(getChildString(element, MetaStoreConst.DB_ATTR_ID_DATABASE_NAME));
    databaseMeta.setUsername(getChildString(element, MetaStoreConst.DB_ATTR_ID_USERNAME));
    databaseMeta.setPassword(metaStore.getTwoWayPasswordEncoder().decode(getChildString(element, MetaStoreConst.DB_ATTR_ID_PASSWORD)));
    databaseMeta.setServername(getChildString(element, MetaStoreConst.DB_ATTR_ID_SERVERNAME));
    databaseMeta.setDataTablespace(getChildString(element, MetaStoreConst.DB_ATTR_ID_DATA_TABLESPACE));
    databaseMeta.setIndexTablespace(getChildString(element, MetaStoreConst.DB_ATTR_ID_INDEX_TABLESPACE));
    IMetaStoreAttribute attributesChild = element.getChild(MetaStoreConst.DB_ATTR_ID_ATTRIBUTES);
    if (attributesChild != null) {
        // Now add a list of all the attributes set on the database connection...
        // 
        Properties attributes = databaseMeta.getAttributes();
        for (IMetaStoreAttribute attr : attributesChild.getChildren()) {
            String code = attr.getId();
            String value = getAttributeString(attr);
            attributes.put(code, Const.NVL(value, ""));
        }
    }
    return databaseMeta;
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) Properties(java.util.Properties) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 19 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class PurRepository_GetObjectInformation_IT method getObjectInformation_InvalidRepositoryId_ExceptionIsHandled.

@Test
public void getObjectInformation_InvalidRepositoryId_ExceptionIsHandled() throws Exception {
    IUnifiedRepository unifiedRepository = mock(IUnifiedRepository.class);
    when(unifiedRepository.getFileById(any(Serializable.class))).thenThrow(new RuntimeException("unknown id"));
    purRepository.setTest(unifiedRepository);
    RepositoryObject information = purRepository.getObjectInformation(new StringObjectId("invalid id"), RepositoryObjectType.JOB);
    assertNull("Should return null if file was not found", information);
}
Also used : Serializable(java.io.Serializable) RepositoryObject(org.pentaho.di.repository.RepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 20 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class MQTTProducerMetaTest method testSavingToRepository.

@Test
public void testSavingToRepository() throws Exception {
    StringObjectId stepId = new StringObjectId("step1");
    StringObjectId transId = new StringObjectId("trans1");
    MQTTProducerMeta localMeta = testMeta();
    localMeta.setTopic("weather");
    localMeta.saveRep(rep, metaStore, transId, stepId);
    verify(rep).saveStepAttribute(transId, stepId, "step-xml", localMeta.getXML());
    verifyNoMoreInteractions(rep);
}
Also used : StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Aggregations

StringObjectId (org.pentaho.di.repository.StringObjectId)123 KettleException (org.pentaho.di.core.exception.KettleException)49 ObjectId (org.pentaho.di.repository.ObjectId)38 Test (org.junit.Test)34 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)25 KettleFileException (org.pentaho.di.core.exception.KettleFileException)21 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)18 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)18 ArrayList (java.util.ArrayList)16 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)15 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)14 RepositoryObject (org.pentaho.di.repository.RepositoryObject)14 TransMeta (org.pentaho.di.trans.TransMeta)14 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)13 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)13 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)13 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)13 Repository (org.pentaho.di.repository.Repository)11 IOException (java.io.IOException)10 FileObject (org.apache.commons.vfs2.FileObject)10