Loading src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilder.java +4 −10 Original line number Original line Diff line number Diff line Loading @@ -95,14 +95,12 @@ public class ServiceCatalogApiRouteBuilder extends RouteBuilder { from( CATALOG_GET_SERVICECATALOGS ) from( CATALOG_GET_SERVICECATALOGS ) .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATALOGS + " message received!") .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATALOGS + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( catalogRepoService, "findAllEager()") .bean( catalogRepoService, "findAllEager()"); .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); from( CATALOG_GET_SERVICECATALOG_BY_NAME ) from( CATALOG_GET_SERVICECATALOG_BY_NAME ) .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATALOG_BY_NAME + " message received!") .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATALOG_BY_NAME + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( catalogRepoService, "findByNameEager(${header.catalogId})") .bean( catalogRepoService, "findByNameEager(${header.catalogName})") .marshal().json( JsonLibrary.Jackson, String.class) .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); .convertBodyTo( String.class ); Loading @@ -110,9 +108,7 @@ public class ServiceCatalogApiRouteBuilder extends RouteBuilder { from( CATALOG_GET_SERVICECATEGORIES ) from( CATALOG_GET_SERVICECATEGORIES ) .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATEGORIES + " message received!") .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATEGORIES + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( catalogRepoService, "findAllCategoriesByCatalogName(${header.catalogName})") .bean( catalogRepoService, "findAllCategoriesByCatalogName(${header.catalogName})"); .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); from( CATALOG_GET_SERVICECATEGORY_BY_ID ) from( CATALOG_GET_SERVICECATEGORY_BY_ID ) Loading @@ -126,9 +122,7 @@ public class ServiceCatalogApiRouteBuilder extends RouteBuilder { from( CATALOG_GET_SERVICESPECREFS_BYCATEGORY_ID ) from( CATALOG_GET_SERVICESPECREFS_BYCATEGORY_ID ) .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICESPECREFS_BYCATEGORY_ID + " message received!") .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICESPECREFS_BYCATEGORY_ID + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( categoryRepoService, "findAllServiceSpecRefsByCategId(${header.categoryId})") .bean( categoryRepoService, "findAllServiceSpecRefsByCategId(${header.categoryId})"); .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); } } Loading src/main/java/org/etsi/osl/tmf/scm633/api/ServiceSpecificationApiRouteBuilder.java +1 −3 Original line number Original line Diff line number Diff line Loading @@ -127,9 +127,7 @@ public class ServiceSpecificationApiRouteBuilder extends RouteBuilder { from( CATALOG_SEARCH_SERVICESPECREFS ) from( CATALOG_SEARCH_SERVICESPECREFS ) .log(LoggingLevel.INFO, log, CATALOG_SEARCH_SERVICESPECREFS + " message received!") .log(LoggingLevel.INFO, log, CATALOG_SEARCH_SERVICESPECREFS + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( serviceSpecificationRepoService, "searchServiceSpecRefs(${header.searchText})") .bean( serviceSpecificationRepoService, "searchServiceSpecRefs(${header.searchText})"); .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); } } Loading src/main/java/org/etsi/osl/tmf/scm633/reposervices/CatalogRepoService.java +4 −2 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,7 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.Transaction; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory; import jakarta.validation.Valid; import jakarta.validation.Valid; Loading Loading @@ -241,8 +242,9 @@ public class CatalogRepoService { * return recursively all categories in catalog * return recursively all categories in catalog * @param catalogName * @param catalogName */ */ @Transactional public String findAllCategoriesByCatalogName(String catalogName) { public String findAllCategoriesByCatalogName(String catalogName) { String res="{}"; String res="[]"; Optional<ServiceCatalog> scopt = this.catalogRepo.findByName(catalogName); Optional<ServiceCatalog> scopt = this.catalogRepo.findByName(catalogName); Loading @@ -268,7 +270,6 @@ public class CatalogRepoService { } catch (JsonProcessingException e) { } catch (JsonProcessingException e) { // TODO Auto-generated catch block // TODO Auto-generated catch block e.printStackTrace(); e.printStackTrace(); return "{}"; } } Loading @@ -277,6 +278,7 @@ public class CatalogRepoService { } } @Transactional private List<ServiceCategory> getCategories( @Valid List<ServiceCategoryRef> list) { private List<ServiceCategory> getCategories( @Valid List<ServiceCategoryRef> list) { List<ServiceCategory> categories = new ArrayList<ServiceCategory>(); List<ServiceCategory> categories = new ArrayList<ServiceCategory>(); Loading src/main/java/org/etsi/osl/tmf/scm633/reposervices/CategoryRepoService.java +9 −1 Original line number Original line Diff line number Diff line Loading @@ -52,6 +52,7 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.Transaction; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory; import jakarta.validation.Valid; import jakarta.validation.Valid; Loading Loading @@ -151,10 +152,18 @@ public class CategoryRepoService { @Transactional public String findAllServiceSpecRefsByCategId(String categoryId) { public String findAllServiceSpecRefsByCategId(String categoryId) { String res="[]"; List<ServiceSpecificationRef> serviceSpecificationRefList = new ArrayList<>(); List<ServiceSpecificationRef> serviceSpecificationRefList = new ArrayList<>(); ServiceCategory category = this.findByUuid(categoryId); ServiceCategory category = this.findByUuid(categoryId); if ( category == null ) { return res; } Set<ServiceCandidate> serviceCands = category.getServiceCandidateObj(); Set<ServiceCandidate> serviceCands = category.getServiceCandidateObj(); for (ServiceCandidate serviceCandidate : serviceCands) { for (ServiceCandidate serviceCandidate : serviceCands) { Loading @@ -169,7 +178,6 @@ public class CategoryRepoService { // this will fetch all lazy objects before marshaling // this will fetch all lazy objects before marshaling mapper.registerModule(new Hibernate5JakartaModule()); mapper.registerModule(new Hibernate5JakartaModule()); String res="{}"; try { try { res = mapper.writeValueAsString( serviceSpecificationRefList ); res = mapper.writeValueAsString( serviceSpecificationRefList ); } catch (JsonProcessingException e) { } catch (JsonProcessingException e) { Loading src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java +104 −12 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,7 @@ import java.util.List; import java.util.Map; import java.util.Map; import java.util.Optional; import java.util.Optional; import java.util.UUID; import java.util.UUID; import java.util.stream.Collectors; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.hibernate5.jakarta.Hibernate5JakartaModule; import com.fasterxml.jackson.datatype.hibernate5.jakarta.Hibernate5JakartaModule; Loading Loading @@ -62,6 +63,7 @@ import org.etsi.osl.tmf.scm633.api.ServiceSpecificationApiRouteBuilderNSD; import org.etsi.osl.tmf.scm633.model.ServiceCandidate; import org.etsi.osl.tmf.scm633.model.ServiceCandidate; import org.etsi.osl.tmf.scm633.model.ServiceCandidateCreate; import org.etsi.osl.tmf.scm633.model.ServiceCandidateCreate; import org.etsi.osl.tmf.scm633.model.ServiceCandidateUpdate; import org.etsi.osl.tmf.scm633.model.ServiceCandidateUpdate; import org.etsi.osl.tmf.scm633.model.ServiceCategory; import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristic; import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristic; import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristicValue; import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristicValue; import org.etsi.osl.tmf.scm633.model.ServiceSpecRelationship; import org.etsi.osl.tmf.scm633.model.ServiceSpecRelationship; Loading Loading @@ -209,12 +211,14 @@ public class ServiceSpecificationRepoService { } } sql += " FROM ServiceSpecification s"; sql += " FROM ServiceSpecification s"; if (allParams.size() > 0) { if (allParams.size() > 0) { sql += " WHERE "; for (String pname : allParams.keySet()) { sql += " " + pname + " LIKE "; String pval = URLDecoder.decode(allParams.get(pname), StandardCharsets.UTF_8.toString()); String items = allParams.entrySet() sql += "'" + pval + "'"; .stream() } .map(entry -> "s." + entry.getKey() + " LIKE '%" + URLDecoder.decode( entry.getValue(), StandardCharsets.UTF_8 )+ "%'" ) .collect(Collectors.joining(" OR ")); sql += " WHERE " + items; } } sql += " ORDER BY s.name"; sql += " ORDER BY s.name"; Loading @@ -230,10 +234,10 @@ public class ServiceSpecificationRepoService { Map<String, Object> result = new LinkedHashMap<String, Object>(tuple.length); Map<String, Object> result = new LinkedHashMap<String, Object>(tuple.length); for (int i = 0; i < tuple.length; i++) { for (int i = 0; i < tuple.length; i++) { String alias = aliases[i]; String alias = aliases[i]; if (alias != null) { if (alias.equals("type")) { if (alias.equals("type")) { alias = "@type"; alias = "@type"; } } if (alias != null) { result.put(alias, tuple[i]); result.put(alias, tuple[i]); } } } } Loading Loading @@ -271,6 +275,10 @@ public class ServiceSpecificationRepoService { } } // @Transactional(propagation=Propagation.REQUIRED , readOnly=true, // @Transactional(propagation=Propagation.REQUIRED , readOnly=true, // noRollbackFor=Exception.class) // noRollbackFor=Exception.class) public ServiceSpecification findByUuid(String id) { public ServiceSpecification findByUuid(String id) { Loading Loading @@ -1463,12 +1471,16 @@ public class ServiceSpecificationRepoService { return serviceSpecCharacteristicItem; return serviceSpecCharacteristicItem; } } @Transactional public String searchServiceSpecRefs(String searchText) { public String searchServiceSpecRefs(String searchText) { String res = "{}"; String res = "[]"; Map<String, String> criteria = new HashMap<>(); Map<String, String> criteria = new HashMap<>(); try { try { List<ServiceSpecification> specs= this.findAll(res, criteria); criteria.put("name", searchText); criteria.put("description", searchText); List<String> specs= this.searchSpecsInCategories( null, criteria); ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper(); // Registering Hibernate4Module to support lazy objects // Registering Hibernate4Module to support lazy objects Loading @@ -1488,5 +1500,85 @@ public class ServiceSpecificationRepoService { } } /** * * This findAll is optimized on fields. * @param fields * @param allParams * @return * @throws UnsupportedEncodingException */ @Transactional public List searchSpecsInCategories(@Valid String fields, Map<String, String> allParams) throws UnsupportedEncodingException { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List<ServiceCategory> alist = null; try { String sql = "SELECT s.id as serviceSpecificationId, s.name as serviceName, s.description as serviceDescription"; sql += " FROM ServiceCategory as scateg JOIN scateg.serviceCandidateObj as scandidate JOIN scandidate.serviceSpecificationObj as s "; if (allParams.size() > 0) { String items = allParams.entrySet() .stream() .map(entry -> "s." + entry.getKey() + " LIKE '%" + URLDecoder.decode( entry.getValue(), StandardCharsets.UTF_8 )+ "%'" ) .collect(Collectors.joining(" OR ")); sql += " WHERE " + items; } sql += " ORDER BY s.name"; // List<ServiceSpecification> specs = session // .createQuery( sql, ServiceSpecification.class) // .getResultList(); List<Object> mapaEntity = session .createQuery(sql ) .setResultTransformer( new ResultTransformer() { @Override public Object transformTuple(Object[] tuple, String[] aliases) { Map<String, Object> result = new LinkedHashMap<String, Object>(tuple.length); for (int i = 0; i < tuple.length; i++) { String alias = aliases[i]; if (alias != null) { if (alias.equals("type")) { alias = "@type"; } result.put(alias, tuple[i]); } } return result; } @Override public List transformList(List collection) { return collection; } } ) .list(); // //this will fetch the whole object fields return mapaEntity; } finally { tx.commit(); session.close(); } } } } Loading
src/main/java/org/etsi/osl/tmf/scm633/api/ServiceCatalogApiRouteBuilder.java +4 −10 Original line number Original line Diff line number Diff line Loading @@ -95,14 +95,12 @@ public class ServiceCatalogApiRouteBuilder extends RouteBuilder { from( CATALOG_GET_SERVICECATALOGS ) from( CATALOG_GET_SERVICECATALOGS ) .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATALOGS + " message received!") .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATALOGS + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( catalogRepoService, "findAllEager()") .bean( catalogRepoService, "findAllEager()"); .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); from( CATALOG_GET_SERVICECATALOG_BY_NAME ) from( CATALOG_GET_SERVICECATALOG_BY_NAME ) .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATALOG_BY_NAME + " message received!") .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATALOG_BY_NAME + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( catalogRepoService, "findByNameEager(${header.catalogId})") .bean( catalogRepoService, "findByNameEager(${header.catalogName})") .marshal().json( JsonLibrary.Jackson, String.class) .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); .convertBodyTo( String.class ); Loading @@ -110,9 +108,7 @@ public class ServiceCatalogApiRouteBuilder extends RouteBuilder { from( CATALOG_GET_SERVICECATEGORIES ) from( CATALOG_GET_SERVICECATEGORIES ) .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATEGORIES + " message received!") .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICECATEGORIES + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( catalogRepoService, "findAllCategoriesByCatalogName(${header.catalogName})") .bean( catalogRepoService, "findAllCategoriesByCatalogName(${header.catalogName})"); .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); from( CATALOG_GET_SERVICECATEGORY_BY_ID ) from( CATALOG_GET_SERVICECATEGORY_BY_ID ) Loading @@ -126,9 +122,7 @@ public class ServiceCatalogApiRouteBuilder extends RouteBuilder { from( CATALOG_GET_SERVICESPECREFS_BYCATEGORY_ID ) from( CATALOG_GET_SERVICESPECREFS_BYCATEGORY_ID ) .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICESPECREFS_BYCATEGORY_ID + " message received!") .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICESPECREFS_BYCATEGORY_ID + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( categoryRepoService, "findAllServiceSpecRefsByCategId(${header.categoryId})") .bean( categoryRepoService, "findAllServiceSpecRefsByCategId(${header.categoryId})"); .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); } } Loading
src/main/java/org/etsi/osl/tmf/scm633/api/ServiceSpecificationApiRouteBuilder.java +1 −3 Original line number Original line Diff line number Diff line Loading @@ -127,9 +127,7 @@ public class ServiceSpecificationApiRouteBuilder extends RouteBuilder { from( CATALOG_SEARCH_SERVICESPECREFS ) from( CATALOG_SEARCH_SERVICESPECREFS ) .log(LoggingLevel.INFO, log, CATALOG_SEARCH_SERVICESPECREFS + " message received!") .log(LoggingLevel.INFO, log, CATALOG_SEARCH_SERVICESPECREFS + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( serviceSpecificationRepoService, "searchServiceSpecRefs(${header.searchText})") .bean( serviceSpecificationRepoService, "searchServiceSpecRefs(${header.searchText})"); .marshal().json( JsonLibrary.Jackson, String.class) .convertBodyTo( String.class ); } } Loading
src/main/java/org/etsi/osl/tmf/scm633/reposervices/CatalogRepoService.java +4 −2 Original line number Original line Diff line number Diff line Loading @@ -43,6 +43,7 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.Transaction; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory; import jakarta.validation.Valid; import jakarta.validation.Valid; Loading Loading @@ -241,8 +242,9 @@ public class CatalogRepoService { * return recursively all categories in catalog * return recursively all categories in catalog * @param catalogName * @param catalogName */ */ @Transactional public String findAllCategoriesByCatalogName(String catalogName) { public String findAllCategoriesByCatalogName(String catalogName) { String res="{}"; String res="[]"; Optional<ServiceCatalog> scopt = this.catalogRepo.findByName(catalogName); Optional<ServiceCatalog> scopt = this.catalogRepo.findByName(catalogName); Loading @@ -268,7 +270,6 @@ public class CatalogRepoService { } catch (JsonProcessingException e) { } catch (JsonProcessingException e) { // TODO Auto-generated catch block // TODO Auto-generated catch block e.printStackTrace(); e.printStackTrace(); return "{}"; } } Loading @@ -277,6 +278,7 @@ public class CatalogRepoService { } } @Transactional private List<ServiceCategory> getCategories( @Valid List<ServiceCategoryRef> list) { private List<ServiceCategory> getCategories( @Valid List<ServiceCategoryRef> list) { List<ServiceCategory> categories = new ArrayList<ServiceCategory>(); List<ServiceCategory> categories = new ArrayList<ServiceCategory>(); Loading
src/main/java/org/etsi/osl/tmf/scm633/reposervices/CategoryRepoService.java +9 −1 Original line number Original line Diff line number Diff line Loading @@ -52,6 +52,7 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.Transaction; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory; import jakarta.validation.Valid; import jakarta.validation.Valid; Loading Loading @@ -151,10 +152,18 @@ public class CategoryRepoService { @Transactional public String findAllServiceSpecRefsByCategId(String categoryId) { public String findAllServiceSpecRefsByCategId(String categoryId) { String res="[]"; List<ServiceSpecificationRef> serviceSpecificationRefList = new ArrayList<>(); List<ServiceSpecificationRef> serviceSpecificationRefList = new ArrayList<>(); ServiceCategory category = this.findByUuid(categoryId); ServiceCategory category = this.findByUuid(categoryId); if ( category == null ) { return res; } Set<ServiceCandidate> serviceCands = category.getServiceCandidateObj(); Set<ServiceCandidate> serviceCands = category.getServiceCandidateObj(); for (ServiceCandidate serviceCandidate : serviceCands) { for (ServiceCandidate serviceCandidate : serviceCands) { Loading @@ -169,7 +178,6 @@ public class CategoryRepoService { // this will fetch all lazy objects before marshaling // this will fetch all lazy objects before marshaling mapper.registerModule(new Hibernate5JakartaModule()); mapper.registerModule(new Hibernate5JakartaModule()); String res="{}"; try { try { res = mapper.writeValueAsString( serviceSpecificationRefList ); res = mapper.writeValueAsString( serviceSpecificationRefList ); } catch (JsonProcessingException e) { } catch (JsonProcessingException e) { Loading
src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java +104 −12 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,7 @@ import java.util.List; import java.util.Map; import java.util.Map; import java.util.Optional; import java.util.Optional; import java.util.UUID; import java.util.UUID; import java.util.stream.Collectors; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.hibernate5.jakarta.Hibernate5JakartaModule; import com.fasterxml.jackson.datatype.hibernate5.jakarta.Hibernate5JakartaModule; Loading Loading @@ -62,6 +63,7 @@ import org.etsi.osl.tmf.scm633.api.ServiceSpecificationApiRouteBuilderNSD; import org.etsi.osl.tmf.scm633.model.ServiceCandidate; import org.etsi.osl.tmf.scm633.model.ServiceCandidate; import org.etsi.osl.tmf.scm633.model.ServiceCandidateCreate; import org.etsi.osl.tmf.scm633.model.ServiceCandidateCreate; import org.etsi.osl.tmf.scm633.model.ServiceCandidateUpdate; import org.etsi.osl.tmf.scm633.model.ServiceCandidateUpdate; import org.etsi.osl.tmf.scm633.model.ServiceCategory; import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristic; import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristic; import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristicValue; import org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristicValue; import org.etsi.osl.tmf.scm633.model.ServiceSpecRelationship; import org.etsi.osl.tmf.scm633.model.ServiceSpecRelationship; Loading Loading @@ -209,12 +211,14 @@ public class ServiceSpecificationRepoService { } } sql += " FROM ServiceSpecification s"; sql += " FROM ServiceSpecification s"; if (allParams.size() > 0) { if (allParams.size() > 0) { sql += " WHERE "; for (String pname : allParams.keySet()) { sql += " " + pname + " LIKE "; String pval = URLDecoder.decode(allParams.get(pname), StandardCharsets.UTF_8.toString()); String items = allParams.entrySet() sql += "'" + pval + "'"; .stream() } .map(entry -> "s." + entry.getKey() + " LIKE '%" + URLDecoder.decode( entry.getValue(), StandardCharsets.UTF_8 )+ "%'" ) .collect(Collectors.joining(" OR ")); sql += " WHERE " + items; } } sql += " ORDER BY s.name"; sql += " ORDER BY s.name"; Loading @@ -230,10 +234,10 @@ public class ServiceSpecificationRepoService { Map<String, Object> result = new LinkedHashMap<String, Object>(tuple.length); Map<String, Object> result = new LinkedHashMap<String, Object>(tuple.length); for (int i = 0; i < tuple.length; i++) { for (int i = 0; i < tuple.length; i++) { String alias = aliases[i]; String alias = aliases[i]; if (alias != null) { if (alias.equals("type")) { if (alias.equals("type")) { alias = "@type"; alias = "@type"; } } if (alias != null) { result.put(alias, tuple[i]); result.put(alias, tuple[i]); } } } } Loading Loading @@ -271,6 +275,10 @@ public class ServiceSpecificationRepoService { } } // @Transactional(propagation=Propagation.REQUIRED , readOnly=true, // @Transactional(propagation=Propagation.REQUIRED , readOnly=true, // noRollbackFor=Exception.class) // noRollbackFor=Exception.class) public ServiceSpecification findByUuid(String id) { public ServiceSpecification findByUuid(String id) { Loading Loading @@ -1463,12 +1471,16 @@ public class ServiceSpecificationRepoService { return serviceSpecCharacteristicItem; return serviceSpecCharacteristicItem; } } @Transactional public String searchServiceSpecRefs(String searchText) { public String searchServiceSpecRefs(String searchText) { String res = "{}"; String res = "[]"; Map<String, String> criteria = new HashMap<>(); Map<String, String> criteria = new HashMap<>(); try { try { List<ServiceSpecification> specs= this.findAll(res, criteria); criteria.put("name", searchText); criteria.put("description", searchText); List<String> specs= this.searchSpecsInCategories( null, criteria); ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper(); // Registering Hibernate4Module to support lazy objects // Registering Hibernate4Module to support lazy objects Loading @@ -1488,5 +1500,85 @@ public class ServiceSpecificationRepoService { } } /** * * This findAll is optimized on fields. * @param fields * @param allParams * @return * @throws UnsupportedEncodingException */ @Transactional public List searchSpecsInCategories(@Valid String fields, Map<String, String> allParams) throws UnsupportedEncodingException { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List<ServiceCategory> alist = null; try { String sql = "SELECT s.id as serviceSpecificationId, s.name as serviceName, s.description as serviceDescription"; sql += " FROM ServiceCategory as scateg JOIN scateg.serviceCandidateObj as scandidate JOIN scandidate.serviceSpecificationObj as s "; if (allParams.size() > 0) { String items = allParams.entrySet() .stream() .map(entry -> "s." + entry.getKey() + " LIKE '%" + URLDecoder.decode( entry.getValue(), StandardCharsets.UTF_8 )+ "%'" ) .collect(Collectors.joining(" OR ")); sql += " WHERE " + items; } sql += " ORDER BY s.name"; // List<ServiceSpecification> specs = session // .createQuery( sql, ServiceSpecification.class) // .getResultList(); List<Object> mapaEntity = session .createQuery(sql ) .setResultTransformer( new ResultTransformer() { @Override public Object transformTuple(Object[] tuple, String[] aliases) { Map<String, Object> result = new LinkedHashMap<String, Object>(tuple.length); for (int i = 0; i < tuple.length; i++) { String alias = aliases[i]; if (alias != null) { if (alias.equals("type")) { alias = "@type"; } result.put(alias, tuple[i]); } } return result; } @Override public List transformList(List collection) { return collection; } } ) .list(); // //this will fetch the whole object fields return mapaEntity; } finally { tx.commit(); session.close(); } } } }