PDF_Generation_and_Automation/force-app/main/default/classes/NoParamPdfController.cls
2025-08-24 12:01:08 +05:30

148 lines
6.1 KiB
OpenEdge ABL

public with sharing class NoParamPdfController {
@AuraEnabled
public static Map<String, Object> generatePreview() {
try {
System.debug('=== NO PARAM PREVIEW ===');
// Make HTTP callout to Python API with hardcoded data
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://160.187.166.67:8000/api/preview');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
// Hardcoded request body - no parameters needed
String requestBody = '{' +
'"template": "professional-1pager",' +
'"layout": "1-page",' +
'"propertyData": {' +
'"propertyName": "Sample Property",' +
'"propertyType": "AP",' +
'"location": "Dubai",' +
'"price": "AED 2,500,000",' +
'"bedrooms": "2",' +
'"bathrooms": "2",' +
'"area": "1,200 sq ft",' +
'"description": "Modern property with contemporary amenities"' +
'},' +
'"customizationOptions": {' +
'"headerStyle": "modern",' +
'"colorScheme": "professional",' +
'"fontStyle": "clean"' +
'},' +
'"generatePreview": true' +
'}';
request.setBody(requestBody);
request.setTimeout(120000); // 2 minutes
System.debug('Request body: ' + requestBody);
HttpResponse response = http.send(request);
System.debug('Response Status: ' + response.getStatusCode());
System.debug('Response Body: ' + response.getBody());
Map<String, Object> result = new Map<String, Object>();
if (response.getStatusCode() == 200) {
try {
Map<String, Object> responseData = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
result.put('success', true);
result.put('data', responseData);
} catch (Exception e) {
result.put('success', true);
result.put('data', response.getBody());
}
} else {
result.put('success', false);
result.put('error', 'HTTP ' + response.getStatusCode() + ': ' + response.getBody());
}
return result;
} catch (Exception e) {
System.debug('Error in NoParamPdfController: ' + e.getMessage());
System.debug('Stack trace: ' + e.getStackTraceString());
Map<String, Object> errorResult = new Map<String, Object>();
errorResult.put('success', false);
errorResult.put('error', 'Exception: ' + e.getMessage());
return errorResult;
}
}
@AuraEnabled
public static Map<String, Object> generatePdf() {
try {
System.debug('=== NO PARAM PDF ===');
// Make HTTP callout to Python API with hardcoded data
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://160.187.166.67:8000/api/generate-pdf');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
// Hardcoded request body - no parameters needed
String requestBody = '{' +
'"template": "professional-1pager",' +
'"layout": "1-page",' +
'"propertyData": {' +
'"propertyName": "Sample Property",' +
'"propertyType": "AP",' +
'"location": "Dubai",' +
'"price": "AED 2,500,000",' +
'"bedrooms": "2",' +
'"bathrooms": "2",' +
'"area": "1,200 sq ft",' +
'"description": "Modern property with contemporary amenities"' +
'},' +
'"customizationOptions": {' +
'"headerStyle": "modern",' +
'"colorScheme": "professional",' +
'"fontStyle": "clean"' +
'},' +
'"generatePDF": true' +
'}';
request.setBody(requestBody);
request.setTimeout(120000); // 2 minutes
System.debug('Request body: ' + requestBody);
HttpResponse response = http.send(request);
System.debug('Response Status: ' + response.getStatusCode());
System.debug('Response Body: ' + response.getBody());
Map<String, Object> result = new Map<String, Object>();
if (response.getStatusCode() == 200) {
try {
Map<String, Object> responseData = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
result.put('success', true);
result.put('data', responseData);
} catch (Exception e) {
result.put('success', true);
result.put('data', response.getBody());
}
} else {
result.put('success', false);
result.put('error', 'HTTP ' + response.getStatusCode() + ': ' + response.getBody());
}
return result;
} catch (Exception e) {
System.debug('Error in NoParamPdfController: ' + e.getMessage());
System.debug('Stack trace: ' + e.getStackTraceString());
Map<String, Object> errorResult = new Map<String, Object>();
errorResult.put('success', false);
errorResult.put('error', 'Exception: ' + e.getMessage());
return errorResult;
}
}
}