Commit 77ee4ed8 authored by MeesterWaffles's avatar MeesterWaffles
Browse files

endpoint and gui

parent 91947d4e
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="CompilerConfiguration">
    <annotationProcessing>
      <profile name="Maven default annotation processors profile" enabled="true">
        <sourceOutputDir name="target/generated-sources/annotations" />
        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
        <outputRelativeToContentRoot value="true" />
        <module name="Java_MarkLogic_Template" />
      </profile>
    </annotationProcessing>
    <bytecodeTargetLevel>
      <module name="Java_MarkLogic_Template" target="1.5" />
    </bytecodeTargetLevel>
  </component>
</project>
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="MavenProjectsManager">
    <option name="originalFiles">
      <list>
        <option value="$PROJECT_DIR$/pom.xml" />
      </list>
    </option>
  </component>
  <component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -49,6 +49,10 @@
            <version>2.4</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.marklogic</groupId>
            <artifactId>marklogic-client-api</artifactId>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
+32 −22
Original line number Diff line number Diff line
@@ -88,8 +88,10 @@ public class MLRestController {

    @PostMapping(value = "/restCreateDoc")
    public @ResponseBody
    String restCreateDoc(@RequestParam("files") MultipartFile[] uploadfiles) {
        try {
    String restCreateDoc(@RequestParam("files") MultipartFile[] uploadfiles)
    {
        try
        {
            CredentialsProvider provider = new BasicCredentialsProvider();
            Credentials credentials = new UsernamePasswordCredentials("admin", "admin");
            provider.setCredentials(AuthScope.ANY, credentials);
@@ -97,8 +99,8 @@ public class MLRestController {

            String uri = "";


            for (MultipartFile uploadfile : uploadfiles) {
            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
                // convert the MultipartFile into a file
@@ -114,24 +116,22 @@ public class MLRestController {
                HttpResponse response = httpClient.execute(put);
                System.out.println(response);
            }
        } catch (Exception e) {
            //-f, fail silently
            System.out.println(e);
        }
        catch (Exception e) { System.out.println(e); }
        return "Done ...";
    }

    @GetMapping(value = "/restDeleteDocShow")
    public String restDeleteDocShow() {
        return "restDeleteDoc";
    }
    public String restDeleteDocShow() { return "restDeleteDoc"; }

    @DeleteMapping(value = "/restDeleteDoc")
    public @ResponseBody
    String restDeleteDoc(@RequestParam("doc_uri") String doc_uri) {
    String restDeleteDoc(@RequestParam("doc_uri") String doc_uri)
    {
        HttpHeaders headers = new HttpHeaders();
        byte[] ba = null;
        try {
        try
        {
            CredentialsProvider provider = new BasicCredentialsProvider();
            Credentials credentials = new UsernamePasswordCredentials("admin", "admin");  // provide username & password
            provider.setCredentials(AuthScope.ANY, credentials);
@@ -149,8 +149,10 @@ public class MLRestController {

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

        } catch (IOException ex) {
        catch (IOException ex)
        {
            Logger.getLogger(MLRestController.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
        }
@@ -158,17 +160,22 @@ public class MLRestController {
    }

    @GetMapping(value = "/restQueryDocShow")
    public String restQueryDocShow() {
        return "restQueryDoc";
    public String restQueryDocShow() { return "restQueryDoc"; }

    @PostMapping(value = "/restCTSQueryDocShow")
    public ResponseEntity<ArrayList<ConfidenceFitness>> restQueryCTSDocShow(@RequestParam("cts_query_string") String cts_query_string)
    {
    }

    @GetMapping(value = "/restQueryDoc", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<ArrayList<ConfidenceFitness>> restQueryDoc(@RequestParam("query_string") String query_string) {
    public ResponseEntity<ArrayList<ConfidenceFitness>> restQueryDoc(@RequestParam("query_string") String query_string)
    {
        byte[] ba = null;
        ArrayList<ConfidenceFitness> alcf = new ArrayList<>();
        query_string = query_string.replace(" ", "%20");  // a space is changed to the HTML code %20 to prevent error
        JsonNode actualObj = null;
        try {
        try
        {
            CredentialsProvider provider = new BasicCredentialsProvider();
            Credentials credentials = new UsernamePasswordCredentials("admin", "admin");  // provide username & password
            provider.setCredentials(AuthScope.ANY, credentials);
@@ -192,9 +199,11 @@ public class MLRestController {
            ObjectMapper mapper = new ObjectMapper();
            actualObj = mapper.readTree(content);

            if (actualObj.get("results") != null) {
            if (actualObj.get("results") != null)
            {
                JsonNode doc_array = actualObj.get("results");
                for (JsonNode jn : doc_array) {
                for (JsonNode jn : doc_array)
                {
                    ConfidenceFitness cf = new ConfidenceFitness();
                    cf.setUri(jn.get("uri").asText());
                    // provide code to complete the content for the cf object
@@ -204,10 +213,11 @@ public class MLRestController {
                    alcf.add(cf);
                }
            }
        } catch (IOException | URISyntaxException ex) {
        }
        catch (IOException | URISyntaxException ex)
        {
            Logger.getLogger(MLRestController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ResponseEntity.accepted().body(alcf);
    }

}
 No newline at end of file
+9 −1
Original line number Diff line number Diff line
@@ -56,6 +56,14 @@ and open the template in the editor.
                        <a href="/restQueryDocShow">restQueryDoc (All file types)</a>
                    </td>
                </tr>
                <tr>
                    <td>
                        CTSqueryJSON
                    </td>
                    <td>
                        <a href="/restCTSQueryDocShow">restCTSQueryDoc (All file types)</a>
                    </td>
                </tr>
            </table>
        </div>
        <script src="/js/jquery-1.12.4.js"></script>
Loading