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;
}
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);
}
}
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);
}
}
Aggregations