Search in sources :

Example 56 with StringObjectId

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

the class TransMetaJsonDeserializerTest method testWriteJsonFields.

@Test
public void testWriteJsonFields() throws Exception {
    JsonNode fields = mock(JsonNode.class);
    ObjectId stepId = new StringObjectId("id");
    List<Map<String, Object>> fieldLists = new ArrayList<Map<String, Object>>();
    Map<String, Object> fieldMap0 = new HashMap<String, Object>() {

        {
            put("name", "Test 1");
            put("int", 2);
            put("long", 3L);
            put("double", 3.0D);
            put("bool", true);
            put("null", null);
        }
    };
    Map<String, Object> fieldMap1 = new HashMap<String, Object>() {

        {
            put("name", "Test 2");
            put("int", 2);
            put("long", 3L);
            put("double", 3.0D);
            put("bool", true);
            put("null", null);
        }
    };
    fieldLists.add(fieldMap0);
    fieldLists.add(fieldMap1);
    when(fields.toString()).thenReturn("mockedFields");
    when(mapper.readValue("mockedFields", fieldLists.getClass())).then(invocationOnMock -> fieldLists);
    deserializer.writeJsonFields(fields, mapper, stepId);
    verify(repo).saveStepAttribute(null, stepId, 0, "name", "Test 1");
    verify(repo).saveStepAttribute(null, stepId, 1, "name", "Test 2");
    verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("int"), anyInt());
    verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("long"), eq(3L));
    verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("double"), eq(3.0D));
    verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("bool"), eq(true));
    verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("null"), anyString());
}
Also used : StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) Matchers.anyString(org.mockito.Matchers.anyString) StringObjectId(org.pentaho.di.repository.StringObjectId) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 57 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceReferenceSynchronizerTest method before.

@Before
public void before() {
    ObjectId transId = new StringObjectId("transId");
    when(transMeta.getMetaStore()).thenReturn(externalMetastore);
    when(transMeta.getEmbeddedMetaStore()).thenReturn(embeddedMetastore);
    when(transMeta.getObjectId()).thenReturn(transId);
    when(transMeta.getRepository()).thenReturn(repository);
    when(repository.getRepositoryMeta()).thenReturn(repositoryMeta);
    when(repositoryMeta.getRepositoryCapabilities()).thenReturn(mock(RepositoryCapabilities.class));
    RepositoryDirectoryInterface root = mock(RepositoryDirectoryInterface.class);
    RepositoryDirectoryInterface dir = new RepositoryDirectory(root, "location");
    when(root.findDirectory(eq("/"))).thenReturn(dir);
    try {
        when(repository.getTransformationID(eq("location"), eq(dir))).thenReturn(transId);
        when(repository.loadRepositoryDirectoryTree()).thenReturn(root);
    } catch (KettleException ke) {
    // Noop
    }
    when(context.getPushDownFactories()).thenReturn(Collections.emptyList());
    synchronizer = new DataServiceReferenceSynchronizer(context) {

        protected <T> MetaStoreFactory<T> getMetastoreFactory(IMetaStore metaStore, Class<T> clazz) {
            return externalMetaStoreFactory;
        }

        protected MetaStoreFactory<DataServiceMeta> getEmbeddedMetaStoreFactory(TransMeta meta) {
            return embeddedMetaStoreFactory;
        }
    };
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) MetaStoreFactory(org.pentaho.metastore.persist.MetaStoreFactory) TransMeta(org.pentaho.di.trans.TransMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) IMetaStore(org.pentaho.metastore.api.IMetaStore) RepositoryCapabilities(org.pentaho.di.repository.RepositoryCapabilities) Before(org.junit.Before)

Example 58 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pdi-dataservice-server-plugin by pentaho.

the class BaseTest method createTransMeta.

protected TransMeta createTransMeta(String dataServiceTrans) {
    try {
        KettleClientEnvironment.init();
    } catch (KettleException e) {
        e.printStackTrace();
    }
    TransMeta transMeta = spy(new TransMeta());
    transMeta.setName(dataServiceTrans);
    transMeta.setObjectId(new StringObjectId(UUID.randomUUID().toString()));
    try {
        doNothing().when(transMeta).activateParameters();
        doAnswer(RETURNS_DEEP_STUBS).when(transMeta).getStepFields(any(StepMeta.class));
    } catch (KettleException e) {
        Throwables.propagate(e);
    }
    return transMeta;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransMeta(org.pentaho.di.trans.TransMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) StepMeta(org.pentaho.di.trans.step.StepMeta)

Example 59 with StringObjectId

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

the class JobMetaJsonSerializer method serializeSteps.

@Override
protected void serializeSteps(JobMeta meta, JsonGenerator json) throws IOException {
    json.writeArrayFieldStart(JSON_PROPERTY_STEPS);
    int numberOfEntries = meta.nrJobEntries();
    for (int i = 0; i < numberOfEntries; i++) {
        JobEntryCopy jobEntry = meta.getJobEntry(i);
        LineageRepository repo = getLineageRepository();
        ObjectId jobId = meta.getObjectId() == null ? new StringObjectId(meta.getName()) : meta.getObjectId();
        ObjectId entryId = jobEntry.getObjectId() == null ? new StringObjectId(jobEntry.getName()) : jobEntry.getObjectId();
        JobEntryInterface jobEntryInterface = jobEntry.getEntry();
        JobEntryBase jobEntryBase = getJobEntryBase(jobEntryInterface);
        Job job = new Job(null, meta);
        jobEntryBase.setParentJob(job);
        jobEntryInterface.setObjectId(entryId);
        try {
            jobEntryInterface.saveRep(repo, null, jobId);
        } catch (KettleException e) {
            LOGGER.warn(Messages.getString("INFO.Serialization.Trans.Step", jobEntry.getName()), e);
        }
        json.writeObject(jobEntryBase);
    }
    json.writeEndArray();
}
Also used : JobEntryBase(org.pentaho.di.job.entry.JobEntryBase) KettleException(org.pentaho.di.core.exception.KettleException) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) LineageRepository(org.pentaho.metaverse.impl.model.kettle.LineageRepository) Job(org.pentaho.di.job.Job) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 60 with StringObjectId

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

the class TransMetaJsonDeserializer method deserializeSteps.

protected void deserializeSteps(TransMeta transMeta, JsonNode node, ObjectMapper mapper) throws IOException {
    ArrayNode stepsArrayNode = (ArrayNode) node.get(TransMetaJsonSerializer.JSON_PROPERTY_STEPS);
    String stepName = null;
    for (int i = 0; i < stepsArrayNode.size(); i++) {
        JsonNode stepNode = stepsArrayNode.get(i);
        String className = stepNode.get(IInfo.JSON_PROPERTY_CLASS).asText();
        stepName = stepNode.get(IInfo.JSON_PROPERTY_NAME).asText();
        ObjectId stepId = new StringObjectId(stepName);
        // add the step attributes to the repo so they can be found when they are looked up by the readRep impl
        JsonNode attributes = stepNode.get(AbstractStepMetaJsonSerializer.JSON_PROPERTY_ATTRIBUTES);
        writeJsonAttributes(attributes, mapper, stepId);
        JsonNode fields = stepNode.get(AbstractStepMetaJsonSerializer.JSON_PROPERTY_FIELDS);
        writeJsonFields(fields, mapper, stepId);
        try {
            Class clazz = this.getClass().getClassLoader().loadClass(className);
            BaseStepMeta meta = (BaseStepMeta) clazz.newInstance();
            meta.readRep(getRepository(), null, stepId, transMeta.getDatabases());
            StepMetaInterface smi = (StepMetaInterface) meta;
            StepMeta step = new StepMeta(stepName, smi);
            transMeta.addStep(step);
        } catch (Exception e) {
            LOGGER.warn(Messages.getString("WARNING.Deserialization.Trans.Steps", stepName), e);
        }
    }
}
Also used : StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) KettleException(org.pentaho.di.core.exception.KettleException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

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