diff --git a/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF b/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF index ec000e6..9fcc209 100644 --- a/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF +++ b/xyz.veronie.bgg.ui/META-INF/MANIFEST.MF @@ -13,10 +13,10 @@ Require-Bundle: javax.inject, org.eclipse.e4.ui.workbench, org.eclipse.e4.ui.di, org.eclipse.jface, - org.eclipse.e4.ui.model.workbench, - com.ibm.icu + org.eclipse.e4.ui.model.workbench Bundle-RequiredExecutionEnvironment: JavaSE-11 -Import-Package: javax.annotation;version="1.0.0";resolution:=optional, +Import-Package: com.ibm.icu, + javax.annotation;version="1.0.0";resolution:=optional, javax.inject;version="1.0.0", org.eclipse.e4.core.commands, org.eclipse.e4.core.contexts, diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java index 9acdc5a..8b51103 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingProvider.java @@ -125,7 +125,7 @@ public class ThingProvider { return localDbAdapterService.loadThingListNames(); } - public void fetchDetails() { + public void fetchDetails() throws RuntimeException { // prepare list of ids to retrieve Set ids = new HashSet<>(); for (Thing thing : things) { @@ -133,15 +133,36 @@ public class ThingProvider { ids.add(thing.getId()); } } + - System.out.println(Thing.makeResultHeader()); - ArrayList thingsWithDetails = bggApi.getThingDetails(ids); - for (Thing thing : thingsWithDetails) { - System.out.println(thing.toResultTxtLine()); + // nothing to fetch + if(!ids.isEmpty()) { + ArrayList thingsWithDetails = bggApi.getThingDetails(ids); + + if(thingsWithDetails.size() != things.size()) { + throw new RuntimeException("Some details could not be retrieved from BGG."); + } + + // Now join the details from thing query with the things that already + // contain user data, then output complete things. + for (Thing thingUser : things) { + for (Thing thingWD : thingsWithDetails) { + if(thingWD.getId() == thingUser.getId()) { + thingUser.setDetails(thingWD.getDetails()); + continue; + } + } + } } - - // TODO: - // Now join the details with the things that already contain user data, and output THOSE. + } + + public String toResultString() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(Thing.makeResultHeader()); + for (Thing thing : things) { + stringBuilder.append(thing.toResultTxtLine()); + } + return stringBuilder.toString(); } } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/internal/OutputResultHelper.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/internal/OutputResultHelper.java index f3ed241..2b55768 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/internal/OutputResultHelper.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/internal/OutputResultHelper.java @@ -7,7 +7,7 @@ import xyz.veronie.bgg.result.IdString; public class OutputResultHelper { public static String floatToResult(Float f) { - if(f == null) { + if(f == null || f == 0.0) { return "N/A"; } else { return Float.toString(f.floatValue()); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ExportResultHandler.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ExportResultHandler.java index 2c6e0fe..636b737 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ExportResultHandler.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/handlers/ExportResultHandler.java @@ -2,11 +2,19 @@ package xyz.veronie.bgg.ui.handlers; import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; import xyz.veronie.bgg.result.BggApi; import xyz.veronie.bgg.result.Thing; import xyz.veronie.bgg.result.ThingProvider; +import xyz.veronie.bgg.ui.helpers.Resources; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -18,21 +26,30 @@ import org.eclipse.e4.core.di.annotations.CanExecute; public class ExportResultHandler { + private static final String RESULT_TXT = "result.txt"; + @Inject ThingProvider thingProvider; - @Inject - private BggApi bggApi; - @Execute - public void execute() { + public void execute(Shell shell, BggApi bggApi) { thingProvider.fetchDetails(); + + String exportString = thingProvider.toResultString(); + String resultFilePath = Resources.INSTANCE.getTmpDir() + File.separator + RESULT_TXT; + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(resultFilePath)); + writer.write(exportString); + writer.close(); + } + catch (IOException e) { + MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); + msgBox.setMessage("Could not write tmp file '" + resultFilePath + "'."); + msgBox.open(); + e.printStackTrace(); + } } - - - - @CanExecute public boolean canExecute() { return thingProvider != null;