Skip to content

Commit

Permalink
some further improvements and catch exception during output creation.…
Browse files Browse the repository at this point in the history
… Log exception with message and return all valid outputs
  • Loading branch information
Carsten Hollmann committed Nov 6, 2020
1 parent 9853b29 commit 90f0679
Show file tree
Hide file tree
Showing 42 changed files with 781 additions and 616 deletions.
77 changes: 35 additions & 42 deletions dao/src/main/java/org/n52/series/db/da/AbstractDataRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,34 @@

public abstract class AbstractDataRepository<S extends DatasetEntity,
E extends DataEntity<T>,
V extends AbstractValue< ? >,
T>
extends
SessionAwareRepository implements
DataRepository<S, E, V, T> {
V extends AbstractValue<?>, T>
extends SessionAwareRepository implements DataRepository<S, E, V, T> {

@Override
public Data<V> getData(String datasetId, DbQuery dbQuery) {
Session session = getSession();
try {
// DatasetDao<S> seriesDao = getSeriesDao(session);
// IoParameters parameters = dbQuery.getParameters();
// DatasetDao<S> seriesDao = getSeriesDao(session);
// IoParameters parameters = dbQuery.getParameters();
// remove spatial filter on metadata
// S series = seriesDao.getInstance(datasetId, getDbQuery(parameters.removeAllOf(Parameters.BBOX)
// .removeAllOf(Parameters.NEAR)
// .removeAllOf(Parameters.ODATA_FILTER)));
// if (series.getService() == null) {
// series.setService(getServiceEntity());
// }
return dbQuery.isExpanded()
? assembleExpandedData(Long.parseLong(datasetId), dbQuery, session)
: assembleData(Long.parseLong(datasetId), dbQuery, session);
// S series = seriesDao.getInstance(datasetId, getDbQuery(parameters.removeAllOf(Parameters.BBOX)
// .removeAllOf(Parameters.NEAR)
// .removeAllOf(Parameters.ODATA_FILTER)));
// if (series.getService() == null) {
// series.setService(getServiceEntity());
// }
return dbQuery.isExpanded() ? assembleExpandedData(Long.parseLong(datasetId), dbQuery, session)
: assembleData(Long.parseLong(datasetId), dbQuery, session);
} finally {
returnSession(session);
}
}

protected Data<V> assembleExpandedData(S dataset, DbQuery dbQuery, Session session) {
protected Data<V> assembleExpandedData(S dataset, DbQuery dbQuery, Session session) {
return assembleExpandedData(dataset.getId(), dbQuery, session);
}

protected Data<V> assembleExpandedData(Long dataset, DbQuery dbQuery, Session session) {
protected Data<V> assembleExpandedData(Long dataset, DbQuery dbQuery, Session session) {
return assembleData(dataset, dbQuery, session);
}

Expand All @@ -102,26 +98,24 @@ public V assembleDataValueWithMetadata(E data, S dataset, DbQuery query) {

@Override
public V getFirstValue(S entity, Session session, DbQuery query) {
return entity.getFirstObservation() != null
? assembleDataValue(unproxy(entity.getFirstObservation(), session), entity, query)
: null;
DataEntity<?> value = entity.getFirstObservation() != null ? entity.getFirstObservation()
: entity.isSetFirstValueAt() ? createDataDao(session).getDataValueViaTimestart(entity, query) : null;
return value != null ? assembleDataValue(unproxy(value, session), entity, query) : null;
}

@Override
public V getLastValue(S entity, Session session, DbQuery query) {
return entity.getLastObservation() != null
? assembleDataValue(unproxy(entity.getLastObservation(), session), entity, query)
: null;
DataEntity<?> value = entity.getLastObservation() != null ? entity.getLastObservation()
: entity.isSetLastValueAt() ? createDataDao(session).getDataValueViaTimeend(entity, query) : null;
return value != null ? assembleDataValue(unproxy(value, session), entity, query) : null;
}

@Override
public GeometryEntity getLastKnownGeometry(DatasetEntity entity, Session session, DbQuery query) {
// DataDao<E> dao = createDataDao(session);
// return dao.getValueGeometryViaTimeend(entity, query);
DataEntity<?> lastObservation = entity.getLastObservation();
return lastObservation != null
? lastObservation.getGeometryEntity()
: null;
return lastObservation != null ? lastObservation.getGeometryEntity() : null;
}

protected DatasetDao<S> getSeriesDao(Session session) {
Expand Down Expand Up @@ -156,11 +150,11 @@ protected V prepareValue(E observation, DbQuery query) {
return emptyValue;
}

protected boolean hasValidEntriesWithinRequestedTimespan(List< ? > observations) {
protected boolean hasValidEntriesWithinRequestedTimespan(List<?> observations) {
return observations.size() > 0;
}

protected boolean hasSingleValidReferenceValue(List< ? > observations) {
protected boolean hasSingleValidReferenceValue(List<?> observations) {
return observations.size() == 1;
}

Expand All @@ -182,34 +176,34 @@ protected V addMetadatasIfNeeded(E observation, V value, S dataset, DbQuery quer
return value;
}

protected void addGeometry(DataEntity< ? > dataEntity, AbstractValue< ? > value, DbQuery query) {
protected void addGeometry(DataEntity<?> dataEntity, AbstractValue<?> value, DbQuery query) {
if (dataEntity.isSetGeometryEntity()) {
GeometryEntity geometry = dataEntity.getGeometryEntity();
value.setGeometry(geometry.getGeometry());
}
}

protected void addValidTime(DataEntity< ? > observation, AbstractValue< ? > value, IoParameters parameters) {
protected void addValidTime(DataEntity<?> observation, AbstractValue<?> value, IoParameters parameters) {
if (observation.isSetValidStartTime() || observation.isSetValidEndTime()) {
TimeOutput validFrom = observation.isSetValidStartTime()
? createTimeOutput(observation.getValidTimeStart(), parameters)
: null;
TimeOutput validUntil = observation.isSetValidEndTime()
? createTimeOutput(observation.getValidTimeEnd(), parameters)
: null;
TimeOutput validFrom =
observation.isSetValidStartTime() ? createTimeOutput(observation.getValidTimeStart(), parameters)
: null;
TimeOutput validUntil =
observation.isSetValidEndTime() ? createTimeOutput(observation.getValidTimeEnd(), parameters)
: null;
value.setValidTime(validFrom, validUntil);
}
}

protected void addResultTime(DataEntity< ? > observation, AbstractValue< ? > value) {
protected void addResultTime(DataEntity<?> observation, AbstractValue<?> value) {
if (observation.getResultTime() != null) {
value.setResultTime(new DateTime(observation.getResultTime()));
}
}

protected void addParameters(DataEntity< ? > observation, AbstractValue< ? > value, DbQuery query) {
protected void addParameters(DataEntity<?> observation, AbstractValue<?> value, DbQuery query) {
if (observation.hasParameters()) {
for (ParameterEntity< ? > parameter : observation.getParameters()) {
for (ParameterEntity<?> parameter : observation.getParameters()) {
value.addParameter(parameter.toValueMap(query.getLocale()));
}
}
Expand Down Expand Up @@ -257,9 +251,8 @@ protected E unproxy(DataEntity<?> dataEntity, Session session) {
return (E) Hibernate.unproxy(dataEntity);
}


protected BigDecimal format(BigDecimal value, DatasetEntity dataset) {
return format(value, dataset.getNumberOfDecimals());
return format(value, dataset.getNumberOfDecimals());
}

protected BigDecimal format(BigDecimal value, Integer scale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
import org.n52.series.db.beans.DatasetEntity;
import org.n52.series.db.dao.DbQuery;

public abstract class AbstractNumericalDataRepository<E extends DataEntity<T>,
V extends AbstractValue< ? >,
T>
extends AbstractDataRepository<DatasetEntity, E, V, T> {
public abstract class AbstractNumericalDataRepository<E extends DataEntity<T>, V extends AbstractValue<?>, T>
extends AbstractDataRepository<DatasetEntity, E, V, T> {

protected V getMax(DatasetEntity dataset, DbQuery query, Session session) {
return assembleDataValue(createDataDao(session).getMax(dataset), dataset, query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,9 @@ protected Data<BooleanValue> assembleData(Long dataset, DbQuery query, Session s
}

@Override
public BooleanValue assembleDataValue(BooleanDataEntity observation,
DatasetEntity series,
DbQuery query) {
public BooleanValue assembleDataValue(BooleanDataEntity observation, DatasetEntity series, DbQuery query) {
ServiceEntity service = getServiceEntity(series);
Boolean observationValue = !service.isNoDataValue(observation)
? observation.getValue()
: null;
Boolean observationValue = !service.isNoDataValue(observation) ? observation.getValue() : null;

BooleanValue value = prepareValue(observation, query);
value.setValue(observationValue);
Expand Down
22 changes: 6 additions & 16 deletions dao/src/main/java/org/n52/series/db/da/CategoryDataRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,22 @@ protected Data<CategoryValue> assembleData(Long dataset, DbQuery query, Session
}

@Override
public CategoryValue assembleDataValue(CategoryDataEntity observation,
DatasetEntity series,
DbQuery query) {
public CategoryValue assembleDataValue(CategoryDataEntity observation, DatasetEntity series, DbQuery query) {
ServiceEntity service = getServiceEntity(series);
String observationValue = !service.isNoDataValue(observation)
? observation.getValue()
: null;
String observationValue = !service.isNoDataValue(observation) ? observation.getValue() : null;

CategoryValue value = createValue(observation, series, query, observationValue);
return addMetadatasIfNeeded(observation, value, series, query);
}

private CategoryValue createValue(CategoryDataEntity observation,
DatasetEntity series,
DbQuery query,
String observationValue) {
private CategoryValue createValue(CategoryDataEntity observation, DatasetEntity series, DbQuery query,
String observationValue) {
ServiceEntity service = getServiceEntity(series);
String textValue = !service.isNoDataValue(observation)
? observation.getValue()
: null;
String textValue = !service.isNoDataValue(observation) ? observation.getValue() : null;
return createValue(textValue, observation, query);
}

CategoryValue createValue(String observationValue,
CategoryDataEntity observation,
DbQuery query) {
CategoryValue createValue(String observationValue, CategoryDataEntity observation, DbQuery query) {
CategoryValue value = prepareValue(observation, query);
value.setValue(observationValue);
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ public CategoryProfileDataRepository() {
}

@Override
protected ProfileValue<String> createValue(ProfileDataEntity observation,
DatasetEntity dataset,
DbQuery query) {
protected ProfileValue<String> createValue(ProfileDataEntity observation, DatasetEntity dataset, DbQuery query) {
ProfileValue<String> profile = createProfileValue(observation, query);
List<ProfileDataItem<String>> dataItems = new ArrayList<>();
for (DataEntity< ? > dataEntity : observation.getValue()) {
for (DataEntity<?> dataEntity : observation.getValue()) {
CategoryDataEntity categoryEntity = (CategoryDataEntity) dataEntity;
CategoryValue valueItem = categoryRepository.createValue(categoryEntity.getValue(), categoryEntity, query);
addParameters(categoryEntity, valueItem, query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
package org.n52.series.db.da;

import org.hibernate.Session;
import org.n52.io.response.AbstractOutput;
import org.n52.io.response.CategoryOutput;
import org.n52.io.response.ServiceOutput;
import org.n52.series.db.beans.CategoryEntity;
import org.n52.series.db.dao.AbstractDao;
import org.n52.series.db.dao.CategoryDao;
Expand Down Expand Up @@ -64,12 +62,7 @@ protected SearchableDao<CategoryEntity> createSearchableDao(Session session) {

@Override
protected CategoryOutput createExpanded(CategoryEntity entity, DbQuery query, Session session) {
CategoryOutput result = createCondensed(entity, query, session);
ServiceOutput service = (query.getHrefBase() != null)
? getCondensedExtendedService(getServiceEntity(entity), query.withoutFieldsFilter())
: getCondensedService(getServiceEntity(entity), query.withoutFieldsFilter());
result.setValue(AbstractOutput.SERVICE, service, query.getParameters(), result::setService);
return result;
return getMapperFactory().getCategoryMapper().createExpanded(entity, query, session);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@
import org.n52.series.db.dao.DataDao;
import org.n52.series.db.dao.DbQuery;


@DataRepositoryComponent(value = "count", datasetEntityType = DatasetEntity.class)
public class CountDataRepository
extends AbstractNumericalDataRepository<CountDataEntity, CountValue, Integer> {
public class CountDataRepository extends AbstractNumericalDataRepository<CountDataEntity, CountValue, Integer> {

@Override
protected CountValue createEmptyValue() {
Expand Down Expand Up @@ -71,9 +69,7 @@ public CountValue assembleDataValue(CountDataEntity observation, DatasetEntity s
}

ServiceEntity service = getServiceEntity(series);
Integer observationValue = !service.isNoDataValue(observation)
? observation.getValue()
: null;
Integer observationValue = !service.isNoDataValue(observation) ? observation.getValue() : null;

CountValue value = prepareValue(observation, query);
value.setValue(observationValue);
Expand Down
Loading

0 comments on commit 90f0679

Please sign in to comment.