use of com.qcadoo.model.api.EntityOpResult 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();
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class DataAccessServiceImpl method delete.
@Override
@Transactional
@Monitorable
public EntityOpResult delete(final InternalDataDefinition dataDefinition, final Long... entityIds) {
InternalDataDefinition dataDefinitionToDelete = getDataDefinitionByMasterModel(dataDefinition);
checkState(dataDefinitionToDelete.isDeletable(), "Entity must be deletable");
checkState(dataDefinitionToDelete.isEnabled(), L_DATA_DEFINITION_BELONGS_TO_DISABLED_PLUGIN);
checkState(entityIds.length > 0, "EntityIds must be given");
for (Long entityId : entityIds) {
EntityOpResult result = deleteEntity(dataDefinitionToDelete, entityId);
if (!result.isSuccessfull()) {
return result;
}
}
return EntityOpResult.successfull();
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class CrudIntegrationTest method shouldFieldRequirementRejectHardDeleteEntity.
@Test
public void shouldFieldRequirementRejectHardDeleteEntity() throws Exception {
// given
Entity factory = save(createFactory("factory"));
Entity division1 = save(createDivision("firstDivision", factory));
Entity division2 = save(createDivision("secondDivision", factory));
verifyHooks.clear();
// when
EntityOpResult result = delete(factory);
// then
assertFalse(result.isSuccessfull());
assertNotNull(fromDb(factory));
Entity division1fromDb = fromDb(division1);
assertNotNull(division1fromDb);
assertNotNull(division1fromDb.getField("factory"));
Entity division2fromDb = fromDb(division2);
assertNotNull(division2fromDb);
assertNotNull(division2fromDb.getField("factory"));
int total = jdbcTemplate.queryForInt("select count(*) from " + TABLE_NAME_FACTORY);
assertEquals(1, total);
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.SAVE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.CREATE));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.COPY));
assertEquals(0, verifyHooks.getNumOfInvocations(HookType.UPDATE));
assertEquals(1, verifyHooks.getNumOfInvocations(HookType.DELETE));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldNotDeleteFormEntity.
@Test
public void shouldNotDeleteFormEntity() throws Exception {
// given
EntityMessagesHolder messagesHolder = mock(EntityMessagesHolder.class);
final String message = "some.message";
ErrorMessage errorMessage = new ErrorMessage(message);
given(messagesHolder.getGlobalErrors()).willReturn(Lists.newArrayList(errorMessage));
Map<String, ErrorMessage> fieldErrors = Maps.newHashMap();
fieldErrors.put("name", errorMessage);
given(messagesHolder.getErrors()).willReturn(fieldErrors);
EntityOpResult result = EntityOpResult.failure(messagesHolder);
given(dataDefinition.delete(13L)).willReturn(result);
name.setFieldValue("text");
form.setFieldValue(13L);
// when
form.performEvent(viewDefinitionState, "delete", new String[0]);
// then
assertNotNull(name.getFieldValue());
verify(dataDefinition).delete(13L);
assertEquals(13L, form.getFieldValue());
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class CyclesPreventionTest method shouldNotFallIntoInfiniteCycleDuringCascadeHasManyDeletion2entities.
@Test
public final void shouldNotFallIntoInfiniteCycleDuringCascadeHasManyDeletion2entities() {
// given
Entity modelA = buildEntity(aDataDefinition);
Entity modelB = buildEntity(bDataDefinition);
modelA.setField(FIELD_BT_B, modelB.getId());
modelB.setField(FIELD_BT_A, modelA.getId());
modelA = fromDb(save(modelA));
modelB = fromDb(save(modelB));
// when
EntityOpResult result = aDataDefinition.delete(modelA.getId());
// then
Assert.assertTrue(result.isSuccessfull());
Assert.assertNull(fromDb(modelA));
Assert.assertNull(fromDb(modelB));
}
Aggregations