use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.
the class DataAccessServiceImpl method get.
@Override
@Transactional(readOnly = true)
@Monitorable
public Entity get(final InternalDataDefinition dataDefinition, final Long entityId) {
checkNotNull(dataDefinition, L_DATA_DEFINITION_MUST_BE_GIVEN);
checkState(dataDefinition.isEnabled(), L_DATA_DEFINITION_BELONGS_TO_DISABLED_PLUGIN);
checkNotNull(entityId, "EntityId must be given");
Object databaseEntity = getDatabaseEntity(dataDefinition, entityId);
if (databaseEntity == null) {
logEntityInfo(dataDefinition, entityId, "hasn't been retrieved, because it doesn't exist");
return null;
}
Entity entity = entityService.convertToGenericEntity(dataDefinition, databaseEntity);
if (LOG.isDebugEnabled()) {
LOG.debug(entity + " has been retrieved");
}
return entity;
}
use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.
the class CrudController method prepareView.
@Monitorable(threshold = 500)
@RequestMapping(value = CONTROLLER_PATH, method = RequestMethod.GET)
public ModelAndView prepareView(@PathVariable(PLUGIN_IDENTIFIER_VARIABLE) final String pluginIdentifier, @PathVariable(VIEW_NAME_VARIABLE) final String viewName, @RequestParam final Map<String, String> arguments, final Locale locale) {
ModelAndView mav = crudService.prepareView(pluginIdentifier, viewName, arguments, locale);
mav.addObject("useCompressedStaticResources", useCompressedStaticResources);
return mav;
}
use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.
the class ExportToCsvController method generateCsv.
@Monitorable(threshold = 500)
@ResponseBody
@RequestMapping(value = { L_CONTROLLER_PATH }, method = RequestMethod.POST)
public Object generateCsv(@PathVariable(L_PLUGIN_IDENTIFIER_VARIABLE) final String pluginIdentifier, @PathVariable(L_VIEW_NAME_VARIABLE) final String viewName, @RequestBody final JSONObject body, final Locale locale, @RequestHeader("User-Agent") final String userAgent) {
try {
changeMaxResults(body);
ViewDefinitionState state = crudService.invokeEvent(pluginIdentifier, viewName, body, locale);
GridComponent grid = (GridComponent) state.getComponentByReference(QcadooViewConstants.L_GRID);
if (grid == null) {
JSONArray args = body.getJSONObject("event").getJSONArray("args");
if (args.length() > 0) {
grid = (GridComponent) state.getComponentByReference(args.getString(0));
}
}
List<String> columns = getColumns(grid);
List<String> columnNames = getColumnNames(grid, columns);
List<Map<String, String>> rows;
if (grid.getSelectedEntitiesIds().isEmpty()) {
rows = grid.getColumnValuesOfAllRecords();
} else {
rows = grid.getColumnValuesOfSelectedRecords();
}
File file = exportToCsv.createExportFile(columns, columnNames, rows, grid.getName());
boolean openInNewWindow = !StringUtils.isNoneBlank(userAgent) || (!userAgent.contains("Chrome") && !userAgent.contains("Safari")) || userAgent.contains("Edge");
state.redirectTo(fileService.getUrl(file.getAbsolutePath()) + "?clean", openInNewWindow, false);
return crudService.renderView(state);
} catch (JSONException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.
the class ExportToPdfController method generatePdf.
@Monitorable(threshold = 500)
@ResponseBody
@RequestMapping(value = { L_CONTROLLER_PATH }, method = RequestMethod.POST)
public Object generatePdf(@PathVariable(L_PLUGIN_IDENTIFIER_VARIABLE) final String pluginIdentifier, @PathVariable(L_VIEW_NAME_VARIABLE) final String viewName, @RequestBody final JSONObject body, final Locale locale, @RequestHeader("User-Agent") final String userAgent) {
try {
changeMaxResults(body);
ViewDefinitionState state = crudService.invokeEvent(pluginIdentifier, viewName, body, locale);
GridComponent grid = (GridComponent) state.getComponentByReference(QcadooViewConstants.L_GRID);
if (grid == null) {
JSONArray args = body.getJSONObject("event").getJSONArray("args");
if (args.length() > 0) {
grid = (GridComponent) state.getComponentByReference(args.getString(0));
}
}
Document document = new Document(PageSize.A4.rotate());
String date = DateFormat.getDateInstance().format(new Date());
File file = fileService.createExportFile("export_" + grid.getName() + "_" + date + ".pdf");
FileOutputStream fileOutputStream = new FileOutputStream(file);
PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream);
pdfWriter.setPageEvent(new PdfPageNumbering(footerResolver.resolveFooter(locale)));
document.setMargins(40, 40, 60, 60);
document.addTitle("export.pdf");
pdfHelper.addMetaData(document);
pdfWriter.createXmpMetadata();
document.open();
String title = translationService.translate(pluginIdentifier + "." + viewName + ".window.mainTab." + grid.getName() + ".header", locale);
Date generationDate = new Date();
pdfHelper.addDocumentHeader(document, "", title, translationService.translate("qcadooReport.commons.generatedBy.label", locale), generationDate);
List<String> columns = getColumns(grid);
List<String> columnNames = getColumnNames(grid, columns);
PdfPTable pdfTable = pdfHelper.createTableWithHeader(columnNames.size(), columnNames, false);
List<Map<String, String>> rows;
if (grid.getSelectedEntitiesIds().isEmpty()) {
rows = grid.getColumnValuesOfAllRecords();
} else {
rows = grid.getColumnValuesOfSelectedRecords();
}
addPdfTableCells(pdfTable, rows, columns, viewName);
document.add(pdfTable);
document.close();
boolean openInNewWindow = !StringUtils.isNoneBlank(userAgent) || (!userAgent.contains("Chrome") && !userAgent.contains("Safari")) || userAgent.contains("Edge");
state.redirectTo(fileService.getUrl(file.getAbsolutePath()) + "?clean", openInNewWindow, false);
return crudService.renderView(state);
} catch (JSONException | FileNotFoundException | DocumentException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.
the class DictionaryServiceImpl method getActiveValues.
@Override
@Transactional(readOnly = true)
@Monitorable
public Map<String, String> getActiveValues(final String dictionary, final Locale locale) {
checkArgument(hasText(dictionary), "dictionary name must be given");
List<Entity> items = createCriteriaForActiveItemsFrom(dictionary).addOrder(SearchOrders.asc(DictionaryItemFields.NAME)).list().getEntities();
Map<String, String> values = new LinkedHashMap<>();
// TODO MAKU translate dictionary values
for (Entity item : items) {
values.put(item.getStringField(DictionaryItemFields.NAME), item.getStringField(DictionaryItemFields.NAME));
}
return values;
}
Aggregations