/** * Check if DLNA service is allowed by Messic configuration * * @return boolean */ public boolean isGenericAllowed() { return this.daoSettings.getSettings().isAllowDLNA(); }
/** * Return the messic server name * @return */ public String getMessicServerName() { return daoSettings.getSettings().getMessicServerName(); }
/** * Check if we have a different version at database. Receive the current version of messic * * @param sversion {@link String} current version of messic * @return boolean true->is different */ private boolean isDifferentVersion( String sversion ) { String dbVersion = daoSettings.getSettings().getVersion(); if ( dbVersion != null && dbVersion.equals( sversion ) ) { return false; } else { return true; } } }
/** * Return the list of folders at the author level file system (at the messic music folder of the user scope) * * @param user {@link User} scope * @return {@link List}<{@link String}/> List of folders at the messic music folder */ public List<String> getAuthorFolders( MDOUser user ) { String userPath = user.calculateAbsolutePath( daoSettings.getSettings() ); File fuserPath = new File( userPath ); if ( fuserPath.exists() ) { String[] list = fuserPath.list(); List<String> rlist = new ArrayList<String>(); for ( String string : list ) { rlist.add( string ); } return rlist; } else { return new ArrayList<String>(); } } }
/** * Check if the folders are just the needed folders.. * * @param albumSid * @return */ @Transactional public List<FolderResourceConsistency> checkConsistency( MDOUser user ) { List<FolderResourceConsistency> result = new ArrayList<FolderResourceConsistency>(); String userPath = user.calculateAbsolutePath( daoSettings.getSettings() ); File fuserPath = new File( userPath ); File[] authorFolders = fuserPath.listFiles(); for ( File faufolder : authorFolders ) { List<FolderResourceConsistency> pr = checkConsistencyFolder( user, faufolder ); result.addAll( pr ); } return result; }
@Transactional public void remove( User user, Long authorSid ) throws IOException { MDOAuthor author = daoAuthor.get( user.getLogin(), authorSid ); if ( author != null ) { String path = author.calculateAbsolutePath( daoSettings.getSettings() ); daoAuthor.remove( author ); FileUtils.deleteDirectory( new File( path ) ); } }
@Transactional public File get( User user, Long resourceSid ) throws IOException { MDOAlbumResource resource = this.daoAlbumResource.get( user.getLogin(), resourceSid ); if ( resource != null && resource instanceof MDOPhysicalResource ) { File f = new File( resource.calculateAbsolutePath( daoSettings.getSettings() ) ); if ( f.exists() ) { return f; } } throw new IOException( "Album resource not found!" ); } }
/** * Delete all the files of a certain path, and subpaths, except those files in the list of the parameter * exceptionFiles * * @param basePath {@link String} basePath to start searching * @param exceptionFiles List<File/> Black list we don't want to remove */ private void deleteFiles( String basePath, List<org.messic.server.api.datamodel.File> exceptionFiles ) { File directory = new File( basePath ); char replacementChar = daoSettings.getSettings().getIllegalCharacterReplacement(); // get all the files from a directory File[] fList = directory.listFiles(); for ( File file : fList ) { if ( file.isFile() ) { if ( !isAnExceptionFile( file, exceptionFiles, replacementChar ) && !file.getName().toUpperCase().equals( APIAlbum.INDEX_TMP_PROPERTIES_FILENAME.toUpperCase() ) ) { file.delete(); } } else if ( file.isDirectory() ) { deleteFiles( file.getAbsolutePath(), exceptionFiles ); } } }
public void checkService() { if ( this.daoSettings.getSettings().isAllowMessicDiscovering() ) { if ( this.threadCover != null ) { this.threadCover.interrupt(); } this.stop(); this.stop = false; this.threadCover = new Thread( this ); this.threadCover.start(); } else { this.stop(); } }
public void removeUser( Long sid, boolean removeMusicContent ) throws Exception { MDOUser mdoUserToRemove = daoUser.getUserById( sid ); if ( mdoUserToRemove != null ) { if ( removeMusicContent ) { String absolutePath = mdoUserToRemove.calculateAbsolutePath( daoSettings.getSettings() ); File fabsolutePath = new File( absolutePath ); if ( fabsolutePath.exists() ) { FileUtils.deleteDirectory( new File( absolutePath ) ); } } // first we remove genres of the user // daoGenre.removeAllGenres( mdoUserToRemove.getLogin() ); // daoGenre.flush(); // finally we remove the user daoUser.remove( mdoUserToRemove ); } else { throw new Exception( "User doesn't exist!" ); } }
@Transactional public void remove( User user, Long resourceSid ) throws IOException { MDOAlbumResource resource = this.daoAlbumResource.get( user.getLogin(), resourceSid ); if ( resource != null ) { // first, removing the resource file String path = resource.calculateAbsolutePath( daoSettings.getSettings() ); File fpath = new File( path ); fpath.delete(); // after, removing the album data from database this.daoAlbumResource.remove( resource ); } }
ZipEntry ze = new ZipEntry( entryName ); zos.putNextEntry( ze ); FileInputStream in = new FileInputStream( song.calculateAbsolutePath( daoSettings.getSettings() ) ); int len; byte buffer[] = new byte[1024];
@Transactional public boolean remove( User user, Long albumSid ) throws IOException { MDOAlbum album = this.daoAlbum.getAlbum( albumSid, user.getLogin() ); if ( album != null ) { MDOAuthor author = album.getAuthor(); if ( author.getAlbums().size() <= 1 ) { File fpath = new File( author.calculateAbsolutePath( daoSettings.getSettings() ) ); FileUtils.deleteDirectory( fpath ); // after, removing the author data from database daoAuthor.remove( album.getAuthor() ); return true; } else { // first, removing the album folder File fpath = new File( album.calculateAbsolutePath( daoSettings.getSettings() ) ); FileUtils.deleteDirectory( fpath ); // after, removing the album data from database this.daoAlbum.remove( album ); return false; } } return false; }
String basePath = mdouser.calculateTmpPath( daoSettings.getSettings(), albumCode ); File tmpPath = new File( basePath );
public byte[] getAlbumResource( User mdouser, Long resourceSid ) throws SidNotFoundMessicException, ResourceNotFoundMessicException, IOException { MDOAlbumResource resource = daoAlbumResource.get( resourceSid ); if ( resource != null ) { String resourcePath = resource.calculateAbsolutePath( daoSettings.getSettings() ); File ftor = new File( resourcePath ); if ( ftor.exists() ) { return Util.readFile( resourcePath ); } else { throw new ResourceNotFoundMessicException( resourcePath ); } } else { throw new SidNotFoundMessicException(); } }
@Transactional public void getAlbumZip( User user, Long albumSid, OutputStream os ) throws IOException { MDOAlbum album = this.daoAlbum.getAlbum( albumSid, user.getLogin() ); if ( album != null ) { String basePath = album.calculateAbsolutePath( daoSettings.getSettings() ); Util.zipFolder( basePath + File.separatorChar, album.getAuthor().getName() + "-" + album.getName(), os ); } else { throw new IOException( "Album not found!" ); } }
String filepath = newResource.calculateAbsolutePath( daoSettings.getSettings() ); File newFilePath = Util.getRollFileNumber( new File( filepath ) ); newResource.setLocation( newFilePath.getName() );
/** * update the current database to the new version * * @param sversion {@link String} version like "1.0.0-snapshot" * @param version int the vesrion number (first number) * @param revision int the revision number (second number) * @param compile int the compilation number (third number) * @param semantic String the semantic number (snapshot). This could not be present */ @Transactional public void update( String sversion, int version, int revision, int compile, String semantic ) { if ( isDifferentVersion( sversion ) ) { updateToVersion( version, revision, compile, semantic ); MDOMessicSettings mms = daoSettings.getSettings(); mms.setVersion( sversion ); daoSettings.saveSettings( mms ); daoUser.usersNotifyMessicUpdate(); } }
public void playSong( String username, long sidSong, int clientQueuePosition ) throws IOException { MDOSong song = daoSong.get( username, sidSong ); if ( song != null ) { MessicRadioPlugin mrp = getPlugin(); File mp3song = new File( song.calculateAbsolutePath( daoSettings.getSettings() ) ); if ( mp3song.exists() ) { MessicRadioSong mrs = new MessicRadioSong(); mrs.songFile = mp3song; mrs.authorName = song.getAlbum().getAuthor().getName(); mrs.albumName = song.getAlbum().getName(); mrs.albumyear = song.getAlbum().getYear(); MDOAlbumResource mar = song.getAlbum().getCover(); if ( mar != null ) { mrs.coverImage = new File( mar.calculateAbsolutePath( daoSettings.getSettings() ) ); } mrs.songSid = song.getSid(); mrs.songName = song.getName(); mrs.trackNumber = song.getTrack(); mrs.albumGenre = ( song.getAlbum().getGenre() != null ? song.getAlbum().getGenre().getName() : "" ); mrs.albumComments = song.getAlbum().getComments(); mrs.clientQueuePosition = clientQueuePosition; mrp.castSong( mrs ); } } }
/** * Obtain the MDOSettings corresponding with the settings of this object * * @param daoSettings * @return */ public MDOMessicSettings getMDOSettings( DAOMessicSettings daoSettings ) { MDOMessicSettings mdoSettings = daoSettings.getSettings(); mdoSettings.setAllowDLNA( this.isAllowDLNA() ); mdoSettings.setAllowUserCreation( this.isAllowUserCreation() ); mdoSettings.setIllegalCharacterReplacement( this.getIllegalCharacterReplacement() ); mdoSettings.setAllowMessicDiscovering( this.isAllowDiscovering() ); mdoSettings.setMessicServerName( this.getMessicServerName() ); return mdoSettings; }