/** * Details for a facet. * @param facet the facet * @return an object with error details */ public static ErrorDetails facet( Facet facet ) { return facet( facet.getName()); }
private Facet findFacetByName( Collection<Facet> facets, String facetName ) { Facet result = null; for( Facet f : facets ) { if( facetName.equals( f.getName())) { result = f; break; } } return result; } }
private Graphs buildFinalGraphs() { Graphs result = new Graphs(); for( ComponentData cd : this.componentNameToComponentData.values()) { if( ComponentHelpers.findAllAncestors( cd.object ).isEmpty()) result.getRootComponents().add( cd.object ); } for( FacetData data : this.facetNameToFacetData.values()) result.getFacetNameToFacet().put( data.object.getName(), data.object ); return result; }
/** * Finds all the components that depend on a given component. * @param component a component * @param app the application * @return a non-null map (key = component name, value = true if the dependency is optional, false otherwise) */ public static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app ) { // Determine the matching prefixes. Set<String> prefixes = new HashSet<> (); prefixes.add( component.getName()); for( Facet f : findAllFacets( component )) prefixes.add( f.getName()); // Resolve names to components Map<Component,Boolean> result = new HashMap<> (); for( Component c : findAllComponents( app )) { Map<String,Boolean> map = findComponentDependenciesFor( c ); map.keySet().retainAll( prefixes ); // Empty map => 'c' does not depend on 'component' if( map.isEmpty()) continue; // Otherwise, determine the dependency boolean value = true; for( Boolean b : map.values()) value = value && b; result.put( c, value ); } return result; }
/** * Finds all the components a component depends on. * @param component a component * @param app the application * @return a non-null map (key = component name, value = true if the dependency is optional, false otherwise) */ public static Map<Component,Boolean> findComponentDependenciesFor( Component component, ApplicationTemplate app ) { // Determine which components or facets are required. Map<String,Boolean> map = findComponentDependenciesFor( component ); // Resolve names to components Map<Component,Boolean> result = new HashMap<> (); for( Component c : findAllComponents( app )) { // Check component names first. Boolean required = map.get( c.getName()); if( required != null ) { result.put( c, required ); } // Or maybe it is a facet name. else for( Facet f : findAllFacets( c )) { required = map.get( f.getName()); // If this component owns the facet, stop here. if( required != null ) { result.put( c, required ); break; } } } return result; }
result.getBlocks().addAll( buildComponent( result, c, addComment )); for( Facet f : ComponentHelpers.findAllFacets( c )) { if( alreadySerializedNames.contains( f.getName())) continue; alreadySerializedNames.add( f.getName()); result.getBlocks().addAll( buildFacet( result, f, addComment )); if( alreadySerializedNames.contains( f.getName())) continue; alreadySerializedNames.add( f.getName()); result.getBlocks().addAll( buildFacet( result, f, addComment ));
if( Utils.isEmptyOrWhitespaces( facet.getName())) result.add( new ModelError( RM_EMPTY_FACET_NAME, facet )); else if( ! facet.getName().matches( ParsingConstants.PATTERN_FLEX_ID )) result.add( new ModelError( RM_INVALID_FACET_NAME, facet, facet( facet ))); else if( facet.getName().contains( "." )) result.add( new ModelError( RM_DOT_IS_NOT_ALLOWED, facet, facet( facet )));
@Test public void testFacetsSorting() { List<Facet> facets = new ArrayList<Facet> (); facets.add( new Facet( "z" )); facets.add( new Facet( "m" )); facets.add( new Facet( "a" )); facets.add( new Facet( "b" )); Assert.assertEquals( "z", facets.get( 0 ).getName()); Collections.sort( facets, new AbstractTypeComparator()); Assert.assertEquals( "a", facets.get( 0 ).getName()); Assert.assertEquals( "b", facets.get( 1 ).getName()); Assert.assertEquals( "m", facets.get( 2 ).getName()); Assert.assertEquals( "z", facets.get( 3 ).getName()); }
final String sectionName = DocConstants.SECTION_FACETS + facet.getName(); StringBuilder section = startSection( sectionName ); section.append( renderTitle2( facet.getName())); String customInfo = readCustomInformation( this.applicationDirectory, facet.getName(), DocConstants.FACET_DETAILS ); if( Utils.isEmptyOrWhitespaces( customInfo )) customInfo = this.typeAnnotations.get( facet.getName());
final String sectionName = DocConstants.SECTION_FACETS + facet.getName(); StringBuilder section = startSection( sectionName ); section.append( renderTitle2( facet.getName())); String customInfo = readCustomInformation( this.applicationDirectory, facet.getName(), DocConstants.FACET_DETAILS ); if( Utils.isEmptyOrWhitespaces( customInfo )) customInfo = this.typeAnnotations.get( facet.getName());
for( Facet f : graphs.getFacetNameToFacet().values()) { facetVariables.addAll( f.exportedVariables.keySet()); facetVariables.add( f.getName() + "." + Constants.WILDCARD );
allExportedVariables.put( superFacet.getName() + "." + Constants.WILDCARD, null );
Collection<Facet> facets = ComponentHelpers.findAllFacets( c ); Assert.assertEquals( 1, facets.size()); Assert.assertEquals( "Virtual_Machine", facets.iterator().next().getName()); Assert.assertEquals( 3, ComponentHelpers.findAllChildren( c ).size()); Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName()); Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName()); Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName());
serverWithAnotherApp.addExportedVariable( new ExportedVariable( serverFacet.getName() + ".url-suffix", "another/path" )); serverWithAnotherApp.addExportedVariable( new ExportedVariable( "whatever", "something" )); serverWithAnotherApp.addExportedVariable( new ExportedVariable( "env", "prod" )); Assert.assertEquals( "test", exports.get( serverWithApp.getName() + ".env" )); Assert.assertEquals( "some/path", exports.get( serverWithApp.getName() + ".url-suffix" )); Assert.assertEquals( "some/path", exports.get( serverFacet.getName() + ".url-suffix" )); Assert.assertEquals( "8080", exports.get( serverWithAnotherApp.getName() + ".port" )); Assert.assertEquals( "another/path", exports.get( serverFacet.getName() + ".url-suffix" )); Assert.assertEquals( "some/path", exports.get( serverWithApp.getName() + ".url-suffix" )); Assert.assertEquals( "some/path", exports.get( serverWithAnotherApp.getName() + ".url-suffix" ));
graph.getFacetNameToFacet().put( facetDeployable.getName(), facetDeployable ); graph.getFacetNameToFacet().put( facetVm.getName(), facetVm ); facetVm.addChild( facetDeployable ); facetVm.addExportedVariable( new ExportedVariable( Constants.SPECIFIC_VARIABLE_IP, null )); graph.getFacetNameToFacet().put( facetJee.getName(), facetJee ); facetJee.addExportedVariable( new ExportedVariable( "server-suffix", "/path" )); facetJee.extendFacet( facetDeployable ); graph.getFacetNameToFacet().put( facetWeb.getName(), facetWeb ); facetWeb.addExportedVariable( new ExportedVariable( "server-suffix", "/path" )); facetWeb.extendFacet( facetDeployable ); graph.getFacetNameToFacet().put( facetDb.getName(), facetDb ); facetDb.addExportedVariable( new ExportedVariable( "port", "3306" )); facetDb.extendFacet( facetDeployable ); graph.getFacetNameToFacet().put( facetStorage.getName(), facetStorage ); facetStorage.extendFacet( facetDb );