Ignore:
Timestamp:
Jan 17, 2011, 3:49:20 PM (13 years ago)
Author:
robert@…
Message:

Implemented trash in order to prevent deletion of data

Location:
trunk/grails-app/controllers/nl/tno/metagenomics
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/nl/tno/metagenomics/AssayController.groovy

    r3 r4  
    433433        }
    434434
    435         /**
    436          * Updates existing run
    437          */
    438         def updateRun = {
    439                 // load study with id specified by param.id
    440                 def assay = Assay.get(params.id as Long)
    441 
    442                 if (!assay) {
    443                         flash.message = "No assay found with id: $params.id"
    444                         redirect('action': 'errorPage')
    445                         return
    446                 }
    447 
    448                 if( !params.run_id ) {
    449                         flash.message = "No run id given"
    450                         redirect(action: 'show', id: params.id)
    451                         return
    452                 }
    453 
    454                 def run
    455 
    456                 try {
    457                         run = Run.findById( params.run_id as Long )
    458                 } catch( Exception e ) {
    459                         throw e
    460                         flash.message = "Incorrect run id given: "
    461                         redirect(action: 'show', id: params.id)
    462                         return
    463                 }
    464 
    465                 // Set properties to the run
    466                 params.parameterFile = params.editParameterFile
    467                 run.setPropertiesFromForm( params );
    468 
    469                 if( run.save() ) {
    470                         flash.message = "Run succesfully saved";
    471                 } else {
    472                         flash.error = "Run could not be saved: " + run.getErrors();
    473                 }
    474 
    475                 redirect( action: 'show', id: params.id)
    476         }
    477 
    478435        def errorPage = {
    479436                render "An error has occured. $flash.message"
  • trunk/grails-app/controllers/nl/tno/metagenomics/RunController.groovy

    r2 r4  
    77class RunController {
    88        def fileService
     9       
     10        /** 
     11         * Shows information about this run in dialog style
     12         */
     13        def show = {
     14                Run run = Run.get( params.id as long );
     15                Assay assay = Assay.get( params.assayId as long );
     16               
     17                if( !run ) {
     18                        render "Run not found";
     19                        return
     20                }
     21               
     22                if( !assay ) {
     23                        render "Assay not found";
     24                        return
     25                }
     26               
     27                [assay: assay, run: run]
     28        }
     29       
     30        /**
     31         * Shows a form to edit the specified run in dialog mode
     32         */
     33        def editForm = {
     34                Run run = Run.get( params.id as long );
     35                Assay assay = Assay.get( params.assayId as long );
     36               
     37                if( !run ) {
     38                        render "Run not found";
     39                        return
     40                }
     41               
     42                if( !assay ) {
     43                        render "Assay not found";
     44                        return
     45                }
     46               
     47                [assay: assay, run: run]
     48        }
    949       
    1050    def create = {
     
    2666                redirect( controller: "assay", action: "show", id: params.id )
    2767        }
     68       
     69        def update = {
     70                if( !params.assayId ) {
     71                        flash.error = "No assay id given"
     72                        redirect(controller: 'assay', action: 'errorpage')
     73                        return
     74                }
     75                def assay = Assay.get(params.assayId as Long)
     76               
     77                // load run with id specified by param.id
     78                if (!assay) {
     79                        flash.message = "No assay found with id: ${params.assayId}"
     80                        redirect(controller: 'assay', 'action': 'errorPage')
     81                        return
     82                }
     83
     84
     85                def run
     86
     87                try {
     88                        run = Run.get( params.id as Long );
     89                } catch( Exception e ) {
     90                        throw e
     91                        flash.message = "Incorrect run id given: "
     92                        redirect(controller: 'assay', action: 'show', id: params.assayId)
     93                        return
     94                }
     95
     96                // Set properties to the run
     97                params.parameterFile = params.editParameterFile
     98                run.setPropertiesFromForm( params );
     99
     100                if( run.save() ) {
     101                        flash.message = "Run succesfully saved";
     102                } else {
     103                        flash.error = "Run could not be saved: " + run.getErrors();
     104                }
     105
     106                redirect( controller: 'assay', action: 'show', id: params.assayId)
     107        }
     108       
     109        def delete = {
     110                Run run = Run.get( params.id as long );
     111
     112                // Don't remove runs for which data exists
     113                if( run.sequenceData?.size() ) {
     114                        flash.message = "Run could not be deleted because samples are associated with it.";
     115                        redirect( controller: "assay", action: "show", id: params.assayId )
     116                }
     117               
     118                // Remove all associations
     119                run.assays.each {
     120                        run.removeFromAssays( it );
     121                }
     122               
     123                def name = run.name
     124                run.delete();
     125                flash.message = "Run " + name + " has been deleted from the system."
     126
     127                redirect( controller: "assay", action: "show", id: params.assayId )
     128               
     129        }
    28130}
  • trunk/grails-app/controllers/nl/tno/metagenomics/StudyController.groovy

    r3 r4  
    55        def gscfService
    66        def fileService
     7        def trashService
    78       
    89        def index = {
     
    1617                fileService.cleanDirectory();
    1718               
     19                // Clean the trash if needed
     20                trashService.cleanTrash();
     21               
    1822                // Filter studies for the ones the user is allowed to see
    19                 def studies = Study.findAll();
    20                 [studies: studies.findAll { it.canRead( session.user ) }, gscfAddUrl: gscfService.urlAddStudy(), lastSynchronized: synchronizationService.lastFullSynchronization ]
     23                def studies = Study.list();
     24                [studies: studies.findAll { it.canRead( session.user ) },
     25                        gscfAddUrl: gscfService.urlAddStudy(),
     26                        lastSynchronized: synchronizationService.lastFullSynchronization ]
    2127        }
    2228
  • trunk/grails-app/controllers/nl/tno/metagenomics/integration/RestController.groovy

    r3 r4  
    343343                        render url as JSON
    344344                }
    345         }.metagenomics.baseURL
     345        }
    346346       
    347347        /***************************************************/
  • trunk/grails-app/controllers/nl/tno/metagenomics/integration/SynchronizeController.groovy

    r3 r4  
    1717                //              /synchronize    -> fails with an error, redirects to /study
    1818                //                      etc...
    19                 synchronizationService.lastFullSynchronization = new Date();
     19                // synchronizationService.lastFullSynchronization = new Date();
    2020                       
    2121                [ url: redirectUrl ]
     
    2727
    2828                synchronizationService.fullSynchronization();
    29                
     29
    3030                render "";
    3131        }
Note: See TracChangeset for help on using the changeset viewer.