9 |
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
10 |
import org.springframework.web.bind.annotation.*;
|
11 |
11 |
|
|
12 |
import java.io.UnsupportedEncodingException;
|
|
13 |
import java.net.URLEncoder;
|
12 |
14 |
import java.util.ArrayList;
|
13 |
15 |
import java.util.List;
|
14 |
16 |
import java.util.Map;
|
... | ... | |
43 |
45 |
@PathVariable("categoryId") String categoryId,
|
44 |
46 |
@PathVariable("subcategoryId") String subcategoryId,
|
45 |
47 |
@PathVariable("sectionId") String sectionId,
|
46 |
|
@RequestBody Indicator indicator) {
|
|
48 |
@RequestBody Indicator indicator) throws UnsupportedEncodingException {
|
47 |
49 |
log.debug("save indicator");
|
48 |
50 |
log.debug("Name: "+indicator.getName() + " - Id: "+indicator.getId() + " - Stakeholder: "+stakeholderId + " - Topic: "+topicId + " - Category: "+categoryId+ " - SubCategory: "+subcategoryId + " - Section: "+sectionId);
|
49 |
51 |
|
... | ... | |
75 |
77 |
return indicator;
|
76 |
78 |
}
|
77 |
79 |
|
78 |
|
public void onSaveDefaultIndicator(Indicator indicator, String defaultSectionId) {
|
|
80 |
public void onSaveDefaultIndicator(Indicator indicator, String defaultSectionId) throws UnsupportedEncodingException {
|
79 |
81 |
log.debug("On save default indicator");
|
80 |
82 |
|
81 |
83 |
// new indicator in default profile - add it on profiles of the same type
|
... | ... | |
98 |
100 |
}
|
99 |
101 |
}
|
100 |
102 |
|
101 |
|
public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder) {
|
|
103 |
public void onUpdateDefaultIndicator(Indicator indicator, Stakeholder stakeholder) throws UnsupportedEncodingException {
|
102 |
104 |
log.debug("On update default indicator");
|
103 |
105 |
|
104 |
106 |
// indicator already exists - check if changed and update all indicators based on it
|
... | ... | |
165 |
167 |
}
|
166 |
168 |
}
|
167 |
169 |
|
168 |
|
public void parameterMapping(IndicatorPath indicatorPath, Stakeholder stakeholder) {
|
169 |
|
if (indicatorPath.getParameters().containsKey("funder_name")) {
|
170 |
|
indicatorPath.getParameters().put("funder_name", stakeholder.getIndex_name());
|
171 |
|
} else if (indicatorPath.getParameters().containsKey("fsn")) {
|
172 |
|
indicatorPath.getParameters().put("fsn", stakeholder.getIndex_name().toLowerCase());
|
173 |
|
} else if (indicatorPath.getParameters().containsKey("funder_id")) {
|
174 |
|
indicatorPath.getParameters().put("funder_id", stakeholder.getIndex_id());
|
|
170 |
public void parameterMapping(IndicatorPath indicatorPath, Stakeholder stakeholder) throws UnsupportedEncodingException {
|
|
171 |
if (indicatorPath.getParameters().containsKey("index_name")) {
|
|
172 |
indicatorPath.getParameters().put("index_name", stakeholder.getIndex_name());
|
|
173 |
} else if (indicatorPath.getParameters().containsKey("index_shortName")) {
|
|
174 |
indicatorPath.getParameters().put("index_shortName", stakeholder.getIndex_name().toLowerCase());
|
|
175 |
} else if (indicatorPath.getParameters().containsKey("index_id")) {
|
|
176 |
indicatorPath.getParameters().put("index_id", stakeholder.getIndex_id());
|
175 |
177 |
}
|
|
178 |
|
|
179 |
|
|
180 |
String url = indicatorPath.getUrl();
|
|
181 |
String encoded_index_id = urlEncode(URLEncoder.encode(stakeholder.getIndex_id(), "UTF-8"));
|
|
182 |
url = url.replace("index_id", encoded_index_id);
|
|
183 |
String encoded_index_name = urlEncode(URLEncoder.encode(stakeholder.getIndex_name(), "UTF-8"));
|
|
184 |
url = url.replace("index_name", encoded_index_name);
|
|
185 |
String encoded_index_shortName = urlEncode(URLEncoder.encode(stakeholder.getIndex_shortName(), "UTF-8"));
|
|
186 |
url = url.replace("index_shortName", encoded_index_shortName);
|
|
187 |
indicatorPath.setUrl(url);
|
176 |
188 |
}
|
177 |
189 |
|
|
190 |
public String urlEncode(String encodedIndicatorPathField) {
|
|
191 |
String indicatorPathField = "";
|
|
192 |
|
|
193 |
for( int i=0; i<encodedIndicatorPathField.length(); i++ ){
|
|
194 |
String character = encodedIndicatorPathField.substring(i, i+1);
|
|
195 |
|
|
196 |
if(character.equals("+")) {
|
|
197 |
indicatorPathField = indicatorPathField.concat("%20");
|
|
198 |
} else if(character.equals("%")) {
|
|
199 |
//grab the hex in pairs
|
|
200 |
String output = encodedIndicatorPathField.substring(i+1, (i + 3));
|
|
201 |
|
|
202 |
if(output.equals("7E") || output.equals("27") || output.equals("28") || output.equals("29") || output.equals("21")) {
|
|
203 |
//convert hex to decimal
|
|
204 |
int decimal = Integer.parseInt(output, 16);
|
|
205 |
//convert the decimal to character
|
|
206 |
StringBuilder sb = new StringBuilder();
|
|
207 |
sb.append((char) decimal);
|
|
208 |
|
|
209 |
indicatorPathField = indicatorPathField.concat(sb.toString());
|
|
210 |
} else {
|
|
211 |
indicatorPathField = indicatorPathField.concat(character + output);
|
|
212 |
}
|
|
213 |
|
|
214 |
i += 2;
|
|
215 |
} else {
|
|
216 |
indicatorPathField = indicatorPathField.concat(character);
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
return indicatorPathField;
|
|
221 |
}
|
|
222 |
|
178 |
223 |
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/delete", method = RequestMethod.DELETE)
|
179 |
224 |
public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId,
|
180 |
225 |
@PathVariable("topicId") String topicId,
|
[Trunk | Monitor Service]:
1. SectionController.java: In 'saveSection()' method add in path index where section will be stored in subcategory (path: /{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save/{index}).
2. IndicatorController.java: In 'parameterMapping()' method add replacement in number url - add 'urlEncode()' helper method.