@Test public void testHandleLocationDeleted() { ServiceResource serviceResource = new ServiceResource(); serviceResource.setId("service1"); serviceResource.setLocationIds(new String[] { "location1", "location2" }); alienDao.save(serviceResource); serviceResourceService.handleLocationDeleted(new AfterLocationDeleted(this, "location3")); serviceResource = serviceResourceService.getOrFail("service1"); Assert.assertArrayEquals(new String[] { "location1", "location2" }, serviceResource.getLocationIds()); serviceResourceService.handleLocationDeleted(new AfterLocationDeleted(this, "location1")); serviceResource = serviceResourceService.getOrFail("service1"); Assert.assertArrayEquals(new String[] { "location2" }, serviceResource.getLocationIds()); }
@EventListener public synchronized void handleLocationDeleted(AfterLocationDeleted event) { GetMultipleDataResult<ServiceResource> serviceResourceResult = alienDAO.buildQuery(ServiceResource.class) .setFilters(singleKeyFilter("locationIds", event.getLocationId())).prepareSearch().search(0, Integer.MAX_VALUE); if (serviceResourceResult.getData() == null) { return; } for (ServiceResource serviceResource : serviceResourceResult.getData()) { Set<String> locations = CollectionUtils.safeNewHashSet(serviceResource.getLocationIds()); locations.remove(event.getLocationId()); serviceResource.setLocationIds(locations.toArray(new String[locations.size()])); } alienDAO.save(serviceResourceResult.getData()); }
ServiceResourceService { @EventListener public synchronized void handleLocationDeleted(AfterLocationDeleted event) { GetMultipleDataResult<ServiceResource> serviceResourceResult = alienDAO.buildQuery(ServiceResource.class) .setFilters(singleKeyFilter("locationIds", event.getLocationId())).prepareSearch().search(0, Integer.MAX_VALUE); if (serviceResourceResult.getData() == null) { return; } for (ServiceResource serviceResource : serviceResourceResult.getData()) { Set<String> locations = CollectionUtils.safeNewHashSet(serviceResource.getLocationIds()); locations.remove(event.getLocationId()); serviceResource.setLocationIds(locations.toArray(new String[locations.size()])); } alienDAO.save(serviceResourceResult.getData()); } }
ServiceResourceService { @EventListener public synchronized void handleLocationDeleted(AfterLocationDeleted event) { GetMultipleDataResult<ServiceResource> serviceResourceResult = alienDAO.buildQuery(ServiceResource.class) .setFilters(singleKeyFilter("locationIds", event.getLocationId())).prepareSearch().search(0, Integer.MAX_VALUE); if (serviceResourceResult.getData() == null) { return; } for (ServiceResource serviceResource : serviceResourceResult.getData()) { Set<String> locations = CollectionUtils.safeNewHashSet(serviceResource.getLocationIds()); locations.remove(event.getLocationId()); serviceResource.setLocationIds(locations.toArray(new String[locations.size()])); } alienDAO.save(serviceResourceResult.getData()); }  }
ServiceResourceService { @EventListener public synchronized void handleLocationDeleted(AfterLocationDeleted event) { GetMultipleDataResult<ServiceResource> serviceResourceResult = alienDAO.buildQuery(ServiceResource.class) .setFilters(singleKeyFilter("locationIds", event.getLocationId())).prepareSearch().search(0, Integer.MAX_VALUE); if (serviceResourceResult.getData() == null) { return; } for (ServiceResource serviceResource : serviceResourceResult.getData()) { Set<String> locations = CollectionUtils.safeNewHashSet(serviceResource.getLocationIds()); locations.remove(event.getLocationId()); serviceResource.setLocationIds(locations.toArray(new String[locations.size()])); } alienDAO.save(serviceResourceResult.getData()); }  String create(String serviceName, String serviceVersion, String serviceNodeType, String serviceNodeVersion); String create(String serviceName, String serviceVersion, String serviceNodeType, String serviceNodeVersion, String environmentId); GetMultipleDataResult<ServiceResource> list(int from, int count); FacetedSearchResult<ServiceResource> search(String searchText, Map<String, String[]> filters, String sortField, boolean desc, int from,
            int count); ServiceResource getOrFail(String id); void update(String resourceId, String name, String version, String description, String nodeType, String nodeTypeVersion,
            Map<String, AbstractPropertyValue> nodeProperties, Map<String, Capability> nodeCapabilities, Map<String, String> nodeAttributeValues,
            String[] locations, Map<String, String> capabilitiesRelationshipTypes, Map<String, String> requirementsRelationshipTypes); String duplicate(String serviceId); void patch(String resourceId, String name, String version, String description, String nodeType, String nodeTypeVersion,
            Map<String, AbstractPropertyValue> nodeProperties, Map<String, Capability> nodeCapabilities, Map<String, String> nodeAttributeValues,
            String[] locations, Map<String, String> capabilitiesRelationshipTypes, Map<String, String> requirementsRelationshipTypes); synchronized void save(ServiceResource serviceResource, boolean ensureUniqueness); synchronized void save(ServiceResource serviceResource); synchronized void delete(String id); @EventListener synchronized void handleLocationDeleted(AfterLocationDeleted event); List<ServiceResource> searchByLocation(String locationId); ServiceResource[] getByNodeTypes(String nodeType, String nodeTypeVersion); void isLocationAuthorized(String serviceId, String locationId); @EventListener void reportArchiveUsage(ArchiveUsageRequestEvent event); }
ServiceResourceService { @EventListener public synchronized void handleLocationDeleted(AfterLocationDeleted event) { GetMultipleDataResult<ServiceResource> serviceResourceResult = alienDAO.buildQuery(ServiceResource.class) .setFilters(singleKeyFilter("locationIds", event.getLocationId())).prepareSearch().search(0, Integer.MAX_VALUE); if (serviceResourceResult.getData() == null) { return; } for (ServiceResource serviceResource : serviceResourceResult.getData()) { Set<String> locations = CollectionUtils.safeNewHashSet(serviceResource.getLocationIds()); locations.remove(event.getLocationId()); serviceResource.setLocationIds(locations.toArray(new String[locations.size()])); } alienDAO.save(serviceResourceResult.getData()); }  String create(String serviceName, String serviceVersion, String serviceNodeType, String serviceNodeVersion); String create(String serviceName, String serviceVersion, String serviceNodeType, String serviceNodeVersion, String environmentId); GetMultipleDataResult<ServiceResource> list(int from, int count); FacetedSearchResult<ServiceResource> search(String searchText, Map<String, String[]> filters, String sortField, boolean desc, int from,
            int count); ServiceResource getOrFail(String id); void update(String resourceId, String name, String version, String description, String nodeType, String nodeTypeVersion,
            Map<String, AbstractPropertyValue> nodeProperties, Map<String, Capability> nodeCapabilities, Map<String, String> nodeAttributeValues,
            String[] locations, Map<String, String> capabilitiesRelationshipTypes, Map<String, String> requirementsRelationshipTypes); String duplicate(String serviceId); void patch(String resourceId, String name, String version, String description, String nodeType, String nodeTypeVersion,
            Map<String, AbstractPropertyValue> nodeProperties, Map<String, Capability> nodeCapabilities, Map<String, String> nodeAttributeValues,
            String[] locations, Map<String, String> capabilitiesRelationshipTypes, Map<String, String> requirementsRelationshipTypes); synchronized void save(ServiceResource serviceResource, boolean ensureUniqueness); synchronized void save(ServiceResource serviceResource); synchronized void delete(String id); @EventListener synchronized void handleLocationDeleted(AfterLocationDeleted event); List<ServiceResource> searchByLocation(String locationId); ServiceResource[] getByNodeTypes(String nodeType, String nodeTypeVersion); void isLocationAuthorized(String serviceId, String locationId); @EventListener void reportArchiveUsage(ArchiveUsageRequestEvent event);  }