no message

This commit is contained in:
Ioannis Kalyvas 2018-01-23 17:21:38 +02:00
parent d2f6f0d898
commit 76b4023f4a
29 changed files with 294 additions and 193 deletions

View File

@ -15,6 +15,7 @@ import eu.eudat.models.helpers.responses.*;
import eu.eudat.models.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.security.Principal;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import eu.eudat.validators.DataManagementPlanTableRequestValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@ -44,61 +45,80 @@ import eu.eudat.managers.DataManagementPlanManager;
@CrossOrigin
public class DMPs extends BaseController {
@Autowired
public DMPs(ApiContext apiContext){
super(apiContext);
}
@Autowired
public DMPs(ApiContext apiContext) {
super(apiContext);
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/getPaged" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) {
try {
DataTableData<DataManagementPlanListingModel> dataTable = new DataManagementPlanManager().getPaged(this.getApiContext(), dataManagementPlanTableRequest,principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(HttpStatus.OK).payload(dataTable));
@RequestMapping(method = RequestMethod.POST, value = {"/dmps/getPaged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) {
try {
DataTableData<DataManagementPlanListingModel> dataTable = new DataManagementPlanManager().getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/getSingle/{id}" }, produces="application/json")
public @ResponseBody ResponseEntity<ResponseItem<DataManagementPlan>> getSingle(@PathVariable String id,Principal principal) {
try {
eu.eudat.models.dmp.DataManagementPlan project = new DataManagementPlanManager().getSingle(this.getApiContext().getDatabaseRepository().getDmpDao(), id,principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(HttpStatus.OK).payload(project));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlan>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/createOrUpdate" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.dmp.DataManagementPlan dataManagementPlan, Principal principal) {
try{
DataManagementPlanManager.createOrUpdate(this.getApiContext(),dataManagementPlan,principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(HttpStatus.CREATED));
}catch (Exception ex){
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
}
@RequestMapping(method = RequestMethod.GET, value = {"/dmps/getSingle/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataManagementPlan>> getSingle(@PathVariable String id, Principal principal) {
try {
eu.eudat.models.dmp.DataManagementPlan dataManagementPlan = new DataManagementPlanManager().getSingle(this.getApiContext().getDatabaseRepository().getDmpDao(), id, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/dmps/createOrUpdate"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.dmp.DataManagementPlan dataManagementPlan, Principal principal) {
try {
DataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/dmps/clone/{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@PathVariable UUID id, @RequestBody eu.eudat.models.dmp.DataManagementPlan dataManagementPlan, Principal principal) {
try {
DataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/get" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<DataManagementPlan>>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria,Principal principal) {
try {
List<DataManagementPlan> dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagementPlan>>().status(HttpStatus.OK).payload(dataTable));
}
@RequestMapping(method = RequestMethod.POST, value = {"/dmps/get"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<DataManagementPlan>>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) {
try {
List<DataManagementPlan> dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagementPlan>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DataManagementPlan>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DataManagementPlan>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
}
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.controllers;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.security.Principal;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -31,11 +32,11 @@ public class DashBoardController extends BaseController{
try {
DashBoardStatistics statistics = new DashBoardManager().getStatistics(this.getApiContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getDatabaseRepository().getDmpDao()
, this.getApiContext().getDatabaseRepository().getProjectDao());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(HttpStatus.OK).payload(statistics));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DashBoardStatistics>().status(HttpStatus.INTERNAL_SERVER_ERROR).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
}

View File

@ -9,6 +9,7 @@ import javax.transaction.Transactional;
import eu.eudat.entities.DataRepository;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -51,13 +52,13 @@ public class DataRepositories extends BaseController{
public @ResponseBody ResponseEntity<ResponseItem<List<Map<String,String>>>> listExternalDataRepositories(@RequestParam(value="query", required=false) String query ){
try {
List<Map<String,String>> remoteRepos = this.getApiContext().getRemoteFetcher().getRepositories(query);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Map<String,String>>>().status(HttpStatus.OK).payload(remoteRepos));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Map<String,String>>>().status(ApiMessageCode.NO_MESSAGE).payload(remoteRepos));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<Map<String,String>>>().status(HttpStatus.INTERNAL_SERVER_ERROR).payload(null));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<Map<String,String>>>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()).payload(null));
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<Map<String,String>>>().status(HttpStatus.UNPROCESSABLE_ENTITY).payload(null));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<Map<String,String>>>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()).payload(null));
}
}

View File

@ -10,6 +10,7 @@ import eu.eudat.models.components.commons.datafield.AutoCompleteData;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.user.composite.DatasetProfile;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -53,11 +54,11 @@ public class DatasetProfileController extends BaseController{
Map<String,Object> properties = (Map<String, Object>)jobject.toMap();
datasetprofile.fromJsonObject(properties);
}
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetProfile>().status(HttpStatus.OK).payload(datasetprofile));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile));
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetProfile>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetProfile>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}

View File

@ -17,6 +17,7 @@ import eu.eudat.models.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -56,9 +57,9 @@ public class DatasetProfiles extends BaseController {
ResponseEntity<ResponseItem<List<DatasetProfileAutocompleteItem>>> get(@RequestBody DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) {
try {
List<DatasetProfileAutocompleteItem> datasetProfileAutocompleteItems = DatasetProfileManager.getWithCriteria(this.getApiContext().getDatabaseRepository().getDatasetProfileDao(), datasetProfileAutocompleteRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileAutocompleteItem>>().status(HttpStatus.OK).payload(datasetProfileAutocompleteItems));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileAutocompleteItem>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileAutocompleteItems));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DatasetProfileAutocompleteItem>>().status(HttpStatus.BAD_REQUEST));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DatasetProfileAutocompleteItem>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE));
}
}
@ -67,9 +68,9 @@ public class DatasetProfiles extends BaseController {
ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem) {
try {
DataTableData<DatasetProfileListingModel> datasetProfileTableData = DatasetProfileManager.getPaged(this.getApiContext().getDatabaseRepository().getDatasetProfileDao(), datasetProfileTableRequestItem);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(HttpStatus.OK).payload(datasetProfileTableData));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(HttpStatus.BAD_REQUEST));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE));
}
}
@ -78,9 +79,9 @@ public class DatasetProfiles extends BaseController {
ResponseEntity<ResponseItem<List<DatasetProfileListingModel>>> getAll() {
try {
List<DatasetProfileListingModel> datasetProfileTableData = DatasetProfileManager.getAll(this.getApiContext().getDatabaseRepository().getDatasetProfileDao());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileListingModel>>().status(HttpStatus.OK).payload(datasetProfileTableData));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DatasetProfileListingModel>>().status(HttpStatus.BAD_REQUEST));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DatasetProfileListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE));
}
}
}

View File

@ -17,6 +17,7 @@ import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.listingmodels.DatasetListingModel;
import eu.eudat.models.security.Principal;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -45,11 +46,11 @@ public class DatasetWizardController extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<List<DataManagentPlanListingModel>>> getUserDmps(@RequestBody DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, Principal principal) {
try {
List<DataManagentPlanListingModel> dataManagementPlans = DatasetWizardManager.getUserDmps(this.getApiContext().getDatabaseRepository().getDmpDao(), datasetWizardAutocompleteRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagentPlanListingModel>>().status(HttpStatus.OK).payload(dataManagementPlans));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagentPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlans));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DataManagentPlanListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DataManagentPlanListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -57,11 +58,11 @@ public class DatasetWizardController extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<List<AssociatedProfile>>> getAvailableProfiles(@RequestBody DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest, Principal principal) {
try {
List<AssociatedProfile> dataManagementPlans = DatasetWizardManager.getAvailableProfiles(this.getApiContext().getDatabaseRepository().getDmpDao(), datasetProfileWizardAutocompleteRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<AssociatedProfile>>().status(HttpStatus.OK).payload(dataManagementPlans));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<AssociatedProfile>>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlans));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<AssociatedProfile>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<AssociatedProfile>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -69,10 +70,10 @@ public class DatasetWizardController extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<DatasetWizardModel>> getPaged(@PathVariable String id, Principal principal) {
try {
DatasetWizardModel dataset = new DatasetManager().getSingle(this.getApiContext().getDatabaseRepository().getDatasetDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(HttpStatus.OK).payload(dataset));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DatasetWizardModel>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -81,10 +82,10 @@ public class DatasetWizardController extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<Dataset>> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) {
try {
eu.eudat.entities.Dataset dataset = DatasetManager.createOrUpdate(this.getApiContext(), profile);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Dataset>().status(HttpStatus.OK).payload(dataset));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dataset));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Dataset>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Dataset>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
}

View File

@ -15,6 +15,7 @@ import eu.eudat.models.helpers.responses.*;
import eu.eudat.models.listingmodels.DatasetListingModel;
import eu.eudat.models.security.Principal;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -42,11 +43,11 @@ public class Datasets extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<DatasetListingModel>>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) {
try {
DataTableData<DatasetListingModel> dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.OK).payload(dataTable));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DatasetListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -55,11 +56,11 @@ public class Datasets extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<Dataset>> makePublic(@PathVariable UUID id, Principal principal) {
try {
DatasetManager.makePublic(this.getApiContext().getDatabaseRepository().getDatasetDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(HttpStatus.OK).message("Dataset Has Been Made Public"));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Dataset Has Been Made Public"));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Dataset>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Dataset>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}

View File

@ -14,6 +14,7 @@ import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectCriteriaRequest;
import eu.eudat.models.security.Principal;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -38,11 +39,11 @@ public class ExternalDatasets extends BaseController{
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<ExternalDatasetListingModel>>> getPaged(@RequestBody ExternalDatasetTableRequest datasetTableRequest, Principal principal) {
try {
DataTableData<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getPaged(this.getApiContext().getDatabaseRepository().getExternalDatasetDao(), datasetTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<ExternalDatasetListingModel>>().status(HttpStatus.OK).payload(dataTable));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<ExternalDatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<ExternalDatasetListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<ExternalDatasetListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -50,10 +51,10 @@ public class ExternalDatasets extends BaseController{
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalDatasetListingModel>>> getWithExternal(@RequestParam(value = "query", required = false) String query, Principal principal) {
try {
List<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getWithExternal(this.getApiContext().getDatabaseRepository().getExternalDatasetDao(), query, this.getApiContext().getRemoteFetcher());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalDatasetListingModel>>().payload(dataTable).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalDatasetListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<ExternalDatasetListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<ExternalDatasetListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -61,10 +62,10 @@ public class ExternalDatasets extends BaseController{
public @ResponseBody ResponseItem<ExternalDatasetListingModel> getWithExternal(@PathVariable UUID id, Principal principal) {
try {
ExternalDatasetListingModel externalDatasetModel = new ExternalDatasetManager().getSingle(this.getApiContext().getDatabaseRepository().getExternalDatasetDao(), id);
return new ResponseItem<ExternalDatasetListingModel>().payload(externalDatasetModel ).status(HttpStatus.OK);
return new ResponseItem<ExternalDatasetListingModel>().payload(externalDatasetModel ).status(ApiMessageCode.NO_MESSAGE);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<ExternalDatasetListingModel>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
return new ResponseItem<ExternalDatasetListingModel>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage());
}
}
}

View File

@ -8,6 +8,7 @@ import eu.eudat.models.security.Principal;
import eu.eudat.security.CustomAuthenticationProvider;
import eu.eudat.security.validators.twitter.TwitterTokenValidator;
import eu.eudat.services.AuthenticationService;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -41,34 +42,34 @@ public class Login {
@RequestMapping(method = RequestMethod.POST, value = { "/externallogin" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<ResponseItem<Principal>> googleLogin(@RequestBody LoginInfo credentials) {
try {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(customAuthenticationProvider.authenticate(credentials)).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(customAuthenticationProvider.authenticate(credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
}catch (UnauthorisedException ex){
throw ex;
}
catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Principal>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/twitterRequestToken" }, produces="application/json")
public @ResponseBody ResponseEntity<ResponseItem<OAuthToken>> twitterRequestToken() {
try {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OAuthToken>().payload(this.twitterTokenValidator.getRequestToken()).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OAuthToken>().payload(this.twitterTokenValidator.getRequestToken()).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OAuthToken>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OAuthToken>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/me" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) {
try {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(this.authenticationService.Touch(principal.getToken())).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(this.authenticationService.Touch(principal.getToken())).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Principal>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -76,11 +77,11 @@ public class Login {
public @ResponseBody ResponseEntity<ResponseItem<Principal>> logout(Principal principal) {
try {
this.authenticationService.Logout(principal.getToken());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Principal>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
}

View File

@ -11,6 +11,7 @@ import eu.eudat.models.external.OrganisationsExternalSourcesModel;
import eu.eudat.models.external.ProjectsExternalSourcesModel;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -54,15 +55,15 @@ public class Organisations extends BaseController{
try {
List<Map<String,String>> remoteRepos = this.getApiContext().getRemoteFetcher().getOrganisations(query);
OrganisationsExternalSourcesModel projectsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.SUCCESS_MESSAGE));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("External Url Not Found"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("Huge Result Set"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
}catch (Exception ex){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<OrganisationsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}

View File

@ -18,6 +18,7 @@ import eu.eudat.models.project.ProjectCriteriaRequest;
import eu.eudat.models.project.ProjectListingModel;
import eu.eudat.models.security.Principal;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
@ -70,11 +71,11 @@ public class Projects extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<ProjectListingModel>>> getPaged(@Valid @RequestBody ProjectTableRequest projectTableRequest, Principal principal) {
try {
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new ProjectManager().getPaged(this.getApiContext().getDatabaseRepository().getProjectDao(), projectTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().payload(dataTable).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -82,10 +83,10 @@ public class Projects extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<eu.eudat.models.project.Project>> getSingle(@PathVariable String id, Principal principal) {
try {
eu.eudat.models.project.Project project = new ProjectManager().getSingle(this.getApiContext().getDatabaseRepository().getProjectDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.project.Project>().payload(project).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.project.Project>().payload(project).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.project.Project>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.project.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -95,9 +96,9 @@ public class Projects extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<Project>> addProject(@Valid @RequestBody eu.eudat.models.project.Project project, Principal principal) {
try {
ProjectManager.createOrUpdate(this.getApiContext().getDatabaseRepository().getProjectDao(), this.getApiContext().getDatabaseRepository().getUserInfoDao(), project, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -107,9 +108,9 @@ public class Projects extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<Project>> inactivate(@PathVariable String id, Principal principal) {
try {
Project project = new ProjectManager().inactivate(this.getApiContext().getDatabaseRepository().getProjectDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -118,10 +119,10 @@ public class Projects extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<List<eu.eudat.models.project.Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) {
try {
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteriaWithExternal(this.getApiContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getRemoteFetcher());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<eu.eudat.models.project.Project>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<eu.eudat.models.project.Project>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -129,10 +130,10 @@ public class Projects extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<List<eu.eudat.models.project.Project>>> get(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) {
try {
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteria(this.getApiContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getRemoteFetcher());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<eu.eudat.models.project.Project>>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<eu.eudat.models.project.Project>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
}
}
@ -141,13 +142,13 @@ public class Projects extends BaseController {
try {
List<Map<String, String>> remoteRepos = this.getApiContext().getRemoteFetcher().getProjects(query);
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ProjectsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ProjectsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (NoURLFound ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("External Url Not Found"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
} catch (HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("Huge Result Set"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}

View File

@ -9,6 +9,7 @@ import eu.eudat.models.external.RegistriesExternalSourcesModel;
import eu.eudat.models.external.ResearchersExternalSourcesModel;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -55,18 +56,18 @@ public class Registries extends BaseController{
try {
List<Map<String,String>> remoteRepos = this.getApiContext().getRemoteFetcher().getRegistries(query);
RegistriesExternalSourcesModel registriesExternalSourcesModel = new RegistriesExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<RegistriesExternalSourcesModel>().payload(registriesExternalSourcesModel).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<RegistriesExternalSourcesModel>().payload(registriesExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
}
catch(NoURLFound ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<RegistriesExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("External Url Not Found"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<RegistriesExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
}
catch(HugeResultSet ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<RegistriesExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("Huge Result Set"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<RegistriesExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
}catch (Exception ex){
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<RegistriesExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<RegistriesExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}

View File

@ -11,6 +11,7 @@ import eu.eudat.models.external.ResearchersExternalSourcesModel;
import eu.eudat.models.external.ServiceExternalSourcesModel;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -54,15 +55,15 @@ public class Researchers extends BaseController{
try {
List<Map<String,String>> remoteRepos = this.getApiContext().getRemoteFetcher().getResearchers(query);
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ResearchersExternalSourcesModel>().payload(researchersExternalSourcesModel).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ResearchersExternalSourcesModel>().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ResearchersExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("External Url Not Found"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ResearchersExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ResearchersExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("Huge Result Set"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ResearchersExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
}catch (Exception ex){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ResearchersExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ResearchersExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}

View File

@ -10,6 +10,7 @@ import eu.eudat.entities.Service;
import eu.eudat.models.external.ServiceExternalSourcesModel;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -53,15 +54,15 @@ public class Services extends BaseController{
try {
List<Map<String,String>> remoteRepos = this.getApiContext().getRemoteFetcher().getServices(query);
ServiceExternalSourcesModel serviceExternalSourcesModel = new ServiceExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ServiceExternalSourcesModel>().payload(serviceExternalSourcesModel).status(HttpStatus.OK));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ServiceExternalSourcesModel>().payload(serviceExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ServiceExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("External Url Not Found"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ServiceExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ServiceExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message("Huge Result Set"));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ServiceExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
}catch (Exception ex){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ServiceExternalSourcesModel>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ServiceExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}

View File

@ -8,6 +8,7 @@ import eu.eudat.models.security.Principal;
import eu.eudat.models.userinfo.UserInfoInvitationModel;
import eu.eudat.models.userinfo.UserInfoRequestItem;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -35,10 +36,10 @@ public class UserInvitationController extends BaseController{
public @ResponseBody ResponseEntity<ResponseItem<Invitation>> users(@RequestBody Invitation invitation, Principal principal) {
try {
InvitationsManager.inviteUsers(this.getApiContext(),invitation,principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Invitation>().status(HttpStatus.OK).message("Users have beeen invited"));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Invitation>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Users have beeen invited"));
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Invitation>().message(e.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Invitation>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage()));
}
}
@ -47,14 +48,14 @@ public class UserInvitationController extends BaseController{
public @ResponseBody ResponseEntity<ResponseItem<UUID>> exchange(@PathVariable UUID invitationID, Principal principal) {
try {
UUID dmpId = InvitationsManager.assignUserAcceptedInvitation(this.getApiContext(),invitationID,principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(HttpStatus.OK).payload(dmpId));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(dmpId));
}catch (UnauthorisedException e){
e.printStackTrace();
throw e;
}
catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<UUID>().message(e.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).message(e.getMessage()));
}
}
@ -62,10 +63,10 @@ public class UserInvitationController extends BaseController{
public @ResponseBody ResponseEntity<ResponseItem<List<UserInfoInvitationModel>>> getUsers(@RequestBody UserInfoRequestItem userInfoRequestItem) {
try {
List<UserInfoInvitationModel> users = InvitationsManager.getUsers(this.getApiContext(),userInfoRequestItem);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<UserInfoInvitationModel>>().status(HttpStatus.OK).payload(users));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<UserInfoInvitationModel>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(users));
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<UserInfoInvitationModel>>().status(HttpStatus.BAD_REQUEST).message(e.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<UserInfoInvitationModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(e.getMessage()));
}
}
}

View File

@ -43,9 +43,9 @@ public class DMP implements Serializable, DataEntity<DMP> {
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Type(type = "org.hibernate.type.PostgresUUIDType")
@Column(name = "\"Previous\"")
private UUID previous;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Previous\"")
private DMP previous;
@Column(name = "\"Label\"")
private String label;
@ -182,11 +182,11 @@ public class DMP implements Serializable, DataEntity<DMP> {
this.id = id;
}
public UUID getPrevious() {
public DMP getPrevious() {
return previous;
}
public void setPrevious(UUID previous) {
public void setPrevious(DMP previous) {
this.previous = previous;
}
@ -271,17 +271,4 @@ public class DMP implements Serializable, DataEntity<DMP> {
return new UUID[]{this.id == null ? null : this.id};
}
/*
public String toString() {
try {
return new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(this);
} catch (JsonProcessingException e) {
return "";
}
}
*/
}

View File

@ -20,7 +20,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@NamedEntityGraph(
name = "datasetListingModel",
attributeNodes = {@NamedAttributeNode("services"),@NamedAttributeNode("dataRepositories"),@NamedAttributeNode("registries"),
@NamedAttributeNode("dmp"),@NamedAttributeNode("profile")})
@NamedAttributeNode("dmp"),@NamedAttributeNode("profile"),@NamedAttributeNode("creator")})
})
public class Dataset implements DataEntity<Dataset> {

View File

@ -86,7 +86,7 @@ public class Transformers {
DMP dmp = new DMP();
dmp.setLabel(formData.getFirst("DMP.label"));
try {
dmp.setPrevious(UUID.fromString(formData.getFirst("DMP.previous")));
//dmp.setPrevious(UUID.fromString(formData.getFirst("DMP.previous")));
}catch(Exception ex) {/*do nothing*/}
dmp.setProfile(profile);
dmp.setAssociatedDmps(formData.getFirst("DMP.profileData"));

View File

@ -67,6 +67,19 @@ public class DataManagementPlanManager {
}
public static void clone(ApiContext apiContext, UUID uuid, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
DMP oldDmp = new DMP();
oldDmp.setId(uuid);
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getDatabaseRepository().getUserInfoDao().find(principal.getId());
createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user);
newDmp.setPrevious(oldDmp);
apiContext.getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
}
private static void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) {
if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) {
for (eu.eudat.entities.Researcher researcher : newDmp.getResearchers()) {

View File

@ -3,6 +3,7 @@ package eu.eudat.models.dmp;
import eu.eudat.entities.*;
import eu.eudat.models.DataModel;
import eu.eudat.models.project.Project;
import eu.eudat.models.userinfo.UserInfo;
import eu.eudat.utilities.builders.DomainModelConverter;
import eu.eudat.utilities.builders.XmlBuilder;
import org.w3c.dom.Document;
@ -14,10 +15,10 @@ import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
public class DataManagementPlan implements DataModel<DMP>{
public class DataManagementPlan implements DataModel<DMP> {
private UUID id;
private String label;
private UUID previous;
private DataManagementPlan previous;
private int version;
private int status;
private String description;
@ -25,8 +26,10 @@ public class DataManagementPlan implements DataModel<DMP>{
private eu.eudat.models.project.Project project;
private List<Organisation> organisations;
private List<Researcher> researchers;
private List<UserInfo> associatedUsers;
private eu.eudat.models.userinfo.UserInfo creator;
private Date created;
public UUID getId() {
return id;
}
@ -43,14 +46,22 @@ public class DataManagementPlan implements DataModel<DMP>{
this.label = label;
}
public UUID getPrevious() {
public DataManagementPlan getPrevious() {
return previous;
}
public void setPrevious(UUID previous) {
public void setPrevious(DataManagementPlan previous) {
this.previous = previous;
}
public List<UserInfo> getAssociatedUsers() {
return associatedUsers;
}
public void setAssociatedUsers(List<UserInfo> associatedUsers) {
this.associatedUsers = associatedUsers;
}
public int getVersion() {
return version;
}
@ -92,12 +103,12 @@ public class DataManagementPlan implements DataModel<DMP>{
}
public eu.eudat.models.userinfo.UserInfo getCreator() {
return creator;
}
return creator;
}
public void setCreator(eu.eudat.models.userinfo.UserInfo creator) {
this.creator = creator;
}
public void setCreator(eu.eudat.models.userinfo.UserInfo creator) {
this.creator = creator;
}
public List<AssociatedProfile> getProfiles() {
return profiles;
@ -126,56 +137,59 @@ public class DataManagementPlan implements DataModel<DMP>{
@Override
public void fromDataModel(DMP entity) throws InstantiationException, IllegalAccessException {
this.id = entity.getId();
this.organisations =new DomainModelConverter<eu.eudat.entities.Organisation,Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class);
this.researchers =new DomainModelConverter<eu.eudat.entities.Researcher,Researcher>().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()),Researcher.class);
this.organisations = new DomainModelConverter<eu.eudat.entities.Organisation, Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()), Organisation.class);
this.researchers = new DomainModelConverter<eu.eudat.entities.Researcher, Researcher>().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()), Researcher.class);
this.version = entity.getVersion();
this.previous = entity.getPrevious();
this.previous = this.previous == null ? null : new DomainModelConverter<DMP, DataManagementPlan>().fromDataModel(Arrays.asList(entity.getPrevious()), DataManagementPlan.class).get(0);
this.label = entity.getLabel();
this.project = new Project();
this.project.fromDataModel(entity.getProject());
this.creator = new eu.eudat.models.userinfo.UserInfo();
if(entity.getCreator()!=null)this.creator.fromDataModel(entity.getCreator());
if (entity.getCreator() != null) this.creator.fromDataModel(entity.getCreator());
if(entity.getAssociatedDmps()!=null&&!entity.getAssociatedDmps().isEmpty()){
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
Document viewStyleDoc = XmlBuilder.fromXml(entity.getAssociatedDmps());
Element item = (Element) viewStyleDoc.getElementsByTagName("profiles").item(0);
this.profiles = new LinkedList<>();
if(item!=null){
if (item != null) {
NodeList associatedProfilesElement = item.getChildNodes();
for (int temp = 0; temp < associatedProfilesElement.getLength(); temp++) {
Node associatedProfileElement = associatedProfilesElement.item(temp);
if (associatedProfileElement.getNodeType() == Node.ELEMENT_NODE) {
this.profiles.add(new AssociatedProfile().fromXml((Element)associatedProfileElement));
this.profiles.add(new AssociatedProfile().fromXml((Element) associatedProfileElement));
}
}
}
}
this.created = entity.getCreated();
this.description = entity.getDescription();
this.associatedUsers = new DomainModelConverter<eu.eudat.entities.UserInfo,UserInfo>().fromDataModel(entity.getUsers().stream().collect(Collectors.toList()),UserInfo.class);
}
@Override
public DMP toDataModel() throws Exception {
DMP dataManagementPlanEntity = new DMP();
dataManagementPlanEntity.setId(this.id);
if(this.organisations!=null&&!this.organisations.isEmpty())dataManagementPlanEntity.setOrganisations(new HashSet<eu.eudat.entities.Organisation>(new DomainModelConverter<eu.eudat.entities.Organisation,Organisation>().toDataModel(this.organisations)));
if(this.researchers!=null&&!this.researchers.isEmpty())dataManagementPlanEntity.setResearchers(new HashSet<eu.eudat.entities.Researcher>(new DomainModelConverter<eu.eudat.entities.Researcher,Researcher>().toDataModel(this.researchers)));
if (this.organisations != null && !this.organisations.isEmpty())
dataManagementPlanEntity.setOrganisations(new HashSet<eu.eudat.entities.Organisation>(new DomainModelConverter<eu.eudat.entities.Organisation, Organisation>().toDataModel(this.organisations)));
if (this.researchers != null && !this.researchers.isEmpty())
dataManagementPlanEntity.setResearchers(new HashSet<eu.eudat.entities.Researcher>(new DomainModelConverter<eu.eudat.entities.Researcher, Researcher>().toDataModel(this.researchers)));
dataManagementPlanEntity.setVersion(this.version);
dataManagementPlanEntity.setPrevious(this.previous);
dataManagementPlanEntity.setLabel(this.label);
if(this.project!=null)dataManagementPlanEntity.setProject(this.project.toDataModel());
dataManagementPlanEntity.setStatus((short)this.status);
if (this.project != null) dataManagementPlanEntity.setProject(this.project.toDataModel());
dataManagementPlanEntity.setStatus((short) this.status);
dataManagementPlanEntity.setDescription(this.description);
if(this.profiles!=null) {
if (this.profiles != null) {
Document associatedProfileDoc = XmlBuilder.getDocument();
Element associatedProfilesElement = associatedProfileDoc.createElement("profiles");
for(AssociatedProfile associatedProfile:this.profiles){
for (AssociatedProfile associatedProfile : this.profiles) {
associatedProfilesElement.appendChild(associatedProfile.toXml(associatedProfileDoc));
}
associatedProfileDoc.appendChild(associatedProfilesElement);
dataManagementPlanEntity.setAssociatedDmps(XmlBuilder.generateXml(associatedProfileDoc));
}
dataManagementPlanEntity.setCreated(this.created!=null?this.created:new Date());
dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
return dataManagementPlanEntity;
}

View File

@ -1,20 +1,21 @@
package eu.eudat.models.helpers.responses;
import eu.eudat.types.ApiMessageCode;
import org.springframework.http.HttpStatus;
/**
* Created by ikalyvas on 12/15/2017.
*/
public class ResponseItem<T> {
private HttpStatus statusCode;
private Integer statusCode;
private String message;
private T payload;
public HttpStatus getStatusCode() {
public Integer getStatusCode() {
return statusCode;
}
public void setStatusCode(HttpStatus statusCode) {
public void setStatusCode(Integer statusCode) {
this.statusCode = statusCode;
}
@ -34,8 +35,8 @@ public class ResponseItem<T> {
this.payload = payload;
}
public ResponseItem<T> status(HttpStatus statusCode){
this.statusCode = statusCode;
public ResponseItem<T> status(ApiMessageCode statusCode){
this.statusCode = statusCode.getValue();
return this;
}

View File

@ -23,6 +23,7 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
private String researchers;
private String organisations;
private String version;
private Integer numOfDatasets;
public String getId() {
return id;
@ -80,6 +81,14 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
this.version = version;
}
public Integer getNumOfDatasets() {
return numOfDatasets;
}
public void setNumOfDatasets(Integer numOfDatasets) {
this.numOfDatasets = numOfDatasets;
}
@Override
public void fromDataModel(DMP entity) throws InstantiationException, IllegalAccessException {
this.id = entity.getId().toString();
@ -89,6 +98,7 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
this.organisations =LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.Organisation,Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class));
this.researchers =LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.Researcher,Researcher>().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()),Researcher.class));
this.version = ""+entity.getVersion();
this.numOfDatasets = entity.getDataset().size();
}
@Override

View File

@ -162,8 +162,8 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project>
this.reference = entity.getReference();
this.uri = entity.getUri();
this.definition = entity.getDefinition();
this.startDate = entity.getStartdate().toString();
this.endDate = entity.getEnddate().toString();
this.startDate = entity.getStartdate() != null ? entity.getStartdate().toString() : null;
this.endDate = entity.getEnddate() != null ? entity.getEnddate().toString() : null;
this.setStatus(entity.getStatus());
this.created = entity.getCreated().toString();
this.modified = entity.getModified().toString();
@ -173,7 +173,7 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project>
@Override
public eu.eudat.entities.Project toDataModel() throws Exception {
throw new Exception("Not Implemented");
throw new Exception("Not Implemented");
}
@Override

View File

@ -0,0 +1,37 @@
package eu.eudat.types;
import eu.eudat.entities.Project;
/**
* Created by ikalyvas on 1/23/2018.
*/
public enum ApiMessageCode {
NO_MESSAGE(0),SUCCESS_MESSAGE(200), WARN_MESSAGE(300), ERROR_MESSAGE(400), DEFAULT_ERROR_MESSAGE(444);
private Integer value;
private ApiMessageCode(Integer value) {
this.value = value;
}
public Integer getValue() {
return value;
}
public static ApiMessageCode fromInteger(Integer value) {
switch (value) {
case 0:
return NO_MESSAGE;
case 200:
return SUCCESS_MESSAGE;
case 300:
return WARN_MESSAGE;
case 400:
return ERROR_MESSAGE;
case 444:
return DEFAULT_ERROR_MESSAGE;
default:
throw new RuntimeException("Unsupported Api Message Code");
}
}
}

View File

@ -19,10 +19,8 @@ public class ModelBuilder {
try {
list.add(item.toDatabaseDefinition(clazz.newInstance()));
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@ -35,10 +33,8 @@ public class ModelBuilder {
try {
list.add(item.toDatabaseDefinition(clazz.newInstance()));
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@ -53,10 +49,8 @@ public class ModelBuilder {
modelItem.fromDatabaseDefinition(item);
list.add(modelItem);
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

View File

@ -17,15 +17,15 @@ configuration.externalUrls=/classes/ExternalUrls.xml
########################/Email#############################
spring.mail.default-encoding=UTF-8
spring.mail.host=smtp.gmail.com
spring.mail.username=kalivasioan@gmail.com
spring.mail.password=A3b*1*92gianniskalyvas
spring.mail.username=citesagrdev@gmail.com
spring.mail.password=w3l0v3CITe
spring.mail.port=587
spring.mail.protocol=smtp
spring.mail.test-connection=false
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
mail.subject=Invitation to DMP Plan {dmpname}
mail.content=You have been invited to {dmpname} data management plan.Follow the link http://dl043.madgik.di.uoa.gr/invitation/{invitationID} to submit it
mail.content=You have been invited to {dmpname} data management plan.Follow the link http://dl043.madgik.di.uoa.gr:8080/invitation/{invitationID} to submit it
mail.from=citesagrdev@gmail.com
########################FACEBOOK LOGIN Properties#############################
facebook.login.clientId=110586756143149

View File

@ -13,8 +13,9 @@ export class SnackBarNotificationComponent {
}
parseMessage(message: any, language: TranslateService): void {
language.get(message).subscribe((value: string) => {
if(language) language.get(message).subscribe((value: string) => {
this.message = value;
});
else this.message = message;
}
}

View File

@ -1,3 +1,4 @@
import { ApiMessageCode } from '../types/ApiMessageCode';
import { Injectable } from '@angular/core';
import { Http, RequestOptions, Response, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
@ -67,8 +68,8 @@ export class BaseHttpService {
private interceptRepsonse<T>(observable: Observable<Object>): Observable<T> {
return observable
.catch((error) => {
if (error.status === 401) {
.catch((errorResponse) => {
if (errorResponse.status === 401) {
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
data: { message: 'GENERAL.SNACK-BAR.SUCCESSFUL-LOGOUT', language: this.language },
duration: 3000,
@ -79,17 +80,19 @@ export class BaseHttpService {
//this.notification.httpError(error);
return Observable.of<T>();
} else {
return Observable.throw(error);
return Observable.throw(errorResponse);
}
})
.map(response => {
if (response.statusCode < 200 || response.statusCode >= 300) {
if (response.statusCode = ApiMessageCode.SUCCESS_MESSAGE) {
//throw new Error('Request failed');
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
data: { message: 'GENERAL.ERRORS.HTTP-REQUEST-ERROR', language: this.language },
data: { message: response.message, language: null },
duration: 3000,
extraClasses: ['snackbar-warning']
extraClasses: ['snackbar-success']
})
return response.payload;
}
else {
return response.payload;

View File

@ -0,0 +1,7 @@
export enum ApiMessageCode {
NO_MESSAGE = 0,
SUCCESS_MESSAGE = 200,
WARN_MESSAGE = 300,
ERROR_MESSAGE = 400,
DEFAULT_ERROR_MESSAGE = 444
}