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

transaction was not available during loading war file in tomcat

parent 6959d58e
No related branches found
No related tags found
1 merge request!202Resolve "tomcat deployment init db error"
Pipeline #
...@@ -1459,26 +1459,26 @@ public class ProjectService implements IProjectService { ...@@ -1459,26 +1459,26 @@ public class ProjectService implements IProjectService {
userService.updateUser(dbUser); userService.updateUser(dbUser);
user.setAnnotationSchema(annotationSchema); user.setAnnotationSchema(annotationSchema);
} }
@Override @Override
public List<UserAnnotatorsParam> getAnnotatorsParams(User user) { public List<UserAnnotatorsParam> getAnnotatorsParams(User user) {
User dbUser = userDao.getById(user.getId()); User dbUser = userDao.getById(user.getId());
UserAnnotationSchema annotationSchema = dbUser.getAnnotationSchema(); UserAnnotationSchema annotationSchema = dbUser.getAnnotationSchema();
if (annotationSchema == null) { if (annotationSchema == null) {
annotationSchema = new UserAnnotationSchema(); annotationSchema = new UserAnnotationSchema();
dbUser.setAnnotationSchema(annotationSchema); dbUser.setAnnotationSchema(annotationSchema);
} }
/* /*
* Hibernate lazy loads collections so each element needs to be accessed * Hibernate lazy loads collections so each element needs to be accessed to be
* to be loaded now or otherwise the data might not be available * loaded now or otherwise the data might not be available when accessed because
* when accessed because the session might not be available at that time. * the session might not be available at that time.
*/ */
List<UserAnnotatorsParam> aps = new ArrayList<>(); List<UserAnnotatorsParam> aps = new ArrayList<>();
for (UserAnnotatorsParam ap: annotationSchema.getAnnotatorsParams()){ for (UserAnnotatorsParam ap : annotationSchema.getAnnotatorsParams()) {
aps.add(ap); aps.add(ap);
} }
return aps; return aps;
} }
/** /**
...@@ -1627,4 +1627,9 @@ public class ProjectService implements IProjectService { ...@@ -1627,4 +1627,9 @@ public class ProjectService implements IProjectService {
this.taxonomyBackend = taxonomyBackend; this.taxonomyBackend = taxonomyBackend;
} }
@Override
public List<Project> getAllProjects() {
return projectDao.getAll();
}
} }
...@@ -22,180 +22,184 @@ import lcsb.mapviewer.services.view.ProjectView; ...@@ -22,180 +22,184 @@ import lcsb.mapviewer.services.view.ProjectView;
*/ */
public interface IProjectService { public interface IProjectService {
/** /**
* Returns a project with a give {@link Project#projectId project identifier}. * Returns a project with a give {@link Project#projectId project identifier}.
* *
* @param projectId * @param projectId
* {@link Project#projectId project identifier} * {@link Project#projectId project identifier}
* @return project with an identifier given as parameter. Null if such project * @return project with an identifier given as parameter. Null if such project
* doesn't exist. * doesn't exist.
*/ */
Project getProjectByProjectId(String projectId, AuthenticationToken token) throws UserAccessException; Project getProjectByProjectId(String projectId, AuthenticationToken token) throws UserAccessException;
/** /**
* Checks if project with a given {@link Project#projectId identifier} exists. * Checks if project with a given {@link Project#projectId identifier} exists.
* *
* @param projectId * @param projectId
* {@link Project#projectId project identifier} * {@link Project#projectId project identifier}
* @return <code>true</code> if the project with the given name exists, * @return <code>true</code> if the project with the given name exists,
* <code>false</code> otherwise * <code>false</code> otherwise
*/ */
boolean projectExists(String projectId); boolean projectExists(String projectId);
/** /**
* Returns list of all projects. * Returns list of all projects.
* *
* @return list of all projects. * @return list of all projects.
*/ */
List<Project> getAllProjects(AuthenticationToken token); List<Project> getAllProjects(AuthenticationToken token);
/** /**
* Returns a list of Project views for all projects. * Returns a list of Project views for all projects.
* *
* @return list of Project views for all projects * @return list of Project views for all projects
*/ */
List<ProjectView> getAllProjectViews(AuthenticationToken token); List<ProjectView> getAllProjectViews(AuthenticationToken token);
/** /**
* Updates project. * Updates project.
* *
* @param projectView * @param projectView
* project view with the data to update * project view with the data to update
*/ */
void updateProject(ProjectView projectView); void updateProject(ProjectView projectView);
/** /**
* Removes project from the system. * Removes project from the system.
* *
* @param homeDir * @param homeDir
* directory where the system is deployed * directory where the system is deployed
* *
* @param projectView * @param projectView
* information about project to remove * information about project to remove
* @param async * @param async
* should the operation be done asynchronously * should the operation be done asynchronously
* @throws UserAccessException * @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. /**
* * Removes project from the system.
* @param homeDir *
* directory where the system is deployed * @param homeDir
* @param project * directory where the system is deployed
* object to remove * @param project
* @param async * object to remove
* should the operation be done asynchronously * @param async
* @throws UserAccessException * 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} * @param projectId
* @return view of the project * {@link Project#projectId project identifier}
* @throws UserAccessException * @return view of the project
*/ * @throws UserAccessException
ProjectView getProjectViewByProjectId(String projectId, AuthenticationToken token) throws UserAccessException; */
ProjectView getProjectViewByProjectId(String projectId, AuthenticationToken token) throws UserAccessException;
/**
* Adds project to the system. /**
* * Adds project to the system.
* @param project *
* object to add * @param project
*/ * object to add
void addProject(Project project); */
void addProject(Project project);
/**
* Return the view of the project identified by database identifier. /**
* * Return the view of the project identified by database identifier.
* @param id *
* database identifier of the project * @param id
* @return project view * database identifier of the project
* @throws UserAccessException * @return project view
*/ * @throws UserAccessException
ProjectView getProjectViewById(Integer id, AuthenticationToken token) throws UserAccessException; */
ProjectView getProjectViewById(Integer id, AuthenticationToken token) throws UserAccessException;
/**
* Creates project using give parameters. See {@link CreateProjectParams}. /**
* * Creates project using give parameters. See {@link CreateProjectParams}.
* @param params *
* information about project to create * @param params
* @throws SecurityException * information about project to create
*/ * @throws SecurityException
void createProject(CreateProjectParams params) throws SecurityException; */
void createProject(CreateProjectParams params) throws SecurityException;
/**
* Creates empty {@link ProjectView}. /**
* * Creates empty {@link ProjectView}.
* @return empty {@link ProjectView} *
*/ * @return empty {@link ProjectView}
ProjectView createEmpty(); */
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
* {@link lcsb.mapviewer.annotation.services.annotators.ElementAnnotator * be annotated and associate set of
* ElementAnnotator} valid for these classes. * {@link lcsb.mapviewer.annotation.services.annotators.ElementAnnotator
* * ElementAnnotator} valid for these classes.
* @param user *
* for which information should be retrieved * @param user
* @return {@link TreeNode} that contains information about all classes that * for which information should be retrieved
* can be annotated * @return {@link TreeNode} that contains information about all classes that can
*/ * be annotated
TreeNode createClassAnnotatorTree(User user); */
TreeNode createClassAnnotatorTree(User user);
/**
* Update default set of annotators, lists of required/valid annotations for a /**
* given user and default params used when creating project. * Update default set of annotators, lists of required/valid annotations for a
* * given user and default params used when creating project.
* @param user *
* user for which we updte information * @param user
* @param sbgnFormat * user for which we updte information
* new * @param sbgnFormat
* {@link lcsb.mapviewer.model.user.UserAnnotationSchema#sbgnFormat} * new
* value * {@link lcsb.mapviewer.model.user.UserAnnotationSchema#sbgnFormat}
* @param networkLayoutAsDefault * value
* new * @param networkLayoutAsDefault
* {@link lcsb.mapviewer.model.user.UserAnnotationSchema#networkLayoutAsDefault} * new
* value * {@link lcsb.mapviewer.model.user.UserAnnotationSchema#networkLayoutAsDefault}
* @param annotatorsTree * value
* {@link TreeNode} that contains information about all classes that * @param annotatorsTree
* can be annotated * {@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.
* /**
* @param project * Method that updates information about raw {@link Project} object.
* project to update *
*/ * @param project
void updateProject(Project project); * project to update
*/
/** void updateProject(Project project);
* Returns content of the file that was used to create project given in the
* parameter. /**
* * Returns content of the file that was used to create project given in the
* @param projectView * parameter.
* view of the {@link Project} for which we are looking for an *
* original source file * @param projectView
* @return content of the file that was used to create project given in the * view of the {@link Project} for which we are looking for an original
* parameter * source file
*/ * @return content of the file that was used to create project given in the
byte[] getInputDataForProject(ProjectView projectView); * parameter
*/
UserAnnotationSchema prepareUserAnnotationSchema(User user); byte[] getInputDataForProject(ProjectView projectView);
/** UserAnnotationSchema prepareUserAnnotationSchema(User user);
* Retrieves list of annotators {@link UserAnnotatorsParam parameters}
* @return /**
* list of annotators parameters * Retrieves list of annotators {@link UserAnnotatorsParam parameters}
*/ *
List<UserAnnotatorsParam> getAnnotatorsParams(User user); * @return list of annotators parameters
*/
List<UserAnnotatorsParam> getAnnotatorsParams(User user);
List<Project> getAllProjects();
} }
...@@ -31,137 +31,144 @@ import lcsb.mapviewer.services.interfaces.IReferenceGenomeService; ...@@ -31,137 +31,144 @@ import lcsb.mapviewer.services.interfaces.IReferenceGenomeService;
@ApplicationScoped @ApplicationScoped
public class StartupBean { public class StartupBean {
/** /**
* Default class logger. * Default class logger.
*/ */
private final transient Logger logger = Logger.getLogger(StartupBean.class); private final transient Logger logger = Logger.getLogger(StartupBean.class);
/** /**
* Dao used to access information about projects. * Dao used to access information about projects.
* *
*/ */
@ManagedProperty(value = "#{ProjectDao}") @ManagedProperty(value = "#{ProjectService}")
private transient ProjectDao projectDao; private transient IProjectService projectService;
/** /**
* Service used to access configuration params from db. * Service used to access configuration params from db.
* *
* @see IProjectService * @see IProjectService
*/ */
@ManagedProperty(value = "#{ConfigurationService}") @ManagedProperty(value = "#{ConfigurationService}")
private transient IConfigurationService configurationService; private transient IConfigurationService configurationService;
/** /**
* Service used to access information about reference genomes. * Service used to access information about reference genomes.
* *
* @see IReferenceGenomeService * @see IReferenceGenomeService
*/ */
@ManagedProperty(value = "#{ReferenceGenomeService}") @ManagedProperty(value = "#{ReferenceGenomeService}")
private transient IReferenceGenomeService referenceGenomeService; private transient IReferenceGenomeService referenceGenomeService;
/** /**
* Method that process initial script of application. * Method that process initial script of application.
*/ */
@PostConstruct @PostConstruct
public void init() { public void init() {
logger.debug("Application startup script starts"); logger.debug("Application startup script starts");
try { setInterruptedProjectsStatuses();
setInterruptedProjectsStatuses(); modifyXFrameDomain();
Configuration.setxFrameDomain(configurationService.getConfigurationValue(ConfigurationElementType.X_FRAME_DOMAIN)); removeInterruptedReferenceGenomeDownloads();
logger.debug("Application startup script ends");
removeInterruptedReferenceGenomeDownloads(); }
} catch (Exception e) {
logger.error("Problem running init script...", e); private void modifyXFrameDomain() {
} try {
logger.debug("Application startup script ends"); Configuration
} .setxFrameDomain(configurationService.getConfigurationValue(ConfigurationElementType.X_FRAME_DOMAIN));
} catch (Exception e) {
/** logger.error("Problem with modyfing x frame domain...", e);
* Removes downloads of reference genomes that were interrupted by tomcat }
* restart. }
*/
private void removeInterruptedReferenceGenomeDownloads() { /**
for (ReferenceGenome genome : referenceGenomeService.getDownloadedGenomes()) { * Removes downloads of reference genomes that were interrupted by tomcat
if (genome.getDownloadProgress() < IProgressUpdater.MAX_PROGRESS) { * restart.
logger.warn("Removing genome that was interrupted: " + genome); */
try { private void removeInterruptedReferenceGenomeDownloads() {
referenceGenomeService.removeGenome(genome); try {
} catch (IOException e) { for (ReferenceGenome genome : referenceGenomeService.getDownloadedGenomes()) {
logger.error("Problem with removing genome: " + genome); if (genome.getDownloadProgress() < IProgressUpdater.MAX_PROGRESS) {
} logger.warn("Removing genome that was interrupted: " + genome);
} try {
} referenceGenomeService.removeGenome(genome);
} } catch (IOException e) {
logger.error("Problem with removing genome: " + genome);
/** }
* Set {@link ProjectStatus#FAIL} statuses to projects that were uploading }
* when application was shutdown. }
*/ } catch (Exception e) {
private void setInterruptedProjectsStatuses() { logger.error("Problem with removing interrupted downloads...", e);
for (Project project : projectDao.getAll()) { }
if (!ProjectStatus.DONE.equals(project.getStatus()) && !ProjectStatus.FAIL.equals(project.getStatus())) {
String errors = project.getErrors(); }
if (errors == null || errors.trim().isEmpty()) {
errors = ""; /**
} else { * Set {@link ProjectStatus#FAIL} statuses to projects that were uploading when
errors = errors.trim() + "\n"; * application was shutdown.
} */
errors += "Project uploading was interrupted by application restart (at the stage: " + project.getStatus() + ")."; private void setInterruptedProjectsStatuses() {
project.setStatus(ProjectStatus.FAIL); try {
project.setErrors(errors); for (Project project : projectService.getAllProjects()) {
projectDao.update(project); if (!ProjectStatus.DONE.equals(project.getStatus()) && !ProjectStatus.FAIL.equals(project.getStatus())) {
logger.info("Status of project: " + project.getProjectId() + " changed to fail. Errors: " + errors); String errors = project.getErrors();
} if (errors == null || errors.trim().isEmpty()) {
} errors = "";
} } else {
errors = errors.trim() + "\n";
/** }
* @return the configurationService errors += "Project uploading was interrupted by application restart (at the stage: " + project.getStatus()
* @see #configurationService + ").";
*/ project.setStatus(ProjectStatus.FAIL);
public IConfigurationService getConfigurationService() { project.setErrors(errors);
return configurationService; projectService.updateProject(project);
} logger.info("Status of project: " + project.getProjectId() + " changed to fail. Errors: " + errors);
}
/** }
* @param configurationService } catch (Exception e) {
* the configurationService to set logger.error("Problem with changing project status ...", e);
* @see #configurationService }
*/ }
public void setConfigurationService(IConfigurationService configurationService) {
this.configurationService = configurationService; /**
} * @return the configurationService
* @see #configurationService
/** */
* @return the referenceGenomeService public IConfigurationService getConfigurationService() {
* @see #referenceGenomeService return configurationService;
*/ }
public IReferenceGenomeService getReferenceGenomeService() {
return referenceGenomeService; /**
} * @param configurationService
* the configurationService to set
/** * @see #configurationService
* @param referenceGenomeService */
* the referenceGenomeService to set public void setConfigurationService(IConfigurationService configurationService) {
* @see #referenceGenomeService this.configurationService = configurationService;
*/ }
public void setReferenceGenomeService(IReferenceGenomeService referenceGenomeService) {
this.referenceGenomeService = referenceGenomeService; /**
} * @return the referenceGenomeService
* @see #referenceGenomeService
/** */
* @return the projectDao public IReferenceGenomeService getReferenceGenomeService() {
* @see #projectDao return referenceGenomeService;
*/ }
public ProjectDao getProjectDao() {
return projectDao; /**
} * @param referenceGenomeService
* the referenceGenomeService to set
/** * @see #referenceGenomeService
* @param projectDao the projectDao to set */
* @see #projectDao public void setReferenceGenomeService(IReferenceGenomeService referenceGenomeService) {
*/ this.referenceGenomeService = referenceGenomeService;
public void setProjectDao(ProjectDao projectDao) { }
this.projectDao = projectDao;
} public IProjectService getProjectService() {
return projectService;
}
public void setProjectService(IProjectService projectService) {
this.projectService = projectService;
}
} }
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