no message

This commit is contained in:
Ioannis Kalyvas 2018-02-16 09:45:18 +02:00
parent eb62c65272
commit 8892c62791
73 changed files with 1276 additions and 337 deletions

View File

@ -14,6 +14,7 @@
<properties> <properties>
<project.http.version>1.19.0</project.http.version> <project.http.version>1.19.0</project.http.version>
<project.oauth.version>1.19.0</project.oauth.version> <project.oauth.version>1.19.0</project.oauth.version>
<project.version>0.2.0</project.version>
<dmp-backend-commons.version>0.0.1-SNAPSHOT</dmp-backend-commons.version> <dmp-backend-commons.version>0.0.1-SNAPSHOT</dmp-backend-commons.version>
<org.springframework.version>4.3.8.RELEASE</org.springframework.version> <org.springframework.version>4.3.8.RELEASE</org.springframework.version>
@ -34,10 +35,9 @@
<logback.version>1.1.1</logback.version> <logback.version>1.1.1</logback.version>
<javax.inject.version>1</javax.inject.version> <javax.inject.version>1</javax.inject.version>
<javax.servlet.servlet-api.version>3.0.1</javax.servlet.servlet-api.version> <javax.servlet.servlet-api.version>3.0.1</javax.servlet.servlet-api.version>
<!-- <jcloverslf4j.version>1.7.6</jcloverslf4j.version> --> <docker.image.prefix>ikalyvas</docker.image.prefix>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
@ -189,6 +189,7 @@
</dependencies> </dependencies>
<build> <build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources> <resources>
<resource> <resource>
<directory>src/main/ui-resources</directory> <directory>src/main/ui-resources</directory>
@ -206,8 +207,22 @@
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins> </plugins>
<finalName>${project.artifactId}</finalName>
</build> </build>
<profiles> <profiles>

View File

@ -0,0 +1,8 @@
package eu.eudat.builders;
/**
* Created by ikalyvas on 2/15/2018.
*/
public abstract class Builder<T> {
public abstract T build();
}

View File

@ -0,0 +1,8 @@
package eu.eudat.builders;
/**
* Created by ikalyvas on 2/15/2018.
*/
public interface BuilderFactory {
<T extends Builder> T getBuilder(Class<T> tClass);
}

View File

@ -0,0 +1,30 @@
package eu.eudat.builders;
import eu.eudat.builders.entity.*;
import eu.eudat.builders.model.criteria.DataRepositoryCriteriaBuilder;
import eu.eudat.builders.model.criteria.RegistryCriteriaBuilder;
import eu.eudat.builders.model.models.DataTableDataBuilder;
import eu.eudat.builders.model.models.PrincipalBuilder;
import eu.eudat.builders.model.models.ProjectBuilder;
import org.springframework.stereotype.Service;
/**
* Created by ikalyvas on 2/15/2018.
*/
@Service("builderFactory")
public class BuilderFactoryImpl implements BuilderFactory {
public <T extends Builder> T getBuilder(Class<T> tClass) {
if (tClass.equals(CredentialBuilder.class)) return (T) new CredentialBuilder();
if (tClass.equals(DataRepositoryCriteriaBuilder.class)) return (T) new DataRepositoryCriteriaBuilder();
if (tClass.equals(DatasetProfileBuilder.class)) return (T) new DatasetProfileBuilder();
if (tClass.equals(DataTableDataBuilder.class)) return (T) new DataTableDataBuilder<>();
if (tClass.equals(PrincipalBuilder.class)) return (T) new PrincipalBuilder();
if (tClass.equals(ProjectBuilder.class)) return (T) new ProjectBuilder();
if (tClass.equals(RegistryCriteriaBuilder.class)) return (T) new RegistryCriteriaBuilder();
if (tClass.equals(UserInfoBuilder.class)) return (T) new UserInfoBuilder();
if (tClass.equals(UserRoleBuilder.class)) return (T) new UserRoleBuilder();
if (tClass.equals(UserTokenBuilder.class)) return (T) new UserTokenBuilder();
return null;
}
}

View File

@ -0,0 +1,86 @@
package eu.eudat.builders.entity;
import eu.eudat.builders.Builder;
import eu.eudat.entities.Credential;
import eu.eudat.entities.UserInfo;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.util.Date;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class CredentialBuilder extends Builder<Credential> {
private UUID id;
private UserInfo userInfo;
private Integer status;
private Integer provider;
private String publicValue;
private String secret;
private Date creationTime;
private Date lastUpdateTime;
public CredentialBuilder id(UUID id) {
this.id = id;
return this;
}
public CredentialBuilder userInfo(UserInfo userInfo) {
this.userInfo = userInfo;
return this;
}
public CredentialBuilder status(Integer status) {
this.status = status;
return this;
}
public CredentialBuilder provider(Integer provider) {
this.provider = provider;
return this;
}
public CredentialBuilder publicValue(String publicValue) {
this.publicValue = publicValue;
return this;
}
public CredentialBuilder secret(String secret) {
this.secret = secret;
return this;
}
public CredentialBuilder creationTime(Date creationTime) {
this.creationTime = creationTime;
return this;
}
public CredentialBuilder lastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
return this;
}
public Credential build(){
Credential credential = new Credential();
credential.setStatus(status);
credential.setLastUpdateTime(lastUpdateTime);
credential.setCreationTime(creationTime);
credential.setProvider(provider);
credential.setSecret(secret);
credential.setPublicValue(publicValue);
credential.setUserInfo(userInfo);
credential.setId(id);
return credential;
}
}

View File

@ -0,0 +1,89 @@
package eu.eudat.builders.entity;
import eu.eudat.builders.Builder;
import eu.eudat.entities.Dataset;
import eu.eudat.entities.DatasetProfile;
import org.hibernate.annotations.Type;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class DatasetProfileBuilder extends Builder<DatasetProfile> {
private UUID id;
private String label;
private Set<Dataset> dataset;
private String definition;
private Short status;
private Date created;
private Date modified = new Date();
private String description;
public DatasetProfileBuilder id(UUID id) {
this.id = id;
return this;
}
public DatasetProfileBuilder label(String label) {
this.label = label;
return this;
}
public DatasetProfileBuilder dataset(Set<Dataset> dataset) {
this.dataset = dataset;
return this;
}
public DatasetProfileBuilder definition(String definition) {
this.definition = definition;
return this;
}
public DatasetProfileBuilder status(Short status) {
this.status = status;
return this;
}
public DatasetProfileBuilder created(Date created) {
this.created = created;
return this;
}
public DatasetProfileBuilder modified(Date modified) {
this.modified = modified;
return this;
}
public DatasetProfileBuilder description(String description) {
this.description = description;
return this;
}
@Override
public DatasetProfile build() {
DatasetProfile datasetProfile = new DatasetProfile();
datasetProfile.setCreated(created);
datasetProfile.setStatus(status);
datasetProfile.setId(id);
datasetProfile.setDataset(dataset);
datasetProfile.setDefinition(definition);
datasetProfile.setDescription(description);
datasetProfile.setModified(modified);
datasetProfile.setLabel(label);
return datasetProfile;
}
}

View File

@ -0,0 +1,122 @@
package eu.eudat.builders.entity;
import eu.eudat.builders.Builder;
import eu.eudat.entities.Credential;
import eu.eudat.entities.DMP;
import eu.eudat.entities.UserInfo;
import eu.eudat.entities.UserRole;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class UserInfoBuilder extends Builder<UserInfo> {
private UUID id;
private String email = null;
private Short authorization_level; //0 admin, 1 user
private Short usertype; // 0 internal, 1 external
private Boolean verified_email = null;
private String name = null;
private Date created = null;
private Date lastloggedin = null;
private String additionalinfo;
private Set<DMP> dmps;
private Set<Credential> credentials = new HashSet<>();
private Set<UserRole> userRoles = new HashSet<>();
public UserInfoBuilder id(UUID id) {
this.id = id;
return this;
}
public UserInfoBuilder email(String email) {
this.email = email;
return this;
}
public UserInfoBuilder authorization_level(Short authorization_level) {
this.authorization_level = authorization_level;
return this;
}
public UserInfoBuilder usertype(Short usertype) {
this.usertype = usertype;
return this;
}
public UserInfoBuilder verified_email(Boolean verified_email) {
this.verified_email = verified_email;
return this;
}
public UserInfoBuilder name(String name) {
this.name = name;
return this;
}
public UserInfoBuilder created(Date created) {
this.created = created;
return this;
}
public UserInfoBuilder lastloggedin(Date lastloggedin) {
this.lastloggedin = lastloggedin;
return this;
}
public UserInfoBuilder additionalinfo(String additionalinfo) {
this.additionalinfo = additionalinfo;
return this;
}
public UserInfoBuilder dmps(Set<DMP> dmps) {
this.dmps = dmps;
return this;
}
public UserInfoBuilder credentials(Set<Credential> credentials) {
this.credentials = credentials;
return this;
}
public UserInfoBuilder userRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles;
return this;
}
@Override
public UserInfo build() {
UserInfo userInfo = new UserInfo();
userInfo.setId(id);
userInfo.setUsertype(usertype);
userInfo.setAuthorization_level(authorization_level);
userInfo.setLastloggedin(lastloggedin);
userInfo.setCreated(created);
userInfo.setEmail(email);
userInfo.setName(name);
userInfo.setAdditionalinfo(additionalinfo);
userInfo.setUserRoles(userRoles);
userInfo.setCredentials(credentials);
userInfo.setDmps(dmps);
userInfo.setVerified_email(verified_email);
return userInfo;
}
}

View File

@ -0,0 +1,47 @@
package eu.eudat.builders.entity;
import eu.eudat.builders.Builder;
import eu.eudat.entities.UserInfo;
import eu.eudat.entities.UserRole;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class UserRoleBuilder extends Builder<UserRole> {
private UUID id;
private int role;
private UserInfo userInfo;
public UserRoleBuilder id(UUID id) {
this.id = id;
return this;
}
public UserRoleBuilder role(int role) {
this.role = role;
return this;
}
public UserRoleBuilder userInfo(UserInfo userInfo) {
this.userInfo = userInfo;
return this;
}
@Override
public UserRole build() {
UserRole userRole = new UserRole();
userRole.setUserInfo(userInfo);
userRole.setRole(role);
userRole.setId(id);
return userRole;
}
}

View File

@ -0,0 +1,56 @@
package eu.eudat.builders.entity;
import eu.eudat.builders.Builder;
import eu.eudat.entities.UserInfo;
import eu.eudat.entities.UserToken;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import java.util.Date;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class UserTokenBuilder extends Builder<UserToken> {
private UUID token;
private UserInfo user;
private Date issuedAt;
private Date expiresAt;
public UserTokenBuilder token(UUID token) {
this.token = token;
return this;
}
public UserTokenBuilder user(UserInfo user) {
this.user = user;
return this;
}
public UserTokenBuilder issuedAt(Date issuedAt) {
this.issuedAt = issuedAt;
return this;
}
public UserTokenBuilder expiresAt(Date expiresAt) {
this.expiresAt = expiresAt;
return this;
}
@Override
public UserToken build() {
UserToken userToken = new UserToken();
userToken.setExpiresAt(expiresAt);
userToken.setToken(token);
userToken.setUser(user);
userToken.setIssuedAt(issuedAt);
return userToken;
}
}

View File

@ -0,0 +1,23 @@
package eu.eudat.builders.model.criteria;
import eu.eudat.builders.Builder;
import eu.eudat.models.criteria.DataRepositoryCriteria;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class DataRepositoryCriteriaBuilder extends Builder<DataRepositoryCriteria> {
private String like;
public DataRepositoryCriteriaBuilder like(String like) {
this.like = like;
return this;
}
@Override
public DataRepositoryCriteria build() {
DataRepositoryCriteria dataRepositoryCriteria = new DataRepositoryCriteria();
dataRepositoryCriteria.setLike(like);
return dataRepositoryCriteria;
}
}

View File

@ -0,0 +1,23 @@
package eu.eudat.builders.model.criteria;
import eu.eudat.builders.Builder;
import eu.eudat.models.criteria.ExternalDatasetCriteria;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class ExternalDatasetCriteriaBuilder extends Builder<ExternalDatasetCriteria> {
private String like;
public ExternalDatasetCriteriaBuilder like(String like) {
this.like = like;
return this;
}
@Override
public ExternalDatasetCriteria build() {
ExternalDatasetCriteria externalDatasetCriteria = new ExternalDatasetCriteria();
externalDatasetCriteria.setLike(like);
return externalDatasetCriteria;
}
}

View File

@ -0,0 +1,24 @@
package eu.eudat.builders.model.criteria;
import eu.eudat.builders.Builder;
import eu.eudat.entities.Registry;
import eu.eudat.models.criteria.RegistryCriteria;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class RegistryCriteriaBuilder extends Builder<RegistryCriteria> {
private String like;
public RegistryCriteriaBuilder like(String like) {
this.like = like;
return this;
}
@Override
public RegistryCriteria build() {
RegistryCriteria registryCriteria = new RegistryCriteria();
registryCriteria.setLike(like);
return registryCriteria;
}
}

View File

@ -0,0 +1,23 @@
package eu.eudat.builders.model.criteria;
import eu.eudat.builders.Builder;
import eu.eudat.models.criteria.ServiceCriteria;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class ServiceCriteriaBuilder extends Builder<ServiceCriteria> {
private String like;
public ServiceCriteriaBuilder setLike(String like) {
this.like = like;
return this;
}
@Override
public ServiceCriteria build() {
ServiceCriteria serviceCriteria = new ServiceCriteria();
serviceCriteria.setLike(like);
return serviceCriteria;
}
}

View File

@ -0,0 +1,33 @@
package eu.eudat.builders.model.models;
import eu.eudat.builders.Builder;
import eu.eudat.models.helpers.common.DataTableData;
import java.util.List;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class DataTableDataBuilder<T> extends Builder<DataTableData<T>> {
private Long totalCount;
private List<T> data;
public DataTableDataBuilder<T> totalCount(Long totalCount) {
this.totalCount = totalCount;
return this;
}
public DataTableDataBuilder<T> data(List<T> data) {
this.data = data;
return this;
}
@Override
public DataTableData<T> build() {
DataTableData<T> dataTableData = new DataTableData<>();
dataTableData.setTotalCount(totalCount);
dataTableData.setData(data);
return dataTableData;
}
}

View File

@ -0,0 +1,57 @@
package eu.eudat.builders.model.models;
import eu.eudat.builders.Builder;
import eu.eudat.models.security.Principal;
import eu.eudat.types.Authorities;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class PrincipalBuilder extends Builder<Principal> {
private UUID id;
private UUID token;
private String name;
private Date expiresAt;
private Set<Authorities> authorities;
public PrincipalBuilder id(UUID id) {
this.id = id;
return this;
}
public PrincipalBuilder token(UUID token) {
this.token = token;
return this;
}
public PrincipalBuilder name(String name) {
this.name = name;
return this;
}
public PrincipalBuilder expiresAt(Date expiresAt) {
this.expiresAt = expiresAt;
return this;
}
public PrincipalBuilder authorities(Set<Authorities> authorities) {
this.authorities = authorities;
return this;
}
@Override
public Principal build() {
Principal principal = new Principal();
principal.setAuthorities(authorities);
principal.setName(name);
principal.setExpiresAt(expiresAt);
principal.setToken(token);
principal.setId(id);
return principal;
}
}

View File

@ -0,0 +1,134 @@
package eu.eudat.builders.model.models;
import eu.eudat.builders.Builder;
import eu.eudat.entities.UserInfo;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.project.Project;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* Created by ikalyvas on 2/15/2018.
*/
public class ProjectBuilder extends Builder<Project> {
private UUID id;
private List<DataManagementPlan> dmps;
private String label;
private String abbreviation;
private String reference;
private String uri;
private String definition;
private Date startDate;
private Date endDate;
private eu.eudat.entities.Project.Status status;
private UserInfo creationUser;
private Date created;
private Date modified;
private String description;
public ProjectBuilder id(UUID id) {
this.id = id;
return this;
}
public ProjectBuilder dmps(List<DataManagementPlan> dmps) {
this.dmps = dmps;
return this;
}
public ProjectBuilder label(String label) {
this.label = label;
return this;
}
public ProjectBuilder abbreviation(String abbreviation) {
this.abbreviation = abbreviation;
return this;
}
public ProjectBuilder reference(String reference) {
this.reference = reference;
return this;
}
public ProjectBuilder uri(String uri) {
this.uri = uri;
return this;
}
public ProjectBuilder definition(String definition) {
this.definition = definition;
return this;
}
public ProjectBuilder startDate(Date startDate) {
this.startDate = startDate;
return this;
}
public ProjectBuilder endDate(Date endDate) {
this.endDate = endDate;
return this;
}
public ProjectBuilder status(eu.eudat.entities.Project.Status status) {
this.status = status;
return this;
}
public ProjectBuilder creationUser(UserInfo creationUser) {
this.creationUser = creationUser;
return this;
}
public ProjectBuilder created(Date created) {
this.created = created;
return this;
}
public ProjectBuilder modified(Date modified) {
this.modified = modified;
return this;
}
public ProjectBuilder description(String description) {
this.description = description;
return this;
}
@Override
public Project build() {
Project project = new Project();
project.setStatus(status.getValue());
project.setAbbreviation(abbreviation);
project.setCreated(created);
project.setCreationUser(creationUser);
project.setDefinition(definition);
project.setDescription(description);
project.setDmps(dmps);
project.setEndDate(endDate);
project.setId(id);
project.setLabel(label);
project.setModified(modified);
project.setReference(reference);
project.setCreationUser(creationUser);
project.setStartDate(startDate);
return project;
}
}

View File

@ -44,7 +44,7 @@ public class Admin extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/admin/addDmp"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/admin/addDmp"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
try { try {
eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile); eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile,getApiContext());
this.getApiContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); this.getApiContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
} catch (Exception ex) { } catch (Exception ex) {
@ -57,7 +57,7 @@ public class Admin extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/admin/addDmp/{id}"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/admin/addDmp/{id}"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<UUID>> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { public ResponseEntity<ResponseItem<UUID>> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
try { try {
eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile); eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile,getApiContext());
eu.eudat.entities.DatasetProfile datasetprofile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); eu.eudat.entities.DatasetProfile datasetprofile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
datasetprofile.setDefinition(modelDefinition.getDefinition()); datasetprofile.setDefinition(modelDefinition.getDefinition());

View File

@ -73,8 +73,6 @@ public class DMPs extends BaseController {
ex.printStackTrace(); ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
} }
} }
@RequestMapping(method = RequestMethod.POST, value = {"/dmps/new/{id}"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/dmps/new/{id}"}, consumes = "application/json", produces = "application/json")

View File

@ -47,7 +47,7 @@ public class DatasetProfiles extends BaseController {
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem) { ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem) {
try { try {
DataTableData<DatasetProfileListingModel> datasetProfileTableData = DatasetProfileManager.getPaged(this.getApiContext().getDatabaseRepository().getDatasetProfileDao(), datasetProfileTableRequestItem); DataTableData<DatasetProfileListingModel> datasetProfileTableData = DatasetProfileManager.getPaged(this.getApiContext(), datasetProfileTableRequestItem);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
} catch (Exception ex) { } catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE)); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE));

View File

@ -30,7 +30,7 @@ public class ExternalDatasets extends BaseController{
@RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets/getPaged"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets/getPaged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<ExternalDatasetListingModel>>> getPaged(@RequestBody ExternalDatasetTableRequest datasetTableRequest, Principal principal) { public @ResponseBody ResponseEntity<ResponseItem<DataTableData<ExternalDatasetListingModel>>> getPaged(@RequestBody ExternalDatasetTableRequest datasetTableRequest, Principal principal) {
try { try {
DataTableData<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getPaged(this.getApiContext().getDatabaseRepository().getExternalDatasetDao(), datasetTableRequest); DataTableData<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getPaged(this.getApiContext(), datasetTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<ExternalDatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<ExternalDatasetListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
} catch (Exception ex) { } catch (Exception ex) {
@ -42,7 +42,7 @@ public class ExternalDatasets extends BaseController{
@RequestMapping(method = RequestMethod.GET, value = {"/external/datasets"}, produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = {"/external/datasets"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalDatasetListingModel>>> getWithExternal(@RequestParam(value = "query", required = false) String query, Principal principal) { public @ResponseBody ResponseEntity<ResponseItem<List<ExternalDatasetListingModel>>> getWithExternal(@RequestParam(value = "query", required = false) String query, Principal principal) {
try { try {
List<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getWithExternal(this.getApiContext().getDatabaseRepository().getExternalDatasetDao(), query, this.getApiContext().getRemoteFetcher()); List<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getWithExternal(this.getApiContext(), query, this.getApiContext().getRemoteFetcher());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalDatasetListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalDatasetListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();

View File

@ -104,7 +104,7 @@ public class Projects extends BaseController {
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<List<eu.eudat.models.project.Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) { ResponseEntity<ResponseItem<List<eu.eudat.models.project.Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) {
try { try {
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteriaWithExternal(this.getApiContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getRemoteFetcher()); List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteriaWithExternal(this.getApiContext(), projectCriteria, this.getApiContext().getRemoteFetcher());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();

View File

@ -38,7 +38,7 @@ public class Users extends BaseController {
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<UserListingModel>>> getPaged(@Valid @RequestBody UserInfoTableRequestItem userInfoTableRequestItem, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { ResponseEntity<ResponseItem<DataTableData<UserListingModel>>> getPaged(@Valid @RequestBody UserInfoTableRequestItem userInfoTableRequestItem, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
try { try {
DataTableData<UserListingModel> dataTable = UserManager.getPaged(this.getApiContext().getDatabaseRepository().getUserInfoDao(), userInfoTableRequestItem); DataTableData<UserListingModel> dataTable = UserManager.getPaged(this.getApiContext(), userInfoTableRequestItem);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();

View File

@ -3,6 +3,8 @@ package eu.eudat.managers;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import eu.eudat.builders.entity.DatasetProfileBuilder;
import eu.eudat.services.ApiContext;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@ -20,7 +22,7 @@ import eu.eudat.utilities.helpers.ModelBuilderCollector;
public class AdminManager { public class AdminManager {
public static eu.eudat.entities.DatasetProfile generateViewStyleDefinition(DatasetProfile profile){ public static eu.eudat.entities.DatasetProfile generateViewStyleDefinition(DatasetProfile profile, ApiContext apiContext) {
ViewStyleModel viewStyleModel = new ViewStyleModel(); ViewStyleModel viewStyleModel = new ViewStyleModel();
viewStyleModel.setSections(new ModelBuilder().toViewStyleDefinition(profile.getSections(), eu.eudat.entities.xmlmodels.datasetprofiledefinition.Section.class)); viewStyleModel.setSections(new ModelBuilder().toViewStyleDefinition(profile.getSections(), eu.eudat.entities.xmlmodels.datasetprofiledefinition.Section.class));
viewStyleModel.setPages(new ModelBuilder().toViewStyleDefinition(profile.getPages(), eu.eudat.entities.xmlmodels.datasetprofiledefinition.Page.class)); viewStyleModel.setPages(new ModelBuilder().toViewStyleDefinition(profile.getPages(), eu.eudat.entities.xmlmodels.datasetprofiledefinition.Page.class));
@ -29,11 +31,10 @@ public class AdminManager {
viewStyleDoc.appendChild(elementViewStyle); viewStyleDoc.appendChild(elementViewStyle);
String xml = XmlBuilder.generateXml(viewStyleDoc); String xml = XmlBuilder.generateXml(viewStyleDoc);
eu.eudat.entities.DatasetProfile datasetProfile = new eu.eudat.entities.DatasetProfile(); eu.eudat.entities.DatasetProfile datasetProfile = apiContext.getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel())
datasetProfile.setDefinition(xml); .status((short) 1).created(new Date())
datasetProfile.setLabel(profile.getLabel()); .build();
datasetProfile.setStatus((short)1);
datasetProfile.setCreated(new Date());
return datasetProfile; return datasetProfile;
} }

View File

@ -4,6 +4,7 @@ import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import eu.eudat.builders.entity.UserInfoBuilder;
import eu.eudat.dao.entities.*; import eu.eudat.dao.entities.*;
import eu.eudat.entities.*; import eu.eudat.entities.*;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsException; import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsException;
@ -22,7 +23,6 @@ import eu.eudat.models.listingmodels.DatasetListingModel;
import eu.eudat.models.security.Principal; import eu.eudat.models.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.services.ApiContext; import eu.eudat.services.ApiContext;
import eu.eudat.utilities.builders.DomainModelConverter;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
public class DataManagementPlanManager { public class DataManagementPlanManager {
@ -37,7 +37,7 @@ public class DataManagementPlanManager {
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>(); DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> { CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> {
List<DataManagementPlanListingModel> datamanagementPlans = new DomainModelConverter<DMP, DataManagementPlanListingModel>().fromDataModel(resultList, DataManagementPlanListingModel.class); List<DataManagementPlanListingModel> datamanagementPlans = resultList.stream().map(item -> new DataManagementPlanListingModel().fromDataModel(item)).collect(Collectors.toList());
dataTable.setData(datamanagementPlans); dataTable.setData(datamanagementPlans);
}); });
@ -59,7 +59,7 @@ public class DataManagementPlanManager {
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria) throws IllegalAccessException, InstantiationException { public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria) throws IllegalAccessException, InstantiationException {
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria()); QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria());
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = new DomainModelConverter<eu.eudat.entities.DMP, eu.eudat.models.dmp.DataManagementPlan>().fromDataModel(items.toList(), eu.eudat.models.dmp.DataManagementPlan.class); List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = items.toList().stream().map(item -> new DataManagementPlan().fromDataModel(item)).collect(Collectors.toList());
return datamanagementPlans; return datamanagementPlans;
} }
@ -88,8 +88,7 @@ public class DataManagementPlanManager {
DMP newDmp = dataManagementPlan.toDataModel(); DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao()); createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao()); createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao());
UserInfo user = new UserInfo(); UserInfo user = apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
user.setId(principal.getId());
createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user); createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user); newDmp.setCreator(user);
newDmp.setGroupId(oldDmp.getGroupId()); newDmp.setGroupId(oldDmp.getGroupId());
@ -103,8 +102,7 @@ public class DataManagementPlanManager {
DMP newDmp = dataManagementPlan.toDataModel(); DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao()); createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao()); createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao());
UserInfo user = new UserInfo(); UserInfo user = apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
user.setId(principal.getId());
createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user); createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user); newDmp.setCreator(user);
newDmp.setGroupId(UUID.randomUUID()); newDmp.setGroupId(UUID.randomUUID());

View File

@ -1,5 +1,6 @@
package eu.eudat.managers; package eu.eudat.managers;
import eu.eudat.builders.entity.UserInfoBuilder;
import eu.eudat.dao.entities.*; import eu.eudat.dao.entities.*;
import eu.eudat.entities.Dataset; import eu.eudat.entities.Dataset;
import eu.eudat.entities.UserInfo; import eu.eudat.entities.UserInfo;
@ -12,12 +13,10 @@ import eu.eudat.models.dataset.DatasetTableRequest;
import eu.eudat.models.datasetwizard.DatasetWizardModel; import eu.eudat.models.datasetwizard.DatasetWizardModel;
import eu.eudat.models.helpers.common.DataTableData; import eu.eudat.models.helpers.common.DataTableData;
import eu.eudat.models.listingmodels.DatasetListingModel; import eu.eudat.models.listingmodels.DatasetListingModel;
import eu.eudat.models.properties.PropertiesModel;
import eu.eudat.models.security.Principal; import eu.eudat.models.security.Principal;
import eu.eudat.models.user.composite.PagedDatasetProfile; import eu.eudat.models.user.composite.PagedDatasetProfile;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.services.ApiContext; import eu.eudat.services.ApiContext;
import eu.eudat.utilities.builders.DomainModelConverter;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.HashMap; import java.util.HashMap;
@ -25,20 +24,20 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class DatasetManager { public class DatasetManager {
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception { public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
UserInfo userInfo = new UserInfo(); UserInfo userInfo = apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
userInfo.setId(principal.getId());
QueryableList<eu.eudat.entities.Dataset> items = apiContext.getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()); QueryableList<eu.eudat.entities.Dataset> items = apiContext.getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria());
QueryableList<eu.eudat.entities.Dataset> authItems = apiContext.getDatabaseRepository().getDatasetDao().getAuthenticated(items, userInfo); QueryableList<eu.eudat.entities.Dataset> authItems = apiContext.getDatabaseRepository().getDatasetDao().getAuthenticated(items, userInfo);
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest); QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>(); DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
CompletableFuture<List<Dataset>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> { CompletableFuture<List<Dataset>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> {
List<DatasetListingModel> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, DatasetListingModel>().fromDataModel(resultList, DatasetListingModel.class); List<DatasetListingModel> datasets = resultList.stream().map(item-> new DatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
dataTable.setData(datasets); dataTable.setData(datasets);
}); });
@ -70,8 +69,7 @@ public class DatasetManager {
public static eu.eudat.entities.Dataset createOrUpdate(ApiContext apiContext, DatasetWizardModel profile, Principal principal) throws Exception { public static eu.eudat.entities.Dataset createOrUpdate(ApiContext apiContext, DatasetWizardModel profile, Principal principal) throws Exception {
eu.eudat.entities.Dataset dataset = profile.toDataModel(); eu.eudat.entities.Dataset dataset = profile.toDataModel();
propertiesModelToString(profile, dataset); propertiesModelToString(profile, dataset);
UserInfo userInfo = new UserInfo(); UserInfo userInfo = apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
userInfo.setId(principal.getId());
dataset.setCreator(userInfo); dataset.setCreator(userInfo);
createRegistriesIfTheyDontExist(apiContext.getDatabaseRepository().getRegistryDao(), dataset); createRegistriesIfTheyDontExist(apiContext.getDatabaseRepository().getRegistryDao(), dataset);
createDataRepositoriesIfTheyDontExist(apiContext.getDatabaseRepository().getDataRepositoryDao(), dataset); createDataRepositoriesIfTheyDontExist(apiContext.getDatabaseRepository().getDataRepositoryDao(), dataset);

View File

@ -1,5 +1,6 @@
package eu.eudat.managers; package eu.eudat.managers;
import eu.eudat.builders.model.models.DataTableDataBuilder;
import eu.eudat.dao.entities.DatasetProfileDao; import eu.eudat.dao.entities.DatasetProfileDao;
import eu.eudat.entities.DatasetProfile; import eu.eudat.entities.DatasetProfile;
import eu.eudat.models.datasetprofile.DatasetProfileAutocompleteItem; import eu.eudat.models.datasetprofile.DatasetProfileAutocompleteItem;
@ -8,32 +9,30 @@ import eu.eudat.models.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.models.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.models.helpers.common.DataTableData; import eu.eudat.models.helpers.common.DataTableData;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter; import eu.eudat.services.ApiContext;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class DatasetProfileManager { public class DatasetProfileManager {
public static List<DatasetProfileAutocompleteItem> getWithCriteria(DatasetProfileDao datasetProfileRepository, DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException { public static List<DatasetProfileAutocompleteItem> getWithCriteria(DatasetProfileDao datasetProfileRepository, DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException {
QueryableList<DatasetProfile> items = datasetProfileRepository.getWithCriteria(datasetProfileAutocompleteRequest.getCriteria()); QueryableList<DatasetProfile> items = datasetProfileRepository.getWithCriteria(datasetProfileAutocompleteRequest.getCriteria());
List<DatasetProfileAutocompleteItem> datasetProfiles = new DomainModelConverter<DatasetProfile, DatasetProfileAutocompleteItem>().fromDataModel( items.toList(), DatasetProfileAutocompleteItem.class); List<DatasetProfileAutocompleteItem> datasetProfiles = items.toList().stream().map(item -> new DatasetProfileAutocompleteItem().fromDataModel(item)).collect(Collectors.toList());
return datasetProfiles; return datasetProfiles;
} }
public static DataTableData<DatasetProfileListingModel> getPaged(DatasetProfileDao datasetProfileRepository, DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception { public static DataTableData<DatasetProfileListingModel> getPaged(ApiContext apiContext, DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception {
QueryableList<DatasetProfile> items = datasetProfileRepository.getWithCriteria(datasetProfileTableRequestItem.getCriteria()); QueryableList<DatasetProfile> items = apiContext.getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria());
QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem); QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem);
List<DatasetProfileListingModel> datasetProfiles = new DomainModelConverter<DatasetProfile, DatasetProfileListingModel>().fromDataModel( pagedItems.toList(), DatasetProfileListingModel.class); List<DatasetProfileListingModel> datasetProfiles = pagedItems.toList().stream().map(item -> new DatasetProfileListingModel().fromDataModel(item)).collect(Collectors.toList());
DataTableData<DatasetProfileListingModel> dataTable = new DataTableData<>(); return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
dataTable.setData(datasetProfiles);
dataTable.setTotalCount(items.count());
return dataTable;
} }
public static List<DatasetProfileListingModel> getAll(DatasetProfileDao datasetProfileRepository) throws IllegalAccessException, InstantiationException { public static List<DatasetProfileListingModel> getAll(DatasetProfileDao datasetProfileRepository) throws IllegalAccessException, InstantiationException {
QueryableList<DatasetProfile> items = datasetProfileRepository.getAll(); QueryableList<DatasetProfile> items = datasetProfileRepository.getAll();
List<DatasetProfileListingModel> datasetProfiles = new DomainModelConverter<DatasetProfile, DatasetProfileListingModel>().fromDataModel( items.toList(), DatasetProfileListingModel.class); List<DatasetProfileListingModel> datasetProfiles = items.toList().stream().map(item -> new DatasetProfileListingModel().fromDataModel(item)).collect(Collectors.toList());
return datasetProfiles; return datasetProfiles;
} }
} }

View File

@ -1,24 +1,19 @@
package eu.eudat.managers; package eu.eudat.managers;
import eu.eudat.dao.entities.DMPDao; import eu.eudat.dao.entities.DMPDao;
import eu.eudat.dao.entities.DatasetDao;
import eu.eudat.entities.DMP; import eu.eudat.entities.DMP;
import eu.eudat.entities.Dataset;
import eu.eudat.entities.UserInfo; import eu.eudat.entities.UserInfo;
import eu.eudat.models.datasetwizard.DataManagentPlanListingModel; import eu.eudat.models.datasetwizard.DataManagentPlanListingModel;
import eu.eudat.models.datasetwizard.DatasetProfileWizardAutocompleteRequest; import eu.eudat.models.datasetwizard.DatasetProfileWizardAutocompleteRequest;
import eu.eudat.models.datasetwizard.DatasetWizardAutocompleteRequest; import eu.eudat.models.datasetwizard.DatasetWizardAutocompleteRequest;
import eu.eudat.models.dmp.AssociatedProfile; import eu.eudat.models.dmp.AssociatedProfile;
import eu.eudat.models.dmp.DataManagementPlan; import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.listingmodels.DatasetListingModel;
import eu.eudat.models.security.Principal; import eu.eudat.models.security.Principal;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -28,12 +23,12 @@ public class DatasetWizardManager {
UserInfo userInfo = new UserInfo(); UserInfo userInfo = new UserInfo();
userInfo.setId(principal.getId()); userInfo.setId(principal.getId());
QueryableList<DMP> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest, userInfo); QueryableList<DMP> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest, userInfo);
List<DataManagentPlanListingModel> dataManagementPlans = new DomainModelConverter<DMP, DataManagentPlanListingModel>().fromDataModel( items.toList(), DataManagentPlanListingModel.class); List<DataManagentPlanListingModel> dataManagementPlans = items.toList().stream().map(item -> new DataManagentPlanListingModel().fromDataModel(item)).collect(Collectors.toList());
return dataManagementPlans; return dataManagementPlans;
} }
public static List<AssociatedProfile> getAvailableProfiles(DMPDao dmpRepository, DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest) throws InstantiationException, IllegalAccessException { public static List<AssociatedProfile> getAvailableProfiles(DMPDao dmpRepository, DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest) throws InstantiationException, IllegalAccessException {
DataManagementPlan dataManagementPlan = new DomainModelConverter<eu.eudat.entities.DMP,DataManagementPlan>().fromDataModel(new LinkedList<DMP>(Arrays.asList(dmpRepository.find(datasetProfileWizardAutocompleteRequest.getCriteria().getId()))),DataManagementPlan.class).get(0); DataManagementPlan dataManagementPlan = new DataManagementPlan().fromDataModel(dmpRepository.find(datasetProfileWizardAutocompleteRequest.getCriteria().getId()));
if (dataManagementPlan.getProfiles() == null || dataManagementPlan.getProfiles().isEmpty()) { if (dataManagementPlan.getProfiles() == null || dataManagementPlan.getProfiles().isEmpty()) {
return new LinkedList<>(); return new LinkedList<>();
} }

View File

@ -1,5 +1,7 @@
package eu.eudat.managers; package eu.eudat.managers;
import eu.eudat.builders.model.criteria.ExternalDatasetCriteriaBuilder;
import eu.eudat.builders.model.models.DataTableDataBuilder;
import eu.eudat.dao.entities.ExternalDatasetDao; import eu.eudat.dao.entities.ExternalDatasetDao;
import eu.eudat.entities.ExternalDataset; import eu.eudat.entities.ExternalDataset;
import eu.eudat.models.criteria.ExternalDatasetCriteria; import eu.eudat.models.criteria.ExternalDatasetCriteria;
@ -10,29 +12,26 @@ import eu.eudat.proxy.config.exceptions.HugeResultSet;
import eu.eudat.proxy.config.exceptions.NoURLFound; import eu.eudat.proxy.config.exceptions.NoURLFound;
import eu.eudat.proxy.fetching.RemoteFetcher; import eu.eudat.proxy.fetching.RemoteFetcher;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter; import eu.eudat.services.ApiContext;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class ExternalDatasetManager { public class ExternalDatasetManager {
public DataTableData<ExternalDatasetListingModel> getPaged(ExternalDatasetDao externalDatasetDao, ExternalDatasetTableRequest externalDatasetTableRequest) throws Exception { public DataTableData<ExternalDatasetListingModel> getPaged(ApiContext apiContext, ExternalDatasetTableRequest externalDatasetTableRequest) throws Exception {
QueryableList<ExternalDataset> items = externalDatasetDao.getWithCriteria(externalDatasetTableRequest.getCriteria()); QueryableList<ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(externalDatasetTableRequest.getCriteria());
QueryableList<ExternalDataset> pagedItems = PaginationManager.applyPaging(items, externalDatasetTableRequest); QueryableList<ExternalDataset> pagedItems = PaginationManager.applyPaging(items, externalDatasetTableRequest);
List<ExternalDatasetListingModel> externalDatasetListingmodels = new DomainModelConverter<ExternalDataset, ExternalDatasetListingModel>().fromDataModel(pagedItems.toList(), ExternalDatasetListingModel.class); List<ExternalDatasetListingModel> externalDatasetListingmodels = pagedItems.toList().stream().map(item -> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
DataTableData<ExternalDatasetListingModel> externalDatasetDataTableData = new DataTableData<>(); return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(externalDatasetListingmodels).totalCount(items.count()).build();
externalDatasetDataTableData.setData(externalDatasetListingmodels);
externalDatasetDataTableData.setTotalCount(items.count());
return externalDatasetDataTableData;
} }
public List<ExternalDatasetListingModel> getWithExternal(ExternalDatasetDao externalDatasetDao , String query, RemoteFetcher remoteFetcher) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException { public List<ExternalDatasetListingModel> getWithExternal(ApiContext apiContext, String query, RemoteFetcher remoteFetcher) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException {
ExternalDatasetCriteria criteria = new ExternalDatasetCriteria(); ExternalDatasetCriteria criteria = apiContext.getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
criteria.setLike(query); QueryableList<eu.eudat.entities.ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
QueryableList<eu.eudat.entities.ExternalDataset> items = externalDatasetDao.getWithCriteria(criteria); List<ExternalDatasetListingModel> externalDatasets = items.toList().stream().map(item-> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
List<ExternalDatasetListingModel> externalDatasets = new DomainModelConverter<eu.eudat.entities.ExternalDataset, ExternalDatasetListingModel>().fromDataModel(items.toList(), ExternalDatasetListingModel.class);
return externalDatasets; return externalDatasets;
} }

View File

@ -9,7 +9,6 @@ import eu.eudat.models.userinfo.UserInfoInvitationModel;
import eu.eudat.models.userinfo.UserInfoRequestItem; import eu.eudat.models.userinfo.UserInfoRequestItem;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.services.ApiContext; import eu.eudat.services.ApiContext;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -22,21 +21,22 @@ public class InvitationsManager {
UserInfo principalUser = new UserInfo(); UserInfo principalUser = new UserInfo();
principalUser.setId(principal.getId()); principalUser.setId(principal.getId());
List<UserInfoInvitationModel> alreadySignedInUsers = invitation.getUsers().stream().filter(item -> item.getId() != null).collect(Collectors.toList()); List<UserInfoInvitationModel> alreadySignedInUsers = invitation.getUsers().stream().filter(item -> item.getId() != null).collect(Collectors.toList());
List<UserInfo> alreadySignedInUsersEntities = new DomainModelConverter<UserInfo, UserInfoInvitationModel>().toDataModel(alreadySignedInUsers); List<UserInfo> alreadySignedInUsersEntities = alreadySignedInUsers.stream().map(item -> item.toDataModel()).collect(Collectors.toList());
DMP dataManagementPlan = apiContext.getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan()); DMP dataManagementPlan = apiContext.getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan());
apiContext.getInvitationService().createInvitations(apiContext.getDatabaseRepository().getInvitationDao(), apiContext.getMailService(), new DomainModelConverter<UserInfo, UserInfoInvitationModel>().toDataModel(invitation.getUsers()), dataManagementPlan, principalUser); apiContext.getInvitationService().createInvitations(apiContext.getDatabaseRepository().getInvitationDao(), apiContext.getMailService(), invitation.getUsers().stream().map(item -> item.toDataModel()).collect(Collectors.toList()), dataManagementPlan, principalUser);
apiContext.getInvitationService().assignToDmp(apiContext.getDatabaseRepository().getDmpDao(), alreadySignedInUsersEntities, dataManagementPlan); apiContext.getInvitationService().assignToDmp(apiContext.getDatabaseRepository().getDmpDao(), alreadySignedInUsersEntities, dataManagementPlan);
} }
public static List<UserInfoInvitationModel> getUsers(ApiContext apiContext, UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException { public static List<UserInfoInvitationModel> getUsers(ApiContext apiContext, UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException {
QueryableList<UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoRequestItem.getCriteria()); QueryableList<UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoRequestItem.getCriteria());
List<UserInfoInvitationModel> userModels = new DomainModelConverter<UserInfo, UserInfoInvitationModel>().fromDataModel(users.toList(), UserInfoInvitationModel.class); List<UserInfoInvitationModel> userModels = users.toList().stream().map(item -> new UserInfoInvitationModel().fromDataModel(item)).collect(Collectors.toList());
return userModels; return userModels;
} }
public static UUID assignUserAcceptedInvitation(ApiContext apiContext, UUID invitationID, Principal principal) throws UnauthorisedException { public static UUID assignUserAcceptedInvitation(ApiContext apiContext, UUID invitationID, Principal principal) throws UnauthorisedException {
eu.eudat.entities.Invitation invitation = apiContext.getDatabaseRepository().getInvitationDao().find(invitationID); eu.eudat.entities.Invitation invitation = apiContext.getDatabaseRepository().getInvitationDao().find(invitationID);
if (invitation == null) throw new UnauthorisedException("There is no Data Management Plan assigned to this Link"); if (invitation == null)
throw new UnauthorisedException("There is no Data Management Plan assigned to this Link");
if (invitation.getAcceptedInvitation()) throw new UnauthorisedException("This Url Has Expired"); if (invitation.getAcceptedInvitation()) throw new UnauthorisedException("This Url Has Expired");
UserInfo invitedUser = apiContext.getDatabaseRepository().getUserInfoDao().find(principal.getId()); UserInfo invitedUser = apiContext.getDatabaseRepository().getUserInfoDao().find(principal.getId());
DMP datamanagementPlan = invitation.getDmp(); DMP datamanagementPlan = invitation.getDmp();

View File

@ -5,14 +5,15 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import eu.eudat.builders.model.models.ProjectBuilder;
import eu.eudat.dao.entities.ProjectDao; import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.dao.entities.UserInfoDao; import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.models.HintedModelFactory; import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.external.ExternalSourcesItemModel; import eu.eudat.models.external.ExternalSourcesItemModel;
import eu.eudat.models.external.ProjectsExternalSourcesModel; import eu.eudat.models.external.ProjectsExternalSourcesModel;
import eu.eudat.models.helpers.common.DataTableData; import eu.eudat.models.helpers.common.DataTableData;
import eu.eudat.models.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.project.Project; import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectCriteriaRequest; import eu.eudat.models.project.ProjectCriteriaRequest;
import eu.eudat.models.project.ProjectListingModel; import eu.eudat.models.project.ProjectListingModel;
@ -22,7 +23,7 @@ import eu.eudat.proxy.config.exceptions.HugeResultSet;
import eu.eudat.proxy.config.exceptions.NoURLFound; import eu.eudat.proxy.config.exceptions.NoURLFound;
import eu.eudat.proxy.fetching.RemoteFetcher; import eu.eudat.proxy.fetching.RemoteFetcher;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter; import eu.eudat.services.ApiContext;
public class ProjectManager { public class ProjectManager {
@ -32,7 +33,7 @@ public class ProjectManager {
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<eu.eudat.models.project.ProjectListingModel>(); DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<eu.eudat.models.project.ProjectListingModel>();
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).toListAsync().whenComplete((results, throwable) -> { CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).toListAsync().whenComplete((results, throwable) -> {
List<eu.eudat.models.project.ProjectListingModel> projects = new DomainModelConverter<eu.eudat.entities.Project, ProjectListingModel>().fromDataModel(results, eu.eudat.models.project.ProjectListingModel.class); List<eu.eudat.models.project.ProjectListingModel> projects = results.stream().map(item -> new ProjectListingModel().fromDataModel(item)).collect(Collectors.toList());
dataTable.setData(projects); dataTable.setData(projects);
}); });
@ -55,19 +56,18 @@ public class ProjectManager {
return project; return project;
} }
public List<eu.eudat.models.project.Project> getCriteriaWithExternal(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { public List<eu.eudat.models.project.Project> getCriteriaWithExternal(ApiContext apiContext, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); QueryableList<eu.eudat.entities.Project> items = apiContext.getDatabaseRepository().getProjectDao().getWithCriteria(projectCriteria.getCriteria());
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(items.toList(), eu.eudat.models.project.Project.class); List<eu.eudat.models.project.Project> projects = items.toList().stream().map(item -> new Project().fromDataModel(item)).collect(Collectors.toList());
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike()); List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike());
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos); ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) { for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
eu.eudat.models.project.Project project = new eu.eudat.models.project.Project(); eu.eudat.models.project.Project project = apiContext.getBuilderFactory().getBuilder(ProjectBuilder.class)
project.setReference(externalListingItem.getRemoteId()); .reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
project.setLabel(externalListingItem.getName()); .description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
project.setDescription(externalListingItem.getDescription()); .abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.entities.Project.Status.fromInteger(0))
project.setUri(externalListingItem.getUri()); .build();
project.setAbbreviation(externalListingItem.getAbbreviation());
project.setStatus((short) 0);
projects.add(project); projects.add(project);
} }
@ -76,7 +76,7 @@ public class ProjectManager {
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(items.toList(), eu.eudat.models.project.Project.class); List<eu.eudat.models.project.Project> projects = items.toList().stream().map(item -> new Project().fromDataModel(item)).collect(Collectors.toList());
return projects; return projects;
} }

View File

@ -2,9 +2,7 @@ package eu.eudat.managers;
import eu.eudat.entities.Researcher; import eu.eudat.entities.Researcher;
import eu.eudat.services.ApiContext; import eu.eudat.services.ApiContext;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.lang.reflect.Array;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -13,7 +11,7 @@ import java.util.Arrays;
public class ResearcherManager { public class ResearcherManager {
public static Researcher create(ApiContext apiContext, eu.eudat.models.researcher.Researcher researcher) throws Exception { public static Researcher create(ApiContext apiContext, eu.eudat.models.researcher.Researcher researcher) throws Exception {
Researcher researcherEntity = new DomainModelConverter<Researcher, eu.eudat.models.researcher.Researcher>().toDataModel(Arrays.asList(researcher)).get(0); Researcher researcherEntity = researcher.toDataModel();
return apiContext.getDatabaseRepository().getResearcherDao().createOrUpdate(researcherEntity); return apiContext.getDatabaseRepository().getResearcherDao().createOrUpdate(researcherEntity);
} }
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.managers; package eu.eudat.managers;
import eu.eudat.dao.entities.UserInfoDao; import eu.eudat.builders.entity.UserRoleBuilder;
import eu.eudat.builders.model.models.DataTableDataBuilder;
import eu.eudat.entities.UserRole; import eu.eudat.entities.UserRole;
import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.models.helpers.common.DataTableData; import eu.eudat.models.helpers.common.DataTableData;
@ -11,13 +12,13 @@ import eu.eudat.models.userinfo.UserListingModel;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.services.ApiContext; import eu.eudat.services.ApiContext;
import eu.eudat.services.AuthenticationService; import eu.eudat.services.AuthenticationService;
import eu.eudat.utilities.builders.DomainModelConverter;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import eu.eudat.utilities.builders.XmlBuilder; import eu.eudat.utilities.builders.XmlBuilder;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class UserManager { public class UserManager {
public static eu.eudat.models.user.composite.DatasetProfile generateDatasetProfileModel(eu.eudat.entities.DatasetProfile profile) { public static eu.eudat.models.user.composite.DatasetProfile generateDatasetProfileModel(eu.eudat.entities.DatasetProfile profile) {
@ -31,24 +32,19 @@ public class UserManager {
return datasetprofile; return datasetprofile;
} }
public static DataTableData<UserListingModel> getPaged(UserInfoDao userInfoDao, UserInfoTableRequestItem userInfoTableRequestItem) throws Exception { public static DataTableData<UserListingModel> getPaged(ApiContext apiContext, UserInfoTableRequestItem userInfoTableRequestItem) throws Exception {
QueryableList<eu.eudat.entities.UserInfo> users = userInfoDao.getWithCriteria(userInfoTableRequestItem.getCriteria()); QueryableList<eu.eudat.entities.UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoTableRequestItem.getCriteria());
QueryableList<eu.eudat.entities.UserInfo> pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem); QueryableList<eu.eudat.entities.UserInfo> pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem);
List<UserListingModel> modelUsers = new DomainModelConverter<eu.eudat.entities.UserInfo, UserListingModel>().fromDataModel(pagedUsers.toList(), UserListingModel.class); List<UserListingModel> modelUsers = pagedUsers.toList().stream().map(item -> new UserListingModel().fromDataModel(item)).collect(Collectors.toList());
DataTableData<UserListingModel> dataTableData = new DataTableData<>(); return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build();
dataTableData.setData(modelUsers);
dataTableData.setTotalCount(users.count());
return dataTableData;
} }
public static void editRoles(ApiContext apiContext, UserListingModel user) { public static void editRoles(ApiContext apiContext, UserListingModel user) {
eu.eudat.entities.UserInfo userInfo = apiContext.getDatabaseRepository().getUserInfoDao().find(user.getId()); eu.eudat.entities.UserInfo userInfo = apiContext.getDatabaseRepository().getUserInfoDao().find(user.getId());
userInfo.getUserRoles().stream().forEach(item -> apiContext.getDatabaseRepository().getUserRoleDao().delete(item)); userInfo.getUserRoles().stream().forEach(item -> apiContext.getDatabaseRepository().getUserRoleDao().delete(item));
for (Integer role : user.getAppRoles()) { for (Integer role : user.getAppRoles()) {
UserRole userRole = new UserRole(); UserRole userRole = apiContext.getBuilderFactory().getBuilder(UserRoleBuilder.class).role(role).userInfo(userInfo).build();
userRole.setRole(role);
userRole.setUserInfo(userInfo);
apiContext.getDatabaseRepository().getUserRoleDao().createOrUpdate(userRole); apiContext.getDatabaseRepository().getUserRoleDao().createOrUpdate(userRole);
} }
} }

View File

@ -2,8 +2,8 @@ package eu.eudat.models;
import eu.eudat.entities.DataEntity; import eu.eudat.entities.DataEntity;
public interface DataModel<T extends DataEntity> { public interface DataModel<T extends DataEntity,M extends DataModel> {
void fromDataModel(T entity) throws InstantiationException, IllegalAccessException; M fromDataModel(T entity);
T toDataModel() throws Exception; T toDataModel() throws Exception;
String getHint(); String getHint();
} }

View File

@ -1,9 +1,7 @@
package eu.eudat.models.criteria; package eu.eudat.models.criteria;
import eu.eudat.entities.DMP; import eu.eudat.entities.DMP;
import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectCriteriaModel; import eu.eudat.models.project.ProjectCriteriaModel;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.util.Date; import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
@ -61,7 +59,7 @@ public class DataManagementPlanCriteria extends Criteria<DMP> {
public List<eu.eudat.entities.Project> getProjectEntities() { public List<eu.eudat.entities.Project> getProjectEntities() {
try { try {
return new DomainModelConverter<eu.eudat.entities.Project, ProjectCriteriaModel>().toDataModel(this.projects); return this.projects.stream().map(item-> item.toDataModel()).collect(Collectors.toList());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return new LinkedList<>(); return new LinkedList<>();

View File

@ -5,7 +5,7 @@ import eu.eudat.utilities.helpers.LabelGenerator;
import java.util.Date; import java.util.Date;
public class DataRepository implements DataModel<eu.eudat.entities.DataRepository>,LabelGenerator{ public class DataRepository implements DataModel<eu.eudat.entities.DataRepository,DataRepository>,LabelGenerator{
private String pid; private String pid;
private String name; private String name;
private String uri; private String uri;
@ -34,10 +34,11 @@ public class DataRepository implements DataModel<eu.eudat.entities.DataRepositor
this.uri = uri; this.uri = uri;
} }
public void fromDataModel(eu.eudat.entities.DataRepository entity){ public DataRepository fromDataModel(eu.eudat.entities.DataRepository entity){
this.pid = entity.getReference(); this.pid = entity.getReference();
this.name = entity.getLabel(); this.name = entity.getLabel();
this.uri = entity.getUri(); this.uri = entity.getUri();
return this;
} }
public eu.eudat.entities.DataRepository toDataModel(){ public eu.eudat.entities.DataRepository toDataModel(){

View File

@ -3,16 +3,14 @@ package eu.eudat.models.dataset;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
import eu.eudat.models.datasetprofile.DatasetProfileListingModel; import eu.eudat.models.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.dmp.DataManagementPlan; import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Dataset implements DataModel<eu.eudat.entities.Dataset>{ public class Dataset implements DataModel<eu.eudat.entities.Dataset,Dataset>{
private UUID id; private UUID id;
private String label; private String label;
private String reference; private String reference;
@ -114,7 +112,7 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
this.profile = profile; this.profile = profile;
} }
public void fromDataModel(eu.eudat.entities.Dataset entity) throws IllegalAccessException, InstantiationException{ public Dataset fromDataModel(eu.eudat.entities.Dataset entity) {
this.id = entity.getId(); this.id = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.properties = entity.getProperties(); this.properties = entity.getProperties();
@ -122,10 +120,11 @@ public class Dataset implements DataModel<eu.eudat.entities.Dataset>{
this.description = entity.getDescription(); this.description = entity.getDescription();
this.profile = new DatasetProfileListingModel(); this.profile = new DatasetProfileListingModel();
this.profile.fromDataModel(entity.getProfile()); this.profile.fromDataModel(entity.getProfile());
this.registries = new DomainModelConverter<eu.eudat.entities.Registry,Registry>().fromDataModel(entity.getRegistries().stream().collect(Collectors.toList()), Registry.class); this.registries = entity.getRegistries().stream().map(item-> new Registry().fromDataModel(item)).collect(Collectors.toList());
this.dataRepositories = new DomainModelConverter<eu.eudat.entities.DataRepository,DataRepository>().fromDataModel(entity.getDataRepositories().stream().collect(Collectors.toList()), DataRepository.class); this.dataRepositories = entity.getDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item)).collect(Collectors.toList());
this.services = new DomainModelConverter<eu.eudat.entities.Service,Service>().fromDataModel(entity.getServices().stream().collect(Collectors.toList()), Service.class); this.services = entity.getServices().stream().map(item -> new Service().fromDataModel(item)).collect(Collectors.toList());
this.created = entity.getCreated(); this.created = entity.getCreated();
return this;
} }
public eu.eudat.entities.Dataset toDataModel() throws Exception { public eu.eudat.entities.Dataset toDataModel() throws Exception {

View File

@ -7,7 +7,7 @@ import org.hibernate.annotations.Type;
import javax.persistence.Column; import javax.persistence.Column;
import java.util.UUID; import java.util.UUID;
public class Registry implements DataModel<eu.eudat.entities.Registry>,LabelGenerator { public class Registry implements DataModel<eu.eudat.entities.Registry,Registry>,LabelGenerator {
private UUID id; private UUID id;
private String label; private String label;
private String abbreviation; private String abbreviation;
@ -68,13 +68,14 @@ public class Registry implements DataModel<eu.eudat.entities.Registry>,LabelGene
this.definition = definition; this.definition = definition;
} }
public void fromDataModel(eu.eudat.entities.Registry entity){ public Registry fromDataModel(eu.eudat.entities.Registry entity){
this.id = entity.getId(); this.id = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.abbreviation = entity.getAbbreviation(); this.abbreviation = entity.getAbbreviation();
this.reference = entity.getReference(); this.reference = entity.getReference();
this.uri = entity.getUri(); this.uri = entity.getUri();
this.definition = entity.getDefinition(); this.definition = entity.getDefinition();
return this;
} }
public eu.eudat.entities.Registry toDataModel(){ public eu.eudat.entities.Registry toDataModel(){

View File

@ -7,7 +7,7 @@ import org.hibernate.annotations.Type;
import javax.persistence.Column; import javax.persistence.Column;
import java.util.UUID; import java.util.UUID;
public class Service implements DataModel<eu.eudat.entities.Service>,LabelGenerator{ public class Service implements DataModel<eu.eudat.entities.Service,Service>,LabelGenerator{
private UUID id; private UUID id;
private String label; private String label;
@ -67,13 +67,14 @@ public class Service implements DataModel<eu.eudat.entities.Service>,LabelGenera
this.definition = definition; this.definition = definition;
} }
public void fromDataModel(eu.eudat.entities.Service entity){ public Service fromDataModel(eu.eudat.entities.Service entity){
this.id = entity.getId(); this.id = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.abbreviation = entity.getAbbreviation(); this.abbreviation = entity.getAbbreviation();
this.reference = entity.getReference(); this.reference = entity.getReference();
this.uri = entity.getUri(); this.uri = entity.getUri();
this.definition = entity.getDefinition(); this.definition = entity.getDefinition();
return this;
} }
public eu.eudat.entities.Service toDataModel(){ public eu.eudat.entities.Service toDataModel(){

View File

@ -6,7 +6,7 @@ import eu.eudat.models.DataModel;
import java.util.UUID; import java.util.UUID;
public class DatasetProfileAutocompleteItem implements DataModel<DatasetProfile> { public class DatasetProfileAutocompleteItem implements DataModel<DatasetProfile,DatasetProfileAutocompleteItem> {
private UUID id; private UUID id;
@ -29,9 +29,10 @@ public class DatasetProfileAutocompleteItem implements DataModel<DatasetProfile>
} }
@Override @Override
public void fromDataModel(DatasetProfile entity) throws InstantiationException, IllegalAccessException { public DatasetProfileAutocompleteItem fromDataModel(DatasetProfile entity) {
this.id = entity.getId(); this.id = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
return this;
} }
@Override @Override

View File

@ -14,7 +14,7 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class DatasetProfileListingModel implements DataModel<DatasetProfile> { public class DatasetProfileListingModel implements DataModel<DatasetProfile,DatasetProfileListingModel> {
private UUID id; private UUID id;
@ -77,13 +77,14 @@ public class DatasetProfileListingModel implements DataModel<DatasetProfile> {
} }
@Override @Override
public void fromDataModel(DatasetProfile entity) throws InstantiationException, IllegalAccessException { public DatasetProfileListingModel fromDataModel(DatasetProfile entity) {
this.id = entity.getId(); this.id = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.status = entity.getStatus(); this.status = entity.getStatus();
this.created = entity.getCreated(); this.created = entity.getCreated();
this.modified = entity.getModified(); this.modified = entity.getModified();
this.description = entity.getDescription(); this.description = entity.getDescription();
return this;
} }
@Override @Override

View File

@ -4,7 +4,7 @@ import eu.eudat.entities.DMP;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
public class DataManagentPlanListingModel implements DataModel<DMP>{ public class DataManagentPlanListingModel implements DataModel<DMP,DataManagentPlanListingModel>{
private String id; private String id;
private String label; private String label;
@ -26,9 +26,10 @@ public class DataManagentPlanListingModel implements DataModel<DMP>{
} }
@Override @Override
public void fromDataModel(DMP entity) throws InstantiationException, IllegalAccessException { public DataManagentPlanListingModel fromDataModel(DMP entity) {
this.id = entity.getId().toString(); this.id = entity.getId().toString();
this.label = entity.getLabel(); this.label = entity.getLabel();
return this;
} }
@Override @Override

View File

@ -1,6 +1,5 @@
package eu.eudat.models.datasetwizard; package eu.eudat.models.datasetwizard;
import eu.eudat.entities.DMP;
import eu.eudat.entities.Dataset; import eu.eudat.entities.Dataset;
import eu.eudat.entities.ExternalDataset; import eu.eudat.entities.ExternalDataset;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
@ -10,17 +9,13 @@ import eu.eudat.models.dataset.Service;
import eu.eudat.models.datasetprofile.DatasetProfileListingModel; import eu.eudat.models.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.dmp.DataManagementPlan; import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.externaldataset.ExternalDatasetListingModel; import eu.eudat.models.externaldataset.ExternalDatasetListingModel;
import eu.eudat.models.listingmodels.DatasetListingModel;
import eu.eudat.models.properties.PropertiesModel;
import eu.eudat.models.user.composite.DatasetProfile;
import eu.eudat.models.user.composite.PagedDatasetProfile; import eu.eudat.models.user.composite.PagedDatasetProfile;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class DatasetWizardModel implements DataModel<Dataset> { public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel> {
private UUID id; private UUID id;
private String label; private String label;
@ -150,7 +145,7 @@ public class DatasetWizardModel implements DataModel<Dataset> {
} }
@Override @Override
public void fromDataModel(Dataset entity) throws InstantiationException, IllegalAccessException { public DatasetWizardModel fromDataModel(Dataset entity) {
this.id = entity.getId(); this.id = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.status = entity.getStatus(); this.status = entity.getStatus();
@ -159,12 +154,13 @@ public class DatasetWizardModel implements DataModel<Dataset> {
this.profile = new DatasetProfileListingModel(); this.profile = new DatasetProfileListingModel();
this.uri = entity.getUri(); this.uri = entity.getUri();
this.profile.fromDataModel(entity.getProfile()); this.profile.fromDataModel(entity.getProfile());
this.registries = new DomainModelConverter<eu.eudat.entities.Registry, Registry>().fromDataModel(entity.getRegistries().stream().collect(Collectors.toList()), Registry.class); this.registries = entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList());
this.dataRepositories = new DomainModelConverter<eu.eudat.entities.DataRepository, DataRepository>().fromDataModel(entity.getDataRepositories().stream().collect(Collectors.toList()), DataRepository.class); this.dataRepositories = entity.getDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item)).collect(Collectors.toList());
this.services = new DomainModelConverter<eu.eudat.entities.Service, Service>().fromDataModel(entity.getServices().stream().collect(Collectors.toList()), Service.class); this.services = entity.getServices().stream().map(item -> new Service().fromDataModel(item)).collect(Collectors.toList());
this.created = entity.getCreated(); this.created = entity.getCreated();
this.dmp = new DomainModelConverter<eu.eudat.entities.DMP, DataManagementPlan>().fromDataModel(Arrays.asList(entity.getDmp()), DataManagementPlan.class).get(0); this.dmp = new DataManagementPlan().fromDataModel(entity.getDmp());
this.externalDatasets = new DomainModelConverter<ExternalDataset, ExternalDatasetListingModel>().fromDataModel(entity.getExternalDatasets().stream().collect(Collectors.toList()), ExternalDatasetListingModel.class); this.externalDatasets = entity.getExternalDatasets().stream().map(item -> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
return this;
} }
@Override @Override

View File

@ -4,18 +4,16 @@ import eu.eudat.entities.*;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
import eu.eudat.models.project.Project; import eu.eudat.models.project.Project;
import eu.eudat.models.userinfo.UserInfo; import eu.eudat.models.userinfo.UserInfo;
import eu.eudat.utilities.builders.DomainModelConverter;
import eu.eudat.utilities.builders.XmlBuilder; import eu.eudat.utilities.builders.XmlBuilder;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import java.text.ParseException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class DataManagementPlan implements DataModel<DMP> { public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
private UUID id; private UUID id;
private String label; private String label;
private UUID groupId; private UUID groupId;
@ -135,10 +133,10 @@ public class DataManagementPlan implements DataModel<DMP> {
} }
@Override @Override
public void fromDataModel(DMP entity) throws InstantiationException, IllegalAccessException { public DataManagementPlan fromDataModel(DMP entity) {
this.id = entity.getId(); this.id = entity.getId();
this.organisations = new DomainModelConverter<eu.eudat.entities.Organisation, Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()), Organisation.class); this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
this.researchers = new DomainModelConverter<eu.eudat.entities.Researcher, Researcher>().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()), Researcher.class); this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
this.version = entity.getVersion(); this.version = entity.getVersion();
this.groupId = this.groupId == null ? null : this.groupId; this.groupId = this.groupId == null ? null : this.groupId;
this.label = entity.getLabel(); this.label = entity.getLabel();
@ -164,7 +162,8 @@ public class DataManagementPlan implements DataModel<DMP> {
} }
this.created = entity.getCreated(); this.created = entity.getCreated();
this.description = entity.getDescription(); this.description = entity.getDescription();
this.associatedUsers = new DomainModelConverter<eu.eudat.entities.UserInfo, UserInfo>().fromDataModel(entity.getUsers().stream().collect(Collectors.toList()), UserInfo.class); this.associatedUsers = entity.getUsers().stream().map(item -> new UserInfo().fromDataModel(item)).collect(Collectors.toList());
return this;
} }
@Override @Override
@ -172,9 +171,9 @@ public class DataManagementPlan implements DataModel<DMP> {
DMP dataManagementPlanEntity = new DMP(); DMP dataManagementPlanEntity = new DMP();
dataManagementPlanEntity.setId(this.id); dataManagementPlanEntity.setId(this.id);
if (this.organisations != null && !this.organisations.isEmpty()) if (this.organisations != null && !this.organisations.isEmpty())
dataManagementPlanEntity.setOrganisations(new HashSet<eu.eudat.entities.Organisation>(new DomainModelConverter<eu.eudat.entities.Organisation, Organisation>().toDataModel(this.organisations))); dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
if (this.researchers != null && !this.researchers.isEmpty()) if (this.researchers != null && !this.researchers.isEmpty())
dataManagementPlanEntity.setResearchers(new HashSet<eu.eudat.entities.Researcher>(new DomainModelConverter<eu.eudat.entities.Researcher, Researcher>().toDataModel(this.researchers))); dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
dataManagementPlanEntity.setVersion(this.version); dataManagementPlanEntity.setVersion(this.version);
dataManagementPlanEntity.setLabel(this.label); dataManagementPlanEntity.setLabel(this.label);
@ -192,7 +191,7 @@ public class DataManagementPlan implements DataModel<DMP> {
} }
dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID()); dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID());
dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date()); dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
dataManagementPlanEntity.setUsers(new HashSet<>(new DomainModelConverter<eu.eudat.entities.UserInfo,UserInfo>().toDataModel(this.associatedUsers))); dataManagementPlanEntity.setUsers(new HashSet<>(this.associatedUsers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
return dataManagementPlanEntity; return dataManagementPlanEntity;
} }

View File

@ -5,18 +5,17 @@ import eu.eudat.models.DataModel;
import eu.eudat.models.dataset.Dataset; import eu.eudat.models.dataset.Dataset;
import eu.eudat.models.project.Project; import eu.eudat.models.project.Project;
import eu.eudat.models.userinfo.UserInfo; import eu.eudat.models.userinfo.UserInfo;
import eu.eudat.utilities.builders.DomainModelConverter;
import eu.eudat.utilities.builders.XmlBuilder; import eu.eudat.utilities.builders.XmlBuilder;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import java.lang.reflect.Array;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* Created by ikalyvas on 2/5/2018. * Created by ikalyvas on 2/5/2018.
*/ */
public class DataManagementPlanNewVersionModel implements DataModel<DMP> { public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataManagementPlanNewVersionModel> {
private UUID id; private UUID id;
private String label; private String label;
private UUID groupId; private UUID groupId;
@ -145,15 +144,15 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP> {
} }
@Override @Override
public void fromDataModel(DMP entity) throws InstantiationException, IllegalAccessException { public DataManagementPlanNewVersionModel fromDataModel(DMP entity) {
return null;
} }
@Override @Override
public DMP toDataModel() throws Exception { public DMP toDataModel() throws Exception {
DMP entity = new DMP(); DMP entity = new DMP();
entity.setId(this.id); entity.setId(this.id);
entity.setUsers(new HashSet<>(new DomainModelConverter<eu.eudat.entities.UserInfo, UserInfo>().toDataModel(this.associatedUsers))); entity.setUsers(new HashSet<>(this.associatedUsers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
entity.setDescription(this.description); entity.setDescription(this.description);
entity.setStatus((short) this.status); entity.setStatus((short) this.status);
entity.setGroupId(this.groupId == null ? UUID.randomUUID() : this.groupId); entity.setGroupId(this.groupId == null ? UUID.randomUUID() : this.groupId);
@ -170,9 +169,9 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP> {
entity.setDataset(new HashSet<>(datasets)); entity.setDataset(new HashSet<>(datasets));
} }
if (this.organisations != null && !this.organisations.isEmpty()) if (this.organisations != null && !this.organisations.isEmpty())
entity.setOrganisations(new HashSet<eu.eudat.entities.Organisation>(new DomainModelConverter<eu.eudat.entities.Organisation, Organisation>().toDataModel(this.organisations))); entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
if (this.researchers != null && !this.researchers.isEmpty()) if (this.researchers != null && !this.researchers.isEmpty())
entity.setResearchers(new HashSet<eu.eudat.entities.Researcher>(new DomainModelConverter<eu.eudat.entities.Researcher, Researcher>().toDataModel(this.researchers))); entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
if (this.project != null) entity.setProject(this.project.toDataModel()); if (this.project != null) entity.setProject(this.project.toDataModel());
if (this.profiles != null) { if (this.profiles != null) {
Document associatedProfileDoc = XmlBuilder.getDocument(); Document associatedProfileDoc = XmlBuilder.getDocument();

View File

@ -5,7 +5,7 @@ import eu.eudat.utilities.helpers.LabelGenerator;
import java.util.Date; import java.util.Date;
public class Organisation implements DataModel<eu.eudat.entities.Organisation>,LabelGenerator { public class Organisation implements DataModel<eu.eudat.entities.Organisation,Organisation>,LabelGenerator {
private String label; private String label;
private String name; private String name;
private String id; private String id;
@ -44,10 +44,11 @@ public class Organisation implements DataModel<eu.eudat.entities.Organisation>,L
} }
@Override @Override
public void fromDataModel(eu.eudat.entities.Organisation entity) { public Organisation fromDataModel(eu.eudat.entities.Organisation entity) {
this.id = entity.getReference(); this.id = entity.getReference();
this.name = entity.getLabel(); this.name = entity.getLabel();
this.label = entity.getUri(); this.label = entity.getUri();
return this;
} }
@Override @Override

View File

@ -5,7 +5,7 @@ import eu.eudat.utilities.helpers.LabelGenerator;
import java.util.Date; import java.util.Date;
public class Researcher implements DataModel<eu.eudat.entities.Researcher>,LabelGenerator { public class Researcher implements DataModel<eu.eudat.entities.Researcher,Researcher>,LabelGenerator {
private String label; private String label;
private String name; private String name;
private String id; private String id;
@ -44,11 +44,12 @@ public class Researcher implements DataModel<eu.eudat.entities.Researcher>,Label
} }
@Override @Override
public void fromDataModel(eu.eudat.entities.Researcher entity) { public Researcher fromDataModel(eu.eudat.entities.Researcher entity) {
this.id = entity.getReference(); this.id = entity.getReference();
this.label = entity.getUri(); this.label = entity.getUri();
this.name = entity.getLabel(); this.name = entity.getLabel();
this.status = entity.getStatus(); this.status = entity.getStatus();
return this;
} }
@Override @Override

View File

@ -8,7 +8,7 @@ import java.util.Date;
import java.util.UUID; import java.util.UUID;
public class ExternalDatasetListingModel implements DataModel<ExternalDataset> { public class ExternalDatasetListingModel implements DataModel<ExternalDataset,ExternalDatasetListingModel> {
private UUID id; private UUID id;
private String label; private String label;
@ -66,13 +66,14 @@ public class ExternalDatasetListingModel implements DataModel<ExternalDataset> {
} }
@Override @Override
public void fromDataModel(ExternalDataset entity) throws InstantiationException, IllegalAccessException { public ExternalDatasetListingModel fromDataModel(ExternalDataset entity) {
this.id = entity.getId(); this.id = entity.getId();
this.abbreviation = entity.getAbbreviation(); this.abbreviation = entity.getAbbreviation();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.modified = entity.getModified(); this.modified = entity.getModified();
this.created = entity.getCreated(); this.created = entity.getCreated();
this.reference = entity.getReference(); this.reference = entity.getReference();
return this;
} }
@Override @Override

View File

@ -1,20 +1,15 @@
package eu.eudat.models.listingmodels; package eu.eudat.models.listingmodels;
import eu.eudat.entities.DMP; import eu.eudat.entities.DMP;
import eu.eudat.entities.DataRepository;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
import eu.eudat.models.dmp.Organisation; import eu.eudat.models.dmp.Organisation;
import eu.eudat.models.dmp.Researcher;
import eu.eudat.utilities.builders.DomainModelConverter;
import eu.eudat.utilities.helpers.LabelBuilder; import eu.eudat.utilities.helpers.LabelBuilder;
import eu.eudat.utilities.helpers.LabelGenerator;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class DataManagementPlanListingModel implements DataModel<DMP> { public class DataManagementPlanListingModel implements DataModel<DMP,DataManagementPlanListingModel> {
private String id; private String id;
private String label; private String label;
private String project; private String project;
@ -98,16 +93,17 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
} }
@Override @Override
public void fromDataModel(DMP entity) throws InstantiationException, IllegalAccessException { public DataManagementPlanListingModel fromDataModel(DMP entity) {
this.id = entity.getId().toString(); this.id = entity.getId().toString();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.project = entity.getProject().getLabel(); this.project = entity.getProject().getLabel();
if(entity.getProfile()!=null)this.profile = entity.getProfile().getLabel(); if(entity.getProfile()!=null)this.profile = entity.getProfile().getLabel();
this.organisations =LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.Organisation,Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class)); this.organisations =LabelBuilder.getLabel(entity.getOrganisations().stream().map(item-> new Organisation().fromDataModel(item)).collect(Collectors.toList()));
this.creationTime = entity.getCreated().toString(); this.creationTime = entity.getCreated().toString();
this.version = ""+entity.getVersion(); this.version = ""+entity.getVersion();
this.groupId = entity.getGroupId(); this.groupId = entity.getGroupId();
this.numOfDatasets = entity.getDataset().size(); this.numOfDatasets = entity.getDataset().size();
return this;
} }
@Override @Override

View File

@ -1,28 +1,16 @@
package eu.eudat.models.listingmodels; package eu.eudat.models.listingmodels;
import eu.eudat.entities.*;
import eu.eudat.entities.DataRepository;
import eu.eudat.entities.Dataset; import eu.eudat.entities.Dataset;
import eu.eudat.entities.Organisation;
import eu.eudat.entities.Registry; import eu.eudat.entities.Registry;
import eu.eudat.entities.Researcher;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
import eu.eudat.models.dataset.*; import eu.eudat.models.dataset.DataRepository;
import eu.eudat.models.dataset.Service; import eu.eudat.models.dataset.Service;
import eu.eudat.models.dmp.*;
import eu.eudat.utilities.builders.DomainModelConverter;
import eu.eudat.utilities.helpers.LabelBuilder; import eu.eudat.utilities.helpers.LabelBuilder;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class DatasetListingModel implements DataModel<Dataset> { public class DatasetListingModel implements DataModel<Dataset, DatasetListingModel> {
private String id; private String id;
private String label; private String label;
private String dmp; private String dmp;
@ -115,7 +103,7 @@ public class DatasetListingModel implements DataModel<Dataset> {
} }
@Override @Override
public void fromDataModel(Dataset entity) throws InstantiationException, IllegalAccessException { public DatasetListingModel fromDataModel(Dataset entity) {
this.id = entity.getId().toString(); this.id = entity.getId().toString();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.created = entity.getCreated().toString(); this.created = entity.getCreated().toString();
@ -123,9 +111,10 @@ public class DatasetListingModel implements DataModel<Dataset> {
this.profile = entity.getProfile() != null ? entity.getProfile().getLabel() : ""; this.profile = entity.getProfile() != null ? entity.getProfile().getLabel() : "";
this.description = entity.getDescription(); this.description = entity.getDescription();
this.status = "" + entity.getStatus(); this.status = "" + entity.getStatus();
this.registries = LabelBuilder.getLabel(new DomainModelConverter<Registry, eu.eudat.models.dataset.Registry>().fromDataModel(entity.getRegistries().stream().collect(Collectors.toList()), eu.eudat.models.dataset.Registry.class)); this.registries = LabelBuilder.getLabel(entity.getRegistries().stream().map(item -> new eu.eudat.models.dataset.Registry().fromDataModel(item)).collect(Collectors.toList()));
this.dataRepositories = LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.DataRepository, eu.eudat.models.dataset.DataRepository>().fromDataModel(entity.getDataRepositories().stream().collect(Collectors.toList()), eu.eudat.models.dataset.DataRepository.class)); this.dataRepositories = LabelBuilder.getLabel(entity.getDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item)).collect(Collectors.toList()));
this.services = LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.Service, eu.eudat.models.dataset.Service>().fromDataModel(entity.getServices().stream().collect(Collectors.toList()), Service.class)); this.services = LabelBuilder.getLabel(entity.getServices().stream().map(item -> new Service().fromDataModel(item)).collect(Collectors.toList()));
return this;
} }
@Override @Override

View File

@ -10,7 +10,7 @@ import eu.eudat.models.DataModel;
import eu.eudat.models.dmp.DataManagementPlan; import eu.eudat.models.dmp.DataManagementPlan;
public class Project implements DataModel<eu.eudat.entities.Project> { public class Project implements DataModel<eu.eudat.entities.Project,Project> {
private UUID id; private UUID id;
@ -154,7 +154,7 @@ public class Project implements DataModel<eu.eudat.entities.Project> {
} }
@Override @Override
public void fromDataModel(eu.eudat.entities.Project entity) throws InstantiationException, IllegalAccessException { public Project fromDataModel(eu.eudat.entities.Project entity) {
this.id = entity.getId(); this.id = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.abbreviation = entity.getAbbreviation(); this.abbreviation = entity.getAbbreviation();
@ -167,6 +167,7 @@ public class Project implements DataModel<eu.eudat.entities.Project> {
this.created = entity.getCreated(); this.created = entity.getCreated();
this.modified = entity.getModified(); this.modified = entity.getModified();
this.description = entity.getDescription(); this.description = entity.getDescription();
return this;
} }
@Override @Override

View File

@ -7,7 +7,7 @@ import eu.eudat.models.DataModel;
import java.util.UUID; import java.util.UUID;
public class ProjectCriteriaModel implements DataModel<eu.eudat.entities.Project> { public class ProjectCriteriaModel implements DataModel<eu.eudat.entities.Project,ProjectCriteriaModel> {
private UUID id; private UUID id;
public UUID getId() { public UUID getId() {
@ -19,8 +19,9 @@ public class ProjectCriteriaModel implements DataModel<eu.eudat.entities.Project
} }
@Override @Override
public void fromDataModel(Project entity) throws InstantiationException, IllegalAccessException { public ProjectCriteriaModel fromDataModel(Project entity) {
this.id = entity.getId(); this.id = entity.getId();
return this;
} }
@Override @Override

View File

@ -11,7 +11,7 @@ import eu.eudat.models.DataModel;
import eu.eudat.models.dmp.DataManagementPlan; import eu.eudat.models.dmp.DataManagementPlan;
public class ProjectListingModel implements DataModel<eu.eudat.entities.Project> { public class ProjectListingModel implements DataModel<eu.eudat.entities.Project,ProjectListingModel> {
private UUID id; private UUID id;
@ -155,7 +155,7 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project>
} }
@Override @Override
public void fromDataModel(eu.eudat.entities.Project entity) throws InstantiationException, IllegalAccessException { public ProjectListingModel fromDataModel(eu.eudat.entities.Project entity) {
this.id = entity.getId(); this.id = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.abbreviation = entity.getAbbreviation(); this.abbreviation = entity.getAbbreviation();
@ -168,7 +168,7 @@ public class ProjectListingModel implements DataModel<eu.eudat.entities.Project>
this.created = entity.getCreated().toString(); this.created = entity.getCreated().toString();
this.modified = entity.getModified().toString(); this.modified = entity.getModified().toString();
this.description = entity.getDescription(); this.description = entity.getDescription();
return this;
} }
@Override @Override

View File

@ -10,7 +10,7 @@ import java.util.UUID;
/** /**
* Created by ikalyvas on 2/5/2018. * Created by ikalyvas on 2/5/2018.
*/ */
public class Researcher implements DataModel<eu.eudat.entities.Researcher> { public class Researcher implements DataModel<eu.eudat.entities.Researcher,Researcher> {
private String firstName; private String firstName;
@ -33,8 +33,8 @@ public class Researcher implements DataModel<eu.eudat.entities.Researcher> {
} }
@Override @Override
public void fromDataModel(eu.eudat.entities.Researcher entity) throws InstantiationException, IllegalAccessException { public Researcher fromDataModel(eu.eudat.entities.Researcher entity) {
return null;
} }
@Override @Override

View File

@ -5,7 +5,7 @@ import java.util.UUID;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
public class UserInfo implements DataModel<eu.eudat.entities.UserInfo>{ public class UserInfo implements DataModel<eu.eudat.entities.UserInfo,UserInfo>{
private UUID id; private UUID id;
private String email = null; private String email = null;
@ -97,11 +97,12 @@ public class UserInfo implements DataModel<eu.eudat.entities.UserInfo>{
} }
@Override @Override
public void fromDataModel(eu.eudat.entities.UserInfo entity) throws InstantiationException, IllegalAccessException { public UserInfo fromDataModel(eu.eudat.entities.UserInfo entity) {
this.name = entity.getName(); this.name = entity.getName();
this.email = entity.getEmail(); this.email = entity.getEmail();
this.usertype = entity.getUsertype(); this.usertype = entity.getUsertype();
this.id = entity.getId(); this.id = entity.getId();
return this;
} }
@Override @Override

View File

@ -7,7 +7,7 @@ import eu.eudat.models.DataModel;
import java.util.UUID; import java.util.UUID;
public class UserInfoInvitationModel implements DataModel<eu.eudat.entities.UserInfo>{ public class UserInfoInvitationModel implements DataModel<eu.eudat.entities.UserInfo,UserInfoInvitationModel>{
private UUID id; private UUID id;
private String email; private String email;
private String name; private String name;
@ -37,10 +37,11 @@ public class UserInfoInvitationModel implements DataModel<eu.eudat.entities.User
} }
@Override @Override
public void fromDataModel(eu.eudat.entities.UserInfo entity) throws InstantiationException, IllegalAccessException { public UserInfoInvitationModel fromDataModel(eu.eudat.entities.UserInfo entity) {
this.id = entity.getId(); this.id = entity.getId();
this.email = entity.getEmail(); this.email = entity.getEmail();
this.name = entity.getName(); this.name = entity.getName();
return this;
} }
@Override @Override

View File

@ -10,7 +10,7 @@ import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class UserListingModel implements DataModel<eu.eudat.entities.UserInfo> { public class UserListingModel implements DataModel<eu.eudat.entities.UserInfo,UserListingModel> {
private UUID id; private UUID id;
@ -103,7 +103,7 @@ public class UserListingModel implements DataModel<eu.eudat.entities.UserInfo> {
} }
@Override @Override
public void fromDataModel(UserInfo entity) throws InstantiationException, IllegalAccessException { public UserListingModel fromDataModel(UserInfo entity) {
this.id = entity.getId(); this.id = entity.getId();
this.email = entity.getEmail(); this.email = entity.getEmail();
this.usertype = entity.getUsertype(); this.usertype = entity.getUsertype();
@ -113,6 +113,7 @@ public class UserListingModel implements DataModel<eu.eudat.entities.UserInfo> {
this.lastloggedin = entity.getLastloggedin(); this.lastloggedin = entity.getLastloggedin();
this.additionalinfo = entity.getAdditionalinfo(); this.additionalinfo = entity.getAdditionalinfo();
this.appRoles = entity.getUserRoles().stream().map(item -> item.getRole()).collect(Collectors.toList()); this.appRoles = entity.getUserRoles().stream().map(item -> item.getRole()).collect(Collectors.toList());
return this;
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package eu.eudat.services; package eu.eudat.services;
import eu.eudat.builders.BuilderFactory;
import eu.eudat.proxy.fetching.RemoteFetcher; import eu.eudat.proxy.fetching.RemoteFetcher;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
@ -12,4 +13,5 @@ public interface ApiContext {
RemoteFetcher getRemoteFetcher(); RemoteFetcher getRemoteFetcher();
MailService getMailService(); MailService getMailService();
MessageSource getMessageSource(); MessageSource getMessageSource();
BuilderFactory getBuilderFactory();
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.services; package eu.eudat.services;
import eu.eudat.builders.BuilderFactory;
import eu.eudat.proxy.fetching.RemoteFetcher; import eu.eudat.proxy.fetching.RemoteFetcher;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -16,6 +17,7 @@ public class ApiContextImpl implements ApiContext{
private InvitationService invitationService; private InvitationService invitationService;
private MailService mailService; private MailService mailService;
private MessageSource messageSource; private MessageSource messageSource;
private BuilderFactory builderFactory;
@Autowired @Autowired
public void setDatabaseRepository(DatabaseRepository databaseRepository) { public void setDatabaseRepository(DatabaseRepository databaseRepository) {
@ -76,4 +78,14 @@ public class ApiContextImpl implements ApiContext{
public void setMessageSource(MessageSource messageSource) { public void setMessageSource(MessageSource messageSource) {
this.messageSource = messageSource; this.messageSource = messageSource;
} }
@Override
public BuilderFactory getBuilderFactory() {
return builderFactory;
}
@Autowired
public void setBuilderFactory(BuilderFactory builderFactory) {
this.builderFactory = builderFactory;
}
} }

View File

@ -1,7 +1,9 @@
package eu.eudat.services; package eu.eudat.services;
import eu.eudat.dao.entities.UserInfoDao; import eu.eudat.builders.entity.CredentialBuilder;
import eu.eudat.dao.entities.security.UserTokenDao; import eu.eudat.builders.entity.UserInfoBuilder;
import eu.eudat.builders.entity.UserTokenBuilder;
import eu.eudat.builders.model.models.PrincipalBuilder;
import eu.eudat.entities.Credential; import eu.eudat.entities.Credential;
import eu.eudat.entities.UserInfo; import eu.eudat.entities.UserInfo;
import eu.eudat.entities.UserRole; import eu.eudat.entities.UserRole;
@ -17,9 +19,7 @@ import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.xml.ws.ServiceMode;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Service("authenticationService ") @Service("authenticationService ")
@ -51,11 +51,10 @@ public class AuthenticationService {
UserInfo user = this.apiContext.getDatabaseRepository().getUserInfoDao().find(token.getUser().getId()); UserInfo user = this.apiContext.getDatabaseRepository().getUserInfoDao().find(token.getUser().getId());
if (user == null) return null; if (user == null) return null;
Principal principal = new Principal(); Principal principal = this.apiContext.getBuilderFactory().getBuilder(PrincipalBuilder.class)
principal.setId(user.getId()); .id(user.getId()).token(token.getToken())
principal.setToken(token.getToken()); .expiresAt(token.getExpiresAt()).name(user.getName())
principal.setExpiresAt(token.getExpiresAt()); .build();
principal.setName(user.getName());
List<UserRole> userRoles = apiContext.getDatabaseRepository().getUserRoleDao().getUserRoles(user); List<UserRole> userRoles = apiContext.getDatabaseRepository().getUserRoleDao().getUserRoles(user);
for (UserRole item : userRoles) { for (UserRole item : userRoles) {
@ -68,16 +67,21 @@ public class AuthenticationService {
public Principal Touch(Credentials credentials) { public Principal Touch(Credentials credentials) {
Credential credential = this.apiContext.getDatabaseRepository().getCredentialDao().getLoggedInCredentials(credentials); Credential credential = this.apiContext.getDatabaseRepository().getCredentialDao().getLoggedInCredentials(credentials);
if (credential == null && credentials.getUsername().equals(environment.getProperty("autouser.root.username"))) if (credential == null && credentials.getUsername().equals(environment.getProperty("autouser.root.username"))) {
try {
credential = this.autoCreateUser(credentials.getUsername(), credentials.getSecret()); credential = this.autoCreateUser(credentials.getUsername(), credentials.getSecret());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
if (credential == null) return null; if (credential == null) return null;
UserToken userToken = new UserToken(); UserToken userToken = this.apiContext.getBuilderFactory().getBuilder(UserTokenBuilder.class)
userToken.setUser(credential.getUserInfo()); .issuedAt(new Date()).user(credential.getUserInfo())
userToken.setIssuedAt(new Date()); .token(UUID.randomUUID()).expiresAt(addADay(new Date()))
userToken.setToken(UUID.randomUUID()); .build();
userToken.setExpiresAt(addADay(new Date()));
userToken = apiContext.getDatabaseRepository().getUserTokenDao().createOrUpdate(userToken); userToken = apiContext.getDatabaseRepository().getUserTokenDao().createOrUpdate(userToken);
return this.Touch(userToken); return this.Touch(userToken);
@ -89,22 +93,19 @@ public class AuthenticationService {
criteria.setEmail(profile.getEmail()); criteria.setEmail(profile.getEmail());
UserInfo userInfo = apiContext.getDatabaseRepository().getUserInfoDao().asQueryable().withHint("userInfo").where((builder, root) -> builder.equal(root.get("email"), profile.getEmail())).getSingleOrDefault(); UserInfo userInfo = apiContext.getDatabaseRepository().getUserInfoDao().asQueryable().withHint("userInfo").where((builder, root) -> builder.equal(root.get("email"), profile.getEmail())).getSingleOrDefault();
final Credential credential = new Credential(); final Credential credential = this.apiContext.getBuilderFactory().getBuilder(CredentialBuilder.class)
credential.setId(UUID.randomUUID()); .id(UUID.randomUUID()).creationTime(new Date()).status(1)
credential.setCreationTime(new Date()); .lastUpdateTime(new Date()).provider((int) profile.getProvider().getValue())
credential.setStatus(1); .secret(profile.getSecret())
credential.setLastUpdateTime(new Date()); .build();
credential.setProvider((int) profile.getProvider().getValue());
credential.setSecret(profile.getSecret());
if (userInfo == null) { if (userInfo == null) {
userInfo = new UserInfo(); userInfo = this.apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class)
userInfo.setName(profile.getName()); .name(profile.getName()).verified_email(profile.getIsVerified())
userInfo.setVerified_email(profile.getIsVerified()); .email(profile.getEmail()).created(new Date()).lastloggedin(new Date())
userInfo.setEmail(profile.getEmail()); .authorization_level((short) 1).usertype((short) 1)
userInfo.setCreated(new Date()); .build();
userInfo.setLastloggedin(new Date());
userInfo.setAuthorization_level(new Short("1"));
userInfo.setUsertype(new Short("1"));
userInfo = apiContext.getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo); userInfo = apiContext.getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
credential.setPublicValue(userInfo.getName()); credential.setPublicValue(userInfo.getName());
credential.setUserInfo(userInfo); credential.setUserInfo(userInfo);
@ -131,11 +132,11 @@ public class AuthenticationService {
userInfo = apiContext.getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo); userInfo = apiContext.getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
} }
UserToken userToken = new UserToken(); UserToken userToken = this.apiContext.getBuilderFactory().getBuilder(UserTokenBuilder.class)
userToken.setUser(userInfo); .token(UUID.randomUUID()).user(userInfo)
userToken.setIssuedAt(new Date()); .expiresAt(addADay(new Date())).issuedAt(new Date())
userToken.setToken(UUID.randomUUID()); .build();
userToken.setExpiresAt(addADay(new Date()));
apiContext.getDatabaseRepository().getUserTokenDao().createOrUpdate(userToken); apiContext.getDatabaseRepository().getUserTokenDao().createOrUpdate(userToken);
return Touch(userToken.getToken()); return Touch(userToken.getToken());
} }
@ -155,13 +156,11 @@ public class AuthenticationService {
if (!environment.getProperty("autouser.root.username").equals(username) || !environment.getProperty("autouser.root.password").equals(password)) if (!environment.getProperty("autouser.root.username").equals(username) || !environment.getProperty("autouser.root.password").equals(password))
return null; return null;
UserInfo userInfo = new UserInfo(); UserInfo userInfo = this.apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class)
userInfo.setName(username); .name(username).email(environment.getProperty("autouser.root.email")).created(new Date())
userInfo.setEmail(environment.getProperty("autouser.root.email")); .lastloggedin(new Date()).authorization_level((short) 1).usertype((short) 1)
userInfo.setCreated(new Date()); .build();
userInfo.setLastloggedin(new Date());
userInfo.setAuthorization_level((short) 1);
userInfo.setUsertype((short) 1);
userInfo = this.apiContext.getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo); userInfo = this.apiContext.getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
UserRole role = new UserRole(); UserRole role = new UserRole();
@ -169,14 +168,12 @@ public class AuthenticationService {
role.setUserInfo(userInfo); role.setUserInfo(userInfo);
this.apiContext.getDatabaseRepository().getUserRoleDao().createOrUpdate(role); this.apiContext.getDatabaseRepository().getUserRoleDao().createOrUpdate(role);
Credential credential = new Credential(); Credential credential = this.apiContext.getBuilderFactory().getBuilder(CredentialBuilder.class)
credential.setUserInfo(userInfo); .userInfo(userInfo).publicValue(username).secret(password)
credential.setPublicValue(username); .provider((int) TokenValidatorFactoryImpl.LoginProvider.NATIVELOGIN.getValue())
credential.setSecret(password); .creationTime(new Date()).lastUpdateTime(new Date()).status(0)
credential.setProvider((int) TokenValidatorFactoryImpl.LoginProvider.NATIVELOGIN.getValue()); .build();
credential.setCreationTime(new Date());
credential.setLastUpdateTime(new Date());
credential.setStatus(0);
return this.apiContext.getDatabaseRepository().getCredentialDao().createOrUpdate(credential); return this.apiContext.getDatabaseRepository().getCredentialDao().createOrUpdate(credential);
} }
} }

View File

@ -1,37 +0,0 @@
package eu.eudat.utilities.builders;
import eu.eudat.entities.DataEntity;
import eu.eudat.models.DataModel;
import java.text.ParseException;
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) throws Exception {
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) {
List<U> models = new LinkedList<>();
for(T entity:entities){
U model = null;
try {
model = clazz.newInstance();
model.fromDataModel(entity);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
models.add(model);
}
return models;
}
}

View File

@ -45,7 +45,7 @@ twitter.login.clientId=HiR4hQH9HNubKC5iKQy0l4mAZ
twitter.login.clientSecret=9KZHgkqUO2QFnELSL14jeUvfUacWX23rqD8OW8X0xoRDXOSfKH twitter.login.clientSecret=9KZHgkqUO2QFnELSL14jeUvfUacWX23rqD8OW8X0xoRDXOSfKH
twitter.login.redirect_uri=http://dl043.madgik.di.uoa.gr:8080/login/twitter twitter.login.redirect_uri=http://dl043.madgik.di.uoa.gr:8080/login/twitter
########################Persistence/Hibernate/Batch############################## ########################Persistence/Hibernate/Batch##############################
spring.profiles.active=production spring.profiles.active=devel
########################Persistence/Hibernate/Connection pool#################### ########################Persistence/Hibernate/Connection pool####################
autouser.root.email = root@dmp.com autouser.root.email = root@dmp.com
autouser.root.password = root autouser.root.password = root

View File

@ -1,4 +1,21 @@
<app-navigation></app-navigation> <app-navigation></app-navigation>
<div class="container">
<div class="container-fluid">
<div class="row">
<help-content position="top"></help-content>
</div>
<div class="row">
<div class="col-md-2">
<help-content position="left"></help-content>
</div>
<div class="col-md-8">
<router-outlet></router-outlet> <router-outlet></router-outlet>
</div> </div>
<div class="col-md-2">
<help-content position="right"></help-content>
</div>
</div>
<div class="row">
<help-content position="bottom"></help-content>
</div>
</div>

View File

@ -1,4 +1,4 @@
import { environment } from '../environments/environment.prod'; import { environment } from '../environments/environment';
export const HostConfiguration = { export const HostConfiguration = {
Server: environment.Server, Server: environment.Server,
App: environment.App App: environment.App

View File

@ -31,13 +31,16 @@ import { AppComponent } from './app.component';
import { NgModule } from "@angular/core"; import { NgModule } from "@angular/core";
import { DatasetProfileModule } from './dataset-profile-form/dataset-profile.module'; import { DatasetProfileModule } from './dataset-profile-form/dataset-profile.module';
import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component'; import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component';
import { HelpContentService } from './services/help-content/help-content.service';
import { HelpContentComponent } from './help-content/help-content.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
PageNotFoundComponent, PageNotFoundComponent,
HomepageComponent, HomepageComponent,
WelcomepageComponent WelcomepageComponent,
HelpContentComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -81,7 +84,8 @@ import { WelcomepageComponent } from '@app/welcomepage/welcomepage.component';
providers: [ providers: [
AuthService, AuthService,
DashboardService, DashboardService,
BaseHttpService BaseHttpService,
HelpContentService
], ],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })

View File

@ -0,0 +1,56 @@
/**
* Created by stefania on 7/17/17.
*/
import { Component, OnInit, Input } from '@angular/core';
import { ActivatedRoute, Router, NavigationStart } from "@angular/router";
import { PageHelpContent } from '../models/help-content/page-help-content';
import { HelpContentService } from '../services/help-content/help-content.service';
@Component({
selector: 'help-content',
template: `
<ng-template [ngIf]="contents && contents.length>0">
<ng-template ngFor let-content [ngForOf]="contents">
<div [innerHTML]="content.content" class="uk-margin-medium-bottom"></div>
</ng-template>
</ng-template>
`,
})
export class HelpContentComponent implements OnInit {
@Input('position')
position: string;
contents: any[];
errorMessage: string = null;
constructor(private _helpContentService: HelpContentService, private route: ActivatedRoute, private router: Router) {
}
ngOnInit() {
this.errorMessage = null;
this.router.events.subscribe(event => {
if (event instanceof NavigationStart) {
this._helpContentService.getActivePageContent(event["url"]).subscribe(
pageContent => this.shiftThroughContent(pageContent),
error => this.handleError(<any>error))
}
})
}
shiftThroughContent(pageContent: PageHelpContent) {
this.contents = pageContent.content[this.position];
}
isPresent() {
return (this.contents && this.contents.length > 0);
}
handleError(error) {
this.errorMessage = 'System error retrieving page content (Server responded: ' + error + ')';
}
}
@Component({
selector: 'aside-help-content',
template: `
<ng-template [ngIf]="contents && contents.length>0">
<ng-template ngFor let-content [ngForOf]="contents">
<div [innerHTML]="content.content" class="uk-card uk-card-body uk-card-default sidemenu uk-margin-bottom"></div>
</ng-template>
</ng-template>
`,
})
export class AsideHelpContentComponent extends HelpContentComponent {
}

View File

@ -0,0 +1,10 @@
/**
* Created by stefania on 4/26/17.
*/
import { Topic } from "./topic";
import { Question } from "./question";
export interface ActiveTopicQuestions {
topic: Topic;
questionList: Question[];
}

View File

@ -0,0 +1,24 @@
/**
* Created by stefania on 7/13/17.
*/
import { Page } from "./page";
export interface PageHelpContent {
_id: string;
page: Page | string;
placement : string;
order: number;
content: string;
isActive: boolean;
}
export interface CheckPageHelpContent {
pageHelpContent : PageHelpContent;
checked : boolean;
}
export interface PageHelpContentFilterOptions {
id : string;
active : Boolean;
text : RegExp;
}

View File

@ -0,0 +1,13 @@
/**
* Created by stefania on 7/13/17.
*/
export interface Page {
_id: string;
route: string;
name: string;
}
export interface CheckPage {
page : Page;
checked : boolean;
}

View File

@ -0,0 +1,26 @@
/**
* Created by stefania on 4/26/17.
*/
import { Topic } from "./topic";
export interface Question {
_id: string;
question: string;
answer: string;
date : Date;
isActive: boolean;
weight: number;
hitCount: number;
topics: Topic[] | string[];
}
export interface CheckQuestion {
question : Question;
checked : boolean;
}
export interface QuestionFilterOptions {
id : string;
active : Boolean;
text : RegExp;
}

View File

@ -0,0 +1,16 @@
/**
* Created by stefania on 4/26/17.
*/
export interface Topic {
_id: string;
name: string;
description: string;
date : Date;
weight: number;
questionOrder: string;
}
export interface CheckTopic {
topic : Topic;
checked : boolean;
}

View File

@ -0,0 +1,43 @@
/**
* Created by stefania on 7/17/17.
*/
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { PageHelpContent } from '../../models/help-content/page-help-content';
@Injectable()
export class HelpContentService {
private _helpServiceUrl = "http://localhost:5000";
constructor (private http: Http) {
}
cache : any = {};
getActivePageContent(route: string) {
if (!this.cache[route]) {
this.cache[route] = this.http.get(this._helpServiceUrl + "/page/route?q=" + route)
.map(res => <PageHelpContent> res.json())
.catch(this.handleError)
.share();
}
return this.cache[route];
}
private extractData(res: Response) {
let body = res.json();
return body.data || { };
}
private handleError (error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
// We'd also dig deeper into the error to get a better message
let errMsg = "";
console.log(error);
if (error instanceof Response) {
const body = error.text() || '';
//const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${body}`;
} else {
errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
}
return Observable.throw(errMsg);
}
}

View File

@ -4,8 +4,9 @@
{{item.label}} {{item.label}}
<mat-icon matChipRemove>cancel</mat-icon> <mat-icon matChipRemove>cancel</mat-icon>
</mat-chip> </mat-chip>
<input matInput [matAutocomplete]="auto" [matChipInputFor]="chipList" [formControl]="control" placeholder="{{placeholder}}" [required]="required">
</mat-chip-list> </mat-chip-list>
<input matInput [matAutocomplete]="auto" [matChipInputFor]="chipList" [formControl]="term" placeholder="{{placeholder}}" [required]="required">
<mat-error *ngIf="control.errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> <mat-error *ngIf="control.errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="validationErrorString">{{errorString}}</mat-error> <mat-error *ngIf="validationErrorString">{{errorString}}</mat-error>
<mat-progress-spinner matSuffix mode="indeterminate" *ngIf="loading" [diameter]="22"></mat-progress-spinner> <mat-progress-spinner matSuffix mode="indeterminate" *ngIf="loading" [diameter]="22"></mat-progress-spinner>

View File

@ -37,6 +37,8 @@ export class AutocompleteChipComponent implements OnInit {
@Input() @Input()
disabled: boolean = false; disabled: boolean = false;
@Input()
multiChips: boolean = false;
// @Input() selectedDropdownItem: AutoCompleteItem; // @Input() selectedDropdownItem: AutoCompleteItem;
// @Output() selectedDropdownItemChange = new EventEmitter<AutoCompleteItem>(); // @Output() selectedDropdownItemChange = new EventEmitter<AutoCompleteItem>();
@ -45,8 +47,9 @@ export class AutocompleteChipComponent implements OnInit {
@Input() control: FormControl; @Input() control: FormControl;
// @Input() createNew = false; // @Input() createNew = false;
// //term = new FormControl(); term = new FormControl();
// @Input() // @Input()
// ClickFunctionCall: Function; // ClickFunctionCall: Function;
@ -61,11 +64,9 @@ export class AutocompleteChipComponent implements OnInit {
ngOnInit() { ngOnInit() {
const valueChanges = this.control.valueChanges.share(); const valueChanges = this.term.valueChanges.share();
valueChanges.subscribe(searchTerm => { valueChanges.subscribe(searchTerm => {
if (this.hasSelectedItem) { //proswrina epeidh ta projects den eixan ids...gia test!!! if (!this.hasSelectedItem) { //proswrina epeidh ta projects den eixan ids...gia test!!!
this.resetFormControlValue();
} else {
this.loading = true; this.loading = true;
} }
}); });
@ -75,8 +76,9 @@ export class AutocompleteChipComponent implements OnInit {
.switchMap(val => { .switchMap(val => {
if (this.hasSelectedItem) { if (this.hasSelectedItem) {
this.loading = false; this.loading = false;
this.resetFormControlValue();
return []; return [];
} else if (typeof(val)== "string") { } else {
this.configuration.requestItem.criteria.like = val; this.configuration.requestItem.criteria.like = val;
return this.configuration.callback(this.configuration.requestItem).map(result => { return this.configuration.callback(this.configuration.requestItem).map(result => {
this.filteredItems = (<any[]>result) this.filteredItems = (<any[]>result)
@ -89,7 +91,7 @@ export class AutocompleteChipComponent implements OnInit {
resetFormControlValue() { resetFormControlValue() {
this.hasSelectedItem = false; this.hasSelectedItem = false;
//this.control.setValue(null, { emitEvent: false }); this.term.setValue(null);
} }
// // listingItemToDropDown(item: DropdownListingItem): AutoCompleteItem { // // listingItemToDropDown(item: DropdownListingItem): AutoCompleteItem {
@ -99,7 +101,10 @@ export class AutocompleteChipComponent implements OnInit {
optionSelected(event: any) { optionSelected(event: any) {
this.hasSelectedItem = true; this.hasSelectedItem = true;
this.selectedItems.push(event.option.value) this.selectedItems.push(event.option.value)
this.control.setValue(this.selectedItems, { emitEvent: false }); let value = this.control.value;
if (this.multiChips) value.push(event.option.value)
else value = event.option.value
this.control.setValue(value, { emitEvent: false });
this.filteredItems = this.selectedItems; this.filteredItems = this.selectedItems;
//this.selectedDropdownItemChange.emit(event.option.value); //this.selectedDropdownItemChange.emit(event.option.value);