Search in sources :

Example 1 with EntityMessagesHolder

use of com.qcadoo.model.api.EntityMessagesHolder 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();
}
Also used : Entity(com.qcadoo.model.api.Entity) JoinFieldHolder(com.qcadoo.model.api.types.JoinFieldHolder) EntityMessagesHolder(com.qcadoo.model.api.EntityMessagesHolder)

Example 2 with EntityMessagesHolder

use of com.qcadoo.model.api.EntityMessagesHolder 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 3 with EntityMessagesHolder

use of com.qcadoo.model.api.EntityMessagesHolder in project mes by qcadoo.

the class UnusedContextsCleanUpService method performCleanUp.

@Async
@Scheduled(cron = CRON_EVERYDAY_AT_5AM)
@RunIfEnabled(TechnologiesGeneratorConstants.PLUGIN_IDENTIFIER)
public void performCleanUp() {
    DateTime threshold = DateTime.now().minusWeeks(1);
    Either<EntityMessagesHolder, List<ContextId>> result = generatorContextDataProvider.deleteContextsNotUsedSince(threshold);
    if (result.isLeft()) {
        warn(String.format("CleanUp aborted - Technology generator context couldn't be deleted: %s", result.getLeft()));
    } else {
        info(String.format("CleanUp done - %s technology generator contexts were deleted.", result.getRight().size()));
    }
}
Also used : List(java.util.List) DateTime(org.joda.time.DateTime) EntityMessagesHolder(com.qcadoo.model.api.EntityMessagesHolder) Scheduled(org.springframework.scheduling.annotation.Scheduled) Async(org.springframework.scheduling.annotation.Async) RunIfEnabled(com.qcadoo.plugin.api.RunIfEnabled)

Aggregations

EntityMessagesHolder (com.qcadoo.model.api.EntityMessagesHolder)3 Entity (com.qcadoo.model.api.Entity)1 EntityOpResult (com.qcadoo.model.api.EntityOpResult)1 JoinFieldHolder (com.qcadoo.model.api.types.JoinFieldHolder)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 RunIfEnabled (com.qcadoo.plugin.api.RunIfEnabled)1 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 Async (org.springframework.scheduling.annotation.Async)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1