Skip to content

Commit 63da24c

Browse files
author
Carsten Hollmann
committed
Improve getting valueType by using own query instead of getting output
1 parent e4781f5 commit 63da24c

File tree

8 files changed

+192
-25
lines changed

8 files changed

+192
-25
lines changed

rest/src/main/java/org/n52/web/ctrl/data/DataController.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.io.InputStream;
3333
import java.util.Arrays;
3434
import java.util.Collections;
35+
import java.util.LinkedList;
36+
import java.util.List;
3537
import java.util.Map;
3638
import java.util.Set;
3739

@@ -57,7 +59,9 @@
5759
import org.n52.io.response.dataset.Data;
5860
import org.n52.io.response.dataset.DataCollection;
5961
import org.n52.io.response.dataset.DatasetOutput;
62+
import org.n52.io.response.dataset.DatasetTypesMetadata;
6063
import org.n52.series.spi.srv.DataService;
64+
import org.n52.series.spi.srv.DatasetTypesService;
6165
import org.n52.series.spi.srv.ParameterService;
6266
import org.n52.series.spi.srv.RawDataService;
6367
import org.n52.series.spi.srv.RawFormats;
@@ -88,7 +92,7 @@ public abstract class DataController extends BaseController {
8892
protected static final String SHOWTIMEINTERVALS_QUERY_OPTION = "showTimeIntervals";
8993

9094
protected static final String PROFILE = "profile";
91-
95+
protected static final String TRAJECTORY = "trajectory";
9296
protected static final String OBSERVATIONS = "observations";
9397

9498
private static final Logger LOGGER = LoggerFactory.getLogger(DatasetsDataController.class);
@@ -409,6 +413,27 @@ protected boolean isProfileType(DatasetOutput<AbstractValue< ? >> item) {
409413
|| datasetType.equals(PROFILE);
410414
}
411415

416+
protected boolean isProfileType(DatasetTypesMetadata types) {
417+
return types.getObservationType().equals(PROFILE) || types.getDatasetType().equals(PROFILE);
418+
}
419+
420+
protected boolean isTrajectoryType(DatasetTypesMetadata types) {
421+
return types.getObservationType().equals(TRAJECTORY) || types.getDatasetType().equals(TRAJECTORY);
422+
}
423+
424+
protected List<DatasetTypesMetadata> geDatasetTypes(IoParameters map) {
425+
return (getDatasetService() instanceof DatasetTypesService)
426+
? ((DatasetTypesService) getDatasetService()).getDatasetTypesMetadata(map)
427+
: geDatasetTypes(getFirstDatasetOutput(map));
428+
}
429+
430+
private List<DatasetTypesMetadata> geDatasetTypes(DatasetOutput<AbstractValue<?>> item) {
431+
List<DatasetTypesMetadata> list = new LinkedList<>();
432+
list.add(new DatasetTypesMetadata().setId(item.getId()).setDatasetType(item.getDatasetType())
433+
.setObservationType(item.getObservationType()).setValueType(item.getValueType()));
434+
return list;
435+
}
436+
412437
protected DatasetOutput<AbstractValue< ? >> getFirstDatasetOutput(IoParameters map) {
413438
return datasetService.getCondensedParameters(map)
414439
.getItem(0);

rest/src/main/java/org/n52/web/ctrl/data/DatasetsDataController.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.n52.io.response.dataset.AbstractValue;
3434
import org.n52.io.response.dataset.Data;
3535
import org.n52.io.response.dataset.DatasetOutput;
36+
import org.n52.io.response.dataset.DatasetTypesMetadata;
3637
import org.n52.series.spi.srv.DataService;
3738
import org.n52.series.spi.srv.ParameterService;
3839
import org.n52.web.ctrl.UrlSettings;
@@ -55,10 +56,18 @@ public DatasetsDataController(DefaultIoFactory<DatasetOutput<AbstractValue<?>>,
5556

5657
@Override
5758
protected String getValueType(IoParameters map, String requestUrl) {
58-
DatasetOutput<AbstractValue<?>> item = getFirstDatasetOutput(map);
59-
return isProfileType(item)
60-
? PROFILE
61-
: item.getValueType();
59+
DatasetTypesMetadata types = geDatasetTypes(map).iterator().next();
60+
if (isProfileType(types)) {
61+
// return types.getValueType() + MINUS + PROFILE;
62+
return PROFILE;
63+
} else if (isTrajectoryType(types)) {
64+
// return types.getValueType() + MINUS + TRAJECTORY;
65+
return TRAJECTORY;
66+
} else {
67+
return types.getValueType();
68+
}
6269
}
6370

71+
72+
6473
}

rest/src/main/java/org/n52/web/ctrl/data/IndividualObservationsDataController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.n52.io.response.dataset.AbstractValue;
3636
import org.n52.io.response.dataset.Data;
3737
import org.n52.io.response.dataset.DatasetOutput;
38+
import org.n52.io.response.dataset.DatasetTypesMetadata;
3839
import org.n52.series.spi.srv.DataService;
3940
import org.n52.series.spi.srv.ParameterService;
4041
import org.n52.web.ctrl.UrlSettings;
@@ -59,17 +60,17 @@ public IndividualObservationsDataController(DefaultIoFactory<DatasetOutput<Abstr
5960

6061
@Override
6162
protected String getValueType(IoParameters map, String requestUrl) {
62-
DatasetOutput<AbstractValue< ? >> item = getFirstDatasetOutput(map);
63-
String datasetType = item.getDatasetType();
63+
DatasetTypesMetadata types = geDatasetTypes(map).iterator().next();
64+
String datasetType = types.getDatasetType();
6465
if (!"individualObservation".equalsIgnoreCase(datasetType)) {
6566
String expectedType = UrlSettings.COLLECTION_INDIVIDUAL_OBSERVATIONS;
6667
String template = "The dataset with id ''{0}'' was not found for ''{1}''.";
67-
String message = MessageFormat.format(template, item.getId(), expectedType);
68+
String message = MessageFormat.format(template, types.getId(), expectedType);
6869
throw new ResourceNotFoundException(message);
6970
}
70-
return isProfileType(item)
71+
return isProfileType(types)
7172
? PROFILE
72-
: item.getValueType();
73+
: types.getValueType();
7374
}
7475

7576
}

rest/src/main/java/org/n52/web/ctrl/data/ProfilesDataController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.n52.io.response.dataset.AbstractValue;
3636
import org.n52.io.response.dataset.Data;
3737
import org.n52.io.response.dataset.DatasetOutput;
38+
import org.n52.io.response.dataset.DatasetTypesMetadata;
3839
import org.n52.series.spi.srv.DataService;
3940
import org.n52.series.spi.srv.ParameterService;
4041
import org.n52.web.ctrl.UrlSettings;
@@ -58,17 +59,17 @@ public ProfilesDataController(DefaultIoFactory<DatasetOutput<AbstractValue< ? >>
5859

5960
@Override
6061
protected String getValueType(IoParameters map, String requestUrl) {
61-
DatasetOutput<AbstractValue< ? >> item = getFirstDatasetOutput(map);
62-
String observationType = item.getObservationType();
62+
DatasetTypesMetadata types = geDatasetTypes(map).iterator().next();
63+
String observationType = types.getObservationType();
6364
if (!"profile".equalsIgnoreCase(observationType)) {
6465
String expectedType = UrlSettings.COLLECTION_PROFILES;
6566
String template = "The dataset with id ''{0}'' was not found for ''{1}''.";
66-
String message = MessageFormat.format(template, item.getId(), expectedType);
67+
String message = MessageFormat.format(template, types.getId(), expectedType);
6768
throw new ResourceNotFoundException(message);
6869
}
69-
return isProfileType(item)
70+
return isProfileType(types)
7071
? PROFILE
71-
: item.getValueType();
72+
: types.getValueType();
7273
}
7374

7475
}

rest/src/main/java/org/n52/web/ctrl/data/TimeseriesDataController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.n52.io.response.dataset.AbstractValue;
4343
import org.n52.io.response.dataset.Data;
4444
import org.n52.io.response.dataset.DatasetOutput;
45+
import org.n52.io.response.dataset.DatasetTypesMetadata;
4546
import org.n52.series.spi.srv.DataService;
4647
import org.n52.series.spi.srv.ParameterService;
4748
import org.n52.web.ctrl.UrlSettings;
@@ -179,17 +180,17 @@ public ModelAndView getTimeseriesData(HttpServletRequest request,
179180

180181
@Override
181182
protected String getValueType(IoParameters map, String requestUrl) {
182-
DatasetOutput<AbstractValue< ? >> item = getFirstDatasetOutput(map);
183-
String datasetType = item.getDatasetType();
183+
DatasetTypesMetadata types = geDatasetTypes(map).iterator().next();
184+
String datasetType = types.getDatasetType();
184185
if (!"timeseries".equalsIgnoreCase(datasetType)) {
185186
String expectedType = UrlSettings.COLLECTION_TIMESERIES;
186187
String template = "The dataset with id ''{0}'' was not found for ''{1}''.";
187-
String message = MessageFormat.format(template, item.getId(), expectedType);
188+
String message = MessageFormat.format(template, types.getId(), expectedType);
188189
throw new ResourceNotFoundException(message);
189190
}
190-
return isProfileType(item)
191+
return isProfileType(types)
191192
? PROFILE
192-
: item.getValueType();
193+
: types.getValueType();
193194
}
194195

195196
// TODO set preredering config instead of task

rest/src/main/java/org/n52/web/ctrl/data/TrajectoriesDataController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.n52.io.response.dataset.AbstractValue;
3636
import org.n52.io.response.dataset.Data;
3737
import org.n52.io.response.dataset.DatasetOutput;
38+
import org.n52.io.response.dataset.DatasetTypesMetadata;
3839
import org.n52.series.spi.srv.DataService;
3940
import org.n52.series.spi.srv.ParameterService;
4041
import org.n52.web.ctrl.UrlSettings;
@@ -58,17 +59,17 @@ public TrajectoriesDataController(DefaultIoFactory<DatasetOutput<AbstractValue<
5859

5960
@Override
6061
protected String getValueType(IoParameters map, String requestUrl) {
61-
DatasetOutput<AbstractValue< ? >> item = getFirstDatasetOutput(map);
62-
String datasetType = item.getDatasetType();
62+
DatasetTypesMetadata types = geDatasetTypes(map).iterator().next();
63+
String datasetType = types.getDatasetType();
6364
if (!"trajectory".equalsIgnoreCase(datasetType)) {
6465
String expectedType = UrlSettings.COLLECTION_TRAJECTORIES;
6566
String template = "The dataset with id ''{0}'' was not found for ''{1}''.";
66-
String message = MessageFormat.format(template, item.getId(), expectedType);
67+
String message = MessageFormat.format(template, types.getId(), expectedType);
6768
throw new ResourceNotFoundException(message);
6869
}
69-
return isProfileType(item)
70+
return isProfileType(types)
7071
? PROFILE
71-
: item.getValueType();
72+
: types.getValueType();
7273
}
7374

7475
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (C) 2013-2021 52°North Initiative for Geospatial Open Source
3+
* Software GmbH
4+
*
5+
* This program is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 as published
7+
* by the Free Software Foundation.
8+
*
9+
* If the program is linked with libraries which are licensed under one of
10+
* the following licenses, the combination of the program with the linked
11+
* library is not considered a "derivative work" of the program:
12+
*
13+
* - Apache License, version 2.0
14+
* - Apache Software License, version 1.0
15+
* - GNU Lesser General Public License, version 3
16+
* - Mozilla Public License, versions 1.0, 1.1 and 2.0
17+
* - Common Development and Distribution License (CDDL), version 1.0
18+
*
19+
* Therefore the distribution of the program linked with libraries licensed
20+
* under the aforementioned licenses, is permitted by the copyright holders
21+
* if the distribution is compliant with both the GNU General Public License
22+
* version 2 and the aforementioned licenses.
23+
*
24+
* This program is distributed in the hope that it will be useful, but
25+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27+
* for more details.
28+
*/
29+
package org.n52.io.response.dataset;
30+
31+
public class DatasetTypesMetadata {
32+
33+
private String id;
34+
private String datasetType;
35+
private String observationType;
36+
private String valueType;
37+
38+
public DatasetTypesMetadata() {
39+
}
40+
41+
public DatasetTypesMetadata(String id, String datasetType, String observationType, String valueType) {
42+
this.id = id;
43+
this.datasetType = datasetType;
44+
this.observationType = observationType;
45+
this.valueType = valueType;
46+
}
47+
48+
public String getId() {
49+
return id;
50+
}
51+
52+
public DatasetTypesMetadata setId(Long id) {
53+
this.id = Long.toString(id);
54+
return this;
55+
}
56+
57+
public DatasetTypesMetadata setId(String id) {
58+
this.id = id;
59+
return this;
60+
}
61+
62+
public String getDatasetType() {
63+
return datasetType;
64+
}
65+
66+
public DatasetTypesMetadata setDatasetType(String datasetType) {
67+
this.datasetType = datasetType;
68+
return this;
69+
}
70+
71+
public String getObservationType() {
72+
return observationType;
73+
}
74+
75+
public DatasetTypesMetadata setObservationType(String observationType) {
76+
this.observationType = observationType;
77+
return this;
78+
}
79+
80+
public String getValueType() {
81+
return valueType;
82+
}
83+
84+
public DatasetTypesMetadata setValueType(String valueType) {
85+
this.valueType = valueType;
86+
return this;
87+
}
88+
89+
90+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2013-2021 52°North Initiative for Geospatial Open Source
3+
* Software GmbH
4+
*
5+
* This program is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 as published
7+
* by the Free Software Foundation.
8+
*
9+
* If the program is linked with libraries which are licensed under one of
10+
* the following licenses, the combination of the program with the linked
11+
* library is not considered a "derivative work" of the program:
12+
*
13+
* - Apache License, version 2.0
14+
* - Apache Software License, version 1.0
15+
* - GNU Lesser General Public License, version 3
16+
* - Mozilla Public License, versions 1.0, 1.1 and 2.0
17+
* - Common Development and Distribution License (CDDL), version 1.0
18+
*
19+
* Therefore the distribution of the program linked with libraries licensed
20+
* under the aforementioned licenses, is permitted by the copyright holders
21+
* if the distribution is compliant with both the GNU General Public License
22+
* version 2 and the aforementioned licenses.
23+
*
24+
* This program is distributed in the hope that it will be useful, but
25+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27+
* for more details.
28+
*/
29+
package org.n52.series.spi.srv;
30+
31+
import java.util.List;
32+
33+
import org.n52.io.request.IoParameters;
34+
import org.n52.io.response.dataset.DatasetTypesMetadata;
35+
36+
public interface DatasetTypesService {
37+
38+
List<DatasetTypesMetadata> getDatasetTypesMetadata(IoParameters map);
39+
}

0 commit comments

Comments
 (0)