Commit 9b3cf57b authored by LAVENIER's avatar LAVENIER
Browse files

[fix] Configuration file: keep Spring load order

parent 31e0131b
...@@ -22,6 +22,7 @@ package net.sumaris.core.util.env; ...@@ -22,6 +22,7 @@ package net.sumaris.core.util.env;
* #L% * #L%
*/ */
import com.google.common.collect.Lists;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
...@@ -43,14 +44,14 @@ public class ConfigurableEnvironments { ...@@ -43,14 +44,14 @@ public class ConfigurableEnvironments {
List<MapPropertySource> sources = env.getPropertySources().stream() List<MapPropertySource> sources = env.getPropertySources().stream()
.filter(source -> source instanceof MapPropertySource) .filter(source -> source instanceof MapPropertySource)
.map(source -> (MapPropertySource)source).collect(Collectors.toList()); .map(source -> (MapPropertySource)source).collect(Collectors.toList());
Properties target = defaultOptions; final Properties target = new Properties(defaultOptions);
target = new Properties(target);
for (MapPropertySource source: sources) { for (MapPropertySource source: Lists.reverse(sources)) {
// Cascade properties (keep original order) // Cascade properties (keep original order)
for (String key: source.getPropertyNames()) { for (String key: source.getPropertyNames()) {
Object value = source.getProperty(key); Object value = source.getProperty(key);
if (value != null) { if (value != null) {
//log.info(" {}={}", key, value.toString()); log.info(" {}={}", key, value);
target.setProperty(key, value.toString()); target.setProperty(key, value.toString());
} }
} }
......
...@@ -108,7 +108,7 @@ public class VesselSnapshotDaoImpl extends HibernateDaoSupport implements Vessel ...@@ -108,7 +108,7 @@ public class VesselSnapshotDaoImpl extends HibernateDaoSupport implements Vessel
// Apply sorting // Apply sorting
addSorting(query, cb, root, sortAttribute, sortDirection); addSorting(query, cb, root, sortAttribute, sortDirection);
// No tripFilter: execute request // No filter: execute request
if (filter == null) { if (filter == null) {
TypedQuery<VesselSnapshotResult> q = getEntityManager().createQuery(query) TypedQuery<VesselSnapshotResult> q = getEntityManager().createQuery(query)
.setFirstResult(offset) .setFirstResult(offset)
......
...@@ -19,3 +19,6 @@ spring.datasource.hikari.connectionInitSql=BEGIN \ ...@@ -19,3 +19,6 @@ spring.datasource.hikari.connectionInitSql=BEGIN \
DBMS_SESSION.SET_NLS('NLS_SORT', 'FRENCH_AI'); \ DBMS_SESSION.SET_NLS('NLS_SORT', 'FRENCH_AI'); \
DBMS_SESSION.SET_NLS('NLS_COMP', 'LINGUISTIC'); \ DBMS_SESSION.SET_NLS('NLS_COMP', 'LINGUISTIC'); \
END; END;
# Mandatory for Oracle with sequences incrementing with 1
sumaris.persistence.sequence.increment=1
\ No newline at end of file
...@@ -161,11 +161,7 @@ public class DataGraphQLService { ...@@ -161,11 +161,7 @@ public class DataGraphQLService {
@GraphQLArgument(name = "sortBy", defaultValue = VesselSnapshotVO.Fields.EXTERIOR_MARKING) String sort, @GraphQLArgument(name = "sortBy", defaultValue = VesselSnapshotVO.Fields.EXTERIOR_MARKING) String sort,
@GraphQLArgument(name = "sortDirection", defaultValue = "asc") String direction @GraphQLArgument(name = "sortDirection", defaultValue = "asc") String direction
) { ) {
// Filter on SIH program, when not an admin fillVesselFilter(filter); // Restrict vessels access
if (!authService.isAdmin()) {
filter = VesselFilterVO.nullToEmpty(filter);
filter.setProgramLabel(ProgramEnum.SIH.getLabel());
}
return vesselService.findSnapshotByFilter( return vesselService.findSnapshotByFilter(
filter, filter,
...@@ -182,11 +178,7 @@ public class DataGraphQLService { ...@@ -182,11 +178,7 @@ public class DataGraphQLService {
@GraphQLArgument(name = "sortBy") String sort, @GraphQLArgument(name = "sortBy") String sort,
@GraphQLArgument(name = "sortDirection", defaultValue = "asc") String direction @GraphQLArgument(name = "sortDirection", defaultValue = "asc") String direction
) { ) {
// Filter on SIH program, when not an admin fillVesselFilter(filter); // Restrict vessels access
if (!authService.isAdmin()) {
filter = VesselFilterVO.nullToEmpty(filter);
filter.setProgramLabel(ProgramEnum.SIH.getLabel());
}
return vesselService.findVesselsByFilter( return vesselService.findVesselsByFilter(
filter, filter,
...@@ -198,6 +190,8 @@ public class DataGraphQLService { ...@@ -198,6 +190,8 @@ public class DataGraphQLService {
@Transactional(readOnly = true) @Transactional(readOnly = true)
@IsUser @IsUser
public long getVesselsCount(@GraphQLArgument(name = "filter") VesselFilterVO filter) { public long getVesselsCount(@GraphQLArgument(name = "filter") VesselFilterVO filter) {
fillVesselFilter(filter); // Restrict vessels access
return vesselService.countVesselsByFilter(filter); return vesselService.countVesselsByFilter(filter);
} }
...@@ -1449,6 +1443,19 @@ public class DataGraphQLService { ...@@ -1449,6 +1443,19 @@ public class DataGraphQLService {
.build(); .build();
} }
/**
* Restrict to vessel, depending of user access rights
* @param filter
*/
protected VesselFilterVO fillVesselFilter(VesselFilterVO filter) {
// Filter on SIH program, when not an admin
if (!authService.isAdmin()) {
filter = VesselFilterVO.nullToEmpty(filter);
filter.setProgramLabel(ProgramEnum.SIH.getLabel());
}
return filter;
}
/** /**
* Restrict to self data and/or department data * Restrict to self data and/or department data
* @param filter * @param filter
......
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