use of com.searchcode.app.dao.Data in project searchcode-server by boyter.
the class DataServiceTest method testTestAddToPersistent.
public void testTestAddToPersistent() {
Data mockData = Mockito.mock(Data.class);
DataService dataService = new DataService(mockData);
when(mockData.getDataByName(Values.PERSISTENT_DELETE_QUEUE, "[]")).thenReturn("[]");
dataService.addToPersistentDelete("test");
verify(mockData, times(1)).saveData(any(), any());
}
use of com.searchcode.app.dao.Data in project searchcode-server by boyter.
the class StatsServiceTest method testIncrementSearchIntergerOverflow.
public void testIncrementSearchIntergerOverflow() {
Data dataMock = Mockito.mock(Data.class);
when(dataMock.getDataByName(Values.CACHE_TOTAL_SEARCH, "0")).thenReturn("" + Integer.MAX_VALUE);
StatsService statsService = new StatsService(dataMock);
statsService.incrementSearchCount();
verify(dataMock, times(1)).saveData(Values.CACHE_TOTAL_SEARCH, "1");
}
use of com.searchcode.app.dao.Data in project searchcode-server by boyter.
the class StatsServiceTest method testIncrementSearchCountTwo.
public void testIncrementSearchCountTwo() {
Data dataMock = Mockito.mock(Data.class);
when(dataMock.getDataByName(Values.CACHE_TOTAL_SEARCH, "0")).thenReturn("100");
StatsService statsService = new StatsService(dataMock);
statsService.incrementSearchCount();
verify(dataMock, times(1)).saveData(Values.CACHE_TOTAL_SEARCH, "101");
}
use of com.searchcode.app.dao.Data in project searchcode-server by boyter.
the class App method preStart.
/**
* Called on startup to run all the DAO object table creation/migration logic. Slight overhead using this technique.
* TODO Do the migrations inside the sqlite database so the application does not need to
*/
public static void preStart() {
// Database migrations
Data data = Singleton.getData();
Repo repo = Singleton.getRepo();
Api api = Singleton.getApi();
data.createTableIfMissing();
api.createTableIfMissing();
repo.createTableIfMissing();
repo.addSourceToTable();
repo.addBranchToTable();
repo.addDataToTable();
}
use of com.searchcode.app.dao.Data in project searchcode-server by boyter.
the class CodeRouteService method getCode.
public Map<String, Object> getCode(Request request, Response response) {
Map<String, Object> map = new HashMap<>();
Repo repo = Singleton.getRepo();
Data data = Singleton.getData();
SearchcodeLib scl = Singleton.getSearchcodeLib(data);
OWASPClassifier owaspClassifier = new OWASPClassifier();
Cocomo2 coco = new Cocomo2();
String codeId = request.params(":codeid");
CodeResult codeResult = this.codeSearcher.getByCodeId(codeId);
if (codeResult == null) {
response.redirect("/404/");
halt();
}
List<String> codeLines = codeResult.code;
StringBuilder code = new StringBuilder();
StringBuilder lineNos = new StringBuilder();
String padStr = "";
for (int total = codeLines.size() / 10; total > 0; total = total / 10) {
padStr += " ";
}
for (int i = 1, d = 10, len = codeLines.size(); i <= len; i++) {
if (i / d > 0) {
d *= 10;
// Del last char
padStr = padStr.substring(0, padStr.length() - 1);
}
code.append("<span id=\"").append(i).append("\"></span>").append(StringEscapeUtils.escapeHtml4(codeLines.get(i - 1))).append("\n");
lineNos.append(padStr).append("<a href=\"#").append(i).append("\">").append(i).append("</a>").append("\n");
}
List<OWASPMatchingResult> owaspResults = new ArrayList<OWASPMatchingResult>();
if (CommonRouteService.owaspAdvisoriesEnabled()) {
if (!codeResult.languageName.equals("Text") && !codeResult.languageName.equals("Unknown")) {
owaspResults = owaspClassifier.classifyCode(codeLines, codeResult.languageName);
}
}
int limit = Integer.parseInt(Properties.getProperties().getProperty(Values.HIGHLIGHT_LINE_LIMIT, Values.DEFAULT_HIGHLIGHT_LINE_LIMIT));
boolean highlight = Singleton.getHelpers().tryParseInt(codeResult.codeLines, "0") <= limit;
RepoResult repoResult = repo.getRepoByName(codeResult.repoName);
if (repoResult != null) {
map.put("source", repoResult.getSource());
}
map.put("fileName", codeResult.fileName);
// TODO fix this properly code path includes the repo name and should be removed
String codePath = codeResult.codePath;
if (codeResult.codePath.contains("/")) {
codePath = codeResult.codePath.substring(codeResult.codePath.indexOf('/'), codeResult.codePath.length());
}
if (!codePath.startsWith("/")) {
codePath = "/" + codePath;
}
map.put("codePath", codePath);
map.put("codeLength", codeResult.codeLines);
map.put("linenos", lineNos.toString());
map.put("languageName", codeResult.languageName);
map.put("md5Hash", codeResult.md5hash);
map.put("repoName", codeResult.repoName);
map.put("highlight", highlight);
map.put("repoLocation", codeResult.getRepoLocation());
map.put("codeValue", code.toString());
map.put("highligher", CommonRouteService.getSyntaxHighlighter());
map.put("codeOwner", codeResult.getCodeOwner());
map.put("owaspResults", owaspResults);
double estimatedEffort = coco.estimateEffort(scl.countFilteredLines(codeResult.getCode()));
int estimatedCost = (int) coco.estimateCost(estimatedEffort, CommonRouteService.getAverageSalary());
if (estimatedCost != 0 && !scl.languageCostIgnore(codeResult.getLanguageName())) {
map.put("estimatedCost", estimatedCost);
}
map.put("logoImage", CommonRouteService.getLogo());
map.put("isCommunity", App.ISCOMMUNITY);
map.put(Values.EMBED, Singleton.getData().getDataByName(Values.EMBED, Values.EMPTYSTRING));
return map;
}
Aggregations