use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class HtmlMappingExporter method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
this.reporter = reporter;
context = new VelocityContext();
cellIds = new Identifiers<Cell>(Cell.class, false);
alignment = getAlignment();
// $NON-NLS-1$
URL headlinePath = this.getClass().getResource("bg-headline.png");
// $NON-NLS-1$
URL cssPath = this.getClass().getResource("style.css");
// $NON-NLS-1$
URL linkPath = this.getClass().getResource("int_link.png");
// $NON-NLS-1$
URL tooltipIcon = this.getClass().getResource("tooltip.gif");
final String filesSubDir = FilenameUtils.removeExtension(FilenameUtils.getName(getTarget().getLocation().getPath())) + // $NON-NLS-1$
"_files";
final File filesDir = new File(FilenameUtils.getFullPath(getTarget().getLocation().getPath()), filesSubDir);
filesDir.mkdirs();
context.put(FILE_DIRECTORY, filesSubDir);
try {
init();
} catch (Exception e) {
return reportError(reporter, "Initializing error", e);
}
File cssOutputFile = new File(filesDir, "style.css");
FileUtils.copyFile(getInputFile(cssPath), cssOutputFile);
// create headline picture
// $NON-NLS-1$
File headlineOutputFile = new File(filesDir, "bg-headline.png");
FileUtils.copyFile(getInputFile(headlinePath), headlineOutputFile);
// $NON-NLS-1$
File linkOutputFile = new File(filesDir, "int_link.png");
FileUtils.copyFile(getInputFile(linkPath), linkOutputFile);
// $NON-NLS-1$
File tooltipIconFile = new File(filesDir, "tooltip.png");
FileUtils.copyFile(getInputFile(tooltipIcon), tooltipIconFile);
File htmlExportFile = new File(getTarget().getLocation().getPath());
if (projectInfo != null) {
Date date = new Date();
DateFormat dfm = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
// associate variables with information data
String exportDate = dfm.format(date);
context.put(EXPORT_DATE, exportDate);
if (projectInfo.getCreated() != null) {
String created = dfm.format(projectInfo.getCreated());
context.put(CREATED_DATE, created);
}
context.put(PROJECT_INFO, projectInfo);
}
if (alignment != null) {
Collection<TypeCellInfo> typeCellInfos = new ArrayList<TypeCellInfo>();
Collection<? extends Cell> cells = alignment.getTypeCells();
Iterator<? extends Cell> it = cells.iterator();
while (it.hasNext()) {
final Cell cell = it.next();
// this is the collection of type cell info
TypeCellInfo typeCellInfo = new TypeCellInfo(cell, alignment, cellIds, filesSubDir);
typeCellInfos.add(typeCellInfo);
}
// put the full collection of type cell info to the context (for the
// template)
context.put(TYPE_CELL_INFOS, typeCellInfos);
createImages(filesDir);
}
context.put(TOOLTIP, getParameter(TOOLTIP).as(boolean.class));
Template template;
try {
template = velocityEngine.getTemplate(templateFile.getName(), "UTF-8");
} catch (Exception e) {
return reportError(reporter, "Could not load template", e);
}
FileWriter fileWriter = new FileWriter(htmlExportFile);
template.merge(context, fileWriter);
fileWriter.close();
reporter.setSuccess(true);
return reporter;
}
use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class TypeCellInfo method getPropertyCellsInfo.
/**
* Returns a collection of property cells info
*
* @return property cells info, may be <code>null</code>
*/
public Collection<ICellInfo> getPropertyCellsInfo() {
Collection<ICellInfo> propCellInfo = new ArrayList<ICellInfo>();
Collection<? extends Cell> propCells = align.getPropertyCells(getCell());
Iterator<? extends Cell> it = propCells.iterator();
while (it.hasNext()) {
Cell propCell = it.next();
propCellInfo.add(new CellInfo(propCell, cellIds, subDir));
}
return propCellInfo;
}
use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class OMLReaderTest method testAssign1.
/**
* Test assign function in alignment4
*/
@Test
@Ignore
public // because now NilReasonFunction also produces assign cells
void testAssign1() {
Collection<? extends Cell> cells = alignment4.getCells();
Iterator<? extends Cell> it = cells.iterator();
List<Cell> assignCells = new ArrayList<Cell>();
while (it.hasNext()) {
Cell temp = it.next();
if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.hale.align.assign")) {
assignCells.add(temp);
}
}
// test all cells that have an assign function
for (int i = 0; i < assignCells.size(); i++) {
Cell cell = assignCells.get(i);
ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
List<ParameterValue> values = params.get("value");
assertEquals(1, values.size());
// size is always 1
String temp = values.get(0).as(String.class);
// test cell #1
if (i == 0) {
assertEquals("FR", temp);
}
// test cell #2
if (i == 1) {
assertEquals("FR.IGN.ERM", temp);
}
// test cell #3
if (i == 2) {
assertEquals("250000", temp);
}
}
// check if all cells with an assign function were tested
assertEquals(3, assignCells.size());
}
use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class OMLReaderTest method testFormattedString3.
/**
* Test for formatted string function in alignment5
*/
@Test
public void testFormattedString3() {
Collection<? extends Cell> cells = alignment5.getCells();
Iterator<? extends Cell> it = cells.iterator();
Cell cell = null;
while (it.hasNext()) {
Cell temp = it.next();
if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.hale.align.formattedstring")) {
cell = temp;
break;
}
}
assertNotNull(cell);
ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
List<ParameterValue> values = params.get("pattern");
assertEquals(1, values.size());
// size is 1
assertEquals("{Grundbuch}:{Nummer}:{Einlage}", values.get(0).getValue());
}
use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.
the class OMLReaderTest method testClassificationMapping2.
/**
* Test for classification mapping function in alignment4
*/
@Test
public void testClassificationMapping2() {
Collection<? extends Cell> cells = alignment4.getCells();
Iterator<? extends Cell> it = cells.iterator();
List<Cell> classMapCells = new ArrayList<Cell>();
while (it.hasNext()) {
Cell temp = it.next();
if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.hale.align.classification")) {
classMapCells.add(temp);
}
}
// test all cells that have a classification mapping function
for (int i = 0; i < classMapCells.size(); i++) {
Cell cell = classMapCells.get(i);
ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
List<ParameterValue> values = params.get("classificationMapping");
// for each cell too
for (int j = 0; j < values.size(); j++) {
String temp = values.get(j).as(String.class);
// test cell #1
if (i == 0 && j == 0) {
assertEquals("underConstruction 5", temp);
}
// test cell #2
if (i == 1 && j == 0) {
assertEquals("manMade 4", temp);
}
if (i == 1 && j == 1) {
assertEquals("natural 5", temp);
}
// test cell #3
if (i == 2 && j == 0) {
assertEquals("intermittent 6", temp);
}
if (i == 2 && j == 1) {
assertEquals("perennial 8", temp);
}
// test cell #4
if (i == 3 && j == 0) {
assertEquals("false 1", temp);
}
if (i == 3 && j == 1) {
assertEquals("true 2", temp);
}
}
}
// check if all cells with a classification mapping function were tested
assertEquals(4, classMapCells.size());
}
Aggregations