Project

General

Profile

« Previous | Next » 

Revision 46675

wfs ui

View differences:

modules/dnet-springboot-apps/trunk/dnet-administration-uis/src/main/java/eu/dnetlib/administration/uis/modules/workflows/WorkflowsModule.java
9 9
import javax.servlet.http.HttpServletRequest;
10 10

  
11 11
import org.apache.commons.lang3.StringUtils;
12
import org.apache.commons.lang3.math.NumberUtils;
12 13
import org.apache.commons.logging.Log;
13 14
import org.apache.commons.logging.LogFactory;
14 15
import org.dom4j.Document;
16
import org.dom4j.Element;
15 17
import org.dom4j.Node;
16 18
import org.dom4j.io.SAXReader;
17 19
import org.springframework.beans.factory.annotation.Autowired;
18 20
import org.springframework.ui.ModelMap;
19 21
import org.springframework.web.bind.annotation.PathVariable;
22
import org.springframework.web.bind.annotation.RequestBody;
20 23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestMethod;
21 25
import org.springframework.web.bind.annotation.RequestParam;
22 26
import org.springframework.web.bind.annotation.RestController;
23 27

  
......
26 30
import eu.dnetlib.administration.uis.annotations.MenuGroup;
27 31
import eu.dnetlib.administration.uis.annotations.PermissionLevel;
28 32
import eu.dnetlib.administration.uis.modules.UIModule;
33
import eu.dnetlib.administration.uis.modules.workflows.objects.WorkflowNotificationInfo;
34
import eu.dnetlib.administration.uis.modules.workflows.objects.WorkflowUpdateInfo;
29 35
import eu.dnetlib.clients.dsManager.DsManagerClient;
36
import eu.dnetlib.clients.is.InformationServiceClient;
37
import eu.dnetlib.msro.workflows.NotificationCondition;
38
import eu.dnetlib.msro.workflows.StartMode;
39
import eu.dnetlib.msro.workflows.WorkflowsConstants;
30 40

  
31 41
@RestController
32 42
@RequestMapping("/ajax/wfs")
......
40 50
	private DsManagerClient dsClient;
41 51

  
42 52
	@Autowired
53
	private InformationServiceClient isClient;
54

  
55
	@Autowired
43 56
	private WorkflowsUIUtils wfUtils;
44 57

  
45 58
	@Override
......
50 63
		return wfUtils.listWorflowsForSection(section);
51 64
	}
52 65

  
66
	@RequestMapping(value = "workflowParams", method = RequestMethod.GET)
67
	public WorkflowUpdateInfo getWorkflowUpdateInfo(@RequestParam final String wfId) throws Exception {
68

  
69
		final String xml = isClient.getProfile(wfId);
70

  
71
		final Document doc = (new SAXReader()).read(new StringReader(xml));
72

  
73
		final WorkflowUpdateInfo info = new WorkflowUpdateInfo();
74
		info.setWfId(wfId);
75
		info.setMode(StartMode.valueOf(doc.valueOf("//CONFIGURATION/@start")));
76
		info.setPriority(NumberUtils.toInt(doc.valueOf("//WORKFLOW_PRIORITY"), WorkflowsConstants.DEFAULT_WF_PRIORITY));
77

  
78
		info.setScheduled("true".equalsIgnoreCase(doc.valueOf("//SCHEDULING/@enabled")));
79
		info.setCron(doc.valueOf("//SCHEDULING/CRON"));
80
		info.setInterval(NumberUtils.toInt(doc.valueOf("//SCHEDULING/MININTERVAL"), 120)); // Default: 120 minutes
81

  
82
		for (final Object o : doc.selectNodes("//NOTIFICATIONS/EMAIL")) {
83
			info.getNotifications().add(new WorkflowNotificationInfo(
84
					((Element) o).valueOf("@address"),
85
					((Element) o).valueOf("@messageProfileId"),
86
					NotificationCondition.valueOf(((Element) o).valueOf("@condition"))));
87
		}
88

  
89
		return info;
90
	}
91

  
92
	@RequestMapping(value = "workflowParams", method = RequestMethod.POST)
93
	public WorkflowUpdateInfo saveWorkflowUpdateInfo(@RequestParam final String wfId, @RequestBody final WorkflowUpdateInfo info) throws Exception {
94

  
95
		log.info("Updating workflow " + info.getWfId());
96

  
97
		final String xml = isClient.getProfile(info.getWfId());
98

  
99
		final Document doc = new SAXReader().read(new StringReader(xml));
100

  
101
		doc.selectSingleNode("//CONFIGURATION/@start").setText(info.getMode().toString());
102

  
103
		final Element notificationsNode = (Element) doc.selectSingleNode("//NOTIFICATIONS");
104
		notificationsNode.clearContent();
105
		if (info.getNotifications() != null) {
106
			for (final WorkflowNotificationInfo n : info.getNotifications()) {
107
				final Element emailNode = notificationsNode.addElement("EMAIL");
108
				emailNode.addAttribute("address", n.getEmail());
109
				emailNode.addAttribute("messageProfileId", n.getMessageProfileId());
110
				emailNode.addAttribute("condition", n.getCondition().toString());
111
			}
112
		}
113

  
114
		doc.selectSingleNode("//WORKFLOW_PRIORITY").setText(Integer.toString(info.getPriority()));
115

  
116
		final Node node = doc.selectSingleNode("//SCHEDULING");
117
		((Element) node).addAttribute("enabled", Boolean.toString(info.isScheduled()));
118
		if (info.isScheduled()) {
119
			node.selectSingleNode("./CRON").setText(info.getCron() != null ? info.getCron() : "");
120
			node.selectSingleNode("./MININTERVAL").setText(Integer.toString(info.getInterval()));
121
		}
122
		isClient.updateProfile(wfId, doc.asXML());
123

  
124
		return info;
125
	}
126

  
53 127
	@RequestMapping("ds/compliance/override/{level}")
54 128
	public boolean updateRepoApiCompliance(@RequestParam final String dsId, @RequestParam final String ifaceId, @PathVariable final String level)
55 129
			throws Exception {
modules/dnet-springboot-apps/trunk/dnet-administration-uis/src/main/java/eu/dnetlib/administration/uis/modules/workflows/objects/WorkflowUpdateInfo.java
1
package eu.dnetlib.administration.uis.modules.workflows.objects;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import com.google.gson.Gson;
7

  
8
import eu.dnetlib.msro.workflows.StartMode;
9

  
10
public class WorkflowUpdateInfo implements Comparable<WorkflowUpdateInfo> {
11

  
12
	private String wfId;
13
	private StartMode mode;
14
	private int priority;
15
	private List<WorkflowNotificationInfo> notifications = new ArrayList<>();
16
	private boolean scheduled;
17
	private String cron;
18
	private int interval;
19

  
20
	public WorkflowUpdateInfo() {}
21

  
22
	public WorkflowUpdateInfo(final String wfId,
23
			final StartMode mode,
24
			final int priority,
25
			final List<WorkflowNotificationInfo> notifications,
26
			final boolean scheduled,
27
			final String cron,
28
			final int interval) {
29
		this.wfId = wfId;
30
		this.mode = mode;
31
		this.priority = priority;
32
		setNotifications(notifications);
33
		this.scheduled = scheduled;
34
		this.cron = cron;
35
		this.interval = interval;
36
	}
37

  
38
	public String getWfId() {
39
		return wfId;
40
	}
41

  
42
	public void setWfId(final String wfId) {
43
		this.wfId = wfId;
44
	}
45

  
46
	public StartMode getMode() {
47
		return mode;
48
	}
49

  
50
	public void setMode(final StartMode mode) {
51
		this.mode = mode;
52
	}
53

  
54
	public int getPriority() {
55
		return priority;
56
	}
57

  
58
	public void setPriority(final int priority) {
59
		this.priority = priority;
60
	}
61

  
62
	public List<WorkflowNotificationInfo> getNotifications() {
63
		return notifications;
64
	}
65

  
66
	public void setNotifications(final List<WorkflowNotificationInfo> notifications) {
67
		this.notifications = notifications;
68
	}
69

  
70
	public boolean isScheduled() {
71
		return scheduled;
72
	}
73

  
74
	public void setScheduled(final boolean scheduled) {
75
		this.scheduled = scheduled;
76
	}
77

  
78
	public String getCron() {
79
		return cron;
80
	}
81

  
82
	public void setCron(final String cron) {
83
		this.cron = cron;
84
	}
85

  
86
	public int getInterval() {
87
		return interval;
88
	}
89

  
90
	public void setInterval(final int interval) {
91
		this.interval = interval;
92
	}
93

  
94
	public String toJson() {
95
		return (new Gson()).toJson(this);
96
	}
97

  
98
	@Override
99
	public int compareTo(final WorkflowUpdateInfo o) {
100
		return getWfId().compareTo(o.getWfId());
101
	}
102

  
103
}
modules/dnet-springboot-apps/trunk/dnet-administration-uis/src/main/java/eu/dnetlib/administration/uis/modules/workflows/objects/WorkflowNotificationInfo.java
1
package eu.dnetlib.administration.uis.modules.workflows.objects;
2

  
3
import eu.dnetlib.msro.workflows.NotificationCondition;
4

  
5
public class WorkflowNotificationInfo {
6

  
7
	private String email;
8
	private String messageProfileId;
9
	private NotificationCondition condition;
10

  
11
	public WorkflowNotificationInfo() {}
12

  
13
	public WorkflowNotificationInfo(final String email, final String messageProfileId, final NotificationCondition condition) {
14
		this.email = email;
15
		this.messageProfileId = messageProfileId;
16
		this.condition = condition;
17
	}
18

  
19
	public String getEmail() {
20
		return email;
21
	}
22

  
23
	public void setEmail(final String email) {
24
		this.email = email;
25
	}
26

  
27
	public String getMessageProfileId() {
28
		return messageProfileId;
29
	}
30

  
31
	public void setMessageProfileId(final String messageProfileId) {
32
		this.messageProfileId = messageProfileId;
33
	}
34

  
35
	public NotificationCondition getCondition() {
36
		return condition;
37
	}
38

  
39
	public void setCondition(final NotificationCondition condition) {
40
		this.condition = condition;
41
	}
42

  
43
}
modules/dnet-springboot-apps/trunk/dnet-administration-uis/src/main/resources/static/js/wfs/wfs.js
60 60

  
61 61
			scope.reset = function () {
62 62
				showSpinner();
63
				$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
64
				$http.post('wf/update_workflow.get?wfId=' + scope.wfId).success(function (data) {
63
				$http.get('/ajax/wfs/workflowParams?wfId=' + scope.wfId).success(function (data) {
65 64
					hideSpinner();
66 65
					scope.wf = data;
67 66
				}).error(function (err) {
......
90 89

  
91 90
			scope.updateWf = function () {
92 91
				showSpinner();
93
				$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
94
				$http.post('wf/update_workflow.do', $.param({
95
					'json': JSON.stringify(scope.wf)
96
				})).success(function (data) {
92
				$http.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
93
				$http.post('/ajax/wfs/workflowParams', scope.wf).success(function (data) {
97 94
					hideSpinner();
98 95
					show_notification("info", 'Workflow updated !');
99 96
				}).error(function (err) {

Also available in: Unified diff