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();
}
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());
}
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()));
}
}
Aggregations