Commit 50dba086 authored by femiadeyemi's avatar femiadeyemi
Browse files

add API for updating relationship between service and org

parent 91b93b70
......@@ -192,6 +192,15 @@ public class MarketServiceController
return marketServiceService.addProvider(provider);
}
@PreAuthorize("isAuthenticated()")
@Operation(security = @SecurityRequirement(name = "hdf-aai"))
@PutMapping(path = "/providers",
consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<MarketService> updateProvider(@Valid @RequestBody ServiceProvider provider)
{
return marketServiceService.updateProvider(provider);
}
@PreAuthorize("isAuthenticated()")
@Operation(security = @SecurityRequirement(name = "hdf-aai"))
@DeleteMapping(path = "/affiliations")
......
......@@ -32,6 +32,15 @@ public interface MarketServiceRepository extends Neo4jRepository<MarketService,
@Param("orgUuid") String orgUuid,
@Param("roles") String[] roles);
@SuppressWarnings("UnusedReturnValue")
@Query("MATCH (service:MarketService)-[r:HOSTED_BY]->(org:Organization) " +
"WHERE service.uuid = $serviceUuid AND org.uuid = $orgUuid " +
"SET r.serviceTechnicalName = $softwareName " +
"RETURN service")
MarketService updateServiceProviderRelationship(
@Param("serviceUuid") String serviceUuid,
@Param("orgUuid") String orgUuid, @Param("softwareName") String serviceTechnicalName);
@SuppressWarnings("UnusedReturnValue")
@Query("MATCH (service:MarketService)-[r:HOSTED_BY]->(org:Organization) " +
"WHERE service.uuid = $serviceUuid AND org.uuid = $orgUuid " +
......
......@@ -103,6 +103,31 @@ public class MarketServiceService extends CerebrumServiceBase<MarketService, Mar
}
}
public ResponseEntity<MarketService> updateProvider(ServiceProvider serviceProvider)
{
MarketService serviceNode = serviceProvider.getMarketService();
Organization organizationNode = serviceProvider.getOrganization();
if (serviceNode.getUuid() != null && organizationNode.getUuid() != null) {
MarketService service = getServiceByAttributes("uuid", serviceNode.getUuid());
if (service.getServiceProviders() == null) {
return addProvider(serviceProvider);
}
for (ServiceProvider provider : service.getServiceProviders()) {
if (provider.getOrganization().getAbbreviation()
.equals(organizationNode.getAbbreviation())) {
MarketService updatedRelationship = marketServiceRepository.updateServiceProviderRelationship(
service.getUuid(),
provider.getOrganization().getUuid(),
serviceProvider.getServiceTechnicalName());
return ResponseEntity.ok().body(updatedRelationship);
}
}
}
return addProvider(serviceProvider);
}
public ResponseEntity<MarketService> deleteProviders(
String serviceKey, String serviceValue, String organizationKey, String organizationValue)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment