2017-12-15 00:01:26 +01:00
package eu.eudat.controllers ;
2017-10-06 19:20:05 +02:00
import java.util.List ;
2017-11-22 10:50:47 +01:00
import java.util.Map ;
2017-10-12 14:02:41 +02:00
2017-12-19 15:09:49 +01:00
import eu.eudat.models.external.OrganisationsExternalSourcesModel ;
import eu.eudat.models.helpers.responses.ResponseItem ;
2018-01-04 10:32:39 +01:00
import eu.eudat.services.ApiContext ;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode ;
2017-10-06 19:20:05 +02:00
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.http.HttpStatus ;
import org.springframework.http.ResponseEntity ;
import org.springframework.web.bind.annotation.CrossOrigin ;
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.bind.annotation.ResponseBody ;
import org.springframework.web.bind.annotation.RestController ;
2017-12-15 00:01:26 +01:00
import eu.eudat.proxy.config.exceptions.HugeResultSet ;
import eu.eudat.proxy.config.exceptions.NoURLFound ;
2017-10-06 19:20:05 +02:00
@RestController
@CrossOrigin
2018-01-04 10:32:39 +01:00
public class Organisations extends BaseController {
@Autowired
public Organisations ( ApiContext apiContext ) {
super ( apiContext ) ;
}
2017-11-22 11:14:10 +01:00
@RequestMapping ( method = RequestMethod . GET , value = { " /external/organisations " } , produces = " application/json " )
2018-01-22 08:41:31 +01:00
public @ResponseBody ResponseEntity < ResponseItem < OrganisationsExternalSourcesModel > > listExternalOrganisations ( @RequestParam ( value = " query " , required = false ) String query ) {
2017-11-22 10:50:47 +01:00
try {
2018-01-04 10:32:39 +01:00
List < Map < String , String > > remoteRepos = this . getApiContext ( ) . getRemoteFetcher ( ) . getOrganisations ( query ) ;
2017-12-19 15:09:49 +01:00
OrganisationsExternalSourcesModel projectsExternalSourcesModel = new OrganisationsExternalSourcesModel ( ) . fromExternalItem ( remoteRepos ) ;
2018-01-23 16:21:38 +01:00
return ResponseEntity . status ( HttpStatus . OK ) . body ( new ResponseItem < OrganisationsExternalSourcesModel > ( ) . payload ( projectsExternalSourcesModel ) . status ( ApiMessageCode . SUCCESS_MESSAGE ) ) ;
2017-11-22 10:50:47 +01:00
}
catch ( NoURLFound ex ) {
2018-01-23 16:21:38 +01:00
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < OrganisationsExternalSourcesModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " External Url Not Found " ) ) ;
2017-11-22 10:50:47 +01:00
}
catch ( HugeResultSet ex ) {
2018-01-23 16:21:38 +01:00
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < OrganisationsExternalSourcesModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( " Huge Result Set " ) ) ;
2017-12-19 15:09:49 +01:00
} catch ( Exception ex ) {
2018-01-23 16:21:38 +01:00
return ResponseEntity . status ( HttpStatus . BAD_REQUEST ) . body ( new ResponseItem < OrganisationsExternalSourcesModel > ( ) . status ( ApiMessageCode . ERROR_MESSAGE ) . message ( ex . getMessage ( ) ) ) ;
2017-11-22 10:50:47 +01:00
}
}
2017-10-06 19:20:05 +02:00
}