Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dao/src/main/java/org/n52/series/db/da/DatasetRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ private void addCondensedResults(DatasetDao<? extends DatasetEntity> dao,
List<DatasetOutput> results,
Session session)
throws DataAccessException {
for (DatasetEntity series : dao.getAllInstances(query)) {
Iterable<? extends DatasetEntity> entities = addServiceFilter(dao.getAllInstances(query), query);
for (DatasetEntity series : entities) {
results.add(createCondensed(series, query, session));
}
}
Expand Down Expand Up @@ -212,7 +213,8 @@ private void addExpandedResults(DatasetDao< ? extends DatasetEntity> dao,
List<DatasetOutput> results,
Session session)
throws DataAccessException {
for (DatasetEntity series : dao.getAllInstances(query)) {
Iterable<? extends DatasetEntity> entities = addServiceFilter(dao.getAllInstances(query), query);
for (DatasetEntity series : entities) {
results.add(createExpanded(series, query, session));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ private PlatformOutput getPlatfom(FeatureEntity entity, DbQuery parameters) thro
String.valueOf(entity.getPkid()))
.extendWith(Parameters.FILTER_PLATFORM_TYPES,
"all"));

List<PlatformOutput> platforms = platformRepository.getAllCondensed(platformQuery);
return platforms.iterator()
.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public abstract class HierarchicalParameterRepository<E extends HierarchicalEnti
@Override
protected List<O> createExpanded(Iterable<E> entities, DbQuery query, Session session) throws DataAccessException {
Set<O> results = new HashSet<>();
if (entities != null) {
if (entities != null && entities.iterator().hasNext()) {
addServiceFilter(entities, query);
for (E entity : entities) {
O result = createExpanded(entity, query, session);
results.add(result);
Expand All @@ -58,7 +59,8 @@ protected List<O> createExpanded(Iterable<E> entities, DbQuery query, Session se
@Override
protected List<O> createCondensed(Iterable<E> entities, DbQuery query, Session session) {
Set<O> results = new HashSet<>();
if (entities != null) {
if (entities != null && entities.iterator().hasNext()) {
addServiceFilter(entities, query);
for (E entity : entities) {
O result = createCondensed(entity, query, session);
results.add(result);
Expand Down
14 changes: 11 additions & 3 deletions dao/src/main/java/org/n52/series/db/da/ParameterRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ public List<O> getAllCondensed(DbQuery query, Session session) throws DataAccess

protected List<O> createCondensed(Iterable<E> allInstances, DbQuery query, Session session) {
List<O> results = new ArrayList<>();
for (E entity : allInstances) {
Iterable<E> entities = addServiceFilter(allInstances, query);
for (E entity : entities) {
/*
* there are cases where entity does not match a filter
* which could not be added to a db criteria, e.g. spatial
* filters on mobile platforms (last location is calculated
* after db query has been finished already)
*/
results.add(createCondensed(entity, query, session));
}
return results;
Expand Down Expand Up @@ -131,11 +138,12 @@ public List<O> getAllExpanded(DbQuery query, Session session) throws DataAccessE
protected List<O> createExpanded(Iterable<E> allInstances, DbQuery query, Session session)
throws DataAccessException {
List<O> results = new ArrayList<>();
for (E entity : allInstances) {
Iterable<E> entities = addServiceFilter(allInstances, query);
for (E entity : entities) {
O instance = createExpanded(entity, query, session);
if (instance != null) {
/*
* there are cases where entities does not match a filter
* there are cases where entity does not match a filter
* which could not be added to a db criteria, e.g. spatial
* filters on mobile platforms (last location is calculated
* after db query has been finished already)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public PlatformOutput getInstance(String id, DbQuery query, Session session) thr

PlatformEntity getEntity(String id, DbQuery parameters, Session session) throws DataAccessException {
if (PlatformType.isStationaryId(id)) {
return getStation(id, parameters, session);
return addServiceFilter(getStation(id, parameters, session), parameters);
} else {
return getPlatform(id, parameters, session);
return addServiceFilter(getPlatform(id, parameters, session), parameters);
}
}

Expand Down Expand Up @@ -266,10 +266,10 @@ protected List<PlatformEntity> getAllInstances(DbQuery query, Session session) t
List<PlatformEntity> platforms = new ArrayList<>();
FilterResolver filterResolver = query.getFilterResolver();
if (filterResolver.shallIncludeStationaryPlatformTypes()) {
platforms.addAll(getAllStationary(query, session));
platforms.addAll(addServiceFilter(getAllStationary(query, session), query));
}
if (filterResolver.shallIncludeMobilePlatformTypes()) {
platforms.addAll(getAllMobile(query, session));
platforms.addAll(addServiceFilter(getAllMobile(query, session), query));
}
return platforms;
}
Expand Down
28 changes: 28 additions & 0 deletions dao/src/main/java/org/n52/series/db/da/SessionAwareRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Iterator;

import org.hibernate.Session;
import org.slf4j.Logger;
Expand Down Expand Up @@ -301,4 +302,31 @@ private void assertServiceAvailable(DescribableEntity entity) throws IllegalStat
}
}

protected <T extends DescribableEntity, V extends Iterable<T>> V addServiceFilter(V allInstances, DbQuery query) {
Iterator iterator = allInstances.iterator();
while (iterator.hasNext()) {
T element = (T) iterator.next();
if (!query.getParameters().getServices().isEmpty() &&
!query.getParameters()
.getServices()
.contains(Long.toString(getServiceEntity(element).getPkid()))) {
try {
iterator.remove();
} catch (UnsupportedOperationException e) {
// dao returning immutable list does not want serviceFilter to be added
}
}
}
return allInstances;
}

protected <T extends DescribableEntity> T addServiceFilter(T instance, DbQuery query) {
if (!query.getParameters().getServices().isEmpty() &&
!query.getParameters().getServices()
.contains(Long.toString(getServiceEntity(instance).getPkid()))) {
return null;
} else {
return instance;
}
}
}
11 changes: 7 additions & 4 deletions dao/src/main/java/org/n52/series/db/da/StationRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Collection<SearchResult> searchFor(IoParameters parameters) {
try {
FeatureDao stationDao = createDao(session);
DbQuery query = addPointLocationOnlyRestriction(getDbQuery(parameters));
List<FeatureEntity> found = stationDao.find(query);
List<FeatureEntity> found = addServiceFilter(stationDao.find(query), query);
return convertToSearchResults(found, query);
} finally {
returnSession(session);
Expand Down Expand Up @@ -142,7 +142,7 @@ public List<StationOutput> getAllExpanded(DbQuery parameters, Session session) t

private List<FeatureEntity> getAllInstances(DbQuery parameters, Session session) throws DataAccessException {
FeatureDao featureDao = createDao(session);
return featureDao.getAllInstances(addPointLocationOnlyRestriction(parameters));
return addServiceFilter(featureDao.getAllInstances(addPointLocationOnlyRestriction(parameters)), parameters);
}

@Override
Expand All @@ -167,13 +167,16 @@ public StationOutput getInstance(String id, DbQuery parameters, Session session)
private FeatureEntity getFeatureEntity(String id, DbQuery parameters, Session session)
throws DataAccessException, BadRequestException {
DbQuery query = addPointLocationOnlyRestriction(parameters);
return createDao(session).getInstance(parseId(id), query);
return addServiceFilter(createDao(session).getInstance(parseId(id), query), parameters);
}

public StationOutput getCondensedInstance(String id, DbQuery parameters, Session session)
throws DataAccessException {
FeatureDao featureDao = createDao(session);
FeatureEntity result = featureDao.getInstance(parseId(id), getDbQuery(IoParameters.createDefaults()));
FeatureEntity result = addServiceFilter(
featureDao.getInstance(parseId(id), getDbQuery(IoParameters.createDefaults())),
parameters
);
return createCondensed(result, parameters);
}

Expand Down
12 changes: 7 additions & 5 deletions dao/src/main/java/org/n52/series/db/da/TimeseriesRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public List<TimeseriesMetadataOutput> getAllCondensed(DbQuery query) throws Data
public List<TimeseriesMetadataOutput> getAllCondensed(DbQuery query, Session session) throws DataAccessException {
List<TimeseriesMetadataOutput> results = new ArrayList<>();
DatasetDao<QuantityDatasetEntity> seriesDao = createDao(session);
for (QuantityDatasetEntity timeseries : seriesDao.getAllInstances(query)) {
Iterable<QuantityDatasetEntity> entities = addServiceFilter(seriesDao.getAllInstances(query), query);
for (QuantityDatasetEntity timeseries : entities) {
results.add(createCondensed(timeseries, query, session));
}
return results;
Expand All @@ -157,7 +158,8 @@ public List<TimeseriesMetadataOutput> getAllExpanded(DbQuery query) throws DataA
public List<TimeseriesMetadataOutput> getAllExpanded(DbQuery query, Session session) throws DataAccessException {
List<TimeseriesMetadataOutput> results = new ArrayList<>();
DatasetDao<QuantityDatasetEntity> seriesDao = createDao(session);
for (QuantityDatasetEntity timeseries : seriesDao.getAllInstances(query)) {
Iterable<QuantityDatasetEntity> entities = addServiceFilter(seriesDao.getAllInstances(query), query);
for (QuantityDatasetEntity timeseries : entities) {
results.add(createExpanded(timeseries, query, session));
}
return results;
Expand All @@ -174,14 +176,14 @@ public TimeseriesMetadataOutput getInstance(String timeseriesId, DbQuery dbQuery
}

@Override
public TimeseriesMetadataOutput getInstance(String timeseriesId, DbQuery dbQuery, Session session)
public TimeseriesMetadataOutput getInstance(String timeseriesId, DbQuery query, Session session)
throws DataAccessException {
DatasetDao<QuantityDatasetEntity> seriesDao = createDao(session);
QuantityDatasetEntity result = seriesDao.getInstance(parseId(timeseriesId), dbQuery);
QuantityDatasetEntity result = addServiceFilter(seriesDao.getInstance(parseId(timeseriesId), query), query);
if (result == null) {
throw new ResourceNotFoundException("Resource with id '" + timeseriesId + "' could not be found.");
}
return createExpanded(result, dbQuery, session);
return createExpanded(result, query, session);
}

protected TimeseriesMetadataOutput createExpanded(QuantityDatasetEntity series, DbQuery query, Session session)
Expand Down