Skip to content
Snippets Groups Projects
Commit c3a4b2eb authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '97-data-upload' into 'master'

Resolve "data upload"

Closes #97

See merge request !43
parents 03d6549e 8a3ec136
No related branches found
No related tags found
1 merge request!43Resolve "data upload"
......@@ -15,6 +15,8 @@ import java.util.Map;
*/
public final class TextFileUtils {
public static String COLUMN_COUNT_PARAM = "__COLUMN_COUNT";
/**
* Default constructor that prevents instatiation.
*/
......@@ -46,6 +48,9 @@ public final class TextFileUtils {
result.put(key, value);
}
} else {
String key = COLUMN_COUNT_PARAM;
String value = line.split("\t").length + "";
result.put(key, value);
break;
}
}
......
......@@ -8,6 +8,9 @@ var PanelControlElementType = require('../PanelControlElementType');
var GuiConnector = require('../../GuiConnector');
var logger = require('../../logger');
var Functions = require('../../Functions');
var NetworkError = require('../../NetworkError');
var HttpStatus = require('http-status-codes');
function OverlayPanel(params) {
params.panelName = "overlays";
......@@ -369,21 +372,22 @@ OverlayPanel.prototype.parseFile = function(fileContent) {
OverlayPanel.prototype.openAddOverlayDialog = function() {
var self = this;
var fileContent = null;
var contentInput = null;
var content = document.createElement("div");
content.style.width = "100%";
content.style.height = "100%";
content.appendChild(self.createLabel("Name"));
content.appendChild(self.createLabel("Name: "));
var nameInput = self.createInputText();
content.appendChild(nameInput);
content.appendChild(self.createNewLine());
content.appendChild(self.createLabel("Description"));
content.appendChild(self.createLabel("Description: "));
content.appendChild(self.createNewLine());
var descriptionInput = self.createTextArea();
content.appendChild(descriptionInput);
content.appendChild(self.createNewLine());
content.appendChild(self.createLabel("File"));
content.appendChild(self.createLabel("Upload file: "));
var fileInput = self.createFileButton();
fileInput.addEventListener("change", function() {
fileContent = null;
......@@ -415,12 +419,24 @@ OverlayPanel.prototype.openAddOverlayDialog = function() {
content.appendChild(fileInput);
content.appendChild(self.createNewLine());
content.appendChild(self.createLabel("Or privde list of elements here: "));
content.appendChild(self.createNewLine());
contentInput = self.createTextArea();
content.appendChild(contentInput);
content.appendChild(self.createNewLine());
var buttons = [ {
text : "UPLOAD",
click : function() {
var dialog = this;
if (contentInput.value !== undefined && contentInput.value !== null) {
contentInput.value = contentInput.value.trim();
if (contentInput.value !== "") {
fileContent = contentInput.value;
}
}
if (fileContent === null) {
GuiConnector.alert("No file was selected");
GuiConnector.alert("Neither file was selected nor data was enterd");
} else {
var data = {
name : nameInput.value,
......@@ -433,6 +449,16 @@ OverlayPanel.prototype.openAddOverlayDialog = function() {
return self.refresh();
}).then(function() {
$(dialog).dialog("close");
}, function(error) {
if (error instanceof NetworkError) {
if (error.statusCode === HttpStatus.BAD_REQUEST) {
GuiConnector.alert("Problematic input: <br/>" + error.content);
} else {
throw error;
}
} else {
throw error;
}
});
}
}
......
......@@ -95,7 +95,11 @@ public class ColorSchemaReader {
*/
public Collection<ColorSchema> readColorSchema(InputStream colorInputStream, Map<String, String> params) throws IOException, InvalidColorSchemaException {
if (params.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE) == null) {
return readGenericColorSchema(colorInputStream);
if (Integer.valueOf(params.get(TextFileUtils.COLUMN_COUNT_PARAM)) == 1) {
return readSimpleNameColorSchema(colorInputStream);
} else {
return readGenericColorSchema(colorInputStream);
}
} else {
ColorSchemaType type = ColorSchemaType.valueOf(params.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE));
if (type == null) {
......@@ -550,6 +554,35 @@ public class ColorSchemaReader {
return result;
}
protected Collection<ColorSchema> readSimpleNameColorSchema(InputStream colorInputStream) throws IOException, InvalidColorSchemaException {
List<ColorSchema> result = new ArrayList<>();
BufferedReader br = new BufferedReader(new InputStreamReader(colorInputStream));
try {
String line = br.readLine();
while (line != null && line.startsWith("#")) {
line = br.readLine();
}
while (line != null) {
if (line.trim().equals("")) {
line = br.readLine();
continue;
}
String[] values = line.split("\t", -1);
ColorSchema schema = new GenericColorSchema();
processNameColumn(schema, values[0]);
schema.setValue(1.0);
result.add(schema);
line = br.readLine();
}
} finally {
br.close();
}
return result;
}
/**
* Sets proper reaction identifier to {@link ColorSchema} from cell content.
*
......
......@@ -11,6 +11,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import org.apache.commons.io.output.ByteArrayOutputStream;
......@@ -279,4 +280,17 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
}
}
@Test
public void testSimpleNameSchemas() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
String input = "#header\ns1\ns2\n";
Collection<ColorSchema> schemas = reader.readSimpleNameColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
assertEquals(2, schemas.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -137,7 +137,6 @@ table.mapInfoBoxResultsTable, table.mapInfoBoxResultsTable th, table.mapInfoBoxR
}
.searchPanel {
height: 100%;
background-color: #FFFFFF;
box-shadow: 0 3px 30px #B9B9B9;
padding: 15px;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment