public static JobPersistence convert(JobDescriptor jd){
if(jd==null){
return null;
}
JobPersistence persist=new JobPersistence();
JSONArray resArray=new JSONArray();
for(Map<String, String> map:jd.getResources()){
JSONObject o=new JSONObject();
for(String key:map.keySet()){
o.put(key, map.get(key));
}
resArray.add(o);
}
persist.setResources(resArray.toString());
JSONObject object=new JSONObject();
for(Object key:jd.getProperties().keySet()){
object.put(key, jd.getProperties().get(key.toString()));
}
persist.setAuto(jd.getAuto()?1:0);
persist.setConfigs(object.toString());
persist.setCronExpression(jd.getCronExpression());
persist.setDependencies(StringUtils.join(jd.getDependencies().iterator(), ","));
persist.setDescr(jd.getDesc());
persist.setGroupId(jd.getGroupId()==null?null:Integer.valueOf(jd.getGroupId()));
if(jd.getId()!=null){
persist.setId(Long.valueOf(jd.getId()));
}
persist.setName(jd.getName());
persist.setOwner(jd.getOwner());
persist.setRunType(jd.getJobType()==null?null:jd.getJobType().toString());
persist.setScheduleType(jd.getScheduleType()==null?null:jd.getScheduleType().getType());
persist.setScript(jd.getScript());
JSONArray preArray=new JSONArray();
for(Processer p:jd.getPreProcessers()){
JSONObject o=new JSONObject();
o.put("id", p.getId());
o.put("config", p.getConfig());
preArray.add(o);
}
persist.setPreProcessers(preArray.toString());
JSONArray postArray=new JSONArray();
for(Processer p:jd.getPostProcessers()){
JSONObject o=new JSONObject();
o.put("id", p.getId());
o.put("config", p.getConfig());
postArray.add(o);
}
persist.setPostProcessers(postArray.toString());
return persist;
}