@Override public ApplicationTemplate findTemplate( String name, String version ) { ApplicationTemplate result = null; for( ApplicationTemplate tpl : this.templates.keySet()) { if( Objects.equals( tpl.getName(), name ) && Objects.equals( tpl.getVersion(), version )) { result = tpl; break; } } return result; }
/** * Constructor. * @param app */ public InstanceContext( AbstractApplication app ) { this.name = app.getName(); this.qualifier = app instanceof ApplicationTemplate ? ((ApplicationTemplate) app).getVersion() : null; }
@Override public boolean equals( Object obj ) { return obj instanceof ApplicationTemplate && Objects.equals( this.name, ((ApplicationTemplate) obj ).getName()) && Objects.equals( this.version, ((ApplicationTemplate) obj ).getVersion()); }
/** * Finds the directory that contains the files for an application template. * @param tpl an application template * @param configurationDirectory the DM's configuration directory * @return a non-null file that should point to a directory */ public static File findTemplateDirectory( ApplicationTemplate tpl, File configurationDirectory ) { StringBuilder sb = new StringBuilder( TEMPLATES ); sb.append( "/" ); sb.append( tpl.getName()); if( ! Utils.isEmptyOrWhitespaces( tpl.getVersion())) { sb.append( " - " ); sb.append( tpl.getVersion()); } return new File( configurationDirectory, sb.toString()); }
/** * Finds the URL to access the icon of an application or templates. * @param app an application or an application template * @return the empty string if no icon was found, a string otherwise */ public static String findIconUrl( AbstractApplication app ) { StringBuilder sb = new StringBuilder(); File iconFile = findIcon( app ); if( iconFile != null ) { sb.append( "/" ); sb.append( app.getName()); if( app instanceof ApplicationTemplate ) { sb.append( "/" ); sb.append(((ApplicationTemplate) app).getVersion()); } sb.append( "/" ); sb.append( iconFile.getName()); } return sb.toString(); }
/** * Details for an application template. * @param tpl the application template * @return an object with error details */ public static ErrorDetails applicationTpl( ApplicationTemplate tpl ) { return applicationTpl( tpl.getName(), tpl.getVersion()); }
String qualifier = app instanceof ApplicationTemplate ? ((ApplicationTemplate) app).getVersion() : null;
sb.append( creator.getName()); sb.append( " - " ); sb.append( creator.getVersion());
/** * Renders an applicationTemplate. * @throws IOException */ private void renderApplication() throws IOException { StringBuilder sb = new StringBuilder(); // First pages sb.append( renderDocumentTitle()); sb.append( renderPageBreak()); sb.append( renderParagraph( this.messages.get( "intro" ))); //$NON-NLS-1$ sb.append( renderPageBreak()); sb.append( renderDocumentIndex()); sb.append( renderPageBreak()); sb.append( startTable()); sb.append( addTableLine( this.messages.get( "app.name" ), this.applicationTemplate.getName())); //$NON-NLS-1$ sb.append( addTableLine( this.messages.get( "app.qualifier" ), this.applicationTemplate.getVersion())); //$NON-NLS-1$ sb.append( endTable()); sb.append( renderApplicationDescription()); sb.append( renderPageBreak()); sb.append( renderSections( new ArrayList<String>( 0 ))); // Render information about components sb.append( renderComponents()); // Render information about initial instances sb.append( renderInstances()); writeFileContent( sb.toString()); }
sb.append( addTableLine( this.messages.get( "app.qualifier" ), this.applicationTemplate.getVersion())); //$NON-NLS-1$ sb.append( endTable());
/** * Renders an applicationTemplate. * @throws IOException */ private void renderApplication() throws IOException { StringBuilder sb = new StringBuilder(); // First pages sb.append( renderDocumentTitle()); sb.append( renderPageBreak()); sb.append( renderParagraph( this.messages.get( "intro" ))); //$NON-NLS-1$ sb.append( renderPageBreak()); sb.append( renderDocumentIndex()); sb.append( renderPageBreak()); sb.append( startTable()); sb.append( addTableLine( this.messages.get( "app.name" ), this.applicationTemplate.getName())); //$NON-NLS-1$ sb.append( addTableLine( this.messages.get( "app.qualifier" ), this.applicationTemplate.getVersion())); //$NON-NLS-1$ sb.append( endTable()); sb.append( renderApplicationDescription()); sb.append( renderPageBreak()); sb.append( renderSections( new ArrayList<String>( 0 ))); // Render information about components sb.append( renderComponents()); // Render information about initial instances sb.append( renderInstances()); writeFileContent( sb.toString()); }
generator.writeStringField( DESC, app.getDescription()); if( app.getVersion() != null ) generator.writeStringField( VERSION, app.getVersion());
errors.add( new ModelError( RM_INVALID_APPLICATION_NAME, app )); if( Utils.isEmptyOrWhitespaces( app.getVersion())) errors.add( new ModelError( RM_MISSING_APPLICATION_VERSION, app )); else if( Version.parseVersion( app.getVersion()) == null ) errors.add( new ModelError( RM_INVALID_APPLICATION_VERSION, app, unexpected( app.getVersion())));
sb.append( addTableLine( this.messages.get( "app.qualifier" ), this.applicationTemplate.getVersion())); //$NON-NLS-1$ sb.append( endTable());
/** * Saves an application descriptor. * @param f the file where the properties will be saved * @param app an application (not null) * @throws IOException if the file could not be written */ public static void save( File f, Application app ) throws IOException { Properties properties = new Properties(); if( ! Utils.isEmptyOrWhitespaces( app.getDisplayName())) properties.setProperty( APPLICATION_NAME, app.getDisplayName()); if( ! Utils.isEmptyOrWhitespaces( app.getDescription())) properties.setProperty( APPLICATION_DESCRIPTION, app.getDescription()); if( app.getTemplate() != null ) { if( ! Utils.isEmptyOrWhitespaces( app.getTemplate().getName())) properties.setProperty( APPLICATION_TPL_NAME, app.getTemplate().getName()); if( ! Utils.isEmptyOrWhitespaces( app.getTemplate().getVersion())) properties.setProperty( APPLICATION_TPL_VERSION, app.getTemplate().getVersion()); } Utils.writePropertiesFile( properties, f ); } }
if( app.getTemplate().getVersion() != null ) generator.writeStringField( APP_INST_TPL_VERSION, app.getTemplate().getVersion());
Assert.assertEquals( "1.0.1-SNAPSHOT", result.applicationTemplate.getVersion()); Assert.assertEquals( "roboconf-1.0", result.applicationTemplate.getDslId());
Assert.assertEquals( "1.0.1-SNAPSHOT", result.applicationTemplate.getVersion());
@Test public void testChain() { ApplicationTemplate app = new ApplicationTemplate().name( "ins" ).description( "desc" ).version( "snapshot" ).graphs( new Graphs()); Assert.assertEquals( "ins", app.getName()); Assert.assertEquals( "desc", app.getDescription()); Assert.assertEquals( "snapshot", app.getVersion()); Assert.assertNotNull( app.getGraphs()); }