Skip to content

Commit 4ee0cae

Browse files
committed
2 parents b5a8c4d + 9379a0d commit 4ee0cae

4 files changed

Lines changed: 178 additions & 1 deletion

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.docusign.controller.monitor.examples;
2+
3+
import com.docusign.DSConfiguration;
4+
import com.docusign.common.WorkArguments;
5+
import com.docusign.controller.monitor.services.WebQueryEndpointService;
6+
import com.docusign.core.model.DoneExample;
7+
import com.docusign.core.model.Session;
8+
import com.docusign.core.model.User;
9+
import org.json.JSONObject;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.stereotype.Controller;
12+
import org.springframework.ui.ModelMap;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
15+
import javax.servlet.http.HttpServletResponse;
16+
import java.time.LocalDate;
17+
import java.time.format.DateTimeFormatter;
18+
19+
/**
20+
* Get monitoring data<br />
21+
* This example demonstrates how to get monitoring data from the Monitor API.
22+
*/
23+
@Controller
24+
@RequestMapping("/m002")
25+
public class M002WebQueryEndpoint extends AbstractMonitorController {
26+
27+
private static final String MODEL_START_DATE = "startDate";
28+
private static final String MODEL_END_DATE = "endDate";
29+
private static final int FROM_DATE_OFFSET_DAYS = 10;
30+
private static final int FROM_DATE_FORWARD_DAYS = 1;
31+
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
32+
private final Session session;
33+
private final User user;
34+
35+
@Autowired
36+
public M002WebQueryEndpoint(DSConfiguration config, Session session, User user) {
37+
super(config, "m002", "Query monitoring data with filters");
38+
this.session = session;
39+
this.user = user;
40+
}
41+
42+
@Override
43+
protected void onInitModel(WorkArguments args, ModelMap model) throws Exception {
44+
super.onInitModel(args, model);
45+
46+
LocalDate endDate = LocalDate.now().plusDays(FROM_DATE_FORWARD_DAYS);
47+
LocalDate startDate = LocalDate.now().minusDays(FROM_DATE_OFFSET_DAYS);
48+
49+
model.addAttribute(MODEL_START_DATE, DATE_FORMATTER.format(startDate));
50+
model.addAttribute(MODEL_END_DATE, DATE_FORMATTER.format(endDate));
51+
}
52+
53+
@Override
54+
protected Object doWork(WorkArguments args, ModelMap model, HttpServletResponse response) throws Exception {
55+
String accessToken = this.user.getAccessToken();
56+
57+
// Check, if you are using the JWT authentication
58+
// step 1 start
59+
accessToken = ensureUsageOfJWTToken(accessToken, this.session);
60+
String accountId = session.getAccountId();
61+
// step 1 end
62+
63+
JSONObject queryResult = WebQueryEndpointService.postWebQueryMethod(
64+
createDataSetApi(accessToken, this.session),
65+
accountId,
66+
args.getStartDate(),
67+
args.getEndDate()
68+
);
69+
70+
// Cleaning the data from unsupported symbols
71+
String queryResultCleaned = queryResult.toString().replaceAll("'", "");
72+
73+
// Process results
74+
DoneExample.createDefault(title)
75+
.withMessage("Results from DataSet:postWebQuery method:")
76+
.withJsonObject(queryResultCleaned)
77+
.addToModel(model);
78+
79+
return DONE_EXAMPLE_PAGE;
80+
}
81+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.docusign.controller.monitor.services;
2+
3+
import com.docusign.monitor.api.DataSetApi;
4+
import com.docusign.monitor.model.AggregateResult;
5+
import com.docusign.monitor.model.AggregateResultResult;
6+
import com.docusign.monitor.model.WebQuery;
7+
import com.docusign.monitor.client.ApiException;
8+
import org.json.JSONObject;
9+
10+
import java.util.List;
11+
12+
public final class WebQueryEndpointService {
13+
private static final String API_VERSION = "2.0";
14+
private static final String NAME_OF_DATASET = "monitor";
15+
public static JSONObject postWebQueryMethod(
16+
DataSetApi datasetApi,
17+
String accountId,
18+
String filterStartDate,
19+
String filterEndDate) throws ApiException {
20+
AggregateResult aggregateResult = datasetApi.postWebQuery(
21+
API_VERSION,
22+
NAME_OF_DATASET,
23+
prepareWebQueryOptions(accountId, filterStartDate, filterEndDate));
24+
25+
AggregateResultResult methodResult = null;
26+
List<AggregateResultResult> aggregateResultList = aggregateResult.getResult();
27+
28+
if (aggregateResultList != null && !aggregateResultList.isEmpty()) {
29+
methodResult = aggregateResultList.get(0);
30+
}
31+
32+
return new JSONObject(methodResult);
33+
}
34+
35+
private static WebQuery prepareWebQueryOptions(String accountId, String filterStartDate, String filterEndDate) {
36+
WebQuery webQuery = new WebQuery();
37+
webQuery.addFiltersItem(new Object(){
38+
public String FilterName = "Time";
39+
public String BeginTime = filterStartDate;
40+
public String EndTime = filterEndDate;
41+
});
42+
webQuery.addFiltersItem(new Object(){
43+
public String FilterName = "Has";
44+
public String ColumnName = "AccountId";
45+
public String Value = accountId;
46+
});
47+
webQuery.addAggregationsItem(new Object(){
48+
public String aggregationName = "Raw";
49+
public String limit = "1";
50+
public String[] orderby = new String[] { "Timestamp, desc" };
51+
});
52+
return webQuery;
53+
}
54+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2+
<jsp:include page="../../../partials/head.jsp"/>
3+
4+
<h4>2. Query monitoring data with filters</h4>
5+
<p>Demonstrates how to query an organization's data based on specified filters and aggregations.</p>
6+
<p>
7+
API method used:
8+
<a target='_blank' href="https://developers.docusign.com/docs/monitor-api/reference/monitor/dataset/postwebquery/">DataSet:postWebQuery</a>.
9+
</p>
10+
<p>
11+
View source file <a target='_blank' href='${sourceUrl}'>${sourceFile}</a> on GitHub.
12+
</p>
13+
14+
<p>
15+
Please select start and end dates.
16+
</p>
17+
18+
<form class="eg" action="" method="post" data-busy="form">
19+
20+
<div class="form-group">
21+
<label for="startDate">Start date</label>
22+
<input type="date" name="startDate" id="startDate"
23+
value="${startDate}" class="form-control" placeholder="yyyy-MM-dd">
24+
</div>
25+
<div class="form-group">
26+
<label for="endDate">End date</label>
27+
<input type="date" name="endDate" id="endDate"
28+
value="${endDate}" class="form-control" placeholder="yyyy-MM-dd">
29+
</div>
30+
<input type="hidden" name="_csrf" value="${csrfToken}">
31+
<button type="submit" class="btn btn-docu">Submit</button>
32+
</form>
33+
34+
<jsp:include page="../../../partials/foot.jsp"/>

src/main/webapp/WEB-INF/templates/views/pages/monitor/index.jsp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@
2626

2727
<h4 id='example001'>1. <a href='m001'>Get monitoring data</a></h4>
2828
<p> Demonstrates how to get and display all of your organization's monitoring data.</p>
29-
<p>API method used:
29+
<p>
30+
API method used:
3031
<a target ='_blank' rel='noopener noreferrer' href='https://developers.docusign.com/docs/monitor-api/reference/monitor/dataset/getstream/'>DataSet:getStream</a>
3132
</p>
33+
34+
<h4 id="example002">2. <a href="m002">Query monitoring data with filters</a></h4>
35+
<p>Demonstrates how to query an organization's data based on specified filters and aggregations.</p>
36+
<p>
37+
API method used:
38+
<a target='_blank' href="https://developers.docusign.com/docs/monitor-api/reference/monitor/dataset/postwebquery/">DataSet:postWebQuery</a>.
39+
</p>
3240
</div>
3341

3442
<!-- anchor-js is only for the index page -->

0 commit comments

Comments
 (0)