Skip to content

Commit

Permalink
Minor tidy up
Browse files Browse the repository at this point in the history
Signed-off-by: Grégoire Athanase <[email protected]>
  • Loading branch information
gathanase committed Dec 19, 2024
1 parent f557096 commit 00ec1b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,35 +413,31 @@ private AbstractResultDTO handleSnapshot(final SensiNactSession userSession, fin
for (var filter: query.filter) {
ICriterion criterion = resourceSelectorFilterFactory.parseResourceSelector(filter);
for (var providerSnapshot: executeFilter(criterion)) {
if (criterion.getProviderFilter() == null || criterion.getProviderFilter().test(providerSnapshot)) {
for (var serviceSnapshot: providerSnapshot.getServices()) {
if (criterion.getServiceFilter() == null || criterion.getServiceFilter().test(serviceSnapshot)) {
for (var resourceSnapshot: serviceSnapshot.getResources()) {
if ((criterion.getResourceFilter() == null || criterion.getResourceFilter().test(resourceSnapshot)) && resourceSnapshot.getValue() != null) {
SnapshotProviderDTO providerDTO = result.providers.computeIfAbsent(providerSnapshot.getName(), (name) -> {
var dto = new SnapshotProviderDTO();
dto.name = providerSnapshot.getName();
dto.modelName = providerSnapshot.getModelName();
dto.services = new HashMap<>();
return dto;
});
SnapshotServiceDTO serviceDTO = providerDTO.services.computeIfAbsent(serviceSnapshot.getName(), (name) -> {
var dto = new SnapshotServiceDTO();
dto.name = serviceSnapshot.getName();
dto.resources = new HashMap<>();
return dto;
});
SnapshotResourceDTO resourceDTO = new SnapshotResourceDTO();
resourceDTO.name = resourceSnapshot.getName();
resourceDTO.type = resourceSnapshot.getType().getName();
resourceDTO.timestamp = resourceSnapshot.getValue().getTimestamp().toEpochMilli();
resourceDTO.value = resourceSnapshot.getValue().getValue();
if (query.includeMetadata) {
resourceDTO.attributes = generateMetadataDescriptions(resourceSnapshot.getMetadata());
}
serviceDTO.resources.put(resourceSnapshot.getName(), resourceDTO);
}
for (var serviceSnapshot: providerSnapshot.getServices()) {
for (var resourceSnapshot: serviceSnapshot.getResources()) {
if (resourceSnapshot.getValue() != null) {
SnapshotProviderDTO providerDTO = result.providers.computeIfAbsent(providerSnapshot.getName(), (name) -> {
var dto = new SnapshotProviderDTO();
dto.name = providerSnapshot.getName();
dto.modelName = providerSnapshot.getModelName();
dto.services = new HashMap<>();
return dto;
});
SnapshotServiceDTO serviceDTO = providerDTO.services.computeIfAbsent(serviceSnapshot.getName(), (name) -> {
var dto = new SnapshotServiceDTO();
dto.name = serviceSnapshot.getName();
dto.resources = new HashMap<>();
return dto;
});
SnapshotResourceDTO resourceDTO = new SnapshotResourceDTO();
resourceDTO.name = resourceSnapshot.getName();
resourceDTO.type = resourceSnapshot.getType().getName();
resourceDTO.timestamp = resourceSnapshot.getValue().getTimestamp().toEpochMilli();
resourceDTO.value = resourceSnapshot.getValue().getValue();
if (query.includeMetadata) {
resourceDTO.attributes = generateMetadataDescriptions(resourceSnapshot.getMetadata());
}
serviceDTO.resources.put(resourceSnapshot.getName(), resourceDTO);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;

Expand Down Expand Up @@ -201,7 +200,7 @@ public AbstractResultDTO getSnapshot(final boolean includeMetadata, List<Resourc
final QuerySnapshotDTO query = new QuerySnapshotDTO();
query.uri = new SensinactPath();
query.filter = filter;
query.includeMetadata = Optional.ofNullable(includeMetadata).orElse(false);
query.includeMetadata = includeMetadata;
return handleQuery(query);
}

Expand Down

0 comments on commit 00ec1b2

Please sign in to comment.