Skip to content

Commit f474362

Browse files
committed
first draft
1 parent e0d09c3 commit f474362

24 files changed

Lines changed: 298 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
report.errors.querytype=Unknown query type: {0}
12
validatereport.successful=The query was executed successfully and returned {0} results.
23
validatereport.errors.query=The query encountered errors: {0}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
report.errors.querytype=Unbekannter Abfrage Typ: {0}
12
validatereport.successful=Die Abfrage wurde erfolgreich ausgeführt und lieferte {0} Ergebnisse.
23
validatereport.errors.query=Die Abfrage hat Fehler: {0}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
report.errors.querytype=Unknown query type: {0}
12
validatereport.successful=The query was executed successfully and returned {0} results.
23
validatereport.errors.query=The query encountered errors: {0}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package tools.sapcx.commerce.reporting.backoffice.action;
2+
3+
import com.hybris.cockpitng.actions.ActionContext;
4+
import com.hybris.cockpitng.actions.ActionResult;
5+
import com.hybris.cockpitng.actions.CockpitAction;
6+
import jakarta.annotation.Resource;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
import org.zkoss.zhtml.Messagebox;
10+
import tools.sapcx.commerce.reporting.enums.SearchQueryType;
11+
import tools.sapcx.commerce.reporting.model.QueryReportConfigurationModel;
12+
import tools.sapcx.commerce.reporting.report.ReportService;
13+
import tools.sapcx.commerce.reporting.search.GenericSearchResult;
14+
import tools.sapcx.commerce.reporting.search.GenericSearchService;
15+
16+
import java.text.MessageFormat;
17+
import java.util.Map;
18+
19+
public abstract class AbstractReportAction implements CockpitAction<QueryReportConfigurationModel, Object> {
20+
private static final Logger LOG = LoggerFactory.getLogger(AbstractReportAction.class);
21+
private static final String WRONG_QUERYTYPE = "report.errors.querytype";
22+
23+
@Resource(name = "cxGenericSearchServicesMap")
24+
protected Map<SearchQueryType, GenericSearchService> genericSearchServices;
25+
26+
@Resource(name = "cxReportService")
27+
protected ReportService dataReportService;
28+
29+
@Override
30+
public boolean needsConfirmation(ActionContext<QueryReportConfigurationModel> ctx) {
31+
return false;
32+
}
33+
34+
@Override
35+
public ActionResult<Object> perform(ActionContext<QueryReportConfigurationModel> actionContext) {
36+
final QueryReportConfigurationModel report = actionContext.getData();
37+
if (!genericSearchServices.containsKey(report.getSearchQueryType())) {
38+
return error(MessageFormat.format(actionContext.getLabel(WRONG_QUERYTYPE), report.getSearchQueryType()));
39+
}
40+
41+
final GenericSearchService genericSearchService = genericSearchServices.get(report.getSearchQueryType());
42+
final String query = report.getSearchQuery();
43+
final Map<String, Object> params = dataReportService.getReportParameters(report);
44+
final Map<String, Object> configuration = dataReportService.getReportConfiguration(report);
45+
46+
LOG.debug("Processing query {} with params {} and config {}", query, params, configuration);
47+
final GenericSearchResult searchResult = genericSearchService.search(query, params, configuration);
48+
return processSearchResult(actionContext, searchResult);
49+
}
50+
51+
protected abstract ActionResult<Object> processSearchResult(ActionContext<QueryReportConfigurationModel> actionContext, GenericSearchResult searchResult);
52+
53+
protected ActionResult<Object> error() {
54+
return error(null);
55+
}
56+
57+
protected ActionResult<Object> error(String msg) {
58+
if (msg != null) {
59+
Messagebox.show(msg, "Error", Messagebox.OK, Messagebox.ERROR);
60+
}
61+
final ActionResult<Object> result = new ActionResult<>(ActionResult.ERROR);
62+
result.setResultMessage(msg);
63+
return result;
64+
}
65+
66+
protected ActionResult<Object> success() {
67+
return success(null);
68+
}
69+
70+
protected ActionResult<Object> success(String msg) {
71+
if (msg != null) {
72+
Messagebox.show(msg);
73+
}
74+
return new ActionResult<>(ActionResult.SUCCESS);
75+
}
76+
}

core-customize/hybris/bin/custom/sapcxtools/sapcxreporting/backoffice/src/tools/sapcx/commerce/reporting/backoffice/action/ExecuteReportAction.java

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import com.hybris.cockpitng.actions.ActionContext;
1414
import com.hybris.cockpitng.actions.ActionResult;
15-
import com.hybris.cockpitng.actions.CockpitAction;
1615

1716
import de.hybris.platform.servicelayer.dto.converter.Converter;
1817

@@ -22,54 +21,42 @@
2221
import org.zkoss.zul.Filedownload;
2322
import org.zkoss.zul.Messagebox;
2423

24+
import tools.sapcx.commerce.reporting.enums.SearchQueryType;
2525
import tools.sapcx.commerce.reporting.model.QueryReportConfigurationModel;
2626
import tools.sapcx.commerce.reporting.report.ReportService;
2727
import tools.sapcx.commerce.reporting.report.data.QueryFileConfigurationData;
28-
import tools.sapcx.commerce.reporting.search.FlexibleSearchGenericSearchService;
2928
import tools.sapcx.commerce.reporting.search.GenericSearchResult;
3029

3130
import jakarta.annotation.Resource;
31+
import tools.sapcx.commerce.reporting.search.GenericSearchService;
3232

33-
public class ExecuteReportAction implements CockpitAction<QueryReportConfigurationModel, Object> {
33+
public class ExecuteReportAction extends AbstractReportAction {
3434
private static final Logger LOG = LoggerFactory.getLogger(ExecuteReportAction.class);
3535
private static final String CONFIRMATION = "executereport.confirmation";
3636
private static final String SEARCH_ERROR = "executereport.errors.search";
3737
private static final String REPORT_GENERATE_ERROR = "executereport.errors.generation";
3838
private static final String FILE_READ_ERROR = "executereport.errors.fileread";
3939

40-
@Resource(name = "cxGenericSearchService")
41-
private FlexibleSearchGenericSearchService flexibleSearchService;
42-
43-
@Resource(name = "cxReportService")
44-
private ReportService dataReportService;
45-
4640
@Resource(name = "queryConfigurationConverter")
4741
private Converter<QueryReportConfigurationModel, QueryFileConfigurationData> queryConfigurationConverter;
4842

4943
@Override
50-
public ActionResult<Object> perform(ActionContext<QueryReportConfigurationModel> actionContext) {
51-
QueryReportConfigurationModel report = actionContext.getData();
52-
53-
String query = report.getSearchQuery();
54-
Map<String, Object> params = dataReportService.getReportParameters(report);
55-
56-
LOG.debug("Executing query {} with params {}", query, params);
57-
GenericSearchResult searchResult = flexibleSearchService.search(query, params);
58-
44+
protected ActionResult<Object> processSearchResult(ActionContext<QueryReportConfigurationModel> actionContext, GenericSearchResult searchResult) {
45+
final QueryReportConfigurationModel report = actionContext.getData();
5946
if (searchResult.hasError()) {
6047
return error(MessageFormat.format(actionContext.getLabel(SEARCH_ERROR), searchResult.getError()));
6148
}
6249

63-
QueryFileConfigurationData queryFileConfigurationData = queryConfigurationConverter.convert(report);
64-
Optional<File> reportFile = dataReportService.getReportFile(queryFileConfigurationData, searchResult);
50+
final QueryFileConfigurationData queryFileConfigurationData = queryConfigurationConverter.convert(report);
51+
final Optional<File> reportFile = dataReportService.getReportFile(queryFileConfigurationData, searchResult);
6552
if (!reportFile.isPresent()) {
6653
return error(actionContext.getLabel(REPORT_GENERATE_ERROR));
6754
}
6855

69-
File media = reportFile.get();
56+
final File media = reportFile.get();
7057
try {
71-
String extension = FilenameUtils.getExtension(media.getAbsolutePath());
72-
String filename = defaultIfBlank(report.getTitle(), report.getId()) + "." + extension;
58+
final String extension = FilenameUtils.getExtension(media.getAbsolutePath());
59+
final String filename = defaultIfBlank(report.getTitle(), report.getId()) + "." + extension;
7360
Filedownload.save(new FileInputStream(media), Files.probeContentType(media.toPath()), filename);
7461
return success();
7562
} catch (IOException e) {
@@ -84,18 +71,6 @@ public ActionResult<Object> perform(ActionContext<QueryReportConfigurationModel>
8471
}
8572
}
8673

87-
private ActionResult<Object> success() {
88-
return new ActionResult<>(ActionResult.SUCCESS);
89-
}
90-
91-
private ActionResult<Object> error(String msg) {
92-
Messagebox.show(msg, "Error", Messagebox.OK, Messagebox.ERROR);
93-
94-
ActionResult<Object> result = new ActionResult<>(ActionResult.ERROR);
95-
result.setResultMessage(msg);
96-
return result;
97-
}
98-
9974
@Override
10075
public boolean needsConfirmation(ActionContext<QueryReportConfigurationModel> ctx) {
10176
return true;
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,27 @@
11
package tools.sapcx.commerce.reporting.backoffice.action;
22

33
import java.text.MessageFormat;
4-
import java.util.Map;
54

65
import com.hybris.cockpitng.actions.ActionContext;
76
import com.hybris.cockpitng.actions.ActionResult;
8-
import com.hybris.cockpitng.actions.CockpitAction;
97

108
import org.slf4j.Logger;
119
import org.slf4j.LoggerFactory;
12-
import org.zkoss.zhtml.Messagebox;
1310

1411
import tools.sapcx.commerce.reporting.model.QueryReportConfigurationModel;
15-
import tools.sapcx.commerce.reporting.report.ReportService;
16-
import tools.sapcx.commerce.reporting.search.FlexibleSearchGenericSearchService;
1712
import tools.sapcx.commerce.reporting.search.GenericSearchResult;
1813

19-
import jakarta.annotation.Resource;
20-
21-
public class ValidateReportAction implements CockpitAction<QueryReportConfigurationModel, Object> {
14+
public class ValidateReportAction extends AbstractReportAction {
2215
private static final Logger LOG = LoggerFactory.getLogger(ValidateReportAction.class);
2316
private static final String SEARCH_SUCCESS = "validatereport.successful";
2417
private static final String SEARCH_ERROR = "validatereport.errors.query";
2518

26-
@Resource(name = "cxGenericSearchService")
27-
private FlexibleSearchGenericSearchService flexibleSearchService;
28-
29-
@Resource(name = "cxReportService")
30-
private ReportService dataReportService;
31-
3219
@Override
33-
public ActionResult<Object> perform(ActionContext<QueryReportConfigurationModel> actionContext) {
34-
QueryReportConfigurationModel report = actionContext.getData();
35-
String query = report.getSearchQuery();
36-
Map<String, Object> params = dataReportService.getReportParameters(report);
37-
38-
LOG.debug("Executing query {} with params {}", query, params);
39-
GenericSearchResult search = flexibleSearchService.search(query, params);
40-
41-
if (search.hasError()) {
42-
return error(MessageFormat.format(actionContext.getLabel(SEARCH_ERROR), search.getError()));
20+
protected ActionResult<Object> processSearchResult(ActionContext<QueryReportConfigurationModel> actionContext, GenericSearchResult searchResult) {
21+
if (searchResult.hasError()) {
22+
return error(MessageFormat.format(actionContext.getLabel(SEARCH_ERROR), searchResult.getError()));
4323
} else {
44-
return success(MessageFormat.format(actionContext.getLabel(SEARCH_SUCCESS), search.getValues().size()));
24+
return success(MessageFormat.format(actionContext.getLabel(SEARCH_SUCCESS), searchResult.getValues().size()));
4525
}
4626
}
47-
48-
private ActionResult<Object> success(String msg) {
49-
Messagebox.show(msg);
50-
return new ActionResult<>(ActionResult.SUCCESS);
51-
}
52-
53-
private ActionResult<Object> error(String msg) {
54-
Messagebox.show(msg, "Error", Messagebox.OK, Messagebox.ERROR);
55-
ActionResult<Object> result = new ActionResult<>(ActionResult.ERROR);
56-
result.setResultMessage(msg);
57-
return result;
58-
}
59-
60-
@Override
61-
public boolean needsConfirmation(ActionContext<QueryReportConfigurationModel> ctx) {
62-
return false;
63-
}
6427
}

core-customize/hybris/bin/custom/sapcxtools/sapcxreporting/resources/localization/sapcxreporting-locales.properties

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ type.ReportGenerationSchedule.name=Report Schedule
22
type.ReportGenerationSchedule.reports.name=Reports
33

44
type.QueryReportConfiguration.name=Query Report
5+
type.QueryReportConfiguration.searchQueryType.name=Query Type
56
type.QueryReportConfiguration.searchQuery.name=Query
6-
type.QueryReportConfiguration.searchQuery.description=Enter the query in FlexibleSearch Syntax
7+
type.QueryReportConfiguration.searchQuery.description=Enter the query in syntax according to query type.
78
type.QueryReportConfiguration.id.name=ID
89
type.QueryReportConfiguration.title.name=Title
910
type.QueryReportConfiguration.description.name=Description
@@ -41,4 +42,12 @@ type.PropertyConfigurationParameter.name=Property Parameter
4142
type.ConfigurationPropertyAccessor.name=Property Accessor
4243
type.ConfigurationPropertyAccessor.description=Allow to inject configuration properties into flexible search queries.
4344
type.ConfigurationPropertyAccessor.key.name=Key
44-
type.ConfigurationPropertyAccessor.value.name=Value
45+
type.ConfigurationPropertyAccessor.value.name=Value
46+
47+
type.ReportExportFormat.name=Export format
48+
type.ReportExportFormat.CSV.name=Comma-separated values (CSV)
49+
type.ReportExportFormat.XLS.name=Microsoft Excel (XLS)
50+
51+
type.SearchQueryType.name=Query type
52+
type.SearchQueryType.FlexibleSearch.name=Flexible Search
53+
type.SearchQueryType.ImpExExport.name=ImpEx Export

core-customize/hybris/bin/custom/sapcxtools/sapcxreporting/resources/localization/sapcxreporting-locales_de.properties

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ type.ReportGenerationSchedule.name=Bericht Zeitplan
22
type.ReportGenerationSchedule.reports.name=Berichte
33

44
type.QueryReportConfiguration.name=Bericht
5+
type.QueryReportConfiguration.searchQueryType.name=Abfrage-Typ
56
type.QueryReportConfiguration.searchQuery.name=Anfrage
6-
type.QueryReportConfiguration.searchQuery.description=Eingabe der Anfrage (FlexibleSearch Syntax)
7+
type.QueryReportConfiguration.searchQuery.description=Eingabe der Anfrage (Syntax passend zum Typ)
78
type.QueryReportConfiguration.id.name=ID
89
type.QueryReportConfiguration.title.name=Titel
910
type.QueryReportConfiguration.description.name=Beschreibung
@@ -42,3 +43,11 @@ type.ConfigurationPropertyAccessor.name=Konfigurationswert
4243
type.ConfigurationPropertyAccessor.description=Ermöglicht die Verwendung von Konfigurationswerten in Flexible Search Queries
4344
type.ConfigurationPropertyAccessor.key.name=Schlüssel
4445
type.ConfigurationPropertyAccessor.value.name=Wert
46+
47+
type.ReportExportFormat.name=Exportformat
48+
type.ReportExportFormat.CSV.name=Comma-separated values (CSV)
49+
type.ReportExportFormat.XLS.name=Microsoft Excel (XLS)
50+
51+
type.SearchQueryType.name=Abfragetyp
52+
type.SearchQueryType.FlexibleSearch.name=Flexible Search
53+
type.SearchQueryType.ImpExExport.name=ImpEx Export

core-customize/hybris/bin/custom/sapcxtools/sapcxreporting/resources/localization/sapcxreporting-locales_en.properties

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ type.ReportGenerationSchedule.name=Report Schedule
22
type.ReportGenerationSchedule.reports.name=Reports
33

44
type.QueryReportConfiguration.name=Query Report
5+
type.QueryReportConfiguration.searchQueryType.name=Query Type
56
type.QueryReportConfiguration.searchQuery.name=Query
6-
type.QueryReportConfiguration.searchQuery.description=Enter the query in FlexibleSearch Syntax
7+
type.QueryReportConfiguration.searchQuery.description=Enter the query in syntax according to query type.
78
type.QueryReportConfiguration.id.name=ID
89
type.QueryReportConfiguration.title.name=Title
910
type.QueryReportConfiguration.description.name=Description
@@ -42,3 +43,11 @@ type.ConfigurationPropertyAccessor.name=Property Accessor
4243
type.ConfigurationPropertyAccessor.description=Allow to inject configuration properties into flexible search queries.
4344
type.ConfigurationPropertyAccessor.key.name=Key
4445
type.ConfigurationPropertyAccessor.value.name=Value
46+
47+
type.ReportExportFormat.name=Export format
48+
type.ReportExportFormat.CSV.name=Comma-separated values (CSV)
49+
type.ReportExportFormat.XLS.name=Microsoft Excel (XLS)
50+
51+
type.SearchQueryType.name=Query type
52+
type.SearchQueryType.FlexibleSearch.name=Flexible Search
53+
type.SearchQueryType.ImpExExport.name=ImpEx Export

core-customize/hybris/bin/custom/sapcxtools/sapcxreporting/resources/sapcxreporting-backoffice-config.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<list-view:list-view>
120120
<list-view:column qualifier="id" hflex="true"/>
121121
<list-view:column qualifier="title" hflex="true"/>
122+
<list-view:column qualifier="searchQueryType" width="150" hflex="false"/>
122123
<list-view:column qualifier="exportFormat" width="150" hflex="false"/>
123124
<list-view:column qualifier="compress" width="200" hflex="false"/>
124125
<list-view:column qualifier="emailEmptyResult" width="200" hflex="false"/>
@@ -188,6 +189,7 @@
188189
</editorArea:attribute>
189190
</editorArea:panel>
190191
<editorArea:panel name="sapcxreporting.backoffice.panel.query">
192+
<editorArea:attribute qualifier="searchQueryType"/>
191193
<editorArea:attribute qualifier="searchQuery">
192194
<editorArea:editor-parameter>
193195
<editorArea:name>rows</editorArea:name>

0 commit comments

Comments
 (0)