Search in sources :

Example 1 with AppFolder

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

the class FilterDelegateImpl method setFilterActionsEnabled.

protected void setFilterActionsEnabled() {
    boolean isGlobal = filterEntity.getUser() == null;
    boolean userCanEditGlobalFilter = uerCanEditGlobalFilter();
    boolean userCanEditFilters = userCanEditFilers();
    boolean filterEditable = isEditable();
    boolean userCanEditGlobalAppFolder = userSessionSource.getUserSession().isSpecificPermitted(GLOBAL_APP_FOLDERS_PERMISSION);
    MetaClass searchFolderMetaClass = metadata.getClass(SearchFolder.class);
    boolean userCanEditSearchFolder = userSessionSource.getUserSession().isEntityOpPermitted(searchFolderMetaClass, EntityOp.CREATE) || userSessionSource.getUserSession().isEntityOpPermitted(searchFolderMetaClass, EntityOp.UPDATE);
    boolean createdByCurrentUser = userSessionSource.getUserSession().getCurrentOrSubstitutedUser().equals(filterEntity.getUser());
    boolean hasCode = !Strings.isNullOrEmpty(filterEntity.getCode());
    boolean isFolder = filterEntity.getFolder() != null;
    boolean isSearchFolder = isFolder && (filterEntity.getFolder() instanceof SearchFolder);
    boolean isAppFolder = isFolder && (filterEntity.getFolder() instanceof AppFolder);
    boolean isSet = BooleanUtils.isTrue(filterEntity.getIsSet());
    boolean isDefault = BooleanUtils.isTrue(filterEntity.getIsDefault());
    boolean isAdHocFilter = filterEntity == adHocFilter;
    boolean editActionEnabled = !isSet && filterEditable && userCanEditFilters && (!isGlobal || userCanEditGlobalFilter);
    filterSavingPossible = editActionEnabled && ((isGlobal && userCanEditGlobalFilter) || (!isGlobal && createdByCurrentUser)) && ((!isFolder && !hasCode) || isSearchFolder || (isAppFolder && userCanEditGlobalAppFolder));
    boolean saveActionEnabled = filterSavingPossible && (isFolder || isFilterModified());
    boolean saveAsActionEnabled = !isSet && filterEditable && userCanEditFilters;
    boolean removeActionEnabled = !isSet && (!hasCode && !isFolder) && ((isGlobal && userCanEditGlobalFilter) || (!isGlobal && createdByCurrentUser)) && !isAdHocFilter && filterEditable && userCanEditFilters;
    boolean makeDefaultActionEnabled = !isDefault && !isFolder && !isSet && !isAdHocFilter && (!isGlobal || userCanEditGlobalFilter);
    boolean pinAppliedActionEnabled = lastAppliedFilter != null && !(lastAppliedFilter.getFilterEntity() == adHocFilter && lastAppliedFilter.getConditions().getRoots().size() == 0) && (adapter == null || Stores.isMain(metadata.getTools().getStoreName(adapter.getMetaClass())));
    boolean saveAsSearchFolderActionEnabled = folderActionsEnabled && !isFolder && !hasCode && userCanEditSearchFolder;
    boolean saveAsAppFolderActionEnabled = folderActionsEnabled && !isFolder && !hasCode && userCanEditGlobalAppFolder;
    saveAction.setEnabled(saveActionEnabled);
    saveWithValuesAction.setEnabled(filterSavingPossible && !conditions.toConditionsList().isEmpty());
    saveAsAction.setEnabled(saveAsActionEnabled);
    editAction.setEnabled(editActionEnabled);
    removeAction.setEnabled(removeActionEnabled);
    makeDefaultAction.setEnabled(makeDefaultActionEnabled);
    pinAppliedAction.setEnabled(pinAppliedActionEnabled);
    saveAsSearchFolderAction.setEnabled(saveAsSearchFolderActionEnabled);
    saveAsAppFolderAction.setEnabled(saveAsAppFolderActionEnabled);
    if (filterHelper.isTableActionsEnabled() && filterHelper.mainScreenHasFoldersPane(filter.getFrame())) {
        fillTableActions();
    }
}
Also used : AppFolder(com.haulmont.cuba.core.entity.AppFolder) MetaClass(com.haulmont.chile.core.model.MetaClass) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder)

Example 2 with AppFolder

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

the class EntityManagerTest method testMergeWithRefToNewSubclassedEntityOfOriginalAttributeClass.

@Test
public void testMergeWithRefToNewSubclassedEntityOfOriginalAttributeClass() {
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Folder folder = cont.metadata().create(Folder.class);
        AppFolder appFolder = cont.metadata().create(AppFolder.class);
        // folder can have any other folders as a parent, let's set appFolder as a parent
        folder.setParent(appFolder);
        em.merge(folder);
        assertTrue(folder.getParent() instanceof AppFolder);
        tx.commit();
    } finally {
        tx.end();
    }
}
Also used : AppFolder(com.haulmont.cuba.core.entity.AppFolder) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Folder(com.haulmont.cuba.core.entity.Folder) Test(org.junit.jupiter.api.Test)

Example 3 with AppFolder

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

the class QueryCacheTestClass method testStaleData_UpdateParentEntity.

@Test
public void testStaleData_UpdateParentEntity() throws Exception {
    appender.clearMessages();
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.entityManager();
        Query query = em.createQuery("select f from sys$Folder f");
        query.setCacheable(true);
        query.getResultList();
        tx.commit();
    }
    assertEquals(1, queryCache.size());
    appender.clearMessages();
    appFolder = cont.metadata().create(AppFolder.class);
    appFolder.setName("new app folder");
    try (Transaction tx = cont.persistence().createTransaction()) {
        cont.entityManager().persist(appFolder);
        tx.commit();
    }
    appender.clearMessages();
    assertEquals(0, queryCache.size());
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.entityManager();
        Query query = em.createQuery("select f from sys$Folder f");
        query.setCacheable(true);
        query.getResultList();
        tx.commit();
    }
    assertEquals(1, queryCache.size());
}
Also used : AppFolder(com.haulmont.cuba.core.entity.AppFolder) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query) TypedQuery(com.haulmont.cuba.core.TypedQuery) Test(org.junit.jupiter.api.Test)

Example 4 with AppFolder

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

the class FoldersServiceBean method loadAppFolders.

@Override
public List<AppFolder> loadAppFolders() {
    log.debug("Loading AppFolders");
    StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
    stopWatch.start();
    List<AppFolder> resultList;
    try (Transaction tx = persistence.createTransaction()) {
        String metaClassName = metadata.getExtendedEntities().getEffectiveMetaClass(AppFolder.class).getName();
        TypedQuery<AppFolder> q = persistence.getEntityManager().createQuery("select f from " + metaClassName + " f order by f.sortOrder, f.name", AppFolder.class);
        resultList = q.getResultList();
        // fetch parent folder
        resultList.forEach(Folder::getParent);
        tx.commit();
    } finally {
        stopWatch.stop();
    }
    if (CollectionUtils.isNotEmpty(resultList)) {
        Binding binding = new Binding();
        binding.setVariable("persistence", persistence);
        binding.setVariable("metadata", metadata);
        binding.setVariable("userSession", userSessionSource.getUserSession());
        Iterator<AppFolder> iterator = resultList.iterator();
        while (iterator.hasNext()) {
            AppFolder folder = iterator.next();
            try (Transaction tx = persistence.createTransaction()) {
                boolean evaluatedVisibilityScript = true;
                try {
                    if (!StringUtils.isBlank(folder.getVisibilityScript())) {
                        binding.setVariable("folder", folder);
                        Boolean visible = runScript(folder.getVisibilityScript(), binding);
                        if (BooleanUtils.isFalse(visible)) {
                            iterator.remove();
                            continue;
                        }
                    }
                } catch (Exception e) {
                    log.warn("Unable to evaluate AppFolder visibility script for folder: id: {}  name: {}", folder.getId(), folder.getName(), e);
                    // because EclipseLink Query marks transaction as rollback-only on JPQL syntax errors
                    evaluatedVisibilityScript = false;
                }
                boolean evaluatedQuantityScript = loadFolderQuantity(binding, folder);
                if (evaluatedVisibilityScript && evaluatedQuantityScript) {
                    tx.commit();
                }
            }
        }
    }
    return resultList;
}
Also used : Binding(groovy.lang.Binding) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) AppFolder(com.haulmont.cuba.core.entity.AppFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Folder(com.haulmont.cuba.core.entity.Folder) IOException(java.io.IOException) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Transaction(com.haulmont.cuba.core.Transaction)

Example 5 with AppFolder

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

the class FoldersServiceBean method reloadAppFolders.

@Override
public List<AppFolder> reloadAppFolders(List<AppFolder> folders) {
    log.debug("Reloading AppFolders {}", folders);
    StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
    stopWatch.start();
    try {
        if (!folders.isEmpty()) {
            Binding binding = new Binding();
            binding.setVariable("persistence", persistence);
            binding.setVariable("metadata", metadata);
            binding.setProperty("userSession", userSessionSource.getUserSession());
            for (AppFolder folder : folders) {
                Transaction tx = persistence.createTransaction();
                try {
                    if (loadFolderQuantity(binding, folder)) {
                        tx.commit();
                    }
                } finally {
                    tx.end();
                }
            }
        }
        return folders;
    } finally {
        stopWatch.stop();
    }
}
Also used : Binding(groovy.lang.Binding) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Transaction(com.haulmont.cuba.core.Transaction) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Aggregations

AppFolder (com.haulmont.cuba.core.entity.AppFolder)15 Folder (com.haulmont.cuba.core.entity.Folder)5 Transaction (com.haulmont.cuba.core.Transaction)4 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)4 EntityManager (com.haulmont.cuba.core.EntityManager)2 FoldersService (com.haulmont.cuba.core.app.FoldersService)2 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)2 Binding (groovy.lang.Binding)2 Test (org.junit.jupiter.api.Test)2 StopWatch (org.perf4j.StopWatch)2 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 Query (com.haulmont.cuba.core.Query)1 TypedQuery (com.haulmont.cuba.core.TypedQuery)1 User (com.haulmont.cuba.security.entity.User)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 IOException (java.io.IOException)1