forked from hygieia/hygieia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectDataClientSetupImpl.java
executable file
·221 lines (201 loc) · 7.75 KB
/
ProjectDataClientSetupImpl.java
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
52
53
54
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*************************DA-BOARD-LICENSE-START*********************************
* Copyright 2014 CapitalOne, LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*************************DA-BOARD-LICENSE-END*********************************/
package com.capitalone.dashboard.client.project;
import com.atlassian.jira.rest.client.api.domain.BasicProject;
import com.capitalone.dashboard.client.DataClientSetup;
import com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl;
import com.capitalone.dashboard.model.Scope;
import com.capitalone.dashboard.repository.FeatureCollectorRepository;
import com.capitalone.dashboard.repository.ScopeRepository;
import com.capitalone.dashboard.util.Constants;
import com.capitalone.dashboard.util.DateUtil;
import com.capitalone.dashboard.util.FeatureSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* Implemented class which is extended by children to perform actual
* source-system queries as a service and to update the MongoDB in accordance.
*
* @author kfk884
*
*/
@Component
public abstract class ProjectDataClientSetupImpl implements DataClientSetup {
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectDataClientSetupImpl.class);
protected final FeatureSettings featureSettings;
protected final FeatureCollectorRepository featureCollectorRepository;
protected String todayDateISO;
protected Class<?> objClass;
protected String returnDate;
protected ScopeRepository projectRepo;
/**
* Constructs the feature data collection based on system settings.
*
* @param featureSettings
* Feature collector system settings
*/
public ProjectDataClientSetupImpl(FeatureSettings featureSettings,
ScopeRepository projectRepository, FeatureCollectorRepository featureCollectorRepository) {
super();
LOGGER.debug("Constructing data collection for the feature widget...");
this.featureSettings = featureSettings;
this.projectRepo = projectRepository;
this.featureCollectorRepository = featureCollectorRepository;
returnDate = featureSettings.getMasterStartDate();
setTodayDateISO(DateUtil.toISODateFormat(DateUtil.getTodayNoTime()));
}
/**
* This method is used to update the database with model defined in the
* collector model definitions.
*
* @see Story
*/
public void updateObjectInformation() {
LOGGER.info("Beginning collection of project data at " + Calendar.getInstance().getTime());
long start = System.nanoTime();
String jiraCredentials = this.featureSettings.getJiraCredentials();
String jiraBaseUrl = this.featureSettings.getJiraBaseUrl();
String proxyUri = null;
String proxyPort = null;
if (!this.featureSettings.getJiraProxyUrl().isEmpty()
&& (this.featureSettings.getJiraProxyPort() != null)) {
proxyUri = this.featureSettings.getJiraProxyUrl();
proxyPort = this.featureSettings.getJiraProxyPort();
}
JiraDataFactoryImpl jiraDataFactory = new JiraDataFactoryImpl(jiraCredentials, jiraBaseUrl,
proxyUri, proxyPort);
try {
List<BasicProject> rs = jiraDataFactory.getJiraTeams();
if ((rs != null) && (!rs.isEmpty())) {
updateMongoInfo(rs);
} else {
LOGGER.error("The response from Jira was blank or non existant - please check your property configurations");
}
} catch (Exception e) {
LOGGER.error("Unexpected error in Jira paging request of " + e.getClass().getName()
+ "\n[" + e.getMessage() + "]");
} finally {
jiraDataFactory.destroy();
}
double elapsedTime = (System.nanoTime() - start) / 1000000000.0;
LOGGER.info("Process took :" + elapsedTime + " seconds to update");
}
/**
* Generates and retrieves the local server time stamp in Unix Epoch format.
*
* @param unixTimeStamp
* The current millisecond value of since the Unix Epoch
* @return Unix Epoch-formatted time stamp for the current date/time
*/
public String getLocalTimeStampFromUnix(long unixTimeStamp) {
long unixSeconds = unixTimeStamp;
SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy 'at' h:mm a");
String date = sdf.format(unixSeconds);
LOGGER.debug(unixSeconds + "==>" + date);
return date;
}
/**
* Generates and retrieves the change date that occurs a minute prior to the
* specified change date in ISO format.
*
* @param changeDateISO
* A given change date in ISO format
* @return The ISO-formatted date/time stamp for a minute prior to the given
* change date
*/
public String getChangeDateMinutePrior(String changeDateISO) {
int priorMinutes = this.featureSettings.getScheduledPriorMin();
return DateUtil.toISODateRealTimeFormat(DateUtil.getDatePriorToMinutes(
DateUtil.fromISODateTimeFormat(changeDateISO), priorMinutes));
}
/**
* Generates and retrieves the sprint start date in ISO format.
*
* @return The ISO-formatted date/time stamp for the sprint start date
*/
public String getSprintBeginDateFilter() {
int priorDays = this.featureSettings.getSprintDays();
return DateUtil.toISODateRealTimeFormat(DateUtil.getDatePriorToNDays(
DateUtil.getDateNoTime(new Date()), priorDays));
}
/**
* Generates and retrieves the sprint end date in ISO format.
*
* @return The ISO-formatted date/time stamp for the sprint end date
*/
public String getSprintEndDateFilter() {
int afterDays = this.featureSettings.getSprintDays();
return DateUtil.toISODateRealTimeFormat(DateUtil.addDays(
DateUtil.getDateNoTime(new Date()), afterDays));
}
/**
* Generates and retrieves the difference between the sprint start date and
* the sprint end date in ISO format.
*
* @return The ISO-formatted date/time stamp for the sprint start date
*/
public String getSprintDeltaDateFilter() {
int priorDeltaDays = this.featureSettings.getSprintEndPrior();
return DateUtil.toISODateRealTimeFormat(DateUtil.getDatePriorToNDays(
DateUtil.getDateNoTime(new Date()), priorDeltaDays));
}
/**
* Accessor method for today's date in ISO format
*/
public String getTodayDateISO() {
return todayDateISO;
}
/**
* Mutator method for setting today's date in ISO format
*/
public void setTodayDateISO(String todayDateISO) {
this.todayDateISO = todayDateISO;
}
/**
* Retrieves the maximum change date for a given query.
*
* @return A list object of the maximum change date
*/
public String getMaxChangeDate() {
String data = null;
try {
List<Scope> response = projectRepo
.findTopByCollectorIdAndChangeDateGreaterThanOrderByChangeDateDesc(
featureCollectorRepository.findByName(Constants.JIRA).getId(),
featureSettings.getDeltaStartDate());
if ((response != null) && !response.isEmpty()) {
data = response.get(0).getChangeDate();
}
} catch (Exception e) {
LOGGER.error("There was a problem retrieving or parsing data from the local repository while retrieving a max change date\nReturning null");
}
return data;
}
/**
* Abstract method required by children methods to update the MongoDB with a
* JSONArray received from the source system back-end.
*
* @param currentPagedJiraRs
* A list response of Jira issues from the source system
* @return
*/
protected abstract void updateMongoInfo(List<BasicProject> currentPagedJiraRs);
}