argos/dmp-backend/src/main/java/rest/entities/Admin.java

78 lines
3.1 KiB
Java
Raw Normal View History

2017-11-27 14:40:16 +01:00
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;
2017-11-27 14:40:16 +01:00
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
2017-11-27 14:40:16 +01:00
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;
2017-11-27 14:40:16 +01:00
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;
2017-11-27 14:40:16 +01:00
import models.composite.DatasetProfile;
import utilities.builders.ModelBuilder;
import utilities.builders.XmlBuilder;
import utilities.helpers.ModelBuilderCollector;
2017-11-27 14:40:16 +01:00
@RestController
@CrossOrigin
public class Admin {
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Transactional
2017-11-27 14:40:16 +01:00
@RequestMapping(method = RequestMethod.POST, value = { "/admin/addDmp" },consumes = "application/json", produces="application/json")
public ResponseEntity<Object> 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);
2017-11-27 14:40:16 +01:00
return ResponseEntity.status(HttpStatus.OK).body(profile);
}catch(Exception ex){
ex.printStackTrace();
2017-11-27 14:40:16 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"reason\":\""+ex.getMessage()+"\"}");
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/admin/get/{id}" }, produces="application/json")
public ResponseEntity<Object> 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()+"\"}");
}
}
2017-11-27 14:40:16 +01:00
}