/* * Copyright (c) 2012. The Genome Analysis Centre, Norwich, UK * MISO project contacts: Robert Davey, Mario Caccamo @ TGAC * ********************************************************************* * * This file is part of MISO. * * MISO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MISO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MISO. If not, see <http://www.gnu.org/licenses/>. * * ********************************************************************* */ package uk.ac.bbsrc.tgac.miso.webapp.controller; import java.io.IOException; import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import uk.ac.bbsrc.tgac.miso.core.data.*; import com.eaglegenomics.simlims.core.User; import uk.ac.bbsrc.tgac.miso.core.data.type.PlatformType; import uk.ac.bbsrc.tgac.miso.core.manager.RequestManager; import com.eaglegenomics.simlims.core.manager.SecurityManager; import uk.ac.bbsrc.tgac.miso.core.factory.DataObjectFactory; import uk.ac.bbsrc.tgac.miso.sqlstore.util.DbUtils; @Controller @RequestMapping("/experimentwizard") @SessionAttributes("experimentwizard") public class ExperimentWizardController { protected static final Logger log = LoggerFactory.getLogger(ExperimentWizardController.class); @Autowired private SecurityManager securityManager; @Autowired private RequestManager requestManager; @Autowired private DataObjectFactory dataObjectFactory; @Autowired private JdbcTemplate interfaceTemplate; public void setInterfaceTemplate(JdbcTemplate interfaceTemplate) { this.interfaceTemplate = interfaceTemplate; } public void setDataObjectFactory(DataObjectFactory dataObjectFactory) { this.dataObjectFactory = dataObjectFactory; } public void setRequestManager(RequestManager requestManager) { this.requestManager = requestManager; } public void setSecurityManager(SecurityManager securityManager) { this.securityManager = securityManager; } @ModelAttribute("studyTypes") public Collection<String> populateStudyTypes() throws IOException { return requestManager.listAllStudyTypes(); } @ModelAttribute("maxLengths") public Map<String, Integer> maxLengths() throws IOException { return DbUtils.getColumnSizes(interfaceTemplate, "Experiment"); } @ModelAttribute("platforms") public Collection<Platform> populatePlatforms() throws IOException { return requestManager.listAllPlatforms(); } public Collection<? extends Pool> populateAvailablePools(Experiment experiment) throws IOException { if (experiment.getPlatform() != null) { PlatformType platformType = experiment.getPlatform().getPlatformType(); ArrayList<Pool> pools = new ArrayList<Pool>(); for (Pool p : requestManager.listAllPoolsByPlatform(platformType)) { if (experiment.getPool() == null || !experiment.getPool().equals(p)) { pools.add(p); } Collections.sort(pools); } return pools; /* if (experiment.getPlatform().getPlatformType().equals(PlatformType.ILLUMINA)) { ArrayList<IlluminaPool> pools = new ArrayList<IlluminaPool>(); for (IlluminaPool p : requestManager.listAllIlluminaPools()) { if (experiment.getPool() == null || !experiment.getPool().equals(p)) { pools.add(p); } Collections.sort(pools); } return pools; } else if (experiment.getPlatform().getPlatformType().equals(PlatformType.LS454)) { ArrayList<LS454Pool> pools = new ArrayList<LS454Pool>(); for (LS454Pool p : requestManager.listAll454Pools()) { if (experiment.getPool() == null || !experiment.getPool().equals(p)) { pools.add(p); } Collections.sort(pools); } return pools; } else if (experiment.getPlatform().getPlatformType().equals(PlatformType.SOLID)) { ArrayList<SolidPool> pools = new ArrayList<SolidPool>(); for (SolidPool p : requestManager.listAllSolidPools()) { if (experiment.getPool() == null || !experiment.getPool().equals(p)) { pools.add(p); } Collections.sort(pools); } return pools; } else { return Collections.emptyList(); } */ } return requestManager.listAllPools(); } @RequestMapping(value = "/new/{projectId}", method = RequestMethod.GET) public ModelAndView newAssignedProject(@PathVariable Long projectId, ModelMap model) throws IOException { try { User user = securityManager.getUserByLoginName(SecurityContextHolder.getContext().getAuthentication().getName()); StringBuilder a = new StringBuilder(); StringBuilder b = new StringBuilder(); for (Platform platform : requestManager.listAllPlatforms()) { a.append("<option value=\"" + platform.getPlatformId() + "\">" + platform.getNameAndModel() + "</option>"); } for (String st : requestManager.listAllStudyTypes()) { b.append("<option value=\"" + st + "\">" + st + "</option>"); } model.put("projectId", projectId); model.put("platforms", a.toString()); model.put("studyTypes", b.toString()); return new ModelAndView("/pages/experimentWizard.jsp", model); } catch (IOException ex) { if (log.isDebugEnabled()) { log.debug("Failed to show experiment wizard", ex); } throw ex; } } }