From: Omar Sweidan Date: Fri, 6 May 2022 13:22:48 +0000 (+0200) Subject: feladat megoldva X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=66cdfe04385cdf01e052d13accf4fff98aecc666;p=mediacube.git feladat megoldva --- diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java b/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java index 3e16b64e..7c128a10 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java @@ -155,16 +155,24 @@ public class NoSQLUtils { * * @param source a BasicDBObject to be deep-copied */ - public static void /* BasicDBObject */ deepCopy(BasicDBObject source, BasicDBObject target) { -// BasicDBObject target = new BasicDBObject(); + public static BasicDBObject deepCopy(BasicDBObject source) { HashMap sourceAsMap = (HashMap) source.toMap(); - + BasicDBObject target= new BasicDBObject(); + for (HashMap.Entry entry : sourceAsMap.entrySet()) { String key = entry.getKey(); Object val = entry.getValue(); + if(val instanceof BasicDBList) { + List listval= asList((BasicDBList) val); + val= new BasicDBList(); + + for (BasicDBObject innerObject : listval) { + ((BasicDBList) val).add(deepCopy(innerObject)); + } + } target.put(key, val); } - -// return target; + + return target; } } diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/IJobEngineConfiguration.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/IJobEngineConfiguration.java index f0a9c9de..31b3337c 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/IJobEngineConfiguration.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/IJobEngineConfiguration.java @@ -39,11 +39,11 @@ public interface IJobEngineConfiguration { void saveTemplateXml(JobTemplate jobTemplate) throws ParserConfigurationException; - void saveSchedulesJson() throws Exception; + void saveSchedulesJson(BasicDBObject originalJob, BasicDBObject newJob) throws Exception; void resetStepClassLoader(); - void duplicateTemplate(String originalTemplateName); + String duplicateTemplate(BasicDBObject selectedJob); boolean scheduleExists(String name); diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java index 9f3a83bc..ccae13d4 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java @@ -380,40 +380,24 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { } @Override - public void saveSchedulesJson() throws Exception { + public void saveSchedulesJson(BasicDBObject originalJob, BasicDBObject newJob) throws Exception { logger.info("saveSchedulesJson()"); Path schedulesPath = null; try { schedulesPath = Paths.get(systemConfig.getConfig(CONF_SCHEDULES)); -// if (!Files.exists(schedulesPath)) { -// Files.createFile(schedulesPath); -// } if (Files.isDirectory(schedulesPath)) throw new FileNotFoundException(schedulesPath + " is a directory!"); logger.info("Saving schedules.json to {}", schedulesPath); - BasicDBObject dbo = new BasicDBObject(); - BasicDBList jobList = new BasicDBList(); - for (int i = 0; i < schedules.size(); i++) { - BasicDBObject temp = schedules.get(i).getValue(); - temp.remove("xml"); - jobList.add(temp); - } - dbo.put("joblist", jobList); - if (Files.isWritable(schedulesPath)) { - logger.info("{} is writable", schedulesPath); - } else { - logger.info("{} was not writable", schedulesPath); - DosFileAttributeView dos = Files.getFileAttributeView(schedulesPath, DosFileAttributeView.class); - if (dos != null) { - try { - dos.setReadOnly(false); - logger.info("{} is writable"); - } catch (IOException e) { - logger.info("IOException: {}", e.getCause()); - } + for (int i = 0; i < getSchedules().size(); i++) { + BasicDBObject value = getSchedules().get(i).getValue(); + if (value.equals(originalJob)) { + getSchedules().get(i).setValue(newJob); + break; } } + BasicDBObject dbo = assembleSchedulesJson(); + setFileAsWritable(schedulesPath); Files.write(schedulesPath, dbo.toPrettyString("").getBytes()); } catch (FileNotFoundException e) { logger.error("File not found: {}", CONF_SCHEDULES); @@ -422,6 +406,43 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { } } + private BasicDBObject assembleSchedulesJson() { + BasicDBObject dbo = new BasicDBObject(); + BasicDBList jobList = new BasicDBList(); + for (int i = 0; i < schedules.size(); i++) { + BasicDBObject temp = schedules.get(i).getValue(); + temp.remove("xml"); + temp.remove("nextTime"); + if(temp.get("active") == null) { + temp.remove("active"); + } + if(temp.get("executeimmediate") == null) { + temp.remove("executeimmediate"); + } + jobList.add(temp); + } + dbo.put("joblist", jobList); + + return dbo; + } + + private void setFileAsWritable(Path schedulesPath) { + if (Files.isWritable(schedulesPath)) { + logger.info("{} is writable", schedulesPath); + } else { + logger.info("{} was not writable", schedulesPath); + DosFileAttributeView dos = Files.getFileAttributeView(schedulesPath, DosFileAttributeView.class); + if (dos != null) { + try { + dos.setReadOnly(false); + logger.info("{} is now writable"); + } catch (IOException e) { + logger.info("IOException: {}", e.getCause()); + } + } + } + } + @Override public void saveTemplateXml(JobTemplate templateToSave) { logger.info("saveTemplateXml()"); @@ -485,34 +506,30 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { } @Override - public void duplicateTemplate(String originalTemplateName) { + public String duplicateTemplate(BasicDBObject selectedJob) { logger.info("duplicateTemplate()"); - if (originalTemplateName == null) { - throw new NullPointerException("originalTemplateName == null"); - } Path templatesPath = null; String filePath = null; String duplicateFileName = null; try { templatesPath = Paths.get(systemConfig.getConfig(DIR_TEMPLATES)); - if (!Files.isDirectory(templatesPath)) - throw new FileNotFoundException(templatesPath + " is not a directory!"); - duplicateFileName = FilenameUtils.getName(originalTemplateName).replace(".xml", "").concat("-copy.xml"); + duplicateFileName = FilenameUtils.getName(selectedJob.getString("template")).replace(".xml", "").concat("-copy.xml"); filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator() + duplicateFileName; while (Files.exists(Paths.get(filePath))) { duplicateFileName = FilenameUtils.getName(duplicateFileName).replace(".xml", "").concat("-copy.xml"); filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator() + duplicateFileName; } InputStream is = new FileInputStream( - templatesPath.toString() + FileSystems.getDefault().getSeparator() + originalTemplateName); + templatesPath.toString() + FileSystems.getDefault().getSeparator() + selectedJob.getString("template")); Files.copy(is, Paths.get(filePath)); } catch (FileNotFoundException e) { logger.error("File not found: {}", filePath); } catch (IOException e) { logger.error("IOException: {}", e.getCause()); } - + return duplicateFileName; + } @Override diff --git a/server/user.mediacube.gui/pages/jobeditor2.zul b/server/user.mediacube.gui/pages/jobeditor2.zul index 2cc73997..4f9e2dc1 100644 --- a/server/user.mediacube.gui/pages/jobeditor2.zul +++ b/server/user.mediacube.gui/pages/jobeditor2.zul @@ -13,11 +13,9 @@ - - - - - + + +
@@ -41,53 +39,54 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
- + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -105,29 +104,18 @@
- - -