use of org.icij.datashare.text.Project in project datashare by ICIJ.
the class DocumentResourceTest method test_get_document_source_with_good_mask.
@Test
public void test_get_document_source_with_good_mask() throws Exception {
File txtFile = new File(temp.getRoot(), "file.txt");
write(txtFile, "content");
when(indexer.get("local-datashare", "docId", "root")).thenReturn(createDoc("doc").with(txtFile.toPath()).build());
when(repository.getProject("local-datashare")).thenReturn(new Project("local-datashare", "*.*.*.*"));
get("/api/local-datashare/documents/src/docId?routing=root").should().respond(200);
when(repository.getProject("local-datashare")).thenReturn(new Project("local-datashare", "127.0.0.*"));
get("/api/local-datashare/documents/src/docId?routing=root").should().respond(200);
}
use of org.icij.datashare.text.Project in project datashare by ICIJ.
the class ProjectResourceTest method test_is_allowed.
@Test
public void test_is_allowed() {
when(repository.getProject("projectId")).thenReturn(new Project("projectId", "127.0.0.1"));
get("/api/project/isDownloadAllowed/projectId").should().respond(200);
}
use of org.icij.datashare.text.Project in project datashare by ICIJ.
the class ProjectResourceTest method test_get_project.
@Test
public void test_get_project() {
when(repository.getProject("projectId")).thenReturn(new Project("projectId"));
get("/api/project/projectId").should().respond(200).contain("projectId");
}
use of org.icij.datashare.text.Project in project datashare by ICIJ.
the class DocumentResourceTest method test_get_document_source_with_bad_mask.
@Test
public void test_get_document_source_with_bad_mask() {
when(indexer.get("local-datashare", "docId", "root")).thenReturn(createDoc("doc").build());
when(repository.getProject("local-datashare")).thenReturn(new Project("local-datashare", "1.2.3.4"));
get("/api/local-datashare/documents/src/docId?routing=root").should().respond(403);
when(repository.getProject("local-datashare")).thenReturn(new Project("local-datashare", "127.0.1.*"));
get("/api/local-datashare/documents/src/docId?routing=root").should().respond(403);
}
use of org.icij.datashare.text.Project in project datashare by ICIJ.
the class BatchSearchResource method search.
/**
* Creates a new batch search. This is a multipart form with 8 fields :
* name, description, csvFile, published, fileTypes, paths, fuzziness, phrase_matches
*
* No matter the order. The name and csv file are mandatory else it will return 400 (bad request)
* Csv file must have under 60 000 lines else it will return 413 (payload too large)
* Queries with less than two characters are filtered
*
* To do so with bash you can create a text file like :
* ```
* --BOUNDARY
* Content-Disposition: form-data; name="name"
*
* my batch search
* --BOUNDARY
* Content-Disposition: form-data; name="description"
*
* search description
* --BOUNDARY
* Content-Disposition: form-data; name="csvFile"; filename="search.csv"
* Content-Type: text/csv
*
* Obama
* skype
* test
* query three
* --BOUNDARY--
* Content-Disposition: form-data; name="published"
*
* true
* --BOUNDARY--
* ```
* Then replace `\n` with `\r\n` with a sed like this:
*
* `sed -i 's/$/^M/g' ~/multipart.txt`
*
* Then make a curl request with this file :
* ```
* curl -i -XPOST localhost:8080/api/batch/search/prj -H 'Content-Type: multipart/form-data; boundary=BOUNDARY' --data-binary @/home/dev/multipart.txt
* ```
* @param projectId
* @param context : the request body
* @return 200 or 400 or 413
*/
@Post("/search/:project")
public Payload search(String projectId, Context context) throws Exception {
List<Part> parts = context.parts();
String name = fieldValue("name", parts);
String csv = fieldValue("csvFile", parts);
if (name == null || csv == null) {
return badRequest();
}
String description = fieldValue("description", parts);
boolean published = "true".equalsIgnoreCase(fieldValue("published", parts)) ? TRUE : FALSE;
List<String> fileTypes = fieldValues("fileTypes", parts);
List<String> paths = fieldValues("paths", parts);
Optional<Part> fuzzinessPart = parts.stream().filter(p -> "fuzziness".equals(p.name())).findAny();
int fuzziness = fuzzinessPart.isPresent() ? parseInt(fuzzinessPart.get().content()) : 0;
Optional<Part> phraseMatchesPart = parts.stream().filter(p -> "phrase_matches".equals(p.name())).findAny();
boolean phraseMatches = phraseMatchesPart.isPresent() ? parseBoolean(phraseMatchesPart.get().content()) : FALSE;
LinkedHashSet<String> queries = getQueries(csv).stream().map(query -> (phraseMatches && query.contains("\"")) ? query : sanitizeDoubleQuotesInQuery(query)).collect(Collectors.toCollection(LinkedHashSet::new));
if (queries.size() >= MAX_BATCH_SIZE)
return new Payload(413);
BatchSearch batchSearch = new BatchSearch(project(projectId), name, description, queries, (User) context.currentUser(), published, fileTypes, paths, fuzziness, phraseMatches);
boolean isSaved = batchSearchRepository.save(batchSearch);
if (isSaved)
batchSearchQueue.put(batchSearch.uuid);
return isSaved ? new Payload("application/json", batchSearch.uuid, 200) : badRequest();
}
Aggregations