Skip to content

Commit

Permalink
Merge pull request #20 from bartoszgorka/rest_fix
Browse files Browse the repository at this point in the history
REST
  • Loading branch information
bartoszgorka authored Jan 7, 2018
2 parents f096a63 + c730074 commit 144a9ec
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.LinkedList;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Class used to analyze the scenario
Expand Down Expand Up @@ -29,7 +31,7 @@ public class ScenarioManager {
* @param scenario Long scenario text lines separated \n
*/
public ScenarioManager(String scenario) {
String[] scenarioLines = scenario.split("\n");
String[] scenarioLines = scenario.split("\\r\\n|\\n|\\r");

pullOutActors(scenarioLines[0]);
buildTreeStructure(scenarioLines);
Expand All @@ -40,7 +42,7 @@ public ScenarioManager(String scenario) {
* @param header Scenario header to fetch actors
*/
private void pullOutActors(String header) {
actors = header.split(",");
actors = header.split("\\s*,\\s*");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,97 +19,97 @@ public class ScenarioController {
/**
* Default error message in invalid nesting level request
*/
private static final String ERROR_MESSAGE = "Second param is not number.";
private static final String ERROR_MESSAGE = "Nesting level is not a integer!";

/**
* Get scenario with numeric
* @param text Scenario without numeric
* @param body Scenario without numeric
* @return Scenario with numeric
*/
@RequestMapping(value = "/numeric/{text}", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public String getScenarioWithNumeric(@PathVariable String text) {
logger.debug(text);
ScenarioManager scenarioManager = new ScenarioManager(text);
@RequestMapping(value = "/numeric", method = RequestMethod.POST, produces = "application/json")
public String getScenarioWithNumeric(@RequestBody String body) {
logger.debug(body);
ScenarioManager scenarioManager = new ScenarioManager(body);
return scenarioManager.getScenarioWithNumeration();
}

/**
* Get scenario in base form
* @param text Test of scenario
* @param body Test of scenario
* @return Scenario in base form
*/
@RequestMapping(value = "/{text}", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public String getScenario(@PathVariable String text) {
logger.debug(text);
ScenarioManager scenarioManager = new ScenarioManager(text);
@RequestMapping(value = "scenario", method = RequestMethod.POST, produces = "application/json")
public String getScenario(@RequestBody String body) {
logger.debug(body);
ScenarioManager scenarioManager = new ScenarioManager(body);
return scenarioManager.getScenario();
}

/**
* Scenario without actors
* @param text Scenario text
* @param body Scenario text
* @return Scenario without actors
*/
@RequestMapping(value = "/without_actors/{text}", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public String getScenarioWithoutActors(@PathVariable String text) {
logger.debug(text);
ScenarioManager scenarioManager = new ScenarioManager(text);
@RequestMapping(value = "/without_actors", method = RequestMethod.POST, produces = "application/json")
public String getScenarioWithoutActors(@RequestBody String body) {
logger.debug(body);
ScenarioManager scenarioManager = new ScenarioManager(body);
return scenarioManager.cutActorsFromScenario();
}

/**
* Count keywords in scenario
* @param text Scenario text
* @param body Scenario text
* @return Amount of keywords in scenario
*/
@RequestMapping(value = "/number_keywords/{text}", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public String getScenarioNumberKeyWords(@PathVariable String text) {
logger.debug(text);
ScenarioManager scenarioManager = new ScenarioManager(text);
@RequestMapping(value = "/number_keywords", method = RequestMethod.POST, produces = "application/json")
public String getScenarioNumberKeyWords(@RequestBody String body) {
logger.debug(body);
ScenarioManager scenarioManager = new ScenarioManager(body);
return Integer.toString(scenarioManager.countKeyWordsInScenario());
}

/**
* Count steps in scenario
* @param text Scenario text
* @param body Scenario text
* @return Amount of steps in scenario
*/
@RequestMapping(value = "/steps/{text}", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public String getScenarioSteps(@PathVariable String text) {
logger.debug(text);
ScenarioManager scenarioManager = new ScenarioManager(text);
@RequestMapping(value = "/steps", method = RequestMethod.POST, produces = "application/json")
public String getScenarioSteps(@RequestBody String body) {
logger.debug(body);
ScenarioManager scenarioManager = new ScenarioManager(body);
return Integer.toString(scenarioManager.countNumberOfScenarioSteps());
}

/**
* Check maximum nesting level in scenario
* @param text Scenario text
* @param body Scenario text
* @return Integer with maximum nesting level
*/
@RequestMapping(value = "/nesting/{text}", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public String getScenarioNesting(@PathVariable String text) {
logger.debug(text);
ScenarioManager scenarioManager = new ScenarioManager(text);
@RequestMapping(value = "/nesting", method = RequestMethod.POST, produces = "application/json")
public String getScenarioNesting(@RequestBody String body) {
logger.debug(body);
ScenarioManager scenarioManager = new ScenarioManager(body);
return Integer.toString(scenarioManager.countScenarioNesting());
}

/**
* Scenario to limit nesting level
* @param text Scenario text
* @param body Scenario text
* @param toLevel Nesting level limit
* @return Scenario with limit of nesting level
*/
@RequestMapping(value = "/level/{text}", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
public String getScenarioToLevel(@PathVariable String text, @RequestParam(value = "level", defaultValue = "1") String toLevel) {
logger.debug(text);
@RequestMapping(value = "/level", method = RequestMethod.POST, produces = "application/json")
public String getScenarioToLevel(@RequestBody String body, @RequestParam(value = "level", defaultValue = "1") String toLevel) {
logger.debug(body);
logger.debug(toLevel);
int level = 0;
try {
level = Integer.parseInt(toLevel);
} catch (NumberFormatException e) {
return ERROR_MESSAGE;
}
ScenarioManager scenarioManager = new ScenarioManager(text);
ScenarioManager scenarioManager = new ScenarioManager(body);
return scenarioManager.getScenario(level);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void getScenarioToLevel2Test(){
@Test
public void getScenarioToLevelIsNotNumberTest(){
String toLevel = "I am not number!";
String errorMessage = "Second param is not number.";
String errorMessage = "Nesting level is not a integer!";
assertEquals(errorMessage, scenarioController.getScenarioToLevel(messageToAPI, toLevel));
}

Expand Down
35 changes: 20 additions & 15 deletions GUI/src/main/java/put/io/black/java/gui/ScenarioGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.awt.*;
import java.util.logging.Logger;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

Expand Down Expand Up @@ -113,6 +116,7 @@ public void mouseClicked(MouseEvent e) {

/**
* Main function to run GUI.
*
* @param args for now args are for nothing.
*/
public static void main(String args[]) {
Expand All @@ -126,6 +130,7 @@ public static void main(String args[]) {

/**
* Function to send data
*
* @param scheme - scheme like http
* @param host - name of serwer
* @param port - connection port
Expand All @@ -145,8 +150,9 @@ private String sendRequest(String scheme, String host, String port, String sourc
URL url = new URL(uriComponents.toUriString());
logger.warning(url.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-Type", "application/json");

if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
Expand Down Expand Up @@ -175,52 +181,51 @@ private String sendRequest(String scheme, String host, String port, String sourc
}

{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}

// DO NOT EDIT OR ADD ANY CODE HERE!
// NO CALL!
private void $$$setupUI$$$() {
panelMain = new JPanel();
panelMain.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(10, 2, new Insets(10, 10, 10, 10), -1, -1));
panelMain.setLayout(new GridLayoutManager(10, 2, new Insets(10, 10, 10, 10), -1, -1));
inputLabel = new JLabel();
inputLabel.setText("Poniżej wpisz treść scenariusza.");
panelMain.add(inputLabel, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 2, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
panelMain.add(inputLabel, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
outputLabel = new JLabel();
outputLabel.setText("Poniżej zostanie wypisany wynik.");
panelMain.add(outputLabel, new com.intellij.uiDesigner.core.GridConstraints(5, 0, 1, 2, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
panelMain.add(outputLabel, new GridConstraints(5, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
getScenarioToXLevel = new JButton();
getScenarioToXLevel.setText("Pobierz scenariusz do określonego poziomu");
panelMain.add(getScenarioToXLevel, new com.intellij.uiDesigner.core.GridConstraints(9, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
panelMain.add(getScenarioToXLevel, new GridConstraints(9, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
getScenarioWithNumber = new JButton();
getScenarioWithNumber.setText("Pobierz scenariusz z numeracją");
panelMain.add(getScenarioWithNumber, new com.intellij.uiDesigner.core.GridConstraints(4, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
panelMain.add(getScenarioWithNumber, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
whichStepsNotStartFromActor = new JButton();
whichStepsNotStartFromActor.setText("Które kroki nie rozpoczynają się od aktora?");
panelMain.add(whichStepsNotStartFromActor, new com.intellij.uiDesigner.core.GridConstraints(3, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
panelMain.add(whichStepsNotStartFromActor, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
howManyStepsKeyWord = new JButton();
howManyStepsKeyWord.setText("Ile króków zawiera słowa kluczowe?");
panelMain.add(howManyStepsKeyWord, new com.intellij.uiDesigner.core.GridConstraints(2, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
panelMain.add(howManyStepsKeyWord, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
inputLevel = new JTextField();
inputLevel.setToolTipText("Wpisz liczbę poziomów");
panelMain.add(inputLevel, new com.intellij.uiDesigner.core.GridConstraints(8, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
panelMain.add(inputLevel, new GridConstraints(8, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
levelLabel = new JLabel();
levelLabel.setText("Wpisz liczbę poziomów:");
panelMain.add(levelLabel, new com.intellij.uiDesigner.core.GridConstraints(7, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
panelMain.add(levelLabel, new GridConstraints(7, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
inputFieldScroll = new JScrollPane();
panelMain.add(inputFieldScroll, new com.intellij.uiDesigner.core.GridConstraints(1, 0, 4, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, new Dimension(300, 200), new Dimension(300, 200), null, 0, false));
panelMain.add(inputFieldScroll, new GridConstraints(1, 0, 4, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, new Dimension(300, 200), new Dimension(300, 200), null, 0, false));
inputField = new JTextArea();
inputField.setLineWrap(false);
inputFieldScroll.setViewportView(inputField);
outputFieldScroll = new JScrollPane();
panelMain.add(outputFieldScroll, new com.intellij.uiDesigner.core.GridConstraints(6, 0, 4, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, new Dimension(300, 200), new Dimension(300, 200), null, 0, false));
panelMain.add(outputFieldScroll, new GridConstraints(6, 0, 4, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, new Dimension(300, 200), new Dimension(300, 200), null, 0, false));
outputField = new JTextArea();
outputField.setEditable(false);
outputFieldScroll.setViewportView(outputField);
howManyStepsScenario = new JButton();
howManyStepsScenario.setText("Ile kroków zawiera scenariusz?");
panelMain.add(howManyStepsScenario, new com.intellij.uiDesigner.core.GridConstraints(1, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
panelMain.add(howManyStepsScenario, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, 25), new Dimension(300, 25), new Dimension(300, 25), 0, false));
}

public JComponent $$$getRootComponent$$$() {
Expand Down

0 comments on commit 144a9ec

Please sign in to comment.