Search in sources :

Example 6 with ParamValue

use of org.pentaho.platform.scheduler2.ws.ParamValue in project pentaho-platform by pentaho.

the class JobParamsAdapter method unmarshal.

public Map<String, ParamValue> unmarshal(JaxBSafeMap safeMap) throws Exception {
    Map<String, ParamValue> unsafeMap = null;
    try {
        unsafeMap = new HashMap<String, ParamValue>();
        for (JaxBSafeEntry safeEntry : safeMap.entry) {
            ParamValue v = safeEntry.getStringValue();
            if (v == null) {
                v = safeEntry.getListValue();
            }
            if (v == null) {
                v = safeEntry.getMapValue();
            }
            unsafeMap.put(safeEntry.key, v);
        }
        return unsafeMap;
    } catch (Throwable t) {
        logger.error(t);
    }
    return null;
}
Also used : JaxBSafeEntry(org.pentaho.platform.scheduler2.ws.JaxBSafeMap.JaxBSafeEntry)

Example 7 with ParamValue

use of org.pentaho.platform.scheduler2.ws.ParamValue in project pentaho-platform by pentaho.

the class ComplianceJaxBTest method testJaxbSafeJob.

@Test
public void testJaxbSafeJob() throws JAXBException {
    JobAdapter.JaxbSafeJob job = new JobAdapter.JaxbSafeJob();
    final Date NOW = new Date();
    job.lastRun = NOW;
    job.nextRun = NOW;
    job.jobName = "testName";
    job.jobId = "testId";
    job.schedulableClass = "test.schedulable.class";
    job.state = Job.JobState.COMPLETE;
    job.userName = "testUsername";
    HashMap<String, ParamValue> params = new HashMap<String, ParamValue>();
    params.put("testStringkey", new StringParamValue("testStringVal"));
    JaxBSafeMap safeMap = new JaxBSafeMap(params);
    job.jobParams = safeMap;
    JobAdapter.JaxbSafeJob unmarshalledJob = JaxBUtil.outin(job, JobAdapter.JaxbSafeJob.class);
    Assert.assertEquals(job.lastRun, unmarshalledJob.lastRun);
    Assert.assertEquals(job.nextRun, unmarshalledJob.nextRun);
    Assert.assertEquals(job.jobName, unmarshalledJob.jobName);
    Assert.assertEquals(job.jobId, unmarshalledJob.jobId);
    Assert.assertEquals(job.schedulableClass, unmarshalledJob.schedulableClass);
    Assert.assertEquals(job.userName, unmarshalledJob.userName);
    Assert.assertEquals(job.state, unmarshalledJob.state);
    Assert.assertEquals(job.jobTrigger, unmarshalledJob.jobTrigger);
    Assert.assertTrue("testStringkey".equals(unmarshalledJob.jobParams.entry.get(0).key));
    Assert.assertTrue("testStringVal".equals(unmarshalledJob.jobParams.entry.get(0).getStringValue().toString()));
}
Also used : HashMap(java.util.HashMap) JaxBSafeMap(org.pentaho.platform.scheduler2.ws.JaxBSafeMap) ListParamValue(org.pentaho.platform.scheduler2.ws.ListParamValue) ParamValue(org.pentaho.platform.scheduler2.ws.ParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) MapParamValue(org.pentaho.platform.scheduler2.ws.MapParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) JobAdapter(org.pentaho.platform.scheduler2.ws.JobAdapter) Date(java.util.Date) Test(org.junit.Test)

Example 8 with ParamValue

use of org.pentaho.platform.scheduler2.ws.ParamValue in project pentaho-platform by pentaho.

the class ComplianceJaxBTest method testJaxbSafeMap.

@Test
public void testJaxbSafeMap() throws JAXBException {
    HashMap<String, ParamValue> params = new HashMap<String, ParamValue>();
    ListParamValue listValue = new ListParamValue();
    listValue.add("testListVal0");
    listValue.add("testListVal1");
    MapParamValue mapValue = new MapParamValue();
    mapValue.put("testMapValueKey", "testMapVal");
    params.put("testStringkey", new StringParamValue("testStringVal"));
    params.put("testListKey", listValue);
    params.put("testMapKey", mapValue);
    // TreeMap implements java.util.SortedMap; applies a natural ordering of its keys;
    Map<String, ParamValue> sortedParams = new TreeMap(params);
    List paramsList = java.util.Arrays.asList(sortedParams.keySet().toArray());
    JaxBSafeMap map = new JaxBSafeMap(sortedParams);
    JaxBSafeMap unmarshalled = JaxBUtil.outin(map, JaxBSafeMap.class, JaxBSafeEntry.class, StringParamValue.class);
    Assert.assertEquals("testStringVal", unmarshalled.entry.get(paramsList.indexOf("testStringkey")).getStringValue().toString());
    Assert.assertEquals("testListVal0", unmarshalled.entry.get(paramsList.indexOf("testListKey")).getListValue().get(0));
    Assert.assertEquals("testMapVal", unmarshalled.entry.get(paramsList.indexOf("testMapKey")).getMapValue().get("testMapValueKey"));
}
Also used : ListParamValue(org.pentaho.platform.scheduler2.ws.ListParamValue) MapParamValue(org.pentaho.platform.scheduler2.ws.MapParamValue) HashMap(java.util.HashMap) JaxBSafeMap(org.pentaho.platform.scheduler2.ws.JaxBSafeMap) ListParamValue(org.pentaho.platform.scheduler2.ws.ListParamValue) ParamValue(org.pentaho.platform.scheduler2.ws.ParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) MapParamValue(org.pentaho.platform.scheduler2.ws.MapParamValue) StringParamValue(org.pentaho.platform.scheduler2.ws.StringParamValue) List(java.util.List) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 9 with ParamValue

use of org.pentaho.platform.scheduler2.ws.ParamValue in project pentaho-platform by pentaho.

the class JobAdapter method toParamValueMap.

@SuppressWarnings("unchecked")
private Map<String, ParamValue> toParamValueMap(Map<String, Serializable> unsafeMap) {
    Map<String, ParamValue> paramValueMap = new HashMap<String, ParamValue>();
    for (Map.Entry<String, Serializable> entry : unsafeMap.entrySet()) {
        if (entry.getValue() instanceof Map) {
            // convert the inner map
            MapParamValue map = new MapParamValue();
            Map innerMap = (Map) entry.getValue();
            Set<Map.Entry> entrySet = innerMap.entrySet();
            for (Map.Entry innerEntry : entrySet) {
                map.put(innerEntry.getKey().toString(), (innerEntry.getValue() == null) ? null : innerEntry.getValue().toString());
            }
            // add the converted map the the top-level map
            paramValueMap.put(entry.getKey(), map);
        } else if (entry.getValue() instanceof List) {
            ListParamValue list = new ListParamValue();
            List innerList = (List) entry.getValue();
            list.addAll(innerList);
            paramValueMap.put(entry.getKey(), list);
        } else {
            paramValueMap.put(entry.getKey(), new StringParamValue((entry.getValue() == null) ? null : entry.getValue().toString()));
        }
    }
    return paramValueMap;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) JaxBSafeEntry(org.pentaho.platform.scheduler2.ws.JaxBSafeMap.JaxBSafeEntry) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ListParamValue (org.pentaho.platform.scheduler2.ws.ListParamValue)7 MapParamValue (org.pentaho.platform.scheduler2.ws.MapParamValue)7 ParamValue (org.pentaho.platform.scheduler2.ws.ParamValue)7 StringParamValue (org.pentaho.platform.scheduler2.ws.StringParamValue)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)5 Date (java.util.Date)4 List (java.util.List)2 Job (org.pentaho.platform.api.scheduler2.Job)2 JaxBSafeMap (org.pentaho.platform.scheduler2.ws.JaxBSafeMap)2 JaxBSafeEntry (org.pentaho.platform.scheduler2.ws.JaxBSafeMap.JaxBSafeEntry)2 Serializable (java.io.Serializable)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Before (org.junit.Before)1 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)1 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)1 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)1 IncrementalRecurrence (org.pentaho.platform.scheduler2.recur.IncrementalRecurrence)1 JobAdapter (org.pentaho.platform.scheduler2.ws.JobAdapter)1