Search in sources :

Example 1 with EntityOpResult

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();
}
Also used : Entity(com.qcadoo.model.api.Entity) EntitySignature(com.qcadoo.model.internal.utils.EntitySignature) EntityOpResult(com.qcadoo.model.api.EntityOpResult)

Example 2 with EntityOpResult

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();
}
Also used : EntityOpResult(com.qcadoo.model.api.EntityOpResult) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EntityOpResult

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityOpResult(com.qcadoo.model.api.EntityOpResult) Test(org.junit.Test)

Example 4 with EntityOpResult

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());
}
Also used : EntityOpResult(com.qcadoo.model.api.EntityOpResult) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) EntityMessagesHolder(com.qcadoo.model.api.EntityMessagesHolder) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 5 with EntityOpResult

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityOpResult(com.qcadoo.model.api.EntityOpResult) Test(org.junit.Test)

Aggregations

EntityOpResult (com.qcadoo.model.api.EntityOpResult)21 Entity (com.qcadoo.model.api.Entity)19 Test (org.junit.Test)15 ProxyEntity (com.qcadoo.model.internal.ProxyEntity)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)2 InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)2 ArrayList (java.util.ArrayList)2 EntityList (com.qcadoo.model.api.EntityList)1 EntityMessagesHolder (com.qcadoo.model.api.EntityMessagesHolder)1 Monitorable (com.qcadoo.model.api.aop.Monitorable)1 CollectionFieldType (com.qcadoo.model.api.types.CollectionFieldType)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 TreeType (com.qcadoo.model.api.types.TreeType)1 EntitySignature (com.qcadoo.model.internal.utils.EntitySignature)1 GridComponent (com.qcadoo.view.api.components.GridComponent)1 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)1 Collection (java.util.Collection)1 List (java.util.List)1