Search in sources :

Example 1 with Monitorable

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

the class SecurityServiceImpl method getCurrentUserName.

@Override
@Monitorable
public String getCurrentUserName() {
    SecurityContext context = getContext();
    Authentication authentication = getAuthentication();
    if (Objects.isNull(context) || Objects.isNull(authentication) || Objects.isNull(authentication.getName())) {
        return null;
    }
    String userName = authentication.getName();
    Entity user = getUserEntity(userName);
    return user.getStringField(UserFields.USER_NAME);
}
Also used : Entity(com.qcadoo.model.api.Entity) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) Monitorable(com.qcadoo.model.api.aop.Monitorable)

Example 2 with Monitorable

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

the class SecurityServiceImpl method getCurrentUserId.

@Override
@Monitorable
public Long getCurrentUserId() {
    SecurityContext context = getContext();
    Authentication authentication = getAuthentication();
    if (Objects.isNull(context) || Objects.isNull(authentication) || Objects.isNull(authentication.getName())) {
        return null;
    }
    String userName = authentication.getName();
    Entity user = getUserEntity(userName);
    return user.getId();
}
Also used : Entity(com.qcadoo.model.api.Entity) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) Monitorable(com.qcadoo.model.api.aop.Monitorable)

Example 3 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 SearchCriteria searchCriteria) {
    checkArgument(searchCriteria != null, "SearchCriteria must be given");
    Criteria criteria = searchCriteria.createCriteria(hibernateService.getCurrentSession());
    int totalNumberOfEntities = hibernateService.getTotalNumberOfEntities(criteria);
    if (totalNumberOfEntities == 0) {
        LOG.debug("There is no entity matching criteria " + searchCriteria);
        return getResultSet(null, totalNumberOfEntities, Collections.emptyList());
    }
    searchCriteria.addFirstAndMaxResults(criteria);
    searchCriteria.addOrders(criteria);
    searchCriteria.addCacheable(criteria);
    List<?> results = hibernateService.list(criteria);
    if (LOG.isDebugEnabled()) {
        LOG.debug("There are " + totalNumberOfEntities + " entities matching criteria " + searchCriteria);
    }
    InternalDataDefinition searchQueryDataDefinition = (InternalDataDefinition) searchCriteria.getDataDefinition();
    if (searchQueryDataDefinition == null) {
        searchQueryDataDefinition = hibernateService.resolveDataDefinition(criteria);
    }
    return getResultSet(searchQueryDataDefinition, totalNumberOfEntities, results);
}
Also used : SearchCriteria(com.qcadoo.model.internal.search.SearchCriteria) Criteria(org.hibernate.Criteria) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Monitorable

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

the class DataAccessServiceImpl method deactivate.

@Override
@Transactional
@Monitorable
public List<Entity> deactivate(final InternalDataDefinition dataDefinition, final Long... entityIds) {
    if (!dataDefinition.isActivable()) {
        return Collections.emptyList();
    }
    InternalDataDefinition dataDefinitionToDeactivate = getDataDefinitionByMasterModel(dataDefinition);
    List<Entity> deactivatedEntities = new ArrayList<Entity>();
    for (Long entityId : entityIds) {
        Entity entity = get(dataDefinitionToDeactivate, entityId);
        if (entity == null) {
            throw new IllegalStateException("Cannot deactivate " + entityId + " (entity not found)");
        }
        if (entity.isActive()) {
            entity.setActive(false);
            entity = save(dataDefinitionToDeactivate, entity);
            if (!entity.isValid()) {
                throw new IllegalStateException("Cannot deactivate " + entity + " because of validation errors");
            }
            LOG.debug(entity + " has been deactivated");
            deactivatedEntities.add(entity);
        }
    }
    return deactivatedEntities;
}
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)

Example 5 with Monitorable

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

the class DataAccessServiceImpl method copy.

@Override
@Transactional
@Monitorable
public List<Entity> copy(final InternalDataDefinition dataDefinition, final Long... entityIds) {
    InternalDataDefinition dataDefinitionToCopy = getDataDefinitionByMasterModel(dataDefinition);
    List<Entity> copiedEntities = new ArrayList<Entity>();
    for (Long entityId : entityIds) {
        Entity sourceEntity = get(dataDefinitionToCopy, entityId);
        Entity targetEntity = copy(dataDefinitionToCopy, sourceEntity);
        if (targetEntity == null) {
            throw new IllegalStateException("Cannot copy " + sourceEntity);
        }
        LOG.debug(sourceEntity + " has been copied to " + targetEntity);
        targetEntity = save(dataDefinitionToCopy, targetEntity);
        if (!targetEntity.isValid()) {
            throw new CopyException(targetEntity);
        }
        copiedEntities.add(targetEntity);
    }
    return copiedEntities;
}
Also used : Entity(com.qcadoo.model.api.Entity) CopyException(com.qcadoo.model.api.CopyException) 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