detailsDOI2.html 3.29 KB
Newer Older
Maxime Chaillet's avatar
Maxime Chaillet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>details from DOI</title>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

<script type="text/javascript">
    
var connection= 	{
		json: "{\"plugin\":\"simple\",\"credentials\":[{\"username\":\"root\"}, {\"password\":\"root\"}]}"
				}

var mySessionId="";

$(document).ready(function() {
	console.log("Hello. The document is ready.");
	$("#doiRequestDiv").hide();
	$("#connectButton").click(function() {
	
		console.log("You clicked on Connection button");
		// From: http://learn.jquery.com/ajax/jquery-ajax-methods/
		// Using the core $.ajax() method
		$.ajax({
			// The URL for the request
			url: "https://linfalcon.esrf.fr:8181/icat/session",
			// The data to send (will be converted to a query string)
			data: connection,
			// Whether this is a POST or GET request
			type: "post",
			// The type of data we expect back
			//dataType : "text",
			dataType : "json",
			// Code to run if the request succeeds;
			// the response is passed to the function
			success: function( data ) {
				console.log("You received some data!");
				mySessionId = data.sessionId;
				$("#connectionState").html("Your session ID is " + data.sessionId);
				$("#doiRequestDiv").show();

			},
			// Code to run if the request fails
			error: function() {
		 		alert( "Sorry, there was a problem!" );
			}
		});
	});
	$("#getDoiButton").click(function() {
		console.log("getDoiButton clicked");
		var doiRequest = $("#doiId").val();
52
53
54
		var myDoiQuery = "select distinct dataCollection from DataCollection dataCollection" + 
			" where dataCollection.doi='" + doiRequest + "'" +
			" include dataCollection.parameters";
Maxime Chaillet's avatar
Maxime Chaillet committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
		
		
		$.ajax({
			// The URL for the request
			url: "https://linfalcon.esrf.fr:8181/icat/entityManager",
			// The data to send (will be converted to a query string)
			data: {
			sessionId: mySessionId,
			server : "https://linfalcon.esrf.fr:8181",
			query : myDoiQuery  
			},
			type: "GET",
			dataType : "json",
			success: function( data ) {
				console.log("The requested DOI was found !");
				// data contains an array
				receptionDOIInfo(data);
				
			},
			// Code to run if the request fails
			error: function() {
		 		alert( "Sorry, error while processing the DOI request !" );
			}
		});
	});
});

function receptionDOIInfo(data){
	if (data.length != 0)
	{
	var doiName = data[0].DataCollection.doi;
	var doiId = data[0].DataCollection.id;
	var title = data[0].DataCollection.parameters[0].stringValue;
	var mintedDate = data[0].DataCollection.parameters[1].dateTimeValue;
	var mintedBy = data[0].DataCollection.parameters[2].stringValue;

	$("#doiResultDiv").html(
			"Received Data : <BR/> " + 
			"doiName : " + doiName + " <BR/>" +
			"doiID : " + doiId + " <BR/>" + 
			"title : " + title + " <BR/>" + 
			"mintedDate : " + mintedDate + " <BR/>" + 
			"mintedBy : " + mintedBy + " <BR/>"
			);
	} else {
 		$("#doiResultDiv").html("Sorry, the DOI was not found !" );

	};
};
</script>

</head>
<body>
	<h1>Salut</h1>
	<p>Cliquer sur le bouton pour connexion sur ICAT server.</p>
	<button id="connectButton">Connexion</button>
	<div id="connectionState"></div>
	<div id="doiRequestDiv"> Enter the requested DOI : 
		<input type="text" id="doiId">
		<button id="getDoiButton"> Get it !</button>
	</div>
	<div id="doiResultDiv"> </div>
</body>
</html>