Skip to content

Commit 554c621

Browse files
authored
Merge pull request #62 from Jalen-Stephens/jalen/pom-bug-fix
fixed pmd and checkstyle errors
2 parents 40b63f8 + 34a69f4 commit 554c621

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/main/java/dev/coms4156/project/metadetect/c2pa/C2paToolInvoker.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,35 @@ public C2paToolInvoker(String c2paToolPath) {
5252

5353

5454

55-
/**
55+
/**
5656
* Backwards-compatible wrapper used by existing code/tests.
57-
*
5857
* Historically, the service used a plain JSON string "manifest" coming
5958
* from c2patool. We now normalize that into {@link C2paMetadata}, but
6059
* expose this helper for callers that still expect a String.
61-
*
6260
* Contract:
6361
* - Never throws.
6462
* - Returns a JSON serialization of {@link C2paMetadata}.
6563
*/
66-
@Deprecated
67-
public String extractManifest(File imageFile) {
68-
C2paMetadata metadata = extractMetadata(imageFile);
64+
@Deprecated
65+
public String extractManifest(File imageFile) {
66+
C2paMetadata metadata = extractMetadata(imageFile);
67+
try {
68+
ObjectMapper mapper = new ObjectMapper();
69+
return mapper.writeValueAsString(metadata);
70+
} catch (Exception e) {
71+
String msg = "Failed to serialize C2PA metadata to JSON: " + e;
72+
log.warn(msg, e);
73+
C2paMetadata error = C2paMetadata.error(msg);
6974
try {
7075
ObjectMapper mapper = new ObjectMapper();
71-
return mapper.writeValueAsString(metadata);
72-
} catch (Exception e) {
73-
String msg = "Failed to serialize C2PA metadata to JSON: " + e;
74-
log.warn(msg, e);
75-
C2paMetadata error = C2paMetadata.error(msg);
76-
try {
77-
ObjectMapper mapper = new ObjectMapper();
78-
return mapper.writeValueAsString(error);
79-
} catch (Exception inner) {
80-
log.warn("Secondary failure serializing error C2PA metadata: {}", inner.toString());
81-
// Last-resort JSON so callers never get null
82-
return "{\"c2paErrorFlag\":1,\"c2paErrorMessage\":\"serialization failure\"}";
83-
}
76+
return mapper.writeValueAsString(error);
77+
} catch (Exception inner) {
78+
log.warn("Secondary failure serializing error C2PA metadata: {}", inner.toString());
79+
// Last-resort JSON so callers never get null
80+
return "{\"c2paErrorFlag\":1,\"c2paErrorMessage\":\"serialization failure\"}";
8481
}
8582
}
83+
}
8684

8785
/**
8886
* Executes the C2PA tool and converts its output into ML-ready metadata.
@@ -192,7 +190,7 @@ private C2paMetadata parseMetadataFromJson(String json) {
192190
// Resolve active manifest (preferred) or fall back to first manifest.
193191
JsonNode activeManifestField = root.get("active_manifest");
194192
String activeManifestId =
195-
(activeManifestField != null && !activeManifestField.isNull())
193+
activeManifestField != null && !activeManifestField.isNull()
196194
? activeManifestField.asText(null)
197195
: null;
198196

src/main/java/dev/coms4156/project/metadetect/service/AnalyzeService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ public Dtos.AnalyzeCompareResponse compare(UUID leftImageId, UUID rightImageId)
193193
/**
194194
* Downloads the asset, runs C2PA, and finalizes the report.
195195
* Converts any thrown errors into a FAILED report with error JSON.
196-
*
197196
* For C2PA specifically, hard failures are converted to a C2paMetadata
198197
* object with c2pa_errorFlag = 1, so the analysis flow is not broken.
199198
*/
@@ -214,7 +213,7 @@ private void runExtractionAndFinalize(UUID analysisId, String storagePath) {
214213
// The details field now stores the C2PA metadata schema, not raw manifest JSON.
215214
markCompleted(analysisId, json, /*confidence*/ null);
216215

217-
} catch (java.io.IOException ioe) {
216+
} catch (IOException ioe) {
218217
// IO-level failures (download, JSON serialization) are genuine failures.
219218
handleGenericFailure(analysisId, storagePath, ioe);
220219

@@ -350,7 +349,7 @@ private void handleGenericFailure(UUID analysisId, String storagePath, Exception
350349
var errorObj = new java.util.LinkedHashMap<String, Object>();
351350
errorObj.put("error", errMsg);
352351
// optionally include more context:
353-
// errorObj.put("storagePath", storagePath);
352+
errorObj.put("storagePath", storagePath);
354353
String errorJson = objectMapper.writeValueAsString(errorObj);
355354
markFailed(analysisId, errorJson);
356355
} catch (Exception jsonEx) {

0 commit comments

Comments
 (0)