package rest.entities; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; import javax.transaction.Transactional; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.w3c.dom.Document; import org.w3c.dom.Element; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import dao.entities.DatasetProfileDao; import dao.entities.DatasetProfileRulesetDao; import dao.entities.DatasetProfileViewstyleDao; import entities.DatasetProfileViewstyle; import entities.xmlmodels.modeldefinition.FieldGroup; import entities.xmlmodels.viewstyledefinition.Section; import managers.AdminManager; import models.components.datasetprofile.FieldSet; import models.composite.DatasetProfile; import utilities.builders.ModelBuilder; import utilities.builders.XmlBuilder; import utilities.helpers.ModelBuilderCollector; @RestController @CrossOrigin public class Admin { @Autowired private DatasetProfileDao datasetProfileDao; @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; @Transactional @RequestMapping(method = RequestMethod.POST, value = { "/admin/addDmp" },consumes = "application/json", produces="application/json") public ResponseEntity addDmp(@RequestBody DatasetProfile profile){ try{ entities.DatasetProfile modelDefinition = AdminManager.generateModelDefinition(profile); entities.DatasetProfileViewstyle viewStyleDefinition = AdminManager.generateViewStyleDefinition(profile); viewStyleDefinition = datasetProfileViewstyleDao.create(viewStyleDefinition); modelDefinition.setViewstyle(viewStyleDefinition); datasetProfileDao.create(modelDefinition); return ResponseEntity.status(HttpStatus.OK).body(profile); }catch(Exception ex){ ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"reason\":\""+ex.getMessage()+"\"}"); } } @RequestMapping(method = RequestMethod.GET, value = { "/admin/get/{id}" }, produces="application/json") public ResponseEntity get(@PathVariable String id){ try{ entities.DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id)); models.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); return ResponseEntity.status(HttpStatus.OK).body(datasetprofile); }catch(Exception ex){ ex.printStackTrace(); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"reason\":\""+ex.getMessage()+"\"}"); } } }