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