This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects

Resolve "Easy Access to ReadMe.md (and potentially other files)"

Files
3
@@ -9,9 +9,10 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.zip.ZipInputStream;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,8 +22,6 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import at.ac.uibk.gitsearch.repository.gitlab.GitLabRepository;
import at.ac.uibk.gitsearch.repository.search.MetaDataRepository;
@@ -184,57 +183,6 @@ public class SearchService {
}
}
/**
* temporary static test data.
*
* @param searchString just a string to add to testdata description.
* @return
*/
@SuppressWarnings("unused")
private SearchResultsDTO readTestResults(String searchString, long first, int length) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
mapper.findAndRegisterModules();
List<SearchResultDTO> loadedMetaData = new ArrayList<>();
for (String testFile : new String[] { "metaData1.yaml", "metaData2.yaml" }) {
log.debug("reading test data from {} ", testFile);
final File metaDataFile = new File("src/main/java/at/ac/uibk/gitsearch/service/testData/" + testFile);
try {
byte[] fileContent = FileCopyUtils.copyToByteArray(metaDataFile);
SearchResultDTO searchResultDTO = mapper.readValue(fileContent, SearchResultDTO.class);
loadedMetaData.add(searchResultDTO);
} catch (IOException e) {
log.error("Cannot read test search input from " + testFile, e);
}
}
List<SearchResultDTO> result = new ArrayList<>();
if (length > 0) {
int metadataPos = 0;
long recordNr = first;
// This loop is only used for testing to get more results.
for (int i = 0; i < 12; ++i) {
metadataPos = 0; // also for testing, remove later
while (metadataPos < length && metadataPos < loadedMetaData.size()) {
final SearchResultDTO loadedMetaDataRecord = new SearchResultDTO(loadedMetaData.get(metadataPos++));
if (loadedMetaDataRecord.toString().contains(searchString)) {
loadedMetaDataRecord.getMetadata()
.setTitle("#" + (recordNr + 1) + " " + loadedMetaDataRecord.getMetadata().getTitle());
result.add(loadedMetaDataRecord);
recordNr++;
log.debug("Added MetaData Record {}", loadedMetaData);
}
log.debug("{} does not contain {}", loadedMetaData, searchString);
}
}
}
return new SearchResultsDTO(result, NUM_TESTRESULTS, first);
}
public File exportExercise(long exerciseId) throws IOException {
try{
final GitLabApi gitLabApi = gitLabRepository.getGitLabApi(tokenProvider.getGitLabAccessInfo());