Search in sources :

Example 21 with Monitorable

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

the class DictionaryServiceImpl method getValues.

@Override
@Transactional(readOnly = true)
@Monitorable
public Map<String, String> getValues(final String dictionary, final Locale locale) {
    checkArgument(hasText(dictionary), "dictionary name must be given");
    List<Entity> items = createCriteriaForItemsFrom(dictionary).addOrder(SearchOrders.asc(DictionaryItemFields.NAME)).list().getEntities();
    Map<String, String> values = new LinkedHashMap<>();
    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)

Example 22 with Monitorable

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

the class DictionaryServiceImpl method createIfNotExists.

@Override
@Transactional
@Monitorable
public void createIfNotExists(final String pluginIdentifier, final String name, final String... values) {
    SearchResult serachResult = getDictionaryDataDefinition().find().add(SearchRestrictions.eq(DictionaryFields.NAME, name)).list();
    if (serachResult.getTotalNumberOfEntities() > 0) {
        Entity dictionaryEntity = serachResult.getEntities().get(0);
        dictionaryEntity.setField(DictionaryFields.ACTIVE, true);
        getDictionaryDataDefinition().save(dictionaryEntity);
        return;
    }
    Entity dictionary = getDictionaryDataDefinition().create();
    dictionary.setField(DictionaryFields.PLUGIN_IDENTIFIER, pluginIdentifier);
    dictionary.setField(DictionaryFields.NAME, name);
    dictionary.setField(DictionaryFields.ACTIVE, true);
    dictionary = getDictionaryDataDefinition().save(dictionary);
    for (String value : values) {
        Entity item = getItemDataDefinition().create();
        item.setField(DictionaryItemFields.DICTIONARY, dictionary);
        item.setField(DictionaryItemFields.DESCRIPTION, "");
        item.setField(DictionaryItemFields.NAME, value);
        getItemDataDefinition().save(item);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchResult(com.qcadoo.model.api.search.SearchResult) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Monitorable

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

the class DictionaryServiceImpl method disable.

@Override
@Transactional
@Monitorable
public void disable(final String pluginIdentifier, final String name) {
    final DataDefinition dictionaryDataDefinition = getDictionaryDataDefinition();
    final SearchCriteriaBuilder searchCriteriaBuilder = dictionaryDataDefinition.find();
    searchCriteriaBuilder.add(SearchRestrictions.eq(DictionaryFields.NAME, name));
    searchCriteriaBuilder.add(SearchRestrictions.eq(DictionaryFields.ACTIVE, true));
    searchCriteriaBuilder.setMaxResults(1);
    final Entity dictionaryEntity = searchCriteriaBuilder.uniqueResult();
    if (dictionaryEntity != null) {
        dictionaryEntity.setField(DictionaryFields.ACTIVE, false);
        dictionaryDataDefinition.save(dictionaryEntity);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) DataDefinition(com.qcadoo.model.api.DataDefinition) 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