Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend Metadata: reuse getPageDevice method for MetadataFile and MetadataDummy #2728

Merged
merged 5 commits into from
Aug 1, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.openems.backend.common.metadata;

import static io.openems.common.utils.StringUtils.containsWithNullCheck;

import java.util.Collection;
import java.util.List;

import io.openems.common.channel.Level;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
import io.openems.common.session.Role;

public class MetadataUtils {

private MetadataUtils() {
}

/**
* Common implementation for
* {@link Metadata#getPageDevice(User, PaginationOptions)}.
*
* @param <EDGE> the type of the {@link Edge}
* @param user the {@link User}
* @param edges a Collection of {@link Edge}s
* @param paginationOptions the {@link PaginationOptions}
* @return the result, a list of {@link EdgeMetadata}
* @throws OpenemsNamedException on error
*/
public static <EDGE extends Edge> List<EdgeMetadata> getPageDevice(User user, Collection<EDGE> edges,
PaginationOptions paginationOptions) throws OpenemsNamedException {
var pagesStream = edges.stream();
final var query = paginationOptions.getQuery();
if (query != null) {
pagesStream = pagesStream.filter(//
edge -> containsWithNullCheck(edge.getId(), query) //
|| containsWithNullCheck(edge.getComment(), query) //
|| containsWithNullCheck(edge.getProducttype(), query) //
);
}
final var searchParams = paginationOptions.getSearchParams();
if (searchParams != null) {
if (searchParams.searchIsOnline()) {
pagesStream = pagesStream.filter(edge -> edge.isOnline() == searchParams.isOnline());
}
if (searchParams.productTypes() != null && !searchParams.productTypes().isEmpty()) {
pagesStream = pagesStream.filter(edge -> searchParams.productTypes().contains(edge.getProducttype()));
}
// TODO sum state filter
}

return pagesStream //
.sorted((s1, s2) -> s1.getId().compareTo(s2.getId())) //
.skip(paginationOptions.getPage() * paginationOptions.getLimit()) //
.limit(paginationOptions.getLimit()) //
.peek(t -> user.setRole(t.getId(), Role.ADMIN)) //
.map(myEdge -> {
return new EdgeMetadata(//
myEdge.getId(), //
myEdge.getComment(), //
myEdge.getProducttype(), //
myEdge.getVersion(), //
Role.ADMIN, //
myEdge.isOnline(), //
myEdge.getLastmessage(), //
null, // firstSetupProtocol
Level.OK);
}).toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.openems.backend.common.metadata.Edge;
import io.openems.backend.common.metadata.EdgeHandler;
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.metadata.MetadataUtils;
import io.openems.backend.common.metadata.SimpleEdgeHandler;
import io.openems.backend.common.metadata.User;
import io.openems.common.channel.Level;
Expand All @@ -48,7 +49,6 @@
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.utils.StringUtils;
import io.openems.common.utils.ThreadPoolUtils;

@Designate(ocd = Config.class, factory = false)
Expand Down Expand Up @@ -330,43 +330,7 @@ public void setUserAlertingSettings(User user, String edgeId, List<UserAlertingS
@Override
public List<EdgeMetadata> getPageDevice(User user, PaginationOptions paginationOptions)
throws OpenemsNamedException {
var pagesStream = this.edges.values().stream();
final var query = paginationOptions.getQuery();
if (query != null) {
pagesStream = pagesStream.filter(//
edge -> StringUtils.containsWithNullCheck(edge.getId(), query) //
|| StringUtils.containsWithNullCheck(edge.getComment(), query) //
|| StringUtils.containsWithNullCheck(edge.getProducttype(), query) //
);
}
final var searchParams = paginationOptions.getSearchParams();
if (searchParams != null) {
if (searchParams.searchIsOnline()) {
pagesStream = pagesStream.filter(edge -> edge.isOnline() == searchParams.isOnline());
}
if (searchParams.productTypes() != null && !searchParams.productTypes().isEmpty()) {
pagesStream = pagesStream.filter(edge -> searchParams.productTypes().contains(edge.getProducttype()));
}
// TODO sum state filter
}

return pagesStream //
.sorted((s1, s2) -> s1.getId().compareTo(s2.getId())) //
.skip(paginationOptions.getPage() * paginationOptions.getLimit()) //
.limit(paginationOptions.getLimit()) //
.peek(t -> user.setRole(t.getId(), Role.ADMIN)) //
.map(myEdge -> {
return new EdgeMetadata(//
myEdge.getId(), //
myEdge.getComment(), //
myEdge.getProducttype(), //
myEdge.getVersion(), //
Role.ADMIN, //
myEdge.isOnline(), //
myEdge.getLastmessage(), //
null, // firstSetupProtocol
Level.OK);
}).toList();
return MetadataUtils.getPageDevice(user, this.edges.values(), paginationOptions);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.openems.backend.common.metadata.Edge;
import io.openems.backend.common.metadata.EdgeHandler;
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.metadata.MetadataUtils;
import io.openems.backend.common.metadata.SimpleEdgeHandler;
import io.openems.backend.common.metadata.User;
import io.openems.common.channel.Level;
Expand All @@ -51,7 +52,6 @@
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.utils.JsonUtils;
import io.openems.common.utils.StringUtils;

/**
* This implementation of MetadataService reads Edges configuration from a file.
Expand Down Expand Up @@ -339,42 +339,7 @@ public void setUserAlertingSettings(User user, String edgeId, List<UserAlertingS
@Override
public List<EdgeMetadata> getPageDevice(User user, PaginationOptions paginationOptions)
throws OpenemsNamedException {
var pagesStream = this.edges.values().stream();
final var query = paginationOptions.getQuery();
if (query != null) {
pagesStream = pagesStream.filter(//
edge -> StringUtils.containsWithNullCheck(edge.getId(), query) //
|| StringUtils.containsWithNullCheck(edge.getComment(), query) //
|| StringUtils.containsWithNullCheck(edge.getProducttype(), query) //
);
}
final var searchParams = paginationOptions.getSearchParams();
if (searchParams != null) {
if (searchParams.searchIsOnline()) {
pagesStream = pagesStream.filter(edge -> edge.isOnline() == searchParams.isOnline());
}
if (searchParams.productTypes() != null) {
pagesStream = pagesStream.filter(edge -> searchParams.productTypes().contains(edge.getProducttype()));
}
// TODO sum state filter
}
return pagesStream //
.sorted((s1, s2) -> s1.getId().compareTo(s2.getId())) //
.skip(paginationOptions.getPage() * paginationOptions.getLimit()) //
.limit(paginationOptions.getLimit()) //
.peek(t -> user.setRole(t.getId(), Role.ADMIN)) //
.map(myEdge -> {
return new EdgeMetadata(//
myEdge.getId(), //
myEdge.getComment(), //
myEdge.getProducttype(), //
myEdge.getVersion(), //
Role.ADMIN, //
myEdge.isOnline(), //
myEdge.getLastmessage(), //
null, // firstSetupProtocol
Level.OK);
}).toList();
return MetadataUtils.getPageDevice(user, this.edges.values(), paginationOptions);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DetailsOverviewComponent extends AbstractHistoryChartOverview {
protected override afterIsInitialized() {
this.service.getCurrentEdge().then(edge => {

if (this.config?.hasComponentNature("io.openems.edge.evcs.api.Evcs", this.component?.id)) {
if (this.component && this.config?.hasComponentNature("io.openems.edge.evcs.api.Evcs", this.component.id)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class FlatComponent extends AbstractFlatWidget implements OnInit {

protected readonly CONVERT_MODE_TO_MANUAL_OFF_AUTOMATIC = Utils.CONVERT_MODE_TO_MANUAL_OFF_AUTOMATIC(this.translate);
protected readonly CONVERT_TIME_OF_USE_TARIFF_STATE = Utils.CONVERT_TIME_OF_USE_TARIFF_STATE(this.translate);
protected priceWithCurrency: string;

protected priceWithCurrency: string = "-";

async presentModal() {
const modal = await this.modalController.create({
Expand Down