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

Merge branch '335-admin-panel-add-project-predefined-overlays' into 'master'

Resolve "Admin panel: Add project, predefined overlays"

Closes #335

See merge request piotr.gawron/minerva!230
parents 376b5991 4a20cf22
No related branches found
No related tags found
1 merge request!230Resolve "Admin panel: Add project, predefined overlays"
Pipeline #
......@@ -22,5 +22,13 @@
<artifactId>xercesImpl</artifactId>
<version>${xercesImp.version}</version>
</dependency>
<!-- mockito used for testing -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -108,14 +108,13 @@ public class ComplexZipConverter {
entries = zipFile.entries();
Model result = null;
List<Layout> layouts = new ArrayList<Layout>();
int overlayOrder = 1;
List<Layout> layouts = new ArrayList<>();
List<DataMiningSet> dataMiningSets = new ArrayList<>();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
ZipEntryFile zef = params.getEntry(entry.getName());
logger.debug(entry.getName());
logger.debug(zef);
if (zef instanceof ModelZipEntryFile) {
ModelZipEntryFile modelEntryFile = (ModelZipEntryFile) zef;
InputStream is = zipFile.getInputStream(entry);
......@@ -129,7 +128,7 @@ public class ComplexZipConverter {
result = model;
}
} else if (zef instanceof LayoutZipEntryFile) {
layouts.add(layoutZipEntryFileToLayout(params, zipFile, entry, (LayoutZipEntryFile) zef));
layouts.add(layoutZipEntryFileToLayout(params, zipFile, entry, (LayoutZipEntryFile) zef, overlayOrder++));
} else if (zef instanceof ImageZipEntryFile) {
continue;
// imageEntries.add((ImageZipEntryFile) zef);
......@@ -372,7 +371,7 @@ public class ComplexZipConverter {
* thrown when there is a problem with accessing {@link ZipFile}
*/
protected Layout layoutZipEntryFileToLayout(ComplexZipConverterParams params, ZipFile zipFile, ZipEntry entry,
LayoutZipEntryFile layoutEntry) throws IOException {
LayoutZipEntryFile layoutEntry, int order) throws IOException {
Layout layout = new Layout();
layout.setDescription(layoutEntry.getDescription());
layout.setDirectory(params.getVisualizationDir() + "/" + layoutEntry.getName().replaceAll(" ", "_"));
......@@ -383,6 +382,7 @@ public class ComplexZipConverter {
layout.setInputData(fileEntry);
layout.setPublicLayout(true);
layout.setTitle(layoutEntry.getName());
layout.setOrderIndex(order);
return layout;
}
......
......@@ -7,20 +7,25 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import lcsb.mapviewer.common.MimeType;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidClassException;
import lcsb.mapviewer.converter.zip.LayoutZipEntryFile;
import lcsb.mapviewer.converter.zip.ModelZipEntryFile;
import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.model.ModelSubmodelConnection;
......@@ -527,4 +532,23 @@ public class ComplexZipConverterTest {
}
}
@Test
public void testLayoutZipEntryFileToLayoutOrder() throws Exception {
ComplexZipConverter converter = new ComplexZipConverter(MockConverter.class);
ComplexZipConverterParams params = new ComplexZipConverterParams();
ZipFile file = Mockito.mock(ZipFile.class);
params.zipFile(file);
LayoutZipEntryFile entry1 = new LayoutZipEntryFile("overlay1.txt", "name", "desc1");
LayoutZipEntryFile entry2 = new LayoutZipEntryFile("overlay2.txt", "name", "desc1");
params.entry(entry1);
params.entry(entry2);
ZipEntry entry = Mockito.mock(ZipEntry.class);
Mockito.when(file.getInputStream(entry)).thenReturn(new ByteArrayInputStream("".getBytes()));
Layout overlay1 = converter.layoutZipEntryFileToLayout(params, file, entry, entry1, 1);
Layout overlay2 = converter.layoutZipEntryFileToLayout(params, file, entry, entry2, 2);
assertTrue(overlay1.getOrderIndex() > 0);
assertTrue(overlay2.getOrderIndex() > overlay1.getOrderIndex());
}
}
......@@ -195,7 +195,7 @@ public class Layout implements Serializable {
this.inputData = new UploadedFileEntry(layout.getInputData());
}
this.hierarchyViewLevel = layout.hierarchyViewLevel;
this.orderIndex = layout.orderIndex;
}
/**
......
......@@ -21,147 +21,161 @@ import lcsb.mapviewer.model.map.model.ModelFullIndexed;
public class LayoutTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testSerialization() {
try {
SerializationUtils.serialize(new Layout());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testConstructor() {
try {
String title = "TIT";
String dir = "TIT";
boolean publicL = true;
Layout layout = new Layout(title, dir, publicL);
assertEquals(title, layout.getTitle());
assertEquals(dir, layout.getDirectory());
assertEquals(publicL, layout.isPublicLayout());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testConstructor2() {
try {
String title = "TIT";
String dir = "TIT";
boolean publicL = true;
Layout layout = new Layout(title, dir, publicL);
Layout layout2 = new Layout(layout);
assertNotNull(layout2);
UploadedFileEntry fileEntry = new UploadedFileEntry();
fileEntry.setFileContent(new byte[] {});
layout.setInputData(fileEntry);
Layout layout3 = new Layout(layout);
assertNotNull(layout3);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCopy() {
try {
String title = "TIT";
String dir = "TIT";
boolean publicL = true;
Layout layout = new Layout(title, dir, publicL);
Layout layout2 = layout.copy();
assertNotNull(layout2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testInvalidCopy() {
try {
Layout layout = new Layout() {
/**
*
*/
private static final long serialVersionUID = 1L;
};
layout.copy();
fail("Exception expected");
} catch (NotImplementedException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetters() {
try {
ModelFullIndexed model = new ModelFullIndexed(null);
Set<Layout> layouts = new HashSet<>();
boolean hierarchicalView = false;
boolean publicLayout = true;
int id = 62;
String description = "qds";
String directory = "vcccv";
String title = "tit";
LayoutStatus status = LayoutStatus.FAILURE;
double progress = 1.6;
UploadedFileEntry inputData = new UploadedFileEntry();
Layout parentLayout = new Layout();
Layout layout = new Layout();
layout.setHierarchicalView(hierarchicalView);
assertEquals(hierarchicalView, layout.isHierarchicalView());
layout.setId(id);
assertEquals(id, layout.getId());
layout.setDescription(description);
assertEquals(description, layout.getDescription());
layout.setDirectory(directory);
assertEquals(directory, layout.getDirectory());
layout.setTitle(title);
assertEquals(title, layout.getTitle());
layout.setModel((ModelData) null);
assertNull(layout.getModel());
layout.setCreator(null);
assertNull(layout.getCreator());
layout.setStatus(status);
assertEquals(status, layout.getStatus());
layout.setProgress(progress);
assertEquals(progress, layout.getProgress(), Configuration.EPSILON);
layout.setInputData(inputData);
assertEquals(inputData, layout.getInputData());
layout.setParentLayout(parentLayout);
assertEquals(parentLayout, layout.getParentLayout());
layout.setPublicLayout(publicLayout);
assertEquals(publicLayout, layout.isPublicLayout());
layout.setLayouts(layouts);
assertEquals(layouts, layout.getLayouts());
layout.addLayout(parentLayout);
assertEquals(1, layouts.size());
layout.setModel(model);
assertEquals(model.getModelData(), layout.getModel());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testSerialization() {
try {
SerializationUtils.serialize(new Layout());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testConstructor() {
try {
String title = "TIT";
String dir = "TIT";
boolean publicL = true;
Layout layout = new Layout(title, dir, publicL);
assertEquals(title, layout.getTitle());
assertEquals(dir, layout.getDirectory());
assertEquals(publicL, layout.isPublicLayout());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testConstructor2() {
try {
String title = "TIT";
String dir = "TIT";
boolean publicL = true;
Layout layout = new Layout(title, dir, publicL);
Layout layout2 = new Layout(layout);
assertNotNull(layout2);
UploadedFileEntry fileEntry = new UploadedFileEntry();
fileEntry.setFileContent(new byte[] {});
layout.setInputData(fileEntry);
Layout layout3 = new Layout(layout);
assertNotNull(layout3);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testConstructorWithOrder() {
try {
boolean publicL = true;
Layout overlay1 = new Layout(null, null, publicL);
overlay1.setOrderIndex(12);
Layout overlay2 = new Layout(overlay1);
assertEquals(overlay1.getOrderIndex(), overlay2.getOrderIndex());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCopy() {
try {
String title = "TIT";
String dir = "TIT";
boolean publicL = true;
Layout layout = new Layout(title, dir, publicL);
Layout layout2 = layout.copy();
assertNotNull(layout2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testInvalidCopy() {
try {
Layout layout = new Layout() {
/**
*
*/
private static final long serialVersionUID = 1L;
};
layout.copy();
fail("Exception expected");
} catch (NotImplementedException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetters() {
try {
ModelFullIndexed model = new ModelFullIndexed(null);
Set<Layout> layouts = new HashSet<>();
boolean hierarchicalView = false;
boolean publicLayout = true;
int id = 62;
String description = "qds";
String directory = "vcccv";
String title = "tit";
LayoutStatus status = LayoutStatus.FAILURE;
double progress = 1.6;
UploadedFileEntry inputData = new UploadedFileEntry();
Layout parentLayout = new Layout();
Layout layout = new Layout();
layout.setHierarchicalView(hierarchicalView);
assertEquals(hierarchicalView, layout.isHierarchicalView());
layout.setId(id);
assertEquals(id, layout.getId());
layout.setDescription(description);
assertEquals(description, layout.getDescription());
layout.setDirectory(directory);
assertEquals(directory, layout.getDirectory());
layout.setTitle(title);
assertEquals(title, layout.getTitle());
layout.setModel((ModelData) null);
assertNull(layout.getModel());
layout.setCreator(null);
assertNull(layout.getCreator());
layout.setStatus(status);
assertEquals(status, layout.getStatus());
layout.setProgress(progress);
assertEquals(progress, layout.getProgress(), Configuration.EPSILON);
layout.setInputData(inputData);
assertEquals(inputData, layout.getInputData());
layout.setParentLayout(parentLayout);
assertEquals(parentLayout, layout.getParentLayout());
layout.setPublicLayout(publicLayout);
assertEquals(publicLayout, layout.isPublicLayout());
layout.setLayouts(layouts);
assertEquals(layouts, layout.getLayouts());
layout.addLayout(parentLayout);
assertEquals(1, layouts.size());
layout.setModel(model);
assertEquals(model.getModelData(), layout.getModel());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
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