use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class SearchQueryImpl method prepareDataDefinitions.
private String prepareDataDefinitions(final String queryString) {
boolean hasSelectSection = !queryString.startsWith("from");
Matcher matcher = pattern.matcher(queryString);
String newQueryString = queryString;
while (matcher.find()) {
InternalDataDefinition dataDefinition = dataAccessService.getDataDefinition(matcher.group(1), matcher.group(2));
newQueryString = newQueryString.replaceAll("#" + dataDefinition.getPluginIdentifier() + "_" + dataDefinition.getName(), dataDefinition.getFullyQualifiedClassName());
if (!hasSelectSection && mainDataDefinition == null) {
mainDataDefinition = dataDefinition;
}
}
return newQueryString;
}
use of com.qcadoo.model.internal.api.InternalDataDefinition 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.internal.api.InternalDataDefinition 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.internal.api.InternalDataDefinition 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;
}
use of com.qcadoo.model.internal.api.InternalDataDefinition in project qcadoo by qcadoo.
the class DataAccessServiceImpl method copyTreeField.
private void copyTreeField(final Entity sourceEntity, final Entity targetEntity, final DataDefinition dataDefinition, final String fieldName) {
FieldDefinition fieldDefinition = dataDefinition.getField(fieldName);
if (!isFieldCopyable(TreeType.class, fieldDefinition, dataDefinition)) {
return;
}
TreeType treeType = ((TreeType) fieldDefinition.getType());
List<Entity> entities = new ArrayList<Entity>();
Entity root = sourceEntity.getTreeField(fieldName).getRoot();
if (root != null) {
root.setField(treeType.getJoinFieldName(), null);
root = copy((InternalDataDefinition) treeType.getDataDefinition(), root);
if (root != null) {
entities.add(root);
}
}
targetEntity.setField(fieldName, entities);
}
Aggregations