From c0cbfd01a2516c268bde5dfaefa37910e7066ca8 Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Fri, 20 Dec 2024 11:42:17 +0200 Subject: [PATCH 1/2] fix for #61 --- .../reposervices/ResourceRepoService.java | 1 - .../sim638/api/ServiceApiRouteBuilder.java | 26 ++-- .../sim638/service/ServiceRepoService.java | 132 +++--------------- 3 files changed, 31 insertions(+), 128 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceRepoService.java b/src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceRepoService.java index 7f52235..e3f0f4c 100644 --- a/src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceRepoService.java +++ b/src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceRepoService.java @@ -449,7 +449,6 @@ public class ResourceRepoService { resource = this.resourceRepo.save(resource); - this.serviceRepoService.updateServicesHavingThisSupportingResource(resource); if (resourceCharacteristicChanged) { raiseResourceAttributeValueChangeEventNotification(resource); diff --git a/src/main/java/org/etsi/osl/tmf/sim638/api/ServiceApiRouteBuilder.java b/src/main/java/org/etsi/osl/tmf/sim638/api/ServiceApiRouteBuilder.java index 84645c5..9373f79 100644 --- a/src/main/java/org/etsi/osl/tmf/sim638/api/ServiceApiRouteBuilder.java +++ b/src/main/java/org/etsi/osl/tmf/sim638/api/ServiceApiRouteBuilder.java @@ -224,19 +224,19 @@ public class ServiceApiRouteBuilder extends RouteBuilder { -// from( EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED ) -// .errorHandler(deadLetterChannel("direct:retriesDeadLetters") -// .maximumRedeliveries(5) -// .redeliveryDelay(1000).useOriginalMessage() -// .logExhausted(true) -// .logHandled(true) -// .retriesExhaustedLogLevel(LoggingLevel.ERROR) -// .retryAttemptedLogLevel(LoggingLevel.ERROR)) -// -// .log(LoggingLevel.INFO, log, EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED + " message received and will be processed for service inventory!") -// .to("log:DEBUG?showBody=true&showHeaders=true") -// .unmarshal().json( JsonLibrary.Jackson, ResourceAttributeValueChangeNotification.class, true) -// .bean( serviceRepoService, "resourceAttrChangedEvent(${body})"); + from( EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED ) + .errorHandler(deadLetterChannel("direct:retriesDeadLetters") + .maximumRedeliveries(5) + .redeliveryDelay(1000).useOriginalMessage() + .logExhausted(true) + .logHandled(true) + .retriesExhaustedLogLevel(LoggingLevel.ERROR) + .retryAttemptedLogLevel(LoggingLevel.ERROR)) + + .log(LoggingLevel.DEBUG, log, EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED + " message received and will be processed for service inventory!") + .to("log:DEBUG?showBody=true&showHeaders=true") + .unmarshal().json( JsonLibrary.Jackson, ResourceAttributeValueChangeNotification.class, true) + .bean( serviceRepoService, "resourceAttrChangedEvent(${body})"); diff --git a/src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java b/src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java index b439bc9..f28905b 100644 --- a/src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java +++ b/src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java @@ -340,26 +340,6 @@ public class ServiceRepoService { noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); s.addNoteItem(noteItem); - // double characteristic investigation - // - // - // int cnt = 0; - // if ( service.getServiceCharacteristic()!=null) - // for (Characteristic ch : service.getServiceCharacteristic()) { - // if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { - // cnt++; - // } - // if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { - // logger.debug("=============================================> FOUND CHARACTERISTIC addService AdditionPropertiesAsJson IN addService" ); - // logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); - // } - // } - - // if ( cnt>1) { - // logger.debug("=============================================> FOUND CHARACTERISTIC TWICE AFTER service addService" ); - - // } - s = this.serviceRepo.save( s ); raiseServiceCreateNotification(s); @@ -385,23 +365,15 @@ public class ServiceRepoService { */ @Transactional public Service updateService(String id, @Valid ServiceUpdate servUpd, boolean triggerServiceActionQueue, Service updatedFromParentService, Service updatedFromChildService ) { - - logger.debug("================> Will updateService = " + id ); - //Service service = this.findByUuid(id); Service service = this.getServiceEager(id); - if ( service == null ) { logger.error("Service cannot be found in registry, UUID: " + id ); return null; } - - - logger.info("Will update service: " + service.getName() ); - //logger.info("Will update service details: " + s.toString() ); ObjectMapper mapper = new ObjectMapper(); String originaServiceAsJson = null; @@ -412,43 +384,6 @@ public class ServiceRepoService { e.printStackTrace(); } - // double characteristic investigation - // - // - // int cnt = 0; - // if ( servUpd.getServiceCharacteristic() != null ) { - // for (Characteristic ch1 : servUpd.getServiceCharacteristic()) { - // if ( ch1.getName().equals( "org.etsi.osl.prefixName" ) ) { - // cnt++; - // } - // if ( ch1.getName().equals( "AdditionPropertiesAsJson" ) ) { - // logger.debug("=============================================> FOUND CHARACTERISTIC AdditionPropertiesAsJson IN servUpd" ); - // logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch1.getValue().getValue().length() ); - // } - - // } - - // if ( cnt>1) { - // logger.debug("=============================================> FOUND CHARACTERISTIC TWICE servUpd updateService servUpd" ); - - // } - // } - // cnt = 0; - // for (Characteristic ch : service.getServiceCharacteristic()) { - // if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { - // cnt++; - // } - // if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { - // logger.debug("=============================================> FOUND CHARACTERISTIC AdditionPropertiesAsJson IN service" ); - // logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); - // } - // } - - // if ( cnt>1) { - // logger.debug("=============================================> FOUND CHARACTERISTIC TWICE service updateService service" ); - - // } - if (servUpd.getType()!=null) { service.setType(servUpd.getType()); @@ -497,8 +432,12 @@ public class ServiceRepoService { boolean stateChanged = false; ServiceStateType previousState = service.getState(); if (servUpd.getState() != null ) { + logger.debug("=============SERVICE STATE == previousState => " + service.getState() +", " + servUpd.getName()); + logger.debug("=============SERVICE STATE == newState ======> " + servUpd.getState() +", " + service.getName()); + stateChanged = service.getState() != servUpd.getState(); service.setState(servUpd.getState()); + } if (servUpd.getServiceSpecificationRef() != null ) { @@ -539,10 +478,6 @@ public class ServiceRepoService { boolean serviceCharacteristicChangedContainsNSLCM; String charChangedForNotes = ""; - //List childCharacteristicsChanged = new ArrayList<>(); - - - //logger.info("==> Will update serviceToString: " + service.toString() ); if ( servUpd.getServiceCharacteristic()!=null ) { @@ -590,20 +525,7 @@ public class ServiceRepoService { } else { service.addServiceCharacteristicItem(n); - - // double characteristic investigation - // - // - // if ( n.getName().equals( "AdditionPropertiesAsJson" ) ) { - // logger.debug("=============================================> ADDING AdditionPropertiesAsJson to service" ); - // if ( n.getValue()!=null ) { - // logger.debug("=============================================> ADDING AdditionPropertiesAsJson charlength=" + n.getValue().getValue().length() ); - // } else { - - // logger.debug("=============================================> ADDING AdditionPropertiesAsJson charlength=NULL" ); - // } - - // } + if ( !n.getName().contains("::") ) { //it is not a child characteristic serviceCharacteristicChanged = true; charChangedForNotes += n.getName() + ", "; @@ -651,7 +573,6 @@ public class ServiceRepoService { noteItem.setAuthor("SIM-638"); noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); service.addNoteItem(noteItem); - logger.debug("=============SERVICE STATE ================================> " + service.getState() ); } @@ -702,24 +623,7 @@ public class ServiceRepoService { service = this.serviceRepo.save( service ); - // double characteristic investigation - // - // - // cnt = 0; - // for (Characteristic ch : service.getServiceCharacteristic()) { - // if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { - // cnt++; - // } - // if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { - // logger.debug("=============================================> FOUND CHARACTERISTIC AFTER AdditionPropertiesAsJson IN service" ); - // logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); - // } - // } - - // if ( cnt>1) { - // logger.debug("=============================================> FOUND CHARACTERISTIC TWICE AFTER service updateService service" ); - - // } + String requestedServiceAsJson = null; try { @@ -958,17 +862,6 @@ public class ServiceRepoService { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new Hibernate5JakartaModule()); String res = mapper.writeValueAsString(s); - - - // Characteristic schart = s.getServiceCharacteristicByName("long_string"); - - // if ( schart!= null ) { - // String teest = schart.getValue().getValue(); - // logger.debug("schart size = " + teest.length() ); - - // logger.debug("schart " + teest ); - // logger.debug("======================================================================================================"); - // } return res; } @@ -1313,7 +1206,7 @@ public class ServiceRepoService { if (! servChar.getValue().getValue().equals( rChar.getValue().getValue() ) ) { characteristicFoundDifferent = true; supd.getServiceCharacteristicByName( characteristicname ) .value(new Any( rChar.getValue() )); - logger.debug("====================> add characteristic: " + characteristicname +", value: "+ rChar.getValue().getValue()); + logger.debug("====================> update characteristic: " + characteristicname +", value: "+ rChar.getValue().getValue()); } } else { @@ -1385,7 +1278,18 @@ public class ServiceRepoService { }catch (Exception e) { e.printStackTrace(); } + } + @Transactional + public void resourceAttrChangedEvent(@Valid ResourceAttributeValueChangeNotification resNotif) { + try { + Resource res = resNotif.getEvent().getEvent().getResource(); + logger.debug("resourceAttrChangedEvent for: " + res.getName()); + updateServiceFromresourceChange(res); + }catch (Exception e) { + e.printStackTrace(); + } + } @Transactional -- GitLab From 8dbd61c2cccb502a56be846622d3628249507416 Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Fri, 20 Dec 2024 12:03:56 +0200 Subject: [PATCH 2/2] fix for #61 --- .../services/api/sim638/ServiceRepoServiceTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java b/src/test/java/org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java index 99e752a..243915a 100644 --- a/src/test/java/org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java +++ b/src/test/java/org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java @@ -287,11 +287,7 @@ public class ServiceRepoServiceTest { - @Valid ResourceAttributeValueChangeNotification resNotid = new ResourceAttributeValueChangeNotification(); - ResourceAttributeValueChangeEvent event = new ResourceAttributeValueChangeEvent(); - event.getEvent().setResource(resource); - - resNotid.setEvent( event ); + Service updatedService = serviceRepoService.findByUuid(id); @@ -324,10 +320,14 @@ public class ServiceRepoServiceTest { Thread.sleep(1000); System.out.println("STEP 3 - =========================================== " ); + + serviceRepoService.updateServicesHavingThisSupportingResource(nullResource); + updatedService = serviceRepoService.findByUuid(id); assertThat( updatedService.getSupportingResource().size() ).isEqualTo( 1); assertThat( updatedService.getServiceCharacteristic().size() ).isEqualTo( 8 ); + Set noteSet = updatedService.getNote(); List noteList = new ArrayList<>(noteSet); -- GitLab