@Test( expected = IOException.class ) public void testLoadApplicationTemplate_invalidDirectory() throws Exception { File source = TestUtils.findApplicationDirectory( "lamp" ); Assert.assertTrue( source.exists()); File apps = new File( this.dmDirectory, ConfigurationUtils.TEMPLATES ); File target = new File( apps, "Legacy LAMP - 1.0.1-SNAPSHOT/sub/dir" ); Utils.copyDirectory( source, target ); this.mngr.loadApplicationTemplate( target ); }
@Override public ApplicationTemplate loadApplicationTemplate( File applicationFilesDirectory ) throws AlreadyExistingException, InvalidApplicationException, IOException, UnauthorizedActionException { synchronized( INSTALL_LOCK ) { this.logger.info( "Loading an application template from " + applicationFilesDirectory + "..." ); ApplicationLoadResult lr = RuntimeModelIo.loadApplication( applicationFilesDirectory ); if( RoboconfErrorHelpers.containsCriticalErrors( lr.getLoadErrors())) throw new InvalidApplicationException( lr.getLoadErrors()); Collection<RoboconfError> warnings = RoboconfErrorHelpers.findWarnings( lr.getLoadErrors()); for( String warningMsg : RoboconfErrorHelpers.formatErrors( warnings, null, true ).values()) this.logger.warning( warningMsg ); ApplicationTemplate tpl = lr.getApplicationTemplate(); if( this.templates.containsKey( tpl )) throw new AlreadyExistingException( tpl.getName()); Set<String> externExportPrefixes = new HashSet<> (); for( ApplicationTemplate otherTpl : this.templates.keySet()) { if( otherTpl.getExternalExportsPrefix() != null ) externExportPrefixes.add( otherTpl.getExternalExportsPrefix()); } if( externExportPrefixes.contains( tpl.getExternalExportsPrefix())) throw new IOException( "The external exports prefix is already used by another template." ); Set<String> newTargetIds = registerTargets( tpl ); File targetDirectory = ConfigurationUtils.findTemplateDirectory( tpl, this.configurationMngr.getWorkingDirectory()); try { if( ! applicationFilesDirectory.equals( targetDirectory )) { if( Utils.isAncestorFile( targetDirectory, applicationFilesDirectory )) throw new IOException( "Cannot move " + applicationFilesDirectory + " in Roboconf's work directory. Already a child directory." ); else Utils.copyDirectory( applicationFilesDirectory, targetDirectory ); } } catch( IOException e ) { unregisterTargets( newTargetIds ); throw e; } tpl.setDirectory( targetDirectory ); for( File targetDir : ResourceUtils.findScopedInstancesDirectories( tpl ).values()) Utils.deleteFilesRecursivelyAndQuietly( targetDir ); this.templates.put( tpl, Boolean.TRUE ); this.logger.info( "Application template " + tpl.getName() + " was successfully loaded." ); this.notificationMngr.applicationTemplate( tpl, EventType.CREATED ); return tpl; } }
ApplicationTemplateMngrImpl implements IApplicationTemplateMngr { @Override public ApplicationTemplate loadApplicationTemplate( File applicationFilesDirectory ) throws AlreadyExistingException, InvalidApplicationException, IOException, UnauthorizedActionException { synchronized( INSTALL_LOCK ) { this.logger.info( "Loading an application template from " + applicationFilesDirectory + "..." ); ApplicationLoadResult lr = RuntimeModelIo.loadApplication( applicationFilesDirectory ); if( RoboconfErrorHelpers.containsCriticalErrors( lr.getLoadErrors())) throw new InvalidApplicationException( lr.getLoadErrors()); Collection<RoboconfError> warnings = RoboconfErrorHelpers.findWarnings( lr.getLoadErrors()); for( String warningMsg : RoboconfErrorHelpers.formatErrors( warnings, null, true ).values()) this.logger.warning( warningMsg ); ApplicationTemplate tpl = lr.getApplicationTemplate(); if( this.templates.containsKey( tpl )) throw new AlreadyExistingException( tpl.getName()); Set<String> externExportPrefixes = new HashSet<> (); for( ApplicationTemplate otherTpl : this.templates.keySet()) { if( otherTpl.getExternalExportsPrefix() != null ) externExportPrefixes.add( otherTpl.getExternalExportsPrefix()); } if( externExportPrefixes.contains( tpl.getExternalExportsPrefix())) throw new IOException( "The external exports prefix is already used by another template." ); Set<String> newTargetIds = registerTargets( tpl ); File targetDirectory = ConfigurationUtils.findTemplateDirectory( tpl, this.configurationMngr.getWorkingDirectory()); try { if( ! applicationFilesDirectory.equals( targetDirectory )) { if( Utils.isAncestorFile( targetDirectory, applicationFilesDirectory )) throw new IOException( "Cannot move " + applicationFilesDirectory + " in Roboconf's work directory. Already a child directory." ); else Utils.copyDirectory( applicationFilesDirectory, targetDirectory ); } } catch( IOException e ) { unregisterTargets( newTargetIds ); throw e; } tpl.setDirectory( targetDirectory ); for( File targetDir : ResourceUtils.findScopedInstancesDirectories( tpl ).values()) Utils.deleteFilesRecursivelyAndQuietly( targetDir ); this.templates.put( tpl, Boolean.TRUE ); this.logger.info( "Application template " + tpl.getName() + " was successfully loaded." ); this.notificationMngr.applicationTemplate( tpl, EventType.CREATED ); return tpl; } } }
ApplicationTemplateMngrImpl implements IApplicationTemplateMngr { @Override public ApplicationTemplate loadApplicationTemplate( File applicationFilesDirectory ) throws AlreadyExistingException, InvalidApplicationException, IOException, UnauthorizedActionException { synchronized( INSTALL_LOCK ) { this.logger.info( "Loading an application template from " + applicationFilesDirectory + "..." ); ApplicationLoadResult lr = RuntimeModelIo.loadApplication( applicationFilesDirectory ); if( RoboconfErrorHelpers.containsCriticalErrors( lr.getLoadErrors())) throw new InvalidApplicationException( lr.getLoadErrors()); Collection<RoboconfError> warnings = RoboconfErrorHelpers.findWarnings( lr.getLoadErrors()); for( String warningMsg : RoboconfErrorHelpers.formatErrors( warnings, null, true ).values()) this.logger.warning( warningMsg ); ApplicationTemplate tpl = lr.getApplicationTemplate(); if( this.templates.containsKey( tpl )) throw new AlreadyExistingException( tpl.getName()); Set<String> externExportPrefixes = new HashSet<> (); for( ApplicationTemplate otherTpl : this.templates.keySet()) { if( otherTpl.getExternalExportsPrefix() != null ) externExportPrefixes.add( otherTpl.getExternalExportsPrefix()); } if( externExportPrefixes.contains( tpl.getExternalExportsPrefix())) throw new IOException( "The external exports prefix is already used by another template." ); Set<String> newTargetIds = registerTargets( tpl ); File targetDirectory = ConfigurationUtils.findTemplateDirectory( tpl, this.configurationMngr.getWorkingDirectory()); try { if( ! applicationFilesDirectory.equals( targetDirectory )) { if( Utils.isAncestorFile( targetDirectory, applicationFilesDirectory )) throw new IOException( "Cannot move " + applicationFilesDirectory + " in Roboconf's work directory. Already a child directory." ); else Utils.copyDirectory( applicationFilesDirectory, targetDirectory ); } } catch( IOException e ) { unregisterTargets( newTargetIds ); throw e; } tpl.setDirectory( targetDirectory ); for( File targetDir : ResourceUtils.findScopedInstancesDirectories( tpl ).values()) Utils.deleteFilesRecursivelyAndQuietly( targetDir ); this.templates.put( tpl, Boolean.TRUE ); this.logger.info( "Application template " + tpl.getName() + " was successfully loaded." ); this.notificationMngr.applicationTemplate( tpl, EventType.CREATED ); return tpl; } } ApplicationTemplateMngrImpl(
			INotificationMngr notificationMngr,
			ITargetsMngr targetsMngr,
			IApplicationMngr applicationMngr,
			IConfigurationMngr configurationMngr ); }
ApplicationTemplateMngrImpl implements IApplicationTemplateMngr { @Override public ApplicationTemplate loadApplicationTemplate( File applicationFilesDirectory ) throws AlreadyExistingException, InvalidApplicationException, IOException, UnauthorizedActionException { synchronized( INSTALL_LOCK ) { this.logger.info( "Loading an application template from " + applicationFilesDirectory + "..." ); ApplicationLoadResult lr = RuntimeModelIo.loadApplication( applicationFilesDirectory ); if( RoboconfErrorHelpers.containsCriticalErrors( lr.getLoadErrors())) throw new InvalidApplicationException( lr.getLoadErrors()); Collection<RoboconfError> warnings = RoboconfErrorHelpers.findWarnings( lr.getLoadErrors()); for( String warningMsg : RoboconfErrorHelpers.formatErrors( warnings, null, true ).values()) this.logger.warning( warningMsg ); ApplicationTemplate tpl = lr.getApplicationTemplate(); if( this.templates.containsKey( tpl )) throw new AlreadyExistingException( tpl.getName()); Set<String> externExportPrefixes = new HashSet<> (); for( ApplicationTemplate otherTpl : this.templates.keySet()) { if( otherTpl.getExternalExportsPrefix() != null ) externExportPrefixes.add( otherTpl.getExternalExportsPrefix()); } if( externExportPrefixes.contains( tpl.getExternalExportsPrefix())) throw new IOException( "The external exports prefix is already used by another template." ); Set<String> newTargetIds = registerTargets( tpl ); File targetDirectory = ConfigurationUtils.findTemplateDirectory( tpl, this.configurationMngr.getWorkingDirectory()); try { if( ! applicationFilesDirectory.equals( targetDirectory )) { if( Utils.isAncestorFile( targetDirectory, applicationFilesDirectory )) throw new IOException( "Cannot move " + applicationFilesDirectory + " in Roboconf's work directory. Already a child directory." ); else Utils.copyDirectory( applicationFilesDirectory, targetDirectory ); } } catch( IOException e ) { unregisterTargets( newTargetIds ); throw e; } tpl.setDirectory( targetDirectory ); for( File targetDir : ResourceUtils.findScopedInstancesDirectories( tpl ).values()) Utils.deleteFilesRecursivelyAndQuietly( targetDir ); this.templates.put( tpl, Boolean.TRUE ); this.logger.info( "Application template " + tpl.getName() + " was successfully loaded." ); this.notificationMngr.applicationTemplate( tpl, EventType.CREATED ); return tpl; } } ApplicationTemplateMngrImpl(
			INotificationMngr notificationMngr,
			ITargetsMngr targetsMngr,
			IApplicationMngr applicationMngr,
			IConfigurationMngr configurationMngr ); @Override Set<ApplicationTemplate> getApplicationTemplates(); @Override ApplicationTemplate findTemplate( String name, String version ); @Override ApplicationTemplate loadApplicationTemplate( File applicationFilesDirectory ); @Override void deleteApplicationTemplate( String tplName, String tplVersion ); @Override void restoreTemplates(); }
ApplicationTemplateMngrImpl implements IApplicationTemplateMngr { @Override public ApplicationTemplate loadApplicationTemplate( File applicationFilesDirectory ) throws AlreadyExistingException, InvalidApplicationException, IOException, UnauthorizedActionException { synchronized( INSTALL_LOCK ) { this.logger.info( "Loading an application template from " + applicationFilesDirectory + "..." ); ApplicationLoadResult lr = RuntimeModelIo.loadApplication( applicationFilesDirectory ); if( RoboconfErrorHelpers.containsCriticalErrors( lr.getLoadErrors())) throw new InvalidApplicationException( lr.getLoadErrors()); Collection<RoboconfError> warnings = RoboconfErrorHelpers.findWarnings( lr.getLoadErrors()); for( String warningMsg : RoboconfErrorHelpers.formatErrors( warnings, null, true ).values()) this.logger.warning( warningMsg ); ApplicationTemplate tpl = lr.getApplicationTemplate(); if( this.templates.containsKey( tpl )) throw new AlreadyExistingException( tpl.getName()); Set<String> externExportPrefixes = new HashSet<> (); for( ApplicationTemplate otherTpl : this.templates.keySet()) { if( otherTpl.getExternalExportsPrefix() != null ) externExportPrefixes.add( otherTpl.getExternalExportsPrefix()); } if( externExportPrefixes.contains( tpl.getExternalExportsPrefix())) throw new IOException( "The external exports prefix is already used by another template." ); Set<String> newTargetIds = registerTargets( tpl ); File targetDirectory = ConfigurationUtils.findTemplateDirectory( tpl, this.configurationMngr.getWorkingDirectory()); try { if( ! applicationFilesDirectory.equals( targetDirectory )) { if( Utils.isAncestorFile( targetDirectory, applicationFilesDirectory )) throw new IOException( "Cannot move " + applicationFilesDirectory + " in Roboconf's work directory. Already a child directory." ); else Utils.copyDirectory( applicationFilesDirectory, targetDirectory ); } } catch( IOException e ) { unregisterTargets( newTargetIds ); throw e; } tpl.setDirectory( targetDirectory ); for( File targetDir : ResourceUtils.findScopedInstancesDirectories( tpl ).values()) Utils.deleteFilesRecursivelyAndQuietly( targetDir ); this.templates.put( tpl, Boolean.TRUE ); this.logger.info( "Application template " + tpl.getName() + " was successfully loaded." ); this.notificationMngr.applicationTemplate( tpl, EventType.CREATED ); return tpl; } } ApplicationTemplateMngrImpl(
			INotificationMngr notificationMngr,
			ITargetsMngr targetsMngr,
			IApplicationMngr applicationMngr,
			IConfigurationMngr configurationMngr ); @Override Set<ApplicationTemplate> getApplicationTemplates(); @Override ApplicationTemplate findTemplate( String name, String version ); @Override ApplicationTemplate loadApplicationTemplate( File applicationFilesDirectory ); @Override void deleteApplicationTemplate( String tplName, String tplVersion ); @Override void restoreTemplates();  }