no message

This commit is contained in:
annabakouli 2017-12-15 12:05:51 +02:00
parent 5f2f66bd71
commit 9a724100d0
22 changed files with 957 additions and 12 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
dmp-frontend/dist.7z dmp-frontend/dist.7z
.idea/ .idea/
*.iml

View File

@ -0,0 +1,14 @@
package eu.eudat;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Created by ikalyvas on 12/15/2017.
*/
@SpringBootApplication
public class EuDatApplication {
public static void main(String[] args) {
SpringApplication.run(EuDatApplication.class, args);
}
}

View File

@ -0,0 +1,72 @@
package eu.eudat.configurations;
/**
* Created by ikalyvas on 12/15/2017.
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.Properties;
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = {"eu.eudat.entities"})
public class DatabaseConfiguration {
@Autowired
private Environment env;
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[]{"eu.eudat.entities"});
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("database.driver-class-name"));
dataSource.setUrl(env.getProperty("database.url"));
dataSource.setUsername(env.getProperty("database.username"));
dataSource.setPassword(env.getProperty("database.password"));
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
private Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
properties.setProperty("hibernate.show_sql", "true");
return properties;
}
}

View File

@ -0,0 +1,51 @@
package eu.eudat.controllers;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import eu.eudat.dao.entities.DMPDao;
import eu.eudat.dao.entities.DMPProfileDao;
import eu.eudat.dao.entities.DataRepositoryDao;
import eu.eudat.dao.entities.DatasetDao;
import eu.eudat.dao.entities.DatasetProfileDao;
import eu.eudat.dao.entities.DatasetProfileRulesetDao;
import eu.eudat.dao.entities.DatasetProfileViewstyleDao;
import eu.eudat.dao.entities.OrganisationDao;
import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.dao.entities.RegistryDao;
import eu.eudat.dao.entities.ResearcherDao;
import eu.eudat.dao.entities.ServiceDao;
import eu.eudat.managers.DashBoardManager;
import eu.eudat.managers.UserManager;
import eu.eudat.models.dashboard.DashBoardStatistics;
@RestController
@CrossOrigin
public class DashBoardController {
@Autowired private DatasetDao datasetDao;
@Autowired private DMPDao dMPDao;
@Autowired private ProjectDao projectDao;
@RequestMapping(method = RequestMethod.GET, value = { "/dashboard/getStatistics" }, produces="application/json")
public ResponseEntity<DashBoardStatistics> getStatistics(){
try {
DashBoardStatistics statistics = new DashBoardManager().getStatistics(datasetDao, dMPDao, projectDao);
return ResponseEntity.status(HttpStatus.OK).body(statistics);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
}

View File

@ -0,0 +1,375 @@
package eu.eudat.controllers;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.MultiValueMap;
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 com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.dao.entities.DMPDao;
import eu.eudat.dao.entities.DMPProfileDao;
import eu.eudat.dao.entities.DataRepositoryDao;
import eu.eudat.dao.entities.DatasetDao;
import eu.eudat.dao.entities.DatasetProfileDao;
import eu.eudat.dao.entities.DatasetProfileRulesetDao;
import eu.eudat.dao.entities.DatasetProfileViewstyleDao;
import eu.eudat.dao.entities.OrganisationDao;
import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.dao.entities.RegistryDao;
import eu.eudat.dao.entities.ResearcherDao;
import eu.eudat.dao.entities.ServiceDao;
import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.entities.DMP;
import eu.eudat.entities.DMPProfile;
import eu.eudat.entities.DataRepository;
import eu.eudat.entities.Dataset;
import eu.eudat.entities.DatasetProfile;
import eu.eudat.entities.DatasetProfileRuleset;
import eu.eudat.entities.Organisation;
import eu.eudat.entities.Project;
import eu.eudat.entities.Registry;
import eu.eudat.entities.Researcher;
import eu.eudat.entities.Service;
import eu.eudat.entities.UserInfo;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.helpers.Transformers;
import eu.eudat.managers.ProjectManager;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.proxy.config.exceptions.HugeResultSet;
import eu.eudat.proxy.config.exceptions.NoURLFound;
import eu.eudat.proxy.fetching.RemoteFetcher;
import eu.eudat.responses.RestResponse;
@RestController
@CrossOrigin
public class Projects {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
@Autowired private RemoteFetcher remoteFetcher;
@RequestMapping(method = RequestMethod.POST, value = { "/projects/getPaged" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<DataTableData<eu.eudat.models.project.Project>> getPaged(@RequestBody ProjectTableRequest projectTableRequest) {
try {
DataTableData<eu.eudat.models.project.Project> dataTable = new ProjectManager().getPaged(projectDao, projectTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(dataTable);
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/projects/getSingle/{id}" }, produces="application/json")
public @ResponseBody ResponseEntity<eu.eudat.models.project.Project> getPaged(@PathVariable String id) {
try {
eu.eudat.models.project.Project project = new ProjectManager().getSingle(projectDao, id);
return ResponseEntity.status(HttpStatus.OK).body(project);
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/projects/add" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<eu.eudat.entities.Project> addProject(@RequestBody eu.eudat.models.project.Project project) {
Project createdProject = projectDao.update(project.toDataModel());
return ResponseEntity.status(HttpStatus.CREATED).body(createdProject);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/external/projects" }, produces="application/json")
public @ResponseBody ResponseEntity<List<Map<String,String>>> listExternalProjects(@RequestParam(value="query", required=false) String query ){
try {
List<Map<String,String>> remoteRepos = remoteFetcher.getProjects(query);
return ResponseEntity.status(HttpStatus.OK).body(remoteRepos);
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(null); //the ex.getMessage has the appropriate text description
}
}
// MANAGE PROJECT(S)
@RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json")
public @ResponseBody ResponseEntity<List<UUID>> listProjects(){
try {
List<UUID> allIDs = projectDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/projects/{id}" }, produces="application/json")
public @ResponseBody ResponseEntity<Project> getProject(@PathVariable("id") String id) {
try {
Project project = projectDao.read(UUID.fromString(id));
System.out.println(project.getId().toString());
return ResponseEntity.status(HttpStatus.OK).body(project);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/project/listAllLabelIDs" }, produces="application/json")
public @ResponseBody ResponseEntity<List<IDLabelPair>> listLabelIds(){
try {
List<IDLabelPair> allIDs = projectDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/project/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllProjects(){
try {
List<Project> allProjects = projectDao.getAll();
return ResponseEntity.status(HttpStatus.OK).body(allProjects);
}
catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Project> createProject(@RequestBody Project project) {
Project createdProject = projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body(createdProject);
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/update" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Project> updateProject(@RequestBody Project project) {
Project updatedProject = projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body(updatedProject);
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/delete" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Project> delete(@RequestBody Project project) {
Project p = new Project();
p.setId(project.getId());
try {
projectDao.delete(p);
return ResponseEntity.status(HttpStatus.CREATED).body(null);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/softdelete" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody Project project) {
project.setStatus(new Short("-1"));
try {
projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body(null);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/getdmps" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> getProjectDmps(@RequestBody Project project) {
try {
Set<DMP> dmps = projectDao.read(project.getId()).getDmps();
return ResponseEntity.status(HttpStatus.CREATED).body(dmps);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
////////////////////////////////
//// USER - RELATED ACTIONS ////
////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/project/getofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> getProjectsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happen
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
List<Project> userProjects = projectDao.getProjectsOfUser(userID);
return ResponseEntity.status(HttpStatus.OK).body(userProjects);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
/*
* OLD ONE
Map<UUID, Researcher> userProjects = new HashMap<UUID, Researcher>();
userInfo.getDmps().forEach( dmp -> {
Researcher proj = dmp.getProject();
userProjects.put(proj.getId(), proj);
});
try {
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(userProjects.values()));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
*/
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/createofuser" }, produces="text/plain", consumes = "application/json")
public @ResponseBody ResponseEntity<Project> createProjectOfUser(@RequestBody Project project){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
try {
project.setId(null);
project.setStatus(new Short("0"));
project.setCreationUser(userInfo);
project.setCreated(new Date());
project.setModified(new Date());
Project newproj = projectDao.create(project);
// DMP newdmp = new DMP();
// newdmp.setId(null);
// newdmp.setLabel("Auto-Generated");
// newdmp.setCreated(new Date());
// newdmp.setVersion(1);
// newdmp.setStatus(new Short("0"));
// newdmp.setProject(newproj);
//
// Set<UserInfo> users = new HashSet<UserInfo>();
// users.add(userInfo);
// newdmp.setUsers(users);
//
// newdmp = dMPDao.create(newdmp);
return ResponseEntity.status(HttpStatus.OK).body(newproj);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = { "/project/updateofuser" }, produces="text/plain")
// public @ResponseBody ResponseEntity<Object> updateProjectOfUser(@RequestBody Researcher project){
//
// if(project.getId()==null)
// return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Cannot update, id was null");
// return setProject(project);
//
// }
}

View File

@ -0,0 +1,145 @@
package eu.eudat.entities.xmlmodels.viewstyledefinition;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import eu.eudat.entities.xmlmodels.modeldefinition.DatabaseModelDefinition;
import eu.eudat.models.components.commons.ViewStyle;
import eu.eudat.models.components.commons.Visibility;
import eu.eudat.models.components.commons.datafield.FieldData;
import eu.eudat.utilities.XmlSerializable;
import eu.eudat.utilities.builders.ModelBuilder;
import eu.eudat.utilities.builders.XmlBuilder;
public class Field implements DatabaseViewStyleDefinition,XmlSerializable<Field>{
private String id;
private int ordinal;
private boolean defaultVisibility;
private String title;
private String description;
private String extendedDescription;
private ViewStyle viewStyle;
private Visibility visible;
private FieldData data;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getOrdinal() {
return ordinal;
}
public void setOrdinal(int ordinal) {
this.ordinal = ordinal;
}
public boolean getDefaultVisibility() {
return defaultVisibility;
}
public void setDefaultVisibility(boolean defaultVisibility) {
this.defaultVisibility = defaultVisibility;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getExtendedDescription() {
return extendedDescription;
}
public void setExtendedDescription(String extendedDescription) {
this.extendedDescription = extendedDescription;
}
public ViewStyle getViewStyle() {
return viewStyle;
}
public void setViewStyle(ViewStyle viewStyle) {
this.viewStyle = viewStyle;
}
public FieldData getData() {
return data;
}
public void setData(FieldData data) {
this.data = data;
}
public Visibility getVisible() {
return visible;
}
public void setVisible(Visibility visible) {
this.visible = visible;
}
@Override
public Element toXml(Document doc) {
Element rootElement = doc.createElement("field");
rootElement.setAttribute("id", this.id);
rootElement.setAttribute("ordinal", ""+this.ordinal);
rootElement.setAttribute("defaultVisibility",""+this.defaultVisibility);
Element extendedDescription = doc.createElement("extendedDescription");
extendedDescription.setTextContent(this.extendedDescription);
Element description = doc.createElement("description");
description.setTextContent(this.description);
Element title = doc.createElement("title");
title.setTextContent(this.title);
Element viewStyle = doc.createElement("viewStyle");
viewStyle.setAttribute("renderstyle", this.viewStyle.getRenderStyle());
viewStyle.setAttribute("cssClass", this.viewStyle.getCssClass());
Element visibility = this.visible.toXml(doc);
rootElement.appendChild(title);
rootElement.appendChild(visibility);
rootElement.appendChild(extendedDescription);
rootElement.appendChild(viewStyle);
rootElement.appendChild(description);
if(this.data!=null)rootElement.appendChild(this.data.toXml(doc));
return rootElement;
}
@Override
public Field fromXml(Element element) {
this.id = element.getAttribute("id");
this.ordinal = Integer.parseInt(element.getAttribute("ordinal"));
this.defaultVisibility = Boolean.valueOf(element.getAttribute("defaultVisibility")).booleanValue();
Element extendedDescription = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "extendedDescription");
this.extendedDescription = extendedDescription.getTextContent();
Element description = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "description");
this.description = description.getTextContent();
Element title = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "title");
this.title = title.getTextContent();
this.viewStyle = new ViewStyle();
Element viewStyle = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "viewStyle");
this.viewStyle.setRenderStyle(viewStyle.getAttribute("renderstyle"));
this.viewStyle.setCssClass(viewStyle.getAttribute("cssClass"));
Element visibility = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "visible");
this.visible = new Visibility().fromXml(visibility);
Element dataElement = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "data");
this.data = new ModelBuilder().toFieldData(null, this.viewStyle.getRenderStyle(),dataElement);
if(this.data!=null)this.data.fromXml(dataElement);
return this;
}
}

View File

@ -11,6 +11,7 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import eu.eudat.entities.DatasetProfileViewstyle; import eu.eudat.entities.DatasetProfileViewstyle;
import eu.eudat.entities.xmlmodels.modeldefinition.FieldGroup; import eu.eudat.entities.xmlmodels.modeldefinition.FieldGroup;
import eu.eudat.entities.xmlmodels.viewstyledefinition.Section;
import eu.eudat.entities.xmlmodels.viewstyledefinition.ViewStyleModel; import eu.eudat.entities.xmlmodels.viewstyledefinition.ViewStyleModel;
import eu.eudat.models.admin.components.datasetprofile.FieldSet; import eu.eudat.models.admin.components.datasetprofile.FieldSet;
import eu.eudat.models.admin.composite.DatasetProfile; import eu.eudat.models.admin.composite.DatasetProfile;
@ -28,7 +29,7 @@ public class AdminManager {
Document modelDoc = XmlBuilder.getDocument(); Document modelDoc = XmlBuilder.getDocument();
fieldGroup.toXml(modelDoc); fieldGroup.toXml(modelDoc);
String xml = XmlBuilder.generateXml(modelDoc); String xml = XmlBuilder.generateXml(modelDoc);
eu.eudat.entities.DatasetProfile datasetProfile = new eu.eudat.entities.DatasetProfile(); eu.eudat.entities.DatasetProfile datasetProfile = new eu.eudat.entities.DatasetProfile();
datasetProfile.setDefinition(xml); datasetProfile.setDefinition(xml);
datasetProfile.setStatus((short)1); datasetProfile.setStatus((short)1);

View File

@ -1,16 +1,17 @@
package eu.eudat.models.admin.components.datasetprofile; package eu.eudat.models.admin.components.datasetprofile;
import eu.eudat.entities.xmlmodels.modeldefinition.*;
import eu.eudat.utilities.ModelDefinition;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import eu.eudat.models.components.commons.DefaultValue; import eu.eudat.models.components.commons.DefaultValue;
import eu.eudat.models.components.commons.Multiplicity; import eu.eudat.models.components.commons.Multiplicity;
import eu.eudat.models.components.commons.ViewStyle; import eu.eudat.models.components.commons.ViewStyle;
import eu.eudat.models.components.commons.Visibility; import eu.eudat.models.components.commons.Visibility;
import eu.eudat.utilities.ModelDefinition;
import eu.eudat.utilities.ViewStyleDefinition; import eu.eudat.utilities.ViewStyleDefinition;
import eu.eudat.utilities.builders.ModelBuilder; import eu.eudat.utilities.builders.ModelBuilder;
public class Field implements ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.Field>,ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.Field>,Comparable{ public class Field implements ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.Field>,ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.Field>,Comparable{
private String id; private String id;
private Integer ordinal; private Integer ordinal;
private String title; private String title;

View File

@ -1,16 +1,15 @@
package eu.eudat.models.admin.components.datasetprofile; package eu.eudat.models.admin.components.datasetprofile;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import eu.eudat.utilities.ModelDefinition;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import eu.eudat.models.components.commons.Multiplicity; import eu.eudat.models.components.commons.Multiplicity;
import eu.eudat.utilities.ModelDefinition;
import eu.eudat.utilities.ViewStyleDefinition; import eu.eudat.utilities.ViewStyleDefinition;
import eu.eudat.utilities.builders.ModelBuilder; import eu.eudat.utilities.builders.ModelBuilder;
public class FieldSet implements Comparable,ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.FieldSet>,ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.FieldSet>{ public class FieldSet implements Comparable,ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.FieldSet>, ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.FieldSet>{
private String id; private String id;
private Integer ordinal; private Integer ordinal;
private Multiplicity multiplicity; private Multiplicity multiplicity;

View File

@ -2,10 +2,10 @@ package eu.eudat.models.admin.components.datasetprofile;
import java.util.List; import java.util.List;
import eu.eudat.utilities.ModelDefinition;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import eu.eudat.entities.xmlmodels.viewstyledefinition.FieldGroup; import eu.eudat.entities.xmlmodels.viewstyledefinition.FieldGroup;
import eu.eudat.utilities.ModelDefinition;
import eu.eudat.utilities.ViewStyleDefinition; import eu.eudat.utilities.ViewStyleDefinition;
import eu.eudat.utilities.builders.ModelBuilder; import eu.eudat.utilities.builders.ModelBuilder;

View File

@ -5,16 +5,16 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import eu.eudat.entities.xmlmodels.modeldefinition.*;
import eu.eudat.models.components.commons.DefaultValue; import eu.eudat.models.components.commons.DefaultValue;
import eu.eudat.models.components.commons.Multiplicity; import eu.eudat.models.components.commons.Multiplicity;
import eu.eudat.models.components.commons.ViewStyle; import eu.eudat.models.components.commons.ViewStyle;
import eu.eudat.models.components.commons.datafield.FieldData;
import eu.eudat.models.user.composite.PropertiesModelBuilder; import eu.eudat.models.user.composite.PropertiesModelBuilder;
import eu.eudat.utilities.ModelDefinition; import eu.eudat.utilities.ModelDefinition;
import eu.eudat.utilities.ViewStyleDefinition; import eu.eudat.utilities.ViewStyleDefinition;
import eu.eudat.utilities.builders.ModelBuilder; import eu.eudat.utilities.builders.ModelBuilder;
public class Field implements Comparable,PropertiesModelBuilder, ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.Field>,ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.Field>{ public class Field implements Comparable,PropertiesModelBuilder,ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.Field>, ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.Field>{
private String id; private String id;
private Integer ordinal; private Integer ordinal;
private String title; private String title;
@ -197,5 +197,5 @@ public class Field implements Comparable,PropertiesModelBuilder, ModelDefinition
public void fromJsonObject(Map<String, Object> properties, String path) { public void fromJsonObject(Map<String, Object> properties, String path) {
this.value = (String)properties.get(path); this.value = (String)properties.get(path);
} }
} }

View File

@ -12,7 +12,7 @@ import eu.eudat.utilities.ModelDefinition;
import eu.eudat.utilities.ViewStyleDefinition; import eu.eudat.utilities.ViewStyleDefinition;
import eu.eudat.utilities.builders.ModelBuilder; import eu.eudat.utilities.builders.ModelBuilder;
public class FieldSet implements Comparable,PropertiesModelBuilder, ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.FieldSet>,ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.FieldSet>{ public class FieldSet implements Comparable,PropertiesModelBuilder,ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.FieldSet>, ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.FieldSet>{
private String id; private String id;
private Integer ordinal; private Integer ordinal;
private Multiplicity multiplicity; private Multiplicity multiplicity;

View File

@ -10,7 +10,7 @@ import eu.eudat.utilities.ModelDefinition;
import eu.eudat.utilities.ViewStyleDefinition; import eu.eudat.utilities.ViewStyleDefinition;
import eu.eudat.utilities.builders.ModelBuilder; import eu.eudat.utilities.builders.ModelBuilder;
public class Group implements PropertiesModelBuilder, ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.FieldGroup>,ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.FieldGroup>{ public class Group implements PropertiesModelBuilder,ModelDefinition<eu.eudat.entities.xmlmodels.modeldefinition.FieldGroup>, ViewStyleDefinition<eu.eudat.entities.xmlmodels.viewstyledefinition.FieldGroup>{
private String id; private String id;
private String title; private String title;
private String section; private String section;

View File

@ -0,0 +1,7 @@
package eu.eudat.utilities;
/**
* Created by ikalyvas on 12/15/2017.
*/
public interface DatabaseDefinition {
}

View File

@ -0,0 +1,8 @@
package eu.eudat.utilities;
import eu.eudat.entities.xmlmodels.modeldefinition.DatabaseModelDefinition;
public interface ModelDefinition<T extends DatabaseModelDefinition> {
T toDatabaseDefinition(T item);
void fromDatabaseDefinition(T item);
}

View File

@ -0,0 +1,13 @@
package eu.eudat.utilities;
/**
* Created by ikalyvas on 12/15/2017.
*/
import eu.eudat.entities.xmlmodels.modeldefinition.DatabaseModelDefinition;
import eu.eudat.entities.xmlmodels.modeldefinition.Field;
import eu.eudat.entities.xmlmodels.viewstyledefinition.DatabaseViewStyleDefinition;
public interface ModelSerializer<T extends DatabaseViewStyleDefinition,U extends DatabaseModelDefinition> {
void fromDatabaseDefinition(T viewStyle,U model);
}

View File

@ -0,0 +1,14 @@
package eu.eudat.utilities;
/**
* Created by ikalyvas on 12/15/2017.
*/
import eu.eudat.entities.xmlmodels.modeldefinition.DatabaseModelDefinition;
import eu.eudat.entities.xmlmodels.viewstyledefinition.DatabaseViewStyleDefinition;
public interface ViewStyleDefinition<T extends DatabaseViewStyleDefinition>{
T toDatabaseDefinition(T item);
void fromDatabaseDefinition(T item);
}

View File

@ -0,0 +1,13 @@
package eu.eudat.utilities;
/**
* Created by ikalyvas on 12/15/2017.
*/
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public interface XmlSerializable <T>{
Element toXml(Document doc);
T fromXml(Element item);
}

View File

@ -0,0 +1,30 @@
package eu.eudat.utilities.builders;
/**
* Created by ikalyvas on 12/15/2017.
*/
import eu.eudat.entities.DataEntity;
import eu.eudat.models.DataModel;
import java.util.List;
import java.util.LinkedList;
public class DomainModelConverter<T extends DataEntity,U extends DataModel<T>> {
public List<T> toDataModel(List<U> models){
List<T> entities = new LinkedList<>();
for(U model : models){
entities.add(model.toDataModel());
}
return entities;
}
public List<U> fromDataModel(List<T> entities,Class<U> clazz) throws IllegalAccessException, InstantiationException {
List<U> models = new LinkedList<>();
for(T entity:entities){
U model = clazz.newInstance();
model.fromDataModel(entity);
models.add(model);
}
return models;
}
}

View File

@ -0,0 +1,104 @@
package eu.eudat.utilities.builders;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Element;
import eu.eudat.entities.xmlmodels.modeldefinition.DatabaseModelDefinition;
import eu.eudat.entities.xmlmodels.viewstyledefinition.DatabaseViewStyleDefinition;
import eu.eudat.models.components.commons.datafield.AutoCompleteData;
import eu.eudat.models.components.commons.datafield.CheckBoxData;
import eu.eudat.models.components.commons.datafield.ComboBoxData;
import eu.eudat.models.components.commons.datafield.FieldData;
import eu.eudat.models.components.commons.datafield.RadioBoxData;
import eu.eudat.models.components.commons.datafield.WordListData;
import eu.eudat.utilities.ModelDefinition;
import eu.eudat.utilities.ViewStyleDefinition;
public class ModelBuilder {
public <U extends ModelDefinition<T>,T extends DatabaseModelDefinition> List<T> toModelDefinition(List<U> items,Class<T> clazz){
List<T> list = new LinkedList<T>();
for(U item : items){
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();
}
}
return list;
}
public <U extends ViewStyleDefinition<T>,T extends DatabaseViewStyleDefinition> List<T> toViewStyleDefinition(List<U> items,Class<T> clazz){
List<T> list = new LinkedList<T>();
for(U item : items){
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();
}
}
return list;
}
public <U extends ViewStyleDefinition<T>,T extends DatabaseViewStyleDefinition> List<U> fromViewStyleDefinition(List<T> items,Class<U> clazz){
List<U> list = new LinkedList<U>();
for(T item : items){
try {
U modelItem = clazz.newInstance();
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();
}
}
return list;
}
public <U extends FieldData<U>> U toFieldData(Object data,String type,Element dataElement){
if(type.equals("combobox")){
if(dataElement!=null){
if(dataElement.getAttribute("type").equals("autocomplete")){
return (U) new AutoCompleteData().fromData(data);
}else if(dataElement.getAttribute("type").equals("wordlist"))
return (U) new WordListData().fromData(data);
}
}
if(type.equals("booleanDecision"))return null;
if(type.equals("radiobox"))return (U) new RadioBoxData().fromData(data);
if(type.equals("checkBox"))return (U) new CheckBoxData().fromData(data);
if(type.equals("freetext"))return null;
return null;
}
public <U extends FieldData<U>> U toFieldData(Object data,String type){
if(type.equals("combobox")){
String comboboxType = (String)((Map<String,Object>)data).get("type");
if(comboboxType.equals("autocomplete")){
return (U) new AutoCompleteData().fromData(data);
}else if(comboboxType.equals("wordlist"))
return (U) new WordListData().fromData(data);
}
if(type.equals("booleanDecision"))return null;
if(type.equals("radiobox"))return (U) new RadioBoxData().fromData(data);
if(type.equals("checkBox"))return (U) new CheckBoxData().fromData(data);
if(type.equals("freetext"))return null;
return null;
}
}

View File

@ -0,0 +1,84 @@
package eu.eudat.utilities.builders;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import eu.eudat.entities.xmlmodels.viewstyledefinition.FieldSet;
public class XmlBuilder {
public static Document getDocument(){
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
try {
docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
return doc;
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public static String generateXml(Document doc){
TransformerFactory tFact = TransformerFactory.newInstance();
Transformer trans;
try {
trans = tFact.newTransformer();
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
return writer.toString();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public static Document fromXml(String xml){
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
try {
docBuilder = docFactory.newDocumentBuilder();
InputSource inputStream = new InputSource(new StringReader(xml));
Document doc = docBuilder.parse(inputStream);
return doc;
} catch (ParserConfigurationException | SAXException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public static Element getNodeFromListByTagName(NodeList list, String tagName) {
for (int temp = 0; temp < list.getLength(); temp++) {
Node element = list.item(temp);
if (element.getNodeType() == Node.ELEMENT_NODE) {
if(element.getNodeName().equals(tagName))return (Element) element;
}
}
return null;
}
}

View File

@ -0,0 +1,13 @@
package eu.eudat.utilities.helpers;
/**
* Created by ikalyvas on 12/15/2017.
*/
import eu.eudat.entities.xmlmodels.modeldefinition.DatabaseModelDefinition;
import eu.eudat.entities.xmlmodels.modeldefinition.Field;
import eu.eudat.entities.xmlmodels.viewstyledefinition.DatabaseViewStyleDefinition;
public interface ModelSerializer<T extends DatabaseViewStyleDefinition,U extends DatabaseModelDefinition> {
void fromDatabaseDefinition(T viewStyle,U model);
}