From 4bece66fe4516f4cf9a4ce4a7dcac88ed68f88ab Mon Sep 17 00:00:00 2001 From: dawncx Date: Wed, 9 Oct 2013 11:19:30 +0800 Subject: [PATCH 1/3] chenxi --- src/main/java/haflow/dto/entity/Flow.java | 23 + .../haflow/service/FlowExecuteService.java | 169 +- src/main/java/haflow/service/FlowService.java | 77 +- .../haflow/ui/controller/FlowController.java | 23 +- .../haflow/ui/controller/HomeController.java | 23 +- .../haflow/ui/controller/RunController.java | 6 +- .../java/haflow/ui/helper/FlowHelper.java | 20 +- src/main/java/haflow/ui/helper/RunHelper.java | 4 +- src/main/resources/hibernate.cfg.xml | 5 +- src/main/webapp/WEB-INF/views/logon.jsp | 22 +- src/main/webapp/WEB-INF/views/main.jsp | 12 + src/main/webapp/script/haflow.main.js | 3249 +++++++++-------- src/main/webapp/style/haflow.main.css | 6 + 13 files changed, 2037 insertions(+), 1602 deletions(-) diff --git a/src/main/java/haflow/dto/entity/Flow.java b/src/main/java/haflow/dto/entity/Flow.java index a6a16a2..4424fe9 100644 --- a/src/main/java/haflow/dto/entity/Flow.java +++ b/src/main/java/haflow/dto/entity/Flow.java @@ -8,6 +8,8 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -18,6 +20,8 @@ public class Flow { private String name; private Set nodes; private Set edges; + private MainUser user; + private Set exeHistory; @Id @Column(name = "id", length = 16) @@ -55,4 +59,23 @@ public class Flow { public void setEdges(Set edges) { this.edges = edges; } + + @OneToMany(mappedBy = "flow", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + public Set getExeHistory() { + return exeHistory; + } + + public void setExeHistory(Set exeHistory) { + this.exeHistory = exeHistory; + } + + @ManyToOne + @JoinColumn(name="mainuser_id",referencedColumnName="id") + public MainUser getUser() { + return user; + } + + public void setUser(MainUser user) { + this.user = user; + } } diff --git a/src/main/java/haflow/service/FlowExecuteService.java b/src/main/java/haflow/service/FlowExecuteService.java index c9d1cb3..4b5b012 100644 --- a/src/main/java/haflow/service/FlowExecuteService.java +++ b/src/main/java/haflow/service/FlowExecuteService.java @@ -1,67 +1,102 @@ -package haflow.service; - -import haflow.dto.entity.Flow; -import haflow.engine.RunFlowResult; -import haflow.engine.oozie.OozieEngine; -import haflow.ui.model.RunFlowResultModel; -import haflow.ui.model.ValidateFlowResultModel; - -import java.util.UUID; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class FlowExecuteService { - - private FlowService flowService; - private OozieEngine engin; - - public OozieEngine getEngin() { - return engin; - } - - @Autowired - public void setEngin(OozieEngine engin) { - this.engin = engin; - } - - private FlowService getFlowService() { - return flowService; - } - - @Autowired - private void setFlowService(FlowService flowService) { - this.flowService = flowService; - } - - // TODO - public ValidateFlowResultModel validateFlow(UUID flowId) { - // Flow flow = (Flow) this.getFlowService().getFlow(flowId); - // this.getEngin().validateFlow(flow); - return null; - } - - public RunFlowResultModel runFlow(UUID flowId) { - RunFlowResultModel result = new RunFlowResultModel(); - result.setFlowId(flowId); - result.setCommited(false); - StringBuilder messageBuilder = new StringBuilder(); - - Flow flow = (Flow) this.getFlowService().getFlow(flowId); - if (flow == null) { - messageBuilder.append("Flow " + flowId + " not found!"); - result.setMessage(messageBuilder.toString()); - return result; - } - - RunFlowResult enginResult = this.getEngin().runFlow(flow); - - result.setCommited(enginResult.isCommitted()); - result.setJobId(enginResult.getJobId()); - result.setMessage(enginResult.getMessage()); - - return result; - } - -} +package haflow.service; + +import haflow.dto.entity.Flow; +import haflow.dto.entity.FlowRunHistory; +import haflow.engine.RunFlowResult; +import haflow.engine.oozie.OozieEngine; +import haflow.ui.model.RunFlowResultModel; +import haflow.ui.model.ValidateFlowResultModel; +import haflow.util.SessionHelper; + +import java.util.Date; +import java.util.UUID; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class FlowExecuteService { + + private FlowService flowService; + private OozieEngine engin; + private SessionHelper sessionHelper; + + public OozieEngine getEngin() { + return engin; + } + + @Autowired + public void setEngin(OozieEngine engin) { + this.engin = engin; + } + + private FlowService getFlowService() { + return flowService; + } + + @Autowired + private void setFlowService(FlowService flowService) { + this.flowService = flowService; + } + + private SessionHelper getSessionHelper() { + return sessionHelper; + } + + @Autowired + private void setSessionHelper(SessionHelper sessionHelper) { + this.sessionHelper = sessionHelper; + } + + // TODO + public ValidateFlowResultModel validateFlow(UUID flowId) { + // Flow flow = (Flow) this.getFlowService().getFlow(flowId); + // this.getEngin().validateFlow(flow); + return null; + } + + public RunFlowResultModel runFlow(UUID flowId) { + RunFlowResultModel result = new RunFlowResultModel(); + result.setFlowId(flowId); + result.setCommited(false); + StringBuilder messageBuilder = new StringBuilder(); + + Flow flow = (Flow) this.getFlowService().getFlow(flowId); + if (flow == null) { + messageBuilder.append("Flow " + flowId + " not found!"); + result.setMessage(messageBuilder.toString()); + return result; + } + + RunFlowResult enginResult = this.getEngin().runFlow(flow); + + //record run history to database + Session session = this.getSessionHelper().openSession(); + Transaction transaction = session.beginTransaction(); + + FlowRunHistory feh = new FlowRunHistory(); + feh.setId(UUID.randomUUID()); + feh.setOozieJobId(enginResult.getJobId()); + feh.setCommitMessage(enginResult.getMessage()); + feh.setTimestamp(new Date()); + feh.setFlow(flow); + + try{ + session.merge(feh); + transaction.commit(); + }catch(Exception e){ + transaction.rollback(); + }finally{ + session.close(); + } + + result.setCommited(enginResult.isCommitted()); + result.setJobId(enginResult.getJobId()); + result.setMessage(enginResult.getMessage()); + + return result; + } + +} diff --git a/src/main/java/haflow/service/FlowService.java b/src/main/java/haflow/service/FlowService.java index cfdbcba..cdf194c 100644 --- a/src/main/java/haflow/service/FlowService.java +++ b/src/main/java/haflow/service/FlowService.java @@ -2,6 +2,7 @@ package haflow.service; import haflow.dto.entity.Edge; import haflow.dto.entity.Flow; +import haflow.dto.entity.MainUser; import haflow.dto.entity.Node; import haflow.util.SessionHelper; @@ -30,10 +31,11 @@ public class FlowService { } public boolean saveFlow(UUID flowId, String name, Set nodes, - Set edges) { + Set edges, int userid) { Session session = this.getSessionHelper().openSession(); Transaction transaction = session.beginTransaction(); try { + MainUser user = (MainUser) session.get(MainUser.class, userid); Flow flow = (Flow) session.get(Flow.class, flowId); if (flow == null) { flow = new Flow(); @@ -41,12 +43,13 @@ public class FlowService { flow.setName(name); flow.setNodes(new HashSet()); flow.setEdges(new HashSet()); - session.merge(flow); - } - + flow.setUser(user); + } + flow.setName(name); flow.getNodes().clear(); flow.getEdges().clear(); + for (Node node : nodes) { node.setFlow(flow); @@ -71,31 +74,50 @@ public class FlowService { } flow.getEdges().add(edge); } + session.merge(flow); + transaction.commit(); - session.close(); return true; } catch (Exception e) { e.printStackTrace(); transaction.rollback(); - session.close(); return false; + } finally { + if (session != null) + session.close(); } } - public boolean removeFlow(UUID flowId) { + public boolean removeFlow(UUID flowId,int userid) { Session session = this.getSessionHelper().openSession(); Transaction transaction = session.beginTransaction(); - Flow flow = (Flow) session.get(Flow.class, flowId); - if (flow == null) { - return false; - } - + MainUser user=(MainUser) session.get(MainUser.class, userid); try { - session.delete(flow); - transaction.commit(); - session.close(); - return true; + for(Flow f:user.getFlows()){ + if(f.getId().equals(flowId)){ + user.getFlows().remove(f); + f.setUser(null); + session.delete(f); + transaction.commit(); + session.close(); + return true; + } + + } + return false; + + //Flow flow = (Flow) session.get(Flow.class, flowId); +// if (flow == null) { +// return false; +// } + +// try { +// System.out.println("remove flow before"); +// session.delete(flow); +// transaction.commit(); +// session.close(); +// return true; } catch (Exception e) { e.printStackTrace(); transaction.rollback(); @@ -105,10 +127,10 @@ public class FlowService { } @SuppressWarnings("unchecked") - public List getFlowList() { + public List getFlowList(int userid) { Session session = this.getSessionHelper().openSession(); try { - Query query = session.createQuery("from Flow flow"); + Query query = session.createQuery("select f from Flow f join f.user u where u.id= "+userid); List flows = (List) query.list(); session.close(); return flows; @@ -119,16 +141,27 @@ public class FlowService { } } - public Flow getFlow(UUID flowId) { + public Flow getFlow(UUID flowId,int userid) { Session session = this.getSessionHelper().openSession(); try { - Flow flow = (Flow) session.get(Flow.class, flowId); - session.close(); - return flow; + MainUser user = (MainUser) session.get(MainUser.class, userid); + + Set flows = (Set) user.getFlows(); + for (Flow flow : flows) { + if (flow.getId().equals(flowId)) { + return flow; + } + } + return null; + //Flow flow = (Flow) session.get(Flow.class, flowId); + } catch (Exception e) { e.printStackTrace(); session.close(); return null; + }finally{ + if(session!=null) + session.close(); } } } diff --git a/src/main/java/haflow/ui/controller/FlowController.java b/src/main/java/haflow/ui/controller/FlowController.java index 06e603d..aaca9e9 100644 --- a/src/main/java/haflow/ui/controller/FlowController.java +++ b/src/main/java/haflow/ui/controller/FlowController.java @@ -1,6 +1,7 @@ package haflow.ui.controller; import haflow.ui.helper.FlowHelper; +import haflow.ui.helper.UserHelper; import haflow.ui.model.SaveFlowModel; import haflow.ui.model.FlowListModel; import haflow.ui.model.FlowModel; @@ -10,6 +11,8 @@ import haflow.ui.model.RemoveFlowResultModel; import java.util.UUID; +import javax.servlet.http.HttpServletRequest; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; @@ -34,35 +37,35 @@ public class FlowController { @RequestMapping(method = RequestMethod.GET) @ResponseBody - public FlowListModel get() { - return this.getFlowHelper().getFlowList(); + public FlowListModel get(HttpServletRequest request) { + return this.getFlowHelper().getFlowList((Integer)request.getSession().getAttribute("userid")); } @RequestMapping(value = "/{flowId}", method = RequestMethod.GET) @ResponseBody - public FlowModel get(@PathVariable UUID flowId) { - return this.getFlowHelper().getFlow(flowId); + public FlowModel get(@PathVariable UUID flowId,HttpServletRequest request) { + return this.getFlowHelper().getFlow(flowId,(Integer)request.getSession().getAttribute("userid")); } @RequestMapping(value = "/{flowId}", method = RequestMethod.POST) @ResponseBody public SaveFlowResultModel post(@PathVariable UUID flowId, - @RequestBody SaveFlowModel model) { - return this.getFlowHelper().saveFlow(flowId, model); + @RequestBody SaveFlowModel model,HttpServletRequest request) { + return this.getFlowHelper().saveFlow(flowId, model,(Integer)request.getSession().getAttribute("userid")); } @RequestMapping(value = "/{flowId}", method = RequestMethod.PUT) @ResponseBody public SaveFlowResultModel put(@PathVariable UUID flowId, - @RequestBody SaveFlowModel model) { - return this.getFlowHelper().saveFlow(flowId, model); + @RequestBody SaveFlowModel model,HttpServletRequest request) { + return this.getFlowHelper().saveFlow(flowId, model,(Integer)request.getSession().getAttribute("userid")); } @RequestMapping(value = "/{flowId}", method = RequestMethod.DELETE) @ResponseBody public RemoveFlowResultModel delete(@PathVariable UUID flowId, - @RequestBody RemoveFlowModel model) { - return this.getFlowHelper().removeFlow(flowId, model); + @RequestBody RemoveFlowModel model,HttpServletRequest request) { + return this.getFlowHelper().removeFlow(flowId, model,(Integer)request.getSession().getAttribute("userid")); } } diff --git a/src/main/java/haflow/ui/controller/HomeController.java b/src/main/java/haflow/ui/controller/HomeController.java index 2337548..34196f6 100644 --- a/src/main/java/haflow/ui/controller/HomeController.java +++ b/src/main/java/haflow/ui/controller/HomeController.java @@ -1,5 +1,7 @@ package haflow.ui.controller; +import javax.servlet.http.HttpServletRequest; + import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @@ -9,18 +11,21 @@ public class HomeController { @RequestMapping("/") public ModelAndView logon() { + return new ModelAndView("logon"); } - @RequestMapping("/main") - public ModelAndView main() { - return new ModelAndView("main"); - } - - @RequestMapping("/admin") - public ModelAndView admin() { - return new ModelAndView("admin"); - } + + +// @RequestMapping("/main") +// public ModelAndView main() { +// return new ModelAndView("main"); +// } +// +// @RequestMapping("/admin") +// public ModelAndView admin() { +// return new ModelAndView("admin"); +// } @RequestMapping({ "/oozie" }) public ModelAndView oozie() { diff --git a/src/main/java/haflow/ui/controller/RunController.java b/src/main/java/haflow/ui/controller/RunController.java index a468285..51cce1b 100644 --- a/src/main/java/haflow/ui/controller/RunController.java +++ b/src/main/java/haflow/ui/controller/RunController.java @@ -2,6 +2,8 @@ package haflow.ui.controller; import java.util.UUID; +import javax.servlet.http.HttpServletRequest; + import haflow.ui.helper.RunHelper; import haflow.ui.model.RunFlowModel; import haflow.ui.model.RunFlowResultModel; @@ -31,7 +33,7 @@ public class RunController { @RequestMapping(value = "/{flowId}", method = RequestMethod.POST) @ResponseBody public RunFlowResultModel post(@PathVariable UUID flowId, - @RequestBody RunFlowModel model) { - return this.getRunHelper().runFlow(flowId, model); + @RequestBody RunFlowModel model,HttpServletRequest request) { + return this.getRunHelper().runFlow(flowId, model,(Integer)request.getSession().getAttribute("userid")); } } diff --git a/src/main/java/haflow/ui/helper/FlowHelper.java b/src/main/java/haflow/ui/helper/FlowHelper.java index 6ac63b7..b6e7a0d 100644 --- a/src/main/java/haflow/ui/helper/FlowHelper.java +++ b/src/main/java/haflow/ui/helper/FlowHelper.java @@ -65,8 +65,8 @@ public class FlowHelper { this.nodeConfigurationProfileService = nodeConfigurationProfileService; } - public FlowListModel getFlowList() { - List flowList = this.getFlowService().getFlowList(); + public FlowListModel getFlowList(int userid) { + List flowList = this.getFlowService().getFlowList(userid); FlowListModel flowListModel = new FlowListModel(); flowListModel.setFlows(new ArrayList()); for (Flow flow : flowList) { @@ -78,8 +78,8 @@ public class FlowHelper { return flowListModel; } - public FlowModel getFlow(UUID flowId) { - Flow flow = this.getFlowService().getFlow(flowId); + public FlowModel getFlow(UUID flowId,int userid) { + Flow flow = this.getFlowService().getFlow(flowId,userid); if (flow == null) { return null; } @@ -127,8 +127,8 @@ public class FlowHelper { return flowModel; } - public SaveFlowResultModel saveFlow(UUID flowId, SaveFlowModel model) { - boolean success = this.doSaveFlow(flowId, model); + public SaveFlowResultModel saveFlow(UUID flowId, SaveFlowModel model,int userid) { + boolean success = this.doSaveFlow(flowId, model,userid); SaveFlowResultModel result = new SaveFlowResultModel(); result.setFlowId(flowId); result.setSuccess(success); @@ -140,7 +140,7 @@ public class FlowHelper { return result; } - public boolean doSaveFlow(UUID flowId, SaveFlowModel model) { + public boolean doSaveFlow(UUID flowId, SaveFlowModel model,int userid) { Set nodes = new HashSet(); Set edges = new HashSet(); for (NodeModel nodeModel : model.getNodes()) { @@ -184,7 +184,7 @@ public class FlowHelper { boolean result = true; result = result && this.getFlowService().saveFlow(flowId, model.getName(), - nodes, edges); + nodes, edges,userid); result = result && this.getNodeAppearanceService() .cleanUpOrphanNodeAppearance(); @@ -194,8 +194,8 @@ public class FlowHelper { return result; } - public RemoveFlowResultModel removeFlow(UUID flowId, RemoveFlowModel model) { - boolean success = this.getFlowService().removeFlow(flowId); + public RemoveFlowResultModel removeFlow(UUID flowId, RemoveFlowModel model,int userid) { + boolean success = this.getFlowService().removeFlow(flowId,userid); success = success && this.getNodeAppearanceService() .cleanUpOrphanNodeAppearance(); diff --git a/src/main/java/haflow/ui/helper/RunHelper.java b/src/main/java/haflow/ui/helper/RunHelper.java index 5f2ab15..53ca516 100644 --- a/src/main/java/haflow/ui/helper/RunHelper.java +++ b/src/main/java/haflow/ui/helper/RunHelper.java @@ -22,9 +22,9 @@ public class RunHelper { this.flowExecuteService = flowExecuteService; } - public RunFlowResultModel runFlow(UUID flowId, RunFlowModel model) { + public RunFlowResultModel runFlow(UUID flowId, RunFlowModel model,int userid) { RunFlowResultModel result = this.getFlowExecuteService() - .runFlow(flowId); + .runFlow(flowId,userid); return result; } diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index aede717..7f7a036 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -18,7 +18,10 @@ - + + + + diff --git a/src/main/webapp/WEB-INF/views/logon.jsp b/src/main/webapp/WEB-INF/views/logon.jsp index e9421d8..a4a27f8 100644 --- a/src/main/webapp/WEB-INF/views/logon.jsp +++ b/src/main/webapp/WEB-INF/views/logon.jsp @@ -9,6 +9,7 @@ + Haflow Logon @@ -24,20 +25,31 @@
+ +
- 用户名: + 用户名: +

- 密码: + 密码: + +

+
<%if(request.getAttribute("message")!=null) out.println(request.getAttribute("message")); %>
+
- +    - +
+
+ 还没有账户?立即注册 +
+
- \ No newline at end of file + diff --git a/src/main/webapp/WEB-INF/views/main.jsp b/src/main/webapp/WEB-INF/views/main.jsp index 4e7e9c6..3a41374 100644 --- a/src/main/webapp/WEB-INF/views/main.jsp +++ b/src/main/webapp/WEB-INF/views/main.jsp @@ -6,6 +6,9 @@ String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; + String username=request.getSession().getAttribute("username").toString(); + Object userid=request.getSession().getAttribute("userid"); + %> @@ -19,6 +22,8 @@ + + + + + + \ No newline at end of file diff --git a/src/main/webapp/script/haflow.main.js b/src/main/webapp/script/haflow.main.js index 9b2a1d4..472fdb1 100644 --- a/src/main/webapp/script/haflow.main.js +++ b/src/main/webapp/script/haflow.main.js @@ -1,1474 +1,1775 @@ -dojo.require("dojo.dom"); -dojo.require("dojo.json"); -dojo.require("dojo.store.Memory"); -dojo.require("dojo.store.Observable"); -dojo.require("dijit.form.Button"); -dojo.require("dijit.form.CheckBox"); -dojo.require("dijit.form.TextBox"); -dojo.require("dijit.layout.BorderContainer"); -dojo.require("dijit.layout.TabContainer"); -dojo.require("dijit.layout.ContentPane"); -dojo.require("dijit.tree.ObjectStoreModel"); -dojo.require("dijit.Menu"); -dojo.require("dijit.MenuItem"); -dojo.require("dijit.MenuBar"); -dojo.require("dijit.MenuBarItem"); -dojo.require("dijit.PopupMenuBarItem"); -dojo.require("dijit.TitlePane"); -dojo.require("dijit.Toolbar"); -dojo.require("dijit.Tree"); -dojo.require("dijit.registry"); - -var flow; - -dojo.ready(function() { - flow = new HAFlow.Main(new HAFlow.UI()); - flow.init(); -}); - -HAFlow.Main = function(ui) { - this.basePath = dojo.byId("basePath").value; - this.ui = ui; - this.rootPath = "hdfs://m150:9000/user/root"; -}; - -// Flow -HAFlow.Main.prototype.newFlow = function() { - var newFlowId = HAFlow.generateUUID(); - this.flows[newFlowId] = {}; - this.flows[newFlowId].id = newFlowId; - this.flows[newFlowId].name = "NewFlow"; - this.flows[newFlowId].nodes = new Array(); - this.flows[newFlowId].edges = new Array(); - var _currentInstance = this; - var contentPane = new dijit.layout.ContentPane({ - id : "flowContainerPane_" + newFlowId, - title : _currentInstance.flows[newFlowId].name, - content : "
", - closable : true, - onClose : _currentInstance.onCloseTab(_currentInstance) - }); - this.ui.centerContainer.addChild(contentPane); - this.ui.centerContainer.selectChild(contentPane); - this.setupDroppable(newFlowId); - this.paintFlow(newFlowId); - this.saveFlow(newFlowId); - this.flowListStore.put({ - id : this.flows[newFlowId].id, - name : this.flows[newFlowId].name, - node : true - }); -}; - -HAFlow.Main.prototype.loadFlow = function(flowId) { - if (dojo.byId("flowContainer_" + flowId) == null) { - var _currentInstance = this; - $.ajax({ - url : _currentInstance.basePath + "flow/" + flowId, - type : "GET", - cache : false, - dataType : "json", - success : function(data, status) { - _currentInstance.flows[data.id] = data; - var contentPane = new dijit.layout.ContentPane({ - id : "flowContainerPane_" + flowId, - title : _currentInstance.flows[flowId].name, - content : "
", - closable : true, - onClose : _currentInstance.onCloseTab(_currentInstance) - }); - _currentInstance.ui.centerContainer.addChild(contentPane); - _currentInstance.setupDroppable(flowId); - _currentInstance.paintFlow(flowId); - _currentInstance.ui.centerContainer.selectChild(dijit - .byId("flowContainerPane_" + flowId)); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while loading flow: " + error); - } - }); - } else { - this.ui.centerContainer.selectChild(dijit.byId("flowContainerPane_" - + flowId)); - } -}; - -HAFlow.Main.prototype.saveFlow = function(flowId) { - var _currentInstance = this; - $.ajax({ - url : _currentInstance.basePath + "flow/" + flowId, - type : "PUT", - dataType : "json", - contentType : "application/json", - data : JSON.stringify(_currentInstance.flows[flowId]), - success : function(data, status) { - HAFlow.showDialog("Save Flow", "Flow saved."); - _currentInstance.refreshFlowList(); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", "An error occurred while saving flow: " - + error); - } - }); -}; - -HAFlow.Main.prototype.removeFlow = function(flowId) { - var _currentInstance = this; - $.ajax({ - url : _currentInstance.basePath + "flow/" + flowId, - type : "DELETE", - dataType : "json", - contentType : "application/json", - data : JSON.stringify({}), - success : function(data, status) { - HAFlow.showDialog("Remove Flow", "Flow removed."); - _currentInstance.ui.centerContainer.removeChild(dijit - .byId("flowContainerPane_" + flowId)); - _currentInstance.refreshFlowList(); - _currentInstance.flowListStore - .remove(_currentInstance.flows[flowId].id); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while removing flow: " + error); - } - }); -}; - -HAFlow.Main.prototype.openoozie = function() { - var _currentInstance = this; - $.ajax({ - url : _currentInstance.basePath + "oozie/", - type : "Post", - success : function(data, status) { - var contentPane = new dijit.layout.ContentPane({ - id : "oozie", - title : "oozie", - content : data, - closable : true, - }); - _currentInstance.ui.centerContainer.addChild(contentPane); - _currentInstance.ui.centerContainer.selectChild(contentPane); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while opening: " + error); - } - }); -}; - -HAFlow.Main.prototype.runFlow = function(flowId) { - var _currentInstance = this; - $.ajax({ - url : _currentInstance.basePath + "flow/" + flowId, - type : "PUT", - dataType : "json", - contentType : "application/json", - data : JSON.stringify(_currentInstance.flows[flowId]), - success : function(data, status) { - HAFlow.showDialog("Save Flow", "Flow saved."); - _currentInstance.refreshFlowList(); - $.ajax({ - url : _currentInstance.basePath + "run/" + flowId, - type : "POST", - dataType : "json", - contentType : "application/json", - data : JSON.stringify({}), - success : function(data, status) { - HAFlow.showDialog("Run Flow", " Commited: " + data.commited - + "\n" + "Result: " + data.message); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while running flow: " + error); - } - }); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", "An error occurred while saving flow: " - + error); - } - }); -}; - -// Flow Helper -HAFlow.Main.prototype.refreshFlowList = function() { - var _currentInstance = this; - $.ajax({ - url : this.basePath + "flow", - type : "GET", - cache : false, - dataType : "json", - success : function(data, status) { - _currentInstance.flowList = data; - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while refreshing flow list: " + error); - } - }); -}; - -HAFlow.Main.prototype.getFlowBriefById = function(instance, flowId) { - var i; - for (i = 0; i < instance.flowList.flows.length; i++) { - if (instance.flowList.flows[i].id == flowId) { - return instance.flowList.flows[i]; - } - } - return null; -}; - -HAFlow.Main.prototype.getNodeById = function(instance, flowId, nodeId) { - var i; - for (i = 0; i < instance.flows[flowId].nodes.length; i++) { - if (instance.flows[flowId].nodes[i].id == nodeId) { - return instance.flows[flowId].nodes[i]; - } - } - return null; -}; - -HAFlow.Main.prototype.getModuleById = function(instance, moduleId) { - var i; - for (i = 0; i < instance.moduleList.modules.length; i++) { - if (instance.moduleList.modules[i].id == moduleId) { - return instance.moduleList.modules[i]; - } - } - return null; -}; - -HAFlow.Main.prototype.getConfigurationValue = function(instance, flowId, - nodeId, key) { - var node = instance.getNodeById(instance, flowId, nodeId); - var i; - for (i = 0; i < node.configurations.length; i++) { - if (node.configurations[i].key == key) { - return node.configurations[i].value; - } - } - return ""; -}; - -HAFlow.Main.prototype.checkNodeName = function(instance, flowId, oldName, - newName) { - var i; - if (oldName == newName) { - return true; - } - var regex = /^[a-zA-Z_][a-zA-Z_0-9]{0,38}$/; - if (!regex.test(newName)) { - return false; - } - for (i = 0; i < instance.flows[flowId].nodes.length; i++) { - if (newName == instance.flows[flowId].nodes[i].name) { - return false; - } - } - return true; -}; - -HAFlow.Main.prototype.checkFlowName = function(instance, oldName, newName) { - var i; - if (oldName == newName) { - return true; - } - var regex = /^[a-zA-Z_][a-zA-Z_0-9]{0,38}$/; - if (!regex.test(newName)) { - return false; - } - for (i = 0; i < instance.flows.length; i++) { - if (newName == instance.flows[i].name) { - return false; - } - } - return true; -}; - -HAFlow.Main.prototype.saveNodeName = function(instance, flowId, nodeId) { - var node = instance.getNodeById(instance, flowId, nodeId); - var value = $("#" + "node_" + nodeId + "_name").val(); - if (instance.checkNodeName(instance, flowId, node.name, value)) { - node.name = value; - instance.paintFlow(flowId); - instance.jsPlumb[flowId].repaintEverything(); - } else { - HAFlow.showDialog("Error", "Invalid node name"); - } -}; - -HAFlow.Main.prototype.saveConfiguration = function(instance, flowId, nodeId) { - var node = instance.getNodeById(instance, flowId, nodeId); - var module = instance.getModuleById(instance, node.moduleId); - var i; - node.configurations = []; - for (i = 0; i < module.configurations.length; i++) { - var val = dijit.registry.byId("flow_" + flowId + "_node_" + nodeId + "_"+ module.configurations[i].key).get("value"); - if (module.configurations[i].type!="BOOLEAN"&&val!=null&&val.match(module.configurations[i].pattern) == null) { - HAFlow.showDialog("Error", "Invalid node configuration: " - + module.configurations[i].displayName); - return; - } - } - for (i = 0; i < module.configurations.length; i++) { - console.log(module.configurations[i].displayName); - node.configurations.push({ - key : module.configurations[i].key, - value:dijit.registry.byId("flow_" + flowId + "_node_" + nodeId + "_"+ module.configurations[i].key).get("value") - }); - } - -}; - -HAFlow.Main.prototype.newConnection = function(flowId, source, sourceEndpoint, - target, targetEndpoint) { - var newConnection = {}; - newConnection["id"] = HAFlow.generateUUID(); - newConnection["flowId"] = flowId; - newConnection["sourceNodeId"] = source; - newConnection["sourceEndpoint"] = sourceEndpoint; - newConnection["targetNodeId"] = target; - newConnection["targetEndpoint"] = targetEndpoint; - return newConnection; -}; - -HAFlow.Main.prototype.deleteConnection = function(instance, flowId, info) { - var source = info.sourceId.replace("node_", ""); - var target = info.targetId.replace("node_", ""); - var i; - var needToDelete = false; - do { - needToDelete = false; - for (i = 0; i < instance.flows[flowId].edges.length; i++) { - if (instance.flows[flowId].edges[i].sourceNodeId == source - && instance.flows[flowId].edges[i].targetNodeId == target) { - needToDelete = true; - break; - } - } - if (needToDelete) { - instance.flows[flowId].edges.splice(i, 1); - } - } while (needToDelete); - instance.jsPlumb[flowId].detach(info); -}; - -HAFlow.Main.prototype.deleteNode = function(instance, flowId, nodeId) { - var i; - var needToDelete = false; - do { - needToDelete = false; - for (i = 0; i < instance.flows[flowId].edges.length; i++) { - if (instance.flows[flowId].edges[i].sourceNodeId == nodeId - || instance.flows[flowId].edges[i].targetNodeId == nodeId) { - needToDelete = true; - break; - } - } - if (needToDelete) { - instance.flows[flowId].edges.splice(i, 1); - } - } while (needToDelete); - do { - needToDelete = false; - for (i = 0; i < instance.flows[flowId].nodes.length; i++) { - if (instance.flows[flowId].nodes[i].id == nodeId) { - needToDelete = true; - break; - } - } - if (needToDelete) { - instance.flows[flowId].nodes.splice(i, 1); - } - } while (needToDelete); - instance.paintFlow(flowId); -}; - -HAFlow.Main.prototype.doAddModule = function(instance, flowId, moduleId, left, - top) { - var currentNewNodeNumber = -1; - var i; - var j; - for (i = 0; i < instance.flows[flowId].nodes.length; i++) { - var pattern = /^NewNode(\d+)$/; - var matches = pattern.exec(instance.flows[flowId].nodes[i].name); - for (j = 0; j < matches.length; j++) { - if (parseInt(matches[j]) > currentNewNodeNumber) { - currentNewNodeNumber = parseInt(matches[j]); - } - } - } - currentNewNodeNumber++; - var newNode = {}; - var id = HAFlow.generateUUID(); - newNode["id"] = id; - newNode["flowId"] = flowId; - newNode["moduleId"] = moduleId; - newNode["name"] = "NewNode" + currentNewNodeNumber; - newNode["position"] = {}; - newNode.position["left"] = left; - newNode.position["top"] = top; - newNode["configurations"] = []; - instance.flows[flowId].nodes.push(newNode); -}; - - -// HDFS -HAFlow.Main.prototype.getHdfsFile = function(path, fileName) { - $.ajax({ - url : this.basePath + "hdfs/file", - type : "GET", - dataType : "json", - data : { - path : path, - fileName : fileName - }, - success : function(data, status) { - alert(data.content); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while loading flow list: " + error); - } - }); -}; - -HAFlow.Main.prototype.getHdfsFileList = function(path) { - var _currentInstance = this; - $.ajax({ - url : this.basePath + "hdfs/list", - type : "GET", - dataType : "json", - data : { - path : path - }, - success : function(data, status) { - _currentInstance.refreshHdfsFileList(_currentInstance, path, data); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while loading flow list: " + error); - } - }); -}; - -HAFlow.Main.prototype.refreshHdfsFileList = function(instance, parentPath, data) { - var i; - for (i = 0; i < data.files.length; i++) { - this.hdfsFileListStore.put({ - name : data.files[i].name, - isDirectory : data.files[i].directory, - path : parentPath + "/" + data.files[i].name, - parentPath : parentPath - }); - if (data.files[i].directory) { - instance.getHdfsFileList(parentPath + "/" + data.files[i].name); - } - } -}; - -// Paint Helper -HAFlow.Main.prototype.addEndpoints = function(instance, flowId, nodeId, module, - sourceEndpoint, targetEndpoint) { - var k = 0; - for ( var i = 0; i < module.outputs.length; i++, k++) { - var sourceId = nodeId + "_" + module.outputs[i].name; - instance.jsPlumb[flowId].allSourceEndpoints - .push(instance.jsPlumb[flowId].addEndpoint(nodeId, - sourceEndpoint, { - anchor : [ 1, - 1 / (module.outputs.length + 1) * (i + 1), - 1, 0 ], - uuid : sourceId, - overlays : [ [ "Label", { - location : [ 0.5, -0.5 ], - label : module.outputs[i].name - } ] ] - })); - } - k = 0; - for ( var j = 0; j < module.inputs.length; j++, k++) { - var targetId = nodeId + "_" + module.inputs[j].name; - instance.jsPlumb[flowId].allTargetEndpoints - .push(instance.jsPlumb[flowId].addEndpoint(nodeId, - targetEndpoint, { - anchor : [ 0, - 1 / (module.inputs.length + 1) * (j + 1), - -1, 0 ], - uuid : targetId, - overlays : [ [ "Label", { - location : [ 0.5, -0.5 ], - label : module.inputs[j].name - } ] ] - })); - } -}; - -// Initialize -HAFlow.Main.prototype.init = function() { - this.flows = {}; - this.jsPlumb = {}; - - this.initUserInterface(); - this.initFlowContainer(); - this.initData(); -}; - -HAFlow.Main.prototype.initNodes = function(flowId) { - var _currentInstance = this; - this.jsPlumb[flowId].draggable($(".node"), { - containment : "#" + "flowContainer_" + flowId, - stop : function(event, ui) { - _currentInstance.onDropNode(_currentInstance, flowId, event, ui); - } - }); - var i; - for (i = 0; i < this.flows[flowId].nodes.length; i++) { - var nodeId = "node_" + this.flows[flowId].nodes[i].id; - var sourceEndpoint = { - paintStyle : { - strokeStyle : "#225588", - fillStyle : "transparent", - radius : 7, - }, - isSource : true, - connector : [ "Flowchart", {} ], - connectorStyle : { - strokeStyle : "#225588", - lineWidth : 3 - } - }; - var targetEndpoint = { - endpoint : "Dot", - isTarget : true, - maxConnections : -1, - }; - - this.jsPlumb[flowId].allSourceEndpoints = []; - this.jsPlumb[flowId].allTargetEndpoints = []; - var node = this.getNodeById(this, flowId, - this.flows[flowId].nodes[i].id); - var module = this.getModuleById(this, node.moduleId); - - this.addEndpoints(this, flowId, nodeId, module, sourceEndpoint, - targetEndpoint); - } -}; - -HAFlow.Main.prototype.initData = function() { - this.initFlowListData(); - this.getHdfsFileList(this.rootPath); -}; - -HAFlow.Main.prototype.initFlowListData = function() { - var _currentInstance = this; - $.ajax({ - url : this.basePath + "flow", - type : "GET", - cache : false, - dataType : "json", - success : function(data, status) { - _currentInstance.flowList = data; - _currentInstance.initModuleListData(); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while loading flow list: " + error); - } - }); -}; - -HAFlow.Main.prototype.initModuleListData = function() { - var _currentInstance = this; - $.ajax({ - - url : _currentInstance.basePath + "module", - type : "GET", - cache : false, - dataType : "json", - success : function(data, status) { - _currentInstance.moduleList = data; - _currentInstance.drawLists(_currentInstance); - }, - error : function(request, status, error) { - HAFlow.showDialog("Error", - "An error occurred while loading module list: " + error); - } - }); -}; - -HAFlow.Main.prototype.initUserInterface = function() { - this.ui.init(); - this.initUserInterfaceId(); - this.initMainMenu(); - this.initToolbar(); - this.initBottomTabs(); - this.initFlowList(); - this.initHdfsFileList(); - this.ui.refresh(); -}; - -HAFlow.Main.prototype.initToolbar = function() { - this.toolbar = {}; - this.toolbar.toolbar = new dijit.Toolbar({ - id : "toolbar" - }); - this.toolbar.newFlowButton = new dijit.form.Button({ - id : "toolbar_newFlow", - label : "New Flow", - showLabel : false, - iconClass : "dijitEditorIcon dijitEditorIconNewPage" - }); - this.toolbar.saveFlowButton = new dijit.form.Button({ - id : "toolbar_saveFlow", - label : "Save Flow", - showLabel : false, - iconClass : "dijitEditorIcon dijitEditorIconSave" - }); - this.toolbar.removeFlowButton = new dijit.form.Button({ - id : "toolbar_removeFlow", - label : "Remove Flow", - showLabel : false, - iconClass : "dijitEditorIcon dijitEditorIconDelete" - }); - this.toolbar.runFlowButton = new dijit.form.Button({ - id : "toolbar_runFlow", - label : "Run Flow", - showLabel : false, - iconClass : "dijitEditorIcon dijitEditorIconTabIndent" - }); - this.toolbar.toolbar.addChild(this.toolbar.newFlowButton); - this.toolbar.toolbar.addChild(this.toolbar.saveFlowButton); - this.toolbar.toolbar.addChild(this.toolbar.removeFlowButton); - this.toolbar.toolbar.addChild(this.toolbar.runFlowButton); - this.toolbar.toolbar.startup(); - - var _currentInstance = this; - dojo.connect(this.toolbar.newFlowButton, "onClick", function(event) { - _currentInstance.newFlow(); - }); - dojo.connect(this.toolbar.saveFlowButton, "onClick", function(event) { - _currentInstance.saveFlow(_currentInstance.currentFlowId); - }); - dojo.connect(this.toolbar.removeFlowButton, "onClick", function(event) { - _currentInstance.removeFlow(_currentInstance.currentFlowId); - }); - dojo.connect(this.toolbar.runFlowButton, "onClick", function(event) { - _currentInstance.runFlow(_currentInstance.currentFlowId); - }); - this.ui.mainMenu.addChild(this.toolbar.toolbar); -}; - -HAFlow.Main.prototype.initUserInterfaceId = function() { - this.flowListContainerId = "flowListTreeContainer"; - this.flowListTreeId = "flowListTree"; - this.hdfsFileListContainerId = "hdfsFileListContainer"; - this.hdfsFileListTreeId = "hdfsFileListTree"; - this.moduleListContainerId = "moduleListContainer"; - this.flowContainerId = "flowContainer"; - this.informationContainerId = "informationContainer"; - this.consoleContainerId = "consoleContainer"; - this.logContainerId = "logContainer"; - this.configurationContainerId = "configurationContainer"; -}; - -HAFlow.Main.prototype.initMainMenu = function() { - this.menu = {}; - this.initFlowMenu(); -}; - -HAFlow.Main.prototype.initFlowMenu = function() { - this.menu.flowMenu = new dijit.Menu({ - id : "flowMenu" - }); - this.menu.flowMenu.newFlowMenuItem = new dijit.MenuItem({ - id : "newFlowMenuItem", - label : "New", - }); - this.menu.flowMenu.openFlowMenuItem = new dijit.MenuItem({ - id : "openFlowMenuItem", - label : "Open", - disabled : true - }); - this.menu.flowMenu.closeFlowMenuItem = new dijit.MenuItem({ - id : "closeFlowMenuItem", - label : "Close", - disabled : true - }); - // this.menu.flowMenu.saveFlowMenuItem = new dijit.MenuItem({ - // id : "saveFlowMenuItem", - // label : "Save Flow" - // }); - this.menu.flowMenu.deleteFlowMenuItem = new dijit.MenuItem({ - id : "deleteFlowMenuItem", - label : "Delete" - }); - this.menu.flowMenu.exportFlowMenuItem = new dijit.MenuItem({ - id : "exportFlowMenuItem", - label : "Export", - disabled : true - }); - this.menu.flowMenu.importFlowMenuItem = new dijit.MenuItem({ - id : "importFlowMenuItem", - label : "Import", - disabled : true - }); - this.menu.flowMenu.addChild(this.menu.flowMenu.newFlowMenuItem); - this.menu.flowMenu.addChild(this.menu.flowMenu.openFlowMenuItem); - this.menu.flowMenu.addChild(this.menu.flowMenu.closeFlowMenuItem); - // this.menu.flowMenu.addChild(this.menu.flowMenu.saveFlowMenuItem); - this.menu.flowMenu.addChild(this.menu.flowMenu.deleteFlowMenuItem); - this.menu.flowMenu.addChild(this.menu.flowMenu.exportFlowMenuItem); - this.menu.flowMenu.addChild(this.menu.flowMenu.importFlowMenuItem); - this.menu.flowMenu.startup(); - - this.menu.runMenu = new dijit.Menu({ - id : "runMenu" - }); - this.menu.runMenu.runMenuItem = new dijit.MenuItem({ - id : "runMenuItem", - label : "Run", - }); - this.menu.runMenu.debugMenuItem = new dijit.MenuItem({ - id : "debugMenuItem", - label : "Debug", - disabled : true - }); - this.menu.runMenu.validateMenuItem = new dijit.MenuItem({ - id : "validateMenuItem", - label : "Validate", - disabled : true - }); - this.menu.runMenu.runHistoryMenuItem = new dijit.MenuItem({ - id : "runHistoryMenuItem", - label : "Run History", - disabled : true - }); - this.menu.runMenu.debugHistoryMenuItem = new dijit.MenuItem({ - id : "debugHistoryMenuItem", - label : "Debug History", - disabled : true - }); - this.menu.runMenu.addChild(this.menu.runMenu.runMenuItem); - this.menu.runMenu.addChild(this.menu.runMenu.debugMenuItem); - this.menu.runMenu.addChild(this.menu.runMenu.validateMenuItem); - this.menu.runMenu.addChild(this.menu.runMenu.runHistoryMenuItem); - this.menu.runMenu.addChild(this.menu.runMenu.debugHistoryMenuItem); - this.menu.runMenu.startup(); - - this.menu.searchMenu = new dijit.Menu({ - id : "searchMenu" - }); - this.menu.searchMenu.searchFlowMenuItem = new dijit.MenuItem({ - id : "searchFlowMenuItem", - label : "Search Flow", - disabled : true - }); - this.menu.searchMenu.searchModuleMenuItem = new dijit.MenuItem({ - id : "searchModuleMenuItem", - label : "Search Module", - disabled : true - }); - this.menu.searchMenu.searchLogMenuItem = new dijit.MenuItem({ - id : "searchLogMenuItem", - label : "Search Log", - disabled : true - }); - this.menu.searchMenu.addChild(this.menu.searchMenu.searchFlowMenuItem); - this.menu.searchMenu.addChild(this.menu.searchMenu.searchModuleMenuItem); - this.menu.searchMenu.addChild(this.menu.searchMenu.searchLogMenuItem); - this.menu.searchMenu.startup(); - - this.menu.windowMenu = new dijit.Menu({ - id : "windowMenu" - }); - this.menu.windowMenu.hideToolbarMenuItem = new dijit.MenuItem({ - id : "hideToolbarMenuItem", - label : "Hide Toolbar", - disabled : true - }); - this.menu.windowMenu.addChild(this.menu.windowMenu.hideToolbarMenuItem); - this.menu.windowMenu.startup(); - - this.menu.helpMenu = new dijit.Menu({ - id : "helpMenu" - }); - this.menu.helpMenu.aboutMenuItem = new dijit.MenuItem({ - id : "aboutMenuItem", - label : "About", - disabled : true - }); - this.menu.helpMenu.manualMenuItem = new dijit.MenuItem({ - id : "manualMenuItem", - label : "Manual", - disabled : true - }); - this.menu.helpMenu.addChild(this.menu.helpMenu.aboutMenuItem); - this.menu.helpMenu.addChild(this.menu.helpMenu.manualMenuItem); - this.menu.helpMenu.startup(); - - this.menu.oozieMenu = new dijit.Menu({ - id : "oozieMenu" - }); - this.menu.oozieMenu.openMenuItem = new dijit.MenuItem({ - id : "openMenuItem", - label : "Open" - }); - this.menu.oozieMenu.closeMenuItem = new dijit.MenuItem({ - id : "closeMenuItem", - label : "Close", - disabled : true - }); - this.menu.oozieMenu.addChild(this.menu.oozieMenu.openMenuItem); - this.menu.oozieMenu.addChild(this.menu.oozieMenu.closeMenuItem); - this.menu.oozieMenu.startup(); - - this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ - id : "flowPopupMenuBarItem", - label : "Flow", - popup : this.menu.flowMenu - })); - this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ - id : "runPopupMenuBarItem", - label : "Run", - popup : this.menu.runMenu - })); - this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ - id : "searchPopupMenuBarItem", - label : "Search", - popup : this.menu.searchMenu - })); - this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ - id : "windowPopupMenuBarItem", - label : "Window", - popup : this.menu.windowMenu - })); - this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ - id : "helpPopupMenuBarItem", - label : "Help", - popup : this.menu.helpMenu - })); - this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ - id : "ooziePopupMenuBarItem", - label : "oozie", - popup : this.menu.oozieMenu - })); - - var _currentInstance = this; - dojo.connect(this.menu.flowMenu.newFlowMenuItem, "onClick", - function(event) { - _currentInstance.newFlow(); - }); - // dojo.connect(this.menu.flowMenu.saveFlowMenuItem, "onClick", - // function(event) { - // _currentInstance.saveFlow(_currentInstance.currentFlowId); - // }); - dojo.connect(this.menu.flowMenu.deleteFlowMenuItem, "onClick", function( - event) { - _currentInstance.removeFlow(_currentInstance.currentFlowId); - }); - dojo.connect(this.menu.runMenu.runMenuItem, "onClick", function(event) { - _currentInstance.runFlow(_currentInstance.currentFlowId); - }); - dojo.connect(this.menu.oozieMenu.openMenuItem, "onClick", function(event) { - _currentInstance.openoozie(); - }); - -}; - -HAFlow.Main.prototype.initBottomTabs = function() { - this.initInformationTab(); - this.initConfigurationTab(); - this.initConsoleTab(); - this.initLogTab(); -}; - -HAFlow.Main.prototype.initInformationTab = function() { - var informationContentPane = (new dijit.layout.ContentPane({ - id : this.informationContainerId, - title : "Information" - })); - this.ui.bottomContainer.addChild(informationContentPane); -}; - -HAFlow.Main.prototype.initConsoleTab = function() { - var consoleContentPane = new dijit.layout.ContentPane({ - id : this.consoleContainerId, - title : "Console" - }); - this.ui.bottomContainer.addChild(consoleContentPane); -}; - -HAFlow.Main.prototype.initLogTab = function() { - var logContentPane = new dijit.layout.ContentPane({ - id : this.logContainerId, - title : "Log" - }); - this.ui.bottomContainer.addChild(logContentPane); -}; - -HAFlow.Main.prototype.initConfigurationTab = function() { - var configurationContentPane = new dijit.layout.ContentPane({ - id : this.configurationContainerId, - title : "Configuration" - }); - this.ui.bottomContainer.addChild(configurationContentPane); -}; - -HAFlow.Main.prototype.initFlowList = function() { - var flowListContentPane = new dijit.layout.ContentPane({ - id : this.flowListContainerId, - title : "Flows" - }); - this.ui.leadingContainer.addChild(flowListContentPane); - this.initFlowListStore(); - this.initFlowListTree(); -}; - -HAFlow.Main.prototype.initHdfsFileList = function() { - var hdfsFileListContentPane = new dijit.layout.ContentPane({ - id : this.hdfsFileListContainerId, - title : "HDFS" - }); - this.ui.leadingContainer.addChild(hdfsFileListContentPane); - this.initHdfsFileListStore(); - this.initHdfsFileListTree(); -}; - -HAFlow.Main.prototype.initHdfsFileListStore = function() { - this.hdfsFileListStore = new dojo.store.Observable(new dojo.store.Memory({ - data : [ { - id : "root", - name : "Root(" + this.rootPath + ")", - isDirectory : true, - path : this.rootPath - } ], - getChildren : function(object) { - return this.query({ - parentPath : object.path - }); - } - })); -}; - -HAFlow.Main.prototype.initHdfsFileListTree = function() { - var treeModel = new dijit.tree.ObjectStoreModel({ - store : this.hdfsFileListStore, - query : { - id : "root" - }, - mayHaveChildren : function(item) { - return item.isDirectory; - } - }); - var tree = new dijit.Tree({ - model : treeModel - }, dojo.create("div", { - id : this.hdfsFileListTreeId, - }, this.hdfsFileListContainerId)); - - var _currentInstance = this; - tree.on("click", function(item) { - if (item.directory == true) { - - } - }, true); - tree.on("dblclick", function(item) { - if (item.isDirectory == true) { - - } else { - _currentInstance.getHdfsFile(item.parentPath, item.name); - } - }, true); - - tree.startup(); -}; - -HAFlow.Main.prototype.initFlowListStore = function() { - this.flowListStore = new dojo.store.Observable(new dojo.store.Memory({ - data : [ { - id : "root", - name : "Flows", - node : false - } ], - - getChildren : function(object) { - if (object.id == "root") { - return this.query({ - node : true - }); - } - return null; - } - })); -}; - -HAFlow.Main.prototype.initFlowListTree = function() { - var treeModel = new dijit.tree.ObjectStoreModel({ - store : this.flowListStore, - query : { - id : "root" - }, - mayHaveChildren : function(item) { - return !(item.node); - } - }); - var tree = new dijit.Tree({ - model : treeModel - }, dojo.create("div", { - id : this.flowListTreeId, - }, this.flowListContainerId)); - - var _currentInstance = this; - tree.on("click", function(item) { - if (item.node == true) { - _currentInstance.onFlowClicked(_currentInstance, item.id); - } - }, true); - tree.on("dblclick", function(item) { - if (item.node == true) { - _currentInstance.loadFlow(item.id); - } - }, true); - - tree.startup(); -}; - -HAFlow.Main.prototype.initFlowContainer = function() { - var _currentInstance = this; - this.ui.centerContainer.watch("selectedChildWidget", function(name, from, - to) { - var flowId = to.domNode.id.replace("flowContainerPane_", ""); - _currentInstance.currentFlowId = flowId; - _currentInstance.setupDroppable(flowId); - _currentInstance.paintFlow(flowId); - }); -}; - -HAFlow.Main.prototype.initJsPlumb = function(flowId) { - this.jsPlumb[flowId] = jsPlumb.getInstance(); - this.jsPlumb[flowId].reset(); - this.jsPlumb[flowId].importDefaults({ - DragOptions : { - cursor : 'pointer', - zIndex : 2000 - }, - Endpoints : [ [ "Dot", { - radius : 8 - } ], [ "Dot", { - radius : 8 - } ] ], - ConnectionOverlays : [ [ "Arrow", { - location : -40 - } ] ] - }); -}; - -HAFlow.Main.prototype.setupDroppable = function(flowId) { - $(".module").draggable({ - appendTo : "#" + "flowContainer_" + flowId, - revert : "invalid", - helper : "clone" - }); - var _currentInstance = this; - $("#" + "flowContainer_" + flowId).droppable( - { - accept : ".module", - drop : function(event, ui) { - _currentInstance.onModuleAdded(_currentInstance, flowId, - event, ui); - } - }); -}; - -HAFlow.Main.prototype.buildFlowListTree = function() { - var i; - for (i = 0; i < this.flowList.flows.length; i++) { - this.flowListStore.put({ - id : this.flowList.flows[i].id, - name : this.flowList.flows[i].name, - node : true - }); - } -}; - -HAFlow.Main.prototype.drawLists = function(instance) { - instance.paintModuleList(); - instance.buildFlowListTree(); -}; - -HAFlow.Main.prototype.saveFlowName = function(instance, flowId) { - if (instance.flows[flowId]) { - var value = $("#" + "flow_" + flowId + "_name").val(); - if (this.checkFlowName(instance, instance.flows[flowId].name, value)) { - instance.flows[flowId].name = value; - instance.getFlowBriefById(instance, flowId).name = value; - var pane = dijit.byId("flowContainerPane_" + flowId); - pane.title = value; - instance.ui.centerContainer.removeChild(pane); - instance.ui.centerContainer.addChild(pane); - instance.ui.centerContainer.selectChild(pane); - instance.flowListStore.remove(flowId); - instance.flowListStore.put({ - id : instance.flows[flowId].id, - name : instance.flows[flowId].name, - node : true - }); - } else { - HAFlow.showDialog("Error", "Invalid flow name"); - } - } else { - HAFlow.showDialog("Error", - "Please load the flow before saving flow metadata!"); - } -}; - -HAFlow.Main.prototype.paintModuleList = function() { - var i; - for (i = 0; i < this.moduleList.modules.length; i++) { - if (dijit.byId(this.moduleListContainerId + "_" - + this.moduleList.modules[i].category) == null) { - var moduleListPane = new dijit.layout.ContentPane({ - id : this.moduleListContainerId + "_" - + this.moduleList.modules[i].category, - title : this.moduleList.modules[i].category - }); - this.ui.trailingContainer.addChild(moduleListPane); - } - text = "
" - + this.moduleList.modules[i].name + "
"; - $( - "#" + this.moduleListContainerId + "_" - + this.moduleList.modules[i].category).append(text); - } - this.ui.refresh(); - -}; - -HAFlow.Main.prototype.paintFlow = function(flowId) { - this.initJsPlumb(flowId); - this.paintNodes(flowId); - this.initNodes(flowId); - this.paintEdges(flowId); - this.bindJsPlumbEvents(flowId); - this.bindFunctions(flowId); - this.jsPlumb[flowId].repaintEverything(); -}; - -HAFlow.Main.prototype.paintNodes = function(flowId) { - var text = ""; - for ( var i = 0; i < this.flows[flowId].nodes.length; i++) { - var moduleName = this.getModuleById(this, - this.flows[flowId].nodes[i].moduleId).name; - text += "
" - + "
" + this.flows[flowId].nodes[i].name + "
" - + "(" + moduleName + ")
" + "
"; - } - $("#" + "flowContainer_" + flowId).html(text); -}; - -HAFlow.Main.prototype.paintEdges = function(flowId) { - for ( var i = 0; i < this.flows[flowId].edges.length; i++) { - this.jsPlumb[flowId].connect({ - uuids : [ - "node_" + this.flows[flowId].edges[i].sourceNodeId + "_" - + this.flows[flowId].edges[i].sourceEndpoint, - "node_" + this.flows[flowId].edges[i].targetNodeId + "_" - + this.flows[flowId].edges[i].targetEndpoint ], - detachable : false - }); - } -}; - -HAFlow.Main.prototype.bindJsPlumbEvents = function(flowId) { - var _currentInstance = this; - this.jsPlumb[flowId].bind("click", function(info) { - _currentInstance.onConnectionClicked(_currentInstance, flowId, info); - }); - this.jsPlumb[flowId].bind("connection", function(info) { - _currentInstance.onConnectionCreated(_currentInstance, flowId, info); - }); - -}; - -HAFlow.Main.prototype.bindFunctions = function(flowId) { - var _currentInstance = this; - $(".node").bind("click", function() { - var nodeId = $(this).attr("id").replace("node_", ""); - _currentInstance.onNodeClicked(_currentInstance, flowId, nodeId); - }); - $(".module").bind("click", function() { - var moduleId = $(this).attr("id").replace("module_", ""); - _currentInstance.onModuleClicked(_currentInstance, flowId, moduleId); - }); -}; - -// Event Handler -HAFlow.Main.prototype.onFlowClicked = function(instance, flowId) { - var flowBrief = instance.getFlowBriefById(instance, flowId); - var text = ""; - text += "
"; - text += "
Flow Info:
"; - text += "
Id: " - + flowBrief.id + "
"; - text += "
Name:"; - text += "
"; - text += "
"; - text += "
"; - $("#" + instance.informationContainerId).html(text); - if (dijit.byId("flow_" + flowBrief.id + "_name") != null) { - dijit.registry.remove("flow_" + flowBrief.id + "_name"); - } - var flowNameTextBox = new dijit.form.TextBox({ - id : "flow_" + flowBrief.id + "_name", - value : flowBrief.name, - style : "width:600px;" - }); - flowNameTextBox.placeAt(dojo.byId("flow_name_text_box")); - flowNameTextBox.startup(); - var button = new dijit.form.Button({ - label : "Save", - onClick : function() { - instance.saveFlowName(instance, flowBrief.id); - } - }); - button.placeAt(dojo.byId("save_flow_name_button")); - button.startup(); -}; - -HAFlow.Main.prototype.onModuleClicked = function(instance, flowId, moduleId) { - var text = ""; - var i; - for (i = 0; i < instance.moduleList.modules.length; i++) { - if (moduleId == instance.moduleList.modules[i].id) { - break; - } - } - text += "
" + - "Name:" - + instance.moduleList.modules[i].name + ".
"; - $("#" + instance.informationContainerId).html(text); -}; - -HAFlow.Main.prototype.onNodeClicked = function(instance, flowId, nodeId) { - var node = instance.getNodeById(instance, flowId, nodeId); - var module = instance.getModuleById(instance, node.moduleId); - var text = ""; - text += "
"; - text += "
Node Id: " - + node.id + "
"; - text += "
Flow: " - + instance.flows[node.flowId].name + "
"; - text += "
Module: " - + module.name + "
"; - text += "
"; - text += "Name: "; - text += ""; - text += "
"; - text += "
"; - text += "
Delete?
"; - text += "
"; - text += "
"; - $("#" + instance.informationContainerId).html(text); - - if (dijit.byId("node_" + nodeId + "_name") != null) { - dijit.registry.remove("node_" + nodeId + "_name"); - } - var nodeNameTextBox = new dijit.form.TextBox({ - id : "node_" + nodeId + "_name", - value : node.name, - style : "width:600px;" - }); - nodeNameTextBox.placeAt(dojo.byId("node_name_text_box")); - nodeNameTextBox.startup(); - - var saveNodeNameButton = new dijit.form.Button({ - label : "Save Node Name", - onClick : function() { - instance.saveNodeName(instance, flowId, nodeId); - } - }); - saveNodeNameButton.placeAt(dojo.byId("save_node_name_button")); - saveNodeNameButton.startup(); - - var deleteNodeButton = new dijit.form.Button({ - label : "Delete Node", - onClick : function() { - instance.deleteNode(instance, flowId, nodeId); - } - }); - deleteNodeButton.placeAt(dojo.byId("delete_node_button")); - deleteNodeButton.startup(); - - var form = ""; - form += "
"; - form += "
Configuration:
"; - var i; - for (i = 0; i < module.configurations.length; i++) { - var textBoxId = "flow_" + flowId + "_node_" + nodeId + "_" - + module.configurations[i].key; - var divId = textBoxId + "_container"; - form += "
"; - if(module.configurations[i].type=="BOOLEAN"){ - form += "
" - + module.configurations[i].displayName +"
"; - } - else{ - form += ("" + module.configurations[i].displayName +""); - form += "
"; - } - form += "
"; - } - form += "
"; - form += "
"; - $("#" + instance.configurationContainerId).html(form); - for (i = 0; i < module.configurations.length; i++) { - var textBoxId = "flow_" + flowId + "_node_" + nodeId + "_" - + module.configurations[i].key; - var divId = textBoxId + "_container"; - if (dijit.byId(textBoxId) != null) { - dijit.registry.remove(textBoxId); - } - if(module.configurations[i].type=="BOOLEAN") - { - var configtype_true=new dijit.form.CheckBox({ - id:textBoxId, - checked:(instance.getConfigurationValue(instance,flowId,nodeId, - module.configurations[i].key)=="on")?true:false - }); - configtype_true.placeAt(dojo.byId(divId)); - configtype_true.startup(); - } - else - { - var configurationTextBox = new dijit.form.TextBox({ - id : textBoxId, - value : instance.getConfigurationValue(instance,flowId,nodeId, - module.configurations[i].key), - style : "width:600px;" - }); - configurationTextBox.placeAt(dojo.byId(divId)); - configurationTextBox.startup(); - } - } - - var saveConfigurationButton = new dijit.form.Button({ - label : "Save Configuration", - onClick : function() { - instance.saveConfiguration(instance, flowId, nodeId); - } - }); - saveConfigurationButton.placeAt(dojo.byId("save_configuration_button")); - saveConfigurationButton.startup(); -}; - -HAFlow.Main.prototype.onConnectionClicked = function(instance, flowId, info) { - var source = info.sourceId.replace("node_", ""); - var sourceEndpoint = info.endpoints[0].overlays[0].getLabel(); - var target = info.targetId.replace("node_", ""); - var targetEndpoint = info.endpoints[1].overlays[0].getLabel(); - var sourceNode = instance.getNodeById(instance, flowId, source); - var targetNode = instance.getNodeById(instance, flowId, target); - - var text = ""; - text += "
"; - text += "
From: " - + sourceNode.name + "." + sourceEndpoint + "
" - + "
To: " - + targetNode.name + "." + targetEndpoint + "
"; - text += "
Delete?
"; - text += "
"; - text += "
"; - $("#" + instance.informationContainerId).html(text); - var button = new dijit.form.Button({ - label : "Delete Connection", - onClick : function() { - instance.deleteConnection(instance, flowId, info); - } - }); - button.placeAt(dojo.byId("delete_connection_button")); - button.startup(); -}; - -HAFlow.Main.prototype.onConnectionCreated = function(instance, flowId, info) { - var source = info.sourceId.replace("node_", ""); - var sourceEndpoint = info.sourceEndpoint.overlays[0].getLabel(); - var target = info.targetId.replace("node_", ""); - var targetEndpoint = info.targetEndpoint.overlays[0].getLabel(); - var exist = false; - var illegal = false; - for ( var i = 0; i < instance.flows[flowId].edges.length; i++) { - if (instance.flows[flowId].edges[i].sourceNodeId == source - && instance.flows[flowId].edges[i].sourceEndpoint == sourceEndpoint - && instance.flows[flowId].edges[i].targetNodeId == target - && instance.flows[flowId].edges[i].targetEndpoint == targetEndpoint) { - exist = true; - break; - } - } - if (source == target) { - illegal = true; - } - if (!exist && !illegal) { - var newConnection = instance.newConnection(instance.flows[flowId].id, - source, sourceEndpoint, target, targetEndpoint); - instance.flows[flowId].edges.push(newConnection); - info.connection.setDetachable(false); - info.connection.setPaintStyle({ - strokeStyle : "rgb(22,55,88)" - }); - } else { - instance.jsPlumb[flowId].detach(info); - } -}; - -HAFlow.Main.prototype.onDropNode = function(instance, flowId, event, ui) { - var newLeft = ui.position.left; - var newTop = ui.position.top; - var nodeId = ui.helper.context.id.replace("node_", ""); - for ( var i = 0; i < instance.flows[flowId].nodes.length; i++) { - if (instance.flows[flowId].nodes[i].id == nodeId) { - instance.flows[flowId].nodes[i].position.left = newLeft; - instance.flows[flowId].nodes[i].position.top = newTop; - } - } - instance.jsPlumb[flowId].repaintEverything(); -}; - -HAFlow.Main.prototype.onCloseTab = function(instance) { - return function() { - var flowId = this.id.replace("flowContainerPane_", ""); - var saveChange = confirm("Save flow before close?"); - if (saveChange) { - instance.saveFlow(flowId); - } - return true; - }; -}; - -HAFlow.Main.prototype.onModuleAdded = function(instance, flowId, event, ui) { - var moduleId = ui.draggable.context.id.replace("module_", ""); - instance.doAddModule(instance, flowId, moduleId, ui.position.left, - ui.position.top); - instance.paintFlow(flowId); -}; +dojo.require("dojo.dom"); +dojo.require("dojo.on"); +dojo.require("dojo.json"); +dojo.require("dojo.mouse"); +dojo.require("dojo.store.Memory"); +dojo.require("dojo.store.Observable"); +dojo.require("dojo.io.iframe"); +dojo.require("dijit.form.Button"); +dojo.require("dijit.form.CheckBox"); +dojo.require("dijit.form.TextBox"); +dojo.require("dijit.layout.BorderContainer"); +dojo.require("dijit.layout.TabContainer"); +dojo.require("dijit.layout.ContentPane"); +dojo.require("dijit.tree.ObjectStoreModel"); +dojo.require("dijit.Menu"); +dojo.require("dijit.MenuItem"); +dojo.require("dijit.MenuBar"); +dojo.require("dijit.MenuBarItem"); +dojo.require("dijit.PopupMenuBarItem"); +dojo.require("dijit.TitlePane"); +dojo.require("dijit.Toolbar"); +dojo.require("dijit.Tree"); +dojo.require("dijit.registry"); +dojo.require("dojox.form.FileUploader"); +var flow; + +dojo.ready(function() { + flow = new HAFlow.Main(new HAFlow.UI()); + flow.init(); +}); + +HAFlow.Main = function(ui) { + this.basePath = dojo.byId("basePath").value; + this.ui = ui; + this.rootPath = "hdfs://133.133.2.150:9000/user/root"; + this.hdfspath=null; +}; + +// Flow +HAFlow.Main.prototype.newFlow = function() { + var newFlowId = HAFlow.generateUUID(); + this.flows[newFlowId] = {}; + this.flows[newFlowId].id = newFlowId; + this.flows[newFlowId].name = "NewFlow"; + this.flows[newFlowId].nodes = new Array(); + this.flows[newFlowId].edges = new Array(); + var _currentInstance = this; + var contentPane = new dijit.layout.ContentPane({ + id : "flowContainerPane_" + newFlowId, + title : _currentInstance.flows[newFlowId].name, + content : "
", + closable : true, + onClose : _currentInstance.onCloseTab(_currentInstance) + }); + this.ui.centerContainer.addChild(contentPane); + this.ui.centerContainer.selectChild(contentPane); + this.setupDroppable(newFlowId); + this.paintFlow(newFlowId); + this.saveFlow(newFlowId); + this.flowListStore.put({ + id : this.flows[newFlowId].id, + name : this.flows[newFlowId].name, + node : true + }); +}; + +HAFlow.Main.prototype.loadFlow = function(flowId) { + if (dojo.byId("flowContainer_" + flowId) == null) { + var _currentInstance = this; + $.ajax({ + url : _currentInstance.basePath + "flow/" + flowId, + type : "GET", + cache : false, + dataType : "json", + success : function(data, status) { + _currentInstance.flows[data.id] = data; + var contentPane = new dijit.layout.ContentPane({ + id : "flowContainerPane_" + flowId, + title : _currentInstance.flows[flowId].name, + content : "
", + closable : true, + onClose : _currentInstance.onCloseTab(_currentInstance) + }); + _currentInstance.ui.centerContainer.addChild(contentPane); + _currentInstance.setupDroppable(flowId); + _currentInstance.paintFlow(flowId); + _currentInstance.ui.centerContainer.selectChild(dijit + .byId("flowContainerPane_" + flowId)); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while loading flow: " + error); + } + }); + } else { + this.ui.centerContainer.selectChild(dijit.byId("flowContainerPane_" + + flowId)); + } +}; + +HAFlow.Main.prototype.saveFlow = function(flowId) { + var _currentInstance = this; + $.ajax({ + url : _currentInstance.basePath + "flow/" + flowId, + type : "PUT", + dataType : "json", + contentType : "application/json", + data : JSON.stringify(_currentInstance.flows[flowId]), + success : function(data, status) { + HAFlow.showDialog("Save Flow", "Flow saved."); + _currentInstance.refreshFlowList(); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", "An error occurred while saving flow: " + + error); + } + }); +}; + +HAFlow.Main.prototype.removeFlow = function(flowId) { + var _currentInstance = this; + $.ajax({ + url : _currentInstance.basePath + "flow/" + flowId, + type : "DELETE", + dataType : "json", + contentType : "application/json", + data : JSON.stringify({}), + success : function(data, status) { + HAFlow.showDialog("Remove Flow", "Flow removed."); + _currentInstance.ui.centerContainer.removeChild(dijit + .byId("flowContainerPane_" + flowId)); + _currentInstance.refreshFlowList(); + _currentInstance.flowListStore + .remove(_currentInstance.flows[flowId].id); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while removing flow: " + error); + } + }); +}; + +HAFlow.Main.prototype.openoozie = function() { + var _currentInstance = this; + $ + .ajax({ + url : _currentInstance.basePath + "oozie/", + type : "Post", + success : function(data, status) { + var contentPane = new dijit.layout.ContentPane( + { + // id : "oozie", + title : "oozie", + content : data, + closable : true, + onClose : function() { + _currentInstance.ui.mainoozieContainer + .addChild(_currentInstance.ui.leadingContainer); + _currentInstance.ui.mainoozieContainer + .addChild(_currentInstance.ui.trailingContainer); + _currentInstance.ui.mainoozieContainer + .addChild(_currentInstance.ui.centerContainerParent); + _currentInstance.ui.mainoozieContainer + .removeChild(contentPaneContainer); + } + }); + var contentPaneContainer = new dijit.layout.TabContainer({ + // id : "ooziecontent", + region : "center", + splitter : "true", + }); + + _currentInstance.ui.mainoozieContainer + .removeChild(_currentInstance.ui.leadingContainer); + _currentInstance.ui.mainoozieContainer + .removeChild(_currentInstance.ui.trailingContainer); + _currentInstance.ui.mainoozieContainer + .removeChild(_currentInstance.ui.centerContainerParent); + contentPaneContainer.addChild(contentPane); + contentPaneContainer.selectChild(contentPane); + contentPaneContainer.startup(); + _currentInstance.ui.mainoozieContainer + .addChild(contentPaneContainer); + + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while opening: " + error); + } + }); +}; + +HAFlow.Main.prototype.runFlow = function(flowId) { + var _currentInstance = this; + $.ajax({ + url : _currentInstance.basePath + "flow/" + flowId, + type : "PUT", + dataType : "json", + contentType : "application/json", + data : JSON.stringify(_currentInstance.flows[flowId]), + success : function(data, status) { + HAFlow.showDialog("Save Flow", "Flow saved."); + _currentInstance.refreshFlowList(); + $.ajax({ + url : _currentInstance.basePath + "run/" + flowId, + type : "POST", + dataType : "json", + contentType : "application/json", + data : JSON.stringify({}), + success : function(data, status) { + HAFlow.showDialog("Run Flow", " Commited: " + data.commited + + "\n" + "Result: " + data.message); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while running flow: " + error); + } + }); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", "An error occurred while saving flow: " + + error); + } + }); +}; + +// Flow Helper +HAFlow.Main.prototype.refreshFlowList = function() { + var _currentInstance = this; + $.ajax({ + url : this.basePath + "flow", + type : "GET", + cache : false, + dataType : "json", + success : function(data, status) { + _currentInstance.flowList = data; + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while refreshing flow list: " + error); + } + }); +}; + +HAFlow.Main.prototype.getFlowBriefById = function(instance, flowId) { + var i; + for (i = 0; i < instance.flowList.flows.length; i++) { + if (instance.flowList.flows[i].id == flowId) { + return instance.flowList.flows[i]; + } + } + return null; +}; + +HAFlow.Main.prototype.getNodeById = function(instance, flowId, nodeId) { + var i; + for (i = 0; i < instance.flows[flowId].nodes.length; i++) { + if (instance.flows[flowId].nodes[i].id == nodeId) { + return instance.flows[flowId].nodes[i]; + } + } + return null; +}; + +HAFlow.Main.prototype.getModuleById = function(instance, moduleId) { + var i; + for (i = 0; i < instance.moduleList.modules.length; i++) { + if (instance.moduleList.modules[i].id == moduleId) { + return instance.moduleList.modules[i]; + } + } + return null; +}; + +HAFlow.Main.prototype.getConfigurationValue = function(instance, flowId, + nodeId, key) { + var node = instance.getNodeById(instance, flowId, nodeId); + var i; + for (i = 0; i < node.configurations.length; i++) { + if (node.configurations[i].key == key) { + return node.configurations[i].value; + } + } + return ""; +}; + +HAFlow.Main.prototype.checkNodeName = function(instance, flowId, oldName, + newName) { + var i; + if (oldName == newName) { + return true; + } + var regex = /^[a-zA-Z_][a-zA-Z_0-9]{0,38}$/; + if (!regex.test(newName)) { + return false; + } + for (i = 0; i < instance.flows[flowId].nodes.length; i++) { + if (newName == instance.flows[flowId].nodes[i].name) { + return false; + } + } + return true; +}; + +HAFlow.Main.prototype.checkFlowName = function(instance, oldName, newName) { + var i; + if (oldName == newName) { + return true; + } + var regex = /^[a-zA-Z_][a-zA-Z_0-9]{0,38}$/; + if (!regex.test(newName)) { + return false; + } + for (i = 0; i < instance.flows.length; i++) { + if (newName == instance.flows[i].name) { + return false; + } + } + return true; +}; + +HAFlow.Main.prototype.saveNodeName = function(instance, flowId, nodeId) { + var node = instance.getNodeById(instance, flowId, nodeId); + var value = $("#" + "node_" + nodeId + "_name").val(); + if (instance.checkNodeName(instance, flowId, node.name, value)) { + node.name = value; + instance.paintFlow(flowId); + instance.jsPlumb[flowId].repaintEverything(); + } else { + HAFlow.showDialog("Error", "Invalid node name"); + } +}; + +HAFlow.Main.prototype.saveConfiguration = function(instance, flowId, nodeId) { + var node = instance.getNodeById(instance, flowId, nodeId); + var module = instance.getModuleById(instance, node.moduleId); + var i; + node.configurations = []; + for (i = 0; i < module.configurations.length; i++) { + var val = dijit.registry.byId( + "flow_" + flowId + "_node_" + nodeId + "_" + + module.configurations[i].key).get("value"); + if (module.configurations[i].type != "BOOLEAN" && val != null + && val.match(module.configurations[i].pattern) == null) { + HAFlow.showDialog("Error", "Invalid node configuration: " + + module.configurations[i].displayName); + return; + } + } + for (i = 0; i < module.configurations.length; i++) { + console.log(module.configurations[i].displayName); + node.configurations.push({ + key : module.configurations[i].key, + value : dijit.registry.byId( + "flow_" + flowId + "_node_" + nodeId + "_" + + module.configurations[i].key).get("value") + }); + } + +}; + +HAFlow.Main.prototype.newConnection = function(flowId, source, sourceEndpoint, + target, targetEndpoint) { + var newConnection = {}; + newConnection["id"] = HAFlow.generateUUID(); + newConnection["flowId"] = flowId; + newConnection["sourceNodeId"] = source; + newConnection["sourceEndpoint"] = sourceEndpoint; + newConnection["targetNodeId"] = target; + newConnection["targetEndpoint"] = targetEndpoint; + return newConnection; +}; + +HAFlow.Main.prototype.deleteConnection = function(instance, flowId, info) { + var source = info.sourceId.replace("node_", ""); + var target = info.targetId.replace("node_", ""); + var i; + var needToDelete = false; + do { + needToDelete = false; + for (i = 0; i < instance.flows[flowId].edges.length; i++) { + if (instance.flows[flowId].edges[i].sourceNodeId == source + && instance.flows[flowId].edges[i].targetNodeId == target) { + needToDelete = true; + break; + } + } + if (needToDelete) { + instance.flows[flowId].edges.splice(i, 1); + } + } while (needToDelete); + instance.jsPlumb[flowId].detach(info); +}; + +HAFlow.Main.prototype.deleteNode = function(instance, flowId, nodeId) { + var i; + var needToDelete = false; + do { + needToDelete = false; + for (i = 0; i < instance.flows[flowId].edges.length; i++) { + if (instance.flows[flowId].edges[i].sourceNodeId == nodeId + || instance.flows[flowId].edges[i].targetNodeId == nodeId) { + needToDelete = true; + break; + } + } + if (needToDelete) { + instance.flows[flowId].edges.splice(i, 1); + } + } while (needToDelete); + do { + needToDelete = false; + for (i = 0; i < instance.flows[flowId].nodes.length; i++) { + if (instance.flows[flowId].nodes[i].id == nodeId) { + needToDelete = true; + break; + } + } + if (needToDelete) { + instance.flows[flowId].nodes.splice(i, 1); + } + } while (needToDelete); + instance.paintFlow(flowId); +}; + +HAFlow.Main.prototype.doAddModule = function(instance, flowId, moduleId, left, + top) { + var currentNewNodeNumber = -1; + var i; + var j; + for (i = 0; i < instance.flows[flowId].nodes.length; i++) { + var pattern = /^NewNode(\d+)$/; + var matches = pattern.exec(instance.flows[flowId].nodes[i].name); + for (j = 0; j < matches.length; j++) { + if (parseInt(matches[j]) > currentNewNodeNumber) { + currentNewNodeNumber = parseInt(matches[j]); + } + } + } + currentNewNodeNumber++; + var newNode = {}; + var id = HAFlow.generateUUID(); + newNode["id"] = id; + newNode["flowId"] = flowId; + newNode["moduleId"] = moduleId; + newNode["name"] = "NewNode" + currentNewNodeNumber; + newNode["position"] = {}; + newNode.position["left"] = left; + newNode.position["top"] = top; + newNode["configurations"] = []; + instance.flows[flowId].nodes.push(newNode); +}; + +// HDFS +HAFlow.Main.prototype.getHdfsFile = function(path, fileName) { + _currentInstance=this; + $.ajax({ + url : this.basePath + "hdfs/file", + type : "GET", + dataType : "json", + data : { + path : path, + fileName : fileName + }, + success : function(data, status) { + var contentPane = new dijit.layout.ContentPane({ + id : data.path, + title : data.filename, + content : data.content, + closable : true, + }); + _currentInstance.ui.centerContainer.addChild(contentPane); + _currentInstance.ui.centerContainer.selectChild(dijit + .byId(data.path)); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while reading hdfs file: " + error); + } + }); +}; + +HAFlow.Main.prototype.getHdfsFileList = function(path) { + var _currentInstance = this; + $.ajax({ + url : this.basePath + "hdfs/list", + type : "GET", + dataType : "json", + data : { + path : path + }, + success : function(data, status) { + _currentInstance.refreshHdfsFileList(_currentInstance, path, data); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while loading flow list: " + error); + } + }); +}; + +HAFlow.Main.prototype.refreshHdfsFileList = function(instance, parentPath, data) { + var i; + for (i = 0; i < data.files.length; i++) { + this.hdfsFileListStore.put({ + id:parentPath + "/" + data.files[i].name, + name : data.files[i].name, + isDirectory : data.files[i].directory, + path : parentPath + "/" + data.files[i].name, + parentPath : parentPath + }); + if (data.files[i].directory) { + instance.getHdfsFileList(parentPath + "/" + data.files[i].name); + } + } +}; + +// Paint Helper +HAFlow.Main.prototype.addEndpoints = function(instance, flowId, nodeId, module, + sourceEndpoint, targetEndpoint) { + var k = 0; + for ( var i = 0; i < module.outputs.length; i++, k++) { + var sourceId = nodeId + "_" + module.outputs[i].name; + instance.jsPlumb[flowId].allSourceEndpoints + .push(instance.jsPlumb[flowId].addEndpoint(nodeId, + sourceEndpoint, { + anchor : [ 1, + 1 / (module.outputs.length + 1) * (i + 1), + 1, 0 ], + uuid : sourceId, + overlays : [ [ "Label", { + location : [ 0.5, -0.5 ], + label : module.outputs[i].name + } ] ] + })); + } + k = 0; + for ( var j = 0; j < module.inputs.length; j++, k++) { + var targetId = nodeId + "_" + module.inputs[j].name; + instance.jsPlumb[flowId].allTargetEndpoints + .push(instance.jsPlumb[flowId].addEndpoint(nodeId, + targetEndpoint, { + anchor : [ 0, + 1 / (module.inputs.length + 1) * (j + 1), + -1, 0 ], + uuid : targetId, + overlays : [ [ "Label", { + location : [ 0.5, -0.5 ], + label : module.inputs[j].name + } ] ] + })); + } +}; + +// Initialize +HAFlow.Main.prototype.init = function() { + this.flows = {}; + this.jsPlumb = {}; + + this.initUserInterface(); + this.initFlowContainer(); + this.initData(); +}; + +HAFlow.Main.prototype.initNodes = function(flowId) { + var _currentInstance = this; + this.jsPlumb[flowId].draggable($(".node"), { + containment : "#" + "flowContainer_" + flowId, + stop : function(event, ui) { + _currentInstance.onDropNode(_currentInstance, flowId, event, ui); + } + }); + var i; + for (i = 0; i < this.flows[flowId].nodes.length; i++) { + var nodeId = "node_" + this.flows[flowId].nodes[i].id; + var sourceEndpoint = { + paintStyle : { + strokeStyle : "#225588", + fillStyle : "transparent", + radius : 7, + }, + isSource : true, + connector : [ "Flowchart", {} ], + connectorStyle : { + strokeStyle : "#225588", + lineWidth : 3 + } + }; + var targetEndpoint = { + endpoint : "Dot", + isTarget : true, + maxConnections : -1, + }; + + this.jsPlumb[flowId].allSourceEndpoints = []; + this.jsPlumb[flowId].allTargetEndpoints = []; + var node = this.getNodeById(this, flowId, + this.flows[flowId].nodes[i].id); + var module = this.getModuleById(this, node.moduleId); + + this.addEndpoints(this, flowId, nodeId, module, sourceEndpoint, + targetEndpoint); + } +}; + +HAFlow.Main.prototype.initData = function() { + this.initFlowListData(); + this.getHdfsFileList(this.rootPath); +}; + +HAFlow.Main.prototype.initFlowListData = function() { + var _currentInstance = this; + $.ajax({ + url : this.basePath + "flow", + type : "GET", + cache : false, + dataType : "json", + success : function(data, status) { + _currentInstance.flowList = data; + _currentInstance.initModuleListData(); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while loading flow list: " + error); + } + }); +}; + +HAFlow.Main.prototype.initModuleListData = function() { + var _currentInstance = this; + $.ajax({ + + url : _currentInstance.basePath + "module", + type : "GET", + cache : false, + dataType : "json", + success : function(data, status) { + _currentInstance.moduleList = data; + _currentInstance.drawLists(_currentInstance); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while loading module list: " + error); + } + }); +}; + +HAFlow.Main.prototype.initUserInterface = function() { + this.ui.init(); + this.initUserInterfaceId(); + this.initMainMenu(); + this.initToolbar(); + this.initBottomTabs(); + this.initFlowList(); + this.initHdfsFileList(); + this.ui.refresh(); +}; + +HAFlow.Main.prototype.initToolbar = function() { + this.toolbar = {}; + this.toolbar.toolbar = new dijit.Toolbar({ + id : "toolbar" + }); + this.toolbar.newFlowButton = new dijit.form.Button({ + id : "toolbar_newFlow", + label : "New Flow", + showLabel : false, + iconClass : "dijitEditorIcon dijitEditorIconNewPage" + }); + this.toolbar.saveFlowButton = new dijit.form.Button({ + id : "toolbar_saveFlow", + label : "Save Flow", + showLabel : false, + iconClass : "dijitEditorIcon dijitEditorIconSave" + }); + this.toolbar.removeFlowButton = new dijit.form.Button({ + id : "toolbar_removeFlow", + label : "Remove Flow", + showLabel : false, + iconClass : "dijitEditorIcon dijitEditorIconDelete" + }); + this.toolbar.runFlowButton = new dijit.form.Button({ + id : "toolbar_runFlow", + label : "Run Flow", + showLabel : false, + iconClass : "dijitEditorIcon dijitEditorIconTabIndent" + }); + this.toolbar.toolbar.addChild(this.toolbar.newFlowButton); + this.toolbar.toolbar.addChild(this.toolbar.saveFlowButton); + this.toolbar.toolbar.addChild(this.toolbar.removeFlowButton); + this.toolbar.toolbar.addChild(this.toolbar.runFlowButton); + this.toolbar.toolbar.startup(); + + var _currentInstance = this; + dojo.connect(this.toolbar.newFlowButton, "onClick", function(event) { + _currentInstance.newFlow(); + }); + dojo.connect(this.toolbar.saveFlowButton, "onClick", function(event) { + _currentInstance.saveFlow(_currentInstance.currentFlowId); + }); + dojo.connect(this.toolbar.removeFlowButton, "onClick", function(event) { + _currentInstance.removeFlow(_currentInstance.currentFlowId); + }); + dojo.connect(this.toolbar.runFlowButton, "onClick", function(event) { + _currentInstance.runFlow(_currentInstance.currentFlowId); + }); + this.ui.mainMenu.addChild(this.toolbar.toolbar); +}; + +HAFlow.Main.prototype.initUserInterfaceId = function() { + this.flowListContainerId = "flowListTreeContainer"; + this.flowListTreeId = "flowListTree"; + this.hdfsFileListContainerId = "hdfsFileListContainer"; + this.hdfsFileListTreeId = "hdfsFileListTree"; + this.moduleListContainerId = "moduleListContainer"; + this.flowContainerId = "flowContainer"; + this.informationContainerId = "informationContainer"; + this.consoleContainerId = "consoleContainer"; + this.logContainerId = "logContainer"; + this.configurationContainerId = "configurationContainer"; +}; + +HAFlow.Main.prototype.initMainMenu = function() { + this.menu = {}; + this.initFlowMenu(); +}; + +HAFlow.Main.prototype.initFlowMenu = function() { + this.menu.flowMenu = new dijit.Menu({ + id : "flowMenu" + }); + this.menu.flowMenu.newFlowMenuItem = new dijit.MenuItem({ + id : "newFlowMenuItem", + label : "New", + }); + this.menu.flowMenu.openFlowMenuItem = new dijit.MenuItem({ + id : "openFlowMenuItem", + label : "Open", + disabled : true + }); + this.menu.flowMenu.closeFlowMenuItem = new dijit.MenuItem({ + id : "closeFlowMenuItem", + label : "Close", + disabled : true + }); + this.menu.flowMenu.deleteFlowMenuItem = new dijit.MenuItem({ + id : "deleteFlowMenuItem", + label : "Delete" + }); + this.menu.flowMenu.exportFlowMenuItem = new dijit.MenuItem({ + id : "exportFlowMenuItem", + label : "Export", + disabled : true + }); + this.menu.flowMenu.importFlowMenuItem = new dijit.MenuItem({ + id : "importFlowMenuItem", + label : "Import", + disabled : true + }); + this.menu.flowMenu.addChild(this.menu.flowMenu.newFlowMenuItem); + this.menu.flowMenu.addChild(this.menu.flowMenu.openFlowMenuItem); + this.menu.flowMenu.addChild(this.menu.flowMenu.closeFlowMenuItem); + this.menu.flowMenu.addChild(this.menu.flowMenu.deleteFlowMenuItem); + this.menu.flowMenu.addChild(this.menu.flowMenu.exportFlowMenuItem); + this.menu.flowMenu.addChild(this.menu.flowMenu.importFlowMenuItem); + this.menu.flowMenu.startup(); + + this.menu.runMenu = new dijit.Menu({ + id : "runMenu" + }); + this.menu.runMenu.runMenuItem = new dijit.MenuItem({ + id : "runMenuItem", + label : "Run", + }); + this.menu.runMenu.debugMenuItem = new dijit.MenuItem({ + id : "debugMenuItem", + label : "Debug", + disabled : true + }); + this.menu.runMenu.validateMenuItem = new dijit.MenuItem({ + id : "validateMenuItem", + label : "Validate", + disabled : true + }); + this.menu.runMenu.runHistoryMenuItem = new dijit.MenuItem({ + id : "runHistoryMenuItem", + label : "Run History", + disabled : true + }); + this.menu.runMenu.debugHistoryMenuItem = new dijit.MenuItem({ + id : "debugHistoryMenuItem", + label : "Debug History", + disabled : true + }); + this.menu.runMenu.addChild(this.menu.runMenu.runMenuItem); + this.menu.runMenu.addChild(this.menu.runMenu.debugMenuItem); + this.menu.runMenu.addChild(this.menu.runMenu.validateMenuItem); + this.menu.runMenu.addChild(this.menu.runMenu.runHistoryMenuItem); + this.menu.runMenu.addChild(this.menu.runMenu.debugHistoryMenuItem); + this.menu.runMenu.startup(); + + this.menu.searchMenu = new dijit.Menu({ + id : "searchMenu" + }); + this.menu.searchMenu.searchFlowMenuItem = new dijit.MenuItem({ + id : "searchFlowMenuItem", + label : "Search Flow", + disabled : true + }); + this.menu.searchMenu.searchModuleMenuItem = new dijit.MenuItem({ + id : "searchModuleMenuItem", + label : "Search Module", + disabled : true + }); + this.menu.searchMenu.searchLogMenuItem = new dijit.MenuItem({ + id : "searchLogMenuItem", + label : "Search Log", + disabled : true + }); + this.menu.searchMenu.addChild(this.menu.searchMenu.searchFlowMenuItem); + this.menu.searchMenu.addChild(this.menu.searchMenu.searchModuleMenuItem); + this.menu.searchMenu.addChild(this.menu.searchMenu.searchLogMenuItem); + this.menu.searchMenu.startup(); + + this.menu.windowMenu = new dijit.Menu({ + id : "windowMenu" + }); + this.menu.windowMenu.hideToolbarMenuItem = new dijit.MenuItem({ + id : "hideToolbarMenuItem", + label : "Hide Toolbar", + disabled : true + }); + this.menu.windowMenu.addChild(this.menu.windowMenu.hideToolbarMenuItem); + this.menu.windowMenu.startup(); + + this.menu.helpMenu = new dijit.Menu({ + id : "helpMenu" + }); + this.menu.helpMenu.aboutMenuItem = new dijit.MenuItem({ + id : "aboutMenuItem", + label : "About", + disabled : true + }); + this.menu.helpMenu.manualMenuItem = new dijit.MenuItem({ + id : "manualMenuItem", + label : "Manual", + disabled : true + }); + this.menu.helpMenu.addChild(this.menu.helpMenu.aboutMenuItem); + this.menu.helpMenu.addChild(this.menu.helpMenu.manualMenuItem); + this.menu.helpMenu.startup(); + + this.menu.oozieMenu = new dijit.Menu({ + id : "oozieMenu" + }); + this.menu.oozieMenu.openMenuItem = new dijit.MenuItem({ + id : "openMenuItem", + label : "Open" + }); + this.menu.oozieMenu.closeMenuItem = new dijit.MenuItem({ + id : "closeMenuItem", + label : "Close", + disabled : true + }); + this.menu.oozieMenu.addChild(this.menu.oozieMenu.openMenuItem); + this.menu.oozieMenu.addChild(this.menu.oozieMenu.closeMenuItem); + this.menu.oozieMenu.startup(); + + this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ + id : "flowPopupMenuBarItem", + label : "Flow", + popup : this.menu.flowMenu + })); + this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ + id : "runPopupMenuBarItem", + label : "Run", + popup : this.menu.runMenu + })); + this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ + id : "searchPopupMenuBarItem", + label : "Search", + popup : this.menu.searchMenu + })); + this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ + id : "windowPopupMenuBarItem", + label : "Window", + popup : this.menu.windowMenu + })); + this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ + id : "helpPopupMenuBarItem", + label : "Help", + popup : this.menu.helpMenu + })); + this.ui.mainMenu.addChild(new dijit.PopupMenuBarItem({ + id : "ooziePopupMenuBarItem", + label : "oozie", + popup : this.menu.oozieMenu + })); + + var _currentInstance = this; + dojo.connect(this.menu.flowMenu.newFlowMenuItem, "onClick", + function(event) { + _currentInstance.newFlow(); + }); + dojo.connect(this.menu.flowMenu.deleteFlowMenuItem, "onClick", function( + event) { + _currentInstance.removeFlow(_currentInstance.currentFlowId); + }); + dojo.connect(this.menu.runMenu.runMenuItem, "onClick", function(event) { + _currentInstance.runFlow(_currentInstance.currentFlowId); + }); + dojo.connect(this.menu.oozieMenu.openMenuItem, "onClick", function(event) { + _currentInstance.openoozie(); + }); + + dojo.connect(this.menu.runMenu.runHistoryMenuItem, "onClick", function(event){ + _currentInstance.showRunHistory(_currentInstance.currentFlowId); + }); +}; + +HAFlow.Main.prototype.initBottomTabs = function() { + this.initInformationTab(); + this.initConfigurationTab(); + this.initConsoleTab(); + this.initLogTab(); +}; + +HAFlow.Main.prototype.initInformationTab = function() { + var informationContentPane = (new dijit.layout.ContentPane({ + id : this.informationContainerId, + title : "Information" + })); + this.ui.bottomContainer.addChild(informationContentPane); +}; + +HAFlow.Main.prototype.initConsoleTab = function() { + var consoleContentPane = new dijit.layout.ContentPane({ + id : this.consoleContainerId, + title : "Console" + }); + this.ui.bottomContainer.addChild(consoleContentPane); +}; + +HAFlow.Main.prototype.initLogTab = function() { + var logContentPane = new dijit.layout.ContentPane({ + id : this.logContainerId, + title : "Log" + }); + this.ui.bottomContainer.addChild(logContentPane); +}; + +HAFlow.Main.prototype.initConfigurationTab = function() { + var configurationContentPane = new dijit.layout.ContentPane({ + id : this.configurationContainerId, + title : "Configuration" + }); + this.ui.bottomContainer.addChild(configurationContentPane); +}; + +HAFlow.Main.prototype.initFlowList = function() { + var flowListContentPane = new dijit.layout.ContentPane({ + id : this.flowListContainerId, + title : "Flows" + }); + this.ui.leadingContainer.addChild(flowListContentPane); + this.initFlowListStore(); + this.initFlowListTree(); +}; + +HAFlow.Main.prototype.initHdfsFileList = function() { + var hdfsFileListContentPane = new dijit.layout.ContentPane({ + id : this.hdfsFileListContainerId, + title : "HDFS" + }); + this.ui.leadingContainer.addChild(hdfsFileListContentPane); + this.initHdfsFileListStore(); + this.initHdfsFileListTree(); +}; + +HAFlow.Main.prototype.initHdfsFileListStore = function() { + this.hdfsFileListStore = new dojo.store.Observable(new dojo.store.Memory({ + data : [ { + id : "root", + name : "Root(" + this.rootPath + ")", + isDirectory : true, + path : this.rootPath + } ], + getChildren : function(object) { + return this.query({ + parentPath : object.path + }); + } + })); +}; + +HAFlow.Main.prototype.initHdfsFileListTree = function() { + var treeModel = new dijit.tree.ObjectStoreModel({ + store : this.hdfsFileListStore, + query : { + id : "root" + }, + mayHaveChildren : function(item) { + return item.isDirectory; + } + }); + var tree = new dijit.Tree({ + model : treeModel + }, dojo.create("div", { + id : this.hdfsFileListTreeId, + }, this.hdfsFileListContainerId)); + var _currentInstance = this; + + this.menu.treeMenu = new dijit.Menu({ + id : "treeMenu", + targetNodeIds : [ _currentInstance.hdfsFileListTreeId ], + selector : ".dijitTreeNode" + }); + this.menu.treeMenu.DownloadMenuItem = new dijit.MenuItem({ + id : "DownloadMenuItem", + label : "Download from Hdfs" + }); + this.menu.treeMenu.CreateMenuItem = new dijit.MenuItem({ + id : "CreateMenuItem", + label : "Create new directory" + }); + this.menu.treeMenu.DeleteMenuItem = new dijit.MenuItem({ + id : "DeleteMenuItem", + label : "Delete" + }); + + this.menu.treeMenu.UploadMenuItem = new dijit.MenuItem({ + id : "UploadMenuItem", + label : "Upload files to Hdfs" + }); + this.menu.treeMenu.addChild(this.menu.treeMenu.DownloadMenuItem); + this.menu.treeMenu.addChild(this.menu.treeMenu.CreateMenuItem); + this.menu.treeMenu.addChild(this.menu.treeMenu.DeleteMenuItem); + this.menu.treeMenu.addChild(this.menu.treeMenu.UploadMenuItem); + + dojo.connect( + this.menu.treeMenu.UploadMenuItem, + "onClick", + function() { + var tn = dijit.byNode(this.getParent().currentTarget); + var path=tn.item.path; + alert(path); + var isDirectory=tn.item.isDirectory; + if(isDirectory==true) + { + var dialog = new dijit.Dialog({ + title : "upload", + content : "
" + + "" + + "
", + style : "width:400px" + }); + dialog.show(); + dojo.connect(dojo.byId("upload_btn"),"onclick",function(){ + // alert("before send. url:"+_currentInstance.basePath+"/hdfs/upload"); + alert(path); + dojo.io.iframe.send({ + form: "hdfsfilepath", //ijformԪذļ· + handleAs: "xml", //htmlҳ + url:_currentInstance.basePath+"/hdfs/upload?remotePath="+path, + load: function(response){ + var success = response.getElementsByTagName("success")[0].childNodes[0].nodeValue; + var filename = response.getElementsByTagName("filename")[0].childNodes[0].nodeValue; + if(success=="true") + { + HAFlow.showDialog("Upload", "Upload scceess."); + _currentInstance.hdfsFileListStore.put({ + id:path+"/"+filename, + name:filename, + isDirectory:false, + path:path+"/"+filename, + parentPath:path, + }); + } + else + HAFlow.showDialog("Upload", "Upload failure."); + }, //ύɹ + error: function(e){ + HAFlow.showDialog("Upload", "Upload failure."); + }//ύʧ + }); + dialog.destroy(); + }); + } + else + HAFlow.showDialog("Upload", "It's a file.Can't upload to it."); + + + }); + dojo.connect( + this.menu.treeMenu.DeleteMenuItem, + "onClick", + function() { + var tn = dijit.byNode(this.getParent().currentTarget); + var path=tn.item.path; + var isDirectory=tn.item.isDirectory; + if(isDirectory==true) + $.ajax({ + url : _currentInstance.basePath+"hdfs/deletedirectory?remotepath="+path, + type : "GET", + dataType : "json", + contentType : "application/json", + data : JSON.stringify({}), + success : function(data, status) { + if(data.success=true) + { + HAFlow.showDialog("Remove HdfsFile Directory", "HdfsFile Directory removed."); + } + else + HAFlow.showDialog("Remove HdfsFile Directory", "HdfsFile Directory can't be removed."); + var file_item=_currentInstance.hdfsFileListStore.query({parentPath:path}); + var i; + for(i=0;i
" + + "new name: " + + "
"); + dojo.connect(dojo.byId("create_btn"),"onclick",function(){ + $.ajax({ + url : _currentInstance.basePath+"hdfs/createdirectory?remotepath="+path+"&directoryname="+dojo.byId("directoryname").value, + type : "GET", + dataType : "json", + contentType : "application/json", + data : JSON.stringify({}), + success : function(data, status) { + if(data.success=true) + { + HAFlow.showDialog("Create HdfsFile Directory", "HdfsFile Directory created."); + _currentInstance.hdfsFileListStore.put({ + id:path+"/"+data.directoryname, + name:data.directoryname, + isDirectory:true, + path:path+"/"+data.directoryname, + parentPath:path, + }); + + } + else + HAFlow.showDialog("Create HdfsFile Directory", "HdfsFile Directory can't be created."); + }, + error : function(request, status, error) { + HAFlow.showDialog("Error", + "An error occurred while removing HdfsFile Directory: " + error); + } + }); + }); + } + else + { + HAFlow.showDialog("Create HdfsFile Directory", "It's a file.HdfsFile Directory can't be created in it."); + } + + }); + dojo.connect( + this.menu.treeMenu.DownloadMenuItem, + "onClick", + function() { + var tn = dijit.byNode(this.getParent().currentTarget); + var path=tn.item.path; + var name=tn.item.name; + var isDirectory=tn.item.isDirectory; + if(isDirectory==false) + { + var form = $("
"); //һform + + form.attr('style','display:none'); //formӲѯ + + form.attr('target',''); + + form.attr('method','post'); + + form.attr('action',"/haflow/hdfs/download"); + + form.attr('id',"form1"); + + var input1 = $(''); + input1.attr('id','input1'); + + input1.attr('type','hidden'); + + input1.attr('name','remotepath'); + + input1.attr('value',path); + + var input2 = $(''); + + input2.attr('type','hidden'); + + input2.attr('name','filename'); + + input2.attr('value',name); + + $('body').append(form); //web + + form.append(input1); //ѯؼύ + form.append(input2); + form.submit(); //ύ + $("#form1").ajaxForm(function(){ + HAFlow.showDialog("Download", "Succeed to download it."); + }); + } + else + { + + HAFlow.showDialog("Download", "It's a directory.Can't download it."); + } + }); + this.menu.treeMenu.startup(); + tree.on("click", function(item) { + if (item.directory == true) { + + } + else{ + hdfspath=item.path; + } + }, true); + tree.on("dblclick", function(item) { + if (item.isDirectory == true) { + + } else { + _currentInstance.getHdfsFile(item.parentPath, item.name); + } + }, true); + + tree.startup(); +}; + +HAFlow.Main.prototype.initFlowListStore = function() { + this.flowListStore = new dojo.store.Observable(new dojo.store.Memory({ + data : [ { + id : "root", + name : "Flows", + node : false + } ], + + getChildren : function(object) { + if (object.id == "root") { + return this.query({ + node : true + }); + } + return null; + } + })); +}; + +HAFlow.Main.prototype.initFlowListTree = function() { + var treeModel = new dijit.tree.ObjectStoreModel({ + store : this.flowListStore, + query : { + id : "root" + }, + mayHaveChildren : function(item) { + return !(item.node); + } + }); + var tree = new dijit.Tree({ + model : treeModel + }, dojo.create("div", { + id : this.flowListTreeId, + }, this.flowListContainerId)); + + var _currentInstance = this; + + tree.on("click", function(item) { + if (item.node == true) { + _currentInstance.onFlowClicked(_currentInstance, item.id); + + } + + }); + tree.on("dblclick", function(item) { + if (item.node == true) { + _currentInstance.loadFlow(item.id); + } + }, true); + + tree.startup(); +}; + +HAFlow.Main.prototype.initFlowContainer = function() { + var _currentInstance = this; + this.ui.centerContainer.watch("selectedChildWidget", function(name, from, + to) { + var flowId = to.domNode.id.replace("flowContainerPane_", ""); + _currentInstance.currentFlowId = flowId; + _currentInstance.setupDroppable(flowId); + _currentInstance.paintFlow(flowId); + }); +}; + +HAFlow.Main.prototype.initJsPlumb = function(flowId) { + this.jsPlumb[flowId] = jsPlumb.getInstance(); + this.jsPlumb[flowId].reset(); + this.jsPlumb[flowId].importDefaults({ + DragOptions : { + cursor : 'pointer', + zIndex : 2000 + }, + Endpoints : [ [ "Dot", { + radius : 8 + } ], [ "Dot", { + radius : 8 + } ] ], + ConnectionOverlays : [ [ "Arrow", { + location : -40 + } ] ] + }); +}; + +HAFlow.Main.prototype.setupDroppable = function(flowId) { + $(".module").draggable({ + appendTo : "#" + "flowContainer_" + flowId, + revert : "invalid", + helper : "clone" + }); + var _currentInstance = this; + $("#" + "flowContainer_" + flowId).droppable( + { + accept : ".module", + drop : function(event, ui) { + _currentInstance.onModuleAdded(_currentInstance, flowId, + event, ui); + } + }); +}; + +HAFlow.Main.prototype.buildFlowListTree = function() { + var i; + for (i = 0; i < this.flowList.flows.length; i++) { + this.flowListStore.put({ + id : this.flowList.flows[i].id, + name : this.flowList.flows[i].name, + node : true + }); + } +}; + +HAFlow.Main.prototype.drawLists = function(instance) { + instance.paintModuleList(); + instance.buildFlowListTree(); +}; + +HAFlow.Main.prototype.saveFlowName = function(instance, flowId) { + if (instance.flows[flowId]) { + var value = $("#" + "flow_" + flowId + "_name").val(); + if (this.checkFlowName(instance, instance.flows[flowId].name, value)) { + instance.flows[flowId].name = value; + instance.getFlowBriefById(instance, flowId).name = value; + var pane = dijit.byId("flowContainerPane_" + flowId); + pane.title = value; + instance.ui.centerContainer.removeChild(pane); + instance.ui.centerContainer.addChild(pane); + instance.ui.centerContainer.selectChild(pane); + instance.flowListStore.remove(flowId); + instance.flowListStore.put({ + id : instance.flows[flowId].id, + name : instance.flows[flowId].name, + node : true + }); + } else { + HAFlow.showDialog("Error", "Invalid flow name"); + } + } else { + HAFlow.showDialog("Error", + "Please load the flow before saving flow metadata!"); + } +}; + +HAFlow.Main.prototype.paintModuleList = function() { + var i; + for (i = 0; i < this.moduleList.modules.length; i++) { + if (dijit.byId(this.moduleListContainerId + "_" + + this.moduleList.modules[i].category) == null) { + var moduleListPane = new dijit.layout.ContentPane({ + id : this.moduleListContainerId + "_" + + this.moduleList.modules[i].category, + title : this.moduleList.modules[i].category + }); + this.ui.trailingContainer.addChild(moduleListPane); + } + text = "
" + + this.moduleList.modules[i].name + "
"; + $( + "#" + this.moduleListContainerId + "_" + + this.moduleList.modules[i].category).append(text); + } + this.ui.refresh(); + +}; + +HAFlow.Main.prototype.paintFlow = function(flowId) { + this.initJsPlumb(flowId); + this.paintNodes(flowId); + this.initNodes(flowId); + this.paintEdges(flowId); + this.bindJsPlumbEvents(flowId); + this.bindFunctions(flowId); + this.jsPlumb[flowId].repaintEverything(); +}; + +HAFlow.Main.prototype.paintNodes = function(flowId) { + var text = ""; + for ( var i = 0; i < this.flows[flowId].nodes.length; i++) { + var moduleName = this.getModuleById(this, + this.flows[flowId].nodes[i].moduleId).name; + text += "
" + + "
" + this.flows[flowId].nodes[i].name + "
" + + "(" + moduleName + ")
" + "
"; + } + $("#" + "flowContainer_" + flowId).html(text); +}; + +HAFlow.Main.prototype.paintEdges = function(flowId) { + for ( var i = 0; i < this.flows[flowId].edges.length; i++) { + this.jsPlumb[flowId].connect({ + uuids : [ + "node_" + this.flows[flowId].edges[i].sourceNodeId + "_" + + this.flows[flowId].edges[i].sourceEndpoint, + "node_" + this.flows[flowId].edges[i].targetNodeId + "_" + + this.flows[flowId].edges[i].targetEndpoint ], + detachable : false + }); + } +}; + +HAFlow.Main.prototype.bindJsPlumbEvents = function(flowId) { + var _currentInstance = this; + this.jsPlumb[flowId].bind("click", function(info) { + _currentInstance.onConnectionClicked(_currentInstance, flowId, info); + }); + this.jsPlumb[flowId].bind("connection", function(info) { + _currentInstance.onConnectionCreated(_currentInstance, flowId, info); + }); + +}; + +HAFlow.Main.prototype.bindFunctions = function(flowId) { + var _currentInstance = this; + $(".node").bind("click", function() { + var nodeId = $(this).attr("id").replace("node_", ""); + _currentInstance.onNodeClicked(_currentInstance, flowId, nodeId); + }); + $(".module").bind("click", function() { + var moduleId = $(this).attr("id").replace("module_", ""); + _currentInstance.onModuleClicked(_currentInstance, flowId, moduleId); + }); +}; + +// Event Handler +HAFlow.Main.prototype.onFlowClicked = function(instance, flowId) { + var flowBrief = instance.getFlowBriefById(instance, flowId); + var text = ""; + text += "
"; + text += "
Flow Info:
"; + text += "
Id: " + + flowBrief.id + "
"; + text += "
Name:"; + text += "
"; + text += "
"; + text += "
"; + $("#" + instance.informationContainerId).html(text); + if (dijit.byId("flow_" + flowBrief.id + "_name") != null) { + dijit.registry.remove("flow_" + flowBrief.id + "_name"); + } + var flowNameTextBox = new dijit.form.TextBox({ + id : "flow_" + flowBrief.id + "_name", + value : flowBrief.name, + style : "width:600px;" + }); + flowNameTextBox.placeAt(dojo.byId("flow_name_text_box")); + flowNameTextBox.startup(); + var button = new dijit.form.Button({ + label : "Save", + onClick : function() { + instance.saveFlowName(instance, flowBrief.id); + } + }); + button.placeAt(dojo.byId("save_flow_name_button")); + button.startup(); +}; + +HAFlow.Main.prototype.onModuleClicked = function(instance, flowId, moduleId) { + var text = ""; + var i; + for (i = 0; i < instance.moduleList.modules.length; i++) { + if (moduleId == instance.moduleList.modules[i].id) { + break; + } + } + text += "
" + + "Name: " + + instance.moduleList.modules[i].name + ".
"; + $("#" + instance.informationContainerId).html(text); +}; + +HAFlow.Main.prototype.onNodeClicked = function(instance, flowId, nodeId) { + var node = instance.getNodeById(instance, flowId, nodeId); + var module = instance.getModuleById(instance, node.moduleId); + var text = ""; + text += "
"; + text += "
Node Id: " + + node.id + "
"; + text += "
Flow: " + + instance.flows[node.flowId].name + "
"; + text += "
Module: " + + module.name + "
"; + text += "
"; + text += "Name: "; + text += ""; + text += "
"; + text += "
"; + text += "
Delete?
"; + text += "
"; + text += "
"; + $("#" + instance.informationContainerId).html(text); + + if (dijit.byId("node_" + nodeId + "_name") != null) { + dijit.registry.remove("node_" + nodeId + "_name"); + } + var nodeNameTextBox = new dijit.form.TextBox({ + id : "node_" + nodeId + "_name", + value : node.name, + style : "width:600px;" + }); + nodeNameTextBox.placeAt(dojo.byId("node_name_text_box")); + nodeNameTextBox.startup(); + + var saveNodeNameButton = new dijit.form.Button({ + label : "Save Node Name", + onClick : function() { + instance.saveNodeName(instance, flowId, nodeId); + } + }); + saveNodeNameButton.placeAt(dojo.byId("save_node_name_button")); + saveNodeNameButton.startup(); + + var deleteNodeButton = new dijit.form.Button({ + label : "Delete Node", + onClick : function() { + instance.deleteNode(instance, flowId, nodeId); + } + }); + deleteNodeButton.placeAt(dojo.byId("delete_node_button")); + deleteNodeButton.startup(); + + var form = ""; + form += "
"; + form += "
Configuration:
"; + var i; + for (i = 0; i < module.configurations.length; i++) { + var textBoxId = "flow_" + flowId + "_node_" + nodeId + "_" + + module.configurations[i].key; + var divId = textBoxId + "_container"; + var hdfspathButtonId=textBoxId+"_hdfspathButton"; + form += "
"; + if (module.configurations[i].type == "BOOLEAN") { + form += "
" + + module.configurations[i].displayName + + "
"; + } else { + form += ("" + module.configurations[i].displayName + ""); + form += "
"; + } + form += "
"; + } + form += "
"; + form += "
"; + $("#" + instance.configurationContainerId).html(form); + for (i = 0; i < module.configurations.length; i++) { + var textBoxId = "flow_" + flowId + "_node_" + nodeId + "_" + + module.configurations[i].key; + var divId = textBoxId + "_container"; + var hdfspathButtonId=textBoxId+"_hdfspathButton"; + if (dijit.byId(textBoxId) != null) { + dijit.registry.remove(textBoxId); + } + if (module.configurations[i].type == "BOOLEAN") { + var configtype_true = new dijit.form.CheckBox({ + id : textBoxId, + checked : (instance.getConfigurationValue(instance, flowId, + nodeId, module.configurations[i].key) == "on") ? true + : false + }); + configtype_true.placeAt(dojo.byId(divId)); + configtype_true.startup(); + } else { + var configurationTextBox = new dijit.form.TextBox({ + id : textBoxId+"_textbox", + value : instance.getConfigurationValue(instance, flowId, + nodeId, module.configurations[i].key), + style : "width:600px;" + }); + configurationTextBox.placeAt(dojo.byId(divId)); + configurationTextBox.startup(); + var hdfspathButton = new dijit.form.Button({ + id:textBoxId, + label : "Hdfs Path", + onClick : function() { + dijit.byId(this.id+"_textbox").set("value",hdfspath); + } + }); + hdfspathButton.placeAt(dojo.byId(hdfspathButtonId)); + hdfspathButton.startup(); + } + } + + var saveConfigurationButton = new dijit.form.Button({ + label : "Save Configuration", + onClick : function() { + instance.saveConfiguration(instance, flowId, nodeId); + } + }); + saveConfigurationButton.placeAt(dojo.byId("save_configuration_button")); + saveConfigurationButton.startup(); +}; + +HAFlow.Main.prototype.onConnectionClicked = function(instance, flowId, info) { + var source = info.sourceId.replace("node_", ""); + var sourceEndpoint = info.endpoints[0].overlays[0].getLabel(); + var target = info.targetId.replace("node_", ""); + var targetEndpoint = info.endpoints[1].overlays[0].getLabel(); + var sourceNode = instance.getNodeById(instance, flowId, source); + var targetNode = instance.getNodeById(instance, flowId, target); + + var text = ""; + text += "
"; + text += "
From: " + + sourceNode.name + "." + sourceEndpoint + "
" + + "
To: " + + targetNode.name + "." + targetEndpoint + "
"; + text += "
Delete?
"; + text += "
"; + text += "
"; + $("#" + instance.informationContainerId).html(text); + var button = new dijit.form.Button({ + label : "Delete Connection", + onClick : function() { + instance.deleteConnection(instance, flowId, info); + } + }); + button.placeAt(dojo.byId("delete_connection_button")); + button.startup(); +}; + +HAFlow.Main.prototype.onConnectionCreated = function(instance, flowId, info) { + var source = info.sourceId.replace("node_", ""); + var sourceEndpoint = info.sourceEndpoint.overlays[0].getLabel(); + var target = info.targetId.replace("node_", ""); + var targetEndpoint = info.targetEndpoint.overlays[0].getLabel(); + var exist = false; + var illegal = false; + for ( var i = 0; i < instance.flows[flowId].edges.length; i++) { + if (instance.flows[flowId].edges[i].sourceNodeId == source + && instance.flows[flowId].edges[i].sourceEndpoint == sourceEndpoint + && instance.flows[flowId].edges[i].targetNodeId == target + && instance.flows[flowId].edges[i].targetEndpoint == targetEndpoint) { + exist = true; + break; + } + } + if (source == target) { + illegal = true; + } + if (!exist && !illegal) { + var newConnection = instance.newConnection(instance.flows[flowId].id, + source, sourceEndpoint, target, targetEndpoint); + instance.flows[flowId].edges.push(newConnection); + info.connection.setDetachable(false); + info.connection.setPaintStyle({ + strokeStyle : "rgb(22,55,88)" + }); + } else { + instance.jsPlumb[flowId].detach(info); + } +}; + +HAFlow.Main.prototype.onDropNode = function(instance, flowId, event, ui) { + var newLeft = ui.position.left; + var newTop = ui.position.top; + var nodeId = ui.helper.context.id.replace("node_", ""); + for ( var i = 0; i < instance.flows[flowId].nodes.length; i++) { + if (instance.flows[flowId].nodes[i].id == nodeId) { + instance.flows[flowId].nodes[i].position.left = newLeft; + instance.flows[flowId].nodes[i].position.top = newTop; + } + } + instance.jsPlumb[flowId].repaintEverything(); +}; + +HAFlow.Main.prototype.onCloseTab = function(instance) { + return function() { + var flowId = this.id.replace("flowContainerPane_", ""); + var saveChange = confirm("Save flow before close?"); + if (saveChange) { + instance.saveFlow(flowId); + } + return true; + }; +}; + +HAFlow.Main.prototype.onModuleAdded = function(instance, flowId, event, ui) { + var moduleId = ui.draggable.context.id.replace("module_", ""); + instance.doAddModule(instance, flowId, moduleId, ui.position.left, + ui.position.top); + instance.paintFlow(flowId); +}; diff --git a/src/main/webapp/style/haflow.main.css b/src/main/webapp/style/haflow.main.css index 0200422..ae559ee 100644 --- a/src/main/webapp/style/haflow.main.css +++ b/src/main/webapp/style/haflow.main.css @@ -1,4 +1,10 @@ @CHARSET "UTF-8"; +.dijitDisabled.dijitButtonDisabled .dijitButtonNode { + + border: none; + background-color: transparent; +} + .node { width: 8em; From 3bf8def93c4556188a7fa12f50bb352424a818fc Mon Sep 17 00:00:00 2001 From: dawncx Date: Wed, 9 Oct 2013 11:22:19 +0800 Subject: [PATCH 2/3] chenxi --- src/main/java/haflow/dto/entity/MainUser.java | 121 +++++++++ src/main/java/haflow/module/util/Md5Util.java | 37 +++ src/main/java/haflow/service/UserService.java | 251 ++++++++++++++++++ .../ui/controller/AdminLogonController.java | 85 ++++++ .../ui/controller/MainLogonController.java | 103 +++++++ .../haflow/ui/controller/UserController.java | 82 ++++++ .../java/haflow/ui/helper/UserHelper.java | 88 ++++++ .../haflow/ui/model/SaveUserResultModel.java | 34 +++ src/main/java/haflow/ui/model/UserModel.java | 92 +++++++ src/main/webapp/1.jsp | 29 ++ src/main/webapp/WEB-INF/views/adminhome.jsp | 79 ++++++ src/main/webapp/WEB-INF/views/adminhome2.jsp | 70 +++++ src/main/webapp/WEB-INF/views/adminhome3.jsp | 109 ++++++++ .../webapp/WEB-INF/views/adminusermana.jsp | 63 +++++ .../webapp/WEB-INF/views/registration.jsp | 70 +++++ src/main/webapp/script/adminusermana.js | 15 ++ src/main/webapp/script/logon.js | 50 ++++ src/main/webapp/script/registration.js | 125 +++++++++ 18 files changed, 1503 insertions(+) create mode 100644 src/main/java/haflow/dto/entity/MainUser.java create mode 100644 src/main/java/haflow/module/util/Md5Util.java create mode 100644 src/main/java/haflow/service/UserService.java create mode 100644 src/main/java/haflow/ui/controller/AdminLogonController.java create mode 100644 src/main/java/haflow/ui/controller/MainLogonController.java create mode 100644 src/main/java/haflow/ui/controller/UserController.java create mode 100644 src/main/java/haflow/ui/helper/UserHelper.java create mode 100644 src/main/java/haflow/ui/model/SaveUserResultModel.java create mode 100644 src/main/java/haflow/ui/model/UserModel.java create mode 100644 src/main/webapp/1.jsp create mode 100644 src/main/webapp/WEB-INF/views/adminhome.jsp create mode 100644 src/main/webapp/WEB-INF/views/adminhome2.jsp create mode 100644 src/main/webapp/WEB-INF/views/adminhome3.jsp create mode 100644 src/main/webapp/WEB-INF/views/adminusermana.jsp create mode 100644 src/main/webapp/WEB-INF/views/registration.jsp create mode 100644 src/main/webapp/script/adminusermana.js create mode 100644 src/main/webapp/script/logon.js create mode 100644 src/main/webapp/script/registration.js diff --git a/src/main/java/haflow/dto/entity/MainUser.java b/src/main/java/haflow/dto/entity/MainUser.java new file mode 100644 index 0000000..f92bccc --- /dev/null +++ b/src/main/java/haflow/dto/entity/MainUser.java @@ -0,0 +1,121 @@ +package haflow.dto.entity; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "mainuser") +public class MainUser { + private int id; + private String name; + private String password; + private String email; + private int role; + private String path; + private double space; + private double usedspace; + private String realname; + private Set flows; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(name = "name", unique = true, nullable = false) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Column(name = "password", nullable = false) + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Column(name = "email", unique = true, nullable = false) + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @Column(name = "role", nullable = false) + public int getRole() { + return role; + } + + public void setRole(int role) { + this.role = role; + } + + @Column(name = "path", nullable = false) + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + @Column(name = "space", nullable = false) + public double getSpace() { + return space; + } + + public void setSpace(double space2) { + this.space = space2; + } + + @Column(name = "usedspace") + public double getUsedspace() { + return usedspace; + } + + public void setUsedspace(double d) { + this.usedspace = d; + } + + @Column(name = "realname") + public String getRealname() { + return realname; + } + + public void setRealname(String realname) { + this.realname = realname; + } + + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) + public Set getFlows() { + return flows; + } + + public void setFlows(Set flows) { + this.flows = flows; + } + +} diff --git a/src/main/java/haflow/module/util/Md5Util.java b/src/main/java/haflow/module/util/Md5Util.java new file mode 100644 index 0000000..137e907 --- /dev/null +++ b/src/main/java/haflow/module/util/Md5Util.java @@ -0,0 +1,37 @@ +package haflow.module.util; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class Md5Util { + + public static String getMd5Hex(String password){ + MessageDigest md=null; + try { + md = MessageDigest.getInstance("MD5"); + md.reset(); + md.update(password.getBytes("UTF-8")); + } catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + System.out.println("NoSuchAlgorithmException caught!"); + System.exit(-1); + + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + byte[] rs=md.digest(); + StringBuffer sb=new StringBuffer(); + for(int i=0;i list=query.list(); + if(list!=null){ + return false; + } + else{ + user.setEmail(email); + } + session.merge(user); + transaction.commit(); + } + return true; + } catch (HibernateException e) { + // TODO Auto-generated catch block + transaction.rollback(); + e.printStackTrace(); + return false; + }finally{ + if(session!=null) + session.close(); + } + } + public boolean updateUser(int userid,String password,int role,double space,double usedspace,String realname){ + Session session=this.getSessionHelper().openSession(); + Transaction transaction = session.beginTransaction(); + MainUser user=(MainUser) session.get(MainUser.class, userid); + if (user == null) + return false; + + try { + if(role>1) + role=user.getRole(); + if(usedspace>space) + return false; + user.setPassword(password); + user.setRole(role); + user.setSpace(space); + user.setUsedspace(usedspace); + user.setRealname(realname); + session.merge(user); + transaction.commit(); + + return true; + } catch (HibernateException e) { + // TODO Auto-generated catch block + transaction.rollback(); + e.printStackTrace(); + return false; + }finally{ + if(session!=null) + session.close(); + } + + + + } + public boolean deleteUser(int userid){ + Session session = this.getSessionHelper().openSession(); + Transaction transaction = session.beginTransaction(); + MainUser user=(MainUser) session.get(MainUser.class, userid); + if (user == null) + return false; + + try { + session.delete(user); + transaction.commit(); + + return true; + } catch (HibernateException e) { + // TODO Auto-generated catch block + transaction.rollback(); + e.printStackTrace(); + return false; + }finally{ + if(session!=null) + session.close(); + } + + + + } + public List getAllUser(){ + Session session=this.getSessionHelper().openSession(); + + try { + Query query=session.createQuery("from MainUser as mainUser where role=0"); + List list=query.list(); + session.close(); + return list; + } catch (Exception e) { + System.out.println("error!!!!!!!"); + // TODO Auto-generated catch block + session.close(); + e.printStackTrace(); + return null; + } + + } + public MainUser getUser(int userid){ + Session session = this.getSessionHelper().openSession(); + Transaction transaction = session.beginTransaction(); + try { + MainUser user=(MainUser) session.get(MainUser.class, userid); + if (user == null) + return null; + else + return user; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + }finally{ + if(session!=null) + session.close(); + } + + } + public boolean saveUser(String username, String password,String email, String mora){ + int role=-1; + double space=0.0; + if(mora.equals("main")){ + role=0; + space=5.0; + } + if(mora.equals("admin")){ + role=1; + space=10.0; + } + if(role==-1) + return false; + Session session=this.getSessionHelper().openSession(); + Transaction tran=session.beginTransaction(); + try{ + org.hibernate.Query query=session.createQuery("from MainUser as u where u.name=?"); + query.setString(0,username); + List list=query.list(); + org.hibernate.Query query1=session.createQuery("from MainUser as u where u.email=?"); + query1.setString(0, email); + List list1=query1.list(); + + if(list.size()==0 && list1.size()==0){ + System.out.println("success!"); + MainUser user=new MainUser(); + user.setName(username); + user.setPassword(password); + user.setEmail(email); + user.setRole(role); + user.setSpace(space); + user.setUsedspace(0.0); + user.setPath("/"+username); + session.save(user); + tran.commit(); + session.close(); + return true; + } + else{ + System.out.println(list.get(0)); + return false; + } + + + }catch(Exception e){ + e.printStackTrace(); + tran.rollback(); + session.close(); + return false; + } + + } + public int validate(String username, String password, String mora) { + int role=-1; + if(mora=="admin") + role=1; + if(mora=="main") + role=0; + Session session = this.getSessionHelper().openSession(); + try{ + org.hibernate.Query query=session.createQuery("from MainUser as u where u.name=? and password=?" ); + //" and role=?"); + query.setString(0, username); + query.setString(1,password); + //query.setInteger(2, role); + List list=query.list(); + session.close(); + + if(list.size()==1){ + int realrol=list.get(0).getRole(); + if(realrol>=role){ + return list.get(0).getId(); + } + else + return -1; + } + else + return -1; + + + + }catch (Exception e){ + //e.printStackTrace(); + session.close(); + return -1; + } + + + } + + +} diff --git a/src/main/java/haflow/ui/controller/AdminLogonController.java b/src/main/java/haflow/ui/controller/AdminLogonController.java new file mode 100644 index 0000000..6881014 --- /dev/null +++ b/src/main/java/haflow/ui/controller/AdminLogonController.java @@ -0,0 +1,85 @@ +package haflow.ui.controller; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import haflow.dto.entity.MainUser; +import haflow.module.util.Md5Util; +import haflow.ui.helper.UserHelper; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +@Controller + +public class AdminLogonController { + private UserHelper userHelper; + + private UserHelper getUserHelper() { + return userHelper; + } + + @Autowired + private void setLogonHelper(UserHelper logonHelper) { + this.userHelper = logonHelper; + } + @RequestMapping(value="/admin") + public ModelAndView admin(HttpServletRequest request){ + + if(UserHelper.isUserLogon(request,1)) + return new ModelAndView("admin"); + else + return new ModelAndView("logon"); + } + @RequestMapping(value="/adminusermana") + public ModelAndView adminmana(HttpServletRequest request){ + + if(UserHelper.isUserLogon(request,1)){ + List list=this.getUserHelper().getAllUser(); + request.setAttribute("list", list); + return new ModelAndView("adminusermana"); + } + + else + return new ModelAndView("logon"); + } + @RequestMapping(value="/adminhome") + public ModelAndView aminhome(HttpServletRequest request){ + if(UserHelper.isUserLogon(request,1)) + return new ModelAndView("adminhome"); + else + return new ModelAndView("logon"); + } + @RequestMapping(value="/adminlogon", method = RequestMethod.POST) + public String post(RedirectAttributes redirectAttributes,HttpServletRequest request,@RequestParam("username") String username,@RequestParam("password") String password) { + System.out.println("admin logon enter!!!"); + System.out.println(username); + System.out.println(password); + if(username==""||password==""){ + redirectAttributes.addFlashAttribute("message", "дû"); + return "redirect:/"; + } + password=Md5Util.getMd5Hex(password); + int userid=this.getUserHelper().validate(username, password, "admin"); + if(userid!=-1){ + System.out.println("admin logon"); + request.getSession().setAttribute("username", username); + request.getSession().setAttribute("userid", userid); + request.getSession().setAttribute("scope", 1); + return "redirect:/adminhome"; + } + else{ + redirectAttributes.addFlashAttribute("message","û"); + return "redirect:/"; + } + + + } + +} \ No newline at end of file diff --git a/src/main/java/haflow/ui/controller/MainLogonController.java b/src/main/java/haflow/ui/controller/MainLogonController.java new file mode 100644 index 0000000..ea818ca --- /dev/null +++ b/src/main/java/haflow/ui/controller/MainLogonController.java @@ -0,0 +1,103 @@ +package haflow.ui.controller; + +import javax.servlet.http.HttpServletRequest; + +import haflow.module.util.Md5Util; +import haflow.ui.helper.UserHelper; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +@Controller +public class MainLogonController { + private UserHelper userHelper; + + private UserHelper getUserHelper() { + return userHelper; + } + + @Autowired + private void setLogonHelper(UserHelper userHelper) { + this.userHelper = userHelper; + } + + @RequestMapping("registration") + public ModelAndView toRegister() { + return new ModelAndView("registration"); + } + + @RequestMapping(value = "/regiscommit", method = RequestMethod.POST) + public String register(RedirectAttributes redirectAttributes, + @RequestParam("username") String username, + @RequestParam("password") String password, + @RequestParam("email") String email,@RequestParam("mora") String mora) { + + password=Md5Util.getMd5Hex(password); + if (this.getUserHelper().saveUser(username, password,email, mora)) { + //System.out.println("successful return main"); + redirectAttributes.addFlashAttribute("message", "עɹ"); + return "redirect:/"; + + } else { + redirectAttributes.addFlashAttribute("message", "ûѴ"); + return "redirect:/registration"; + } + } + @RequestMapping(value="/quit") + public String quit(RedirectAttributes redirectAttributes,HttpServletRequest request){ + request.getSession().setAttribute("username",null); + request.getSession().setAttribute("userid",null); + request.getSession().setAttribute("scope", null); + return "redirect:/"; + } + + + @RequestMapping(value = "/logon", method = RequestMethod.POST) + public String login(RedirectAttributes redirectAttributes, + HttpServletRequest request, + @RequestParam("username") String username, + @RequestParam("password") String password) { + + if (username == "" || password == "") { + redirectAttributes.addFlashAttribute("message", "дû"); + return "redirect:/"; + } + password=Md5Util.getMd5Hex(password); + int userid=this.getUserHelper().validate(username, password, "main"); + if (userid!=-1) { + //System.out.println("logon enter!!!!!!"); + request.getSession().setAttribute("userid", userid); + request.getSession().setAttribute("username", username); + request.getSession().setAttribute("scope", 0); + + return "redirect:/main"; + + } else { + //System.out.println("logon failed!!!!!!"); + redirectAttributes.addFlashAttribute("message","û"); + return "redirect:/"; + } + } + + @RequestMapping(value = "/main") + public ModelAndView post(HttpServletRequest request) { + //System.out.println("main enter!!!!!"); + boolean flag = UserHelper.isUserLogon(request,0); + if(flag){ + ModelAndView main=new ModelAndView("main"); + main.addObject("username", request.getSession().getAttribute("username")); + return main; + } + else{ + ModelAndView mav=new ModelAndView("logon"); + mav.addObject("message","дû룡"); + return mav; + } + } + +} \ No newline at end of file diff --git a/src/main/java/haflow/ui/controller/UserController.java b/src/main/java/haflow/ui/controller/UserController.java new file mode 100644 index 0000000..524e1b4 --- /dev/null +++ b/src/main/java/haflow/ui/controller/UserController.java @@ -0,0 +1,82 @@ +package haflow.ui.controller; + +import javax.servlet.http.HttpServletRequest; + +import haflow.ui.helper.UserHelper; +import haflow.ui.model.SaveUserResultModel; +import haflow.ui.model.UserModel; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +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 org.springframework.web.servlet.mvc.support.RedirectAttributes; + +@Controller +@RequestMapping("/user") +public class UserController { + private UserHelper userHelper; + + public UserHelper getUserHelper() { + return userHelper; + } + + + @Autowired + public void setUserHelper(UserHelper userHelper) { + this.userHelper = userHelper; + } + + @RequestMapping(value = "/get/{userid}", method = RequestMethod.GET) + @ResponseBody + public UserModel get(@PathVariable int userid,HttpServletRequest request){ + + boolean flag=UserHelper.isUserLogon(request, 0); + + if(flag){ + + return this.getUserHelper().getUser(userid); + + } + return null; + + } + @RequestMapping(value = "/update/{userid}", method = RequestMethod.POST) + @ResponseBody + public SaveUserResultModel post(@PathVariable int userid,@RequestBody UserModel user,HttpServletRequest request){ + System.out.println(userid); + System.out.println("!!!!!!!!!!!success update"); + boolean flag=UserHelper.isUserLogon(request, 0); + + if(flag){ + + return this.getUserHelper().updateUser(userid,user); + + } + return null; + + } + @RequestMapping(value = "/remove/{userid}", method = RequestMethod.GET) + public String delete(@PathVariable int userid,HttpServletRequest request,RedirectAttributes redirectAttributes){ + boolean flag=UserHelper.isUserLogon(request, 1); + + if(flag){ + + if(this.getUserHelper().deleteUser(userid)){ + redirectAttributes.addFlashAttribute("message", "success removed a user!"); + return "redirect:/adminhome"; +// mav.addObject("message", "success!"); +// return mav; + } + } + redirectAttributes.addFlashAttribute("message", "failed removed a user!"); + return "redirect:/adminhome"; +// mav.addObject("message", "failed!"); +// return mav; + } + +} diff --git a/src/main/java/haflow/ui/helper/UserHelper.java b/src/main/java/haflow/ui/helper/UserHelper.java new file mode 100644 index 0000000..2928094 --- /dev/null +++ b/src/main/java/haflow/ui/helper/UserHelper.java @@ -0,0 +1,88 @@ +package haflow.ui.helper; + + + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import haflow.service.UserService; +import haflow.ui.model.SaveUserResultModel; +import haflow.ui.model.UserModel; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import haflow.dto.entity.MainUser; +@Component +public class UserHelper { + + private UserService userService; + private UserService getUserService() { + return userService; + } + + @Autowired + private void setUserService(UserService userService) { + this.userService = userService; + } + public UserModel getUser(int userid){ + MainUser user=this.getUserService().getUser(userid); + if(user==null) + return null; + UserModel userModel=new UserModel(); + userModel.setId(user.getId()); + userModel.setPassword(user.getPassword()); + userModel.setEmail(user.getEmail()); + userModel.setName(user.getName()); + userModel.setRealname(user.getRealname()); + userModel.setRole(user.getRole()); + userModel.setSpace(user.getSpace()); + userModel.setUsedspace(user.getUsedspace()); + return userModel; + + } + public SaveUserResultModel updateUser(int userid,UserModel user){ + boolean success=true; + String email=user.getEmail(); + success=this.getUserService().updateUserEmail(userid, email); + success=success&&this.getUserService().updateUser(userid, user.getPassword(), user.getRole(), user.getSpace(), user.getUsedspace(), user.getRealname()); + SaveUserResultModel result=new SaveUserResultModel(); + result.setSuccess(success); + result.setUserid(userid); + if(success){ + result.setMessage("success"); + } + else + result.setMessage("failed"); + return result; + + } + public boolean updateUserEmail(int userid,String email){ + return this.getUserService().updateUserEmail(userid, email); + } + public boolean deleteUser(int userid){ + return this.getUserService().deleteUser(userid); + } + public int validate(String username,String password,String mora){ + return this.getUserService().validate(username,password,mora); + } + public boolean saveUser(String username,String password,String email,String mora){ + return this.getUserService().saveUser(username,password,email,mora); + } + public List getAllUser(){ + return this.getUserService().getAllUser(); + + } + public static boolean isUserLogon(HttpServletRequest request,int authscope) { + String username = (String) request.getSession() + .getAttribute("username"); + Integer scope = (Integer) request.getSession() + .getAttribute("scope"); + + if (username != null&&scope!=null) + if(scope>=authscope) + return true; + return false; + } + +} diff --git a/src/main/java/haflow/ui/model/SaveUserResultModel.java b/src/main/java/haflow/ui/model/SaveUserResultModel.java new file mode 100644 index 0000000..ee531f7 --- /dev/null +++ b/src/main/java/haflow/ui/model/SaveUserResultModel.java @@ -0,0 +1,34 @@ +package haflow.ui.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name="saveUserResult") +public class SaveUserResultModel { + private boolean success; + private int userid; + private String message; + @XmlElement + public boolean isSuccess() { + return success; + } + public void setSuccess(boolean success) { + this.success = success; + } + @XmlElement + public int getUserid() { + return userid; + } + public void setUserid(int userid) { + this.userid = userid; + } + @XmlElement + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + +} diff --git a/src/main/java/haflow/ui/model/UserModel.java b/src/main/java/haflow/ui/model/UserModel.java new file mode 100644 index 0000000..172f0ba --- /dev/null +++ b/src/main/java/haflow/ui/model/UserModel.java @@ -0,0 +1,92 @@ +package haflow.ui.model; + +import java.util.Set; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +@XmlRootElement(name = "mainuser") +public class UserModel { + private int id; + private String name; + private String password; + private String email; + private int role; + //private String path; + private double space; + private double usedspace; + private String realname; + //private Set flows; + @XmlElement + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + @XmlElement + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + @XmlElement + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + @XmlElement + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + @XmlElement + public int getRole() { + return role; + } + public void setRole(int role) { + this.role = role; + } + /*@XmlElement + public String getPath() { + return path; + } + public void setPath(String path) { + this.path = path; + }*/ + @XmlElement + public double getSpace() { + return space; + } + public void setSpace(double space) { + this.space = space; + } + @XmlElement + public double getUsedspace() { + return usedspace; + } + public void setUsedspace(double usedspace) { + this.usedspace = usedspace; + } + @XmlElement + public String getRealname() { + return realname; + } + public void setRealname(String realname) { + this.realname = realname; + } +// @XmlElementWrapper(name = "flows") +// @XmlElement(name = "flow") +// public Set getFlows() { +// return flows; +// } +// public void setFlows(Set flows) { +// this.flows = flows; +// } + +} diff --git a/src/main/webapp/1.jsp b/src/main/webapp/1.jsp new file mode 100644 index 0000000..820d88a --- /dev/null +++ b/src/main/webapp/1.jsp @@ -0,0 +1,29 @@ + + + + + + + + + + + + +
+
+
+ Lorem ipsum and all around... +
+
+ Lorem ipsum and all around - second... +
+
+ Lorem ipsum and all around - last... +
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/adminhome.jsp b/src/main/webapp/WEB-INF/views/adminhome.jsp new file mode 100644 index 0000000..e9f4a69 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/adminhome.jsp @@ -0,0 +1,79 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" + pageEncoding="utf-8"%> + +<% + String path = request.getContextPath(); + String basePath = request.getScheme() + "://" + + request.getServerName() + ":" + request.getServerPort() + + path + "/"; + String username=request.getSession().getAttribute("username").toString(); + boolean flag; + Object message=request.getAttribute("message"); + if(request.getAttribute("message")!=null){ + + flag=true; + } + else{ + System.out.println("fa"); + flag=false; + } +%> + + + + + + + + + + + + +
+
+
+

Haflow Background

+
+
+
+ hello:<%=username %> | quit +
+ +
+
+
+
+
+ +
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/adminhome2.jsp b/src/main/webapp/WEB-INF/views/adminhome2.jsp new file mode 100644 index 0000000..a26299d --- /dev/null +++ b/src/main/webapp/WEB-INF/views/adminhome2.jsp @@ -0,0 +1,70 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" + pageEncoding="utf-8"%> + +<% + String path = request.getContextPath(); + String basePath = request.getScheme() + "://" + + request.getServerName() + ":" + request.getServerPort() + + path + "/"; + String username=request.getSession().getAttribute("username").toString(); +%> + + + + + + + + + + + +
+
+

Haflow

+

Background

+
hello: <%=username %>
+
+
+
+
+ +
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/adminhome3.jsp b/src/main/webapp/WEB-INF/views/adminhome3.jsp new file mode 100644 index 0000000..be5c880 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/adminhome3.jsp @@ -0,0 +1,109 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" + pageEncoding="utf-8"%> + +<% + String path = request.getContextPath(); + String basePath = request.getScheme() + "://" + + request.getServerName() + ":" + request.getServerPort() + + path + "/"; + String username=request.getSession().getAttribute("username").toString(); +%> + + + + + + + + + + + + +
+
+

Haflow Background

+
hello: <%=username %>
+
+
+
+ +
+
+ +
+ +
+
+ +
+
+

Haflow Background

+
hello:<%=username %> | quit
+ +
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + <%--
+
Haflow Background
+
hello: <%=username %>
+ +
+ +
+
+ +
+
+ +
+ +
--%> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/adminusermana.jsp b/src/main/webapp/WEB-INF/views/adminusermana.jsp new file mode 100644 index 0000000..aa17874 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/adminusermana.jsp @@ -0,0 +1,63 @@ +<%@page import="haflow.dto.entity.MainUser"%> +<%@page import="haflow.ui.helper.UserHelper"%> +<%@ page language="java" contentType="text/html; charset=utf-8" + pageEncoding="utf-8"%> + +<% + String path = request.getContextPath(); + String basePath = request.getScheme() + "://" + + request.getServerName() + ":" + request.getServerPort() + + path + "/"; +%> + + + +HA Flow UserManagement + + + +

Haflow Administration

+

User List

+ + + + + + + + + + + + <% if(request.getAttribute("list")!=null){ + java.util.List list=(java.util.List)request.getAttribute("list"); + + if(list!=null){ + for(MainUser user:list){ + %> + + + + + + + + + + + + <% + } + } + } + %> + +
User IdNameRoleSpaceUsedSpaceOperationOperation
<%=user.getId()%><%=user.getName()%><% System.out.print(user.getRole()); + if(user.getRole()==0) out.print("user"); + if(user.getRole()==1) out.print("admin"); + %><%=user.getSpace() %><%=user.getUsedspace() %>RemoveEdit
+ + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/registration.jsp b/src/main/webapp/WEB-INF/views/registration.jsp new file mode 100644 index 0000000..12b07a6 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/registration.jsp @@ -0,0 +1,70 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" + pageEncoding="utf-8"%> +<% + String path = request.getContextPath(); + String basePath = request.getScheme() + "://" + + request.getServerName() + ":" + request.getServerPort() + + path + "/"; +%> + + + + + + +Haflow Registration + + +
+
+

大数据分析服务平台

+
+
+
+ +
+
+ + +
+ 用户名: + +

+
+ 邮箱: + +

+
+ 输入密码: + +

+
+ 确认密码: + +

+
<%if(request.getAttribute("message")!=null) out.println(request.getAttribute("message")); %>
+
+ + +    + +
+
+ 已有账户?立即登陆 +
+ + + + + +
+
+
+
+ + + + + \ No newline at end of file diff --git a/src/main/webapp/script/adminusermana.js b/src/main/webapp/script/adminusermana.js new file mode 100644 index 0000000..51856c2 --- /dev/null +++ b/src/main/webapp/script/adminusermana.js @@ -0,0 +1,15 @@ + + +function openEdit(obj){ + var row = obj.parentNode.parentNode; + var userId = document.getElementById("userList").rows[row.rowIndex] + .cells[0].innerHTML; + +// window.open("user/get/"+scriptId,"_blank","width=400,height=300,toolbar=no,scrollbars"); +} +function openDel(obj){ + var row = obj.parentNode.parentNode; + var scriptId = document.getElementById("userList").rows[row.rowIndex] + .cells[0].innerHTML; + window.open("user/remove/"+scriptId,"_blank","width=400,height=300,toolbar=no,scrollbars"); +} \ No newline at end of file diff --git a/src/main/webapp/script/logon.js b/src/main/webapp/script/logon.js new file mode 100644 index 0000000..f247a49 --- /dev/null +++ b/src/main/webapp/script/logon.js @@ -0,0 +1,50 @@ +function fun(){ + if(checkField()==true) + userlogon(); +} +function fun1(){ + if(checkField()==true) + adminlogon(); +} +function userlogon() +{ + + document.getElementById("form1").action="logon"; + document.getElementById("form1").submit(); +} + +function adminlogon() +{ + document.getElementById("form1").action="adminlogon"; + document.getElementById("form1").submit(); +} + +function checkField(){ + + var usernameValue = document.getElementById("username").value; + var passwordValue = document.getElementById("password").value; + usernameValue = usernameValue.replace(/\s/gi,""); + passwordValue = passwordValue.replace(/\s/gi,""); + if(usernameValue !== "" && passwordValue !== ""){ + return true; + }else if(usernameValue == "" && passwordValue == ""){ + + document.getElementById("errorSpan").innerHTML=""; + document.getElementById("error_username").innerHTML = "用户名不能为空!"; + document.getElementById("error_password").innerHTML = "密码不能为空!"; + + return false ; + }else if(usernameValue !== "" && passwordValue == ""){ + document.getElementById("errorSpan").innerHTML=""; + document.getElementById("password").focus() ; + document.getElementById("error_username").innerHTML = ""; + document.getElementById("error_password").innerHTML = "密码不能为空!"; + return false ; + }else if(passwordValue !== "" && usernameValue == ""){ + document.getElementById("errorSpan").innerHTML=""; + document.getElementById("username").focus() ; + document.getElementById("error_password").innerHTML = ""; + document.getElementById("error_username").innerHTML = "用户名不能为空!"; + return false ; + } +} diff --git a/src/main/webapp/script/registration.js b/src/main/webapp/script/registration.js new file mode 100644 index 0000000..2fa7f97 --- /dev/null +++ b/src/main/webapp/script/registration.js @@ -0,0 +1,125 @@ +function fun3(){ + if(checkAll()&&RePass()){ + + + document.getElementById("mora").value = "main"; + + document.getElementById("form2").submit(); + } + + +} +function fun4(){ +if(checkAll()&&RePass()){ + + document.getElementById("mora").value= "admin"; + + document.getElementById("form2").submit(); + } + +} +function checkAll(){ + if(checkPass()){ + if(form_validation('username')&form_validation('email')&form_validation('password')) + return true; + else + return false; + } + else + return false; +} +function RePass(){ + var retype_pwd = document.getElementsByName('password1')[0].value; + var input_pwd = document.getElementsByName('password')[0].value; + if(retype_pwd==input_pwd){ + return true; + } + else{ + document.getElementById("password1_err").innerHTML="两次密码不一致!"; + return false; + } + +} +//check null +function checkPass() { + + var null_flag=0; + var user_name = document.getElementsByName('username')[0].value; + var eml_msg=document.getElementsByName("email")[0].value; + var retype_pwd = document.getElementsByName('password1')[0].value; + var input_pwd = document.getElementsByName('password')[0].value; + + + if(user_name==""){ + document.getElementById("username_err").innerHTML="用户名不能为空!"; + document.getElementsByName('username')[0].value=""; + document.getElementsByName('username')[0].style.border="1px solid red"; + null_flag=1;} + + if(eml_msg==""){ + document.getElementById("email_err").innerHTML="邮箱不能为空!"; + document.getElementsByName('email')[0].value=""; + document.getElementsByName('email')[0].style.border="1px solid red"; + null_flag=1;} + if(input_pwd==""){ + + document.getElementById("password_err").innerHTML="密码不能为空!"; + document.getElementsByName('password')[0].value=""; + document.getElementsByName('password')[0].style.border="1px solid red"; + null_flag=1;} + + if(retype_pwd==""){ + document.getElementById("password1_err").innerHTML="密码不能为空!"; + document.getElementsByName('password1')[0].value=""; + document.getElementsByName('password1')[0].style.border="1px solid red"; + null_flag=1; + } + if((null_flag==0)) return true; + else return false; + } + +function clean() { + document.getElementsByName('username')[0].value=""; + document.getElementsByName('password')[0].value=""; + document.getElementsByName('email')[0].value=""; + document.getElementsByName('password1')[0].value=""; +} +//check form +function form_validation(name) { + var input_value = document.getElementsByName(name)[0].value; + var regx=null; + var err=null; + if(name=="username"){ + regx=/^[a-z0-9_-]{3,8}$/; + err="3-8位数字或字母!"; + } + if(name=="password"){ + regx=/^[a-z0-9_-]{4,18}$/; + err="4-18位数字或字母!"; + } + if (name == "email") { + regx = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/; + err = "请填写有效的邮箱地址!"; + } + if(!regx.test(input_value)){ + + var errmsg=name+"_err"; + + document.getElementById(errmsg).innerHTML = err; + + document.getElementsByName(name)[0].value=""; + document.getElementsByName(name)[0].style.border="1px solid red"; + + return false; + + } + else + { + return true; + + } +} + + + + From 2ff1551e0269e9ad99667a422d567ab24d7171c1 Mon Sep 17 00:00:00 2001 From: dawncx Date: Wed, 9 Oct 2013 11:23:33 +0800 Subject: [PATCH 3/3] chenxi --- WebContent/META-INF/MANIFEST.MF | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 WebContent/META-INF/MANIFEST.MF diff --git a/WebContent/META-INF/MANIFEST.MF b/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: +