mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-14 09:37:36 -05:00
WIP #34: added channel map manager and new editor window. Removed a
number of unused classes. Removed playlist manager from a number of classes and replaced with the alias, channel and channel map models. Updated playlist manager to no longer retain a playlist except for when loading to models or when storing from models. Extracted version 1 to version 2 playlist conversion and changed playlist manager to keep the original version 1 playlist and create a new version 2 (playlist_v2.xml) file. On startup, try to load a v2, and if not, look for a v1 to convert. Otherwise, don't create a playlist and one will be created once the user adds items to the models.
This commit is contained in:
@@ -36,34 +36,29 @@ import javax.xml.bind.Unmarshaller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import playlist.version1.PlaylistConverterV1ToV2;
|
||||
import properties.SystemProperties;
|
||||
import sample.Listener;
|
||||
import alias.Alias;
|
||||
import alias.AliasDirectory;
|
||||
import alias.AliasEvent;
|
||||
import alias.AliasList;
|
||||
import alias.AliasModel;
|
||||
import alias.Group;
|
||||
import controller.ThreadPoolManager;
|
||||
import controller.channel.Channel;
|
||||
import controller.channel.Channel.ChannelType;
|
||||
import controller.channel.ChannelEvent;
|
||||
import controller.channel.ChannelEventListener;
|
||||
import controller.channel.ChannelModel;
|
||||
import controller.site.Site;
|
||||
import controller.system.SystemList;
|
||||
import controller.channel.map.ChannelMapEvent;
|
||||
import controller.channel.map.ChannelMapModel;
|
||||
|
||||
public class PlaylistManager implements ChannelEventListener, Listener<AliasEvent>
|
||||
public class PlaylistManager implements ChannelEventListener
|
||||
{
|
||||
private final static Logger mLog =
|
||||
LoggerFactory.getLogger( PlaylistManager.class );
|
||||
|
||||
private Playlist mPlaylist = new Playlist();
|
||||
|
||||
private ThreadPoolManager mThreadPoolManager;
|
||||
private AliasModel mAliasModel;
|
||||
private ChannelModel mChannelModel;
|
||||
|
||||
private ChannelMapModel mChannelMapModel;
|
||||
private Path mCurrentPlaylistPath;
|
||||
private AtomicBoolean mPlaylistSavePending = new AtomicBoolean();
|
||||
private boolean mPlaylistLoading = false;
|
||||
|
||||
@@ -79,37 +74,35 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
*/
|
||||
public PlaylistManager( ThreadPoolManager threadPoolManager,
|
||||
AliasModel aliasModel,
|
||||
ChannelModel channelModel )
|
||||
ChannelModel channelModel,
|
||||
ChannelMapModel channelMapModel )
|
||||
{
|
||||
mThreadPoolManager = threadPoolManager;
|
||||
mAliasModel = aliasModel;
|
||||
mChannelModel = channelModel;
|
||||
mChannelMapModel = channelMapModel;
|
||||
|
||||
//Register for alias and channel events so that we can save the
|
||||
//playlist with changes
|
||||
mAliasModel.addListener( this );
|
||||
//Register for alias, channel and channel map events so that we can
|
||||
//save the playlist when there are any changes
|
||||
mChannelModel.addListener( this );
|
||||
}
|
||||
|
||||
public Playlist getPlayist()
|
||||
{
|
||||
return mPlaylist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers data from persisted playlist into system models
|
||||
*/
|
||||
private void transferPlaylistToModels()
|
||||
{
|
||||
//TODO: delete the playlist after we've loaded it, since the models will have
|
||||
//all of the data
|
||||
|
||||
mPlaylistLoading = true;
|
||||
|
||||
mAliasModel.addAliases( mPlaylist.getAliases() );
|
||||
mChannelModel.addChannels( mPlaylist.getChannels() );
|
||||
|
||||
mPlaylistLoading = false;
|
||||
mAliasModel.addListener( new Listener<AliasEvent>()
|
||||
{
|
||||
@Override
|
||||
public void receive( AliasEvent t )
|
||||
{
|
||||
schedulePlaylistSave();
|
||||
}
|
||||
} );
|
||||
|
||||
mChannelMapModel.addListener( new Listener<ChannelMapEvent>()
|
||||
{
|
||||
@Override
|
||||
public void receive( ChannelMapEvent t )
|
||||
{
|
||||
schedulePlaylistSave();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,41 +116,64 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
Path playlistFolder = props.getApplicationFolder( "playlist" );
|
||||
|
||||
String defaultPlaylistFile =
|
||||
props.get( "playlist.defaultfilename", "playlist.xml" );
|
||||
props.get( "playlist.v2.defaultfilename", "playlist_v2.xml" );
|
||||
|
||||
String playlistFile =
|
||||
props.get( "playlist.currentfilename", defaultPlaylistFile );
|
||||
|
||||
load( playlistFolder.resolve( playlistFile ) );
|
||||
}
|
||||
props.get( "playlist.v2.currentfilename", defaultPlaylistFile );
|
||||
|
||||
/**
|
||||
* Alias event listener method. Monitors alias events for events that
|
||||
* indicate that the playlist has changed and queues automatic playlist
|
||||
* saving.
|
||||
*/
|
||||
@Override
|
||||
public void receive( AliasEvent event )
|
||||
{
|
||||
if( !mPlaylistLoading )
|
||||
mCurrentPlaylistPath = playlistFolder.resolve( playlistFile );
|
||||
|
||||
PlaylistV2 playlist = load( mCurrentPlaylistPath );
|
||||
|
||||
boolean saveRequired = false;
|
||||
|
||||
if( playlist == null )
|
||||
{
|
||||
switch( event.getEvent() )
|
||||
mLog.info( "Couldn't find version 2 playlist - looking for "
|
||||
+ "version 1 playlist to convert" );
|
||||
|
||||
Path playlistV1Path = playlistFolder.resolve( "playlist.xml" );
|
||||
|
||||
PlaylistConverterV1ToV2 converter =
|
||||
new PlaylistConverterV1ToV2( playlistV1Path );
|
||||
|
||||
if( converter.hasErrorMessages() )
|
||||
{
|
||||
case ADD:
|
||||
case DELETE:
|
||||
case CHANGE:
|
||||
schedulePlaylistSave();
|
||||
break;
|
||||
default:
|
||||
//When a new event enum entry is added and received, throw an
|
||||
//exception here to ensure developer adds support for the
|
||||
//use case
|
||||
throw new IllegalArgumentException( "Unrecognized Alias "
|
||||
+ "Event [" + event.getEvent().toString() + "]" );
|
||||
mLog.error( "Playlist version 1 conversion errors: " +
|
||||
converter.getErrorMessages() );
|
||||
}
|
||||
|
||||
playlist = converter.getConvertedPlaylist();
|
||||
|
||||
saveRequired = true;
|
||||
}
|
||||
|
||||
transferPlaylistToModels( playlist );
|
||||
|
||||
if( saveRequired )
|
||||
{
|
||||
schedulePlaylistSave();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers data from persisted playlist into system models
|
||||
*/
|
||||
private void transferPlaylistToModels( PlaylistV2 playlist )
|
||||
{
|
||||
if( playlist != null )
|
||||
{
|
||||
mPlaylistLoading = true;
|
||||
|
||||
mAliasModel.addAliases( playlist.getAliases() );
|
||||
mChannelModel.addChannels( playlist.getChannels() );
|
||||
mChannelMapModel.addChannelMaps( playlist.getChannelMaps() );
|
||||
|
||||
mPlaylistLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Channel event listener method. Monitors channel events for events that
|
||||
* indicate that the playlist has changed and queues automatic playlist
|
||||
@@ -200,27 +216,30 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
|
||||
public void save()
|
||||
{
|
||||
//TODO: recreate the playlist and load values from each of the models
|
||||
PlaylistV2 playlist = new PlaylistV2();
|
||||
|
||||
mPlaylist.setAliases( mAliasModel.getAliases() );
|
||||
|
||||
mPlaylist.setChannels( mChannelModel.getChannels() );
|
||||
playlist.setAliases( mAliasModel.getAliases() );
|
||||
playlist.setChannels( mChannelModel.getChannels() );
|
||||
playlist.setChannelMaps( mChannelMapModel.getChannelMaps() );
|
||||
|
||||
JAXBContext context = null;
|
||||
|
||||
SystemProperties props = SystemProperties.getInstance();
|
||||
|
||||
Path playlistPath = props.getApplicationFolder( "playlist" );
|
||||
|
||||
String playlistDefault = props.get( "playlist.defaultfilename",
|
||||
"playlist.xml" );
|
||||
if( mCurrentPlaylistPath == null )
|
||||
{
|
||||
SystemProperties props = SystemProperties.getInstance();
|
||||
|
||||
String playlistCurrent = props.get( "playlist.currentfilename",
|
||||
playlistDefault );
|
||||
Path playlistPath = props.getApplicationFolder( "playlist" );
|
||||
|
||||
String playlistDefault = props.get( "playlist.defaultfilename",
|
||||
"playlist_v2.xml" );
|
||||
|
||||
String playlistCurrent = props.get( "playlist.currentfilename",
|
||||
playlistDefault );
|
||||
|
||||
mCurrentPlaylistPath = playlistPath.resolve( playlistCurrent );
|
||||
}
|
||||
|
||||
Path filePath = playlistPath.resolve( playlistCurrent );
|
||||
|
||||
File outputFile = new File( filePath.toString() );
|
||||
File outputFile = new File( mCurrentPlaylistPath.toString() );
|
||||
|
||||
try
|
||||
{
|
||||
@@ -232,7 +251,7 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
catch( Exception e )
|
||||
{
|
||||
mLog.error( "couldn't create file to save "
|
||||
+ "playlist [" + filePath.toString() + "]" );
|
||||
+ "playlist [" + mCurrentPlaylistPath.toString() + "]" );
|
||||
}
|
||||
|
||||
OutputStream out = null;
|
||||
@@ -243,13 +262,13 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
|
||||
try
|
||||
{
|
||||
context = JAXBContext.newInstance( Playlist.class );
|
||||
context = JAXBContext.newInstance( PlaylistV2.class );
|
||||
|
||||
Marshaller m = context.createMarshaller();
|
||||
|
||||
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
|
||||
|
||||
m.marshal( mPlaylist, out );
|
||||
m.marshal( playlist, out );
|
||||
}
|
||||
catch ( JAXBException e )
|
||||
{
|
||||
@@ -258,7 +277,8 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
mLog.error( "coulcn't open outputstream to save playlist [" + filePath.toString() + "]", e );
|
||||
mLog.error( "coulcn't open outputstream to save playlist [" +
|
||||
mCurrentPlaylistPath.toString() + "]", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -276,85 +296,17 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
}
|
||||
}
|
||||
|
||||
private void createBackupPlaylist()
|
||||
{
|
||||
SystemProperties props = SystemProperties.getInstance();
|
||||
|
||||
Path playlistPath = props.getApplicationFolder( "playlist" );
|
||||
|
||||
String playlistDefault = props.get( "playlist.defaultfilename",
|
||||
"playlist.xml" );
|
||||
|
||||
String playlistCurrent = props.get( "playlist.currentfilename",
|
||||
playlistDefault );
|
||||
|
||||
Path current = playlistPath.resolve( playlistCurrent );
|
||||
|
||||
if( Files.exists( current ) )
|
||||
{
|
||||
int revision = 1;
|
||||
|
||||
String playlistBackup = playlistCurrent.replace( ".xml", "_backup_" + revision + ".xml" );
|
||||
|
||||
Path filePath = playlistPath.resolve( playlistBackup );
|
||||
|
||||
while( Files.exists( filePath ) )
|
||||
{
|
||||
revision++;
|
||||
|
||||
playlistBackup = playlistCurrent.replace( ".xml", "_backup_" + revision + ".xml" );
|
||||
|
||||
filePath = playlistPath.resolve( playlistBackup );
|
||||
|
||||
if( revision > 10 )
|
||||
{
|
||||
mLog.error( "Couldn't create playlist backup - maximum revisions exceeded" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
File outputFile = new File( filePath.toString() );
|
||||
|
||||
try
|
||||
{
|
||||
if( !outputFile.exists() )
|
||||
{
|
||||
outputFile.createNewFile();
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
mLog.error( "PlaylistManager - couldn't create file to save "
|
||||
+ "playlist backup [" + filePath.toString() + "]" );
|
||||
}
|
||||
|
||||
try( OutputStream out = new FileOutputStream( outputFile ) )
|
||||
{
|
||||
Files.copy( current, out );
|
||||
|
||||
mLog.info( "Playlist backed up to:" + filePath );
|
||||
}
|
||||
catch( IOException ioe )
|
||||
{
|
||||
mLog.error( "Error copying playlist to backup file [" + filePath + "]" );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mLog.error( "Couldn't create backup playlist - original playlist does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases current playlist and loads playlist from the playlistPath filename,
|
||||
* if it exists.
|
||||
* Loads a version 2 playlist
|
||||
*/
|
||||
public void load( Path playlistPath )
|
||||
public PlaylistV2 load( Path playlistPath )
|
||||
{
|
||||
mLog.info( "loading version 2 playlist file [" + playlistPath.toString() + "]" );
|
||||
|
||||
PlaylistV2 playlist = null;
|
||||
|
||||
if( Files.exists( playlistPath ) )
|
||||
{
|
||||
mLog.info( "loading playlist file [" + playlistPath.toString() + "]" );
|
||||
|
||||
JAXBContext context = null;
|
||||
|
||||
InputStream in = null;
|
||||
@@ -365,11 +317,11 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
|
||||
try
|
||||
{
|
||||
context = JAXBContext.newInstance( Playlist.class );
|
||||
context = JAXBContext.newInstance( PlaylistV2.class );
|
||||
|
||||
Unmarshaller m = context.createUnmarshaller();
|
||||
|
||||
mPlaylist = (Playlist)m.unmarshal( in );
|
||||
playlist = (PlaylistV2)m.unmarshal( in );
|
||||
}
|
||||
catch ( JAXBException e )
|
||||
{
|
||||
@@ -401,91 +353,10 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
mLog.info( "PlaylistManager - playlist not found at [" +
|
||||
playlistPath.toString() + "]" );
|
||||
}
|
||||
|
||||
boolean saveRequired = false;
|
||||
|
||||
if( mPlaylist == null )
|
||||
{
|
||||
mPlaylist = new Playlist();
|
||||
saveRequired = true;
|
||||
}
|
||||
|
||||
//Check for and convert from legacy play list format
|
||||
if( mPlaylist.hasSystemList() || mPlaylist.hasAliasDirectory() )
|
||||
{
|
||||
convertPlaylistFormat();
|
||||
saveRequired = true;
|
||||
}
|
||||
|
||||
transferPlaylistToModels();
|
||||
|
||||
if( saveRequired )
|
||||
{
|
||||
save();
|
||||
}
|
||||
return playlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts playlist data over to new format
|
||||
*/
|
||||
private void convertPlaylistFormat()
|
||||
{
|
||||
mLog.info( "Legacy playlist format detected - converting" );
|
||||
|
||||
createBackupPlaylist();
|
||||
|
||||
//Playlist version 1 to version 2 format conversion. In order to keep
|
||||
//backwards compatibility, transfer all of the System-Site-Channel
|
||||
//objects over to the new channel list format
|
||||
if( mPlaylist.hasSystemList() )
|
||||
{
|
||||
SystemList systemList = mPlaylist.getSystemList();
|
||||
|
||||
for( controller.system.System system: systemList.getSystem() )
|
||||
{
|
||||
for( Site site: system.getSite() )
|
||||
{
|
||||
for( Channel channel: site.getChannel() )
|
||||
{
|
||||
channel.setSystem( system.getName() );
|
||||
channel.setSite( site.getName() );
|
||||
|
||||
mPlaylist.getChannels().add( channel );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mPlaylist.getSystemList().clearSystems();
|
||||
|
||||
mLog.info( "Converted [" + mPlaylist.getChannels().size() +
|
||||
"] channels to new playlist format" );
|
||||
}
|
||||
|
||||
if( mPlaylist.hasAliasDirectory() )
|
||||
{
|
||||
AliasDirectory aliasDirectory = mPlaylist.getAliasDirectory();
|
||||
|
||||
for( AliasList list: aliasDirectory.getAliasList() )
|
||||
{
|
||||
for( Group group: list.getGroup() )
|
||||
{
|
||||
for( Alias alias: group.getAlias() )
|
||||
{
|
||||
alias.setList( list.getName() );
|
||||
alias.setGroup( group.getName() );
|
||||
|
||||
mPlaylist.getAliases().add( alias );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mPlaylist.getAliasDirectory().clearAliasLists();
|
||||
|
||||
mLog.info( "Converted [" + mPlaylist.getAliases().size() +
|
||||
"] aliases to new playlist format" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a playlist save task. Subsequent calls to this method will be
|
||||
* ignored until the save event occurs, thus limiting repetitive playlist
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import settings.SettingsManager;
|
||||
import source.SourceManager;
|
||||
import alias.AliasDirectory;
|
||||
import alias.AliasDirectoryNode;
|
||||
import controller.BaseNode;
|
||||
import controller.EmptyEditor;
|
||||
import controller.channel.ChannelModel;
|
||||
import controller.channel.ChannelProcessingManager;
|
||||
import controller.channel.map.ChannelMapList;
|
||||
import controller.channel.map.ChannelMapListNode;
|
||||
import controller.system.SystemList;
|
||||
import controller.system.SystemListNode;
|
||||
|
||||
public class PlaylistNode extends BaseNode
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private AliasDirectoryNode mAliasDirectoryNode;
|
||||
private ChannelMapListNode mChannelMapListNode;
|
||||
private SystemListNode mSystemListNode;
|
||||
|
||||
private ChannelModel mChannelModel;
|
||||
private ChannelProcessingManager mChannelProcessingManager;
|
||||
private PlaylistManager mPlaylistManager;
|
||||
private SettingsManager mSettingsManager;
|
||||
private SourceManager mSourceManager;
|
||||
|
||||
public PlaylistNode( ChannelModel channelModel,
|
||||
ChannelProcessingManager channelProcessingManager,
|
||||
PlaylistManager playlistManager,
|
||||
SettingsManager settingsManager,
|
||||
SourceManager sourceManager )
|
||||
{
|
||||
super( null );
|
||||
|
||||
mChannelModel = channelModel;
|
||||
mChannelProcessingManager = channelProcessingManager;
|
||||
mPlaylistManager = playlistManager;
|
||||
mSettingsManager = settingsManager;
|
||||
mSourceManager = sourceManager;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
/**
|
||||
* Delete any existing children
|
||||
*/
|
||||
delete();
|
||||
|
||||
/**
|
||||
* Load the AliasDirectory
|
||||
*/
|
||||
AliasDirectory directory = getPlaylist().getAliasDirectory();
|
||||
|
||||
if( directory == null )
|
||||
{
|
||||
directory = new AliasDirectory();
|
||||
getPlaylist().setAliasDirectory( directory );
|
||||
}
|
||||
|
||||
mAliasDirectoryNode = new AliasDirectoryNode( mPlaylistManager,
|
||||
mSettingsManager, directory );
|
||||
|
||||
getModel().insertNodeInto( mAliasDirectoryNode, this, 0 );
|
||||
|
||||
mAliasDirectoryNode.init();
|
||||
|
||||
/**
|
||||
* Load the Channel Map List
|
||||
*/
|
||||
ChannelMapList channelMapList = getPlaylist().getChannelMapList();
|
||||
|
||||
if( channelMapList == null )
|
||||
{
|
||||
channelMapList = new ChannelMapList();
|
||||
}
|
||||
|
||||
mChannelMapListNode = new ChannelMapListNode( mPlaylistManager, channelMapList );
|
||||
|
||||
getModel().insertNodeInto( mChannelMapListNode, this, 1 );
|
||||
|
||||
mChannelMapListNode.init();
|
||||
|
||||
/**
|
||||
* Load the SystemList
|
||||
*/
|
||||
SystemList list = getPlaylist().getSystemList();
|
||||
|
||||
if( list == null )
|
||||
{
|
||||
list = new SystemList();
|
||||
getPlaylist().setSystemList( list );
|
||||
}
|
||||
|
||||
mSystemListNode = new SystemListNode( list, mChannelModel,
|
||||
mChannelProcessingManager, mPlaylistManager, mSourceManager );
|
||||
|
||||
getModel().insertNodeInto( mSystemListNode, this, 2 );
|
||||
|
||||
mSystemListNode.init();
|
||||
|
||||
mSystemListNode.show();
|
||||
}
|
||||
|
||||
public SystemListNode getSystemListNode()
|
||||
{
|
||||
return mSystemListNode;
|
||||
}
|
||||
|
||||
public AliasDirectoryNode getAliasDirectoryNode()
|
||||
{
|
||||
return mAliasDirectoryNode;
|
||||
}
|
||||
|
||||
public void loadPlaylist()
|
||||
{
|
||||
Playlist playlist = mPlaylistManager.getPlayist();
|
||||
|
||||
setUserObject( playlist );
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
public Playlist getPlaylist()
|
||||
{
|
||||
Playlist retVal = null;
|
||||
|
||||
Object userObject = getUserObject();
|
||||
|
||||
if( userObject != null )
|
||||
{
|
||||
retVal = (Playlist)userObject;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Playlist";
|
||||
}
|
||||
|
||||
public JPanel getEditor()
|
||||
{
|
||||
return new EmptyEditor();
|
||||
}
|
||||
}
|
||||
77
src/playlist/PlaylistV2.java
Normal file
77
src/playlist/PlaylistV2.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import alias.Alias;
|
||||
import controller.channel.Channel;
|
||||
import controller.channel.map.ChannelMap;
|
||||
|
||||
@XmlSeeAlso( { Alias.class,Channel.class,ChannelMap.class } )
|
||||
|
||||
@XmlRootElement( name = "playlist" )
|
||||
public class PlaylistV2
|
||||
{
|
||||
//Version 2 member variables
|
||||
private List<Alias> mAliases = new ArrayList<>();
|
||||
private List<Channel> mChannels = new ArrayList<>();
|
||||
private List<ChannelMap> mChannelMaps = new ArrayList<>();
|
||||
|
||||
public PlaylistV2()
|
||||
{
|
||||
}
|
||||
|
||||
@XmlElement( name = "alias" )
|
||||
public List<Alias> getAliases()
|
||||
{
|
||||
return mAliases;
|
||||
}
|
||||
|
||||
public void setAliases( List<Alias> aliases )
|
||||
{
|
||||
mAliases = aliases;
|
||||
}
|
||||
|
||||
@XmlElement( name = "channel" )
|
||||
public List<Channel> getChannels()
|
||||
{
|
||||
return mChannels;
|
||||
}
|
||||
|
||||
public void setChannels( List<Channel> channels )
|
||||
{
|
||||
mChannels = channels;
|
||||
}
|
||||
|
||||
@XmlElement( name = "channel_map" )
|
||||
public List<ChannelMap> getChannelMaps()
|
||||
{
|
||||
return mChannelMaps;
|
||||
}
|
||||
|
||||
public void setChannelMaps( List<ChannelMap> channelMaps )
|
||||
{
|
||||
mChannelMaps = channelMaps;
|
||||
}
|
||||
}
|
||||
91
src/playlist/version1/AliasDirectory.java
Normal file
91
src/playlist/version1/AliasDirectory.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist.version1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import alias.AliasList;
|
||||
|
||||
@XmlSeeAlso( { AliasList.class} )
|
||||
@XmlRootElement( name = "alias_directory" )
|
||||
@Deprecated
|
||||
public class AliasDirectory
|
||||
{
|
||||
private ArrayList<AliasListOld> mAliasList = new ArrayList<>();
|
||||
|
||||
public AliasDirectory()
|
||||
{
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
}
|
||||
|
||||
public void clearAliasLists()
|
||||
{
|
||||
mAliasList.clear();
|
||||
}
|
||||
|
||||
@XmlElement( name = "alias_list" )
|
||||
public ArrayList<AliasListOld> getAliasList()
|
||||
{
|
||||
return mAliasList;
|
||||
}
|
||||
|
||||
public void setAliasList( ArrayList<AliasListOld> lists )
|
||||
{
|
||||
mAliasList = lists;
|
||||
|
||||
if( mAliasList == null )
|
||||
{
|
||||
mAliasList = new ArrayList<AliasListOld>();
|
||||
}
|
||||
}
|
||||
|
||||
public void addAliasList( AliasListOld list )
|
||||
{
|
||||
mAliasList.add( list );
|
||||
}
|
||||
|
||||
public void removeAliasList( AliasListOld list )
|
||||
{
|
||||
mAliasList.remove( list );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the named alias list, or returns an empty alias list
|
||||
*/
|
||||
public AliasListOld getAliasList( String name )
|
||||
{
|
||||
AliasListOld retVal = new AliasListOld( name );
|
||||
|
||||
for( AliasListOld list: mAliasList )
|
||||
{
|
||||
if( list.getName().equalsIgnoreCase( name ) )
|
||||
{
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
583
src/playlist/version1/AliasListOld.java
Normal file
583
src/playlist/version1/AliasListOld.java
Normal file
@@ -0,0 +1,583 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014,2015 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist.version1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import module.decode.lj1200.LJ1200Message.Function;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import alias.Alias;
|
||||
import alias.action.AliasAction;
|
||||
import alias.action.beep.BeepAction;
|
||||
import alias.action.clip.ClipAction;
|
||||
import alias.action.script.ScriptAction;
|
||||
import alias.id.AliasID;
|
||||
import alias.id.esn.Esn;
|
||||
import alias.id.fleetsync.FleetsyncID;
|
||||
import alias.id.lojack.LoJackFunctionAndID;
|
||||
import alias.id.mdc.MDC1200ID;
|
||||
import alias.id.mobileID.Min;
|
||||
import alias.id.mpt1327.MPT1327ID;
|
||||
import alias.id.nonrecordable.NonRecordable;
|
||||
import alias.id.priority.Priority;
|
||||
import alias.id.siteID.SiteID;
|
||||
import alias.id.status.StatusID;
|
||||
import alias.id.talkgroup.TalkgroupID;
|
||||
import alias.id.uniqueID.UniqueID;
|
||||
import audio.metadata.MetadataType;
|
||||
|
||||
@XmlSeeAlso( { Alias.class,
|
||||
|
||||
/* Alias ID's */
|
||||
AliasID.class,
|
||||
FleetsyncID.class,
|
||||
Esn.class,
|
||||
Group.class,
|
||||
LoJackFunctionAndID.class,
|
||||
MDC1200ID.class,
|
||||
Min.class,
|
||||
MPT1327ID.class,
|
||||
UniqueID.class,
|
||||
SiteID.class,
|
||||
StatusID.class,
|
||||
TalkgroupID.class,
|
||||
|
||||
/* Alias Attributes */
|
||||
NonRecordable.class,
|
||||
Priority.class,
|
||||
|
||||
/* Alias Actions */
|
||||
AliasAction.class,
|
||||
BeepAction.class,
|
||||
ClipAction.class,
|
||||
ScriptAction.class } )
|
||||
|
||||
@Deprecated
|
||||
@XmlRootElement( name = "alias_list" )
|
||||
public class AliasListOld implements Comparable<AliasListOld>
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( AliasListOld.class );
|
||||
|
||||
private String mName;
|
||||
private ArrayList<Group> mGroups = new ArrayList<Group>();
|
||||
|
||||
private Map<String,Alias> mESN = new HashMap<>();
|
||||
private Map<String,Alias> mFleetsync = new HashMap<>();
|
||||
private Map<LoJackFunctionAndID,Alias> mLoJack = new HashMap<>();
|
||||
private Map<String,Alias> mMDC1200 = new HashMap<>();
|
||||
private Map<String,Alias> mMobileID = new HashMap<>();
|
||||
private Map<String,Alias> mMPT1327 = new HashMap<>();
|
||||
private Map<String, Alias> mSiteID = new HashMap<>();
|
||||
private Map<Integer, Alias> mStatus = new HashMap<>();
|
||||
private Map<String,Alias> mTalkgroup = new HashMap<>();
|
||||
private Map<Integer,Alias> mUniqueID = new HashMap<>();
|
||||
|
||||
private boolean mESNWildcard = false;
|
||||
private boolean mMobileIDWildcard = false;
|
||||
private boolean mFleetsyncWildcard = false;
|
||||
private boolean mMDC1200Wildcard = false;
|
||||
private boolean mMPT1327Wildcard = false;
|
||||
private boolean mSiteWildcard = false;
|
||||
private boolean mTalkgroupWildcard = false;
|
||||
|
||||
public AliasListOld()
|
||||
{
|
||||
this( null );
|
||||
}
|
||||
|
||||
public AliasListOld( String name )
|
||||
{
|
||||
mName = name;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load/Reload all lookup hashmaps
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
//Clear hashmaps
|
||||
mESN.clear();
|
||||
mFleetsync.clear();
|
||||
mLoJack.clear();
|
||||
mMDC1200.clear();
|
||||
mMobileID.clear();
|
||||
mMPT1327.clear();
|
||||
mSiteID.clear();
|
||||
mStatus.clear();
|
||||
mTalkgroup.clear();
|
||||
mUniqueID.clear();
|
||||
|
||||
for( Group group: mGroups )
|
||||
{
|
||||
for( Alias alias: group.getAlias() )
|
||||
{
|
||||
for( AliasID id: alias.getId() )
|
||||
{
|
||||
switch( id.getType() )
|
||||
{
|
||||
case ESN:
|
||||
Esn esn = (Esn)id;
|
||||
if( esn.getEsn().contains( "*" ) )
|
||||
{
|
||||
mESNWildcard = true;
|
||||
|
||||
mESN.put( fixWildcard( esn.getEsn() ), alias );
|
||||
}
|
||||
else
|
||||
{
|
||||
mESN.put( esn.getEsn(), alias );
|
||||
}
|
||||
break;
|
||||
case Fleetsync:
|
||||
FleetsyncID fs = (FleetsyncID)id;
|
||||
|
||||
if( fs.getIdent().contains( "*" ) )
|
||||
{
|
||||
mFleetsyncWildcard = true;
|
||||
|
||||
mFleetsync.put( fixWildcard( fs.getIdent() ), alias );
|
||||
}
|
||||
else
|
||||
{
|
||||
mFleetsync.put( fs.getIdent(), alias );
|
||||
}
|
||||
break;
|
||||
case LoJack:
|
||||
mLoJack.put( (LoJackFunctionAndID)id, alias );
|
||||
break;
|
||||
case MDC1200:
|
||||
MDC1200ID mdc = (MDC1200ID)id;
|
||||
|
||||
if( mdc.getIdent().contains( "*" ) )
|
||||
{
|
||||
mMDC1200Wildcard = true;
|
||||
|
||||
//Replace (*) wildcard with regex wildcard (.)
|
||||
mMDC1200.put( fixWildcard( mdc.getIdent() ), alias );
|
||||
}
|
||||
else
|
||||
{
|
||||
mMDC1200.put( mdc.getIdent(), alias );
|
||||
}
|
||||
break;
|
||||
case MPT1327:
|
||||
MPT1327ID mpt = (MPT1327ID)id;
|
||||
|
||||
String ident = mpt.getIdent();
|
||||
|
||||
if( ident != null )
|
||||
{
|
||||
if( ident.contains( "*" ) )
|
||||
{
|
||||
mMPT1327Wildcard = true;
|
||||
|
||||
//Replace (*) wildcard with regex wildcard (.)
|
||||
mMPT1327.put( fixWildcard( ident ), alias );
|
||||
}
|
||||
else
|
||||
{
|
||||
mMPT1327.put( ident, alias );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MIN:
|
||||
Min min = (Min)id;
|
||||
|
||||
if( min.getMin().contains( "*" ) )
|
||||
{
|
||||
mMobileIDWildcard = true;
|
||||
mMobileID.put( fixWildcard( min.getMin() ), alias );
|
||||
}
|
||||
else
|
||||
{
|
||||
mMobileID.put( min.getMin(), alias );
|
||||
}
|
||||
break;
|
||||
case LTRNetUID:
|
||||
UniqueID uid = (UniqueID)id;
|
||||
|
||||
mUniqueID.put( uid.getUid(), alias );
|
||||
break;
|
||||
case Site:
|
||||
SiteID siteID = (SiteID)id;
|
||||
|
||||
if( siteID.getSite().contains( "*" ) )
|
||||
{
|
||||
mSiteWildcard = true;
|
||||
mSiteID.put( fixWildcard( siteID.getSite() ), alias );
|
||||
}
|
||||
else
|
||||
{
|
||||
mSiteID.put( siteID.getSite(), alias );
|
||||
}
|
||||
|
||||
break;
|
||||
case Status:
|
||||
mStatus.put( ((StatusID)id).getStatus(), alias );
|
||||
break;
|
||||
case Talkgroup:
|
||||
TalkgroupID tgid = (TalkgroupID)id;
|
||||
|
||||
if( tgid.getTalkgroup().contains( "*" ) )
|
||||
{
|
||||
mTalkgroupWildcard = true;
|
||||
|
||||
//Replace (*) wildcard with regex wildcard (.)
|
||||
mTalkgroup.put( fixWildcard( tgid.getTalkgroup() ), alias );
|
||||
}
|
||||
else
|
||||
{
|
||||
mTalkgroup.put( tgid.getTalkgroup(), alias );
|
||||
}
|
||||
break;
|
||||
case NonRecordable:
|
||||
case Priority:
|
||||
//We don't maintain lookups for these items
|
||||
break;
|
||||
default:
|
||||
mLog.warn( "Unrecognized Alias ID Type:" + id.getType().name() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts user wildcard character (*) to regex single character wildcard (.)
|
||||
* but ignores a regex multi-character wildcard (.*)
|
||||
*/
|
||||
private String fixWildcard( String value )
|
||||
{
|
||||
if( value.contains( "*" ) && !value.contains( ".*" ) )
|
||||
{
|
||||
return value.replace( "*", "." );
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public Alias getSiteID( String siteID )
|
||||
{
|
||||
if( siteID != null )
|
||||
{
|
||||
if( mSiteWildcard )
|
||||
{
|
||||
for( String regex: mSiteID.keySet() )
|
||||
{
|
||||
if( siteID.matches( regex ) )
|
||||
{
|
||||
return mSiteID.get( regex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return mSiteID.get( siteID );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Alias getStatus( int status )
|
||||
{
|
||||
return mStatus.get( status );
|
||||
}
|
||||
|
||||
public Alias getUniqueID( int uniqueID )
|
||||
{
|
||||
return mUniqueID.get( uniqueID );
|
||||
}
|
||||
|
||||
public Alias getESNAlias( String esn )
|
||||
{
|
||||
if( esn != null )
|
||||
{
|
||||
if( mESNWildcard )
|
||||
{
|
||||
for( String regex: mESN.keySet() )
|
||||
{
|
||||
if( esn.matches( regex ) )
|
||||
{
|
||||
return mESN.get( regex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return mESN.get( esn );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Alias getFleetsyncAlias( String ident )
|
||||
{
|
||||
if( ident != null )
|
||||
{
|
||||
if( mFleetsyncWildcard )
|
||||
{
|
||||
for( String regex: mFleetsync.keySet() )
|
||||
{
|
||||
if( ident.matches( regex ) )
|
||||
{
|
||||
return mFleetsync.get( regex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return mFleetsync.get( ident );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Alias getLoJackAlias( Function function, String id )
|
||||
{
|
||||
if( id != null )
|
||||
{
|
||||
for( LoJackFunctionAndID lojack: mLoJack.keySet() )
|
||||
{
|
||||
if( lojack.matches( function, id ) )
|
||||
{
|
||||
return mLoJack.get( lojack );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Alias getMDC1200Alias( String ident )
|
||||
{
|
||||
if( ident != null )
|
||||
{
|
||||
if( mMDC1200Wildcard )
|
||||
{
|
||||
for( String regex: mMDC1200.keySet() )
|
||||
{
|
||||
if( ident.matches( regex ) )
|
||||
{
|
||||
return mMDC1200.get( regex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return mMDC1200.get( ident );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Alias getMPT1327Alias( String ident )
|
||||
{
|
||||
if( ident != null )
|
||||
{
|
||||
if( mMPT1327Wildcard )
|
||||
{
|
||||
for( String regex: mMPT1327.keySet() )
|
||||
{
|
||||
if( ident.matches( regex ) )
|
||||
{
|
||||
return mMPT1327.get( regex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return mMPT1327.get( ident );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Group getGroup( Alias alias )
|
||||
{
|
||||
if( alias != null )
|
||||
{
|
||||
for( Group group: mGroups )
|
||||
{
|
||||
if( group.contains( alias ) )
|
||||
{
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Alias getMobileIDNumberAlias( String ident )
|
||||
{
|
||||
if( ident != null )
|
||||
{
|
||||
if( mMobileIDWildcard )
|
||||
{
|
||||
for( String regex: mMobileID.keySet() )
|
||||
{
|
||||
if( ident.matches( regex ) )
|
||||
{
|
||||
return mMobileID.get( regex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return mMobileID.get( ident );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Alias getTalkgroupAlias( String tgid )
|
||||
{
|
||||
if( tgid != null )
|
||||
{
|
||||
if( mTalkgroupWildcard )
|
||||
{
|
||||
for( String regex: mTalkgroup.keySet() )
|
||||
{
|
||||
if( tgid.matches( regex ) )
|
||||
{
|
||||
return mTalkgroup.get( regex );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return mTalkgroup.get( tgid );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public ArrayList<Group> getGroup()
|
||||
{
|
||||
return mGroups;
|
||||
}
|
||||
|
||||
public void setGroup( ArrayList<Group> groups )
|
||||
{
|
||||
mGroups = groups;
|
||||
}
|
||||
|
||||
public void addGroup( Group group )
|
||||
{
|
||||
mGroups.add( group );
|
||||
}
|
||||
|
||||
public void removeGroup( Group group )
|
||||
{
|
||||
mGroups.remove( group );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo( AliasListOld otherAliasList )
|
||||
{
|
||||
return getName().compareTo( otherAliasList.getName() );
|
||||
}
|
||||
|
||||
public Alias getAlias( String value, MetadataType type )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case ESN:
|
||||
return getESNAlias( value );
|
||||
case FLEETSYNC:
|
||||
return getFleetsyncAlias( value );
|
||||
case MDC1200:
|
||||
return getMDC1200Alias( value );
|
||||
case MOBILE_ID:
|
||||
return getMobileIDNumberAlias( value );
|
||||
case MPT1327:
|
||||
return getMPT1327Alias( value );
|
||||
case SITE_ID:
|
||||
return getSiteID( value );
|
||||
case STATUS:
|
||||
if( value != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
return getStatus( Integer.valueOf( value ) );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
//do nothing, we couldn't parse the int value
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FROM:
|
||||
case TO:
|
||||
return getTalkgroupAlias( value );
|
||||
case UNIQUE_ID:
|
||||
if( value != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
return getUniqueID( Integer.valueOf( value ) );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
//do nothing, we couldn't parse the int value
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
79
src/playlist/version1/ChannelMapList.java
Normal file
79
src/playlist/version1/ChannelMapList.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist.version1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import controller.channel.map.ChannelMap;
|
||||
|
||||
@XmlSeeAlso( ChannelMap.class )
|
||||
@Deprecated
|
||||
public class ChannelMapList
|
||||
{
|
||||
private ArrayList<ChannelMap> mChannelMap = new ArrayList<ChannelMap>();
|
||||
|
||||
public ChannelMapList()
|
||||
{
|
||||
/* Empty constructor for JAXB */
|
||||
}
|
||||
|
||||
@XmlElement( name = "channel_map" )
|
||||
public ArrayList<ChannelMap> getChannelMap()
|
||||
{
|
||||
return mChannelMap;
|
||||
}
|
||||
|
||||
public void setChannelMap( ArrayList<ChannelMap> ChannelMaps )
|
||||
{
|
||||
mChannelMap = ChannelMaps;
|
||||
}
|
||||
|
||||
public void addChannelMap( ChannelMap ChannelMap )
|
||||
{
|
||||
mChannelMap.add( ChannelMap );
|
||||
}
|
||||
|
||||
public void removeChannelMap( ChannelMap ChannelMap )
|
||||
{
|
||||
mChannelMap.remove( ChannelMap );
|
||||
}
|
||||
|
||||
public void clearChannelMaps()
|
||||
{
|
||||
mChannelMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the named channel map, or returns an empty map
|
||||
*/
|
||||
public ChannelMap getChannelMap( String name )
|
||||
{
|
||||
for( ChannelMap map: mChannelMap )
|
||||
{
|
||||
if( map.getName().equalsIgnoreCase( name ) )
|
||||
{
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
return new ChannelMap();
|
||||
}
|
||||
}
|
||||
76
src/playlist/version1/Group.java
Normal file
76
src/playlist/version1/Group.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist.version1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import alias.Alias;
|
||||
|
||||
@Deprecated
|
||||
public class Group
|
||||
{
|
||||
private String mName;
|
||||
private ArrayList<Alias> mAliases = new ArrayList<Alias>();
|
||||
|
||||
public Group()
|
||||
{
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Group: " + mName;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public ArrayList<Alias> getAlias()
|
||||
{
|
||||
return mAliases;
|
||||
}
|
||||
|
||||
public void setAlias( ArrayList<Alias> aliases )
|
||||
{
|
||||
mAliases = aliases;
|
||||
}
|
||||
|
||||
public void addAlias( Alias alias )
|
||||
{
|
||||
mAliases.add( alias );
|
||||
}
|
||||
|
||||
public void removeAlias( Alias alias )
|
||||
{
|
||||
mAliases.remove( alias );
|
||||
}
|
||||
|
||||
public boolean contains( Alias alias )
|
||||
{
|
||||
return mAliases.contains( alias );
|
||||
}
|
||||
}
|
||||
168
src/playlist/version1/PlaylistConverterV1ToV2.java
Normal file
168
src/playlist/version1/PlaylistConverterV1ToV2.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package playlist.version1;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import playlist.PlaylistV2;
|
||||
import alias.Alias;
|
||||
import alias.AliasList;
|
||||
import controller.channel.Channel;
|
||||
import controller.channel.map.ChannelMap;
|
||||
|
||||
public class PlaylistConverterV1ToV2
|
||||
{
|
||||
private final static Logger mLog =
|
||||
LoggerFactory.getLogger( PlaylistConverterV1ToV2.class );
|
||||
|
||||
private PlaylistV2 mConvertedPlaylist;
|
||||
private List<String> mErrors = new ArrayList<>();
|
||||
|
||||
public PlaylistConverterV1ToV2( Path path )
|
||||
{
|
||||
PlaylistV1 playlistVersion1 = null;
|
||||
|
||||
if( path != null && Files.exists( path ) )
|
||||
{
|
||||
mLog.info( "attempting playlist v1 to v2 conversion [" +
|
||||
path.toString() + "]" );
|
||||
|
||||
JAXBContext context = null;
|
||||
|
||||
InputStream in = null;
|
||||
|
||||
try
|
||||
{
|
||||
in = new FileInputStream( path.toString() );
|
||||
|
||||
try
|
||||
{
|
||||
context = JAXBContext.newInstance( PlaylistV1.class );
|
||||
|
||||
Unmarshaller m = context.createUnmarshaller();
|
||||
|
||||
playlistVersion1 = (PlaylistV1)m.unmarshal( in );
|
||||
}
|
||||
catch ( JAXBException e )
|
||||
{
|
||||
mErrors.add( "Couldn't unmarshall version 1 playlist - " +
|
||||
e.getLocalizedMessage() );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
mErrors.add( "Couldn't open version 1 playlist - [" +
|
||||
path.toString() + "] - " + e.getLocalizedMessage() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if( in != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
mLog.error( "exception while closing " +
|
||||
"the playlist file inputstream reader", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mErrors.add( "version 1 playlist is null or not found [" +
|
||||
path.toString() + "]" );
|
||||
}
|
||||
|
||||
if( playlistVersion1 != null )
|
||||
{
|
||||
mConvertedPlaylist = new PlaylistV2();
|
||||
|
||||
if( playlistVersion1.hasSystemList() )
|
||||
{
|
||||
SystemList systemList = playlistVersion1.getSystemList();
|
||||
|
||||
for( playlist.version1.System system: systemList.getSystem() )
|
||||
{
|
||||
for( Site site: system.getSite() )
|
||||
{
|
||||
for( Channel channel: site.getChannel() )
|
||||
{
|
||||
channel.setSystem( system.getName() );
|
||||
channel.setSite( site.getName() );
|
||||
|
||||
mConvertedPlaylist.getChannels().add( channel );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( playlistVersion1.hasAliasDirectory() )
|
||||
{
|
||||
AliasDirectory aliasDirectory = playlistVersion1.getAliasDirectory();
|
||||
|
||||
for( AliasListOld list: aliasDirectory.getAliasList() )
|
||||
{
|
||||
for( Group group: list.getGroup() )
|
||||
{
|
||||
for( Alias alias: group.getAlias() )
|
||||
{
|
||||
alias.setList( list.getName() );
|
||||
alias.setGroup( group.getName() );
|
||||
|
||||
mConvertedPlaylist.getAliases().add( alias );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( playlistVersion1.hasChannelMapList() )
|
||||
{
|
||||
//Move the channel maps out of the channel map list
|
||||
ChannelMapList channelMapList = playlistVersion1.getChannelMapList();
|
||||
|
||||
List<ChannelMap> channelMaps = channelMapList.getChannelMap();
|
||||
|
||||
if( channelMaps != null && !channelMaps.isEmpty() )
|
||||
{
|
||||
mConvertedPlaylist.getChannelMaps().addAll( channelMaps );
|
||||
}
|
||||
}
|
||||
|
||||
mLog.info( "Converted [" + mConvertedPlaylist.getChannels().size() +
|
||||
"] channels to new playlist format" );
|
||||
mLog.info( "Converted [" + mConvertedPlaylist.getAliases().size() +
|
||||
"] aliases to new playlist format" );
|
||||
mLog.info( "Converted [" + mConvertedPlaylist.getChannelMaps().size() +
|
||||
"] channel maps to new playlist format" );
|
||||
}
|
||||
}
|
||||
|
||||
public PlaylistV2 getConvertedPlaylist()
|
||||
{
|
||||
return mConvertedPlaylist;
|
||||
}
|
||||
|
||||
public List<String> getErrorMessages()
|
||||
{
|
||||
return mErrors;
|
||||
}
|
||||
|
||||
public boolean hasErrorMessages()
|
||||
{
|
||||
return !mErrors.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -15,20 +15,14 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
package playlist.version1;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import alias.Alias;
|
||||
import alias.AliasDirectory;
|
||||
import controller.channel.Channel;
|
||||
import controller.channel.map.ChannelMapList;
|
||||
import controller.system.SystemList;
|
||||
|
||||
@XmlSeeAlso( { AliasDirectory.class,
|
||||
Alias.class,
|
||||
@@ -36,41 +30,19 @@ import controller.system.SystemList;
|
||||
ChannelMapList.class,
|
||||
SystemList.class } )
|
||||
|
||||
@Deprecated
|
||||
@XmlRootElement( name = "playlist" )
|
||||
public class Playlist
|
||||
public class PlaylistV1
|
||||
{
|
||||
//Note: these are for legacy version 1 format playlists
|
||||
private AliasDirectory mAliasDirectory = new AliasDirectory();
|
||||
private ChannelMapList mChannelMapList = new ChannelMapList();
|
||||
private SystemList mSystemList = new SystemList();
|
||||
private List<Alias> mAliases = new ArrayList<>();
|
||||
private List<Channel> mChannels = new ArrayList<>();
|
||||
|
||||
public Playlist()
|
||||
|
||||
public PlaylistV1()
|
||||
{
|
||||
}
|
||||
|
||||
@XmlElement( name = "alias" )
|
||||
public List<Alias> getAliases()
|
||||
{
|
||||
return mAliases;
|
||||
}
|
||||
|
||||
public void setAliases( List<Alias> aliases )
|
||||
{
|
||||
mAliases = aliases;
|
||||
}
|
||||
|
||||
@XmlElement( name = "channel" )
|
||||
public List<Channel> getChannels()
|
||||
{
|
||||
return mChannels;
|
||||
}
|
||||
|
||||
public void setChannels( List<Channel> channels )
|
||||
{
|
||||
mChannels = channels;
|
||||
}
|
||||
|
||||
@XmlElement( name = "alias_directory" )
|
||||
public AliasDirectory getAliasDirectory()
|
||||
{
|
||||
@@ -79,6 +51,7 @@ public class Playlist
|
||||
return mAliasDirectory;
|
||||
}
|
||||
|
||||
|
||||
public void setAliasDirectory( AliasDirectory directory )
|
||||
{
|
||||
mAliasDirectory = directory;
|
||||
@@ -90,6 +63,7 @@ public class Playlist
|
||||
mAliasDirectory.getAliasList() != null &&
|
||||
!mAliasDirectory.getAliasList().isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@XmlElement( name = "system_list" )
|
||||
public SystemList getSystemList()
|
||||
@@ -97,6 +71,7 @@ public class Playlist
|
||||
return mSystemList;
|
||||
}
|
||||
|
||||
|
||||
public void setSystemList( SystemList list )
|
||||
{
|
||||
mSystemList = list;
|
||||
@@ -109,12 +84,21 @@ public class Playlist
|
||||
!mSystemList.getSystem().isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@XmlElement( name = "channel_maps" )
|
||||
public ChannelMapList getChannelMapList()
|
||||
{
|
||||
return mChannelMapList;
|
||||
}
|
||||
|
||||
public boolean hasChannelMapList()
|
||||
{
|
||||
return mChannelMapList != null &&
|
||||
mChannelMapList.getChannelMap() != null &&
|
||||
!mChannelMapList.getChannelMap().isEmpty();
|
||||
}
|
||||
|
||||
|
||||
public void setChannelMapList( ChannelMapList list )
|
||||
{
|
||||
mChannelMapList = list;
|
||||
87
src/playlist/version1/Site.java
Normal file
87
src/playlist/version1/Site.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist.version1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import controller.channel.Channel;
|
||||
|
||||
@XmlSeeAlso( { Channel.class } )
|
||||
@XmlRootElement( name = "site" )
|
||||
@Deprecated
|
||||
public class Site
|
||||
{
|
||||
private String mName;
|
||||
|
||||
private ArrayList<Channel> mChannel = new ArrayList<Channel>();
|
||||
|
||||
public Site()
|
||||
{
|
||||
this( "New Site" );
|
||||
}
|
||||
|
||||
public Site( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public ArrayList<Channel> getChannel()
|
||||
{
|
||||
return mChannel;
|
||||
}
|
||||
|
||||
public void setChannel( ArrayList<Channel> configs )
|
||||
{
|
||||
mChannel = configs;
|
||||
}
|
||||
|
||||
public void addChannel( Channel channel )
|
||||
{
|
||||
mChannel.add( channel );
|
||||
}
|
||||
|
||||
public void removeChannel( Channel channel )
|
||||
{
|
||||
mChannel.remove( channel );
|
||||
}
|
||||
|
||||
public void removeAllChannels()
|
||||
{
|
||||
mChannel.clear();
|
||||
}
|
||||
}
|
||||
84
src/playlist/version1/System.java
Normal file
84
src/playlist/version1/System.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist.version1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
@XmlSeeAlso( { Site.class } )
|
||||
@XmlRootElement( name = "system" )
|
||||
@Deprecated
|
||||
public class System
|
||||
{
|
||||
private String mName;
|
||||
private ArrayList<Site> mSite = new ArrayList<Site>();
|
||||
|
||||
public System()
|
||||
{
|
||||
this( "New System" );
|
||||
}
|
||||
|
||||
public System( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public ArrayList<Site> getSite()
|
||||
{
|
||||
return mSite;
|
||||
}
|
||||
|
||||
public void setSite( ArrayList<Site> sites )
|
||||
{
|
||||
mSite = sites;
|
||||
}
|
||||
|
||||
public void addSite( Site site )
|
||||
{
|
||||
mSite.add( site );
|
||||
}
|
||||
|
||||
public void removeSite( Site site )
|
||||
{
|
||||
mSite.remove( site );
|
||||
}
|
||||
|
||||
public void clearSites()
|
||||
{
|
||||
mSite.clear();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
}
|
||||
61
src/playlist/version1/SystemList.java
Normal file
61
src/playlist/version1/SystemList.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package playlist.version1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
@XmlSeeAlso( { playlist.version1.System.class } )
|
||||
|
||||
@XmlRootElement( name = "system_list" )
|
||||
@Deprecated
|
||||
public class SystemList
|
||||
{
|
||||
private ArrayList<System> mSystem = new ArrayList<System>();
|
||||
|
||||
public SystemList()
|
||||
{
|
||||
}
|
||||
|
||||
public ArrayList<System> getSystem()
|
||||
{
|
||||
return mSystem;
|
||||
}
|
||||
|
||||
public void setSystem( ArrayList<System> systems )
|
||||
{
|
||||
mSystem = systems;
|
||||
}
|
||||
|
||||
public void addSystem( System system )
|
||||
{
|
||||
mSystem.add( system );
|
||||
}
|
||||
|
||||
public void removeSystem( System system )
|
||||
{
|
||||
mSystem.remove( system );
|
||||
}
|
||||
|
||||
public void clearSystems()
|
||||
{
|
||||
mSystem.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user