Skip to content

Commit

Permalink
Merge with testing
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivandervelde committed Jan 8, 2013
2 parents 0910af6 + f5a9a64 commit 1a6cc70
Show file tree
Hide file tree
Showing 24 changed files with 776 additions and 37 deletions.
5 changes: 0 additions & 5 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@
<attribute name="org.eclipse.jst.component.dependency" value="../"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/jersey-json-1.1.5.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="../"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/jetty-6.1.21.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="../"/>
Expand Down
334 changes: 334 additions & 0 deletions doc/molgenis_manual.md

Large diffs are not rendered by default.

Binary file removed lib/jersey-json-1.1.5.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void handleRequest(MolgenisRequest req, MolgenisResponse res) throws Pars
int total_pages = 1;
if (recordCount > 0 && limit > 0)
{
total_pages = (int) (recordCount / limit) + 1;
total_pages = ((int) (recordCount / (double) limit)) + 1;
}

// if for some reasons the requested page is greater than the total
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public List<Field> getColumns() throws TableException
colCount--;
}

int colLimit = (int) (this.colLimit == 0 ? colCount - getColOffset() : getCurrentColumnPageSize(colCount));
int colLimit = this.colLimit == 0 ? colCount - getColOffset() : getCurrentColumnPageSize(colCount);

if (getColOffset() > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/org/molgenis/framework/ui/ApplicationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public Show handleRequest(Database db, MolgenisRequest request, OutputStream out
// by Galaxy to fetch the data)
//
this.setGalaxyUrl(request.getString("GALAXY_URL"));
logger.info("User was forwarded to Molgenis running @ " + ((MolgenisRequest) request).getAppLocation());
logger.info("User was forwarded to Molgenis running @ " + request.getAppLocation());
logger.info("User was forwarded to Molgenis by Galaxy running @ " + this.getGalaxyUrl());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/molgenis/framework/ui/MenuModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void show(String name)
*/
public List<ScreenModel> getVisibleChildren()
{
Vector<ScreenController<? extends ScreenModel>> subscreens = this.getController().getChildren();
Vector<ScreenController<?>> subscreens = this.getController().getChildren();
List<ScreenModel> result = new ArrayList<ScreenModel>();

// remove hidden children from the list, and also commands
Expand Down
2 changes: 1 addition & 1 deletion src/org/molgenis/framework/ui/commands/GalaxyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public List<ActionInput> getActions()
public ScreenModel.Show handleRequest(Database db, MolgenisRequest request, OutputStream downloadStream)
{
logger.debug("galaxy button clicked: " + this.getController().getApplicationController().getGalaxyUrl());
appLoc = ((MolgenisRequest) request).getAppLocation();
appLoc = request.getAppLocation();
return ScreenModel.Show.SHOW_MAIN;
}

Expand Down
9 changes: 4 additions & 5 deletions src/org/molgenis/framework/ui/html/CheckboxInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.List;
import java.util.Vector;

import org.molgenis.util.tuple.Tuple;
import org.molgenis.util.ValueLabel;
import org.molgenis.util.tuple.Tuple;

/**
* Input for checkbox data.
Expand Down Expand Up @@ -78,12 +78,11 @@ public CheckboxInput(String name, List<String> options, List<String> optionLabel
* @param properties
* @throws HtmlInputException
*/
@SuppressWarnings("unchecked")
public CheckboxInput(Tuple properties) throws HtmlInputException
{
super(properties);
if (!properties.isNull(VALUE)) this.setValue((List<String>) properties.getList(VALUE));
if (!properties.isNull(VALUES)) this.setValue((List<String>) properties.getList(VALUES));
if (!properties.isNull(VALUE)) this.setValue(properties.getList(VALUE));
if (!properties.isNull(VALUES)) this.setValue(properties.getList(VALUES));
}

/**
Expand Down Expand Up @@ -125,7 +124,7 @@ public String toHtml()
{
if (getObject() != null)
{
checked = (((List<String>) getObject()).contains(option.getValue().toString()) ? " checked " : "");
checked = getObject().contains(option.getValue().toString()) ? " checked " : "";
}
optionString.append("<input id=\"" + this.getId() + "\" type=\"checkbox\" " + onchange + readonly
+ checked + " name=\"" + this.getName() + "\" value=\"" + option.getValue() + "\">"
Expand Down
2 changes: 1 addition & 1 deletion src/org/molgenis/framework/ui/html/ListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public List<HtmlForm> getRows()
@Override
public ListView setValue(List<HtmlForm> value)
{
this.setRows((List<HtmlForm>) value);
this.setRows(value);
return this;
}

Expand Down
5 changes: 2 additions & 3 deletions src/org/molgenis/framework/ui/html/OptionInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Arrays;
import java.util.List;

import org.molgenis.util.tuple.Tuple;
import org.molgenis.util.ValueLabel;
import org.molgenis.util.tuple.Tuple;

/**
* Common superclass for option based inputs such as xrefs, enums, radio, etc.
Expand Down Expand Up @@ -57,12 +57,11 @@ public OptionInput(Tuple t) throws HtmlInputException
set(t);
}

@SuppressWarnings("unchecked")
@Override
public void set(Tuple t) throws HtmlInputException
{
super.set(t);
this.setOptions((List<String>) t.getList(OPTIONS), (List<String>) t.getList(OPTION_LABELS));
this.setOptions(t.getList(OPTIONS), t.getList(OPTION_LABELS));
}

protected OptionInput()
Expand Down
5 changes: 2 additions & 3 deletions src/org/molgenis/framework/ui/html/SelectMultipleInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import java.util.List;

import org.molgenis.util.Entity;
import org.molgenis.util.tuple.Tuple;
import org.molgenis.util.ValueLabel;
import org.molgenis.util.tuple.Tuple;

/**
* Input for multiple select. This means that a user can select multiple items
Expand Down Expand Up @@ -54,11 +54,10 @@ public SelectMultipleInput(String name, String label, List<String> values, Boole
super(name, label, values, nillable, readonly, description, options, option_labels);
}

@SuppressWarnings("unchecked")
public SelectMultipleInput(Tuple t) throws HtmlInputException
{
super(t);
this.setValue((List<String>) t.getList(VALUES));
this.setValue(t.getList(VALUES));
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/org/molgenis/generators/DataTypeCommons.java.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@
</#list></#if>
<#else>
//set ${JavaName(f)}
// query formal name, else lowercase name
<#if f.type == "xref">
if(tuple.get${settertype(f)}("${f.name}_${f.xrefField.name}") != null) this.set${JavaName(f)}(tuple.get${settertype(f)}("${f.name}_${f.xrefField.name}"));
else if(tuple.get${settertype(f)}("${f.name?lower_case}_${f.xrefField.name?lower_case}") != null) this.set${JavaName(f)}(tuple.get${settertype(f)}("${f.name?lower_case}_${f.xrefField.name?lower_case}"));
else if(strict) this.set${JavaName(f)}(tuple.get${settertype(f)}("${f.name}_${f.xrefField.name}"));
else if(strict) this.set${JavaName(f)}(tuple.get${settertype(f)}("${f.name}_${f.xrefField.name}")); // setting null is not an option due to function overloading

if( tuple.get${settertype(f)}("${entity.name}_${f.name}_${f.xrefField.name}") != null) this.set${JavaName(f)}(tuple.get${settertype(f)}("${entity.name}_${f.name}_${f.xrefField.name}"));
else if( tuple.get${settertype(f)}("${entity.name?lower_case}_${f.name?lower_case}_${f.xrefField.name?lower_case}") != null) this.set${JavaName(f)}(tuple.get${settertype(f)}("${entity.name?lower_case}_${f.name?lower_case}_${f.xrefField.name?lower_case}"));
Expand Down Expand Up @@ -104,14 +105,14 @@
<#if f.xrefLabelNames[0] != f.xrefFieldName><#list f.xrefLabelNames as label>
if(tuple.get("${f.name}_${label}") != null) this.set${JavaName(f)}_${JavaName(label)}(tuple.get${settertype(f.xrefLabels[label_index])}("${f.name}_${label}"));
else if(tuple.get("${f.name?lower_case}_${label?lower_case}") != null) this.set${JavaName(f)}_${JavaName(label)}(tuple.get${settertype(f.xrefLabels[label_index])}("${f.name?lower_case}_${label?lower_case}"));
else if(strict) this.set${JavaName(f)}_${JavaName(label)}(tuple.get${settertype(f.xrefLabels[label_index])}("${f.name}_${label}"));
else if(strict) this.set${JavaName(f)}_${JavaName(label)}(tuple.get${settertype(f.xrefLabels[label_index])}("${f.name}_${label}")); // setting null is not an option due to function overloading
if( tuple.get("${entity.name}_${f.name}_${label}") != null ) this.set${JavaName(f)}_${JavaName(label)}(tuple.get${settertype(f.xrefLabels[label_index])}("${entity.name}_${f.name}_${label}"));
else if( tuple.get("${entity.name?lower_case}_${f.name?lower_case}_${label?lower_case}") != null ) this.set${JavaName(f)}_${JavaName(label)}(tuple.get${settertype(f.xrefLabels[label_index])}("${entity.name?lower_case}_${f.name?lower_case}_${label?lower_case}"));
</#list></#if>
<#else>
if(tuple.get${settertype(f)}("${f.name?lower_case}") != null) this.set${JavaName(f)}(tuple.get${settertype(f)}("${f.name?lower_case}"));
else if(tuple.get${settertype(f)}("${f.name}") != null) this.set${JavaName(f)}(tuple.get${settertype(f)}("${f.name}"));
else if(strict) this.set${JavaName(f)}(tuple.get${settertype(f)}("${f.name?lower_case}"));
else if(strict) this.set${JavaName(f)}(tuple.get${settertype(f)}("${f.name?lower_case}")); // setting null is not an option due to function overloading
if( tuple.get${settertype(f)}("${entity.name?lower_case}_${f.name?lower_case}") != null) this.set${JavaName(f)}(tuple.get${settertype(f)}("${entity.name?lower_case}_${f.name?lower_case}"));
else if( tuple.get${settertype(f)}("${entity.name}_${f.name}") != null) this.set${JavaName(f)}(tuple.get${settertype(f)}("${entity.name}_${f.name}"));
</#if>
Expand Down
5 changes: 5 additions & 0 deletions src/org/molgenis/io/TableReaderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipFile;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -57,6 +58,10 @@ else if (name.endsWith(".xls") || name.endsWith(".xlsx"))
{
return new ExcelReader(file);
}
else if (name.endsWith(".zip"))
{
return new ZipTableReader(new ZipFile(file));
}
else
{
throw new IOException("unknown file type: " + name);
Expand Down
104 changes: 104 additions & 0 deletions src/org/molgenis/io/ZipTableReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.molgenis.io;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import javax.annotation.Nullable;

import org.molgenis.io.csv.CsvReader;

import com.google.common.base.Function;
import com.google.common.collect.Iterators;

public class ZipTableReader implements TableReader
{
private final ZipFile zipFile;
private final Map<String, ZipEntry> tableNameMap;

public ZipTableReader(ZipFile zipFile) throws IOException
{
if (zipFile == null) throw new IllegalArgumentException("zip file is null");
this.zipFile = zipFile;

// init table name map
tableNameMap = new LinkedHashMap<String, ZipEntry>();
for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();)
{
ZipEntry zipEntry = e.nextElement();

// remove extension from filename
int pos = zipEntry.getName().lastIndexOf('.');
String tableName = pos != -1 ? zipEntry.getName().substring(0, pos) : zipEntry.getName();

tableNameMap.put(tableName, zipEntry);
}
}

@Override
public Iterator<TupleReader> iterator()
{
return Iterators.transform(tableNameMap.values().iterator(), new Function<ZipEntry, TupleReader>()
{
@Override
@Nullable
public TupleReader apply(@Nullable
ZipEntry zipEntry)
{
try
{
return toTupleReader(zipEntry);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
});
}

@Override
public void close() throws IOException
{
// noop
}

@Override
public TupleReader getTupleReader(String tableName) throws IOException
{
ZipEntry zipEntry = tableNameMap.get(tableName);
return zipEntry != null ? toTupleReader(zipEntry) : null;
}

@Override
public Iterable<String> getTableNames() throws IOException
{
return tableNameMap.keySet();
}

private TupleReader toTupleReader(ZipEntry zipEntry) throws IOException
{
String name = zipEntry.getName();
if (name.endsWith(".csv") || name.endsWith(".txt"))
{
Reader reader = new InputStreamReader(zipFile.getInputStream(zipEntry), Charset.forName("UTF-8"));
return new CsvReader(reader);
}
else if (name.endsWith(".tsv"))
{
Reader reader = new InputStreamReader(zipFile.getInputStream(zipEntry), Charset.forName("UTF-8"));
return new CsvReader(reader, '\t');
}
else
{
throw new IOException("unknown file type: " + name);
}
}
}
6 changes: 4 additions & 2 deletions src/org/molgenis/io/csv/CsvReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -127,6 +127,8 @@ private Tuple get()
{
for (int i = 0; i < values.length; ++i)
{
// subsequent separators indicate null
// values instead of empty strings
String value = values[i].isEmpty() ? null : values[i];
values[i] = processCell(value, false);
}
Expand Down Expand Up @@ -168,7 +170,7 @@ private Map<String, Integer> toColNamesMap(String[] headers)
if (headers.length == 0) return Collections.emptyMap();

int capacity = (int) (headers.length / 0.75) + 1;
Map<String, Integer> columnIdx = new HashMap<String, Integer>(capacity);
Map<String, Integer> columnIdx = new LinkedHashMap<String, Integer>(capacity);
for (int i = 0; i < headers.length; ++i)
{
String header = processCell(headers[i], true);
Expand Down
4 changes: 2 additions & 2 deletions src/org/molgenis/model/MolgenisModelValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ public static void validateViews(Model model) throws MolgenisModelException
Vector<Entity> viewentities = new Vector<Entity>();
for (Pair<Entity, Entity> p : references)
{
if (!viewentities.contains(p.getA())) viewentities.add((Entity) p.getA());
if (!viewentities.contains(p.getB())) viewentities.add((Entity) p.getB());
if (!viewentities.contains(p.getA())) viewentities.add(p.getA());
if (!viewentities.contains(p.getB())) viewentities.add(p.getB());
}

// if (viewentities.size() != view.getEntities().size())
Expand Down
2 changes: 1 addition & 1 deletion src/org/molgenis/model/elements/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ public Vector<Field> getAllFields() throws MolgenisModelException
// first fields of the interfaces
for (Entity iface : this.getImplements())
{
Vector<Field> ifaceFields = (Vector<Field>) iface.getAllFields();
Vector<Field> ifaceFields = iface.getAllFields();
for (Field ifaceField : ifaceFields)
{
all_fields.put(ifaceField.getName().toLowerCase(), ifaceField);
Expand Down
4 changes: 2 additions & 2 deletions src/org/molgenis/model/elements/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public List<Field> getAllFields() throws MolgenisModelException
public List<Field> getFields() throws MolgenisModelException
{
// retrieve the root
DBSchema database = (DBSchema) getRoot();
DBSchema database = getRoot();

// retrieve all the fields
Vector<Field> fields = new Vector<Field>();
Expand Down Expand Up @@ -99,7 +99,7 @@ public List<Field> getFields() throws MolgenisModelException
public boolean hasXRefs()
{
// retrieve the root
DBSchema database = (DBSchema) getRoot();
DBSchema database = getRoot();

// retrieve all the fields
for (String viewentity : entities)
Expand Down
Loading

0 comments on commit 1a6cc70

Please sign in to comment.