Skip to content

Commit

Permalink
Merge pull request #170 from bci-oss/bug/submodel-fetch-error
Browse files Browse the repository at this point in the history
Bug: Resolved submodel sorting error while fetching
  • Loading branch information
tunacicek authored Jul 21, 2023
2 parents 6325efb + aef64a2 commit 047b1ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.3.11-M1
### Added

## fixed
- In this version, a bug is fixed that occurred while fetching all the submodels for a Shell.

## 0.3.10-M1
### Added
- In this new version, Base64 decoding is provided for the provided encoded parameters. All the provided path parameters has to be Base64 URL encoded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.eclipse.tractusx.semantics.registry.utils;

import java.time.Instant;
import java.util.UUID;

import org.springframework.data.jpa.domain.Specification;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
Expand All @@ -35,17 +37,18 @@ public class ShellSpecification<T> implements Specification<T> {

@Override
public Predicate toPredicate( Root<T> root, CriteriaQuery<?> cq, CriteriaBuilder criteriaBuilder ) {
Predicate predicate = applyFilter( root, criteriaBuilder );
cq.orderBy( criteriaBuilder.asc(criteriaBuilder.coalesce( root.get( sortFieldName ), Instant.now() ) ));
return predicate;
return applyFilter( root,cq, criteriaBuilder );
}

private Predicate applyFilter( Root<T> root, CriteriaBuilder criteriaBuilder ) {
private Predicate applyFilter( Root<T> root,CriteriaQuery<?> cq, CriteriaBuilder criteriaBuilder ) {
if(root.toString().contains( "Shell" )){
var searchValue = shellCursor.getShellSearchCursor();
cq.orderBy( criteriaBuilder.asc( criteriaBuilder.coalesce( root.get( sortFieldName ), Instant.now() ) ) );
return criteriaBuilder.greaterThan( root.get( sortFieldName ), searchValue );
}else{
var searchValue = shellCursor.getSubmodelSearchCursor();
cq.orderBy( criteriaBuilder.asc( criteriaBuilder.coalesce( root.get( sortFieldName ),
UUID.fromString( "00000000-0000-0000-0000-000000000000" )) ) );
return criteriaBuilder.greaterThan( root.get( sortFieldName ), searchValue );
}
}
Expand Down

0 comments on commit 047b1ad

Please sign in to comment.