Commit d8cbb365 authored by LAVENIER's avatar LAVENIER
Browse files

[enh] Root data (e.g. Trip) : add data quality status, to root data filter

parent 72299da3
......@@ -124,7 +124,7 @@
<ehcache.version>3.8.1</ehcache.version>
<ehcache-monitor.version>2.7.11</ehcache-monitor.version>
<lombok.version>1.18.20</lombok.version>
<xmlquery.version>1.2</xmlquery.version>
<xmlquery.version>1.4</xmlquery.version>
<jdom2.version>2.0.6</jdom2.version>
<jaxen.version>1.2.0</jaxen.version>
<spring-boot.version>2.4.5</spring-boot.version>
......
......@@ -74,4 +74,21 @@ public interface DataSpecifications<E extends IDataEntity<? extends Serializable
.addBind(RECORDER_DEPARTMENT_ID_PARAM, recorderDepartmentId);
}
/**
* Control date is null
* @return
*/
default Specification<E> isNotControlled() {
return (root, query, criteriaBuilder) ->
criteriaBuilder.isNull(root.get(IDataEntity.Fields.CONTROL_DATE));
}
/**
* Control date is not null
* @return
*/
default Specification<E> isControlled() {
return (root, query, criteriaBuilder) ->
criteriaBuilder.isNotNull(root.get(IDataEntity.Fields.CONTROL_DATE));
}
}
......@@ -24,15 +24,19 @@ package net.sumaris.core.dao.data;
import net.sumaris.core.dao.technical.jpa.BindableSpecification;
import net.sumaris.core.dao.technical.model.IEntity;
import net.sumaris.core.model.data.DataQualityStatusEnum;
import net.sumaris.core.model.data.IRootDataEntity;
import net.sumaris.core.model.referential.IItemReferentialEntity;
import net.sumaris.core.model.referential.QualityFlag;
import net.sumaris.core.model.referential.QualityFlagEnum;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.data.jpa.domain.Specification;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
/**
* @author peck7 on 28/08/2020.
......@@ -67,4 +71,48 @@ public interface RootDataSpecifications<E extends IRootDataEntity<? extends Seri
return specification;
}
default Specification<E> inDataQualityStatus(DataQualityStatusEnum... dataQualityStatus) {
if (ArrayUtils.isEmpty(dataQualityStatus)) return null;
if (dataQualityStatus.length == 1) {
return withDataQualityStatus(dataQualityStatus[0]);
}
return (root, query, criteriaBuilder) -> criteriaBuilder.or(
Arrays.stream(dataQualityStatus)
.map(this::withDataQualityStatus)
.filter(Objects::nonNull)
.toArray(Predicate[]::new)
);
}
default Specification<E> withDataQualityStatus(DataQualityStatusEnum status) {
if (status != null) {
switch (status) {
case DRAFT:
return isNotControlled();
case CONTROLLED:
return isControlled();
case VALIDATED:
return isValidated();
case QUALIFIED:
return isQualified();
}
}
return null;
}
default Specification<E> isValidated() {
return (root, query, criteriaBuilder) ->
// Validation date not null
criteriaBuilder.isNotNull(root.get(IRootDataEntity.Fields.VALIDATION_DATE));
}
default Specification<E> isQualified() {
return (root, query, criteriaBuilder) -> criteriaBuilder.and(
// Qualification date not null
criteriaBuilder.isNotNull(root.get(IRootDataEntity.Fields.QUALIFICATION_DATE)),
// Quality flag != 0
criteriaBuilder.notEqual(criteriaBuilder.coalesce(root.get(IRootDataEntity.Fields.QUALITY_FLAG).get(QualityFlag.Fields.ID), QualityFlagEnum.NOT_QUALIFIED.getId()), QualityFlagEnum.NOT_QUALIFIED.getId())
);
}
}
......@@ -60,7 +60,9 @@ public class TripRepositoryImpl
.and(id(filter.getTripId()))
.and(betweenDate(filter.getStartDate(), filter.getEndDate()))
.and(hasLocationId(filter.getLocationId()))
.and(hasVesselId(filter.getVesselId()));
.and(hasVesselId(filter.getVesselId()))
.and(excludedIds(filter.getExcludedIds()))
.and(inDataQualityStatus(filter.getDataQualityStatus()));
}
@Override
......
/*
* #%L
* SUMARiS
* %%
* Copyright (C) 2019 SUMARiS Consortium
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package net.sumaris.core.model.data;
import java.io.Serializable;
public enum DataQualityStatusEnum implements Serializable {
DRAFT,
CONTROLLED,
VALIDATED,
QUALIFIED
}
......@@ -27,9 +27,11 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;
import net.sumaris.core.model.data.DataQualityStatusEnum;
import javax.annotation.Nullable;
import java.util.Date;
import java.util.List;
@Data
@Builder
......@@ -57,4 +59,8 @@ public class TripFilterVO implements IRootDataFilter, IVesselFilter {
private Integer locationId;
private Integer tripId;
private Integer[] excludedIds;
private DataQualityStatusEnum[] dataQualityStatus;
}
......@@ -22,8 +22,10 @@ package net.sumaris.core.service.data;
* #L%
*/
import com.google.common.collect.ImmutableList;
import net.sumaris.core.dao.DatabaseResource;
import net.sumaris.core.dao.technical.Page;
import net.sumaris.core.model.data.DataQualityStatusEnum;
import net.sumaris.core.service.AbstractServiceTest;
import net.sumaris.core.util.Beans;
import net.sumaris.core.util.Dates;
......@@ -119,6 +121,29 @@ public class TripServiceReadTest extends AbstractServiceTest{
2);
}
@Test
public void findTripsByQualityStatus() {
assertFindAll(TripFilterVO.builder()
.dataQualityStatus(new DataQualityStatusEnum[]{DataQualityStatusEnum.DRAFT})
.build(),
2);
assertFindAll(TripFilterVO.builder()
.dataQualityStatus(new DataQualityStatusEnum[]{DataQualityStatusEnum.CONTROLLED})
.build(),
1);
assertFindAll(TripFilterVO.builder()
.dataQualityStatus(new DataQualityStatusEnum[]{DataQualityStatusEnum.VALIDATED})
.build(),
0);
assertFindAll(TripFilterVO.builder()
.dataQualityStatus(new DataQualityStatusEnum[]{DataQualityStatusEnum.QUALIFIED})
.build(),
0);
}
@Test
public void getFullGraph() {
......
......@@ -18,7 +18,7 @@ spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
spring.datasource.username=sa
spring.datasource.password=
# For DEV ONLY:
spring.datasource.url=jdbc:hsqldb:hsql://localhost/sumaris
#spring.datasource.url=jdbc:hsqldb:hsql://localhost/sumaris
spring.datasource.platform=hsqldb
spring.datasource.initialization-mode=always
......
......@@ -59,11 +59,15 @@ spring.liquibase.compact.enabled=false
# Disable configuration load from DB
sumaris.persistence.configuration.enabled=false
# Override User Profile labels
# Override enumerations (User Profile labels, etc.)
sumaris.enumeration.UserProfile.ADMIN.label=ALLEGRO_ADMINISTRATEUR
sumaris.enumeration.UserProfile.SUPERVISOR.label=ALLEGRO_SUPER_UTILISATEUR
sumaris.enumeration.UserProfile.USER.label=ALLEGRO_UTILISATEUR
sumaris.enumeration.UserProfile.GUEST.label=SIH_AUTRE
sumaris.enumeration.LocationLevel.COUNTRY.id=21
sumaris.enumeration.LocationLevel.HARBOUR.id=6
sumaris.enumeration.LocationLevel.AUCTION.id=7
# Logging Levels
logging.level.ROOT=info
......
......@@ -21,4 +21,13 @@ spring.datasource.hikari.connectionInitSql=BEGIN \
END;
# Mandatory for Oracle with sequences incrementing with 1
sumaris.persistence.sequence.increment=1
\ No newline at end of file
sumaris.persistence.sequence.increment=1
# Override enumerations (User Profile labels, etc.)
sumaris.enumeration.UserProfile.ADMIN.label=ALLEGRO_ADMINISTRATEUR
sumaris.enumeration.UserProfile.SUPERVISOR.label=ALLEGRO_SUPER_UTILISATEUR
sumaris.enumeration.UserProfile.USER.label=ALLEGRO_UTILISATEUR
sumaris.enumeration.UserProfile.GUEST.label=SIH_AUTRE
sumaris.enumeration.LocationLevel.COUNTRY.id=21
sumaris.enumeration.LocationLevel.HARBOUR.id=6
sumaris.enumeration.LocationLevel.AUCTION.id=7
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment