Skip to content

Commit 49e9857

Browse files
committed
fix alias handling
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
1 parent 9f2be22 commit 49e9857

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,8 @@ private Response getItemHistoryDTO(@Nullable String serviceId, String itemName,
445445

446446
QueryablePersistenceService qService = (QueryablePersistenceService) service;
447447

448-
PersistenceServiceConfiguration config = persistenceServiceConfigurationRegistry.get(effectiveServiceId);
449-
String alias = config != null ? config.getAliases().get(itemName) : null;
450-
alias = alias != null ? alias : itemName;
451448
@Nullable
452-
ItemHistoryDTO dto = createDTO(qService, alias, timeBegin, timeEnd, pageNumber, pageLength, boundary,
449+
ItemHistoryDTO dto = createDTO(qService, itemName, timeBegin, timeEnd, pageNumber, pageLength, boundary,
453450
itemState);
454451
if (dto == null) {
455452
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Item not found: " + itemName);
@@ -462,6 +459,9 @@ private Response getItemHistoryDTO(@Nullable String serviceId, String itemName,
462459
protected @Nullable ItemHistoryDTO createDTO(QueryablePersistenceService qService, String itemName,
463460
@Nullable String timeBegin, @Nullable String timeEnd, int pageNumber, int pageLength, boolean boundary,
464461
boolean itemState) {
462+
PersistenceServiceConfiguration config = persistenceServiceConfigurationRegistry.get(qService.getId());
463+
String alias = config != null ? config.getAliases().get(itemName) : null;
464+
465465
ZonedDateTime dateTimeBegin = ZonedDateTime.now();
466466
ZonedDateTime dateTimeEnd = dateTimeBegin;
467467
if (timeBegin != null) {
@@ -507,7 +507,7 @@ private Response getItemHistoryDTO(@Nullable String serviceId, String itemName,
507507
filterBeforeStart.setEndDate(dateTimeBegin);
508508
filterBeforeStart.setPageSize(1);
509509
filterBeforeStart.setOrdering(Ordering.DESCENDING);
510-
result = qService.query(filterBeforeStart, itemName);
510+
result = qService.query(filterBeforeStart, alias);
511511
if (result.iterator().hasNext()) {
512512
dto.addData(dateTimeBegin.toInstant().toEpochMilli(), result.iterator().next().getState());
513513
quantity++;
@@ -526,7 +526,7 @@ private Response getItemHistoryDTO(@Nullable String serviceId, String itemName,
526526
filter.setBeginDate(dateTimeBegin);
527527
filter.setEndDate(dateTimeEnd);
528528
filter.setOrdering(Ordering.ASCENDING);
529-
result = qService.query(filter, itemName);
529+
result = qService.query(filter, alias);
530530
Iterator<HistoricItem> it = result.iterator();
531531

532532
// Iterate through the data
@@ -558,7 +558,7 @@ private Response getItemHistoryDTO(@Nullable String serviceId, String itemName,
558558
filterAfterEnd.setBeginDate(dateTimeEnd);
559559
filterAfterEnd.setPageSize(1);
560560
filterAfterEnd.setOrdering(Ordering.ASCENDING);
561-
result = qService.query(filterAfterEnd, itemName);
561+
result = qService.query(filterAfterEnd, alias);
562562
if (result.iterator().hasNext()) {
563563
dto.addData(dateTimeEnd.toInstant().toEpochMilli(), result.iterator().next().getState());
564564
quantity++;

bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/QueryablePersistenceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ default Set<PersistenceItemInfo> getItemInfo() throws UnsupportedOperationExcept
112112
* item is not found in the persistence service. If it is not possible to retrieve the information or it would be
113113
* too expensive to do so an {@link UnsupportedOperationException} should be thrown.
114114
* The default implementation will query the persistence service for the last value in the persistence store and
115-
* set the latest timestamp, leaving the {@link PersistenceItemInfo} count to null.
115+
* set the latest timestamp, leaving the {@link PersistenceItemInfo} earliest timestamp and count equal to null.
116116
*
117117
* Note that the method should return the alias for the item in its response if an alias is being used.
118118
*

0 commit comments

Comments
 (0)