Skip to content
Snippets Groups Projects
Commit f489f32e authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Fix exceptions on project import with media

parent 976ff43b
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AntConfiguration">
<buildFile url="file://$PROJECT_DIR$/PlayWall/build.xml" />
</component>
</project>
\ No newline at end of file
......@@ -4,6 +4,8 @@ import de.tobias.playpad.view.PseudoClasses;
import de.tobias.playpad.viewcontroller.dialog.PathMatchDialog;
import javafx.scene.control.TableCell;
import java.nio.file.Path;
public class PathMatchPathCell extends TableCell<PathMatchDialog.TempMediaPath, PathMatchDialog.TempMediaPath> {
@Override
......@@ -14,7 +16,10 @@ public class PathMatchPathCell extends TableCell<PathMatchDialog.TempMediaPath,
if (item.isMatched()) {
setText(item.getLocalPath().toString());
} else {
setText(item.getMediaPath().getPath().toString());
Path path = item.getMediaPath().getPath();
if (path != null) {
setText(path.toString());
}
}
} else {
setText(null);
......
......@@ -365,7 +365,10 @@ public class Pad {
public void removePath(MediaPath path) {
mediaPaths.remove(path);
}
public void removePathListener(MediaPath path) {
if (project.getProjectReference().isSync()) {
CommandManager.execute(Commands.PATH_REMOVE, project.getProjectReference(), path);
}
......
......@@ -26,10 +26,7 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
/**
* Created by tobias on 11.03.17.
......@@ -69,10 +66,11 @@ public class ProjectImporter {
}
importedProjectReference = importProjectFile();
replaceMediaPathIds(loadMediaPaths());
if (includeMedia && delegate.shouldImportMedia()) {
importMedia();
importMedia(loadMediaPaths());
} else {
replaceMediaPathIds(loadMediaPaths());
}
}
......@@ -146,10 +144,20 @@ public class ProjectImporter {
Project project = loader.load();
for (Pad pad : project.getPads()) {
pad.getPaths().forEach(oldMediaPath -> find(mediaPaths, oldMediaPath.getId()).ifPresent(result -> {
pad.removePath(oldMediaPath);
Iterator<MediaPath> iterator = pad.getPaths().iterator();
while (iterator.hasNext()) {
MediaPath oldMediaPath = iterator.next();
find(mediaPaths, oldMediaPath.getId()).ifPresent(result -> {
try {
pad.removePathListener(oldMediaPath);
iterator.remove();
pad.setPath(result.getPath());
}));
} catch (NullPointerException e) {
Logger.error("Import Error on Pad: " + pad.getUuid());
}
});
}
}
}
......@@ -202,7 +210,7 @@ public class ProjectImporter {
profileUUID = localProfileUUID; // Update Profile UUID with new local profile uuid
}
private void importMedia() throws ProjectNotFoundException, ProfileNotFoundException, DocumentException,
private void importMedia(List<MediaPath> mediaPaths) throws ProjectNotFoundException, ProfileNotFoundException, DocumentException,
IOException, ProfileAbortException {
Path folder = delegate.getMediaPath();
......@@ -212,7 +220,10 @@ public class ProjectImporter {
for (Pad pad : project.getPads()) {
for (MediaPath path : pad.getPaths()) {
Path fileName = path.getPath().getFileName();
Optional<MediaPath> result = find(mediaPaths, path.getId());
if (result.isPresent()) {
String fileName = result.get().getFileName();
Path zipMediaFile = Paths.get("/media").resolve(fileName);
Path newMediaPath = folder.resolve(fileName);
......@@ -220,6 +231,7 @@ public class ProjectImporter {
path.setPath(newMediaPath, false);
}
}
}
ProjectReferenceManager.saveSingleProject(project);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment