Revize 5129e35c
Přidáno uživatelem stepanekp před asi 3 roky(ů)
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java | ||
---|---|---|
14 | 14 |
import org.slf4j.Logger; |
15 | 15 |
import org.slf4j.LoggerFactory; |
16 | 16 |
import org.springframework.beans.factory.annotation.Autowired; |
17 |
import org.springframework.core.io.FileSystemResource; |
|
18 | 17 |
import org.springframework.http.HttpStatus; |
19 | 18 |
import org.springframework.http.ResponseEntity; |
20 | 19 |
import org.springframework.stereotype.Controller; |
... | ... | |
330 | 329 |
|
331 | 330 |
AntiPattern antiPattern = antiPatternService.antiPatternToModel(antiPatternService.getAntiPatternById(id)); |
332 | 331 |
|
333 |
String thePath = new FileSystemResource("").getFile().getAbsolutePath() + "\\src\\main\\webapp\\operationalizations\\" + antiPattern.getName() + ".html"; |
|
334 |
|
|
332 |
String thePath = antiPatternService.getOperationalizationFilePath(antiPattern.getName()); |
|
335 | 333 |
try { |
336 | 334 |
Jsoup.clean(innerText, Safelist.basic()); // xss attack prevention |
337 | 335 |
BufferedWriter writer = new BufferedWriter(new FileWriter(thePath)); |
... | ... | |
352 | 350 |
*/ |
353 | 351 |
@GetMapping("/operationalizations/images/{imageName}") |
354 | 352 |
public @ResponseBody byte[] imageGet(@PathVariable String imageName) throws Exception { |
355 |
File f = new File(new FileSystemResource("").getFile().getAbsolutePath() + "\\src\\main\\webapp\\operationalizations\\images\\" + imageName);
|
|
353 |
File f = new File(antiPatternService.getOperationalizationImageFilePath(imageName));
|
|
356 | 354 |
return Files.readAllBytes(f.toPath()); |
357 | 355 |
} |
358 | 356 |
|
... | ... | |
367 | 365 |
|
368 | 366 |
String fileName = file.getOriginalFilename(); |
369 | 367 |
|
370 |
if(new File(new FileSystemResource("").getFile().getAbsolutePath() + "\\src\\main\\webapp\\operationalizations\\images\\" + fileName).isFile()){
|
|
368 |
if(new File(antiPatternService.getOperationalizationImageFilePath(fileName)).isFile()){
|
|
371 | 369 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
372 | 370 |
} |
373 | 371 |
|
374 | 372 |
try { |
375 |
file.transferTo( new File(new FileSystemResource("").getFile().getAbsolutePath() + "\\src\\main\\webapp\\operationalizations\\images\\" + fileName));
|
|
373 |
file.transferTo(new File(antiPatternService.getOperationalizationImageFilePath(fileName)));
|
|
376 | 374 |
} catch (Exception e) { |
377 | 375 |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
378 | 376 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java | ||
---|---|---|
16 | 16 |
import java.io.IOException; |
17 | 17 |
import java.io.InputStreamReader; |
18 | 18 |
import java.lang.reflect.InvocationTargetException; |
19 |
import java.net.MalformedURLException; |
|
19 | 20 |
import java.net.URL; |
20 | 21 |
import java.util.*; |
21 | 22 |
|
... | ... | |
27 | 28 |
|
28 | 29 |
private static final String QUERY_DIR = "/queries/"; |
29 | 30 |
private static final String AP_DIR = "/antipatterns/"; |
31 |
private static final String OPERATIONALIZATION_DIR = "/operationalizations/"; |
|
32 |
private static final String OPERATIONALIZATION_IMG_DIR = "/operationalizations/images/"; |
|
30 | 33 |
private final Logger LOGGER = LoggerFactory.getLogger(AntiPatternRepository.class); |
31 | 34 |
private ServletContext servletContext; |
32 | 35 |
private Map<Long, AntiPatternDetector> antiPatternDetectors; |
... | ... | |
229 | 232 |
return null; |
230 | 233 |
} |
231 | 234 |
|
235 |
public String getOperationalizationDirPathName(){ |
|
236 |
try { |
|
237 |
return servletContext.getResource(OPERATIONALIZATION_DIR).getFile(); |
|
238 |
} catch (Exception e) { |
|
239 |
e.printStackTrace(); |
|
240 |
} |
|
241 |
return null; |
|
242 |
} |
|
243 |
|
|
244 |
public String getOperationalizationImgDirFileName(){ |
|
245 |
try { |
|
246 |
return servletContext.getResource(OPERATIONALIZATION_IMG_DIR).getFile(); |
|
247 |
} catch (Exception e) { |
|
248 |
e.printStackTrace(); |
|
249 |
} |
|
250 |
return null; |
|
251 |
} |
|
252 |
|
|
232 | 253 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternService.java | ||
---|---|---|
43 | 43 |
* @return Description of the anti-pattern |
44 | 44 |
*/ |
45 | 45 |
String getDescriptionFromCatalogue(long id); |
46 |
|
|
47 |
String getOperationalizationFilePath(String antiPatternName); |
|
48 |
|
|
49 |
String getOperationalizationImageFilePath(String imageName); |
|
46 | 50 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternServiceImpl.java | ||
---|---|---|
7 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.CacheablesValues; |
8 | 8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Threshold; |
9 | 9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult; |
10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.Percentage; |
|
11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveFloat; |
|
12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveInteger; |
|
13 | 10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository; |
14 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.JsonParser; |
|
15 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils; |
|
16 | 11 |
import org.jsoup.Jsoup; |
17 | 12 |
import org.springframework.beans.factory.annotation.Autowired; |
18 |
import org.springframework.core.io.FileSystemResource; |
|
19 | 13 |
import org.springframework.stereotype.Service; |
20 | 14 |
|
21 |
import java.io.IOException; |
|
22 |
import java.nio.file.Files; |
|
23 |
import java.nio.file.Paths; |
|
24 | 15 |
import java.util.*; |
25 | 16 |
|
26 | 17 |
|
... | ... | |
173 | 164 |
|
174 | 165 |
return resultDescription.trim(); |
175 | 166 |
} |
167 |
|
|
168 |
@Override |
|
169 |
public String getOperationalizationFilePath(String antiPatternName){ |
|
170 |
return antiPatternRepository.getOperationalizationDirPathName() + antiPatternName + ".html"; |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public String getOperationalizationImageFilePath(String imageName){ |
|
175 |
return antiPatternRepository.getOperationalizationImgDirFileName() + imageName; |
|
176 |
} |
|
176 | 177 |
} |
Také k dispozici: Unified diff
Paths to external files edited