Changeset 14 for trunk/grails-app/services/nl
- Timestamp:
- Feb 16, 2011, 2:24:56 PM (12 years ago)
- Location:
- trunk/grails-app/services/nl/tno/metagenomics
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/nl/tno/metagenomics/SampleExcelService.groovy
r13 r14 87 87 88 88 headers.eachWithIndex { header, idx -> 89 // Do matching using fuzzy search. The 0. 1treshold makes sure that no match if chosen if89 // Do matching using fuzzy search. The 0.8 treshold makes sure that no match if chosen if 90 90 // there is actually no match at all. 91 bestMatches[idx] = fuzzySearchService.mostSimilar( header, possibleFields, 0.1 ); 91 if( !header || header.toString().trim() == "" ) 92 bestMatches[idx] = null 93 else 94 bestMatches[idx] = fuzzySearchService.mostSimilar( header, possibleFields, 0.8 ); 92 95 } 93 96 … … 119 122 def dataMatches = false; 120 123 possibleFields.each { columnName -> 121 columns[ columnName ] = matchColumns.findIndexOf { it.value == columnName } 124 def foundColumn = matchColumns.find { it.value == columnName }; 125 126 columns[ columnName ] = ( foundColumn && foundColumn.key.toString().isInteger() ) ? Integer.valueOf( foundColumn.key.toString() ) : -1; 122 127 123 128 if( columnName != sampleNameName && columns[ columnName ] != -1 ) … … 125 130 } 126 131 132 println columns 133 127 134 // A column to match the sample name must be present 128 135 if( columns[ sampleNameName ] == -1 ) { 129 // Now delete the file, since we don't need it anymore130 _deleteUploadedFileFromSession()131 132 136 return [ success: false, message: "There must be a column present in the excel file that matches the sample name. Please try again." ] 133 137 } … … 135 139 // A column with data should also be present 136 140 if( !dataMatches ) { 137 // Now delete the file, since we don't need it anymore138 _deleteUploadedFileFromSession()139 140 141 return [ success: false, message: "There are no data columns present in the excel file. No samples are updated." ] 141 142 } … … 166 167 String sampleName = rowData[ columns[ sampleNameName ] ] as String 167 168 169 // If no sample name is found, the row is either empty or contains no sample name 170 if( !sampleName ) { 171 failedRows << [ row: rowData, sampleName: "" ]; 172 continue; 173 } 174 168 175 // Find assay by sample name. Since sample names are unique within an assay (enforced by GSCF), 169 176 // this will always work when only using one assay. When multiple assays are used, this might pose 170 177 // a problem 178 // TODO: Fix problem with multiple assays 171 179 AssaySample assaySample = assaySamples.find { it.sample.id == Sample.findByName( sampleName )?.id }; 180 println "Row: " + i + " - Sample name: " + sampleName + " - " + assaySample 172 181 173 182 // If no assaysample is found, add this row to the failed-row list -
trunk/grails-app/services/nl/tno/metagenomics/integration/GscfService.groovy
r13 r14 24 24 */ 25 25 public String urlAuthRemote( def params, def token ) { 26 def redirectURL = "${config.gscf.baseURL}/login/auth_remote?moduleURL=${this.moduleURL()}&consumer=${this.consumerID()}&token=${token}&returnUrl=${config.grails.serverURL}" 27 26 def redirectURL = "${config.gscf.baseURL}/login/auth_remote?moduleURL=${this.moduleURL()}&consumer=${this.consumerID()}&token=${token}&" 27 28 def returnUrl = config.grails.serverURL 28 29 if (params.controller != null){ 29 re directURL+= "/${params.controller}"30 returnUrl += "/${params.controller}" 30 31 if (params.action != null){ 31 re directURL+= "/${params.action}"32 returnUrl += "/${params.action}" 32 33 if (params.id != null){ 33 re directURL+= "/${params.id}"34 returnUrl += "/${params.id}" 34 35 } 35 36 } 36 37 } 37 38 38 return redirectURL 39 // Append other parameters 40 returnUrl += "?" + params.collect { 41 if( it.key != "controller" && it.key != "action" && it.key != "id" ) 42 return it.key.toString().encodeAsURL() + "=" + it.value.toString().encodeAsURL(); 43 else 44 return "" 45 }.findAll { it }.join( "&" ); 46 47 return redirectURL + "returnUrl=" + returnUrl.encodeAsURL(); 39 48 } 40 49 … … 65 74 * @return Map 66 75 */ 67 public Map getUser(String sessionToken) {76 public Map getUser(String sessionToken) throws Exception { 68 77 def user = [:] 69 this.callGSCF(sessionToken, "getUser").each { 70 user[ it.key ] = it.value; 71 } 72 return user 78 try { 79 this.callGSCF(sessionToken, "getUser").each { 80 user[ it.key ] = it.value; 81 } 82 return user 83 } catch( Exception e ) { 84 throw new Exception( "Retrieving user details from GSCF failed", e ); 85 } 73 86 } 74 87 … … 80 93 * @return ArrayList 81 94 */ 82 public ArrayList getStudies(String sessionToken) {95 public ArrayList getStudies(String sessionToken) throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 83 96 return this.callGSCF(sessionToken, "getStudies") 84 97 } … … 92 105 * @return ArrayList 93 106 */ 94 public ArrayList getStudies(String sessionToken, ArrayList studyTokens ) {107 public ArrayList getStudies(String sessionToken, ArrayList studyTokens ) throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 95 108 return this.callGSCF(sessionToken, "getStudies", [ "studyToken": studyTokens ] ); 96 109 } … … 104 117 * @return ArrayList 105 118 */ 106 public def getStudy(String sessionToken, String studyToken) throws NotAuthorizedException, ResourceNotFoundException{119 public def getStudy(String sessionToken, String studyToken) throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 107 120 def list 108 121 … … 131 144 * @return ArrayList 132 145 */ 133 public ArrayList getAssays(String sessionToken, String studyToken) throws NotAuthorizedException, ResourceNotFoundException{146 public ArrayList getAssays(String sessionToken, String studyToken) throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 134 147 try { 135 148 return this.callGSCF(sessionToken, "getAssays", ["studyToken": studyToken]) … … 150 163 * @return ArrayList 151 164 */ 152 public def getAssay(String sessionToken, String studyToken, String assayToken ) throws NotAuthorizedException, ResourceNotFoundException{165 public def getAssay(String sessionToken, String studyToken, String assayToken )throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 153 166 def list 154 167 try { … … 178 191 * @return ArrayList 179 192 */ 180 public def getSample(String sessionToken, String assayToken, String sampleToken) throws NotAuthorizedException, ResourceNotFoundException{193 public def getSample(String sessionToken, String assayToken, String sampleToken) throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 181 194 def list 182 195 … … 205 218 * @return ArrayList 206 219 */ 207 public ArrayList getSamples(String sessionToken, String assayToken) throws NotAuthorizedException, ResourceNotFoundException{220 public ArrayList getSamples(String sessionToken, String assayToken) throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 208 221 // Samples of a Study limited to a single Assay 209 222 try { … … 225 238 * @return ArrayList 226 239 */ 227 public def getSamples(String sessionToken, List sampleTokens) throws NotAuthorizedException, ResourceNotFoundException{240 public def getSamples(String sessionToken, List sampleTokens) throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 228 241 def list 229 242 … … 249 262 * @return ArrayList 250 263 */ 251 public HashMap getAuthorizationLevel(String sessionToken, String studyToken) throws ResourceNotFoundException{264 public HashMap getAuthorizationLevel(String sessionToken, String studyToken) throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 252 265 ArrayList list 253 266 -
trunk/grails-app/services/nl/tno/metagenomics/integration/SynchronizationService.groovy
r13 r14 67 67 } 68 68 } 69 70 // Append other parameters 71 returnUrl += "?" + params.collect { 72 if( it.key != "controller" && it.key != "action" && it.key != "id" ) 73 return it.key.toString().encodeAsURL() + "=" + it.value.toString().encodeAsURL(); 74 else 75 return "" 76 }.findAll { it }.join( "&" ); 77 69 78 if( timeForFullSynchronization() ) { 70 79 return ConfigurationHolder.config.grails.serverURL + "/synchronize/full?redirect=" + returnUrl.encodeAsURL() … … 91 100 * @return ArrayList List of studies or null if the synchronization has failed 92 101 */ 93 public ArrayList<Study> synchronizeStudies() throws NotAuthenticatedException, Exception {102 public ArrayList<Study> synchronizeStudies() throws BadRequestException, NotAuthenticatedException, NotAuthorizedException, ResourceNotFoundException, Exception { 94 103 if( !performSynchronization() ) 95 104 return Study.findAllWhereTrashcan(false) … … 140 149 // synchronizing and return null 141 150 log.error( "Exception occurred when fetching studies: " + e.getMessage() ) 142 throw new Exception( "Error while fetching studies", e)151 throw e 143 152 } 144 153
Note: See TracChangeset
for help on using the changeset viewer.