use of com.qcadoo.model.api.Entity 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.Entity 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.api.Entity in project qcadoo by qcadoo.
the class DataAccessServiceImpl method performCascadeNullification.
private EntityOpResult performCascadeNullification(final InternalDataDefinition childDataDefinition, final Collection<Entity> children, final Entity entity, final FieldType fieldType) {
String joinFieldName = ((JoinFieldHolder) fieldType).getJoinFieldName();
for (Entity child : children) {
child.setField(joinFieldName, null);
child = save(childDataDefinition, child);
if (!child.isValid()) {
String msg = String.format("Can not nullify field '%s' in %s because of following validation errors:", joinFieldName, child);
logEntityErrors(child, msg);
EntityMessagesHolder msgHolder = new EntityMessagesHolderImpl(child);
msgHolder.addGlobalError("qcadooView.errorPage.error.dataIntegrityViolationException.objectInUse.explanation");
return EntityOpResult.failure(msgHolder);
}
}
return EntityOpResult.successfull();
}
use of com.qcadoo.model.api.Entity 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);
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DataAccessServiceImpl method performCascadeDelete.
private EntityOpResult performCascadeDelete(final InternalDataDefinition childDataDefinition, final Collection<Entity> children, final boolean testOnly, final Set<EntitySignature> traversedEntities) {
for (Entity child : children) {
EntitySignature childSignature = EntitySignature.of(child);
if (!traversedEntities.contains(childSignature)) {
traversedEntities.add(childSignature);
EntityOpResult result = deleteEntity(childDataDefinition, child.getId(), testOnly, traversedEntities);
if (!result.isSuccessfull()) {
return result;
}
}
}
return EntityOpResult.successfull();
}
Aggregations