Skip to content

Commit

Permalink
Fix typo. Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
skrasovsky committed Aug 9, 2016
1 parent 35c3396 commit 3ffdbe6
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 44 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
*.iml
target/
goeuro.log
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# GoEuro

It is a console application, which allows to develop any kind of commands and execute them from comand line. Application contains
It is a console application, which allows to develop any kind of commands and execute them from command line. Application contains
only one command for the demonstration. If you need more commands you should extend library and develop your own commands.

What type of commands application allows to create? Any type.
Expand Down Expand Up @@ -42,7 +42,7 @@ public class GetLocationsByCityCSV extends APICommand implements Command {

@Override
protected void validateContext() {
// Add validation of api command context here. For example you need some requered parameters.
// Add validation of api command context here. For example you need some required parameters.
}
}
```
Expand Down Expand Up @@ -83,7 +83,7 @@ The available `-command` arguments:
```
- `-query-string <arg>` - HTTP request query string parameters. Support multiple arguments. Example:
```
-qs name1=valuename2=value2
-qs name1=value name2=value2
```
How to execute command:
Expand Down
Binary file modified goeuro.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private String getFileName() {
assertThat(getContext()).isNotNull();

String date = LocalDateTime.now()
.format(DateTimeFormatter.ofPattern(DATETIME_PATTERN)).toString();
.format(DateTimeFormatter.ofPattern(DATETIME_PATTERN));

return String.format("%s_locations_%s.csv", getContext().getPathParams().get(CITY_PARAM), date);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/goeuro/core/CommandContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CommandContainer {

private static final Logger LOGGER = LoggerFactory.getLogger(CommandContainer.class);

private Class<API> annotation = API.class;
private final Class<API> annotation = API.class;

@Autowired
private ApplicationContext context;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/goeuro/core/api/APICommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public abstract class APICommand {

private APICommandContext context;

public APICommandContext getContext() {
protected APICommandContext getContext() {
return context;
}

public String getBaseUrl() {
protected String getBaseUrl() {
return properties.baseUrl();
}

public String getApiVersion() {
protected String getApiVersion() {
return properties.apiVersion();
}

public String getDefaultLocale() {
protected String getDefaultLocale() {
return properties.defaultLocale();
}

Expand Down Expand Up @@ -169,7 +169,7 @@ private Header[] prepareHeaders() {
.entrySet()
.stream()
.map(h -> new BasicHeader(h.getKey(), h.getValue()))
.toArray(size -> new Header[size]);
.toArray(Header[]::new);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/goeuro/core/api/APICommandContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -162,10 +161,10 @@ private Map<String, String> parseParam(String[] params) {
}

paramMap = new HashMap<>(params.length, 1f);
for (int i = 0; i < params.length; i++) {
String[] param = params[i].split("=");
for (String p : params) {
String[] param = p.split("=");
if (param.length != 2) {
String message = message("Wrong format of the command line argument %s. It should be <name=value>.", params[i]);
String message = message("Wrong format of the command line argument %s. It should be <name=value>.", p);
error(message);
throw new CommandContextBuilderException(message);
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/com/goeuro/core/cmd/CMDOptionsContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ public CommandLine parse(String args[]) throws ParseException {
*/
public void printCMDHelp() {
HelpFormatter helpFormatter = new HelpFormatter();
StringBuilder helpBuilder = new StringBuilder();
helpBuilder.append(properties.helpUsage());
helpBuilder.append("\n");
helpBuilder.append(properties.helpExample());
helpBuilder.append("\n");
helpBuilder.append("\n");
helpFormatter.printHelp(helpBuilder.toString(), options);
helpFormatter.printHelp(properties.helpUsage() + "\n" + properties.helpExample() + "\n" + "\n", options);
}

private Option initListCommandOption() {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/goeuro/core/cmd/CMDQuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Random;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/goeuro/dto/BaseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class BaseDTO implements Serializable {

protected Long id;
private Long id;

public Long getId() {
return id;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/goeuro/model/Language.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.goeuro.model;

/**
* Created by krasovcheg on 16/07/16.
*/
public enum Language {

AA,
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/goeuro/service/csv/CSVService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.goeuro.service.csv;

import com.goeuro.core.CommandExecutor;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.io.IOUtils;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.FileWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ public class CustomConsoleFormatter extends Formatter {

@Override
public String format(LogRecord record) {
StringBuilder builder = new StringBuilder();
builder.append("\n");
builder.append("[GOEURO]# ");
builder.append(formatMessage(record));
return builder.toString();
return "\n" + "[GOEURO]# " + formatMessage(record);
}

public String getHead(Handler handler) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/cmd.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ cmd.api.command.help.title=GoEuro API Command Help:
cmd.api.command.help.template=\n\n Name: %s\n Description: %s\n Template: %s\n Allowed params: %s\n Example: %s

cmd.command.quit.byes=\
See you later! \n#\
Bye... \n#\
Come on, it is not so late. Take one more beer! \n#\
John Snow is still alive! Oops, sorry ... Bye! \n#\
Out of memory detected!!! ... Easy easy, it is a joke! Bye! \n
See you later!\n#\
Bye...\n#\
Come on, it is not so late. Take one more beer!\n#\
John Snow is still alive! Oops, sorry ... Bye!\n#\
Out of memory detected!!! ... Easy easy, it is a joke! Bye!\n
5 changes: 4 additions & 1 deletion src/test/java/com/goeuro/service/csv/CSVServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.List;

import static com.goeuro.service.logger.CustomConsoleLogger.warn;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
Expand Down Expand Up @@ -59,7 +60,9 @@ public void should_create_csv_file_with_data() {
} finally {
IOUtils.closeQuietly(fileReader);
IOUtils.closeQuietly(csvFileParser);
file.delete();
if (!file.delete()) {
warn("Can not delete file " + fileName);
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/resources/cmd.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ cmd.api.command.help.title=GoEuro API Command Help:
cmd.api.command.help.template=\n\n Name: %s\n Description: %s\n Template: %s\n Allowed params: %s\n Example: %s

cmd.command.quit.byes=\
See you later! \n#\
Bye... \n#\
Come on, it is not so late. Take one more beer! \n#\
John Snow is still alive! Oops, sorry ... Bye! \n#\
Out of memory detected!!! ... Easy easy, it is a joke! Bye! \n
See you later!\n#\
Bye...\n#\
Come on, it is not so late. Take one more beer!\n#\
John Snow is still alive! Oops, sorry ... Bye!\n#\
Out of memory detected!!! ... Easy easy, it is a joke! Bye!\n

0 comments on commit 3ffdbe6

Please sign in to comment.