Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase logging for the exact-match-repair function #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions src/main/java/listfix/model/playlists/Playlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import listfix.view.support.ProgressWorker;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -54,6 +56,10 @@ public class Playlist
private static final String BR = System.getProperty("line.separator");
private static final String HOME_DIR = System.getProperty("user.home");
private static int NEW_LIST_COUNT = -1;

private static final Marker markerPlaylist = MarkerManager.getMarker("Playlist");
private static final Marker markerPlaylistRepair = MarkerManager.getMarker("Playlist-Repair").setParents(markerPlaylist);

private File _file;
private List<PlaylistEntry> _entries = new ArrayList<>();
private List<PlaylistEntry> _originalEntries = new ArrayList<>();
Expand Down Expand Up @@ -761,22 +767,16 @@ private List<PlaylistEntry> getEntriesForFiles(File[] files, IProgressObserver<S
return ents;
}

/**
* @param ix
* @param newName
*/
public void changeEntryFileName(int ix, String newName)
{
_entries.get(ix).setFileName(newName);
refreshStatus();
}

// returns positions of repaired rows

/**
* @param mediaLibrary Media library used to reference existing media files
* @param observer Progress observer
* @return
* @return Positions of repaired rows
*/
public List<Integer> repair(IMediaLibrary mediaLibrary, IProgressObserver observer)
{
Expand All @@ -786,35 +786,37 @@ public List<Integer> repair(IMediaLibrary mediaLibrary, IProgressObserver observ
List<Integer> fixed = new ArrayList<>();
for (int ix = 0; ix < _entries.size(); ix++)
{
if (!observer.getCancelled())
if (observer.getCancelled())
{
progress.stepCompleted();
_logger.info(markerPlaylistRepair, "Observer cancelled, quit repair");
return null;
}

PlaylistEntry entry = _entries.get(ix);
if (!entry.isFound() && !entry.isURL())
{
entry.findNewLocationFromFileList(mediaLibrary.getNestedMediaFiles());
if (entry.isFound())
{
fixed.add(ix);
refreshStatus();
}
}
else if (entry.isFound() && !entry.isURL())
progress.stepCompleted();

PlaylistEntry entry = _entries.get(ix);
if (!entry.isFound() && !entry.isURL())
{
_logger.debug(markerPlaylistRepair, "Fixing entry " + entry.getPath());
entry.findNewLocationFromFileList(mediaLibrary.getNestedMediaFiles());
if (entry.isFound())
{
if (entry.updatePathToMediaLibraryIfFoundOutside(mediaLibrary))
{
fixed.add(ix);
refreshStatus();
}
_logger.debug(markerPlaylistRepair, "Fixed entry " + entry.getPath());
fixed.add(ix);
refreshStatus();
}
}
else
else if (entry.isFound() && !entry.isURL())
{
return null;
_logger.debug(markerPlaylistRepair, "Found " + entry.getPath());
if (entry.updatePathToMediaLibraryIfFoundOutside(mediaLibrary))
{
fixed.add(ix);
refreshStatus();
}
}
}

_logger.info(markerPlaylistRepair, "Completed.");
return fixed;
}

Expand Down
20 changes: 16 additions & 4 deletions src/main/java/listfix/view/controls/PlaylistEditCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
Expand Down Expand Up @@ -82,7 +84,9 @@ public class PlaylistEditCtrl extends javax.swing.JPanel
private static final NumberFormat _intFormatter = NumberFormat.getIntegerInstance();
private static final DataFlavor _playlistEntryListFlavor = new DataFlavor(PlaylistEntryList.class, "PlaylistEntyList");
private static final DataFlavor _playlistFlavor = new DataFlavor(Playlist.class, "Playlist");

private static final Marker markerPlaylistControl = MarkerManager.getMarker("PlaylistCtrl");
private static final Marker markerRepair = MarkerManager.getMarker("PlaylistCtrl-Repair").setParents(markerPlaylistControl);
private static final Marker markerRepairWorker = MarkerManager.getMarker("PlaylistCtrl-Repair-Worker").setParents(markerRepair);
private FolderChooser _destDirFileChooser = new FolderChooser();

private int currentlySelectedRow = 0;
Expand Down Expand Up @@ -267,33 +271,41 @@ private void moveSelectedRowsDown()

public void locateMissingFiles()
{
_logger.debug(markerRepair, "Start locateMissingFiles()");
ProgressWorker worker = new ProgressWorker<List<Integer>, Void>()
{
@Override
protected List<Integer> doInBackground()
{
return _playlist.repair(PlaylistEditCtrl.this.getMediaLibrary(), this);
_logger.debug(markerRepairWorker, "Start repairing in background....");
List<Integer> result = _playlist.repair(PlaylistEditCtrl.this.getMediaLibrary(), this);
_logger.debug(markerRepairWorker, "Repair completed.");
return result;
}

@Override
protected void done()
{
_logger.debug(markerRepair, "Handling background done()");
try
{
_logger.debug(markerRepair, "Updating UI-table...");
_uiTable.clearSelection();
List<Integer> fixed = get();
for (Integer fixIx : fixed)
{
int viewIx = _uiTable.convertRowIndexToView(fixIx.intValue());
_uiTable.addRowSelectionInterval(viewIx, viewIx);
}
_logger.debug(markerRepair, "Completed updating UI-table");
}
catch (CancellationException | InterruptedException ignored)
catch (CancellationException | InterruptedException exception)
{
_logger.warn(markerRepair, "Repair interrupted", exception);
}
catch (ExecutionException ex)
{
_logger.error("Error processing missing files", ex);
_logger.error(markerRepair, "Error processing missing files", ex);
}
}
};
Expand Down