Skip to content

Commit 2d26653

Browse files
author
JW Wesson
committed
add models for formatter with template
1 parent 61b194b commit 2d26653

File tree

6 files changed

+128
-0
lines changed

6 files changed

+128
-0
lines changed

src/main/java/com/textkernel/tx/ApiEndpoints.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,6 @@ private String sanitize(String indexOrDocId) throws IllegalArgumentException {
9898

9999
String jobDescriptionGenerate() { return prefix(false) + "/job-description/generate"; }
100100
String jobDescriptionSuggestSkills() { return prefix(false) + "/job-description/suggest-skills"; }
101+
102+
String formatResume() { return prefix() + "/formatter/resume/template"; }
101103
}

src/main/java/com/textkernel/tx/TxClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.textkernel.tx.models.api.dataenrichment.skills.response.GetSkillsTaxonomyResponse;
4545
import com.textkernel.tx.models.api.dataenrichment.skills.response.LookupSkillCodesResponse;
4646
import com.textkernel.tx.models.api.dataenrichment.skills.response.NormalizeSkillsResponse;
47+
import com.textkernel.tx.models.api.formatter.FormatResumeRequest;
4748
import com.textkernel.tx.models.api.geocoding.*;
4849
import com.textkernel.tx.models.api.indexes.*;
4950
import com.textkernel.tx.models.api.jobdescription.GenerateJobRequest;
@@ -287,6 +288,17 @@ public GetAccountInfoResponse getAccountInfo() throws TxException {
287288
HttpResponse<GetAccountInfoResponse> response = executeRequest(apiRequest, GetAccountInfoResponse.class, getBodyIfDebug(apiRequest));
288289
return response.getData();
289290
}
291+
292+
public FormatResumeResponse formatResume(FormatResumeRequest request) throws TxException {
293+
RequestBody body = createJsonBody(request);
294+
Request apiRequest = new Request.Builder()
295+
.url(_endpoints.formatResume())
296+
.post(body)
297+
.build();
298+
299+
HttpResponse<FormatResumeResponse> response = executeRequest(apiRequest, FormatResumeResponse.class, getBodyIfDebug(apiRequest));
300+
return response.getData();
301+
}
290302

291303
/**
292304
* Parse a resume
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright © 2023 Textkernel BV. All rights reserved.
2+
// This file is provided for use by, or on behalf of, Textkernel licensees
3+
// within the terms of their license of Textkernel products or Textkernel customers
4+
// within the Terms of Service pertaining to the Textkernel SaaS products.
5+
6+
package com.textkernel.tx.models.api.formatter;
7+
8+
import java.io.IOException;
9+
import java.time.LocalDate;
10+
11+
import com.textkernel.tx.models.Document;
12+
import com.textkernel.tx.models.resume.ParsedResume;
13+
14+
/**
15+
* Request body for the Format Resume With Template endpoint
16+
*/
17+
public class FormatResumeRequest {
18+
/** The resume to use to populate the template */
19+
public ParsedResume ResumeData;
20+
21+
/**
22+
* A base64-encoded string of the DOCX template document file bytes. This should use the standard 'base64'
23+
* encoding as defined in RFC 4648 Section 4 (not the 'base64url' variant).
24+
* <p>Java users can use {@link java.util.Base64#getEncoder()} and then {@link java.util.Base64.Encoder#encodeToString(byte[])}
25+
* <p>For more information on creating custom templates, see
26+
* <a href="https://developer.textkernel.com/tx-platform/v10/resume-formatter/creating-custom-templates/">here</a>
27+
*/
28+
public String Template;
29+
30+
/** The output document type */
31+
public OutputDocumentFormat OutputType;
32+
33+
/**
34+
* Any data that the template needs that is not in the extracted CV data. For example:
35+
* <pre>
36+
*JSONObject myCustomData = new JSONObject();
37+
*myCustomData.put("CandidateId", "12345");
38+
*myCustomData.put("DateApplied", LocalDate.now());
39+
*formatRequest.CustomData = myCustomData;
40+
*</pre>
41+
*/
42+
public Object CustomData;
43+
44+
/**
45+
* Creates a request to use when calling the Resume Formatter endpoint with a provided template document.
46+
* @param resume The resume to use to populate the template
47+
* @param templatePath The path to the template DOCX file on disk
48+
* @param docType The output document type
49+
* @throws IOException if an error occurs reading the file contents
50+
*/
51+
public FormatResumeRequest(ParsedResume resume, String templatePath, OutputDocumentFormat docType) throws IOException {
52+
ResumeData = resume;
53+
OutputType = docType;
54+
Template = new Document(templatePath).getAsBase64();
55+
}
56+
57+
/**
58+
* Creates a request to use when calling the Resume Formatter endpoint with a provided template document.
59+
* @param resume The resume to use to populate the template
60+
* @param templateFileBytes The bytes of the template DOCX file
61+
* @param docType The output document type
62+
*/
63+
public FormatResumeRequest(ParsedResume resume, byte[] templateFileBytes, OutputDocumentFormat docType) {
64+
ResumeData = resume;
65+
OutputType = docType;
66+
Template = new Document(templateFileBytes, LocalDate.now()).getAsBase64();
67+
}
68+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright © 2023 Textkernel BV. All rights reserved.
2+
// This file is provided for use by, or on behalf of, Textkernel licensees
3+
// within the terms of their license of Textkernel products or Textkernel customers
4+
// within the Terms of Service pertaining to the Textkernel SaaS products.
5+
6+
package com.textkernel.tx.models.api.formatter;
7+
8+
import com.textkernel.tx.models.api.ApiResponse;
9+
10+
/** The response body for a Format Resume API call */
11+
public class FormatResumeResponse extends ApiResponse<FormatResumeResponseValue> {
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright © 2023 Textkernel BV. All rights reserved.
2+
// This file is provided for use by, or on behalf of, Textkernel licensees
3+
// within the terms of their license of Textkernel products or Textkernel customers
4+
// within the Terms of Service pertaining to the Textkernel SaaS products.
5+
6+
package com.textkernel.tx.models.api.formatter;
7+
8+
import com.textkernel.tx.models.api.ApiResponse;
9+
10+
/**
11+
* The {@link ApiResponse#Value} from a Format Resume response
12+
*/
13+
public class FormatResumeResponseValue {
14+
/**
15+
* The formatted resume document (either PDF or DOCX).
16+
* This is a byte[] as a Base64-encoded string. You can use
17+
* {@link java.util.Base64.Decoder#decode(String)} to get a byte[] to save to disk.
18+
*/
19+
public String DocumentAsBase64String;
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright © 2023 Textkernel BV. All rights reserved.
2+
// This file is provided for use by, or on behalf of, Textkernel licensees
3+
// within the terms of their license of Textkernel products or Textkernel customers
4+
// within the Terms of Service pertaining to the Textkernel SaaS products.
5+
6+
package com.textkernel.tx.models.api.formatter;
7+
8+
/** The document type to be output by the formatter endpoint */
9+
public enum OutputDocumentFormat {
10+
/** A Microsoft Word document */
11+
DOCX,
12+
/** A PDF document */
13+
PDF
14+
}

0 commit comments

Comments
 (0)