Skip to content

Commit

Permalink
Numerious cleanups for Gemma Web [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Nov 9, 2024
1 parent 076e6e1 commit 75f3dc9
Show file tree
Hide file tree
Showing 76 changed files with 1,727 additions and 1,963 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ public interface BioMaterialDao extends BaseVoEnabledDao<BioMaterial, BioMateria
Collection<BioMaterial> findByFactor( ExperimentalFactor experimentalFactor );

/**
* @param bioMaterialId biomaterial id
* @return the experiment the biomaterial appears in
* Obtain all the experiments a biomaterial is used in.
*/
ExpressionExperiment getExpressionExperiment( Long bioMaterialId );
Collection<ExpressionExperiment> getExpressionExperiments( BioMaterial bm );

/**
* Thaw the given BioMaterial.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ public Collection<BioMaterial> findByFactor( ExperimentalFactor experimentalFact
}

@Override
public ExpressionExperiment getExpressionExperiment( Long bioMaterialId ) {
return ( ExpressionExperiment ) this.getSessionFactory().getCurrentSession().createQuery(
"select distinct e from ExpressionExperiment e inner join e.bioAssays ba inner join ba.sampleUsed bm where bm.id =:bmid " )
.setParameter( "bmid", bioMaterialId ).uniqueResult();
public Collection<ExpressionExperiment> getExpressionExperiments( BioMaterial bm ) {
//noinspection unchecked
return ( List<ExpressionExperiment> ) this.getSessionFactory().getCurrentSession()
.createQuery( "select distinct e from ExpressionExperiment e join e.bioAssays ba join ba.sampleUsed bm where bm = :bm " )
.setParameter( "bm", bm )
.list();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import ubic.gemma.persistence.service.BaseVoEnabledService;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Map;

Expand Down Expand Up @@ -81,8 +82,9 @@ public interface BioMaterialService extends BaseService<BioMaterial>, BaseVoEnab
@Secured({ "GROUP_USER", "ACL_SECURABLE_EDIT" })
void update( BioMaterial bioMaterial );

@Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_READ" })
ExpressionExperiment getExpressionExperiment( Long id );
@Nullable
@Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "AFTER_ACL_COLLECTION_READ" })
Collection<ExpressionExperiment> getExpressionExperiments( BioMaterial bm );

@CheckReturnValue
@Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "ACL_SECURABLE__READ" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public Collection<BioMaterial> findByFactor( ExperimentalFactor experimentalFact

@Override
@Transactional(readOnly = true)
public ExpressionExperiment getExpressionExperiment( Long id ) {
return this.bioMaterialDao.getExpressionExperiment( id );
public Collection<ExpressionExperiment> getExpressionExperiments( BioMaterial bm ) {
return this.bioMaterialDao.getExpressionExperiments( bm );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public DatabaseBackedGeneSetValueObject loadValueObject( GeneSet geneSet ) {
@Override
public DatabaseBackedGeneSetValueObject loadValueObjectById( Long id ) {
DatabaseBackedGeneSetValueObject vo = loadValueObjectByIdLite( id );
fillGeneIds( Collections.singletonList( vo ) );
if ( vo != null ) {
fillGeneIds( Collections.singletonList( vo ) );
}
return vo;
}

Expand Down
3 changes: 2 additions & 1 deletion gemma-rest/src/main/resources/restapidocs/index.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true" %>
<jsp:useBean id="appConfig" scope="application" type="java.util.Map" />
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,7 @@ public ModelAndView showArrayDesignByName( @RequestParam("name") String name ) {

private ModelAndView showArrayDesignInternal( ArrayDesign arrayDesign ) {
return new ModelAndView( "arrayDesign.detail" )
.addObject( "arrayDesignId", arrayDesign.getId() )
.addObject( "arrayDesignShortName", arrayDesign.getShortName() )
.addObject( "arrayDesignName", arrayDesign.getName() );
.addObject( "arrayDesign", arrayDesign );
}

@RequestMapping(value = "/showCompositeSequenceSummary.html", method = { RequestMethod.GET, RequestMethod.HEAD })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package ubic.gemma.web.controller.expression.bioAssay;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -38,7 +37,6 @@
import ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService;
import ubic.gemma.web.util.EntityNotFoundException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -66,6 +64,15 @@ public class BioAssayController {
@Autowired
private OutlierDetectionService outlierDetectionService;

@RequestMapping(value = { "/showBioAssay.html", "/" }, method = { RequestMethod.GET, RequestMethod.HEAD })
public ModelAndView show( @RequestParam("id") Long id ) {
BioAssay bioAssay = bioAssayService.loadOrFail( id, EntityNotFoundException::new );
bioAssay = bioAssayService.thaw( bioAssay );
return new ModelAndView( "bioAssay.detail" )
.addObject( "bioAssay", new BioAssayValueObject( bioAssay, false ) );
}

@SuppressWarnings("unused") // Is used in EEManager.js
public Collection<BioAssayValueObject> getBioAssays( Long eeId ) {
ExpressionExperiment ee = eeService.loadAndThawLiteOrFail( eeId,
EntityNotFoundException::new, "Could not load experiment with ID=" + eeId );
Expand Down Expand Up @@ -94,39 +101,4 @@ public String markOutlier( Collection<Long> ids ) {
public String unmarkOutlier( Collection<Long> ids ) {
return taskRunningService.submitTaskCommand( new BioAssayOutlierProcessingTaskCommand( ids, true ) );
}

@RequestMapping(value = { "/showBioAssay.html", "/" }, method = { RequestMethod.GET, RequestMethod.HEAD })
public ModelAndView show( @RequestParam("id") Long id ) {
BioAssay bioAssay = bioAssayService.load( id );
if ( bioAssay == null ) {
throw new EntityNotFoundException( id + " not found" );
}
bioAssay = bioAssayService.thaw( bioAssay );
return new ModelAndView( "bioAssay.detail" )
.addObject( "bioAssay", new BioAssayValueObject( bioAssay, false ) );
}

@RequestMapping(value = "/showAllBioAssays.html", method = { RequestMethod.GET, RequestMethod.HEAD })
public ModelAndView showAllBioAssays( @RequestParam(value = "id", required = false) String sId ) {
Collection<BioAssay> bioAssays = new ArrayList<>();
if ( StringUtils.isBlank( sId ) ) {
/*
* Probably not desirable ... there are >380,000 of them
*/
bioAssays = bioAssayService.loadAll();
} else {
String[] idList = StringUtils.split( sId, ',' );
for ( String anIdList : idList ) {
Long id = Long.parseLong( anIdList );
BioAssay bioAssay = bioAssayService.load( id );
if ( bioAssay == null ) {
throw new EntityNotFoundException( id + " not found" );
}
bioAssay = bioAssayService.thaw( bioAssay );
bioAssays.add( bioAssay );
}
}
return new ModelAndView( "bioAssays" ).addObject( "bioAssays", bioAssays );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ public Collection<FactorValueValueObject> getFactorValues( EntityDelegator<BioMa
public ModelAndView show( @RequestParam("id") Long id ) {
BioMaterial bioMaterial = bioMaterialService.loadOrFail( id, EntityNotFoundException::new );
bioMaterial = bioMaterialService.thaw( bioMaterial );
return new ModelAndView( "bioMaterial.detail" ).addObject( "bioMaterial", bioMaterial )
.addObject( "expressionExperiment", bioMaterialService.getExpressionExperiment( id ) );
return new ModelAndView( "bioMaterial.detail" )
.addObject( "bioMaterial", bioMaterial )
.addObject( "expressionExperiments", bioMaterialService.getExpressionExperiments( bioMaterial ) );
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import java.text.NumberFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static ubic.gemma.core.analysis.preprocess.batcheffects.BatchEffectUtils.getBatchEffectStatistics;
import static ubic.gemma.core.analysis.preprocess.batcheffects.BatchEffectUtils.getBatchEffectType;
Expand Down Expand Up @@ -885,9 +886,9 @@ public ModelAndView showAllLinkSummaries() {
@RequestMapping(value = { "/showBioAssaysFromExpressionExperiment.html", "/bioAssays" }, method = { RequestMethod.GET, RequestMethod.HEAD })
public ModelAndView showBioAssays( @RequestParam("id") Long id ) {
ExpressionExperiment expressionExperiment = getExperimentById( id, true );
ModelAndView mv = new ModelAndView( "bioAssays" ).addObject( "bioAssays", bioAssayService.thaw( expressionExperiment.getBioAssays() ) );
ModelAndView mv = new ModelAndView( "expressionExperiment.bioAssays" )
.addObject( "expressionExperiment", expressionExperiment );
this.addQCInfo( expressionExperiment, mv );
mv.addObject( "expressionExperiment", expressionExperiment );
return mv;
}

Expand All @@ -904,15 +905,9 @@ public ModelAndView showBioMaterials( @RequestParam("id") Long id ) {
}
}

ModelAndView mav = new ModelAndView( "bioMaterials" );
if ( ExpressionExperimentController.AJAX ) {
mav.addObject( "bioMaterialIdList", bioMaterialService.getBioMaterialIdList( bioMaterials ) );
}

Integer numBioMaterials = bioMaterials.size();
mav.addObject( "numBioMaterials", numBioMaterials );
mav.addObject( "bioMaterials", bioMaterialService.thaw( bioMaterials ) );

ModelAndView mav = new ModelAndView( "expressionExperiment.bioMaterials" )
.addObject( "expressionExperiment", expressionExperiment )
.addObject( "bioMaterials", bioMaterialService.thaw( bioMaterials ) );
this.addQCInfo( expressionExperiment, mav );

return mav;
Expand Down Expand Up @@ -941,7 +936,8 @@ private ModelAndView showExpressionExperiment( ExpressionExperiment ee ) {
return new ModelAndView( "expressionExperiment.detail" )
.addObject( "expressionExperiment", ee )
.addObject( "eeId", ee.getId() )
.addObject( "eeClass", ee.getClass() );
.addObject( "eeClass", ee.getClass() )
.addObject( "annotations", expressionExperimentService.getAnnotations( ee ).stream().map( AnnotationValueObject::getTermName ).collect( Collectors.joining( "," ) ) );
}

/**
Expand All @@ -953,8 +949,8 @@ public ModelAndView showSubSet( @RequestParam("id") Long id ) {
if ( subset == null ) {
throw new EntityNotFoundException( "No experiment subset with ID " + id + "." );
}
// request.setAttribute( "id", id );
return new ModelAndView( "bioAssays" ).addObject( "bioAssays", subset.getBioAssays() );
return new ModelAndView( "bioAssaySet" )
.addObject( "bioAssaySet", subset );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import ubic.gemma.model.analysis.expression.ExpressionExperimentSet;
import ubic.gemma.model.expression.experiment.ExpressionExperimentDetailsValueObject;
Expand All @@ -39,7 +40,6 @@
import ubic.gemma.web.persistence.SessionListManager;
import ubic.gemma.web.util.EntityNotFoundException;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -343,22 +343,17 @@ public Collection<ExpressionExperimentSetValueObject> removeUserAndSessionGroups
}

@RequestMapping(value = "/showExpressionExperimentSet.html", method = { RequestMethod.GET, RequestMethod.HEAD })
public ModelAndView showExpressionExperimentSet( HttpServletRequest request ) {

ModelAndView mav = new ModelAndView( "expressionExperimentSet.detail" );
StopWatch timer = new StopWatch();
timer.start();

ExpressionExperimentSetValueObject eesvo = this.getExpressionExperimentSetFromRequest( request );

mav.addObject( "eeSetId", eesvo.getId() );
mav.addObject( "eeSetName", eesvo.getName() );

public ModelAndView showExpressionExperimentSet( @RequestParam("id") Long id ) {
StopWatch timer = StopWatch.createStarted();
ExpressionExperimentSetValueObject eesvo = expressionExperimentSetService.loadValueObjectById( id );
if ( eesvo == null ) {
throw new EntityNotFoundException( "No experiment set with ID " + id );
}
if ( timer.getTime() > 200 ) {
log.info( "Show experiment set was slow: id=" + eesvo.getId() + " " + timer.getTime() + "ms" );
}

return mav;
return new ModelAndView( "expressionExperimentSet.detail" )
.addObject( "eeSet", eesvo );
}

/**
Expand Down Expand Up @@ -454,31 +449,6 @@ private ExpressionExperimentSet create( ExpressionExperimentSetValueObject obj )
return expressionExperimentSetValueObjectHelper.create( obj );
}

/**
* @throws IllegalArgumentException if a matching EE can't be loaded
*/
private ExpressionExperimentSetValueObject getExpressionExperimentSetFromRequest( HttpServletRequest request ) {

ExpressionExperimentSetValueObject set;
Long id;

if ( request.getParameter( "id" ) != null ) {
try {
id = Long.parseLong( request.getParameter( "id" ) );
} catch ( NumberFormatException e ) {
throw new IllegalArgumentException( "You must provide a valid numerical identifier" );
}
set = expressionExperimentSetService.loadValueObjectById( id );

if ( set == null ) {
throw new EntityNotFoundException( "Unable to access experiment set with id=" + id );
}
} else {
throw new IllegalArgumentException( "You must provide an id" );
}
return set;
}

/**
* Delete a EEset from the system.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,8 @@ public ModelAndView show( HttpServletRequest request ) {
Long id = geneVO.getId();

assert id != null;
ModelAndView mav = new ModelAndView( "gene.detail" );
mav.addObject( "geneId", id );
mav.addObject( "geneOfficialSymbol", geneVO.getOfficialSymbol() );
mav.addObject( "geneOfficialName", geneVO.getOfficialName() );
mav.addObject( "geneNcbiId", geneVO.getNcbiId() );
mav.addObject( "geneTaxonCommonName", geneVO.getTaxonCommonName() );
mav.addObject( "geneTaxonId", geneVO.getTaxonId() );

return mav;
return new ModelAndView( "gene.detail" )
.addObject( "gene", geneVO );
}

@RequestMapping(value = "/downloadGeneList.html", method = { RequestMethod.GET, RequestMethod.HEAD })
Expand Down
Loading

0 comments on commit 75f3dc9

Please sign in to comment.