Search in sources :

Example 6 with Monitorable

use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.

the class DataAccessServiceImpl method find.

@Override
@Transactional(readOnly = true)
@Monitorable
public SearchResult find(final SearchQuery searchQuery) {
    checkArgument(searchQuery != null, "SearchCriteria must be given");
    Query query = searchQuery.createQuery(hibernateService.getCurrentSession());
    searchQuery.addParameters(query);
    searchQuery.addCacheable(query);
    int totalNumberOfEntities = -1;
    if (searchQuery.hasFirstAndMaxResults()) {
        totalNumberOfEntities = hibernateService.list(query).size();
        searchQuery.addFirstAndMaxResults(query);
    }
    if (totalNumberOfEntities == 0) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("There is no entity matching criteria " + searchQuery);
        }
        return getResultSet(null, totalNumberOfEntities, Collections.emptyList());
    }
    List<?> results = hibernateService.list(query);
    if (totalNumberOfEntities == -1) {
        totalNumberOfEntities = results.size();
        if (totalNumberOfEntities == 0) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("There is no entity matching criteria " + searchQuery);
            }
            return getResultSet(null, totalNumberOfEntities, Collections.emptyList());
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("There are " + totalNumberOfEntities + " entities matching criteria " + searchQuery);
    }
    InternalDataDefinition searchQueryDataDefinition = (InternalDataDefinition) searchQuery.getDataDefinition();
    if (searchQueryDataDefinition == null) {
        searchQueryDataDefinition = hibernateService.resolveDataDefinition(query);
    }
    return getResultSet(searchQueryDataDefinition, totalNumberOfEntities, results);
}
Also used : Query(org.hibernate.Query) SearchQuery(com.qcadoo.model.internal.search.SearchQuery) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Monitorable

use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.

the class DataAccessServiceImpl method delete.

@Override
@Transactional
@Monitorable
public EntityOpResult delete(final InternalDataDefinition dataDefinition, final Long... entityIds) {
    InternalDataDefinition dataDefinitionToDelete = getDataDefinitionByMasterModel(dataDefinition);
    checkState(dataDefinitionToDelete.isDeletable(), "Entity must be deletable");
    checkState(dataDefinitionToDelete.isEnabled(), L_DATA_DEFINITION_BELONGS_TO_DISABLED_PLUGIN);
    checkState(entityIds.length > 0, "EntityIds must be given");
    for (Long entityId : entityIds) {
        EntityOpResult result = deleteEntity(dataDefinitionToDelete, entityId);
        if (!result.isSuccessfull()) {
            return result;
        }
    }
    return EntityOpResult.successfull();
}
Also used : EntityOpResult(com.qcadoo.model.api.EntityOpResult) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Monitorable

use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.

the class DataDefinitionServiceImpl method get.

@Override
@Monitorable
public DataDefinition get(final String pluginIdentifier, final String modelName) {
    DataDefinition dataDefinition = dataDefinitions.get(pluginIdentifier + "." + modelName);
    checkNotNull(dataDefinition, "data definition for %s#%s cannot be found", pluginIdentifier, modelName);
    return dataDefinition;
}
Also used : DataDefinition(com.qcadoo.model.api.DataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable)

Example 9 with Monitorable

use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.

the class DictionaryServiceImpl method getActiveKeys.

@Override
@Transactional(readOnly = true)
@Monitorable
public List<String> getActiveKeys(final String dictionary) {
    checkArgument(hasText(dictionary), "dictionary name must be given");
    List<Entity> items = createCriteriaForItemsFrom(dictionary).add(SearchRestrictions.eq("active", true)).addOrder(SearchOrders.asc(DictionaryItemFields.NAME)).list().getEntities();
    List<String> keys = new ArrayList<>();
    for (Entity item : items) {
        keys.add(item.getStringField(DictionaryItemFields.NAME));
    }
    return keys;
}
Also used : Entity(com.qcadoo.model.api.Entity) ArrayList(java.util.ArrayList) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with Monitorable

use of com.qcadoo.model.api.aop.Monitorable in project qcadoo by qcadoo.

the class DictionaryServiceImpl method getKeys.

@Override
@Transactional(readOnly = true)
@Monitorable
public List<String> getKeys(final String dictionary) {
    checkArgument(hasText(dictionary), "dictionary name must be given");
    List<Entity> items = createCriteriaForItemsFrom(dictionary).addOrder(SearchOrders.asc(DictionaryItemFields.NAME)).list().getEntities();
    List<String> keys = new ArrayList<>();
    for (Entity item : items) {
        keys.add(item.getStringField(DictionaryItemFields.NAME));
    }
    return keys;
}
Also used : Entity(com.qcadoo.model.api.Entity) ArrayList(java.util.ArrayList) 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