forked from hygieia/hygieia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectDataClientImpl.java
executable file
·156 lines (133 loc) · 4.91 KB
/
ProjectDataClientImpl.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
package com.capitalone.dashboard.client.project;
import com.atlassian.jira.rest.client.api.domain.BasicProject;
import com.capitalone.dashboard.model.Scope;
import com.capitalone.dashboard.repository.FeatureCollectorRepository;
import com.capitalone.dashboard.repository.ScopeRepository;
import com.capitalone.dashboard.util.ClientUtil;
import com.capitalone.dashboard.util.Constants;
import com.capitalone.dashboard.util.FeatureSettings;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Iterator;
import java.util.List;
/**
* This is the primary implemented/extended data collector for the feature
* collector. This will get data from the source system, but will grab the
* majority of needed data and aggregate it in a single, flat MongoDB collection
* for consumption.
*
* @author kfk884
*
*/
public class ProjectDataClientImpl extends ProjectDataClientSetupImpl implements ProjectDataClient {
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectDataClientImpl.class);
private final FeatureSettings featureSettings;
private final ScopeRepository projectRepo;
private final static ClientUtil TOOLS = new ClientUtil();
/**
* Extends the constructor from the super class.
*
* @param teamRepository
*/
public ProjectDataClientImpl(FeatureSettings featureSettings,
ScopeRepository projectRepository, FeatureCollectorRepository featureCollectorRepository) {
super(featureSettings, projectRepository, featureCollectorRepository);
LOGGER.debug("Constructing data collection for the feature widget, project-level data...");
this.featureSettings = featureSettings;
this.projectRepo = projectRepository;
}
/**
* Updates the MongoDB with a JSONArray received from the source system
* back-end with story-based data.
*
* @param currentPagedJiraRs
* A list response of Jira issues from the source system
*/
@Override
protected void updateMongoInfo(List<BasicProject> currentPagedJiraRs) {
LOGGER.debug("Size of paged Jira response: ", currentPagedJiraRs.size());
if ((currentPagedJiraRs != null) && !(currentPagedJiraRs.isEmpty())) {
Iterator<BasicProject> globalResponseItr = currentPagedJiraRs.iterator();
while (globalResponseItr.hasNext()) {
try {
/*
* Initialize DOMs
*/
Scope scope = new Scope();
BasicProject jiraScope = globalResponseItr.next();
/*
* Removing any existing entities where they exist in the
* local DB store...
*/
@SuppressWarnings("unused")
boolean deleted = this.removeExistingEntity(TOOLS.sanitizeResponse(jiraScope
.getId()));
/*
* Project Data
*/
// collectorId
scope.setCollectorId(featureCollectorRepository.findByName(Constants.JIRA)
.getId());
// ID;
scope.setpId(TOOLS.sanitizeResponse(jiraScope.getId()));
// name;
scope.setName(TOOLS.sanitizeResponse(jiraScope.getName()));
// beginDate - does not exist for jira
scope.setBeginDate("");
// endDate - does not exist for jira
scope.setEndDate("");
// changeDate - does not exist for jira
scope.setChangeDate("");
// assetState - does not exist for jira
scope.setAssetState("Active");
// isDeleted - does not exist for jira
scope.setIsDeleted("False");
// path - does not exist for Jira
scope.setProjectPath(TOOLS.sanitizeResponse(jiraScope.getName()));
// Saving back to MongoDB
projectRepo.save(scope);
} catch (ArrayIndexOutOfBoundsException | IllegalArgumentException e) {
LOGGER.error(
"Unexpected error caused while mapping data from source system to local data store:\n"
+ e.getMessage() + " : " + e.getCause(), e);
}
}
}
}
/**
* Explicitly updates queries for the source system, and initiates the
* update to MongoDB from those calls.
*/
public void updateProjectInformation() {
super.objClass = Scope.class;
super.returnDate = this.featureSettings.getDeltaStartDate();
if (super.getMaxChangeDate() != null) {
super.returnDate = super.getMaxChangeDate();
}
super.returnDate = getChangeDateMinutePrior(super.returnDate);
updateObjectInformation();
}
/**
* Validates current entry and removes new entry if an older item exists in
* the repo
*
* @param A
* local repository item ID (not the precise mongoID)
*/
protected Boolean removeExistingEntity(String localId) {
boolean deleted = false;
try {
ObjectId tempEntId = projectRepo.getScopeIdById(localId).get(0).getId();
if (localId.equalsIgnoreCase(projectRepo.getScopeIdById(localId).get(0).getpId())) {
projectRepo.delete(tempEntId);
deleted = true;
}
} catch (IndexOutOfBoundsException ioobe) {
LOGGER.debug("Nothing matched the redundancy checking from the database", ioobe);
} catch (Exception e) {
LOGGER.error("There was a problem validating the redundancy of the data model", e);
}
return deleted;
}
}