Skip to content

Commit

Permalink
send correct log type; check log posting response
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichFroebel committed May 18, 2020
1 parent d51961f commit e1263a2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ To create a JAR file, run `gradle jar` (or `./gradlew jar`). The JAR file will b

There is experimental support for bundling the application in a way that no local Java installation is needed for executing it.

To create the corresponding image, run `gradle jpackageImage` (or `./gradlew jpackageImage`). The image will be available inside the `build/jpackage/cmanager` directory. You might want to put this directory into a dedicated archive file for redistribution. **Please note that this an incubating feature of Java 14, so at least Java 14 is required and might break due to API changes.**
To create the corresponding image, run `gradle jpackageImage` (or `./gradlew jpackageImage`). The image will be available inside the `build/jpackage/cmanager` directory. You might want to put this directory into a dedicated archive file for redistribution using the `jpackageImageZip` task. **Please note that this an incubating feature of Java 14, so at least Java 14 is required and this feature might break due to API changes.**

## Usage

Expand All @@ -54,8 +54,8 @@ Run `gradle run` (or `./gradlew run`) from the root directory of the Git reposit

### Starting the application JAR file

Run `java -jar cm-0.2.47.jar` from the directory containing the JAR file.
Run `java -jar cm-0.2.48.jar` from the directory containing the JAR file.

### Starting the Java-independent package

Double-click on `cmanager.exe` from the directory containing this package. *Please note that this version is not being distributed in the release section at the moment.*
Double-click on `cmanager.exe` (on Windows) from the directory containing this package. *Please note that this version is not being distributed in the release section at the moment.*
20 changes: 19 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ project.ext.ocOkapiPropertiesFile = projectDir.getPath() + "${File.separator}oc_
sourceCompatibility = 1.8
targetCompatibility = 1.8

version = '0.2.47'
version = '0.2.48'

wrapper {
gradleVersion = '6.4'
Expand Down Expand Up @@ -155,3 +155,21 @@ runtime {
skipInstaller = true
}
}

// Retrieve the system string for indicating the package content.
def getSystemString() {
def osName = System.properties['os.name'].toLowerCase()
if (osName.contains('windows')) return 'windows';
return osName;
}

// Provide a dedicated task to create a ZIP file of the `jpackage` image.
task jpackageImageZip(type: Zip) {
group = 'Build'
description = 'Bundles the jpackage image as a ZIP file.'
from "${buildDir}/jpackage/cmanager"
include '**/*'
archiveName "cmanager-${version}_${getSystemString()}.zip"
destinationDir file("${buildDir}/jpackage/")
}
jpackageImageZip.dependsOn jpackageImage
13 changes: 10 additions & 3 deletions src/main/java/cmanager/gui/CopyLogDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cmanager.oc.ShadowList;
import cmanager.okapi.OKAPI;
import cmanager.okapi.User;
import cmanager.okapi.responses.UnexpectedLogStatus;
import cmanager.settings.Settings;
import java.awt.BorderLayout;
import java.awt.Color;
Expand Down Expand Up @@ -123,10 +124,16 @@ public void run() {

// copy the log
OKAPI.postLog(User.getOKAPIUser(), oc, log);
// remember that we copied the log so the
// user can not
// double post it by accident
// remember that we copied the log so the user can
// not double post it by accident
logsCopied.add(log);
} catch (UnexpectedLogStatus exception) {
// Handle general log problems separately to provide
// a better error message.
ExceptionPanel.showErrorDialog(
THIS,
exception.getResponseMessage(),
"Unexpected log status");
} catch (Throwable t) {
ExceptionPanel.showErrorDialog(THIS, t);
}
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/cmanager/okapi/OKAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import cmanager.okapi.responses.CachesAroundDocument;
import cmanager.okapi.responses.ErrorDocument;
import cmanager.okapi.responses.FoundStatusDocument;
import cmanager.okapi.responses.LogSubmissionDocument;
import cmanager.okapi.responses.UUIDDocument;
import cmanager.okapi.responses.UnexpectedLogStatus;
import cmanager.okapi.responses.UsernameDocument;
import cmanager.xml.Element;
import cmanager.xml.Parser;
Expand Down Expand Up @@ -353,15 +355,16 @@ public static String getUsername(TokenProviderI tp)
}

public static void postLog(TokenProviderI tp, Geocache cache, GeocacheLog log)
throws MalFormedException, InterruptedException, ExecutionException, IOException {
throws MalFormedException, InterruptedException, ExecutionException, IOException,
UnexpectedLogStatus {
String url =
BASE_URL
+ "/logs/submit"
+ "?format=json"
+ "&cache_code="
+ URLEncoder.encode(cache.getCode(), "UTF-8")
+ "&logtype="
+ URLEncoder.encode("Found it", "UTF-8")
+ URLEncoder.encode(log.getTypeStr(), "UTF-8")
+ "&comment="
+ URLEncoder.encode(log.getText(), "UTF-8")
+ "&when="
Expand All @@ -375,11 +378,15 @@ public static void postLog(TokenProviderI tp, Geocache cache, GeocacheLog log)

final String response = authedHttpGet(tp, url);

/*final LogSubmissionDocument document = new Gson().fromJson(response, LogSubmissionDocument.class);
if (document == null) return;
final LogSubmissionDocument document =
new Gson().fromJson(response, LogSubmissionDocument.class);
if (document == null) {
System.out.println("Problems with handling posted log. Response document is null.");
return;
}
if (!document.isSuccess()) {
System.out.println("Error while logging cache: " + document.getMessage());
}*/
throw new UnexpectedLogStatus(document.getMessage());
}
}

public static Coordinate getHomeCoordinates(TokenProviderI tp)
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/cmanager/okapi/responses/UnexpectedLogStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmanager.okapi.responses;

public class UnexpectedLogStatus extends Exception {

private static final long serialVersionUID = -1132973286480626832L;

private String responseMessage;

public UnexpectedLogStatus(String responseMessage) {
super("Unexpected log status");
this.responseMessage = responseMessage;
}

public String getResponseMessage() {
return responseMessage;
}
}

0 comments on commit e1263a2

Please sign in to comment.