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 b69e14aa5ec939ad97b4aa049cdb99c29e25f4aa..d6ac3af26b7fd7ada59ba3f9584ece6ac547245f 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 @@ -24,11 +24,14 @@ import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -350,6 +353,22 @@ public class ServiceRepoService { .orElse(null); } + /** + * @param id + * @param servUpd + * @param triggerServiceActionQueue + * @param updatedFromParentService + * @param updatedFromChildService + * @return + */ + /** + * @param id + * @param servUpd + * @param triggerServiceActionQueue + * @param updatedFromParentService + * @param updatedFromChildService + * @return + */ /** * @param id * @param servUpd @@ -572,6 +591,28 @@ public class ServiceRepoService { } + /** + * Check here if the characteristics changed are of interest for LCM rules and further processing by the orchestrator + */ + Characteristic lcmchar = service.getServiceCharacteristicByName("_LCM_CHARACTERISTICS_"); + if ( lcmchar != null && lcmchar.getValue() != null && !lcmchar.getValue().getValue().equals("all") && !charChangedForNotes.equals("")) { + + // Split the strings into arrays of values + String[] arrayA = lcmchar.getValue().getValue().split(","); + String[] arrayB = charChangedForNotes.split(","); + // Convert strb values into a set for faster lookup + Set setB = new HashSet<>(Arrays.asList(arrayB)); + // Check if any value from stra exists in strb + boolean valueExists = false; + for (String value : arrayA) { + if (setB.contains(value)) { + valueExists = true; // A common value exists + } + } + if (!valueExists) { + serviceCharacteristicChanged=false; + } + } if (charChangedForNotes.contains( "reconciledAt") ) { //this is just a sync message, so we need to igore such changes serviceCharacteristicChanged = false; @@ -597,7 +638,13 @@ public class ServiceRepoService { service = this.serviceRepo.save( service ); - + String requestedServiceAsJson = null; + try { + requestedServiceAsJson = mapper.writeValueAsString( service ); + } catch (JsonProcessingException e) { + logger.error("cannot umarshall service: " + service.getName() ); + e.printStackTrace(); + } /** * Save in ServiceActionQueueItem @@ -617,7 +664,7 @@ public class ServiceRepoService { } if ( saqi.getAction() != ServiceActionQueueAction.NONE ) { - this.addServiceActionQueueItem(saqi); + this.addServiceActionQueueItem(service, saqi); } } @@ -626,13 +673,13 @@ public class ServiceRepoService { if ( stateChanged ) { ServiceActionQueueItem saqi = new ServiceActionQueueItem(); saqi.setServiceRefId( id ); - saqi.setOriginalServiceInJSON( originaServiceAsJson ); + saqi.setOriginalServiceInJSON( originaServiceAsJson ); if ( service.getState().equals( ServiceStateType.ACTIVE) ) { saqi.setAction( ServiceActionQueueAction.EVALUATE_STATE_CHANGE_TOACTIVE ); - this.addServiceActionQueueItem(saqi); + this.addServiceActionQueueItem(service, saqi); }else if ( previousState!=null && previousState.equals( ServiceStateType.ACTIVE) ) { saqi.setAction( ServiceActionQueueAction.EVALUATE_STATE_CHANGE_TOINACTIVE ); - this.addServiceActionQueueItem(saqi); + this.addServiceActionQueueItem(service, saqi); } } @@ -644,7 +691,7 @@ public class ServiceRepoService { if ( serviceCharacteristicChangedContainsPrimitive ) { saqi.setAction( ServiceActionQueueAction.EVALUATE_CHARACTERISTIC_CHANGED_MANODAY2 ); } - this.addServiceActionQueueItem(saqi); + this.addServiceActionQueueItem(service, saqi); } @@ -665,12 +712,12 @@ public class ServiceRepoService { ServiceActionQueueItem saqi = new ServiceActionQueueItem(); // this will trigger lcm rule to parent saqi.setServiceRefId(serviceRelationship.getService().getId()); try { - saqi.setOriginalServiceInJSON( mapper.writeValueAsString( service ) ); //pass the child service as is + saqi.setOriginalServiceInJSON( mapper.writeValueAsString( service ) ); //pass the child service as is } catch (JsonProcessingException e) { e.printStackTrace(); } saqi.setAction(ServiceActionQueueAction.EVALUATE_CHILD_CHARACTERISTIC_CHANGED); - this.addServiceActionQueueItem(saqi); + this.addServiceActionQueueItem(service, saqi); } } @@ -685,7 +732,7 @@ public class ServiceRepoService { e.printStackTrace(); } saqi.setAction(ServiceActionQueueAction.EVALUATE_CHILD_STATE_CHANGE ); - this.addServiceActionQueueItem(saqi); + this.addServiceActionQueueItem(service, saqi); } } @@ -956,17 +1003,20 @@ public class ServiceRepoService { return (List) this.serviceActionQueueRepo.findFirst10ByOrderByInsertedDate(); } - public ServiceActionQueueItem addServiceActionQueueItem(@Valid ServiceActionQueueItem item) { + public ServiceActionQueueItem addServiceActionQueueItem(Service service, @Valid ServiceActionQueueItem item) { logger.debug("Will add ServiceActionQueueItem ServiceRefId: " + item.getServiceRefId() ); + Characteristic lcmchar = service.getServiceCharacteristicByName("_LCM_CHARACTERISTICS_"); + if ( lcmchar == null || lcmchar.getValue() == null) { + //find any similar action inqueue and delete them, so to keep this one as the most recent + List result = this.serviceActionQueueRepo.findByServiceRefIdAndAction(item.getServiceRefId(), item.getAction()); + logger.debug("Will add ServiceActionQueueItem ServiceRefId result: " +result.size() ); + this.serviceActionQueueRepo.deleteByServiceRefIdAndAction(item.getServiceRefId(), item.getAction()); + + } + + return this.serviceActionQueueRepo.save( item); - - //find any similar action inqueue and delete them, so to keep this one as the most recent - List result = this.serviceActionQueueRepo.findByServiceRefIdAndAction(item.getServiceRefId(), item.getAction()); - logger.debug("Will add ServiceActionQueueItem ServiceRefId result: " +result.size() ); - this.serviceActionQueueRepo.deleteByServiceRefIdAndAction(item.getServiceRefId(), item.getAction()); - - return this.serviceActionQueueRepo.save( item); } /** 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 32238e90662ef2c698a79b4dddc2f9207c67c1e1..c647b1090370d8ba4b2319cbaf4bb140e1640407 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 @@ -127,7 +127,10 @@ public class ServiceRepoServiceTest { @Test public void testDeleteServiceActionQueueItemByUuid() throws Exception { ServiceActionQueueItem saqi = new ServiceActionQueueItem(); - ServiceActionQueueItem saqiResponse = serviceRepoService.addServiceActionQueueItem(saqi); + String response = createService(); + Service aservice = JsonUtils.toJsonObj(response, Service.class); + + ServiceActionQueueItem saqiResponse = serviceRepoService.addServiceActionQueueItem(aservice, saqi); String uuid = saqiResponse.getUuid(); serviceRepoService.deleteServiceActionQueueItemByUuid(uuid);