public boolean isInstanceOf( Instance instance, List<ApplicationComponent> appComps, Component component) { boolean result = false; Long componentId = component.getId(); for (ApplicationComponent ac : appComps) { Long acId = ac.getId(); if (instance.getApplicationComponent().getId().equals(acId) && ac.getComponent().getId().equals(componentId)) { result = true; } } return result; }
@Override public List<Component> getComponents( Long applicationId, Long componentId, Long instanceId, Long cloudId) { List<Component> result = new ArrayList<Component>(); List<Component> components = componentModelService.getAll(); List<Instance> instances = null; List<VirtualMachine> vms = null; List<ApplicationComponent> appComps = applicationComponentModelService.getAll(); for (Component component : components) { boolean suitable = false; if (applicationId != null) { for (ApplicationComponent ac : appComps) { if (ac.getComponent().getId().equals(componentId) && ac.getApplication().getId().equals(applicationId)) { suitable = true; } } } if (componentId != null) { if (componentId.equals(component.getId())) { suitable = suitable && true; } } if (instanceId != null) { if (instances == null) instances = instanceModelService.getAll(); boolean oneFits = false; for (Instance instance : instances) { if (isInstanceOf(instance, appComps, component)) { oneFits = true; } } if (oneFits) { suitable = suitable && true; } else { suitable = false; } } if (cloudId != null) { if (instances == null) instances = instanceModelService.getAll(); if (vms == null) vms = virtualMachineModelService.getAll(); boolean oneFits = false; for (Instance instance : instances) { if (isInstanceOf(instance, vms, cloudId)) { if (isInstanceOf(instance, appComps, component)) { oneFits = true; } } } if (oneFits) { suitable = suitable && true; } else { suitable = false; } } if (suitable) { result.add(component); } } return result; }