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

project contains reference to file that was uploaded

parent 875edb3c
No related branches found
No related tags found
2 merge requests!115Resolve "admin panel should use API",!114Resolve "admin panel should use API"
Showing
with 92 additions and 61 deletions
......@@ -6,13 +6,13 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
......@@ -28,6 +28,7 @@ import org.hibernate.annotations.LazyCollectionOption;
import lcsb.mapviewer.common.EventStorageLoggerAppender;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.OverviewImage;
import lcsb.mapviewer.model.map.OverviewImageLink;
......@@ -123,13 +124,10 @@ public class Project implements Serializable {
/**
* Here we store input file.
*/
@Basic(fetch = FetchType.LAZY)
private byte[] inputData;
/**
* Here we store input file.
*/
private String inputFileName;
@Cascade({ CascadeType.SAVE_UPDATE })
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "file_entry_iddb")
private UploadedFileEntry inputData;
/**
* Organism associated with the project.
......@@ -354,40 +352,6 @@ public class Project implements Serializable {
this.disease = disease;
}
/**
* @return the inputData
* @see #inputData
*/
public byte[] getInputData() {
return inputData;
}
/**
* @param inputData
* the inputData to set
* @see #inputData
*/
public void setInputData(byte[] inputData) {
this.inputData = inputData;
}
/**
* @return the inputFileName
* @see #inputFileName
*/
public String getInputFileName() {
return inputFileName;
}
/**
* @param inputFileName
* the inputFileName to set
* @see #inputFileName
*/
public void setInputFileName(String inputFileName) {
this.inputFileName = inputFileName;
}
/**
* @param organism
* the organism to set
......@@ -580,4 +544,21 @@ public class Project implements Serializable {
}
/**
* @return the inputData
* @see #inputData
*/
public UploadedFileEntry getInputData() {
return inputData;
}
/**
* @param inputData
* the inputData to set
* @see #inputData
*/
public void setInputData(UploadedFileEntry inputData) {
this.inputData = inputData;
}
}
......@@ -19,6 +19,7 @@ import org.junit.Test;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.EventStorageLoggerAppender;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
......@@ -124,12 +125,9 @@ public class ProjectTest {
assertEquals(disease, project.getDisease());
String inputFileName = "x";
byte[] inputData = new byte[] { 1, 2 };
project.setInputData(inputData);
assertEquals(inputData, project.getInputData());
project.setInputFileName(inputFileName);
assertEquals(inputFileName, project.getInputFileName());
UploadedFileEntry entry = new UploadedFileEntry() ;
project.setInputData(entry );
assertEquals(entry , project.getInputData());
project.setOrganism(organism);
assertEquals(organism, project.getOrganism());
......
......@@ -3,3 +3,22 @@ alter table overview_image_table add column project_iddb integer;
update overview_image_table set project_iddb = model_table.project_iddb from model_table where model_table.iddb = overview_image_table.model_iddb;
delete from overview_image_table where project_iddb is null;
alter table overview_image_table drop column model_iddb;
-- project file moved to downloaded files
alter table project_table add column file_entry_iddb integer;
DO $$
DECLARE
project RECORD;
last_id INT;
BEGIN
FOR project IN SELECT * FROM project_table where inputData is not null LOOP
insert into file_entry (filecontent, file_type_db, originalfilename) values
(project.inputdata, 'UPLOADED_FILE_ENTRY',project.inputfilename) returning iddb into last_id;
update project_table set file_entry_iddb = last_id where iddb = project.iddb ;
RAISE NOTICE 'Calling cs_create_job(%, %)', project.iddb, last_id ;
END LOOP;
END $$;
alter table project_table drop column inputdata;
alter table project_table drop column inputfilename;
......@@ -289,4 +289,23 @@ public class ProjectDaoTest extends PersistTestFunctions {
}
}
@Test
public void testGetAll() throws Exception {
try {
long startTime = System.currentTimeMillis();
double max = 10;
logger.debug("---");
for (int i = 0; i < max; i++) {
projectDao.getAll();
}
long estimatedTime = System.currentTimeMillis() - startTime;
logger.debug(estimatedTime/max);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -157,10 +157,7 @@ public class ProjectRestImpl extends BaseRestImpl {
if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
FileEntry entry = new UploadedFileEntry();
entry.setOriginalFileName(project.getInputFileName());
entry.setFileContent(project.getInputData());
return entry;
return project.getInputData();
}
public FileEntry getModelAsImage(String token, String projectId, String modelId, String handlerClass, String backgroundOverlayId, String overlayIds,
......
......@@ -59,6 +59,7 @@ import lcsb.mapviewer.converter.model.sbgnml.SbgnmlXmlConverter;
import lcsb.mapviewer.converter.zip.ZipEntryFile;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.log.LogType;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
......@@ -954,8 +955,10 @@ public class ProjectService implements IProjectService {
File inputFile = new File(params.getProjectFile());
if (inputFile.exists()) {
project.setInputData(IOUtils.toByteArray(new FileInputStream(inputFile)));
project.setInputFileName(FilenameUtils.getName(params.getProjectFile()));
UploadedFileEntry file = new UploadedFileEntry();
file.setFileContent(IOUtils.toByteArray(new FileInputStream(inputFile)));
file.setOriginalFileName(FilenameUtils.getName(params.getProjectFile()));
project.setInputData(file);
}
createModel(params, project);
......@@ -1503,10 +1506,10 @@ public class ProjectService implements IProjectService {
*/
private byte[] getInputDataForProject(int projectId) {
Project project = projectDao.getById(projectId);
if (project == null) {
if (project == null || project.getInputData() == null) {
return null;
} else {
return project.getInputData();
return project.getInputData().getFileContent();
}
}
......
......@@ -75,7 +75,7 @@ public class ProjectViewFactory extends AbstractViewFactory<Project, ProjectView
}
result.setStatus(project.getStatus().toString());
result.setProgress(Integer.valueOf((int) project.getProgress()));
result.setInputDataAvailable(project.getInputFileName() != null);
result.setInputDataAvailable(project.getInputData() != null);
int warnCount = 0;
String warnPreview = "";
......
......@@ -20,3 +20,4 @@ import lcsb.mapviewer.services.view.AllViewTests;
public class AllServicesTests {
}
;
\ No newline at end of file
......@@ -1456,7 +1456,7 @@ public class ProjectBean extends AbstractManagedBean implements Serializable {
Project project = projectService.getProjectByProjectId(projectView.getProjectId(), userBean.getAuthenticationToken());
String string = new String(data, StandardCharsets.UTF_8);
String fileName = project.getInputFileName();
String fileName = project.getInputData().getOriginalFileName();
MimeType respMimeType = null;
if (fileName.endsWith("xml")) {
respMimeType = MimeType.XML;
......@@ -1468,7 +1468,7 @@ public class ProjectBean extends AbstractManagedBean implements Serializable {
logger.warn("Cannot determine mime type of file: " + fileName);
respMimeType = MimeType.TEXT;
}
sendFileAsResponse(string, project.getInputFileName(), respMimeType);
sendFileAsResponse(string, fileName, respMimeType);
}
/**
......
......@@ -2,6 +2,7 @@ package lcsb.mapviewer.bean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
......@@ -11,6 +12,7 @@ import org.apache.commons.lang3.SerializationUtils;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -26,7 +28,9 @@ import lcsb.mapviewer.model.user.ObjectPrivilege;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.map.LayoutDao;
import lcsb.mapviewer.services.view.LayoutView;
import lcsb.mapviewer.services.view.ProjectView;
import lcsb.mapviewer.services.view.ProjectViewTest;
public class LayoutBeanTest extends WebTestFunctions {
Logger logger = Logger.getLogger(LayoutBeanTest.class);
......@@ -79,6 +83,7 @@ public class LayoutBeanTest extends WebTestFunctions {
}
@Ignore
@Test(timeout = 15000)
public void testAddLayout() throws Exception {
Project project = new Project();
......@@ -106,7 +111,7 @@ public class LayoutBeanTest extends WebTestFunctions {
mapBean.setCurrentMapId(project.getProjectId());
getMapBean().setCurrentMapId(project.getProjectId());
User guest = userService.getUserByLogin(Configuration.ANONYMOUS_LOGIN);
User guest = userService.getUserByLogin(Configuration.ANONYMOUS_LOGIN);
// add user a privilege for viewing layouts
BasicPrivilege privilege = new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, guest);
userService.setUserPrivilege(guest, privilege);
......@@ -139,6 +144,7 @@ public class LayoutBeanTest extends WebTestFunctions {
}
}
@Ignore
@Test(timeout = 15000)
public void testAddLayoutForUser() throws Exception {
Project project = new Project();
......@@ -174,6 +180,7 @@ public class LayoutBeanTest extends WebTestFunctions {
privilege = new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, user);
userService.setUserPrivilege(user, privilege);
userDao.flush();
userDao.commit();
layoutBean.addLayout(null);
......@@ -185,8 +192,14 @@ public class LayoutBeanTest extends WebTestFunctions {
layoutDao.refresh(l);
} while (l.getStatus().equals(LayoutStatus.NA) || l.getStatus().equals(LayoutStatus.GENERATING));
ProjectView projectView = projectBean.getProjects().get(projectBean.getProjects().size() - 1);
ProjectView projectView =null;
for (ProjectView view: projectBean.getProjects()) {
if (view.getIdObject().equals(project.getId())) {
projectView = view;
}
}
assertNotNull(projectView);
// check if layout appears on project list
assertEquals(1, projectView.getLayouts().size());
assertFalse(projectView.getLayouts().get(0).getCreator().isEmpty());
......
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