Commit 86969623 authored by Chris Morris's avatar Chris Morris
Browse files

Delete bihhhh

parent 09d747a0
Loading
Loading
Loading
Loading
+25 −13
Original line number Diff line number Diff line
@@ -101,8 +101,8 @@ public class MLRestController {


            for (MultipartFile uploadfile : uploadfiles) {
                // uri = "http://192.168.56.200:8000/LATEST/documents?uri=/final-project/" + uploadfile.getOriginalFilename(); // this works, but doesn't work for the right datahase
                uri = "http://192.168.56.200:8000/LATEST/final-project?uri=/" + uploadfile.getOriginalFilename();           // provide the REST API URI
                uri = "http://192.168.56.200:8000/LATEST/documents?uri=/final-project/" + uploadfile.getOriginalFilename(); // this works, but doesn't work for the right datahase
                // uri = "http://192.168.56.200:8000/LATEST/final-project?uri=/" + uploadfile.getOriginalFilename();           // provide the REST API URI
                // convert the MultipartFile into a file
                File file = new File(uploadfile.getName());          // provide the file object
                file.createNewFile();
@@ -131,18 +131,30 @@ public class MLRestController {
    @DeleteMapping(value = "/restDeleteDoc")
    public @ResponseBody
    String restDeleteDoc(@RequestParam("doc_uri") String doc_uri) {
        HttpHeaders headers = new HttpHeaders();
        byte[] ba = null;
        try {
            CredentialsProvider provider = new BasicCredentialsProvider();
            Credentials credentials = new UsernamePasswordCredentials("admin", "admin");  // provide username & password
            provider.setCredentials(AuthScope.ANY, credentials);
            HttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
            String uri = "http://192.168.56.200:8000/LATEST/documents?uri=" + doc_uri;          // provide the REST API URI
            System.out.println("The URI for deleting the document is: " + uri);
            HttpDelete delete = new HttpDelete(uri);
            HttpResponse response = httpClient.execute(delete);

            String uri = "";       // provide the REST API URI
            // provide additional code that uses httpClient to complete deletion
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            response.getEntity().writeTo(baos);
            ba = baos.toByteArray();              // provide the code to get byte[]

        } catch (Exception e) {
            //-f, fail silently
            System.out.println(e);
            headers.set("Content-Type", response.getEntity().getContentType().getValue());

            String fileName = "";   // provide code to get fileName
            headers.set("Content-Disposition", "filename=" + fileName);

        } catch (IOException ex) {
            Logger.getLogger(MLRestController.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
        }
        return "Done ...";
    }