package rest.entities; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.json.JSONObject; 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.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import dao.entities.DatasetDao; import dao.entities.DatasetProfileDao; import dao.entities.DatasetProfileRulesetDao; import dao.entities.DatasetProfileViewstyleDao; import helpers.SerializerProvider; import managers.AdminManager; import managers.UserManager; import models.properties.PropertiesModel; @RestController @CrossOrigin public class DatasetProfileController { @Autowired private DatasetProfileDao datasetProfileDao; @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; @Autowired private DatasetDao datasetDao; @RequestMapping(method = RequestMethod.GET, value = { "/datasetprofile/get/{id}" }, produces="application/json") public ResponseEntity getSingle(@PathVariable String id){ try { entities.Dataset dataset = datasetDao.read(UUID.fromString(id)); models.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(dataset.getProfile()); datasetprofile.setStatus(dataset.getStatus()); if(dataset.getProperties()!=null){ JSONObject jobject = new JSONObject(dataset.getProperties()); Map properties = (Map)jobject.toMap(); datasetprofile.fromJsonObject(properties); } return ResponseEntity.status(HttpStatus.OK).body(datasetprofile); } catch(Exception ex) { ex.printStackTrace(); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); } } @RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/save/{id}" }, consumes="application/json",produces="application/json") public ResponseEntity postDataset(@PathVariable String id,@RequestBody PropertiesModel properties){ try { entities.Dataset dataset = datasetDao.read(UUID.fromString(id)); Map values = new HashMap(); properties.toMap(values); JSONObject jobject = new JSONObject(values); dataset.setProperties(jobject.toString()); dataset.setStatus((short)properties.getStatus()); datasetDao.update(dataset); return ResponseEntity.status(HttpStatus.OK).body(properties); } catch(Exception ex) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); } } }