public static Tuple<JobDescriptor,JobStatus> convert(JobPersistence persist){
if(persist==null){
return null;
}
JobDescriptor jd=new JobDescriptor();
jd.setId(String.valueOf(persist.getId()));
jd.setName(persist.getName());
jd.setDesc(persist.getDescr());
jd.setOwner(persist.getOwner());
jd.setGroupId(persist.getGroupId()==null?null:String.valueOf(persist.getGroupId()));
jd.setAuto((persist.getAuto()!=null &&persist.getAuto()==1)?true:false);
jd.setCronExpression(persist.getCronExpression());
if(persist.getConfigs()!=null){
JSONObject object=JSONObject.fromObject(persist.getConfigs());
jd.setProperties(new HashMap<String, String>());
for(Object key:object.keySet()){
jd.getProperties().put(key.toString(), object.getString(key.toString()));
}
}
if(persist.getDependencies()!=null){
jd.setDependencies(Arrays.asList(persist.getDependencies().split(",")));
}
jd.setJobType(JobRunType.parser(persist.getRunType()));
jd.setScheduleType(JobScheduleType.parser(persist.getScheduleType()));
String res=persist.getResources();
if(res!=null){
List<Map<String, String>> tempRes=new ArrayList<Map<String,String>>();
JSONArray resArray=JSONArray.fromObject(res);
for(int i=0;i<resArray.size();i++){
JSONObject o=resArray.getJSONObject(i);
Map<String, String> map=new HashMap<String, String>();
for(Object key:o.keySet()){
map.put(key.toString(), o.getString(key.toString()));
}
tempRes.add(map);
}
jd.setResources(tempRes);
}
jd.setScript(persist.getScript());
if(persist.getPreProcessers()!=null && !"".equals(persist.getPreProcessers().trim())){
JSONArray preArray=JSONArray.fromObject(persist.getPreProcessers());
List<Processer> preProcessers=new ArrayList<Processer>();
for(int i=0;i<preArray.size();i++){
Processer p=ProcesserUtil.parse(preArray.getJSONObject(i));
if(p!=null){
preProcessers.add(p);
}
}
jd.setPreProcessers(preProcessers);
}
if(persist.getPostProcessers()!=null && !"".equals(persist.getPostProcessers().trim())){
JSONArray postArray=JSONArray.fromObject(persist.getPostProcessers());
List<Processer> postProcessers=new ArrayList<Processer>();
for(int i=0;i<postArray.size();i++){
Processer p=ProcesserUtil.parse(postArray.getJSONObject(i));
if(p!=null){
postProcessers.add(p);
}
}
jd.setPostProcessers(postProcessers);
}
JobStatus status=new JobStatus();
status.setJobId(String.valueOf(persist.getId()));