Search in sources :

Example 6 with SoftDelete

use of com.haulmont.cuba.core.entity.SoftDelete in project cuba by cuba-platform.

the class EntityRestoreServiceBean method restoreEntities.

@Override
public void restoreEntities(Collection<Entity> entities) {
    for (Entity entity : entities) {
        if (!(entity instanceof SoftDelete))
            continue;
        String storeName = metadata.getTools().getStoreName(metadata.getClassNN(entity.getClass()));
        if (storeName == null) {
            log.warn("Unable to restore entity {}: cannot determine data store", entity);
            continue;
        }
        Transaction tx = persistence.createTransaction(storeName);
        try {
            persistence.getEntityManager(storeName).setSoftDeletion(false);
            restoreEntity(entity, storeName);
            tx.commit();
        } finally {
            tx.end();
        }
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) Transaction(com.haulmont.cuba.core.Transaction)

Example 7 with SoftDelete

use of com.haulmont.cuba.core.entity.SoftDelete in project cuba by cuba-platform.

the class WebEntityLinkField method openEntityEditor.

protected void openEntityEditor() {
    Object value = getValue();
    Entity entity;
    if (value instanceof Entity) {
        entity = (Entity) value;
    } else {
        entity = datasource.getItem();
    }
    if (entity == null) {
        return;
    }
    WindowManager wm;
    Window window = ComponentsHelper.getWindow(this);
    if (window == null) {
        throw new IllegalStateException("Please specify Frame for EntityLinkField");
    } else {
        wm = window.getWindowManager();
    }
    if (screenOpenType.getOpenMode() == OpenMode.DIALOG && screenDialogParams != null) {
        wm.getDialogParams().copyFrom(screenDialogParams);
    }
    if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
        Messages messages = AppBeans.get(Messages.NAME);
        wm.showNotification(messages.getMainMessage("OpenAction.objectIsDeleted"), Frame.NotificationType.HUMANIZED);
        return;
    }
    DataSupplier dataSupplier = window.getDsContext().getDataSupplier();
    entity = dataSupplier.reload(entity, View.MINIMAL);
    String windowAlias = screen;
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    if (windowAlias == null) {
        windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
    }
    final Window.Editor editor = wm.openEditor(windowConfig.getWindowInfo(windowAlias), entity, screenOpenType, screenParams != null ? screenParams : Collections.<String, Object>emptyMap());
    editor.addCloseListener(actionId -> {
        // move focus to component
        component.focus();
        if (Window.COMMIT_ACTION_ID.equals(actionId)) {
            Entity item = editor.getItem();
            afterCommitOpenedEntity(item);
        }
        if (screenCloseListener != null) {
            screenCloseListener.windowClosed(editor, actionId);
        }
    });
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) Entity(com.haulmont.cuba.core.entity.Entity) Messages(com.haulmont.cuba.core.global.Messages) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) WindowManager(com.haulmont.cuba.gui.WindowManager)

Aggregations

SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)7 Entity (com.haulmont.cuba.core.entity.Entity)6 MetaClass (com.haulmont.chile.core.model.MetaClass)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)4 EntityManager (com.haulmont.cuba.core.EntityManager)3 Range (com.haulmont.chile.core.model.Range)2 Query (com.haulmont.cuba.core.Query)2 OnDelete (com.haulmont.cuba.core.entity.annotation.OnDelete)2 OnDeleteInverse (com.haulmont.cuba.core.entity.annotation.OnDeleteInverse)2 java.util (java.util)2 Inject (javax.inject.Inject)2 QueryRunner (com.haulmont.bali.db.QueryRunner)1 Dom4j (com.haulmont.bali.util.Dom4j)1 Persistence (com.haulmont.cuba.core.Persistence)1 Transaction (com.haulmont.cuba.core.Transaction)1 EntityRestoreService (com.haulmont.cuba.core.app.EntityRestoreService)1 EmbeddedParameters (com.haulmont.cuba.core.entity.annotation.EmbeddedParameters)1 EnableRestore (com.haulmont.cuba.core.entity.annotation.EnableRestore)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 DeletePolicy (com.haulmont.cuba.core.global.DeletePolicy)1