Commit 88a76225 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '287-tomcat-deployment-init-db-error' into 'master'

Resolve "tomcat deployment init db error"

Closes #287

See merge request piotr.gawron/minerva!202
parents 6959d58e 0dbd7728
Pipeline #3661 passed with stage
in 1 minute and 24 seconds
......@@ -1470,12 +1470,12 @@ public class ProjectService implements IProjectService {
}
/*
* Hibernate lazy loads collections so each element needs to be accessed
* to be loaded now or otherwise the data might not be available
* when accessed because the session might not be available at that time.
* Hibernate lazy loads collections so each element needs to be accessed to be
* loaded now or otherwise the data might not be available when accessed because
* the session might not be available at that time.
*/
List<UserAnnotatorsParam> aps = new ArrayList<>();
for (UserAnnotatorsParam ap: annotationSchema.getAnnotatorsParams()){
for (UserAnnotatorsParam ap : annotationSchema.getAnnotatorsParams()) {
aps.add(ap);
}
return aps;
......@@ -1627,4 +1627,9 @@ public class ProjectService implements IProjectService {
this.taxonomyBackend = taxonomyBackend;
}
@Override
public List<Project> getAllProjects() {
return projectDao.getAll();
}
}
......@@ -76,7 +76,8 @@ public interface IProjectService {
* should the operation be done asynchronously
* @throws UserAccessException
*/
void removeProject(ProjectView projectView, String homeDir, boolean async, AuthenticationToken token) throws UserAccessException;
void removeProject(ProjectView projectView, String homeDir, boolean async, AuthenticationToken token)
throws UserAccessException;
/**
* Removes project from the system.
......@@ -89,11 +90,11 @@ public interface IProjectService {
* should the operation be done asynchronously
* @throws UserAccessException
*/
void removeProject(Project project, String homeDir, boolean async, AuthenticationToken token) throws UserAccessException;
void removeProject(Project project, String homeDir, boolean async, AuthenticationToken token)
throws UserAccessException;
/**
* Gets view of the project by the {@link Project#projectId project
* identifier}.
* Gets view of the project by the {@link Project#projectId project identifier}.
*
* @param projectId
* {@link Project#projectId project identifier}
......@@ -137,15 +138,15 @@ public interface IProjectService {
ProjectView createEmpty();
/**
* Creates {@link TreeNode} that contains information about all classes that
* can be annotated and associate set of
* Creates {@link TreeNode} that contains information about all classes that can
* be annotated and associate set of
* {@link lcsb.mapviewer.annotation.services.annotators.ElementAnnotator
* ElementAnnotator} valid for these classes.
*
* @param user
* for which information should be retrieved
* @return {@link TreeNode} that contains information about all classes that
* can be annotated
* @return {@link TreeNode} that contains information about all classes that can
* be annotated
*/
TreeNode createClassAnnotatorTree(User user);
......@@ -167,7 +168,8 @@ public interface IProjectService {
* {@link TreeNode} that contains information about all classes that
* can be annotated
*/
void updateClassAnnotatorTreeForUser(User user, TreeNode annotatorsTree, boolean sbgnFormat, boolean networkLayoutAsDefault);
void updateClassAnnotatorTreeForUser(User user, TreeNode annotatorsTree, boolean sbgnFormat,
boolean networkLayoutAsDefault);
/**
* Method that updates information about raw {@link Project} object.
......@@ -182,8 +184,8 @@ public interface IProjectService {
* parameter.
*
* @param projectView
* view of the {@link Project} for which we are looking for an
* original source file
* view of the {@link Project} for which we are looking for an original
* source file
* @return content of the file that was used to create project given in the
* parameter
*/
......@@ -193,9 +195,11 @@ public interface IProjectService {
/**
* Retrieves list of annotators {@link UserAnnotatorsParam parameters}
* @return
* list of annotators parameters
*
* @return list of annotators parameters
*/
List<UserAnnotatorsParam> getAnnotatorsParams(User user);
List<Project> getAllProjects();
}
......@@ -40,8 +40,8 @@ public class StartupBean {
* Dao used to access information about projects.
*
*/
@ManagedProperty(value = "#{ProjectDao}")
private transient ProjectDao projectDao;
@ManagedProperty(value = "#{ProjectService}")
private transient IProjectService projectService;
/**
* Service used to access configuration params from db.
......@@ -65,15 +65,19 @@ public class StartupBean {
@PostConstruct
public void init() {
logger.debug("Application startup script starts");
try {
setInterruptedProjectsStatuses();
Configuration.setxFrameDomain(configurationService.getConfigurationValue(ConfigurationElementType.X_FRAME_DOMAIN));
modifyXFrameDomain();
removeInterruptedReferenceGenomeDownloads();
logger.debug("Application startup script ends");
}
private void modifyXFrameDomain() {
try {
Configuration
.setxFrameDomain(configurationService.getConfigurationValue(ConfigurationElementType.X_FRAME_DOMAIN));
} catch (Exception e) {
logger.error("Problem running init script...", e);
logger.error("Problem with modyfing x frame domain...", e);
}
logger.debug("Application startup script ends");
}
/**
......@@ -81,6 +85,7 @@ public class StartupBean {
* restart.
*/
private void removeInterruptedReferenceGenomeDownloads() {
try {
for (ReferenceGenome genome : referenceGenomeService.getDownloadedGenomes()) {
if (genome.getDownloadProgress() < IProgressUpdater.MAX_PROGRESS) {
logger.warn("Removing genome that was interrupted: " + genome);
......@@ -91,14 +96,19 @@ public class StartupBean {
}
}
}
} catch (Exception e) {
logger.error("Problem with removing interrupted downloads...", e);
}
}
/**
* Set {@link ProjectStatus#FAIL} statuses to projects that were uploading
* when application was shutdown.
* Set {@link ProjectStatus#FAIL} statuses to projects that were uploading when
* application was shutdown.
*/
private void setInterruptedProjectsStatuses() {
for (Project project : projectDao.getAll()) {
try {
for (Project project : projectService.getAllProjects()) {
if (!ProjectStatus.DONE.equals(project.getStatus()) && !ProjectStatus.FAIL.equals(project.getStatus())) {
String errors = project.getErrors();
if (errors == null || errors.trim().isEmpty()) {
......@@ -106,13 +116,17 @@ public class StartupBean {
} else {
errors = errors.trim() + "\n";
}
errors += "Project uploading was interrupted by application restart (at the stage: " + project.getStatus() + ").";
errors += "Project uploading was interrupted by application restart (at the stage: " + project.getStatus()
+ ").";
project.setStatus(ProjectStatus.FAIL);
project.setErrors(errors);
projectDao.update(project);
projectService.updateProject(project);
logger.info("Status of project: " + project.getProjectId() + " changed to fail. Errors: " + errors);
}
}
} catch (Exception e) {
logger.error("Problem with changing project status ...", e);
}
}
/**
......@@ -149,19 +163,12 @@ public class StartupBean {
this.referenceGenomeService = referenceGenomeService;
}
/**
* @return the projectDao
* @see #projectDao
*/
public ProjectDao getProjectDao() {
return projectDao;
public IProjectService getProjectService() {
return projectService;
}
/**
* @param projectDao the projectDao to set
* @see #projectDao
*/
public void setProjectDao(ProjectDao projectDao) {
this.projectDao = projectDao;
public void setProjectService(IProjectService projectService) {
this.projectService = projectService;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment