Skip to content

Commit dfbf64e

Browse files
committed
[ESMO] change creation user to execution user in pdf export
1 parent ab42c87 commit dfbf64e

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

knowage-export/src/main/java/it/eng/knowage/engine/api/export/dashboard/pdf/DashboardPdfExporter.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import it.eng.knowage.engine.api.export.dashboard.DashboardExporter;
55
import it.eng.knowage.engine.api.export.dashboard.Style;
66
import it.eng.spagobi.commons.SingletonConfig;
7+
import it.eng.spagobi.user.UserProfileManager;
78
import it.eng.spagobi.utilities.assertion.Assert;
89
import it.eng.spagobi.utilities.exceptions.SpagoBIRuntimeException;
910
import org.apache.log4j.Logger;
@@ -55,7 +56,7 @@ public DashboardPdfExporter(String userUniqueIdentifier, Locale locale) {
5556

5657
public byte[] getBinaryData(JSONObject template) throws JSONException {
5758

58-
String creationUser;
59+
String executionUser;
5960

6061
if (template == null) {
6162
throw new SpagoBIRuntimeException("Unable to get template for dashboard");
@@ -65,12 +66,12 @@ public byte[] getBinaryData(JSONObject template) throws JSONException {
6566

6667
JSONObject drivers = transformDriversForDatastore(getDrivers(template));
6768
JSONObject parameters = transformParametersForDatastore(template, getParametersFromBody(template));
68-
creationUser = template.getString("creationUser");
69+
executionUser = UserProfileManager.getProfile().getSpagoBIUserProfile().getUserId();
6970

7071
try (PDDocument document = new PDDocument(MemoryUsageSetting.setupTempFileOnly())) {
7172
String widgetId = template.getString("id");
7273

73-
exportTableWidget(document, template, widgetId, creationUser, selections, drivers, parameters);
74+
exportTableWidget(document, template, widgetId, executionUser, selections, drivers, parameters);
7475

7576
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
7677
document.save(byteArrayOutputStream);
@@ -82,7 +83,7 @@ public byte[] getBinaryData(JSONObject template) throws JSONException {
8283
}
8384
}
8485

85-
private void exportTableWidget(PDDocument document, JSONObject widget, String widgetId, String creationUser, Map<String, Map<String, JSONArray>> selections, JSONObject drivers, JSONObject parameters) {
86+
private void exportTableWidget(PDDocument document, JSONObject widget, String widgetId, String executionUser, Map<String, Map<String, JSONArray>> selections, JSONObject drivers, JSONObject parameters) {
8687
try {
8788
JSONObject settings = widget.optJSONObject("settings");
8889

@@ -152,7 +153,7 @@ private void exportTableWidget(PDDocument document, JSONObject widget, String wi
152153
}
153154
}
154155
}
155-
buildFirstPageHeaders(table, settings, groupsAndColumnsMap, columnsOrdered, creationUser, font, extraValueLabel, extraValue);
156+
buildFirstPageHeaders(table, settings, groupsAndColumnsMap, columnsOrdered, executionUser, font, extraValueLabel, extraValue);
156157
}
157158

158159
rows = dataStore.getJSONArray("rows");
@@ -209,8 +210,8 @@ private void initColumnWidths(JSONArray columnsOrdered, Map<String, JSONArray> c
209210
}
210211
}
211212

212-
private void buildFirstPageHeaders(BaseTable table, JSONObject settings, Map<String, String> groupsAndColumnsMap, JSONArray columnsOrdered, String creationUser, PDFont font, String extraValueLabel, String extraValueField) throws JSONException {
213-
createDocumentInformationRow(table, font, creationUser, extraValueLabel, extraValueField);
213+
private void buildFirstPageHeaders(BaseTable table, JSONObject settings, Map<String, String> groupsAndColumnsMap, JSONArray columnsOrdered, String executionUser, PDFont font, String extraValueLabel, String extraValueField) throws JSONException {
214+
createDocumentInformationRow(table, font, executionUser, extraValueLabel, extraValueField);
214215

215216
if (!groupsAndColumnsMap.isEmpty()) {
216217
Row<PDPage> groupHeaderRow = table.createRow(15f);
@@ -273,29 +274,29 @@ private void styleHeaderCell(JSONObject settings, Cell<PDPage> headerCell, PDFon
273274
}
274275
}
275276

276-
private void createDocumentInformationRow(BaseTable table, PDFont font, String creationUser, String extraValueLabel, String extraValue) {
277+
private void createDocumentInformationRow(BaseTable table, PDFont font, String executionUser, String extraValueLabel, String extraValue) {
277278
try {
278279

279280
String executionDateLabel;
280-
String creationUserLabel;
281+
String executionUserLabel;
281282

282283
if (this.locale.toString().equals("sk_SK")) {
283284
executionDateLabel = "Dátum vytvorenia: ";
284-
creationUserLabel = "Vytvoril: ";
285+
executionUserLabel = "Vytvoril: ";
285286
} else if (this.locale.toString().equals("it_IT")) {
286287
executionDateLabel = "Data di esecuzione: ";
287-
creationUserLabel = "Utente di creazione: ";
288+
executionUserLabel = "Utente di esecuzione: ";
288289
} else {
289290
executionDateLabel = "Execution Date: ";
290-
creationUserLabel = "Creation User: ";
291+
executionUserLabel = "Execution User: ";
291292
}
292293

293294
PDPage page = table.getCurrentPage();
294295

295296
String executionDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"));
296297

297298
String line1 = executionDateLabel + executionDate;
298-
String line2 = creationUserLabel + creationUser;
299+
String line2 = executionUserLabel + executionUser;
299300
String line3 = null;
300301
boolean isExtraValuePresent = extraValueLabel != null && !extraValueLabel.isEmpty() && extraValue != null && !extraValue.isEmpty();
301302
if (isExtraValuePresent) {

knowagecockpitengine/src/main/java/it/eng/knowage/engine/cockpit/api/export/CockpitExportResource.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import it.eng.knowage.engine.api.export.oldcockpit.ExcelExporter;
44
import it.eng.knowage.engine.cockpit.api.AbstractCockpitEngineResource;
55
import it.eng.knowage.engine.cockpit.api.export.pdf.PdfExporter;
6+
import it.eng.spagobi.commons.bo.UserProfile;
67
import it.eng.spagobi.utilities.engines.SpagoBIEngineServiceExceptionHandler;
78
import it.eng.spagobi.utilities.exceptions.SpagoBIRuntimeException;
89
import it.eng.spagobi.utilities.mime.MimeUtils;
@@ -115,7 +116,9 @@ public void exportPdf(@Context HttpServletRequest req) {
115116
body.put("template", template);
116117
JSONObject selections = body.optJSONObject("COCKPIT_SELECTIONS").optJSONObject("userSelections");
117118
JSONObject variables = body.optJSONObject("COCKPIT_VARIABLES");
118-
byte[] data = pdfExporter.getBinaryData(documentId, documentLabel, template, selections, variables);
119+
UserProfile profile = getUserProfile();
120+
String executionUser = profile.getSpagoBIUserProfile().getUserId();
121+
byte[] data = pdfExporter.getBinaryData(documentId, executionUser, documentLabel, template, selections, variables);
119122

120123
response.setContentType(MediaType.APPLICATION_OCTET_STREAM);
121124
response.setHeader("Content-length", Integer.toString(data.length));

knowagecockpitengine/src/main/java/it/eng/knowage/engine/cockpit/api/export/pdf/PdfExporter.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ public PdfExporter(String userUniqueIdentifier, JSONObject body) {
7171
super(userUniqueIdentifier, body);
7272
}
7373

74-
public byte[] getBinaryData(Integer documentId, String documentLabel, String templateString, JSONObject selections, JSONObject variables) throws JSONException {
74+
public byte[] getBinaryData(Integer documentId, String executionUser, String documentLabel, String templateString, JSONObject selections, JSONObject variables) throws JSONException {
7575

7676
ObjTemplate template = null;
7777
String message = "Unable to get template for document with id [" + documentId + "] and label ["
7878
+ documentLabel + "]";
79-
String creationUser;
8079
try {
8180
if (documentId != null && documentId != 0)
8281
template = DAOFactory.getObjTemplateDAO().getBIObjectActiveTemplate(documentId);
@@ -89,15 +88,14 @@ else if (documentLabel != null && !documentLabel.isEmpty())
8988
if (templateString == null) {
9089
templateString = new String(template.getContent());
9190
}
92-
creationUser = template.getCreationUser();
9391
} catch (EMFAbstractError e) {
9492
throw new SpagoBIRuntimeException(message, e);
9593
}
9694

9795
try (PDDocument document = new PDDocument(MemoryUsageSetting.setupTempFileOnly())) {
9896
long widgetId = body.getLong("widget");
9997

100-
exportTableWidget(document, templateString, widgetId, creationUser, selections, variables);
98+
exportTableWidget(document, templateString, widgetId, executionUser, selections, variables);
10199

102100
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
103101
document.save(byteArrayOutputStream);
@@ -748,9 +746,9 @@ private void createDocumentInformationRow(BaseTable table, PDFont font, String c
748746
creationUserLabel = "Vytvoril: ";
749747
} else if (getLocale().toString().equals("it_IT")) {
750748
executionDateLabel = "Data di esecuzione: ";
751-
creationUserLabel = "Utente di creazione: ";
749+
creationUserLabel = "Utente di esecuzione: ";
752750
} else {
753-
executionDateLabel = "Execution Date: ";
751+
executionDateLabel = "Execution User: ";
754752
creationUserLabel = "Creation User: ";
755753
}
756754

0 commit comments

Comments
 (0)