Search in sources :

Example 16 with Monitorable

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Monitorable

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) Monitorable(com.qcadoo.model.api.aop.Monitorable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with Monitorable

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);
    }
}
Also used : GridComponent(com.qcadoo.view.api.components.GridComponent) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Map(java.util.Map) File(java.io.File) Monitorable(com.qcadoo.model.api.aop.Monitorable)

Example 19 with Monitorable

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);
    }
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) GridComponent(com.qcadoo.view.api.components.GridComponent) JSONArray(org.json.JSONArray) FileNotFoundException(java.io.FileNotFoundException) JSONException(org.json.JSONException) PdfPageNumbering(com.qcadoo.report.api.pdf.PdfPageNumbering) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Document(com.lowagie.text.Document) Date(java.util.Date) PdfPTable(com.lowagie.text.pdf.PdfPTable) FileOutputStream(java.io.FileOutputStream) DocumentException(com.lowagie.text.DocumentException) File(java.io.File) Map(java.util.Map) Monitorable(com.qcadoo.model.api.aop.Monitorable)

Example 20 with Monitorable

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) LinkedHashMap(java.util.LinkedHashMap) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Monitorable (com.qcadoo.model.api.aop.Monitorable)23 Transactional (org.springframework.transaction.annotation.Transactional)17 Entity (com.qcadoo.model.api.Entity)15 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)7 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)3 DataDefinition (com.qcadoo.model.api.DataDefinition)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 GridComponent (com.qcadoo.view.api.components.GridComponent)2 File (java.io.File)2 Map (java.util.Map)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 Authentication (org.springframework.security.core.Authentication)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 Document (com.lowagie.text.Document)1 DocumentException (com.lowagie.text.DocumentException)1 PdfPTable (com.lowagie.text.pdf.PdfPTable)1 PdfWriter (com.lowagie.text.pdf.PdfWriter)1 CopyException (com.qcadoo.model.api.CopyException)1