Commit f9cfc39d authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fix for #88

parent cdd5f3b8
Loading
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -136,6 +136,35 @@ public class ServiceApiController implements ServiceApi {
	@PreAuthorize("hasAnyAuthority('ROLE_USER')" )
	@Override
	public ResponseEntity<Service> patchService(Principal principal, String id, @Valid ServiceUpdate service) {
		// Check consistency if service characteristics or specification are being updated
		if (service.getServiceCharacteristic() != null ) {
			// Create a temporary service object to check consistency
			Service tempService = new Service();

			// Get the existing service to check against
			Service existingService = serviceRepoService.findByUuid(id);
			if (existingService == null) {
				log.warn("Service not found with id: " + id);
				return new ResponseEntity<Service>(HttpStatus.NOT_FOUND);
			}

			tempService.setServiceSpecificationRef(existingService.getServiceSpecificationRef());
			
			// Use the updated characteristics if provided, otherwise use the existing ones
			if (service.getServiceCharacteristic() != null) {
				tempService.getServiceCharacteristic().addAll(service.getServiceCharacteristic());
			} else {
				tempService.getServiceCharacteristic().addAll(existingService.getServiceCharacteristic());
			}

			// Check consistency before updating the service
			String consistencyReason = serviceRepoService.checkConsistencyReason(tempService);
			if (consistencyReason != null) {
				log.warn("Service consistency check failed during patch: " + consistencyReason);
				return new ResponseEntity<Service>(HttpStatus.BAD_REQUEST);
			}
		}

		Service c = serviceRepoService.updateService(id, service, true, null, null);

		return new ResponseEntity<Service>(c, HttpStatus.OK);
+1 −1
Original line number Diff line number Diff line
@@ -1199,7 +1199,7 @@ public class ServiceCatalogIntegrationTest extends BaseIT {
		specupd = specRepoService.updateExternalServiceSpec(externaluuid, o.getId(), responsesSpec1);
		assertThat( specRepoService.findAll().size() ).isEqualTo( 28 );
		assertThat( specupd.getRelatedParty()).hasSize(1);
		assertThat( specupd.getServiceSpecCharacteristic()).hasSize( 3 ) ;
		assertThat( specupd.getServiceSpecCharacteristic()).hasSize( 10 ) ;
		assertThat( specupd.getName() ).isEqualTo( responsesSpec1.getName()  ) ;
		
		
+1 −1
Original line number Diff line number Diff line
@@ -279,7 +279,7 @@ public class ServiceOrderMetricsApiControllerTest extends BaseIT {
        soi.setService(serviceRestriction);
        
        Characteristic charitem = new Characteristic();
        charitem.setName("Spec2Attribute1");
        charitem.setName("NSLCM");
        charitem.setValue( new Any("3", "Indoor"));
        serviceRestriction.addServiceCharacteristicItem(charitem );