Search in sources :

Example 11 with Monitorable

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

the class DictionaryServiceImpl method getKeyValues.

@Override
@Transactional(readOnly = true)
@Monitorable
public Map<String, String> getKeyValues(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<>();
    for (Entity item : items) {
        values.put(item.getStringField(DictionaryItemFields.TECHNICAL_CODE), 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)

Example 12 with Monitorable

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

the class DictionaryServiceImpl method getDictionaries.

@Override
@Transactional(readOnly = true)
@Monitorable
public Set<String> getDictionaries() {
    List<Entity> dictionaries = getDictionaryDataDefinition().find().addOrder(SearchOrders.asc(DictionaryFields.NAME)).list().getEntities();
    Set<String> names = new HashSet<>();
    for (Entity dictionary : dictionaries) {
        if ((Boolean) dictionary.getField(DictionaryFields.ACTIVE)) {
            names.add(dictionary.getStringField(DictionaryFields.NAME));
        }
    }
    return names;
}
Also used : Entity(com.qcadoo.model.api.Entity) HashSet(java.util.HashSet) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Monitorable

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

the class MenuServiceImpl method getMenu.

@Override
@Transactional(readOnly = true)
@Monitorable
public MenuDefinition getMenu(final Locale locale) {
    MenuDefinition menuDefinition = new MenuDefinition();
    List<Entity> menuCategories = menuCrudService.getSortedMenuCategories();
    for (Entity menuCategory : menuCategories) {
        String authRoleIdentifier = menuCategory.getStringField(MenuCategoryFields.AUTH_ROLE);
        if (!currentUserHasPrivilegesOf(authRoleIdentifier)) {
            continue;
        }
        MenuItemsGroup category = buildCategoryWithItems(menuCategory, locale);
        if (ADMINISTRATION_CATEGORY.equals(category.getName())) {
            menuDefinition.setAdministrationCategory(category);
        } else if (HOME_CATEGORY.equals(category.getName())) {
            menuDefinition.setHomeCategory(category);
        } else if (!category.getItems().isEmpty()) {
            menuDefinition.addItem(category);
        }
    }
    return menuDefinition;
}
Also used : Entity(com.qcadoo.model.api.Entity) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with Monitorable

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

the class DataAccessServiceImpl method move.

@Transactional
@Monitorable
private void move(final InternalDataDefinition dataDefinition, final Long entityId, final int position, final int offset) {
    InternalDataDefinition dataDefinitionToMove = getDataDefinitionByMasterModel(dataDefinition);
    checkNotNull(dataDefinitionToMove, L_DATA_DEFINITION_MUST_BE_GIVEN);
    checkState(dataDefinitionToMove.isPrioritizable(), "Entity must be prioritizable");
    checkState(dataDefinitionToMove.isEnabled(), L_DATA_DEFINITION_BELONGS_TO_DISABLED_PLUGIN);
    checkNotNull(entityId, "EntityId must be given");
    Object databaseEntity = getDatabaseEntity(dataDefinitionToMove, entityId);
    if (databaseEntity == null) {
        logEntityInfo(dataDefinitionToMove, entityId, "hasn't been prioritized, because it doesn't exist");
        return;
    }
    priorityService.move(dataDefinitionToMove, databaseEntity, position, offset);
    logEntityInfo(dataDefinitionToMove, entityId, "has been prioritized");
}
Also used : InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with Monitorable

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

the class DataAccessServiceImpl method activate.

@Override
@Transactional
@Monitorable
public List<Entity> activate(final InternalDataDefinition dataDefinition, final Long... entityIds) {
    if (!dataDefinition.isActivable()) {
        return Collections.emptyList();
    }
    InternalDataDefinition dataDefinitionToActivate = getDataDefinitionByMasterModel(dataDefinition);
    List<Entity> activatedEntities = new ArrayList<Entity>();
    for (Long entityId : entityIds) {
        Entity entity = get(dataDefinitionToActivate, entityId);
        if (entity == null) {
            throw new IllegalStateException("Cannot activate " + entityId);
        }
        if (!entity.isActive()) {
            entity.setActive(true);
            entity = save(dataDefinitionToActivate, entity);
            if (!entity.isValid()) {
                throw new IllegalStateException("Cannot activate " + entity);
            }
            LOG.debug(entity + " has been activated");
            activatedEntities.add(entity);
        }
    }
    return activatedEntities;
}
Also used : Entity(com.qcadoo.model.api.Entity) ArrayList(java.util.ArrayList) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) 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