From 7f535078ef80a7b7efa3e3325bfccb994fbd00e8 Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Thu, 31 Aug 2017 15:16:38 -0400 Subject: Rename packages to org.onap in 1.4.0-SNAPSHOT 19 - remove openecomp 72 - remediate Sonar scan issues 79 - removed unwanted left menu under Report 90 - apply approved license text Issue: PORTAL-19, PORTAL-72, PORTAL-79, PORTAL-90 Change-Id: I41a0ef5fba623d2242574bd15f2d9fb8029a496c Signed-off-by: Christopher Lott (cl778h) --- .../workflow/controllers/WorkflowController.java | 204 +++++++++++++++++++ .../onap/portalsdk/workflow/dao/WorkflowDAO.java | 50 +++++ .../portalsdk/workflow/dao/WorkflowDAOImpl.java | 127 ++++++++++++ .../workflow/domain/WorkflowSchedule.java | 109 ++++++++++ .../onap/portalsdk/workflow/models/Workflow.java | 221 +++++++++++++++++++++ .../portalsdk/workflow/models/WorkflowLite.java | 192 ++++++++++++++++++ .../workflow/scheduler/WorkFlowScheduleJob.java | 62 ++++++ .../scheduler/WorkFlowScheduleRegistry.java | 123 ++++++++++++ .../services/WorkflowScheduleExecutor.java | 138 +++++++++++++ .../workflow/services/WorkflowScheduleService.java | 52 +++++ .../services/WorkflowScheduleServiceImpl.java | 161 +++++++++++++++ .../workflow/services/WorkflowService.java | 56 ++++++ .../workflow/services/WorkflowServiceImpl.java | 95 +++++++++ 13 files changed, 1590 insertions(+) create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/controllers/WorkflowController.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/dao/WorkflowDAO.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/dao/WorkflowDAOImpl.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/domain/WorkflowSchedule.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/models/Workflow.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/models/WorkflowLite.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/scheduler/WorkFlowScheduleJob.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/scheduler/WorkFlowScheduleRegistry.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleExecutor.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleService.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleServiceImpl.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowService.java create mode 100644 ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowServiceImpl.java (limited to 'ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow') diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/controllers/WorkflowController.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/controllers/WorkflowController.java new file mode 100644 index 00000000..2566868e --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/controllers/WorkflowController.java @@ -0,0 +1,204 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.controllers; + +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.workflow.domain.WorkflowSchedule; +import org.onap.portalsdk.workflow.models.Workflow; +import org.onap.portalsdk.workflow.models.WorkflowLite; +import org.onap.portalsdk.workflow.services.WorkflowService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Created by Ikram on 02/15/2016. + */ +@Controller +@RequestMapping("/") +public class WorkflowController extends RestrictedBaseController { + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WorkflowController.class); + + @Autowired + private WorkflowService workflowService; + // @Autowired + // private CronJobService cronJobService; + + @RequestMapping(value = { "workflows/saveCronJob" }, method = RequestMethod.POST) + public void saveCronJob(HttpServletRequest request, HttpServletResponse response) throws Exception { + + try { + // System.out.println("inside save cron job..."); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + + WorkflowSchedule domainCronJobData = new WorkflowSchedule(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + + domainCronJobData.setCronDetails(root.get("cronJobDataObj").get("startDateTime_CRON").textValue()); + domainCronJobData.setWorkflowKey(root.get("cronJobDataObj").get("workflowKey").textValue()); + domainCronJobData.setArguments(root.get("cronJobDataObj").get("workflow_arguments").textValue()); + domainCronJobData.setServerUrl(root.get("cronJobDataObj").get("workflow_server_url").textValue()); + domainCronJobData + .setStartDateTime(dateFormat.parse(root.get("cronJobDataObj").get("startDateTime").textValue())); + domainCronJobData + .setEndDateTime(dateFormat.parse(root.get("cronJobDataObj").get("endDateTime").textValue())); + domainCronJobData.setRecurrence(root.get("cronJobDataObj").get("recurrence").textValue()); + + workflowService.saveCronJob(domainCronJobData); + + // response.getWriter().write("hello".toString()); + + } catch (Exception e) { + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + + } + + } + + @RequestMapping(value = { "workflows/list" }, method = RequestMethod.GET, produces = "application/json") + public @ResponseBody String getWorkflowList() { + ObjectMapper mapper = new ObjectMapper(); + List workflows = workflowService.getAllWorkflows(); + List workflowLites = new ArrayList(); + + try { + + for (Workflow workflow : workflows) { + WorkflowLite wfl = new WorkflowLite(); + wfl.setId(workflow.getId()); + wfl.setName(workflow.getName()); + wfl.setDescription(workflow.getDescription()); + wfl.setActive(workflow.getActive() == null ? "" : workflow.getActive().toString()); + wfl.setCreated(workflow.getCreated() == null ? "" : workflow.getCreated().toString()); + wfl.setCreatedBy(workflow.getCreatedBy() == null ? "" + : workflow.getCreatedBy().getFirstName() + " " + workflow.getCreatedBy().getLastName()); + wfl.setModifiedBy(workflow.getModifiedBy() == null ? "" + : workflow.getModifiedBy().getFirstName() + " " + workflow.getCreatedBy().getLastName()); + wfl.setLastUpdated(workflow.getLastUpdated() == null ? "" : workflow.getLastUpdated().toString()); + wfl.setWorkflowKey(workflow.getWorkflowKey()); + wfl.setRunLink(workflow.getRunLink()); + wfl.setSuspendLink(workflow.getSuspendLink()); + + workflowLites.add(wfl); + } + + return mapper.writeValueAsString(workflowLites); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return ""; + } + + @RequestMapping(value = "workflows/addWorkflow", method = RequestMethod.POST, consumes = "application/json") + public @ResponseBody Workflow addWorkflow(@RequestBody Workflow workflow, HttpServletRequest request, + HttpServletResponse response) { + String loginId = ((User) (request.getSession().getAttribute("user"))).getLoginId(); + return workflowService.addWorkflow(workflow, loginId); + } + + @RequestMapping(value = "workflows/editWorkflow", method = RequestMethod.POST, consumes = "application/json") + public @ResponseBody Workflow editWorkflow(@RequestBody WorkflowLite workflow, HttpServletRequest request, + HttpServletResponse response) { + String loginId = ((User) (request.getSession().getAttribute("user"))).getLoginId(); + return workflowService.editWorkflow(workflow, loginId); + } + + // @RequestMapping(value = "workflows/removeWorkflow", method = + // RequestMethod.DELETE) + @RequestMapping(value = { "workflows/removeWorkflow" }, method = RequestMethod.POST, consumes = "application/json") + public @ResponseBody void removeWorkflow(@RequestBody Long workflowId, HttpServletRequest request, + HttpServletResponse response) { + + // System.out.println("Removing ... " + workflowId); + + workflowService.deleteWorkflow(workflowId); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + PrintWriter out = null; + try { + request.setCharacterEncoding("UTF-8"); + out = response.getWriter(); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "removeWorkflow failed", e); + } + + JSONObject j = new JSONObject("{removed: 123}"); + out.write(j.toString()); + + } + + @RequestMapping(value = "workflows/removeAllWorkflows", method = RequestMethod.DELETE) + public @ResponseBody void removeAllWorkflows() { + // workflowService.deleteAll(); + } + + @RequestMapping(value = { "/workflows" }, method = RequestMethod.GET) + public ModelAndView getWorkflowPartialPage() { + Map model = new HashMap(); + return new ModelAndView(getViewName(), "workflows", model); + } +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/dao/WorkflowDAO.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/dao/WorkflowDAO.java new file mode 100644 index 00000000..cb7b27a3 --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/dao/WorkflowDAO.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.dao; + +import java.util.List; + +import org.onap.portalsdk.workflow.models.Workflow; +import org.onap.portalsdk.workflow.models.WorkflowLite; + +public interface WorkflowDAO { + public List getWorkflows(); + public Workflow save(Workflow workflow, String creatorId); + public Workflow edit(WorkflowLite workflow, String creatorId); + public void delete(Long workflow); +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/dao/WorkflowDAOImpl.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/dao/WorkflowDAOImpl.java new file mode 100644 index 00000000..8fdb64fc --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/dao/WorkflowDAOImpl.java @@ -0,0 +1,127 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.dao; + +import java.util.Date; +import java.util.List; + +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.workflow.models.Workflow; +import org.onap.portalsdk.workflow.models.WorkflowLite; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; +@Repository +public class WorkflowDAOImpl implements WorkflowDAO{ + + @Autowired + private SessionFactory sessionFactory; + + public Workflow save(Workflow workflow, String creatorId){ + Session session = this.sessionFactory.openSession(); + Transaction tx = session.beginTransaction(); + + try{ + Query query = session.createQuery("from User where loginId =:loginId"); + query.setParameter("loginId", creatorId); + User creator = (User)(query.list().get(0)); + + workflow.setCreatedBy(creator); + workflow.setCreated(new Date()); + } + catch(Exception e){ + e.printStackTrace(); + } + + long id = (Long) session.save(workflow); + Workflow savedWorkflow = (Workflow) session.get(Workflow.class, id); + tx.commit(); + session.close(); + return savedWorkflow; + } + + public List getWorkflows(){ + Session session = this.sessionFactory.openSession(); + @SuppressWarnings("unchecked") + List workflows = session.createQuery("from Workflow").list(); + session.close(); + return workflows; + } + + @Override + public void delete(Long workflowId) { + Session session = this.sessionFactory.openSession(); + Transaction tx = session.beginTransaction(); + Query query = session.createQuery("delete from Workflow where id =:id"); + query.setParameter("id", workflowId); + query.executeUpdate(); + tx.commit(); + session.close(); + } + + @Override + public Workflow edit(WorkflowLite workflowLight, String creatorId) { + Session session = this.sessionFactory.openSession(); + Transaction tx = session.beginTransaction(); + + Query query = session.createQuery("from User where loginId =:loginId"); + query.setParameter("loginId", creatorId); + User creator = (User)(query.list().get(0)); + + Workflow workflowToModify = (Workflow) session.get(Workflow.class, workflowLight.getId()); + + workflowToModify.setActive(workflowLight.getActive().equalsIgnoreCase("true") ? true : false ); + workflowToModify.setSuspendLink(workflowLight.getSuspendLink()); + workflowToModify.setRunLink(workflowLight.getRunLink()); + workflowToModify.setDescription(workflowLight.getDescription()); + workflowToModify.setWorkflowKey(workflowLight.getWorkflowKey()); + workflowToModify.setName(workflowLight.getName()); + + workflowToModify.setModifiedBy(creator); + workflowToModify.setLastUpdated(new Date()); + + session.update(workflowToModify); + Workflow savedWorkflow = (Workflow) session.get(Workflow.class, workflowLight.getId()); + tx.commit(); + session.close(); + return savedWorkflow; + } +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/domain/WorkflowSchedule.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/domain/WorkflowSchedule.java new file mode 100644 index 00000000..58f1377a --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/domain/WorkflowSchedule.java @@ -0,0 +1,109 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.domain; +import java.util.Date; + +import org.onap.portalsdk.core.domain.support.DomainVo; +public class WorkflowSchedule extends DomainVo{ + /** + * + */ + private static final long serialVersionUID = 1L; + private Long id; + private String serverUrl; + private String workflowKey; + private String arguments; + private String cronDetails; + private Date endDateTime; + private Date startDateTime; + private String recurrence; + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getServerUrl() { + return serverUrl; + } + public void setServerUrl(String serverUrl) { + this.serverUrl = serverUrl; + } + public String getWorkflowKey() { + return workflowKey; + } + public void setWorkflowKey(String workflowKey) { + this.workflowKey = workflowKey; + } + public String getArguments() { + return arguments; + } + public void setArguments(String arguments) { + this.arguments = arguments; + } + public String getCronDetails() { + return cronDetails; + } + public void setCronDetails(String cronDetails) { + this.cronDetails = cronDetails; + } + public Date getEndDateTime() { + return endDateTime; + } + public void setEndDateTime(Date endDateTime) { + this.endDateTime = endDateTime; + } + public Date getStartDateTime() { + return startDateTime; + } + public void setStartDateTime(Date startDateTime) { + this.startDateTime = startDateTime; + } + public String getRecurrence() { + return recurrence; + } + public void setRecurrence(String recurrence) { + this.recurrence = recurrence; + } + public static long getSerialversionuid() { + return serialVersionUID; + } + + +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/models/Workflow.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/models/Workflow.java new file mode 100644 index 00000000..734b356f --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/models/Workflow.java @@ -0,0 +1,221 @@ + +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.models; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.onap.portalsdk.core.domain.User; + +@Entity +@Table(name = "fn_workflow") +public class Workflow implements Serializable{ + + private static final long serialVersionUID = -3155065449938005856L; + + @Id + @Column(name = "id") + @GeneratedValue + private Long id; + + @Column + private String name; + + @Column (name = "workflow_key") + private String workflowKey; + + @Column + private String description; + + @Column(name = "created") + private Date created; + + @OneToOne(fetch = FetchType.EAGER)//, cascade = CascadeType.ALL) + @JoinColumn(name = "created_by") + private User createdBy; + + @Column(name = "modified") + private Date lastUpdated; + + @OneToOne(fetch = FetchType.EAGER)//, cascade = CascadeType.ALL) + @JoinColumn(name = "modified_by") + private User modifiedBy; + + @Column(name = "active_yn") + private Boolean active; + + @Column(name = "run_link") + private String runLink; + + @Column(name = "suspend_link") + private String suspendLink; + + @Column(name = "modified_link") + private String modifiedLink; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getRunLink() { + return runLink; + } + + public void setRunLink(String runLink) { + this.runLink = runLink; + } + + public String getSuspendLink() { + return suspendLink; + } + + public void setSuspendLink(String suspendLink) { + this.suspendLink = suspendLink; + } + + public String getModifiedLink() { + return modifiedLink; + } + + public void setModifiedLink(String modifiedLink) { + this.modifiedLink = modifiedLink; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public User getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(User createdBy) { + this.createdBy = createdBy; + } + + public Date getLastUpdated() { + return lastUpdated; + } + + public void setLastUpdated(Date lastUpdated) { + this.lastUpdated = lastUpdated; + } + + public User getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(User modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public String getWorkflowKey() { + return workflowKey; + } + + public void setWorkflowKey(String workflowKey) { + this.workflowKey = workflowKey; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Workflow other = (Workflow) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/models/WorkflowLite.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/models/WorkflowLite.java new file mode 100644 index 00000000..3f689095 --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/models/WorkflowLite.java @@ -0,0 +1,192 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.models; + + +import java.io.Serializable; + +public class WorkflowLite implements Serializable{ + + private static final long serialVersionUID = -3155065449938005856L; + + private Long id; + + private String name; + + private String workflowKey; + + private String description; + + private String created; + + private String createdBy; + + private String lastUpdated; + + private String modifiedBy; + + private String active; + + private String runLink; + + private String suspendLink; + + private String modifiedLink; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getWorkflowKey() { + return workflowKey; + } + + public void setWorkflowKey(String workflowKey) { + this.workflowKey = workflowKey; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCreated() { + return created; + } + + public void setCreated(String created) { + this.created = created; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getLastUpdated() { + return lastUpdated; + } + + public void setLastUpdated(String lastUpdated) { + this.lastUpdated = lastUpdated; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public String getActive() { + return active; + } + + public void setActive(String active) { + this.active = active; + } + + public String getRunLink() { + return runLink; + } + + public void setRunLink(String runLink) { + this.runLink = runLink; + } + + public String getSuspendLink() { + return suspendLink; + } + + public void setSuspendLink(String suspendLink) { + this.suspendLink = suspendLink; + } + + public String getModifiedLink() { + return modifiedLink; + } + + public void setModifiedLink(String modifiedLink) { + this.modifiedLink = modifiedLink; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + WorkflowLite other = (WorkflowLite) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/scheduler/WorkFlowScheduleJob.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/scheduler/WorkFlowScheduleJob.java new file mode 100644 index 00000000..3882865a --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/scheduler/WorkFlowScheduleJob.java @@ -0,0 +1,62 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.scheduler; + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.workflow.services.WorkflowScheduleExecutor; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.springframework.scheduling.quartz.QuartzJobBean; + +public class WorkFlowScheduleJob extends QuartzJobBean{ + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WorkFlowScheduleJob.class); + + @Override + protected void executeInternal(JobExecutionContext context) + throws JobExecutionException { + + String serverUrl = (String)context.getMergedJobDataMap().get("serverUrl"); + String workflowKey = (String)context.getMergedJobDataMap().get("workflowKey"); + //String arguments = (String)context.getMergedJobDataMap().get("arguments"); + logger.info(EELFLoggerDelegate.debugLogger, ("Executing the job for the workflow " + workflowKey)); + WorkflowScheduleExecutor executor = new WorkflowScheduleExecutor(serverUrl, workflowKey); + executor.execute(); + } + +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/scheduler/WorkFlowScheduleRegistry.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/scheduler/WorkFlowScheduleRegistry.java new file mode 100644 index 00000000..2412b992 --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/scheduler/WorkFlowScheduleRegistry.java @@ -0,0 +1,123 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.scheduler; + +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.quartz.impl.triggers.CronTriggerImpl; +import org.springframework.context.annotation.DependsOn; +import org.springframework.scheduling.quartz.CronTriggerFactoryBean; +import org.springframework.scheduling.quartz.JobDetailFactoryBean; +import org.springframework.stereotype.Component; + +@Component +@DependsOn({"systemProperties"}) +public class WorkFlowScheduleRegistry{ + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WorkFlowScheduleRegistry.class); + + public WorkFlowScheduleRegistry() { + + } + + private static final String groupName = "AppGroup"; + private static final String jobName = "WorkflowScheduleJob"; + private static final String triggerName = "WorkflowScheduleTrigger"; + + // @Autowired + // private SystemProperties systemProperties; + + // @Bean + public JobDetailFactoryBean jobDetailFactoryBean(Map contextInfoMap) { + + JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean(); + jobDetailFactory.setJobClass(WorkFlowScheduleJob.class); + jobDetailFactory.setJobDataAsMap(contextInfoMap); + jobDetailFactory.setGroup(groupName); + jobDetailFactory.setName(jobName + "_" + UUID.randomUUID()); + jobDetailFactory.afterPropertiesSet(); + return jobDetailFactory; + } + + // @Bean + public CronTriggerFactoryBean cronTriggerFactoryBean(JobDetailFactoryBean jobDetailFactory, Long id, + String cronExpression, Date startDateTime, Date enddatetime) throws Exception { + CronTriggerFactoryBean cronTriggerFactory = new CronTriggerFactoryBean(); + cronTriggerFactory.setJobDetail(jobDetailFactory.getObject()); + cronTriggerFactory.setStartDelay(3000); + cronTriggerFactory.setName(triggerName + "_" + id); + cronTriggerFactory.setGroup(groupName); + logger.debug(EELFLoggerDelegate.debugLogger, (triggerName + " Scheduled: " + cronExpression)); + cronTriggerFactory.setCronExpression( cronExpression); //"0 * * * * ? *" + cronTriggerFactory.afterPropertiesSet(); + + final CronTriggerImpl cronTrigger = (CronTriggerImpl) cronTriggerFactory.getObject(); + cronTrigger.setStartTime(startDateTime == null ? Calendar.getInstance().getTime() : startDateTime); + cronTrigger.setEndTime(enddatetime); + Date fireAgainTime = cronTrigger.getFireTimeAfter(cronTrigger.getStartTime()); + if (fireAgainTime == null) + throw new Exception("Cron not added as it may not fire again " + " Expr: " + cronExpression + " End Time: " + + cronTrigger.getEndTime()); + return cronTriggerFactory; + + } + + public CronTriggerFactoryBean setUpTrigger(Long wfId, String serverUrl, String workflowKey, String arguments, + String startdatetimecron, Date startDateTime, Date enddatetime) throws Exception { + + Map contextInfo = new HashMap(); + contextInfo.put("serverUrl", serverUrl); + contextInfo.put("workflowKey", workflowKey); + contextInfo.put("arguments", arguments); + JobDetailFactoryBean jobDetailFactory = jobDetailFactoryBean(contextInfo); + + CronTriggerFactoryBean cronTriggerFactory = cronTriggerFactoryBean(jobDetailFactory, wfId, startdatetimecron, startDateTime, enddatetime); + + logger.debug(EELFLoggerDelegate.debugLogger, (" Job to be Scheduled: " + contextInfo.get("workflowKey"))); + + //cronTriggerFactory. + + return cronTriggerFactory; + } + +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleExecutor.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleExecutor.java new file mode 100644 index 00000000..90b9e96a --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleExecutor.java @@ -0,0 +1,138 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.services; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; + +public class WorkflowScheduleExecutor { + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WorkflowScheduleExecutor.class); + + private String serverURL; + private String workflowKey; + private String myUrl; + private String payload; + + //constructor + public WorkflowScheduleExecutor(String serverURL,String workflowKey){ + this.serverURL = serverURL; + this.workflowKey = workflowKey; + this.myUrl = this.serverURL + "/engine-rest/process-definition/key/" + this.workflowKey + "/submit-form";; + this.payload="{\"variables\":{}}"; + } + + public static void main(String [] args) throws Exception { + + } + + public void execute() { + POST_fromURL(myUrl,payload); + } + + public static String get_fromURL(String myURL) { + logger.debug(EELFLoggerDelegate.debugLogger, "get_fromURL: Requested URL {}", myURL); + StringBuilder sb = new StringBuilder(); + URLConnection urlConn = null; + InputStreamReader in = null; + try { + URL url = new URL(myURL); + urlConn = url.openConnection(); + if (urlConn != null) + urlConn.setReadTimeout(60 * 1000); + if (urlConn != null && urlConn.getInputStream() != null) { + in = new InputStreamReader(urlConn.getInputStream(), + Charset.defaultCharset()); + BufferedReader bufferedReader = new BufferedReader(in); + int cp; + while ((cp = bufferedReader.read()) != -1) + sb.append((char) cp); + bufferedReader.close(); + in.close(); + } + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "get_fromURL failed", e); + throw new RuntimeException("Exception while calling URL:"+ myURL, e); + } + finally { + try { + if (in != null) + in.close(); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "get_fromURL close failed", e); + } + } + return sb.toString(); + } + + + public static String POST_fromURL(String myURL, String payload) { + String line; + StringBuffer jsonString = new StringBuffer(); + try { + URL url = new URL(myURL); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Accept", "application/json"); + connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); + writer.write(payload); + writer.close(); + BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); + while ((line = br.readLine()) != null) { + jsonString.append(line); + } + br.close(); + connection.disconnect(); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "POST_fromURL failed", e); + throw new RuntimeException(e.getMessage()); + } + return jsonString.toString(); + } +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleService.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleService.java new file mode 100644 index 00000000..1a64812d --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleService.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.services; + +import java.util.List; + +import org.onap.portalsdk.workflow.domain.WorkflowSchedule; +import org.quartz.Trigger; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; + +public interface WorkflowScheduleService { + List findAll(); + WorkflowSchedule getWorkflowScheduleByKey(Long key); + void saveWorkflowSchedule(WorkflowSchedule ws); + public void triggerWorkflowScheduling(SchedulerFactoryBean schedulerBean, WorkflowSchedule ws); + public List triggerWorkflowScheduling(); +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleServiceImpl.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleServiceImpl.java new file mode 100644 index 00000000..73da941c --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowScheduleServiceImpl.java @@ -0,0 +1,161 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.services; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.workflow.domain.WorkflowSchedule; +import org.onap.portalsdk.workflow.scheduler.WorkFlowScheduleRegistry; +import org.quartz.JobDetail; +import org.quartz.Trigger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.scheduling.quartz.CronTriggerFactoryBean; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + + +@Service("workflowScheduleService") +@Transactional + +public class WorkflowScheduleServiceImpl implements WorkflowScheduleService{ + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WorkflowScheduleServiceImpl.class); + + @Autowired + private DataAccessService dataAccessService; + + @Autowired + private WorkFlowScheduleRegistry workflowRegistry; + + @Autowired + private ApplicationContext appContext; + + + public List findAll() { + + /* List allworkflows = getDataAccessService().getList(WorkflowSchedule.class, null); + for (WorkflowSchedule ws : allworkflows) { + + System.out.println("Key:"+ws.getWorkflowKey()+" "+"CronDetails:"+ws.getStartdatetimecron()); + } */ + @SuppressWarnings("unchecked") + List list = getDataAccessService().getList(WorkflowSchedule.class, null); + return list; + } + + + public void saveWorkflowSchedule(WorkflowSchedule ws){ + + getDataAccessService().saveDomainObject(ws, null); + logger.info(EELFLoggerDelegate.debugLogger, ("Workflow Scheduled " + ws.getId() + " " + ws.getEndDateTime())); + triggerWorkflowScheduling((SchedulerFactoryBean)appContext.getBean(SchedulerFactoryBean.class),ws); + + } + + public void triggerWorkflowScheduling(SchedulerFactoryBean schedulerBean, WorkflowSchedule ws) { + + try { + final CronTriggerFactoryBean triggerBean = workflowRegistry.setUpTrigger(ws.getId(), ws.getServerUrl(), ws.getWorkflowKey(),ws.getArguments(),ws.getCronDetails(), ws.getStartDateTime(),ws.getEndDateTime()); + schedulerBean.getScheduler().scheduleJob((JobDetail)triggerBean.getJobDataMap().get("jobDetail"),triggerBean.getObject()); + } catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger, ("Error scheduling work flow with Id" + ws.getId() + e.getMessage())); + } + + } + + public List triggerWorkflowScheduling() { + + Date date = new Date(); + List triggers = new ArrayList(); + + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + if (getDataAccessService() != null) { + @SuppressWarnings("unchecked") + List allWorkflows = getDataAccessService() + .executeQuery("From WorkflowSchedule where endDateTime > '" + dateFormat.format(date) + "'", null); + + for (WorkflowSchedule ws : allWorkflows) { + logger.info(EELFLoggerDelegate.debugLogger, ("Workflow Scheduled " + ws.getId() + "/ End Time: " + ws.getEndDateTime())); + + try { + + final CronTriggerFactoryBean triggerBean = workflowRegistry.setUpTrigger(ws.getId(), ws.getServerUrl(), ws.getWorkflowKey(),ws.getArguments(), ws.getCronDetails(), ws.getStartDateTime(),ws.getEndDateTime()); + + triggers.add(triggerBean.getObject()); + + //schedulerBean.getScheduler().scheduleJob(trigger); + + + } catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger, ("Error scheduling work flow with Id" + ws.getId() + e.getMessage())); + } + + + } + } + + return triggers; + } + + + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + @Override + public WorkflowSchedule getWorkflowScheduleByKey(Long key) { + return (WorkflowSchedule)(getDataAccessService().getDomainObject(WorkflowSchedule.class, key, null)); + } +} + + diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowService.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowService.java new file mode 100644 index 00000000..a246273b --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowService.java @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.services; + +import java.util.List; + +import org.onap.portalsdk.workflow.domain.WorkflowSchedule; +import org.onap.portalsdk.workflow.models.Workflow; +import org.onap.portalsdk.workflow.models.WorkflowLite; + +public interface WorkflowService { + public void saveCronJob(WorkflowSchedule domainCronJobData); + + public Workflow addWorkflow(Workflow workflow, String creatorId); + + public Workflow editWorkflow(WorkflowLite worklow, String creatorId); + + public void deleteWorkflow(Long worklow); + + public List getAllWorkflows(); +} diff --git a/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowServiceImpl.java b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowServiceImpl.java new file mode 100644 index 00000000..b12aba87 --- /dev/null +++ b/ecomp-sdk/epsdk-workflow/src/main/java/org/onap/portalsdk/workflow/services/WorkflowServiceImpl.java @@ -0,0 +1,95 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.workflow.services; + +import java.util.List; + +import org.onap.portalsdk.workflow.dao.WorkflowDAO; +import org.onap.portalsdk.workflow.domain.WorkflowSchedule; +import org.onap.portalsdk.workflow.models.Workflow; +import org.onap.portalsdk.workflow.models.WorkflowLite; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +@Service("workflowService") +public class WorkflowServiceImpl implements WorkflowService { + + @Autowired + private WorkflowDAO workflowDAO; + + //@Autowired + //private DataAccessService dataAccessService; + + @Autowired + private WorkflowScheduleService workflowScheduleService; + + @Override + public void saveCronJob(WorkflowSchedule domainCronJobData) { + // TODO Auto-generated method stub + workflowScheduleService.saveWorkflowSchedule(domainCronJobData); +/* triggerWorkflowScheduling((SchedulerFactoryBean)appContext.getBean(SchedulerFactoryBean.class),domainCronJobData); +*/ } + + /* + private DataAccessService getDataAccessService() { + // TODO Auto-generated method stub + return dataAccessService; + } + */ + + @Override + public Workflow addWorkflow(Workflow workflow, String creatorId) { + return workflowDAO.save(workflow, creatorId); + } + + @Override + public Workflow editWorkflow(WorkflowLite workflow, String creatorId) { + return workflowDAO.edit(workflow, creatorId); + } + + @Override + public void deleteWorkflow(Long workflowId) { + workflowDAO.delete(workflowId); + } + + @Override + public List getAllWorkflows() { + return workflowDAO.getWorkflows(); + } +} -- cgit 1.2.3-korg