2017-11-27 14:40:16 +01:00
|
|
|
package rest.entities;
|
|
|
|
|
2017-11-30 11:10:42 +01:00
|
|
|
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;
|
2017-11-30 11:10:42 +01:00
|
|
|
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;
|
2017-11-30 11:10:42 +01:00
|
|
|
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
|
|
|
|
2017-11-30 11:10:42 +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;
|
2017-11-30 11:10:42 +01:00
|
|
|
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 {
|
|
|
|
|
2017-11-30 11:10:42 +01:00
|
|
|
@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{
|
2017-11-30 11:10:42 +01:00
|
|
|
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){
|
2017-11-30 11:10:42 +01:00
|
|
|
ex.printStackTrace();
|
2017-11-27 14:40:16 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"reason\":\""+ex.getMessage()+"\"}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 11:10:42 +01:00
|
|
|
@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
|
|
|
}
|