Skip to content

Commit

Permalink
setting up the basic logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sh0drun committed Feb 13, 2020
1 parent a2b9c80 commit 58bd4a1
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 84 deletions.
9 changes: 5 additions & 4 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand All @@ -30,19 +31,19 @@
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
Expand Down
68 changes: 0 additions & 68 deletions .factorypath

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./*.py
7 changes: 5 additions & 2 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=1.8
1 change: 1 addition & 0 deletions script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print 12+23
46 changes: 41 additions & 5 deletions src/main/java/com/oracle/challenge/ws/NoteBookWs.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.oracle.challenge.ws;

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import javax.validation.Valid;

import org.springframework.http.HttpStatus;
Expand All @@ -12,15 +18,45 @@
import com.oracle.challenge.model.NoteBookInput;
import com.oracle.challenge.model.NoteBookOutput;


@Controller
public class NoteBookWs {

@RequestMapping(value = "/execute", produces = { "application/json;charset=utf-8" }, consumes = {
"application/json;charset=utf-8" }, method = RequestMethod.POST)

@RequestMapping(value = "/execute",
produces = { "application/json;charset=utf-8" },
consumes = { "application/json;charset=utf-8" },
method = RequestMethod.POST)
ResponseEntity<NoteBookOutput> executeScript(@Valid @RequestBody NoteBookInput noteBookInput) {
NoteBookOutput noteBookOutput = new NoteBookOutput();
noteBookOutput.setResult("123"+noteBookInput.getCode());
try {
//script that will hold all inputs, and gets fed with new input when ever the endpoint is called
BufferedWriter out = new BufferedWriter(new FileWriter("script.py"));
out.write("print "+noteBookInput.getCode());
out.close();

Process process = null;

//script execution
if(System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0) {
process = Runtime.getRuntime().exec(String.format("cmd.exe /c python script.py"));
}
else {
//other os
}

//preparing result of script execution to be binded in the output
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = process.getInputStream().read(buffer)) != -1) {
result.write(buffer, 0, length);
}

noteBookOutput.setResult(result.toString().replaceAll("(\\r|\\n)", ""));
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}

return new ResponseEntity<NoteBookOutput>(noteBookOutput, HttpStatus.CREATED);
}

Expand Down
2 changes: 1 addition & 1 deletion target/classes/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Build-Jdk-Spec: 11
Implementation-Title: BackendNoteBookChallenge
Implementation-Version: 0.0.1-SNAPSHOT
Build-Jdk-Spec: 1.8
Created-By: Maven Integration for Eclipse

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Generated by Maven Integration for Eclipse
#Wed Feb 12 10:17:21 WET 2020
version=0.0.1-SNAPSHOT
groupId=com.oracle
#Wed Feb 12 23:16:14 CET 2020
m2e.projectLocation=D\:\\shadrunWorks\\oracleChallenge\\BackendNoteBookChallenge
m2e.projectName=BackendNoteBookChallenge
m2e.projectLocation=C\:\\Users\\arazik\\Downloads\\AnassGithub\\BackendNoteBookChallenge
groupId=com.oracle
artifactId=BackendNoteBookChallenge
version=0.0.1-SNAPSHOT
Binary file modified target/classes/com/oracle/challenge/ws/NoteBookWs.class
Binary file not shown.

0 comments on commit 58bd4a1

Please sign in to comment.