@Test public void testFindComponentsThatDependOn() { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); Component comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.ROOT_1 ); Assert.assertNotNull( comp ); Map<Component,Boolean> map = ComponentHelpers.findComponentsThatDependOn( comp, app ); Assert.assertEquals( 0, map.size()); comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.MYSQL ); Assert.assertNotNull( comp ); map = ComponentHelpers.findComponentsThatDependOn( comp, app ); Assert.assertEquals( 2, map.size()); Component key = new Component( ComplexApplicationFactory1.APP_1 ); Assert.assertTrue( map.containsKey( key )); Assert.assertTrue( map.get( key )); key = new Component( ComplexApplicationFactory1.APP_2 ); Assert.assertTrue( map.containsKey( key )); Assert.assertFalse( map.get( key )); comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.MONGO_DB ); Assert.assertNotNull( comp ); map = ComponentHelpers.findComponentsThatDependOn( comp, app ); Assert.assertEquals( 1, map.size()); key = new Component( ComplexApplicationFactory1.APP_2 ); Assert.assertTrue( map.containsKey( key )); Assert.assertTrue( map.get( key )); comp = ComponentHelpers.findComponent( app.getGraphs(), ComplexApplicationFactory1.APP_3 ); Assert.assertNotNull( comp ); map = ComponentHelpers.findComponentsThatDependOn( comp, app ); Assert.assertEquals( 0, map.size()); }
public static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app ) { Set<String> prefixes = new HashSet<> (); prefixes.add( component.getName()); for( Facet f : findAllFacets( component )) prefixes.add( f.getName()); Map<Component,Boolean> result = new HashMap<> (); for( Component c : findAllComponents( app )) { Map<String,Boolean> map = findComponentDependenciesFor( c ); map.keySet().retainAll( prefixes ); if( map.isEmpty()) continue; boolean value = true; for( Boolean b : map.values()) value = value && b; result.put( c, value ); } return result; }
ComponentHelpers { public static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app ) { Set<String> prefixes = new HashSet<> (); prefixes.add( component.getName()); for( Facet f : findAllFacets( component )) prefixes.add( f.getName()); Map<Component,Boolean> result = new HashMap<> (); for( Component c : findAllComponents( app )) { Map<String,Boolean> map = findComponentDependenciesFor( c ); map.keySet().retainAll( prefixes ); if( map.isEmpty()) continue; boolean value = true; for( Boolean b : map.values()) value = value && b; result.put( c, value ); } return result; } }
ComponentHelpers { public static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app ) { Set<String> prefixes = new HashSet<> (); prefixes.add( component.getName()); for( Facet f : findAllFacets( component )) prefixes.add( f.getName()); Map<Component,Boolean> result = new HashMap<> (); for( Component c : findAllComponents( app )) { Map<String,Boolean> map = findComponentDependenciesFor( c ); map.keySet().retainAll( prefixes ); if( map.isEmpty()) continue; boolean value = true; for( Boolean b : map.values()) value = value && b; result.put( c, value ); } return result; } private  ComponentHelpers(); }
ComponentHelpers { public static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app ) { Set<String> prefixes = new HashSet<> (); prefixes.add( component.getName()); for( Facet f : findAllFacets( component )) prefixes.add( f.getName()); Map<Component,Boolean> result = new HashMap<> (); for( Component c : findAllComponents( app )) { Map<String,Boolean> map = findComponentDependenciesFor( c ); map.keySet().retainAll( prefixes ); if( map.isEmpty()) continue; boolean value = true; for( Boolean b : map.values()) value = value && b; result.put( c, value ); } return result; } private  ComponentHelpers(); static Component findComponent( Graphs graphs, String name ); static Component findComponent( AbstractApplication app, String name ); static Component findComponentFrom( Component component, String componentName ); static List<String> extractNames( Collection<? extends AbstractType> types ); static boolean isTarget( Component component ); static Collection<Component> findAllChildren( Component component ); static Collection<Component> findAllAncestors( Component component ); static String findComponentInstaller( Component component ); static Map<String,String> findAllExportedVariables( Component component ); static Map<String,String> findAllExportedVariables( AbstractType type ); static Map<String,String> findAllExportedVariables( Graphs graphs ); static Map<String,String> findAllExportedVariables( Facet facet ); static Map<String,ImportedVariable> findAllImportedVariables( Component component ); static Collection<Facet> findAllFacets( Component component ); static List<Component> findAllExtendedComponents( Component component ); static Collection<Facet> findAllExtendedFacets( Facet facet ); static Collection<Facet> findAllExtendingFacets( Facet facet ); static Collection<Component> findAllExtendingComponents( Component component ); static List<Component> findAllComponents( Graphs graphs ); static List<Component> findAllComponents( AbstractApplication app ); static String searchForLoop( Component component ); static String searchForInheritanceCycle( Facet facet ); static String searchForInheritanceCycle( Component component ); static Map<String,Boolean> findComponentDependenciesFor( Component component ); static Map<Component,Boolean> findComponentDependenciesFor( Component component, ApplicationTemplate app ); static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app ); }
ComponentHelpers { public static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app ) { Set<String> prefixes = new HashSet<> (); prefixes.add( component.getName()); for( Facet f : findAllFacets( component )) prefixes.add( f.getName()); Map<Component,Boolean> result = new HashMap<> (); for( Component c : findAllComponents( app )) { Map<String,Boolean> map = findComponentDependenciesFor( c ); map.keySet().retainAll( prefixes ); if( map.isEmpty()) continue; boolean value = true; for( Boolean b : map.values()) value = value && b; result.put( c, value ); } return result; } private  ComponentHelpers(); static Component findComponent( Graphs graphs, String name ); static Component findComponent( AbstractApplication app, String name ); static Component findComponentFrom( Component component, String componentName ); static List<String> extractNames( Collection<? extends AbstractType> types ); static boolean isTarget( Component component ); static Collection<Component> findAllChildren( Component component ); static Collection<Component> findAllAncestors( Component component ); static String findComponentInstaller( Component component ); static Map<String,String> findAllExportedVariables( Component component ); static Map<String,String> findAllExportedVariables( AbstractType type ); static Map<String,String> findAllExportedVariables( Graphs graphs ); static Map<String,String> findAllExportedVariables( Facet facet ); static Map<String,ImportedVariable> findAllImportedVariables( Component component ); static Collection<Facet> findAllFacets( Component component ); static List<Component> findAllExtendedComponents( Component component ); static Collection<Facet> findAllExtendedFacets( Facet facet ); static Collection<Facet> findAllExtendingFacets( Facet facet ); static Collection<Component> findAllExtendingComponents( Component component ); static List<Component> findAllComponents( Graphs graphs ); static List<Component> findAllComponents( AbstractApplication app ); static String searchForLoop( Component component ); static String searchForInheritanceCycle( Facet facet ); static String searchForInheritanceCycle( Component component ); static Map<String,Boolean> findComponentDependenciesFor( Component component ); static Map<Component,Boolean> findComponentDependenciesFor( Component component, ApplicationTemplate app ); static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app );  }