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