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());
}
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;
}
};
}
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;
}
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();
}
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);
}
}
}
Aggregations