Commit 92e6aa4c authored by Kostis Trantzas's avatar Kostis Trantzas
Browse files

Merge branch 'issue_61' into 'develop'

MR: Issue_61 to develop

See merge request !54
parents a3371479 76a337df
Loading
Loading
Loading
Loading
Loading
+126 −67
Original line number Diff line number Diff line
@@ -1118,8 +1118,14 @@ public class ServiceRepoService {
	public void  updateServicesHavingThisSupportingResource(@Valid Resource res) {
      try {
        
        if (res.getResourceStatus()==null){
          logger.debug("================> updateServicesHavingThisSupportingResource resource status NULL");     
          return;
        }
        
        logger.debug("================> Will update services related to this resource with id = " + res.getId() );        
        var aservices = findServicesHavingThisSupportingResourceID(  res.getId() );
        logger.debug("================> Services found = " + aservices.size() );     
        
        for (Service as : aservices) {
            
@@ -1127,10 +1133,18 @@ public class ServiceRepoService {

              ServiceStateType nextState =  aService.getState();
              List<Resource> rlist = new ArrayList<Resource>();
              rlist.add(res);
              
              for (ResourceRef rref : aService.getSupportingResource()) {
                if (!rref.getId().equals( res.getId())) {
                  Optional<Resource> result = resourceRepo.findByUuid(rref.getId());
                  if (result.isPresent()) {
                    rlist.add( result.get() );
                    if ( result.get().getResourceStatus()==null){
                      logger.debug("================> updateServicesHavingThisSupportingResource resource status NULL for resource: "+ result.get().getName()  );     
                      return;
                    }
                  }                  
                }
              }
              
@@ -1139,6 +1153,96 @@ public class ServiceRepoService {
              /*
               * Construct characteristic name
               */

              

              
              
              Boolean stateChaged = false;
              ServiceUpdate supd = new ServiceUpdate();
              nextState = aService.findNextStateBasedOnResourceList(rlist);
              supd.setState(nextState);
              String stateText="";
              if ( !aService.getState().equals(nextState)) {
                stateChaged = true;
                stateText = "State changed from " + aService.getState() + " to " + nextState + ".";
                logger.debug("====================>  stateText = " + stateText);
              }
              for (Resource r : rlist) {
                logger.debug("==================> state: ="+  r.getResourceStatus().name() + ", "+  r.getName() );
                
              }
              
              //adding all characteristics from service
              for (Characteristic ch : aService.getServiceCharacteristic()) {
                supd.addServiceCharacteristicItem(ch);
                
                
              }
              
              
              CharCopyResult result = new CharCopyResult(supd, false);
              
              if ( nextState == ServiceStateType.ACTIVE) {
                if ( !aService.getState().equals(nextState) && nextState == ServiceStateType.ACTIVE) {
                  result = copyCharacteristicsFromAllResources(aService, supd, rlist);                  
                } else {
                  result = copyCharacteristicsFromResource(aService, supd, res);
                }
              }
              
              
                



                
              if ( stateChaged || result.characteristicFoundDifferent) {
                Characteristic noteCheck = as.getServiceCharacteristicByName("_DETAILED_NOTES_");
                if ( noteCheck!= null 
                    && noteCheck.getValue() != null
                    && noteCheck.getValue().getValue() != null
                    && !noteCheck.getValue().getValue().equals("")) {
                  Note n = new Note();
                  n.setText(stateText + "Supporting Resource changed with id: " + res.getId());
                  n.setAuthor( "SIM638-API" );
                  n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() );
                  result.supd.addNoteItem( n );                  
                }               
                
                this.updateService( aService.getId(), result.supd , true, null, null); //update the service 
                
              }

        }
      

      }catch (Exception e) {
        e.printStackTrace();
      }
      
    }
    
    private record CharCopyResult(ServiceUpdate supd, Boolean characteristicFoundDifferent) {
      
    }
    
    private CharCopyResult copyCharacteristicsFromAllResources(Service aService, ServiceUpdate supd, List<Resource> rlist) {
      Boolean characteristicFoundDifferent = false;
      CharCopyResult copyresult = new CharCopyResult(supd, characteristicFoundDifferent);
      for (Resource r : rlist) {
        copyresult = copyCharacteristicsFromResource(aService, copyresult.supd, r);
        characteristicFoundDifferent = characteristicFoundDifferent || copyresult.characteristicFoundDifferent;
      }
      
      CharCopyResult result = new CharCopyResult(copyresult.supd, copyresult.characteristicFoundDifferent);
      return result ;
    }
    
    
    private CharCopyResult copyCharacteristicsFromResource( @Valid Service aService, @Valid ServiceUpdate supd, @Valid Resource res) {

      Boolean characteristicFoundDifferent = false;
      String kind = "";
      String resourcename = res.getName() ;
      
@@ -1169,30 +1273,6 @@ public class ServiceRepoService {
        resourcename = resourcename + ".";
      }
      
              
              Boolean stateChaged = false;
              ServiceUpdate supd = new ServiceUpdate();
              nextState = aService.findNextStateBasedOnResourceList(rlist);
              supd.setState(nextState);
              String stateText="";
              if ( !aService.getState().equals(nextState)) {
                stateChaged = true;
                stateText = "State changed from " + aService.getState() + " to " + nextState + ".";
                logger.debug("====================>  stateText = " + stateText);
                for (Resource r : rlist) {
                  logger.debug("==================>  r:{}, state:{} ="+  r.getName() + ", "+  r.getResourceStatus().name());
                  
                }
              }
              
              //adding all characteristics from service
              for (Characteristic ch : aService.getServiceCharacteristic()) {
                supd.addServiceCharacteristicItem(ch);
                
                
              }
              
              Boolean characteristicFoundDifferent =false;
      String dontCopyChars = "clusterMasterURL,currentContextCluster,fullResourceName,Kind,apiGroup,UID,metadata";
      String[] arrayDontCopyChars = dontCopyChars.split(",");
      Set<String> setB = new HashSet<>(Arrays.asList(arrayDontCopyChars));
@@ -1222,36 +1302,15 @@ public class ServiceRepoService {
          }                  
        }
            
              }
      };
      
      
              if ( stateChaged || characteristicFoundDifferent) {
                Characteristic noteCheck = as.getServiceCharacteristicByName("_DETAILED_NOTES_");
                if ( noteCheck!= null 
                    && noteCheck.getValue() != null
                    && noteCheck.getValue().getValue() != null
                    && !noteCheck.getValue().getValue().equals("")) {
                  Note n = new Note();
                  n.setText(stateText + "Supporting Resource changed with id: " + res.getId());
                  n.setAuthor( "SIM638-API" );
                  n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() );
                  supd.addNoteItem( n );                  
                }               
                
                this.updateService( aService.getId(), supd , true, null, null); //update the service 
                
              }

        }
      CharCopyResult result = new CharCopyResult(supd, characteristicFoundDifferent);
      return result ;
      
      
      }catch (Exception e) {
        e.printStackTrace();
    }

    }
    
    


    @Transactional  
+14 −14
Original line number Diff line number Diff line
@@ -884,15 +884,18 @@ public class ServiceOrderRepoService {
		if (depth>10) {
			return result;
		}

		
		
		for (ServiceRef specRel : soiOrigin.getService().getSupportingService() ) {
			if ( !soiOrigin.getService().getName().equals( specRel.getName()) ) {
				result += "\""+ soiOrigin.getService().getId() + "\""+ " -> " + "\""+ specRel.getId() +"\" "+";\r\n";
			//if ( !soiOrigin.getService().getName().equals( specRel.getName()) ) {
				//result += "\""+ soiOrigin.getService().getId() + "\""+ " -> " + "\""+ specRel.getId() +"\" "+";\r\n";
				result += "\""+ specRel.getId() + "\""+ " [label =\""+ specRel.getName() +"\", color = \"#2596be\"]; \r\n";
				org.etsi.osl.tmf.sim638.model.Service aService= serviceRepoService.findByUuid( specRel.getId() );
				if ( aService!= null) {
					result += getServiceGraphNotation( aService,0 );				
				}
			}
			//}
			
		}

@@ -902,7 +905,7 @@ public class ServiceOrderRepoService {
			
		}
		
		result += "\""+ soiOrigin.getService().getId() + "\""+ " [label = \""+ soiOrigin.getService().getName() +"\", color = \"#2596be\"]; \r\n";
		//result += "\""+ soiOrigin.getService().getId() + "\""+ " [label = \"Order "+ soiOrigin.getService().getName() +"\", color = \"#259600\"]; \r\n";
		return result;
	}

@@ -914,14 +917,11 @@ public class ServiceOrderRepoService {
		for (ServiceRef specRel : aService.getSupportingService() ) {
			result += "\""+ aService.getId() + "\""+ " -> " + "\""+ specRel.getId()  +"\" "+";\r\n";
			result += "\""+ specRel.getId() + "\""+ " [label = \"" + specRel.getName()  + "\", color = \"#2596be\"];\r\n";
			
		}
		for (ResourceRef resRel : aService.getSupportingResource()) {
          
          result += "\""+ aService.getId() + "\""+ " -> " + "\""+ resRel.getId() + "\""+ ";\r\n";
          result += "\""+ resRel.getId() + "\""+ " [ label = \"" + resRel.getName() +"\",  shape = roundedbox, color = \"#e28743\"]; \r\n";          
				
			}
			
        }
		
		
+3 −1
Original line number Diff line number Diff line
@@ -307,6 +307,7 @@ public class ServiceRepoServiceTest {
        resCharacteristicItem.setValue( new Any("nslcm_test2"));
        resourceUpdate.addResourceCharacteristicItem(resCharacteristicItem);
        
        resCharacteristicItem = new org.etsi.osl.tmf.ri639.model.Characteristic();
        resCharacteristicItem.setName( "newChar" );
        resCharacteristicItem.setValue( new Any("myval0"));
        resourceUpdate.addResourceCharacteristicItem(resCharacteristicItem);
@@ -315,7 +316,8 @@ public class ServiceRepoServiceTest {
        System.out.println("STEP 1 - =========================================== " +serviceRepoService.toString() );
        Resource nullResource = resourceRepoService.updateResource( resource.getId(), resourceUpdate, false);
        resource = resourceRepoService.findByUuid(firstResourceRef.getId());        
        assertThat( resource.getResourceCharacteristic().size()  ).isEqualTo( 1 );
        nullResource.setResourceStatus(ResourceStatusType.AVAILABLE);
        assertThat( resource.getResourceCharacteristic().size()  ).isEqualTo( 2 );

        Thread.sleep(1000);