Search in sources :

Example 1 with LoggedEntity

use of io.jmix.audit.entity.LoggedEntity in project jmix by jmix-framework.

the class EntityLogBrowser method onLoggedEntityTableCreate.

@Subscribe("loggedEntityTable.create")
public void onLoggedEntityTableCreate(Action.ActionPerformedEvent event) {
    LoggedEntity entity = metadata.create(LoggedEntity.class);
    entity.setAuto(false);
    entity.setManual(false);
    setSelectAllCheckBox(false);
    loggedEntityDc.getMutableItems().add(entity);
    loggedEntityTable.setEditable(true);
    loggedEntityTable.setSelected(entity);
    enableControls();
    entityNameField.setEditable(true);
    entityNameField.focus();
}
Also used : LoggedEntity(io.jmix.audit.entity.LoggedEntity)

Example 2 with LoggedEntity

use of io.jmix.audit.entity.LoggedEntity in project jmix by jmix-framework.

the class EntityLogImpl method loadEntities.

protected void loadEntities() {
    log.debug("Loading entities");
    entitiesManual = new HashMap<>();
    entitiesAuto = new HashMap<>();
    transaction.executeWithoutResult(status -> {
        TypedQuery<LoggedEntity> q = entityManager.createQuery("select e from audit_LoggedEntity e where e.auto = true or e.manual = true", LoggedEntity.class);
        List<LoggedEntity> list = q.getResultList();
        for (LoggedEntity loggedEntity : list) {
            if (loggedEntity.getName() == null) {
                throw new IllegalStateException("Unable to initialize EntityLog: empty LoggedEntity.name");
            }
            Set<String> attributes = new HashSet<>();
            for (LoggedAttribute loggedAttribute : loggedEntity.getAttributes()) {
                if (loggedAttribute.getName() == null) {
                    throw new IllegalStateException("Unable to initialize EntityLog: empty LoggedAttribute.name");
                }
                attributes.add(loggedAttribute.getName());
            }
            if (BooleanUtils.isTrue(loggedEntity.getAuto()))
                entitiesAuto.put(loggedEntity.getName(), attributes);
            if (BooleanUtils.isTrue(loggedEntity.getManual()))
                entitiesManual.put(loggedEntity.getName(), attributes);
        }
    });
    log.debug("Loaded: entitiesAuto={}, entitiesManual={}", entitiesAuto.size(), entitiesManual.size());
}
Also used : LoggedEntity(io.jmix.audit.entity.LoggedEntity) LoggedAttribute(io.jmix.audit.entity.LoggedAttribute)

Example 3 with LoggedEntity

use of io.jmix.audit.entity.LoggedEntity in project jmix by jmix-framework.

the class EntityLogBrowser method onRemoveBtnClick.

@Subscribe("removeBtn")
protected void onRemoveBtnClick(Button.ClickEvent event) {
    Set<LoggedEntity> selectedItems = loggedEntityTable.getSelected();
    if (!selectedItems.isEmpty()) {
        dialogs.createOptionDialog().withCaption(messages.getMessage("dialogs.Confirmation")).withMessage(messages.getMessage("dialogs.Confirmation.Remove")).withActions(new DialogAction(DialogAction.Type.YES).withHandler(e -> {
            for (LoggedEntity item : selectedItems) {
                if (item.getAttributes() != null) {
                    Set<LoggedAttribute> attributes = new HashSet<>(item.getAttributes());
                    for (LoggedAttribute attribute : attributes) {
                        dataContext.remove(attribute);
                    }
                    dataContext.commit();
                }
                dataContext.remove(item);
                dataContext.commit();
            }
            loggedEntityDc.getMutableItems().removeAll(selectedItems);
            entityLog.invalidateCache();
        }), new DialogAction(DialogAction.Type.NO)).show();
    }
}
Also used : LoggedEntity(io.jmix.audit.entity.LoggedEntity) DialogAction(io.jmix.ui.action.DialogAction) LoggedAttribute(io.jmix.audit.entity.LoggedAttribute)

Example 4 with LoggedEntity

use of io.jmix.audit.entity.LoggedEntity in project jmix by jmix-framework.

the class EntityLogBrowser method onSaveBtnClick.

@Subscribe("saveBtn")
protected void onSaveBtnClick(Button.ClickEvent event) {
    LoggedEntity selectedEntity = loggedEntityTable.getSelected().iterator().next();
    selectedEntity = dataContext.merge(selectedEntity);
    Set<LoggedAttribute> enabledAttributes = selectedEntity.getAttributes();
    for (Component c : attributesBoxScroll.getComponents()) {
        CheckBox currentCheckBox = (CheckBox) c;
        if (SELECT_ALL_CHECK_BOX.equals(currentCheckBox.getId()))
            continue;
        Boolean currentCheckBoxValue = currentCheckBox.getValue();
        MetaClass metaClass = metadata.getClass(selectedEntity.getName());
        if (currentCheckBoxValue && !isEntityHaveAttribute(currentCheckBox.getId(), metaClass, enabledAttributes)) {
            // add attribute if checked and not exist in table
            LoggedAttribute newLoggedAttribute = dataContext.create(LoggedAttribute.class);
            newLoggedAttribute.setName(currentCheckBox.getId());
            newLoggedAttribute.setEntity(selectedEntity);
        }
        if (!currentCheckBoxValue && isEntityHaveAttribute(currentCheckBox.getId(), metaClass, enabledAttributes)) {
            // remove attribute if unchecked and exist in table
            LoggedAttribute removeAtr = getLoggedAttribute(currentCheckBox.getId(), enabledAttributes);
            if (removeAtr != null)
                dataContext.remove(removeAtr);
        }
    }
    dataContext.commit();
    loggedEntityDl.load();
    disableControls();
    loggedEntityTable.setEnabled(true);
    loggedEntityTable.focus();
    entityLog.invalidateCache();
}
Also used : LoggedEntity(io.jmix.audit.entity.LoggedEntity) MetaClass(io.jmix.core.metamodel.model.MetaClass) LoggedAttribute(io.jmix.audit.entity.LoggedAttribute) LookupComponent(io.jmix.ui.screen.LookupComponent)

Aggregations

LoggedEntity (io.jmix.audit.entity.LoggedEntity)4 LoggedAttribute (io.jmix.audit.entity.LoggedAttribute)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 DialogAction (io.jmix.ui.action.DialogAction)1 LookupComponent (io.jmix.ui.screen.LookupComponent)1