Compare commits

..

2 Commits

11
.env

@ -1,5 +1,6 @@
PROFILE=docker
# Version of Elastic products
ELK_VERSION=7.17.4
STACK_VERSION=7.17.4
TAG=6.3.0
ENV=prod
PROFILE=production
AOT=aot
ELASTIC_VERSION=6.3.0
ELASTIC_PASSWORD=changeme

9
.gitignore vendored

@ -40,12 +40,3 @@ dmp-frontend/.vscode/
dmp-frontend/package-lock.json
dmp-backend/logging/target/
ELK.Docker/shared/data-elk/
# Eclipse
.project
.settings/
bin/
*.classpath
openDMP/dmp-backend/uploads/
openDMP/dmp-backend/tmp/
dmp-frontend/.angular/

66
Jenkinsfile vendored

@ -1,66 +0,0 @@
def pipelineContext = [:]
pipeline {
agent any
options {
skipDefaultCheckout(true)
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build API') {
steps {
script {
pipelineContext.apiImage = docker.build("open-dmp-api:${env.BUILD_ID}", "-f dmp-backend/Dockerfile.CI dmp-backend/")
}
}
}
stage('Build WebApp') {
steps {
script {
pipelineContext.webappImage = docker.build("open-dmp-webapp:${env.BUILD_ID}", "-f dmp-frontend/Dockerfile.CI dmp-frontend/")
}
}
}
//stage('SonarQube analysis') {
// steps {
// script {
// def scannerHome = tool 'SonarQube Scanner 4.3';
// withSonarQubeEnv('SonarQube') { // If you have configured more than one global server connection, you can specify its name
// sh "${scannerHome}/bin/sonar-scanner"
// }
// }
// }
//}
//// waiting for sonar results based into the configured web hook in Sonar server which push the status back to jenkins
//stage('SonarQube scan result check') {
// steps {
// timeout(time: 2, unit: 'MINUTES') {
// retry(3) {
// script {
// def qg = waitForQualityGate()
// if (qg.status != 'OK') {
// error "Pipeline aborted due to quality gate failure: ${qg.status}"
// }
// }
// }
// }
// }
//}
stage('Pushing to Docker Registry') {
steps {
script {
docker.withRegistry('http://drepo.local.cite.gr', 'b2c651c1-9a3b-4a98-a6da-e1dd7a20f512') {
pipelineContext.apiImage.push()
pipelineContext.webappImage.push()
}
}
}
}
}
}

@ -1,69 +0,0 @@
**Important note: The deployment, troubleshooting, maintenance and operation of on-premises / self-served OpenDMP instances for development, testing or production use, shall be the sole responsibility of the adopter. No support is guaranteed by OpenDMP implentation team for issues that may be encountered during deployment, extension or operation of such installations.**
**Documentation is provided on a best-effort basis for the code and processes around the development, deployment and operation of OpenDMP. If you find any misalignment of the actual processes with the related documentation, please let us know so that the misalignment is addressed for the benefit of future adopters.**
# Using Docker Compose with Argos
ARGOS is an open extensible service that simplifies the management, validation, monitoring and maintenance and of Data Management Plans. It allows actors (researchers, managers, supervisors etc) to create actionable DMPs that may be freely exchanged among infrastructures for carrying out specific aspects of the Data management process in accordance with the intentions and commitment of Data owners.
## Before running the docker compose commands, configurations must be set
### Database
First of all, database must be configured
The only file that has to be changed is **/dmp-db-scema/Docker/dmp-db.env**
```bash
ADMIN_USER: Admin username (app)
ADMIN_PASSWORD: Admin password (app)
POSTGRES_DB: database name
POSTGRES_USER: Admin username (database)
POSTGRES_PASSWORD: Admin password (database)
```
### Backend
Secondly, a few more options should be asigned
The file **/dmp-backend/web/src/main/resources/config/application-docker.properties** contains all the necessary properties
Values to be modified:
```bash
database.url: the url that is used to connect to database (JDBC based)
database.username: database admin username
database.password: database admin password
elasticsearch.*(optional): setup elastic, check Elasticsearch(optional) section below
google.login.clientId(optional): google as login provider
```
**NOTE:** if you want to configure and integrate other providers, check this reference [Setup configurable login](https://code-repo.d4science.org/MaDgiK-CITE/argos/wiki/Page-2A:-Setup-configurable-login)
If you provide google.login.clientId, then the same value should be set in the field named **loginProviders.googleConfiguration.clientId** which belongs to **/dmp-frontend/src/assets/config/config.json**
## You are ready to build and run the entire application using Docker-compose
1. Go to the project's root directory
2. Type in the **Terminal** `docker volume create --name=dmpdata`
3. Type in the **Terminal** `docker-compose up -d --build`
4. After it's complete your application is running on [http://localhost:8080](http://localhost:8080)
### Elasticsearch(optional)
If you want to set up elasticsearch, you will need the password for the **elastic** user
After your application is running, type in the **Terminal** `docker exec -it elasticsearch /bin/sh`
Run the command `cat data/passwords.txt` in the shell and save its output
Finally, run `exit` to get back to your terminal
The elastic's password that you get has to be set in the **elasticsearch.password** property in the backend configuration
Rerun the application
1. Type in the **Terminal** `docker-compose down`
2. Type in the **Terminal** `docker-compose up -d --build`

@ -1 +1 @@
PROFILE=docker
PROFILE=staging

@ -1,22 +1,22 @@
FROM maven:3-jdk-11 AS MAVEN_BUILD
FROM maven:3-jdk-8-alpine AS MAVEN_BUILD
COPY pom.xml /build/
COPY data /build/data/
COPY elastic /build/elastic/
#COPY logging /build/logging/
COPY logging /build/logging/
COPY queryable /build/queryable/
COPY web /build/web/
WORKDIR /build/
RUN mvn package -q
RUN mvn package
FROM amazoncorretto:11
FROM openjdk:8-jre-alpine
WORKDIR /app
COPY --from=MAVEN_BUILD /build/web/target/web-1.0-SNAPSHOT.jar /app.jar

@ -1,15 +0,0 @@
FROM maven:3-openjdk-11 AS MAVEN_BUILD
COPY pom.xml /build/
COPY data /build/data/
COPY elastic /build/elastic/
COPY queryable /build/queryable/
COPY web /build/web/
WORKDIR /build/
RUN mvn package
FROM adoptopenjdk/openjdk11:alpine-jre
WORKDIR /app
COPY --from=MAVEN_BUILD /build/web/target/web-1.0-SNAPSHOT.jar /app/app.jar
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-Dspring.profiles.active=${PROF}", "-Dspring.config.additional-location=/files/config/", "-cp", "/app/app.jar", "-Dloader.path=/files/repo-jars", "org.springframework.boot.loader.PropertiesLauncher"]

@ -25,10 +25,5 @@
<artifactId>elastic</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.20</version>
</dependency>
</dependencies>
</project>

@ -1,9 +1,9 @@
package eu.eudat.data.dao.criteria;
import io.swagger.annotations.ApiModelProperty;
import eu.eudat.queryable.queryableentity.DataEntity;
public abstract class Criteria<T> {
@ApiModelProperty(value = "like", name = "like", dataType = "String", allowEmptyValue = true, example = "\"\"")
private String like;
public String getLike() {

@ -1,16 +0,0 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DMPProfile;
public class DataManagementPlanBlueprintCriteria extends Criteria<DMPProfile> {
private Integer status;
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}

@ -1,7 +1,6 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.DMPProfile;
import eu.eudat.data.entities.Grant;
import java.util.Date;
@ -11,7 +10,6 @@ import java.util.UUID;
public class DataManagementPlanCriteria extends Criteria<DMP> {
private Date periodStart;
private Date periodEnd;
private DMPProfile profile;
private List<eu.eudat.data.entities.Grant> grants;
private boolean allVersions;
private List<UUID> groupIds;
@ -23,7 +21,6 @@ public class DataManagementPlanCriteria extends Criteria<DMP> {
private boolean isPublic;
private boolean onlyPublic;
private Short grantStatus;
private boolean hasDoi;
public Date getPeriodStart() {
return periodStart;
@ -39,13 +36,6 @@ public class DataManagementPlanCriteria extends Criteria<DMP> {
this.periodEnd = periodEnd;
}
public DMPProfile getProfile() {
return profile;
}
public void setProfile(DMPProfile profile) {
this.profile = profile;
}
public List<Grant> getGrants() {
return grants;
}
@ -124,12 +114,4 @@ public class DataManagementPlanCriteria extends Criteria<DMP> {
public void setGrantStatus(Short grantStatus) {
this.grantStatus = grantStatus;
}
public boolean hasDoi() {
return hasDoi;
}
public void setHasDoi(boolean hasDoi) {
this.hasDoi = hasDoi;
}
}

@ -25,7 +25,6 @@ public class DatasetCriteria extends Criteria<Dataset> {
private List<UUID> groupIds;
private Boolean isPublic;
private Short grantStatus;
private boolean hasDoi;
public boolean getAllVersions() {
return allVersions;
@ -133,12 +132,4 @@ public class DatasetCriteria extends Criteria<Dataset> {
public void setGrantStatus(Short grantStatus) {
this.grantStatus = grantStatus;
}
public boolean hasDoi() {
return hasDoi;
}
public void setHasDoi(boolean hasDoi) {
this.hasDoi = hasDoi;
}
}

@ -1,13 +1,11 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DescriptionTemplate;
import java.util.Date;
import eu.eudat.data.entities.DatasetProfile;
import java.util.List;
import java.util.UUID;
public class DatasetProfileCriteria extends Criteria<DescriptionTemplate> {
public class DatasetProfileCriteria extends Criteria<DatasetProfile> {
public enum DatasetProfileFilter {
DMPs((short) 0), Datasets((short) 1);
@ -25,7 +23,7 @@ public class DatasetProfileCriteria extends Criteria<DescriptionTemplate> {
case 1:
return Datasets;
default:
throw new RuntimeException("Unsupported DescriptionTemplate filter");
throw new RuntimeException("Unsupported DatasetProfile filter");
}
}
}
@ -36,9 +34,6 @@ public class DatasetProfileCriteria extends Criteria<DescriptionTemplate> {
private UUID userId;
private boolean finalized;
private Integer status;
private Integer role;
private List<UUID> ids;
private Date periodStart;
public boolean getAllVersions() { return allVersions; }
public void setAllVersions(boolean allVersions) { this.allVersions = allVersions; }
@ -74,28 +69,4 @@ public class DatasetProfileCriteria extends Criteria<DescriptionTemplate> {
public void setStatus(Integer status) {
this.status = status;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
}

@ -1,11 +1,11 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DatasetProfile;
import java.util.UUID;
public class DatasetProfileWizardCriteria extends Criteria<DescriptionTemplate> {
public class DatasetProfileWizardCriteria extends Criteria<DatasetProfile> {
private UUID id;
public UUID getId() {

@ -1,6 +0,0 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.EmailConfirmation;
public class EmailConfirmationCriteria extends Criteria<EmailConfirmation>{
}

@ -2,12 +2,8 @@ package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Funder;
import java.util.Date;
public class FunderCriteria extends Criteria<Funder> {
private String reference;
private String exactReference;
private Date periodStart;
public String getReference() {
return reference;
@ -15,20 +11,4 @@ public class FunderCriteria extends Criteria<Funder> {
public void setReference(String reference) {
this.reference = reference;
}
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
}

@ -13,8 +13,6 @@ public class GrantCriteria extends Criteria<Grant> {
private boolean isPublic;
private String funderId;
private String funderReference;
private String exactReference;
private boolean isActive;
public Date getPeriodStart() {
return periodStart;
@ -64,20 +62,4 @@ public class GrantCriteria extends Criteria<Grant> {
public void setFunderReference(String funderReference) {
this.funderReference = funderReference;
}
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) {
isActive = active;
}
}

@ -0,0 +1,6 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.LoginConfirmationEmail;
public class LoginConfirmationEmailCriteria extends Criteria<LoginConfirmationEmail>{
}

@ -5,7 +5,6 @@ import eu.eudat.data.entities.Organisation;
public class OrganisationCriteria extends Criteria<Organisation> {
private String labelLike;
private Boolean isPublic;
private boolean isActive;
public String getLabelLike() {
return labelLike;
@ -20,12 +19,4 @@ public class OrganisationCriteria extends Criteria<Organisation> {
public void setPublic(Boolean aPublic) {
isPublic = aPublic;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) {
isActive = active;
}
}

@ -2,12 +2,8 @@ package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Project;
import java.util.Date;
public class ProjectCriteria extends Criteria<Project> {
private String reference;
private String exactReference;
private Date periodStart;
public String getReference() {
return reference;
@ -15,20 +11,4 @@ public class ProjectCriteria extends Criteria<Project> {
public void setReference(String reference) {
this.reference = reference;
}
public String getExactReference() {
return exactReference;
}
public void setExactReference(String exactReference) {
this.exactReference = exactReference;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
}

@ -2,12 +2,8 @@ package eu.eudat.data.dao.criteria;
import eu.eudat.data.entities.Researcher;
import java.util.Date;
public class ResearcherCriteria extends Criteria<Researcher> {
private String name;
private String reference;
private Date periodStart;
public String getName() {
return name;
@ -16,20 +12,4 @@ public class ResearcherCriteria extends Criteria<Researcher> {
public void setName(String name) {
this.name = name;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
}

@ -7,7 +7,6 @@ import eu.eudat.queryable.queryableentity.DataEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.Set;
@ -29,7 +28,6 @@ public class DatabaseService<T extends DataEntity> {
return this.databaseCtx.getQueryable(tClass);
}
@Transactional
public T createOrUpdate(T item, Class<T> tClass) {
return this.databaseCtx.createOrUpdate(item, tClass);
}

@ -16,7 +16,6 @@ import org.springframework.stereotype.Component;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.transaction.Transactional;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@ -42,8 +41,6 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
query.where((builder, root) -> builder.lessThan(root.get("created"), criteria.getPeriodEnd()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
if (criteria.getProfile() != null)
query.where((builder, root) -> builder.equal(root.get("profile"), criteria.getProfile()));
if (criteria.getGrants() != null && !criteria.getGrants().isEmpty())
query.where(((builder, root) -> root.get("grant").in(criteria.getGrants())));
if (!criteria.getAllVersions())
@ -55,14 +52,13 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds()));
if (criteria.getStatus() != null) {
if (criteria.getStatus() == DMP.DMPStatus.FINALISED.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.FINALISED.getValue()));
query.where((builder, root) -> builder.and(builder.equal(root.get("status"), DMP.DMPStatus.FINALISED.getValue()), builder.notEqual(root.get("isPublic"), true)));
} else if (criteria.getStatus() == DMP.DMPStatus.ACTIVE.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.ACTIVE.getValue()));
}
}
if (criteria.getIsPublic()) {
query.where(((builder, root) -> builder.equal(root.get("isPublic"), criteria.getIsPublic())));
}
if (criteria.getIsPublic())
query.where(((builder, root) -> builder.equal(root.get("isPublic"), true)));
/*if (criteria.getRole() != null) {
if (criteria.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())) {
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.OWNER.getValue()));
@ -77,7 +73,7 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
query.where((builder, root) -> root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
}
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty()) {
query.where((builder, root) -> root.join("associatedDmps", JoinType.LEFT).get("datasetprofile").get("id").in(criteria.getDatasetTemplates()));
query.where((builder, root) -> root.join("associatedDmps", JoinType.LEFT).get("id").in(criteria.getDatasetTemplates()));
}
if (criteria.getGrantStatus() != null) {
if (criteria.getGrantStatus().equals(GrantStateType.FINISHED.getValue().shortValue()))
@ -87,10 +83,6 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
builder.or(builder.greaterThan(root.get("grant").get("enddate"), new Date())
, builder.isNull(root.get("grant").get("enddate"))));
}
if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.join("dois").get("id"))));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
return query;
}
@ -109,7 +101,6 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
}
@Override
@Transactional
public DMP createOrUpdate(DMP item) {
return this.getDatabaseService().createOrUpdate(item, DMP.class);
}

@ -1,7 +1,6 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DataManagementPlanBlueprintCriteria;
import eu.eudat.data.dao.criteria.DataManagementPlanProfileCriteria;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.DMPProfile;
@ -16,6 +15,4 @@ public interface DMPProfileDao extends DatabaseAccessLayer<DMPProfile, UUID> {
QueryableList<DMPProfile> getWithCriteria(DataManagementPlanProfileCriteria criteria);
QueryableList<DMPProfile> getWithCriteriaBlueprint(DataManagementPlanBlueprintCriteria criteria);
}

@ -1,7 +1,6 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DataManagementPlanBlueprintCriteria;
import eu.eudat.data.dao.criteria.DataManagementPlanProfileCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DMPProfile;
@ -66,20 +65,4 @@ public class DMPProfileDaoImpl extends DatabaseAccess<DMPProfile> implements DMP
query.where(((builder, root) -> builder.notEqual(root.get("status"), DMPProfile.Status.DELETED.getValue())));
return query;
}
@Override
public QueryableList<DMPProfile> getWithCriteriaBlueprint(DataManagementPlanBlueprintCriteria criteria){
QueryableList<DMPProfile> query = getDatabaseService().getQueryable(DMPProfile.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"));
if (criteria.getStatus() != null) {
if (criteria.getStatus() == DMPProfile.Status.FINALIZED.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMPProfile.Status.FINALIZED.getValue()));
} else if (criteria.getStatus() == DMPProfile.Status.SAVED.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMPProfile.Status.SAVED.getValue()));
}
}
query.where(((builder, root) -> builder.notEqual(root.get("status"), DMPProfile.Status.DELETED.getValue())));
return query;
}
}

@ -13,8 +13,6 @@ public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> {
QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria);
QueryableList<Dataset> filterFromElastic(DatasetCriteria criteria, List<UUID> ids);
QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal, List<Integer> roles);
Dataset isPublicDataset(UUID id);

@ -35,9 +35,9 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
if (criteria.getIsPublic() != null && criteria.getIsPublic()) {
query.where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true));
query.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue()));
/*query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"),
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"),
query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")),
Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));*/
Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
}
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.or(
@ -78,25 +78,11 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
query.where((builder, root) -> root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id").in(criteria.getCollaborators()));
if (criteria.getDatasetTemplates() != null && !criteria.getDatasetTemplates().isEmpty())
query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates()));
if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.join("dmp").join("dois").get("id"))));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue()));
return query;
}
public QueryableList<Dataset> filterFromElastic(DatasetCriteria criteria, List<UUID> ids) {
QueryableList<Dataset> query = getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class);
query.where(((builder, root) -> root.get("id").in(ids)));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
return query;
}
@Override
public Dataset createOrUpdate(Dataset item) {
return getDatabaseService().createOrUpdate(item, Dataset.class);
@ -131,7 +117,6 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
});
} else {
query.where((builder, root) -> builder.equal(root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()));
}
return query;
}

@ -3,6 +3,7 @@ package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DatasetExternalDataset;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;

@ -2,23 +2,15 @@ package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DescriptionTemplateType;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.queryable.QueryableList;
import java.util.List;
import java.util.UUID;
public interface DatasetProfileDao extends DatabaseAccessLayer<DescriptionTemplate, UUID> {
public interface DatasetProfileDao extends DatabaseAccessLayer<DatasetProfile, UUID> {
QueryableList<DescriptionTemplate> getWithCriteria(DatasetProfileCriteria criteria);
QueryableList<DatasetProfile> getWithCriteria(DatasetProfileCriteria criteria);
QueryableList<DescriptionTemplate> getAll();
QueryableList<DescriptionTemplate> getAuthenticated(QueryableList<DescriptionTemplate> query, UUID principal, List<Integer> roles);
List<DescriptionTemplate> getAllIds();
Long countWithType(DescriptionTemplateType type);
QueryableList<DatasetProfile> getAll();
}

@ -3,8 +3,7 @@ package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DescriptionTemplateType;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
@ -12,25 +11,22 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("datasetProfileDao")
public class DatasetProfileDaoImpl extends DatabaseAccess<DescriptionTemplate> implements DatasetProfileDao {
public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implements DatasetProfileDao {
@Autowired
public DatasetProfileDaoImpl(DatabaseService<DescriptionTemplate> databaseService) {
public DatasetProfileDaoImpl(DatabaseService<DatasetProfile> databaseService) {
super(databaseService);
}
@Override
public QueryableList<DescriptionTemplate> getWithCriteria(DatasetProfileCriteria criteria) {
QueryableList<DescriptionTemplate> query = getDatabaseService().getQueryable(DescriptionTemplate.class);
public QueryableList<DatasetProfile> getWithCriteria(DatasetProfileCriteria criteria) {
QueryableList<DatasetProfile> query = getDatabaseService().getQueryable(DatasetProfile.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"));
if (!criteria.getAllVersions())
@ -59,76 +55,47 @@ public class DatasetProfileDaoImpl extends DatabaseAccess<DescriptionTemplate> i
if (criteria.getStatus() != null) {
query.where(((builder, root) -> builder.equal(root.get("status"), criteria.getStatus())));
}
if (criteria.getIds() != null) {
query.where(((builder, root) -> root.get("id").in(criteria.getIds())));
}
if (criteria.getFinalized()) {
query.where(((builder, root) -> builder.equal(root.get("status"), DescriptionTemplate.Status.FINALIZED.getValue())));
query.where(((builder, root) -> builder.equal(root.get("status"), DatasetProfile.Status.FINALIZED.getValue())));
} else {
query.where(((builder, root) -> builder.notEqual(root.get("status"), DescriptionTemplate.Status.DELETED.getValue())));
query.where(((builder, root) -> builder.notEqual(root.get("status"), DatasetProfile.Status.DELETED.getValue())));
}
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThanOrEqualTo(root.get("created"), criteria.getPeriodStart()));
return query;
}
@Override
public DescriptionTemplate createOrUpdate(DescriptionTemplate item) {
return this.getDatabaseService().createOrUpdate(item, DescriptionTemplate.class);
}
@Override
public DescriptionTemplate find(UUID id) {
return getDatabaseService().getQueryable(DescriptionTemplate.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
public DatasetProfile createOrUpdate(DatasetProfile item) {
return this.getDatabaseService().createOrUpdate(item, DatasetProfile.class);
}
@Override
public QueryableList<DescriptionTemplate> getAll() {
return getDatabaseService().getQueryable(DescriptionTemplate.class);
public DatasetProfile find(UUID id) {
return getDatabaseService().getQueryable(DatasetProfile.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public List<DescriptionTemplate> getAllIds(){
return getDatabaseService().getQueryable(DescriptionTemplate.class).withFields(Collections.singletonList("id")).toList();
public QueryableList<DatasetProfile> getAll() {
return getDatabaseService().getQueryable(DatasetProfile.class);
}
@Override
public void delete(DescriptionTemplate item) {
public void delete(DatasetProfile item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DescriptionTemplate> asQueryable() {
return this.getDatabaseService().getQueryable(DescriptionTemplate.class);
public QueryableList<DatasetProfile> asQueryable() {
return this.getDatabaseService().getQueryable(DatasetProfile.class);
}
@Async
@Override
public CompletableFuture<DescriptionTemplate> createOrUpdateAsync(DescriptionTemplate item) {
public CompletableFuture<DatasetProfile> createOrUpdateAsync(DatasetProfile item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DescriptionTemplate find(UUID id, String hint) {
public DatasetProfile find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<DescriptionTemplate> getAuthenticated(QueryableList<DescriptionTemplate> query, UUID principal, List<Integer> roles) {
if (roles != null && !roles.isEmpty()) {
query.where((builder, root) -> {
Join userJoin = root.join("users", JoinType.LEFT);
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal), userJoin.get("role").in(roles));
});
} else {
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal));
}
return query;
}
@Override
public Long countWithType(DescriptionTemplateType type) {
return this.getDatabaseService().getQueryable(DescriptionTemplate.class).where((builder, root) -> builder.equal(root.get("type"), type)).count();
}
}

@ -1,6 +1,7 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.data.entities.DatasetService;
import java.util.UUID;

@ -2,6 +2,8 @@ package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DatasetExternalDataset;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.data.entities.DatasetService;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;

@ -1,10 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DescriptionTemplateType;
import java.util.UUID;
public interface DescriptionTemplateTypeDao extends DatabaseAccessLayer<DescriptionTemplateType, UUID> {
DescriptionTemplateType findFromName(String name);
}

@ -1,65 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DescriptionTemplateType;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("descriptionTemplateTypeDao")
public class DescriptionTemplateTypeDaoImpl extends DatabaseAccess<DescriptionTemplateType> implements DescriptionTemplateTypeDao {
@Autowired
public DescriptionTemplateTypeDaoImpl(DatabaseService<DescriptionTemplateType> databaseService) {
super(databaseService);
}
@Override
public DescriptionTemplateType findFromName(String name){
try {
return this.getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.and(builder.equal(root.get("name"), name), builder.notEqual(root.get("status"), DescriptionTemplateType.Status.DELETED.getValue()))).getSingle();
}
catch(Exception e){
return null;
}
}
@Override
@Transactional
public DescriptionTemplateType createOrUpdate(DescriptionTemplateType item) {
return this.getDatabaseService().createOrUpdate(item, DescriptionTemplateType.class);
}
@Override
public DescriptionTemplateType find(UUID id) {
return getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
}
@Override
public void delete(DescriptionTemplateType item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DescriptionTemplateType> asQueryable() {
return this.getDatabaseService().getQueryable(DescriptionTemplateType.class).where((builder, root) -> builder.notEqual((root.get("status")), DescriptionTemplateType.Status.DELETED.getValue()));
}
@Async
@Override
public CompletableFuture<DescriptionTemplateType> createOrUpdateAsync(DescriptionTemplateType item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DescriptionTemplateType find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

@ -1,9 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DMPDatasetProfile;
import java.util.UUID;
public interface DmpDatasetProfileDao extends DatabaseAccessLayer<DMPDatasetProfile, UUID> {
}

@ -1,52 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.Content;
import eu.eudat.data.entities.DMPDatasetProfile;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("dmpDatasetProfileDao")
public class DmpDatasetProfileDaoImpl extends DatabaseAccess<DMPDatasetProfile> implements DmpDatasetProfileDao {
@Autowired
public DmpDatasetProfileDaoImpl(DatabaseService<DMPDatasetProfile> databaseService) {
super(databaseService);
}
@Override
public DMPDatasetProfile createOrUpdate(DMPDatasetProfile item) {
return this.getDatabaseService().createOrUpdate(item, DMPDatasetProfile.class);
}
@Override
@Async
public CompletableFuture<DMPDatasetProfile> createOrUpdateAsync(DMPDatasetProfile item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DMPDatasetProfile find(UUID id) {
return this.getDatabaseService().getQueryable(DMPDatasetProfile.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public DMPDatasetProfile find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DMPDatasetProfile item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DMPDatasetProfile> asQueryable() {
return this.getDatabaseService().getQueryable(DMPDatasetProfile.class);
}
}

@ -0,0 +1,11 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DoiFunder;
import java.util.UUID;
public interface DoiFunderDao extends DatabaseAccessLayer<DoiFunder, UUID> {
DoiFunder findFunderByName(String name);
}

@ -0,0 +1,55 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.DoiFunder;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("DoiFunderDao")
public class DoiFunderDaoImpl extends DatabaseAccess<DoiFunder> implements DoiFunderDao {
@Autowired
public DoiFunderDaoImpl(DatabaseService<DoiFunder> databaseService) {
super(databaseService);
}
@Override
public DoiFunder findFunderByName(String name) {
return this.asQueryable().toList().stream().filter(doiFunder -> name.contains(doiFunder.getName()) || doiFunder.getName().contains(name)).findFirst().orElse(null);
}
@Override
public DoiFunder createOrUpdate(DoiFunder item) {
return this.getDatabaseService().createOrUpdate(item, DoiFunder.class);
}
@Override
public CompletableFuture<DoiFunder> createOrUpdateAsync(DoiFunder item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DoiFunder find(UUID id) {
return this.getDatabaseService().getQueryable(DoiFunder.class).where(((builder, root) -> builder.equal(root.get("id"), id))).getSingle();
}
@Override
public DoiFunder find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DoiFunder item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DoiFunder> asQueryable() {
return this.getDatabaseService().getQueryable(DoiFunder.class);
}
}

@ -1,13 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface EmailConfirmationDao extends DatabaseAccessLayer<EmailConfirmation, UUID> {
QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria);
}

@ -1,56 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("LoginConfirmationEmailDao")
public class EmailConfirmationDaoImpl extends DatabaseAccess<EmailConfirmation> implements EmailConfirmationDao {
@Autowired
public EmailConfirmationDaoImpl(DatabaseService<EmailConfirmation> databaseService) {
super(databaseService);
}
@Override
public QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria) {
return null;
}
@Override
public EmailConfirmation createOrUpdate(EmailConfirmation item) {
return this.getDatabaseService().createOrUpdate(item, EmailConfirmation.class);
}
@Override
public CompletableFuture<EmailConfirmation> createOrUpdateAsync(EmailConfirmation item) {
return null;
}
@Override
public EmailConfirmation find(UUID id) {
return this.getDatabaseService().getQueryable(EmailConfirmation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public EmailConfirmation find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(EmailConfirmation item) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<EmailConfirmation> asQueryable() {
return this.getDatabaseService().getQueryable(EmailConfirmation.class);
}
}

@ -1,10 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.EntityDoi;
import java.util.UUID;
public interface EntityDoiDao extends DatabaseAccessLayer<EntityDoi, UUID> {
EntityDoi findFromDoi(String doi);
}

@ -1,56 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.EntityDoi;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("EntityDoiDao")
public class EntityDoiDaoImpl extends DatabaseAccess<EntityDoi> implements EntityDoiDao {
@Autowired
public EntityDoiDaoImpl(DatabaseService<EntityDoi> databaseService){
super(databaseService);
}
@Override
public EntityDoi createOrUpdate(EntityDoi item) {
return this.getDatabaseService().createOrUpdate(item, EntityDoi.class);
}
@Override
public CompletableFuture<EntityDoi> createOrUpdateAsync(EntityDoi item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public EntityDoi find(UUID id) {
return this.getDatabaseService().getQueryable(EntityDoi.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public EntityDoi findFromDoi(String doi) {
return this.getDatabaseService().getQueryable(EntityDoi.class).where((builder, root) -> builder.equal(root.get("doi"), doi)).getSingle();
}
@Override
public EntityDoi find(UUID id, String hint) {
return null;
}
@Override
public void delete(EntityDoi item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<EntityDoi> asQueryable() {
return this.getDatabaseService().getQueryable(EntityDoi.class);
}
}

@ -1,11 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.FileUpload;
import java.util.List;
import java.util.UUID;
public interface FileUploadDao extends DatabaseAccessLayer<FileUpload, UUID> {
List<FileUpload> getFileUploads(UUID entityId);
}

@ -1,56 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.FileUpload;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("FileUploadDao")
public class FileUploadDaoImpl extends DatabaseAccess<FileUpload> implements FileUploadDao {
@Autowired
public FileUploadDaoImpl(DatabaseService<FileUpload> databaseService) {
super(databaseService);
}
@Override
public FileUpload createOrUpdate(FileUpload item) {
return getDatabaseService().createOrUpdate(item, FileUpload.class);
}
//
@Override
public CompletableFuture<FileUpload> createOrUpdateAsync(FileUpload item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public FileUpload find(UUID id) {
return getDatabaseService().getQueryable(FileUpload.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public List<FileUpload> getFileUploads(UUID entityId) {
return this.getDatabaseService().getQueryable(FileUpload.class).where((builder, root) -> builder.equal(root.get("entityId"), entityId)).toList();
}
@Override
public FileUpload find(UUID id, String hint) {
return null;
}
@Override
public void delete(FileUpload item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<FileUpload> asQueryable() {
return this.getDatabaseService().getQueryable(FileUpload.class);
}
}

@ -29,10 +29,6 @@ public class FunderDaoImpl extends DatabaseAccess<Funder> implements FunderDao {
builder.or(builder.like(builder.upper(root.get("definition")), "%" + criteria.getLike().toUpperCase() + "%"))));
if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(builder.upper(root.get("reference")), "%" + criteria.getReference().toUpperCase() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(builder.upper(root.get("reference")), criteria.getExactReference().toUpperCase()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThanOrEqualTo(root.get("created"), criteria.getPeriodStart()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Funder.Status.DELETED.getValue()));
return query;
}

@ -39,8 +39,6 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
query.where((builder, root) -> builder.greaterThan(root.get("startdate"), criteria.getPeriodStart()));
if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), criteria.getExactReference()));
if (criteria.getGrantStateType() != null) {
if (criteria.getGrantStateType().equals(GrantStateType.FINISHED.getValue()))
query.where((builder, root) -> builder.lessThan(root.get("enddate"), new Date()));
@ -52,10 +50,6 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
if (criteria.isPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DMP.DMPStatus.FINALISED.getValue())).distinct();
}
if (criteria.isActive()) {
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct();
}
if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty())
query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId())));
if (criteria.getFunderReference() != null && !criteria.getFunderReference().isEmpty())
@ -85,7 +79,7 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
}
public QueryableList<Grant> getAuthenticated(QueryableList<Grant> query, UserInfo principal) {
query.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId())).distinct();
query.where((builder, root) -> builder.or(builder.equal(root.get("creationUser"), principal), builder.equal(root.join("dmps", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()))).distinct();
return query;
}

@ -0,0 +1,13 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.LoginConfirmationEmailCriteria;
import eu.eudat.data.entities.LoginConfirmationEmail;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public interface LoginConfirmationEmailDao extends DatabaseAccessLayer<LoginConfirmationEmail, UUID> {
QueryableList<LoginConfirmationEmail> getWithCriteria(LoginConfirmationEmailCriteria criteria);
}

@ -0,0 +1,56 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.LoginConfirmationEmailCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.LoginConfirmationEmail;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("LoginConfirmationEmailDao")
public class LoginConfirmationEmailDaoImpl extends DatabaseAccess<LoginConfirmationEmail> implements LoginConfirmationEmailDao {
@Autowired
public LoginConfirmationEmailDaoImpl(DatabaseService<LoginConfirmationEmail> databaseService) {
super(databaseService);
}
@Override
public QueryableList<LoginConfirmationEmail> getWithCriteria(LoginConfirmationEmailCriteria criteria) {
return null;
}
@Override
public LoginConfirmationEmail createOrUpdate(LoginConfirmationEmail item) {
return this.getDatabaseService().createOrUpdate(item, LoginConfirmationEmail.class);
}
@Override
public CompletableFuture<LoginConfirmationEmail> createOrUpdateAsync(LoginConfirmationEmail item) {
return null;
}
@Override
public LoginConfirmationEmail find(UUID id) {
return this.getDatabaseService().getQueryable(LoginConfirmationEmail.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public LoginConfirmationEmail find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(LoginConfirmationEmail item) {
throw new UnsupportedOperationException();
}
@Override
public QueryableList<LoginConfirmationEmail> asQueryable() {
return this.getDatabaseService().getQueryable(LoginConfirmationEmail.class);
}
}

@ -26,23 +26,14 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
@Override
public QueryableList<Organisation> getWithCriteria(OrganisationCriteria criteria) {
QueryableList<Organisation> query = this.getDatabaseService().getQueryable(Organisation.class);
if (criteria.getLabelLike() != null && criteria.getLike() != null) {
query.where((builder, root) -> builder.or(builder.equal(root.get("reference"), criteria.getLike()), builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%")));
} else {
if (criteria.getLike() != null)
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike()));
if (criteria.getLabelLike() != null) {
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%"));
}
if (criteria.getPublic() != null && criteria.getPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue()));
}
if (criteria.getLike() != null)
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike()));
if (criteria.getLabelLike() != null) {
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%"));
}
if (criteria.isActive()) {
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct();
if (criteria.getPublic() != null && criteria.getPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue()));
}
return query;
}
@ -73,7 +64,7 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
}
public QueryableList<Organisation> getAuthenticated(QueryableList<Organisation> query, UserInfo principal) {
query.where((builder, root) -> builder.equal(root.join("dmps").join("users").get("user"), principal));
query.where((builder, root) -> builder.equal(root.join("dmps").get("creator"), principal));
return query;
}

@ -28,10 +28,6 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
builder.or(builder.like(builder.upper(root.get("description")), "%" + criteria.getLike().toUpperCase() + "%"))));
if (criteria.getReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), "%" + criteria.getReference() + "%"));
if (criteria.getExactReference() != null)
query.where((builder, root) -> builder.like(root.get("reference"), criteria.getExactReference()));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThanOrEqualTo(root.get("startdate"), criteria.getPeriodStart()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Project.Status.DELETED.getValue()));
return query;
}

@ -24,13 +24,9 @@ public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements Res
public QueryableList<Researcher> getWithCriteria(ResearcherCriteria criteria) {
QueryableList<Researcher> query = asQueryable();
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) ->builder.or(builder.like(builder.lower(root.get("reference")), "%" + criteria.getLike().toLowerCase() + "%")));
query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%")));
if (criteria.getName() != null && !criteria.getName().isEmpty())
query.where((builder, root) ->builder.or(builder.like(builder.lower(root.get("label")), "%" + criteria.getName().toLowerCase() + "%")));
if (criteria.getReference() != null && !criteria.getReference().isEmpty())
query.where((builder, root) ->builder.or(builder.like(root.get("reference"), criteria.getReference())));
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThanOrEqualTo(root.get("created"), criteria.getPeriodStart()));
query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getName().toUpperCase() + "%")));
return query;
}

@ -1,13 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserDatasetProfile;
import java.util.UUID;
/**
* Created by ikalyvas on 2/8/2018.
*/
public interface UserDatasetProfileDao extends DatabaseAccessLayer<UserDatasetProfile, UUID> {
}

@ -1,53 +0,0 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserDatasetProfile;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("userDatasetProfileDao")
public class UserDatasetProfileDaoImpl extends DatabaseAccess<UserDatasetProfile> implements UserDatasetProfileDao {
@Autowired
public UserDatasetProfileDaoImpl(DatabaseService<UserDatasetProfile> databaseService) {
super(databaseService);
}
@Override
public UserDatasetProfile createOrUpdate(UserDatasetProfile item) {
return this.getDatabaseService().createOrUpdate(item, UserDatasetProfile.class);
}
@Override
public UserDatasetProfile find(UUID id) {
return this.getDatabaseService().getQueryable(UserDatasetProfile.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault();
}
@Override
public void delete(UserDatasetProfile item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<UserDatasetProfile> asQueryable() {
return this.getDatabaseService().getQueryable(UserDatasetProfile.class);
}
@Async
@Override
public CompletableFuture<UserDatasetProfile> createOrUpdateAsync(UserDatasetProfile item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public UserDatasetProfile find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

@ -26,7 +26,6 @@ public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInf
@Override
public QueryableList<UserInfo> getWithCriteria(UserInfoCriteria criteria) {
QueryableList<UserInfo> users = this.getDatabaseService().getQueryable(UserInfo.class);
users.where(((builder, root) -> builder.equal(root.get("userStatus"), 0)));
if (criteria.getAppRoles() != null && !criteria.getAppRoles().isEmpty())
users.where((builder, root) -> root.join("userRoles").get("role").in(criteria.getAppRoles()));
if (criteria.getLike() != null)

@ -2,6 +2,7 @@ package eu.eudat.data.dao.entities.security;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.Credential;
import sun.security.krb5.Credentials;
import java.util.UUID;

@ -13,7 +13,7 @@ import java.util.UUID;
*/
@Entity
@Table(name = "\"Content\"")
public class Content implements DataEntity<Content, UUID> { //IGNORE ME
public class Content implements DataEntity<Content, UUID> {
public enum ParentType {
GRANT(0);

@ -34,8 +34,6 @@ public class Credential implements DataEntity<Credential, UUID> {
private Integer provider;
@Column(name = "\"Public\"", nullable = false)
private String publicValue;
@Column(name = "\"Email\"")
private String email;
@Column(name = "\"Secret\"", nullable = false)
private String secret;
@ -90,14 +88,6 @@ public class Credential implements DataEntity<Credential, UUID> {
this.publicValue = publicValue;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSecret() {
return secret;
}
@ -149,7 +139,6 @@ public class Credential implements DataEntity<Credential, UUID> {
public void update(Credential entity) {
this.status = entity.status;
this.publicValue = entity.getPublicValue();
this.email = entity.getEmail();
this.secret = entity.getSecret();
this.lastUpdateTime = new Date();
}

@ -15,40 +15,21 @@ import java.util.stream.Collectors;
@NamedEntityGraphs({
@NamedEntityGraph(
name = "dataManagementPlanListingModel",
attributeNodes = {
@NamedAttributeNode("grant"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile")}/*,*/
/*subgraphs = {
attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"), @NamedAttributeNode("associatedDmps"),
@NamedAttributeNode("grant"), @NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile"), @NamedAttributeNode("dataset")},
subgraphs = {
@NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}),
}*/
}
),
@NamedEntityGraph(
name = "fullyDetailed",
attributeNodes = {
@NamedAttributeNode("grant"), @NamedAttributeNode("profile"),
@NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")
},
subgraphs = {
@NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")})
}
),
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")}),
@NamedEntityGraph(
name = "dmpRecentActivity",
attributeNodes = {
@NamedAttributeNode("users"), @NamedAttributeNode("creator")}),
@NamedEntityGraph(
name = "recentDmpModel",
attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"), @NamedAttributeNode("associatedDmps"),
@NamedAttributeNode("grant"), @NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile"), @NamedAttributeNode(value = "dataset", subgraph = "dataset")},
subgraphs = {
@NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}),
@NamedSubgraph(name = "dataset", attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("label")})
}
),
@NamedEntityGraph(
name = "versionListingModel",
attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("groupId"), @NamedAttributeNode("version")}
)
@NamedAttributeNode("users"), @NamedAttributeNode("creator")})
})
public class DMP implements DataEntity<DMP, UUID> {
@ -112,8 +93,12 @@ public class DMP implements DataEntity<DMP, UUID> {
/*@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true)
private String associatedDmps;*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "dmp")
private Set<DMPDatasetProfile> associatedDmps;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPDatasetProfile\"",
joinColumns = {@JoinColumn(name = "\"dmp\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"datasetprofile\"", referencedColumnName = "\"ID\"")}
)
private Set<DatasetProfile> associatedDmps;
@ManyToOne(fetch = FetchType.LAZY)
@ -182,8 +167,8 @@ public class DMP implements DataEntity<DMP, UUID> {
@Convert(converter = DateToUTCConverter.class)
private Date publishedAt;
@OneToMany(mappedBy = "entityId", fetch = FetchType.LAZY)
private Set<EntityDoi> dois;
@Column(name = "\"DOI\"")
private String doi;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Project\"")
@ -270,10 +255,10 @@ public class DMP implements DataEntity<DMP, UUID> {
this.grant = grant;
}
public Set<DMPDatasetProfile> getAssociatedDmps() {
public Set<DatasetProfile> getAssociatedDmps() {
return associatedDmps;
}
public void setAssociatedDmps(Set<DMPDatasetProfile> associatedDmps) {
public void setAssociatedDmps(Set<DatasetProfile> associatedDmps) {
this.associatedDmps = associatedDmps;
}
@ -340,12 +325,12 @@ public class DMP implements DataEntity<DMP, UUID> {
this.publishedAt = publishedAt;
}
public Set<EntityDoi> getDois() {
return dois;
}
public void setDois(Set<EntityDoi> dois) {
this.dois = dois;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public Project getProject() {
return project;
@ -381,7 +366,7 @@ public class DMP implements DataEntity<DMP, UUID> {
if (entity.getStatus().equals(DMPStatus.FINALISED.getValue())) this.setFinalizedAt(new Date());
if (entity.isPublic) this.setPublishedAt(new Date());
if (entity.getUsers() != null) this.users = entity.getUsers();
this.dois = entity.getDois();
if (entity.getDoi() != null && entity.getDoi().trim().isEmpty()) this.doi = entity.doi;
this.extraProperties = entity.getExtraProperties();
}

@ -1,76 +0,0 @@
package eu.eudat.data.entities;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"DMPDatasetProfile\"")
public class DMPDatasetProfile implements DataEntity<DMPDatasetProfile, UUID> {
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@ManyToOne
@JoinColumn(name = "\"dmp\"")
private DMP dmp;
@ManyToOne
@JoinColumn(name = "\"datasetprofile\"")
private DescriptionTemplate datasetprofile;
@Column(name = "\"data\"")
private String data;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public DMP getDmp() {
return dmp;
}
public void setDmp(DMP dmp) {
this.dmp = dmp;
}
public DescriptionTemplate getDatasetprofile() {
return datasetprofile;
}
public void setDatasetprofile(DescriptionTemplate datasetprofile) {
this.datasetprofile = datasetprofile;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public void update(DMPDatasetProfile entity) {
this.dmp = entity.getDmp();
this.datasetprofile = entity.getDatasetprofile();
this.data = entity.getData();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public DMPDatasetProfile buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
return this;
}
}

@ -26,14 +26,14 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
@Column(name = "\"Abbreviation\"")
private String abbreviation;
@Column(name = "\"Reference\"")
@Column(name = "\"Reference\"", nullable = false)
private String reference;
@Column(name = "\"Uri\"")
private String uri;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Definition\"", columnDefinition = "xml")
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
private String definition;
@OneToMany(mappedBy = "dataRepository", cascade = CascadeType.ALL, orphanRemoval = true)
@ -42,14 +42,14 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,
@Column(name = "\"Status\"", nullable = false)
private Short status;
@Column(name = "\"Created\"", nullable = false)
@Column(name = "\"Created\"")
private Date created = null;
@Column(name = "\"Modified\"", nullable = false)
@Column(name = "\"Modified\"")
private Date modified = new Date();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"")
@JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser;

@ -16,14 +16,13 @@ import java.util.stream.Collectors;
@NamedEntityGraphs({
@NamedEntityGraph(
name = "datasetListingModel",
attributeNodes = {/*@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"),
@NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"),*/
@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode(value = "profile", subgraph = "profile"), @NamedAttributeNode("creator")},
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"),
@NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"),
@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")},
subgraphs = {
@NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users"), @NamedAttributeNode("grant"), @NamedAttributeNode("organisations")}),
@NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}),
@NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")}),
@NamedSubgraph(name = "profile", attributeNodes = {@NamedAttributeNode("label")})
@NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")})
}),
@NamedEntityGraph(
@ -37,17 +36,7 @@ import java.util.stream.Collectors;
@NamedEntityGraph(
name = "datasetDataRepositories",
attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("creator")},
subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")})),
@NamedEntityGraph(
name = "recentDatasetModel",
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"),
@NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"),
@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")},
subgraphs = {
@NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users"), @NamedAttributeNode("grant"), @NamedAttributeNode("organisations")}),
@NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}),
@NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")})
})
subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")}))
})
public class Dataset implements DataEntity<Dataset, UUID> {
@ -92,7 +81,7 @@ public class Dataset implements DataEntity<Dataset, UUID> {
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"Label\"", nullable = false)
@Column(name = "\"Label\"")
private String label;
@ManyToOne(fetch = FetchType.LAZY)
@ -100,23 +89,20 @@ public class Dataset implements DataEntity<Dataset, UUID> {
@JoinColumn(name = "\"DMP\"", nullable = false)
private DMP dmp;
@Column(name = "\"DmpSectionIndex\"")
private Integer dmpSectionIndex;
@Column(name = "\"Uri\"")
private String uri;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Properties\"", columnDefinition = "xml")
@Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true)
private String properties;
@ManyToOne(fetch = FetchType.LAZY)
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"Profile\"")
private DescriptionTemplate profile;
@JoinColumn(name = "\"Profile\"", nullable = true)
private DatasetProfile profile;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Reference\"", columnDefinition = "xml")
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
private String reference;
@OneToMany(fetch = FetchType.LAZY)
@ -139,16 +125,16 @@ public class Dataset implements DataEntity<Dataset, UUID> {
private Short status;
@Column(name = "\"Created\"", nullable = false)
@Column(name = "\"Created\"")
@Convert(converter = DateToUTCConverter.class)
private Date created = null;
@Column(name = "\"Modified\"", nullable = false)
@Column(name = "\"Modified\"")
@Convert(converter = DateToUTCConverter.class)
private Date modified = new Date();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Creator\"")
@JoinColumn(name = "\"Creator\"", nullable = true)
private UserInfo creator;
@Column(name = "\"Description\"")
@ -235,12 +221,6 @@ public class Dataset implements DataEntity<Dataset, UUID> {
this.dmp = dmp;
}
public Integer getDmpSectionIndex() {
return dmpSectionIndex;
}
public void setDmpSectionIndex(Integer dmpSectionIndex) {
this.dmpSectionIndex = dmpSectionIndex;
}
public String getUri() {
return uri;
@ -258,10 +238,10 @@ public class Dataset implements DataEntity<Dataset, UUID> {
}
public DescriptionTemplate getProfile() {
public DatasetProfile getProfile() {
return profile;
}
public void setProfile(DescriptionTemplate profile) {
public void setProfile(DatasetProfile profile) {
this.profile = profile;
}
@ -337,7 +317,6 @@ public class Dataset implements DataEntity<Dataset, UUID> {
this.setRegistries(entity.getRegistries());
this.setDmp(entity.getDmp());
this.setDmpSectionIndex(entity.getDmpSectionIndex());
this.setStatus(entity.getStatus());
this.setProfile(entity.getProfile());
this.setModified(new Date());

@ -14,8 +14,8 @@ import java.util.UUID;
@Entity
@Table(name = "\"DescriptionTemplate\"")
public class DescriptionTemplate implements DataEntity<DescriptionTemplate,UUID>{
@Table(name = "\"DatasetProfile\"")
public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
public enum Status {
SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99);
@ -49,7 +49,7 @@ public class DescriptionTemplate implements DataEntity<DescriptionTemplate,UUID>
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"Label\"", nullable = false)
@Column(name = "\"Label\"")
private String label;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "profile")
@ -79,21 +79,16 @@ public class DescriptionTemplate implements DataEntity<DescriptionTemplate,UUID>
@Column(name = "\"Version\"", nullable = false)
private Short version;
@OneToMany(fetch = FetchType.LAZY)
private Set<DMP> dmps;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPDatasetProfile\"",
joinColumns = {@JoinColumn(name = "\"datasetprofile\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"dmp\"", referencedColumnName = "\"ID\"")}
)
private List<DMP> dmps;
@Column(name = "\"Language\"", nullable = false)
private String language;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"Type\"", nullable = false)
private DescriptionTemplateType type;
@OneToMany(mappedBy = "descriptionTemplate", fetch = FetchType.LAZY)
private Set<UserDatasetProfile> users;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "datasetprofile")
private Set<DMPDatasetProfile> associatedDmps;
public String getDescription() {
return description;
@ -158,31 +153,18 @@ public class DescriptionTemplate implements DataEntity<DescriptionTemplate,UUID>
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public DescriptionTemplateType getType() {
return type;
}
public void setType(DescriptionTemplateType type) {
this.type = type;
}
public Set<UserDatasetProfile> getUsers() {
return users;
}
public void setUsers(Set<UserDatasetProfile> users) {
this.users = users;
}
@Override
public String toString() {
return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", definition=" + definition + ", version=" + version + ", language=" + language + ", type=" + type +"]";
return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", definition=" + definition + ", version=" + version + ", language=" + language + "]";
}
@Override
public void update(DescriptionTemplate entity) {
public void update(DatasetProfile entity) {
}
@Override
@ -191,7 +173,7 @@ public class DescriptionTemplate implements DataEntity<DescriptionTemplate,UUID>
}
@Override
public DescriptionTemplate buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
public DatasetProfile buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
return this;
}

@ -1,89 +0,0 @@
package eu.eudat.data.entities;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"DescriptionTemplateType\"")
public class DescriptionTemplateType implements DataEntity<DescriptionTemplateType, UUID> {
public enum Status {
SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99);
private short value;
private Status(short value) {
this.value = value;
}
public short getValue() {
return value;
}
public static Status fromInteger(int value) {
switch (value) {
case 0:
return SAVED;
case 1:
return FINALIZED;
case 99:
return DELETED;
default:
throw new RuntimeException("Unsupported Description Template Type Status");
}
}
}
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"Name\"", nullable = false)
private String name;
@Column(name = "\"Status\"", nullable = false)
private Short status;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
@Override
public void update(DescriptionTemplateType entity) {
this.name = entity.name;
this.status = entity.status;
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public DescriptionTemplateType buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(!base.isEmpty() ? base + "." + "id" : "id"));
return this;
}
}

@ -0,0 +1,61 @@
package eu.eudat.data.entities;
import eu.eudat.queryable.queryableentity.DataEntity;
import javax.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"DoiFunder\"")
public class DoiFunder implements DataEntity<DoiFunder, UUID> {
@Id
private UUID id;
@Column(name = "name")
private String name;
@Column(name = "doi")
private String doi;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
@Override
public void update(DoiFunder entity) {
this.name = entity.name;
this.doi = entity.doi;
}
@Override
public UUID getKeys() {
return id;
}
@Override
public DoiFunder buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
return null;
}
}

@ -1,121 +0,0 @@
package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Entity
@Table(name = "\"EntityDoi\"")
public class EntityDoi implements DataEntity<EntityDoi, UUID> {
public enum EntityType {
DMP
}
@Id
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Enumerated(EnumType.STRING)
@Type(type = "eu.eudat.configurations.typedefinition.PostgreSQLEnumType")
@Column(name = "\"EntityType\"", nullable = false)
private EntityType entityType;
@Column(name = "\"RepositoryId\"", nullable = false)
private String repositoryId;
@Column(name = "\"Doi\"", nullable = false)
private String doi;
@Column(name = "\"CreatedAt\"", nullable = false)
@Convert(converter = DateToUTCConverter.class)
private Date createdAt;
@Column(name = "\"UpdatedAt\"", nullable = false)
@Convert(converter = DateToUTCConverter.class)
private Date updatedAt;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"EntityId\"", nullable = false)
private DMP entityId;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public EntityType getEntityType() {
return entityType;
}
public void setEntityType(EntityType entityType) {
this.entityType = entityType;
}
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public DMP getEntityId() {
return entityId;
}
public void setEntityId(DMP entityId) {
this.entityId = entityId;
}
@Override
public void update(EntityDoi doi) {
this.entityType = doi.getEntityType();
this.repositoryId = doi.getRepositoryId();
this.doi = doi.getDoi();
this.createdAt = doi.getCreatedAt();
this.updatedAt = doi.getUpdatedAt();
this.entityId = doi.getEntityId();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public EntityDoi buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
if (fields.contains(currentBase + "entityId"))
this.entityId = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields , base.isEmpty() ? "entityId" : base + "." + "entityId")).collect(Collectors.toList()).get(0);
return this;
}
}

@ -1,129 +0,0 @@
package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Entity
@Table(name = "\"FileUpload\"")
public class FileUpload implements DataEntity<FileUpload, UUID> {
public enum EntityType {
DATASET, DMP
}
@Id
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"Name\"", nullable = false)
private String name;
@Column(name = "\"FileType\"", nullable = false)
private String fileType;
@Column(name = "\"EntityId\"", nullable = false)
private UUID entityId;
@Enumerated(EnumType.STRING)
@Type(type = "eu.eudat.configurations.typedefinition.PostgreSQLEnumType")
@Column(name = "\"EntityType\"", nullable = false)
private EntityType entityType;
@Column(name = "\"CreatedAt\"", nullable = false)
@Convert(converter = DateToUTCConverter.class)
private Date createdAt;
@Column(name = "\"IsDeleted\"", nullable = false)
private Boolean isDeleted;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Creator\"")
private UserInfo creator;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFileType() {
return fileType;
}
public void setFileType(String fileType) {
this.fileType = fileType;
}
public UUID getEntityId() {
return entityId;
}
public void setEntityId(UUID entityId) {
this.entityId = entityId;
}
public EntityType getEntityType() {
return entityType;
}
public void setEntityType(EntityType entityType) {
this.entityType = entityType;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Boolean getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
}
public UserInfo getCreator() {
return creator;
}
public void setCreator(UserInfo creator) {
this.creator = creator;
}
@Override
public void update(FileUpload file) {
this.name = file.getName();
this.fileType = file.getFileType();
this.entityId = file.getEntityId();
this.entityType = file.getEntityType();
this.createdAt = file.getCreatedAt();
this.isDeleted = file.getIsDeleted();
this.creator = file.getCreator();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public FileUpload buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
this.creator = tuple.stream().map(x -> new UserInfo().buildFromTuple(tuple, fields , base.isEmpty() ? "creator" : base + "." + "creator")).collect(Collectors.toList()).get(0);
return this;
}
}

@ -106,11 +106,11 @@ public class Grant implements DataEntity<Grant, UUID> {
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
private String definition;
@Column(name = "\"StartDate\"", nullable = true)
@Column(name = "\"StartDate\"", nullable = false)
@Convert(converter = DateToUTCConverter.class)
private Date startdate = null;
@Column(name = "\"EndDate\"", nullable = true)
@Column(name = "\"EndDate\"", nullable = false)
@Convert(converter = DateToUTCConverter.class)
private Date enddate = null;

@ -10,8 +10,8 @@ import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"EmailConfirmation\"")
public class EmailConfirmation implements DataEntity<EmailConfirmation, UUID> {
@Table(name = "\"LoginConfirmationEmail\"")
public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail, UUID> {
@Id
@GeneratedValue
@ -30,9 +30,6 @@ public class EmailConfirmation implements DataEntity<EmailConfirmation, UUID> {
@Column(name = "\"userId\"", nullable = false)
private UUID userId;
@Column(name = "\"data\"")
private String data;
@Column(name = "\"expiresAt\"", nullable = false)
@Convert(converter = DateToUTCConverter.class)
@ -80,14 +77,9 @@ public class EmailConfirmation implements DataEntity<EmailConfirmation, UUID> {
this.expiresAt = expiresAt;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public void update(EmailConfirmation entity) {
public void update(LoginConfirmationEmail entity) {
}
@Override
@ -96,7 +88,7 @@ public class EmailConfirmation implements DataEntity<EmailConfirmation, UUID> {
}
@Override
public EmailConfirmation buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
public LoginConfirmationEmail buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
return null;
}
}

@ -24,7 +24,7 @@ public class Researcher implements DataEntity<Researcher, UUID> {
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"Label\"", nullable = false, length = 250)
@Column(name = "\"Label\"")
private String label;
@Column(name = "\"Uri\"")

@ -1,79 +0,0 @@
package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"UserDatasetProfile\"")
public class UserDatasetProfile implements DataEntity<UserDatasetProfile, UUID> {
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "usr")
private UserInfo user;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"descriptionTemplate\"")
private DescriptionTemplate descriptionTemplate;
@Column(name = "role")
private Integer role;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UserInfo getUser() {
return user;
}
public void setUser(UserInfo user) {
this.user = user;
}
public DescriptionTemplate getDatasetProfile() {
return descriptionTemplate;
}
public void setDatasetProfile(DescriptionTemplate descriptionTemplate) {
this.descriptionTemplate = descriptionTemplate;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
@Override
public void update(UserDatasetProfile entity) {
this.role = entity.getRole();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public UserDatasetProfile buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this;
}
}

@ -15,7 +15,7 @@ import java.util.*;
@NamedEntityGraphs({
@NamedEntityGraph(
name = "userInfo",
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials"), @NamedAttributeNode("additionalinfo")}),
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")}),
})
public class UserInfo implements DataEntity<UserInfo, UUID> {
@ -26,7 +26,7 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
private UUID id;
@Column(name = "email")
@Column(name = "email", nullable = false)
private String email = null;
@Column(name = "authorization_level", nullable = false)
@ -35,9 +35,6 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
@Column(name = "usertype", nullable = false)
private Short usertype; // 0 internal, 1 external
@Column(name = "userstatus", nullable = false)
private Short userStatus; // 0 active, 1 inactive
@Column(name = "verified_email", nullable = true)
private Boolean verified_email = null;
@ -190,14 +187,6 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
this.notifications = notifications;
}
public Short getUserStatus() {
return userStatus;
}
public void setUserStatus(Short userStatus) {
this.userStatus = userStatus;
}
@Override
public void update(UserInfo entity) {
this.name = entity.getName();
@ -205,7 +194,6 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
this.additionalinfo = entity.getAdditionalinfo();
this.lastloggedin = entity.getLastloggedin();
this.userRoles = entity.getUserRoles();
this.userStatus = entity.getUserStatus();
}
@Override

@ -21,12 +21,9 @@ public class PaginationService {
items.withFields(Arrays.asList(tableRequest.getSelection().getFields()));
return items;
}
public static <T extends DataEntity> void applyOrder(QueryableList<T> items, TableQuery tableRequest) {
applyOrder(items, tableRequest.getOrderings());
}
public static <T extends DataEntity> void applyOrder(QueryableList<T> items, ColumnOrderings columnOrderings) {
public static <T extends DataEntity> void applyOrder(QueryableList<T> items, TableQuery tableRequest) {
ColumnOrderings columnOrderings = tableRequest.getOrderings();
for (Ordering ordering : columnOrderings.getFieldOrderings()) {
if (ordering.getOrderByType() == Ordering.OrderByType.ASC)
applyAscOrder(items, ordering);

@ -3,14 +3,12 @@ package eu.eudat.data.query.definition;
import eu.eudat.data.dao.criteria.Criteria;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.queryableentity.DataEntity;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class Query<C extends Criteria<T>, T extends DataEntity> implements CriteriaQuery<C, T> {
private static final Logger logger = LoggerFactory.getLogger(Query.class);
private C criteria;
@ApiModelProperty(value = "query", name = "query", dataType = "String", hidden = true)
private QueryableList<T> query;
public static class QueryBuilder<C extends Criteria<T>, T extends DataEntity, Q extends Query<C, T>> {

@ -6,16 +6,12 @@ import eu.eudat.data.query.definition.helpers.ColumnOrderings;
import eu.eudat.data.query.definition.helpers.SelectionFields;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.queryableentity.DataEntity;
import io.swagger.annotations.ApiModelProperty;
public abstract class TableQuery<C extends Criteria<T>, T extends DataEntity<T, K>, K> extends Query<C, T> implements TableCriteriaQuery<C, T> {
private ColumnOrderings orderings;
@ApiModelProperty(hidden = true)
private SelectionFields selection;
@ApiModelProperty(value = "length", name = "length", dataType = "Integer", example = "2")
private Integer length;
@ApiModelProperty(value = "offset", name = "offset", dataType = "Integer", example = "0")
private Integer offset;
public Integer getLength() {

@ -1,30 +1,27 @@
package eu.eudat.data.query.definition.helpers;
import io.swagger.annotations.ApiModelProperty;
import java.util.LinkedList;
import java.util.List;
public class ColumnOrderings {
@ApiModelProperty(value = "fields", name = "fields", dataType = "List<String>", example = "[]")
private List<String> fields;
private String[] fields;
public List<String> getFields() {
public String[] getFields() {
return fields;
}
public void setFields(List<String> fields) {
public void setFields(String[] fields) {
this.fields = fields;
}
public List<Ordering> getFieldOrderings() {
public Ordering[] getFieldOrderings() {
List<Ordering> orderings = new LinkedList<>();
for (String field : fields) {
orderings.add(this.orderingFromString(field));
}
return orderings;
return orderings.toArray(new Ordering[orderings.size()]);
}
private Ordering orderingFromString(String field) {
@ -37,10 +34,6 @@ public class ColumnOrderings {
ordering.fieldName(ordering.getFieldName().replace("|count|", "")).columnType(Ordering.ColumnType.COUNT);
else if (ordering.getFieldName().contains("|join|"))
ordering.fieldName(ordering.getFieldName().replace("|join|", "")).columnType(Ordering.ColumnType.JOIN_COLUMN);
else if (ordering.getFieldName().equals("asc"))
ordering.fieldName("label").orderByType(Ordering.OrderByType.ASC);
else if (ordering.getFieldName().equals("desc"))
ordering.fieldName("label").orderByType(Ordering.OrderByType.DESC);
return ordering;
}
}

@ -1,11 +1,8 @@
package eu.eudat.data.query.definition.helpers;
import io.swagger.annotations.ApiModelProperty;
public class SelectionFields {
@ApiModelProperty(value = "fields", name = "fields", dataType = "String[]", example = "[]")
private String[] fields;
public String[] getFields() {

@ -1,27 +0,0 @@
package eu.eudat.data.query.items.dmpblueprint;
import eu.eudat.data.dao.criteria.DataManagementPlanBlueprintCriteria;
import eu.eudat.data.entities.DMPProfile;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public class DataManagementPlanBlueprintTableRequest extends TableQuery<DataManagementPlanBlueprintCriteria, DMPProfile, UUID> {
@Override
public QueryableList<DMPProfile> applyCriteria() {
QueryableList<DMPProfile> query = this.getQuery();
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.like(root.get("label"), "%" + this.getCriteria().getLike() + "%"));
if (this.getCriteria().getStatus() != null)
query.where((builder, root) -> builder.equal(root.get("status"), this.getCriteria().getStatus()));
return query;
}
@Override
public QueryableList<DMPProfile> applyPaging(QueryableList<DMPProfile> items) {
return PaginationService.applyPaging(items, this);
}
}

@ -1,24 +1,25 @@
package eu.eudat.data.query.items.item.datasetprofile;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.definition.Query;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public class DatasetProfileAutocompleteRequest extends TableQuery<DatasetProfileCriteria, DescriptionTemplate, UUID> {
public class DatasetProfileAutocompleteRequest extends TableQuery<DatasetProfileCriteria,DatasetProfile, UUID> {
@Override
public QueryableList<DescriptionTemplate> applyCriteria() {
QueryableList<DescriptionTemplate> query = this.getQuery();
public QueryableList<DatasetProfile> applyCriteria() {
QueryableList<DatasetProfile> query = this.getQuery();
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%"));
return query;
}
@Override
public QueryableList<DescriptionTemplate> applyPaging(QueryableList<DescriptionTemplate> items) {
public QueryableList<DatasetProfile> applyPaging(QueryableList<DatasetProfile> items) {
return PaginationService.applyPaging(items, this);
}
}

@ -1,13 +1,15 @@
package eu.eudat.data.query.items.item.datasetprofile;
import eu.eudat.data.dao.criteria.DatasetProfileWizardCriteria;
import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.data.query.definition.Query;
import eu.eudat.queryable.QueryableList;
public class DatasetProfileWizardAutocompleteRequest extends Query<DatasetProfileWizardCriteria, DescriptionTemplate> {
import java.util.UUID;
public class DatasetProfileWizardAutocompleteRequest extends Query<DatasetProfileWizardCriteria,DatasetProfile> {
@Override
public QueryableList<DescriptionTemplate> applyCriteria() {
public QueryableList<DatasetProfile> applyCriteria() {
return null;
}
}

@ -1,56 +0,0 @@
package eu.eudat.data.query.items.table.dataset;
import eu.eudat.data.dao.criteria.DatasetPublicCriteria;
import eu.eudat.data.entities.Dataset;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import eu.eudat.types.grant.GrantStateType;
import java.util.Arrays;
import java.util.Date;
import java.util.UUID;
/**
* Created by ikalyvas on 10/2/2018.
*/
public class DatasetPublicTableRequest extends TableQuery<DatasetPublicCriteria, Dataset, UUID> {
@Override
public QueryableList<Dataset> applyCriteria() {
QueryableList<Dataset> query = this.getQuery();
query.where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true));
query.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue()));
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"),
query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")),
Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%"),
builder.like(builder.upper(root.get("description")), "%" + this.getCriteria().getLike().toUpperCase() + "%")));
if (this.getCriteria().getGrants() != null && !this.getCriteria().getGrants().isEmpty())
query.where(((builder, root) -> root.get("dmp").get("grant").get("id").in(this.getCriteria().getGrants())));
if (this.getCriteria().getGrantStatus() != null) {
if (this.getCriteria().getGrantStatus().getValue().equals(GrantStateType.FINISHED.getValue()))
query.where((builder, root) -> builder.lessThan(root.get("dmp").get("grant").get("enddate"), new Date()));
if (this.getCriteria().getGrantStatus().getValue().equals(GrantStateType.ONGOING.getValue()))
query.where((builder, root) ->
builder.or(builder.greaterThan(root.get("dmp").get("grant").get("enddate"), new Date())
, builder.isNull(root.get("dmp").get("grant").get("enddate"))));
}
if (this.getCriteria().getDmpIds() != null && !this.getCriteria().getDmpIds().isEmpty()) {
query.where(((builder, root) -> root.get("dmp").get("id").in(this.getCriteria().getDmpIds())));
}
if (this.getCriteria().getDatasetProfile() != null && !this.getCriteria().getDatasetProfile().isEmpty()) query
.where(((builder, root) -> root.get("profile").get("id").in(this.getCriteria().getDatasetProfile())));
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty()) query
.where(((builder, root) -> root.join("dmp").join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()));
return query;
}
@Override
public QueryableList<Dataset> applyPaging(QueryableList<Dataset> items) {
return null;
}
}

@ -1,23 +1,23 @@
package eu.eudat.data.query.items.table.datasetprofile;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public class DatasetProfileTableRequestItem extends TableQuery<DatasetProfileCriteria, DescriptionTemplate, UUID> {
public class DatasetProfileTableRequestItem extends TableQuery<DatasetProfileCriteria, DatasetProfile, UUID> {
@Override
public QueryableList<DescriptionTemplate> applyCriteria() {
QueryableList<DescriptionTemplate> query = this.getQuery();
public QueryableList<DatasetProfile> applyCriteria() {
QueryableList<DatasetProfile> query = this.getQuery();
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%"));
return query;
}
@Override
public QueryableList<DescriptionTemplate> applyPaging(QueryableList<DescriptionTemplate> items) {
public QueryableList<DatasetProfile> applyPaging(QueryableList<DatasetProfile> items) {
return null;
}
}

@ -1,54 +0,0 @@
package eu.eudat.data.query.items.table.dmp;
import eu.eudat.data.dao.criteria.DataManagementPlanPublicCriteria;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import eu.eudat.types.grant.GrantStateType;
import java.util.Arrays;
import java.util.Date;
import java.util.UUID;
public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManagementPlanPublicCriteria, DMP, UUID> {
public QueryableList<DMP> applyCriteria() {
QueryableList<DMP> query = this.getQuery();
query.where((builder, root) -> builder.equal(root.get("isPublic"), true));
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%"),
builder.like(builder.upper(root.get("description")), "%" + this.getCriteria().getLike().toUpperCase() + "%")));
if (this.getCriteria().getGrants() != null && !this.getCriteria().getGrants().isEmpty())
query.where(((builder, root) -> root.get("grant").get("id").in(this.getCriteria().getGrants())));
if (this.getCriteria().getGrantStatus() != null) {
if (this.getCriteria().getGrantStatus().getValue().equals(GrantStateType.FINISHED.getValue()))
query.where((builder, root) -> builder.lessThan(root.get("grant").get("enddate"), new Date()));
if (this.getCriteria().getGrantStatus().getValue().equals(GrantStateType.ONGOING.getValue()))
query.where((builder, root) ->
builder.or(builder.greaterThan(root.get("grant").get("enddate"), new Date())
, builder.isNull(root.get("grant").get("enddate"))));
}
if (this.getCriteria().datasetProfile != null && !this.getCriteria().datasetProfile.isEmpty())
query.where((builder, root) -> root.join("associatedDmps").get("id").in(this.getCriteria().datasetProfile));
if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty())
query.where(((builder, root) -> root.join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations())));
if (!this.getCriteria().getAllVersions()) {
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"),
query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("groupId"),
nestedRoot.get("groupId")), builder1.equal(nestedRoot.get("isPublic"), true)), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class)));
}
if (this.getCriteria().getGroupIds() != null && !this.getCriteria().getGroupIds().isEmpty()) {
query.where((builder, root) -> root.get("groupId").in(this.getCriteria().getGroupIds()));
}
return query;
}
@Override
public QueryableList<DMP> applyPaging(QueryableList<DMP> items) {
return PaginationService.applyPaging(items, this);
}
}

@ -4,13 +4,4 @@ import java.util.UUID;
public class DatasetProfileQuery {
private UserQuery userQuery;
public UserQuery getUserQuery() {
return userQuery;
}
public void setUserQuery(UserQuery userQuery) {
this.userQuery = userQuery;
}
}

@ -18,13 +18,9 @@ public class DatasetCriteria extends Criteria {
private List<UUID> collaborators;
private Boolean allowAllVersions;
private List<String> organiztions;
private Boolean hasTags;
private List<Tag> tags;
private boolean isPublic;
private Short grantStatus;
private int offset;
private int size;
private List<SortCriteria> sortCriteria;
public String getLike() {
return like;
@ -121,36 +117,4 @@ public class DatasetCriteria extends Criteria {
public void setGrantStatus(Short grantStatus) {
this.grantStatus = grantStatus;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public List<SortCriteria> getSortCriteria() {
return sortCriteria;
}
public void setSortCriteria(List<SortCriteria> sortCriteria) {
this.sortCriteria = sortCriteria;
}
public Boolean getHasTags() {
return hasTags;
}
public void setHasTags(Boolean hasTags) {
this.hasTags = hasTags;
}
}

@ -9,16 +9,11 @@ public class DmpCriteria extends Criteria {
private List<UUID> templates;
private List<UUID> grants;
private List<UUID> collaborators;
private List<Integer> roles;
private List<UUID> organizations;
private boolean isPublic;
private List<UUID> groupIds;
private boolean allowAllVersions;
private Short grantStatus;
private int offset;
private Integer size;
private List<SortCriteria> sortCriteria;
public String getLike() {
return like;
@ -60,14 +55,6 @@ public class DmpCriteria extends Criteria {
this.collaborators = collaborators;
}
public List<Integer> getRoles() {
return roles;
}
public void setRoles(List<Integer> roles) {
this.roles = roles;
}
public List<UUID> getOrganizations() {
return organizations;
}
@ -107,28 +94,4 @@ public class DmpCriteria extends Criteria {
public void setGrantStatus(Short grantStatus) {
this.grantStatus = grantStatus;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public Integer getSize() {
return size;
}
public void setSize(Integer size) {
this.size = size;
}
public List<SortCriteria> getSortCriteria() {
return sortCriteria;
}
public void setSortCriteria(List<SortCriteria> sortCriteria) {
this.sortCriteria = sortCriteria;
}
}

@ -1,39 +0,0 @@
package eu.eudat.elastic.criteria;
public class SortCriteria {
public enum OrderByType {
ASC, DESC
}
public enum ColumnType {
COUNT, COLUMN, JOIN_COLUMN
}
private String fieldName;
private OrderByType orderByType;
private ColumnType columnType;
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public OrderByType getOrderByType() {
return orderByType;
}
public void setOrderByType(OrderByType orderByType) {
this.orderByType = orderByType;
}
public ColumnType getColumnType() {
return columnType;
}
public void setColumnType(ColumnType columnType) {
this.columnType = columnType;
}
}

@ -4,11 +4,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
public class Collaborator implements ElasticEntity<Collaborator> {
private String id;
private String name;
private int role;
public String getId() {
return id;
@ -26,20 +26,11 @@ public class Collaborator implements ElasticEntity<Collaborator> {
this.name = name;
}
public int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
@Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject();
builder.field("id", this.id);
builder.field("name", this.name);
builder.field("role", this.role);
builder.endObject();
return builder;
}
@ -48,7 +39,6 @@ public class Collaborator implements ElasticEntity<Collaborator> {
public Collaborator fromElasticEntity(Map fields) {
this.id = (String) fields.get("id");
this.name = (String) fields.get("name");
this.role = (int) fields.get("role");
return this;
}
}

@ -5,7 +5,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
@ -60,9 +59,6 @@ public class Dataset implements ElasticEntity<Dataset> {
private Boolean isPublic;
private Short grantStatus;
private String formData;
private Date created;
private Date modified;
private Date finalizedAt;
public String getId() {
return id;
@ -192,30 +188,6 @@ public class Dataset implements ElasticEntity<Dataset> {
this.formData = formData;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public Date getFinalizedAt() {
return finalizedAt;
}
public void setFinalizedAt(Date finalizedAt) {
this.finalizedAt = finalizedAt;
}
@Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject();
@ -225,15 +197,10 @@ public class Dataset implements ElasticEntity<Dataset> {
builder.field("template", this.template.toString());
builder.field("status", this.status.toString());
builder.field("dmp", this.dmp.toString());
builder.field("created", this.created);
builder.field("modified", this.modified);
builder.field("finalizedAt", this.finalizedAt);
if (this.group != null) {
builder.field("group", this.group.toString());
}
if (this.grant != null) {
builder.field("grant", this.grant.toString());
}
builder.field("grant", this.grant.toString());
if (collaborators != null) {
builder.startArray("collaborators");
this.collaborators.forEach(x -> {
@ -285,48 +252,32 @@ public class Dataset implements ElasticEntity<Dataset> {
@Override
public Dataset fromElasticEntity(Map<String, Object> fields) {
if (fields != null) {
if (fields.size() == 1) {
if (fields.containsKey("id")) {
this.id = (String) fields.get("id");
} else if (fields.containsKey("tags")) {
this.tags = ((List<HashMap>) fields.get("tags")).stream().map(hashMap -> new Tag().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
}else if (fields.size() > 1) {
this.id = (String) fields.get("id");
if (fields.get("tags") != null) {
this.tags = ((List<HashMap>) fields.get("tags")).stream().map(hashMap -> new Tag().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
this.label = (String) fields.get("label");
this.description = (String) fields.get("description");
this.template = UUID.fromString((String) fields.get("template"));
this.status = Short.valueOf((String) fields.get("status"));
this.dmp = UUID.fromString((String) fields.get("dmp"));
this.group = UUID.fromString((String) fields.get("group"));
if (fields.get("grant") != null) {
this.grant = UUID.fromString((String) fields.get("grant"));
}
if (fields.get("created") != null)
this.created = Date.from(Instant.parse((String) fields.get("created")));
if (fields.get("modified") != null)
this.modified = Date.from(Instant.parse((String) fields.get("modified")));
if (fields.get("finalizedAt") != null)
this.finalizedAt = Date.from(Instant.parse((String) fields.get("finalizedAt")));
if (fields.get("collaborators") != null) {
this.collaborators = ((List<HashMap>) fields.get("collaborators")).stream().map(hashMap -> new Collaborator().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
this.lastVersion = Boolean.parseBoolean((String) fields.get("lastVersion"));
this.lastPublicVersion = Boolean.parseBoolean((String) fields.get("lastPublicVersion"));
if (fields.get("organizations") != null) {
this.organizations = ((List<HashMap>) fields.get("organizations")).stream().map(hashMap -> new Organization().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
if (fields.get("public") != null) {
this.isPublic = Boolean.valueOf((String) fields.get("public"));
}
if (fields.get("grantStatus") != null) {
this.grantStatus = Short.valueOf((String) fields.get("grantStatus"));
}
this.formData = (String) fields.get("formData");
this.id = (String) fields.get("id");
if (fields.get("tags") != null) {
this.tags = ((List<HashMap>) fields.get("tags")).stream().map(hashMap -> new Tag().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
this.label = (String) fields.get("label");
this.description = (String) fields.get("description");
this.template = UUID.fromString((String) fields.get("template"));
this.status = Short.valueOf((String) fields.get("status"));
this.dmp = UUID.fromString((String) fields.get("dmp"));
this.group = UUID.fromString((String) fields.get("group"));
this.grant = UUID.fromString((String) fields.get("grant"));
if (fields.get("collaborators") != null) {
this.collaborators = ((List<HashMap>) fields.get("collaborators")).stream().map(hashMap -> new Collaborator().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
this.lastVersion = Boolean.parseBoolean((String) fields.get("lastVersion"));
this.lastPublicVersion = Boolean.parseBoolean((String) fields.get("lastPublicVersion"));
if (fields.get("organizations") != null) {
this.organizations = ((List<HashMap>) fields.get("organizations")).stream().map(hashMap -> new Organization().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
if (fields.get("public") != null) {
this.isPublic = Boolean.valueOf((String) fields.get("public"));
}
if (fields.get("grantStatus") != null) {
this.grantStatus = Short.valueOf((String) fields.get("grantStatus"));
}
this.formData = (String) fields.get("formData");
}
return this;
}

@ -1,18 +1,14 @@
package eu.eudat.elastic.entities;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class DatasetTempalate implements ElasticEntity<DatasetTempalate> {
private UUID id;
private String name;
private Map<String, Object> data;
public UUID getId() {
return id;
@ -30,25 +26,11 @@ public class DatasetTempalate implements ElasticEntity<DatasetTempalate> {
this.name = name;
}
public Map<String, Object> getData() {
return data;
}
public void setData(Map<String, Object> data) {
this.data = data;
}
@Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject();
builder.field("id", this.id.toString());
builder.field("name", this.name);
if(this.data != null) {
builder.field("data", new ObjectMapper().writeValueAsString(this.data));
}
else{
builder.field("data", "");
}
builder.endObject();
return builder;
}
@ -57,12 +39,6 @@ public class DatasetTempalate implements ElasticEntity<DatasetTempalate> {
public DatasetTempalate fromElasticEntity(Map<String, Object> fields) {
this.id = UUID.fromString((String) fields.get("id"));
this.name = (String) fields.get("name");
try {
this.data = new ObjectMapper().readValue((String) fields.get("data"), new TypeReference<Map<String, Object>>() {});
}
catch (Exception e){
this.data = new HashMap<>();
}
return this;
}
}

@ -5,8 +5,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.time.Instant;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
public class Dmp implements ElasticEntity<Dmp> {
@ -53,11 +55,6 @@ public class Dmp implements ElasticEntity<Dmp> {
private List<Dataset> datasets;
private UUID grant;
private Short grantStatus;
private Date created;
private Date modified;
private Date finalizedAt;
private Date publishedAt;
private List<Doi> dois;
public UUID getId() {
return id;
@ -171,46 +168,6 @@ public class Dmp implements ElasticEntity<Dmp> {
this.grantStatus = grantStatus;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public Date getFinalizedAt() {
return finalizedAt;
}
public void setFinalizedAt(Date finalizedAt) {
this.finalizedAt = finalizedAt;
}
public Date getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(Date publishedAt) {
this.publishedAt = publishedAt;
}
public List<Doi> getDois() {
return dois;
}
public void setDois(List<Doi> dois) {
this.dois = dois;
}
@Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject();
@ -276,74 +233,37 @@ public class Dmp implements ElasticEntity<Dmp> {
builder.field(MapKey.GRANT.getName(), this.grant.toString());
}
builder.field(MapKey.GRANTSTATUS.getName(), this.grantStatus);
builder.field(MapKey.CREATED.getName(), this.created);
builder.field(MapKey.MODIFIED.getName(), this.modified);
builder.field(MapKey.FINALIZEDAT.getName(), this.finalizedAt);
builder.field(MapKey.PUBLISHEDAT.getName(), this.publishedAt);
if (this.dois != null && !this.dois.isEmpty()) {
builder.startArray(MapKey.DOIS.getName());
this.dois.forEach(doi -> {
try {
doi.toElasticEntity(builder);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
});
builder.endArray();
}
builder.endObject();
return builder;
}
@Override
public Dmp fromElasticEntity(Map<String, Object> fields) {
if (fields == null || fields.isEmpty()) {
return null;
}
this.id = UUID.fromString((String) fields.get(MapKey.ID.getName()));
if (fields.size() > 1) {
this.label = (String) fields.get(MapKey.LABEL.getName());
this.description = (String) fields.get(MapKey.DESCRIPTION.getName());
if (fields.get(MapKey.GROUPID.getName()) != null) {
this.groupId = UUID.fromString((String) fields.get(MapKey.GROUPID.getName()));
}
this.status = Short.valueOf(fields.get(MapKey.STATUS.getName()).toString());
if (fields.get(MapKey.TEMPLATES.getName()) != null) {
this.templates = ((List<HashMap<String, Object>>) fields.get(MapKey.TEMPLATES.getName())).stream().map(hashMap -> new DatasetTempalate().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
if (fields.get(MapKey.COLLABORATORS.getName()) != null) {
this.collaborators = ((List<HashMap<String, Object>>) fields.get(MapKey.COLLABORATORS.getName())).stream().map(map -> new Collaborator().fromElasticEntity(map)).collect(Collectors.toList());
}
if (fields.get(MapKey.ORGANIZATIONS.getName()) != null) {
this.organizations = ((List<HashMap<String, Object>>) fields.get(MapKey.ORGANIZATIONS.getName())).stream().map(map -> new Organization().fromElasticEntity(map)).collect(Collectors.toList());
}
this.lastVersion = (Boolean) fields.get(MapKey.LASTVERSION.getName());
this.lastPublicVersion = (Boolean) fields.get(MapKey.LASTPUBLICVERSION.getName());
this.isPublic = (Boolean) fields.get(MapKey.ISPUBLIC.getName());
if (fields.get(MapKey.DATASETS.getName()) != null) {
this.datasets = ((List<HashMap<String, Object>>) fields.get(MapKey.DATASETS.getName())).stream().map(map -> new Dataset().fromElasticEntity(map)).collect(Collectors.toList());
}
if (fields.containsKey(MapKey.GRANT.getName()) && fields.get(MapKey.GRANT.getName()) != null) {
this.grant = UUID.fromString((String) fields.get(MapKey.GRANT.getName()));
}
if (fields.get(MapKey.GRANTSTATUS.getName()) != null) {
this.grantStatus = Short.valueOf(fields.get(MapKey.GRANTSTATUS.getName()).toString());
}
if (fields.containsKey(MapKey.CREATED.getName())) {
this.created = Date.from(Instant.parse(fields.get(MapKey.CREATED.getName()).toString()));
}
if (fields.containsKey(MapKey.MODIFIED.getName())) {
this.modified = Date.from(Instant.parse(fields.get(MapKey.MODIFIED.getName()).toString()));
}
if (fields.get(MapKey.FINALIZEDAT.getName()) != null) {
this.finalizedAt = Date.from(Instant.parse(fields.get(MapKey.FINALIZEDAT.getName()).toString()));
}
if (fields.get(MapKey.PUBLISHEDAT.getName()) != null) {
this.publishedAt = Date.from(Instant.parse(fields.get(MapKey.PUBLISHEDAT.getName()).toString()));
}
if (fields.get(MapKey.DOIS.getName()) != null) {
this.dois = ((List<HashMap<String, Object>>) fields.get(MapKey.DOIS.getName())).stream().map(map -> new Doi().fromElasticEntity(map)).collect(Collectors.toList());
}
this.label = (String) fields.get(MapKey.LABEL.getName());
this.description = (String) fields.get(MapKey.DESCRIPTION.getName());
if (fields.get(MapKey.GROUPID.getName()) != null) {
this.groupId = UUID.fromString((String) fields.get(MapKey.GROUPID.getName()));
}
this.status = Short.valueOf(fields.get(MapKey.STATUS.getName()).toString());
if (fields.get(MapKey.TEMPLATES.getName()) != null) {
this.templates = ((List<HashMap<String, Object>>) fields.get(MapKey.TEMPLATES.getName())).stream().map(hashMap -> new DatasetTempalate().fromElasticEntity(hashMap)).collect(Collectors.toList());
}
if (fields.get(MapKey.COLLABORATORS.getName()) != null) {
this.collaborators = ((List<HashMap<String, Object>>) fields.get(MapKey.COLLABORATORS.getName())).stream().map(map -> new Collaborator().fromElasticEntity(map)).collect(Collectors.toList());
}
if (fields.get(MapKey.ORGANIZATIONS.getName()) != null) {
this.organizations = ((List<HashMap<String, Object>>) fields.get(MapKey.ORGANIZATIONS.getName())).stream().map(map -> new Organization().fromElasticEntity(map)).collect(Collectors.toList());
}
this.lastVersion = (Boolean) fields.get(MapKey.LASTVERSION.getName());
this.lastPublicVersion = (Boolean) fields.get(MapKey.LASTPUBLICVERSION.getName());
this.isPublic = (Boolean) fields.get(MapKey.ISPUBLIC.getName());
if (fields.get(MapKey.DATASETS.getName()) != null) {
this.datasets = ((List<HashMap<String, Object>>) fields.get(MapKey.DATASETS.getName())).stream().map(map -> new Dataset().fromElasticEntity(map)).collect(Collectors.toList());
}
this.grant = UUID.fromString((String) fields.get(MapKey.GRANT.getName()));
if (fields.get(MapKey.GRANTSTATUS.getName()) != null) {
this.grantStatus = Short.valueOf(fields.get(MapKey.GRANTSTATUS.getName()).toString());
}
return this;
}
@ -362,12 +282,7 @@ public class Dmp implements ElasticEntity<Dmp> {
ISPUBLIC ("isPublic"),
DATASETS ("datasets"),
GRANT ("grant"),
GRANTSTATUS ("grantStatus"),
CREATED ("created"),
MODIFIED ("modified"),
FINALIZEDAT ("finalizedAt"),
PUBLISHEDAT ("publishedAt"),
DOIS ("dois");
GRANTSTATUS ("grantStatus");
private final String name;

@ -1,65 +0,0 @@
package eu.eudat.elastic.entities;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
public class Doi implements ElasticEntity<Doi>{
private UUID id;
private String repositoryId;
private String doi;
private UUID dmp;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public UUID getDmp() {
return dmp;
}
public void setDmp(UUID dmp) {
this.dmp = dmp;
}
@Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject();
builder.field("id", this.id.toString());
builder.field("repositoryId", this.repositoryId);
builder.field("doi", this.doi);
builder.field("dmp", this.dmp.toString());
builder.endObject();
return builder;
}
@Override
public Doi fromElasticEntity(Map<String, Object> fields) {
if (fields == null || fields.isEmpty()) {
return null;
}
this.id = UUID.fromString((String) fields.get("id"));
this.repositoryId = (String) fields.get("repositoryId");
this.doi = (String) fields.get("doi");
this.dmp = UUID.fromString((String) fields.get("dmp"));
return this;
}
}

@ -13,14 +13,6 @@ public class Tag implements ElasticEntity {
private String id;
private String name;
public Tag() {
}
public Tag(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}

@ -24,13 +24,8 @@ import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilters;
import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.io.IOException;
@ -42,12 +37,10 @@ import java.util.stream.Stream;
public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteria> {
private final DmpRepository dmpRepository;
private final Environment environment;
public DatasetRepository(RestHighLevelClient client, DmpRepository dmpRepository, Environment environment) {
public DatasetRepository(RestHighLevelClient client, DmpRepository dmpRepository) {
super(client);
this.dmpRepository = dmpRepository;
this.environment = environment;
}
@Override
@ -55,26 +48,24 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
if (this.getClient() != null) {
XContentBuilder builder = XContentFactory.jsonBuilder();
Dmp dmp = this.dmpRepository.findDocument(entity.getDmp().toString());
if (dmp != null) {
boolean found = false;
if (dmp.getDatasets() != null && !dmp.getDatasets().isEmpty()) {
for (int i = 0; i < dmp.getDatasets().size(); i++) {
if (dmp.getDatasets().get(i).getId().equals(entity.getId())) {
dmp.getDatasets().set(i, entity);
found = true;
break;
}
boolean found = false;
if (dmp.getDatasets() != null && !dmp.getDatasets().isEmpty()) {
for (int i = 0; i < dmp.getDatasets().size(); i++) {
if (dmp.getDatasets().get(i).getId().equals(entity.getId())) {
dmp.getDatasets().set(i, entity);
found = true;
break;
}
}
if (!found) {
if (dmp.getDatasets() == null) {
dmp.setDatasets(new ArrayList<>());
}
dmp.getDatasets().add(entity);
}
if (!found) {
if (dmp.getDatasets() == null) {
dmp.setDatasets(new ArrayList<>());
}
IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(dmp.getId().toString()).source(dmp.toElasticEntity(builder));//new IndexRequest("datasets", "doc", entity.getId()).source(entity.toElasticEntity(builder));
this.getClient().index(request, RequestOptions.DEFAULT);
dmp.getDatasets().add(entity);
}
IndexRequest request = new IndexRequest("dmps").id(dmp.getId().toString()).source(dmp.toElasticEntity(builder));//new IndexRequest("datasets", "doc", entity.getId()).source(entity.toElasticEntity(builder));
this.getClient().index(request, RequestOptions.DEFAULT);
return entity;
}
return null;
@ -83,7 +74,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
@Override
public Dataset findDocument(String id) throws IOException {
if (this.getClient() != null) {
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
SearchRequest searchRequest = new SearchRequest("dmps");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().should(QueryBuilders.termQuery("datasets.id.keyword", id));
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery( "datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder());
@ -104,7 +95,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
@Override
public List<Dataset> query(DatasetCriteria criteria) throws IOException {
if (this.getClient() != null) {
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
SearchRequest searchRequest = new SearchRequest("dmps");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
/*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
@ -112,7 +103,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
Long count = countResponse.getCount();*/
SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
SearchRequest countRequest = new SearchRequest("dmps");
NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
@ -125,209 +116,84 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
searchSourceBuilder.size(count.intValue());
List<SortBuilder> sortBuilders = new ArrayList<>();
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
criteria.getSortCriteria().forEach(sortCriteria -> {
switch(sortCriteria.getColumnType()) {
case COLUMN:
sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
break;
case JOIN_COLUMN:
List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
fields.stream().filter(name -> !name.startsWith("dmp")).forEach(field -> {
sortBuilders.add(SortBuilders.fieldSort(field).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
});
break;
}
});
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList())));
if (criteria.isPublic()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.public", "true"));
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.status", Dataset.Status.FINALISED.getValue()));
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.lastPublicVersion", "true"));
}
if (criteria.getLike() != null && !criteria.getLike().isEmpty()) {
boolQuery = boolQuery.should(QueryBuilders.queryStringQuery(criteria.getLike()).allowLeadingWildcard(true).fields(Stream.of(new Object[][]{
{"datasets.label", 1.0f},
{"datasets.description", 1.0f},
{"datasets.formData", 1.0f}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Float) data[1]))));
}
if (criteria.getDatasetTemplates() != null && criteria.getDatasetTemplates().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.template", criteria.getDatasetTemplates().stream().map(UUID::toString).collect(Collectors.toList())));
}
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.tags"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset())*/.fetchSource("datasets.tags", null);
/*if (criteria.getSize() > 0) {
searchSourceBuilder.size(criteria.getSize());
}*/
sortBuilders.forEach(searchSourceBuilder::sort);
searchRequest.source(searchSourceBuilder);
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
.map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
.map(SearchHits::getHits).flatMap(Arrays::stream)
.map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
}
return null;
}
if (criteria.getStatus() != null) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.status", criteria.getStatus().toString()));
}
public List<Dataset> queryIds(DatasetCriteria criteria) throws IOException {
if (this.getClient() != null) {
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
if (criteria.getDmps() != null && criteria.getDmps().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.dmp", criteria.getDmps().stream().map(UUID::toString).collect(Collectors.toList())));
}
/*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
Long count = countResponse.getCount();*/
if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.group", criteria.getGroupIds().stream().map(UUID::toString).collect(Collectors.toList())));
}
SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
countSourceBuilder.aggregation(nestedAggregationBuilder);
countRequest.source(countSourceBuilder);
SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
Long count = ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
if (criteria.getGrants() != null && criteria.getGrants().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.grant", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGrantStatus() != null) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.grantStatus", criteria.getGrantStatus().toString()));
}
searchSourceBuilder.size(count.intValue());
if (criteria.getCollaborators() != null && criteria.getCollaborators().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.collaborators.id", criteria.getCollaborators().stream().map(UUID::toString).collect(Collectors.toList())));
}
List<SortBuilder> sortBuilders = new ArrayList<>();
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
if (!criteria.isPublic()) {
if (criteria.getAllowAllVersions() != null && !criteria.getAllowAllVersions()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.lastVersion", "true"));
}
}
if (criteria.getOrganiztions() != null && criteria.getOrganiztions().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.organizations.id", criteria.getOrganiztions()));
}
if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
criteria.getSortCriteria().forEach(sortCriteria -> {
switch(sortCriteria.getColumnType()) {
case COLUMN:
sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
break;
case JOIN_COLUMN:
List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
fields.stream().filter(name -> !name.startsWith("dmp")).forEach(field -> {
sortBuilders.add(SortBuilders.fieldSort(field).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
});
break;
}
});
if (criteria.getTags() != null && criteria.getTags().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.tags.name", criteria.getTags().stream().map(Tag::getName).collect(Collectors.toList())));
}
if (boolQuery.should().isEmpty() && boolQuery.mustNot().isEmpty()) {
boolQuery.should(QueryBuilders.matchAllQuery());
} else {
boolQuery.minimumShouldMatch(boolQuery.should().size());
}
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.id"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset()).size(criteria.getSize())*/.fetchSource("datasets.id", null);
sortBuilders.forEach(searchSourceBuilder::sort);
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder());
searchSourceBuilder.query(nestedQueryBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
.map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
.map(SearchHits::getHits).flatMap(Arrays::stream)
.map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
}
return null;
}
@Override
public Long count(DatasetCriteria criteria) throws IOException {
if (this.getClient() != null) {
//CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", boolQuery);
nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
countSourceBuilder.aggregation(nestedAggregationBuilder);
countRequest.source(countSourceBuilder);
SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
return ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
/*NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder());
countRequest.query(nestedQueryBuilder);
CountResponse response = this.getClient().count(countRequest, RequestOptions.DEFAULT);
return response.getCount();*/
.map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
.map(SearchHits::getHits).flatMap(Arrays::stream)
.map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
}
return null;
}
private BoolQueryBuilder createBoolQuery(DatasetCriteria criteria) {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList())));
if (criteria.isPublic()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.public", "true"));
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.status", Dataset.Status.FINALISED.getValue()));
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.lastPublicVersion", "true"));
}
if (criteria.getLike() != null && !criteria.getLike().isEmpty()) {
boolQuery = boolQuery.should(QueryBuilders.queryStringQuery(criteria.getLike()).allowLeadingWildcard(true).fields(Stream.of(new Object[][]{
{"datasets.label", 1.0f},
{"datasets.description", 1.0f},
{"datasets.formData", 1.0f}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Float) data[1]))));
}
if (criteria.getDatasetTemplates() != null && criteria.getDatasetTemplates().size() > 0) {
criteria.setDatasetTemplates(criteria.getDatasetTemplates().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.template", criteria.getDatasetTemplates().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getStatus() != null) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.status", criteria.getStatus().toString()));
}
if (criteria.getDmps() != null && criteria.getDmps().size() > 0) {
criteria.setDmps(criteria.getDmps().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.dmp", criteria.getDmps().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
criteria.setGroupIds(criteria.getGroupIds().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.group", criteria.getGroupIds().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGrants() != null && criteria.getGrants().size() > 0) {
criteria.setGrants(criteria.getGrants().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.grant", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGrantStatus() != null) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.grantStatus", criteria.getGrantStatus().toString()));
}
if (criteria.getCollaborators() != null && criteria.getCollaborators().size() > 0) {
criteria.setCollaborators(criteria.getCollaborators().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.collaborators.id.keyword", criteria.getCollaborators().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (!criteria.isPublic()) {
if (criteria.getAllowAllVersions() != null && !criteria.getAllowAllVersions()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.lastVersion", "true"));
}
}
if (criteria.getOrganiztions() != null && criteria.getOrganiztions().size() > 0) {
criteria.setOrganiztions(criteria.getOrganiztions().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.organizations.id", criteria.getOrganiztions()));
}
if (criteria.getTags() != null && criteria.getTags().size() > 0) {
criteria.setTags(criteria.getTags().stream().filter(Objects::nonNull).collect(Collectors.toList()));
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.tags.name", criteria.getTags().stream().map(Tag::getName).collect(Collectors.toList())));
}
if (criteria.getHasTags() != null) {
boolQuery = criteria.getHasTags() == true ? boolQuery.should(QueryBuilders.existsQuery("datasets.tags.id")) : boolQuery.mustNot(QueryBuilders.existsQuery("datasets.tags.id"));
}
if (boolQuery.should().isEmpty() && boolQuery.mustNot().isEmpty()) {
boolQuery.should(QueryBuilders.matchAllQuery());
} else {
boolQuery.minimumShouldMatch(boolQuery.should().size());
}
return boolQuery;
}
@Override
public boolean exists() throws IOException {
if (this.getClient() != null) {
GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
GetIndexRequest request = new GetIndexRequest("dmps");
// request.indices("datasets");
return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
}

@ -23,13 +23,9 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.io.IOException;
@ -41,12 +37,9 @@ import java.util.stream.Stream;
public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
private static final Logger logger = LoggerFactory.getLogger(DmpRepository.class);
private final Environment environment;
@Autowired
public DmpRepository(RestHighLevelClient client, Environment environment) {
public DmpRepository(RestHighLevelClient client) {
super(client);
this.environment = environment;
}
private void generateMapping() throws IOException {
@ -59,7 +52,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
builder.endObject();
builder.endObject();
builder.endObject();
PutMappingRequest putMappingRequest = new PutMappingRequest(this.environment.getProperty("elasticsearch.index"));
PutMappingRequest putMappingRequest = new PutMappingRequest("dmps");
putMappingRequest.source(builder);
this.getClient().indices().putMapping(putMappingRequest, RequestOptions.DEFAULT);
}
@ -69,7 +62,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
public Dmp createOrUpdate(Dmp entity) throws IOException {
if (this.getClient() != null) {
XContentBuilder builder = XContentFactory.jsonBuilder();
IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(entity.getId().toString()).source(entity.toElasticEntity(builder));
IndexRequest request = new IndexRequest("dmps").id(entity.getId().toString()).source(entity.toElasticEntity(builder));
IndexResponse response = this.getClient().index(request, RequestOptions.DEFAULT);
return entity;
}
@ -79,7 +72,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
@Override
public Dmp findDocument(String id) throws IOException {
if (this.getClient() != null) {
GetRequest request = new GetRequest(this.environment.getProperty("elasticsearch.index"), id);
GetRequest request = new GetRequest("dmps", id);
GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT);
return new Dmp().fromElasticEntity(response.getSourceAsMap());
}
@ -89,118 +82,77 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
@Override
public List<Dmp> query(DmpCriteria criteria) throws IOException {
if (this.getClient() != null) {
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
SearchRequest searchRequest = new SearchRequest("dmps");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
CountRequest countRequest = new CountRequest("dmps");
countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue()))));
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
Long count = countResponse.getCount();
searchSourceBuilder.size(count.intValue());
List<SortBuilder> sortBuilders = new ArrayList<>();
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
criteria.getSortCriteria().forEach(sortCriteria -> {
switch(sortCriteria.getColumnType()) {
case COLUMN:
sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
break;
case JOIN_COLUMN:
List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
fields.forEach(field -> {
sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
});
break;
}
});
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue())));
if (criteria.isPublic()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.ISPUBLIC.getName(), true));
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.STATUS.getName(), Dmp.DMPStatus.FINALISED.getValue()));
}
searchSourceBuilder.query(boolQuery).from(criteria.getOffset()).fetchSource("id", null);
if (criteria.getSize() != null && criteria.getSize() > 0) {
searchSourceBuilder.size(criteria.getSize());
if (criteria.getLike() != null && !criteria.getLike().isEmpty()) {
boolQuery = boolQuery.should(QueryBuilders.queryStringQuery(criteria.getLike()).fields(Stream.of(new Object[][]{
{Dmp.MapKey.LABEL.getName(), 1.0f},
{Dmp.MapKey.DESCRIPTION.getName(), 1.0f}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Float) data[1]))));
}
sortBuilders.forEach(searchSourceBuilder::sort);
searchRequest.source(searchSourceBuilder);
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
return Arrays.stream(response.getHits().getHits()).map(x -> new Dmp().fromElasticEntity((Map<String, Object>) this.transformFromString(x.getSourceAsString(), Map.class))).collect(Collectors.toList());
}
return null;
}
@Override
public Long count(DmpCriteria criteria) throws IOException {
if (this.getClient() != null) {
CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
countRequest.query(boolQuery);
CountResponse response = this.getClient().count(countRequest, RequestOptions.DEFAULT);
return response.getCount();
}
return null;
}
private BoolQueryBuilder createBoolQuery(DmpCriteria criteria) {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue())));
if (criteria.isPublic()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.ISPUBLIC.getName(), true));
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.STATUS.getName(), Dmp.DMPStatus.FINALISED.getValue()));
}
if (criteria.getLike() != null && !criteria.getLike().isEmpty()) {
boolQuery = boolQuery.should(QueryBuilders.queryStringQuery(criteria.getLike()).fields(Stream.of(new Object[][]{
{Dmp.MapKey.LABEL.getName(), 1.0f},
{Dmp.MapKey.DESCRIPTION.getName(), 1.0f}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Float) data[1]))));
}
if (criteria.getTemplates() != null && criteria.getTemplates().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.TEMPLATES.getName() + ".id.keyword", criteria.getTemplates().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getTemplates() != null && criteria.getTemplates().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.TEMPLATES.getName() + ".id.keyword", criteria.getTemplates().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getStatus() != null) {
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.STATUS.getName(), criteria.getStatus().intValue()));
}
if (criteria.getStatus() != null) {
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.STATUS.getName(), criteria.getStatus().intValue()));
}
if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.GROUPID.getName(), criteria.getGroupIds().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGroupIds() != null && criteria.getGroupIds().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.GROUPID.getName(), criteria.getGroupIds().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGrants() != null && criteria.getGrants().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.GRANT.getName() + ".keyword", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGrants() != null && criteria.getGrants().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.GRANT.getName() + ".keyword", criteria.getGrants().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getCollaborators() != null && criteria.getCollaborators().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.COLLABORATORS.getName() + ".id.keyword", criteria.getCollaborators().stream().filter(Objects::nonNull).map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getCollaborators() != null && criteria.getCollaborators().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.COLLABORATORS.getName() + ".keyword", criteria.getCollaborators().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (!criteria.isAllowAllVersions()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery(criteria.isPublic() ? Dmp.MapKey.LASTPUBLICVERSION.getName() : Dmp.MapKey.LASTVERSION.getName(), true));
}
if (!criteria.isAllowAllVersions()) {
boolQuery = boolQuery.should(QueryBuilders.termQuery(criteria.isPublic() ? Dmp.MapKey.LASTPUBLICVERSION.getName() : Dmp.MapKey.LASTVERSION.getName(), true));
}
if (criteria.getOrganizations() != null && criteria.getOrganizations().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.ORGANIZATIONS.getName() + ".id.keyword", criteria.getOrganizations().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getOrganizations() != null && criteria.getOrganizations().size() > 0) {
boolQuery = boolQuery.should(QueryBuilders.termsQuery(Dmp.MapKey.ORGANIZATIONS.getName() + ".id.keyword", criteria.getOrganizations().stream().map(UUID::toString).collect(Collectors.toList())));
}
if (criteria.getGrantStatus() != null) {
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.GRANTSTATUS.getName(), criteria.getGrantStatus()));
}
if (criteria.getGrantStatus() != null) {
boolQuery = boolQuery.should(QueryBuilders.termQuery(Dmp.MapKey.GRANTSTATUS.getName(), criteria.getGrantStatus()));
}
if (boolQuery.should().isEmpty() && boolQuery.mustNot().isEmpty()) {
boolQuery = boolQuery.should(QueryBuilders.matchAllQuery());
} else {
boolQuery.minimumShouldMatch(boolQuery.should().size());
if (boolQuery.should().isEmpty() && boolQuery.mustNot().isEmpty()) {
boolQuery = boolQuery.should(QueryBuilders.matchAllQuery());
} else {
boolQuery.minimumShouldMatch(boolQuery.should().size());
}
searchSourceBuilder.query(boolQuery);
searchRequest.source(searchSourceBuilder);
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
return Arrays.stream(response.getHits().getHits()).map(x -> new Dmp().fromElasticEntity((Map<String, Object>) this.transformFromString(x.getSourceAsString(), Map.class))).collect(Collectors.toList());
}
return boolQuery;
return null;
}
public boolean createIndex() {
try {
if (!this.exists()) {
CreateIndexRequest createIndexRequest = new CreateIndexRequest(this.environment.getProperty("elasticsearch.index"));
CreateIndexRequest createIndexRequest = new CreateIndexRequest("dmps");
this.getClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
this.generateMapping();
}
@ -214,7 +166,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
@Override
public boolean exists() throws IOException {
if (this.getClient() != null) {
GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
GetIndexRequest request = new GetIndexRequest("dmps");
return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
}
return false;
@ -223,10 +175,10 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
@Override
public void clear() throws IOException {
if (exists()) {
DeleteByQueryRequest delete = new DeleteByQueryRequest(this.environment.getProperty("elasticsearch.index"));
DeleteByQueryRequest delete = new DeleteByQueryRequest("dmps");
delete.setQuery(QueryBuilders.matchAllQuery());
this.getClient().deleteByQuery(delete, RequestOptions.DEFAULT);
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(this.environment.getProperty("elasticsearch.index"));
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("dmps");
this.getClient().indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
}
}

@ -30,7 +30,6 @@ public abstract class ElasticRepository<T extends ElasticEntity,C extends Criter
}
} catch (IOException e) {
logger.warn("Unable to connect to Elastic Services");
logger.error(e.getMessage(), e);
this.client = null;
}
}

@ -18,8 +18,6 @@ public interface Repository<ET extends ElasticEntity, C extends Criteria> {
List<ET> query(C criteria) throws ExecutionException, InterruptedException, IOException;
Long count(C criteria) throws ExecutionException, InterruptedException, IOException;
boolean exists() throws IOException;
void clear() throws IOException;

@ -10,7 +10,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<version>1.5.9.RELEASE</version>
</parent>
<modules>
@ -27,27 +27,25 @@
<java.version>1.8</java.version>
<dmp-backend-commons.version>0.0.1-SNAPSHOT</dmp-backend-commons.version>
<org.springframework.version>5.3.8</org.springframework.version>
<org.springframework.version>4.3.8.RELEASE</org.springframework.version>
<!-- <org.springframeweu.eudat.logic.securityrity.version>3.2.10.RELEASE</org.springframeweu.eudat.logic.securityrity.version> -->
<org.springframework.security.version>5.3.10.RELEASE</org.springframework.security.version>
<!--<com.sun.jersey.version>1.19.1</com.sun.jersey.version>-->
<!--
<org.springframework.security.version>4.2.3.RELEASE</org.springframework.security.version>
<com.sun.jersey.version>1.19.1</com.sun.jersey.version>
<org.apache.tomcat.tomcat-jdbc.version>7.0.35</org.apache.tomcat.tomcat-jdbc.version>
-->
<!--<com.fasterxml.jackson>2.9.0</com.fasterxml.jackson>-->
<com.fasterxml.jackson>2.8.4</com.fasterxml.jackson>
<hibernate.version>5.5.3.Final</hibernate.version>
<hibernate.version>5.2.11.Final</hibernate.version>
<commons-codec.version>1.9</commons-codec.version>
<org.junit.version>4.11</org.junit.version>
<log4j.version>1.2.17</log4j.version>
<log4j2.version>2.15.0</log4j2.version>
<slf4j.version>1.7.15</slf4j.version>
<!--<jetty.version>11.0.5
</jetty.version>--> <!-- Adapt this to a version found on http://repo.maven.apache.org/maven2/org/eclipse/jetty/jetty-maven-plugin/ -->
<slf4j.version>1.7.12</slf4j.version>
<jetty.version>9.0.7.v20131107
</jetty.version> <!-- Adapt this to a version found on http://repo.maven.apache.org/maven2/org/eclipse/jetty/jetty-maven-plugin/ -->
<logback.version>1.2.3</logback.version>
<!-- <javax.inject.version>1</javax.inject.version>-->
<!--<javax.servlet.servlet-api.version>3.0.1</javax.servlet.servlet-api.version>-->
<javax.inject.version>1</javax.inject.version>
<javax.servlet.servlet-api.version>3.0.1</javax.servlet.servlet-api.version>
<docker.image.prefix>ikalyvas</docker.image.prefix>
</properties>
<dependencies>
@ -60,7 +58,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework.version}</version>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -71,39 +69,7 @@
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.7.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.12</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.4.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
<version>7.6.0</version>
</dependency>
<dependency>
@ -141,7 +107,7 @@
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.12.3</version>
<version>2.9.3</version>
</dependency>
@ -149,13 +115,13 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.3</version>
<version>2.9.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackeu.eudat.corecore/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
<version>2.9.4</version>
</dependency>
<!-- g/a spring -->
@ -173,13 +139,13 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
<version>4.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->
@ -188,12 +154,6 @@
<artifactId>fop</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/fr.opensagres.xdocreport/org.apache.poi.xwpf.converter.pdf -->
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
@ -219,10 +179,10 @@
<version>2.1</version>
</dependency>
<!--<dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>-->
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
@ -230,90 +190,11 @@
<version>7.6.0</version>
</dependency>
<!--<dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.8.2</version>
</dependency>-->
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-core -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!-- The client -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.11.0</version>
</dependency>
<!-- Hotspot JVM metrics-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.11.0</version>
</dependency>
<!-- Exposition HTTPServer-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.11.0</version>
</dependency>
<!-- Pushgateway exposition-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Micormeter core dependecy -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
</dependencies>
@ -327,18 +208,6 @@
<packaging.type>jar</packaging.type>
</properties>
</profile>
<profile>
<id>intellij-properties-launcher</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-loader</artifactId>
<version>2.5.2</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>production</id>
<properties>

@ -4,8 +4,8 @@ import eu.eudat.queryable.jpa.predicates.*;
import eu.eudat.queryable.queryableentity.DataEntity;
import eu.eudat.queryable.types.SelectionField;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Subquery;
import java.util.List;
import java.util.Map;
@ -44,8 +44,6 @@ public interface QueryableList<T extends DataEntity> {
QueryableList<T> orderBy(OrderByPredicate<T> predicate);
QueryableList<T> groupBy(GroupByPredicate<T> predicate);
QueryableList<T> withHint(String hint);
Long count();
@ -69,8 +67,4 @@ public interface QueryableList<T extends DataEntity> {
<U extends Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass);
<U extends Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass);
Join getJoin(String field, JoinType type);
}

@ -1,9 +1,6 @@
package eu.eudat.queryable.collector;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.persistence.Tuple;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -12,13 +9,9 @@ import java.util.stream.Collectors;
public class Collector {
public List<Map> buildFromTuple(List<Tuple> results, Map<Object, List<Tuple>> groupedResults, List<String> fields, String key) {
return results.stream().map(tuple -> {
Map<String, Object> parsedResult = new HashMap<>();
tuple.getElements().forEach(tupleElement -> parsedResult.put(tupleElement.getAlias(), tuple.get(tupleElement.getAlias())));
return parsedResult;
}).collect(Collectors.toList());/*groupedResults.keySet().stream()
return groupedResults.keySet().stream()
.map(x -> buildOne(groupedResults.get(x), fields, key))
.collect(Collectors.toList());*/
.collect(Collectors.toList());
}
private Map buildOne(List<Tuple> tuples, List<String> fields, String key) {

@ -1,6 +1,5 @@
package eu.eudat.queryable.jpa.hibernatequeryablelist;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.collector.Collector;
import eu.eudat.queryable.exceptions.NotSingleResultException;
@ -34,7 +33,6 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
private List<NestedQuerySinglePredicate<T>> nestedPredicates = new LinkedList<>();
private boolean distinct = false;
private List<OrderByPredicate<T>> orderings = new LinkedList<>();
private List<GroupByPredicate<T>> groupings = new LinkedList<>();
private List<String> fields = new LinkedList<>();
private Integer length;
private Integer offset;
@ -64,7 +62,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
}
private QueryableList<T> selectFields() {
List<Selection> rootFields = fields.stream().map(this::convertFieldToPath).filter(Objects::nonNull).collect(Collectors.toList());
List<Selection> rootFields = fields.stream().map(field -> this.convertFieldToPath(field)).filter(x -> x != null).collect(Collectors.toList());
this.query.select(this.manager.getCriteriaBuilder().tuple(rootFields.toArray(new Selection[rootFields.size()])));
return this;
}
@ -95,7 +93,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
return join;
}
public Join getJoin(String field, JoinType type) {
private Join getJoin(String field, JoinType type) {
if (this.joinsMap.containsKey(field)) return this.joinsMap.get(field);
Join join = this.root.join(field, type);
this.joinsMap.put(field, join);
@ -135,11 +133,11 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
}
public <R> List<R> select(SelectPredicate<T, R> predicate) {
return this.toList().stream().map(predicate::applySelection).collect(Collectors.toList());
return this.toList().stream().map(item -> predicate.applySelection(item)).collect(Collectors.toList());
}
public <R> CompletableFuture<List<R>> selectAsync(SelectPredicate<T, R> predicate) {
return this.toListAsync().thenApplyAsync(items -> items.stream().map(predicate::applySelection).collect(Collectors.toList()));
return this.toListAsync().thenApplyAsync(items -> items.stream().map(item -> predicate.applySelection(item)).collect(Collectors.toList()));
}
public QueryableList<T> distinct() {
@ -152,11 +150,6 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
return this;
}
public QueryableList<T> groupBy(GroupByPredicate<T> predicate) {
this.groupings.add(predicate);
return this;
}
public Long count() {
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
@ -164,16 +157,8 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
if (distinct) criteriaQuery.select(criteriaBuilder.countDistinct(this.root.get("id")));
else criteriaQuery.select(criteriaBuilder.count(this.root));
criteriaQuery.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
if (!this.groupings.isEmpty()) criteriaQuery.groupBy(this.generateGroupPredicates(this.groupings, this.root));
//if (distinct) criteriaQuery.distinct(true);
//GK: Group By special case. When group by is used, since it will result in a list of how many elements have the grouped field common
// then it will instead return the number of the distinct values of the grouped field
if (this.groupings.isEmpty()) {
return this.manager.createQuery(criteriaQuery).getSingleResult();
} else {
return (long) this.manager.createQuery(criteriaQuery).getResultList().size();
}
return this.manager.createQuery(criteriaQuery).getSingleResult();
}
@Async
@ -184,15 +169,8 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
if (distinct) criteriaQuery.select(criteriaBuilder.countDistinct(this.root.get("id")));
else criteriaQuery.select(criteriaBuilder.count(this.root));
criteriaQuery.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
if (!this.groupings.isEmpty()) criteriaQuery.groupBy(this.generateGroupPredicates(this.groupings, this.root));
//if (distinct) criteriaQuery.distinct(true);
return CompletableFuture.supplyAsync(() -> {
if (this.groupings.isEmpty()) {
return this.manager.createQuery(criteriaQuery).getSingleResult();
} else {
return (long) this.manager.createQuery(criteriaQuery).getResultList().size();
}
});
return CompletableFuture.supplyAsync(() -> this.manager.createQuery(criteriaQuery).getSingleResult());
}
@ -227,14 +205,6 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
return predicates.toArray(new Order[predicates.size()]);
}
private Expression[] generateGroupPredicates(List<GroupByPredicate<T>> groupByPredicates, Root<T> root) {
List<Expression> predicates = new LinkedList<>();
for (GroupByPredicate<T> groupPredicate : groupByPredicates) {
predicates.add(groupPredicate.applyPredicate(this.manager.getCriteriaBuilder(), root));
}
return predicates.toArray(new Expression[predicates.size()]);
}
public List<T> toList() {
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
if (!this.fields.isEmpty()) this.query = builder.createTupleQuery();
@ -242,20 +212,22 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
this.root = this.query.from(this.tClass);
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
if (!this.groupings.isEmpty()) this.query.groupBy(this.generateGroupPredicates(this.groupings, this.root));
if (!this.fields.isEmpty()) this.selectFields();
if (distinct) this.query.distinct(true);
//if (!this.fields.isEmpty()) this.query.multiselect(this.parseFields(this.fields));
ObjectMapper mapper = new ObjectMapper();
if (!this.fields.isEmpty()) return this.toListWithFields().stream().map(m -> mapper.convertValue(m, this.tClass)).collect(Collectors.toList());
//if (!this.fields.isEmpty()) return this.toListWithFields();
return this.toListWithOutFields();
}
public List<Map> toListWithFields() {
TypedQuery<Tuple> typedQuery = this.manager.createQuery(this.query);
if (this.offset != null) typedQuery.setFirstResult(this.offset);
if (this.length != null) typedQuery.setMaxResults(this.length);
List<Tuple> results = typedQuery.getResultList();
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
if (!this.fields.isEmpty()) this.query = builder.createTupleQuery();
else this.query = builder.createQuery(this.tClass);
this.root = this.query.from(this.tClass);
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
if (!this.fields.isEmpty()) this.selectFields();
if (distinct) this.query.distinct(true);
List<Tuple> results = this.manager.createQuery(query).getResultList();
Map<Object, List<Tuple>> groupedResults = results.stream()
.collect(Collectors.groupingBy(x -> x.get("id")));
return this.collector.buildFromTuple(results, groupedResults, this.fields, "id");
@ -280,7 +252,6 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
this.root = this.query.from(this.tClass);
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
if (!this.groupings.isEmpty()) this.query.groupBy(this.generateGroupPredicates(this.groupings, this.root));
if (!this.fields.isEmpty()) this.selectFields();
if (distinct) this.query.distinct(true);
if (!this.fields.isEmpty()) return this.toListAsyncWithFields();
@ -385,8 +356,6 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
if (!this.orderings.isEmpty())
criteriaQuery.orderBy(this.generateOrderPredicates(this.orderings, criteriaRoot));
if (!this.groupings.isEmpty()) criteriaQuery.groupBy(this.generateGroupPredicates(this.groupings, this.root));
TypedQuery<T> typedQuery = this.manager.createQuery(criteriaQuery);
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
return typedQuery;
@ -497,11 +466,4 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
.createQuery(update)
.executeUpdate();
}
private Path[] parseFields(List<String> selectedFields) {
List<Path> paths = new ArrayList<>();
selectedFields.forEach(s -> paths.add(root.get(s)));
return paths.toArray(new Path[0]);
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save