Search in sources :

Example 1 with BooleanUtils.isTrue

use of org.apache.commons.lang3.BooleanUtils.isTrue in project herd by FINRAOS.

the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatAttributeDefinitionsHelper.

/**
 * Updates business object format attribute definitions
 *
 * @param businessObjectFormatEntity the business object format entity
 * @param attributeDefinitions the attributes
 */
private void updateBusinessObjectFormatAttributeDefinitionsHelper(BusinessObjectFormatEntity businessObjectFormatEntity, List<AttributeDefinition> attributeDefinitions) {
    // Update the attribute definitions.
    // Load all existing attribute definition entities in a map with a "lowercase" attribute definition name as the key for case insensitivity.
    Map<String, BusinessObjectDataAttributeDefinitionEntity> existingAttributeDefinitionEntities = businessObjectFormatEntity.getAttributeDefinitions().stream().collect(Collectors.toMap(attributeDefinition -> attributeDefinition.getName().toLowerCase(), attributeDefinition -> attributeDefinition));
    // Process the list of attribute definitions to determine that business object definition attribute entities should be created, updated, or deleted.
    List<BusinessObjectDataAttributeDefinitionEntity> createdAttributeDefinitionEntities = new ArrayList<>();
    List<BusinessObjectDataAttributeDefinitionEntity> retainedAttributeDefinitionEntities = new ArrayList<>();
    for (AttributeDefinition attributeDefinition : attributeDefinitions) {
        // Use a "lowercase" attribute name for case insensitivity.
        String lowercaseAttributeName = attributeDefinition.getName().toLowerCase();
        if (existingAttributeDefinitionEntities.containsKey(lowercaseAttributeName)) {
            // Check if the attribute definition value needs to be updated.
            BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = existingAttributeDefinitionEntities.get(lowercaseAttributeName);
            if (!attributeDefinition.isPublish().equals(businessObjectDataAttributeDefinitionEntity.getPublish())) {
                // Update the business object attribute entity.
                businessObjectDataAttributeDefinitionEntity.setPublish(attributeDefinition.isPublish());
            }
            // Add this entity to the list of business object definition attribute entities to be retained.
            retainedAttributeDefinitionEntities.add(businessObjectDataAttributeDefinitionEntity);
        } else {
            // Create a new business object attribute entity.
            BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
            businessObjectFormatEntity.getAttributeDefinitions().add(businessObjectDataAttributeDefinitionEntity);
            businessObjectDataAttributeDefinitionEntity.setBusinessObjectFormat(businessObjectFormatEntity);
            businessObjectDataAttributeDefinitionEntity.setName(attributeDefinition.getName());
            businessObjectDataAttributeDefinitionEntity.setPublish(BooleanUtils.isTrue(attributeDefinition.isPublish()));
            // Add this entity to the list of the newly created business object definition attribute entities.
            createdAttributeDefinitionEntities.add(businessObjectDataAttributeDefinitionEntity);
        }
    }
    // Remove any of the currently existing attribute entities that did not get onto the retained entities list.
    businessObjectFormatEntity.getAttributeDefinitions().retainAll(retainedAttributeDefinitionEntities);
    // Add all of the newly created business object definition attribute entities.
    businessObjectFormatEntity.getAttributeDefinitions().addAll(createdAttributeDefinitionEntities);
}
Also used : Arrays(java.util.Arrays) CustomDdlKey(org.finra.herd.model.api.xml.CustomDdlKey) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) BusinessObjectFormatRetentionInformationUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatRetentionInformationUpdateRequest) Autowired(org.springframework.beans.factory.annotation.Autowired) BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) BusinessObjectFormatAttributesUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatAttributesUpdateRequest) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.finra.herd.model.api.xml.Attribute) Map(java.util.Map) BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) FileTypeDaoHelper(org.finra.herd.service.helper.FileTypeDaoHelper) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) BusinessObjectFormatHelper(org.finra.herd.service.helper.BusinessObjectFormatHelper) Collection(java.util.Collection) PartitionKeyGroupDaoHelper(org.finra.herd.service.helper.PartitionKeyGroupDaoHelper) MessageNotificationEventService(org.finra.herd.service.MessageNotificationEventService) Set(java.util.Set) AttributeDefinition(org.finra.herd.model.api.xml.AttributeDefinition) BusinessObjectFormatDaoHelper(org.finra.herd.service.helper.BusinessObjectFormatDaoHelper) Collectors(java.util.stream.Collectors) NamespacePermissions(org.finra.herd.model.annotation.NamespacePermissions) List(java.util.List) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) BusinessObjectFormatUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatUpdateRequest) BusinessObjectFormatCreateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatCreateRequest) CollectionUtils(org.springframework.util.CollectionUtils) BusinessObjectFormatDdlCollectionRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionRequest) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission) BusinessObjectDefinitionHelper(org.finra.herd.service.helper.BusinessObjectDefinitionHelper) NamespacePermissionEnum(org.finra.herd.model.api.xml.NamespacePermissionEnum) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) DaoSpringModuleConfig(org.finra.herd.dao.config.DaoSpringModuleConfig) BusinessObjectFormatDao(org.finra.herd.dao.BusinessObjectFormatDao) BusinessObjectFormatParentsUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatParentsUpdateRequest) SearchIndexUpdateHelper(org.finra.herd.service.helper.SearchIndexUpdateHelper) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SEARCH_INDEX_UPDATE_TYPE_UPDATE(org.finra.herd.model.dto.SearchIndexUpdateDto.SEARCH_INDEX_UPDATE_TYPE_UPDATE) Propagation(org.springframework.transaction.annotation.Propagation) DdlGeneratorFactory(org.finra.herd.service.helper.DdlGeneratorFactory) Service(org.springframework.stereotype.Service) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) CustomDdlDaoHelper(org.finra.herd.service.helper.CustomDdlDaoHelper) BusinessObjectDefinitionDaoHelper(org.finra.herd.service.helper.BusinessObjectDefinitionDaoHelper) BusinessObjectFormatService(org.finra.herd.service.BusinessObjectFormatService) BusinessObjectDataDao(org.finra.herd.dao.BusinessObjectDataDao) BusinessObjectFormatAttributeEntity(org.finra.herd.model.jpa.BusinessObjectFormatAttributeEntity) AlternateKeyHelper(org.finra.herd.service.helper.AlternateKeyHelper) BusinessObjectFormatDdlCollectionResponse(org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionResponse) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) BusinessObjectDefinitionDao(org.finra.herd.dao.BusinessObjectDefinitionDao) PublishNotificationMessages(org.finra.herd.model.annotation.PublishNotificationMessages) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) BusinessObjectFormatAttributeDefinitionsUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatAttributeDefinitionsUpdateRequest) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatKeys(org.finra.herd.model.api.xml.BusinessObjectFormatKeys) NumberUtils(org.apache.commons.lang3.math.NumberUtils) SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) Schema(org.finra.herd.model.api.xml.Schema) DdlGenerator(org.finra.herd.service.helper.DdlGenerator) Collections(java.util.Collections) AttributeHelper(org.finra.herd.service.helper.AttributeHelper) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) ArrayList(java.util.ArrayList) AttributeDefinition(org.finra.herd.model.api.xml.AttributeDefinition)

Example 2 with BooleanUtils.isTrue

use of org.apache.commons.lang3.BooleanUtils.isTrue in project cuba by cuba-platform.

the class FilterEditor method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    if (Boolean.TRUE.equals(useShortConditionForm)) {
        setCaption(messages.getMainMessage("filter.editor.captionShortForm"));
    }
    getDialogOptions().setWidth(theme.get("cuba.gui.filterEditor.dialog.width")).setHeight(theme.get("cuba.gui.filterEditor.dialog.height")).setResizable(true);
    filterEntity = (FilterEntity) params.get("filterEntity");
    if (filterEntity == null) {
        throw new RuntimeException("Filter entity was not passed to filter editor");
    }
    filter = (Filter) params.get("filter");
    ConditionsTree paramConditions = (ConditionsTree) params.get("conditionsTree");
    conditions = paramConditions.createCopy();
    refreshConditionsDs();
    conditionsTree.expandTree();
    MetaProperty property = metadata.getClassNN(FilterEntity.class).getPropertyNN("name");
    Map<String, Object> annotations = property.getAnnotations();
    Integer maxLength = (Integer) annotations.get("length");
    if (maxLength != null) {
        filterName.setMaxLength(maxLength);
    }
    if (!messages.getMainMessage("filter.adHocFilter").equals(filterEntity.getName())) {
        filterName.setValue(filterEntity.getName());
    }
    availableForAllCb.setValue(filterEntity.getUser() == null);
    defaultCb.setValue(filterEntity.getIsDefault());
    applyDefaultCb.setValue(filterEntity.getApplyDefault());
    globalDefaultCb.setValue(filterEntity.getGlobalDefault());
    if (filterEntity.getUser() != null) {
        globalDefaultCb.setEnabled(false);
    }
    if (!userSessionSource.getUserSession().isSpecificPermitted(GLOBAL_FILTER_PERMISSION)) {
        availableForAllCb.setVisible(false);
        availableForAllLabel.setVisible(false);
        globalDefaultCb.setVisible(false);
        globalDefaultLabel.setVisible(false);
    }
    availableForAllCb.addValueChangeListener(e -> {
        Boolean isFilterAvailableForAll = e.getValue();
        globalDefaultCb.setEnabled(isFilterAvailableForAll);
        if (!isFilterAvailableForAll) {
            globalDefaultCb.setValue(null);
        }
    });
    Configuration configuration = AppBeans.get(Configuration.NAME);
    boolean manualApplyRequired = filter.getManualApplyRequired() != null ? filter.getManualApplyRequired() : configuration.getConfig(ClientConfig.class).getGenericFilterManualApplyRequired();
    if (!manualApplyRequired) {
        applyDefaultCb.setVisible(manualApplyRequired);
        applyDefaultLabel.setVisible(manualApplyRequired);
    }
    if (filterEntity.getFolder() != null) {
        availableForAllCb.setVisible(false);
        availableForAllLabel.setVisible(false);
        globalDefaultCb.setVisible(false);
        globalDefaultLabel.setVisible(false);
        defaultCb.setVisible(false);
        defaultLabel.setVisible(false);
    }
    conditionsDs.addItemChangeListener(e -> {
        if (!treeItemChangeListenerEnabled) {
            return;
        }
        // commit previously selected condition
        if (activeConditionFrame != null) {
            List<Validatable> validatables = new ArrayList<>();
            Collection<Component> frameComponents = ComponentsHelper.getComponents(activeConditionFrame);
            for (Component frameComponent : frameComponents) {
                if (frameComponent instanceof Validatable) {
                    validatables.add((Validatable) frameComponent);
                }
            }
            if (validate(validatables)) {
                activeConditionFrame.commit();
            } else {
                treeItemChangeListenerEnabled = false;
                conditionsTree.setSelected(e.getPrevItem());
                treeItemChangeListenerEnabled = true;
                return;
            }
        }
        if (e.getItem() == null) {
            activeConditionFrame = null;
        } else {
            if (e.getItem() instanceof PropertyCondition) {
                activeConditionFrame = propertyConditionFrame;
            } else if (e.getItem() instanceof DynamicAttributesCondition) {
                activeConditionFrame = dynamicAttributesConditionFrame;
            } else if (e.getItem() instanceof CustomCondition) {
                activeConditionFrame = customConditionFrame;
            } else if (e.getItem() instanceof GroupCondition) {
                activeConditionFrame = groupConditionFrame;
            } else if (e.getItem() instanceof FtsCondition) {
                activeConditionFrame = ftsConditionFrame;
            } else {
                log.warn("Conditions frame for condition with type " + e.getItem().getClass().getSimpleName() + " not found");
            }
        }
        propertyConditionFrame.setVisible(false);
        customConditionFrame.setVisible(false);
        dynamicAttributesConditionFrame.setVisible(false);
        groupConditionFrame.setVisible(false);
        ftsConditionFrame.setVisible(false);
        if (activeConditionFrame != null) {
            activeConditionFrame.setVisible(true);
            activeConditionFrame.setCondition(e.getItem());
            if (Boolean.TRUE.equals(useShortConditionForm)) {
                for (String componentName : componentsToHideInShortForm) {
                    Component component = activeConditionFrame.getComponent(componentName);
                    if (component != null) {
                        if (BooleanUtils.isTrue(showConditionHiddenOption) && componentsForHiddenOption.contains(componentName)) {
                            continue;
                        }
                        component.setVisible(false);
                    }
                }
            }
        }
    });
    addConditionHelper = new AddConditionHelper(filter, BooleanUtils.isTrue(hideDynamicAttributes), BooleanUtils.isTrue(hideCustomConditions), condition -> {
        AbstractCondition item = conditionsDs.getItem();
        if (item != null && item instanceof GroupCondition) {
            Node<AbstractCondition> newNode = new Node<>(condition);
            Node<AbstractCondition> selectedNode = conditions.getNode(item);
            selectedNode.addChild(newNode);
            refreshConditionsDs();
            conditionsTree.expand(item.getId());
        } else {
            conditions.getRootNodes().add(new Node<>(condition));
            refreshConditionsDs();
        }
        conditionsTree.setSelected(condition);
    });
    FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
    filterHelper.initConditionsDragAndDrop(conditionsTree, conditions);
    if (Boolean.TRUE.equals(useShortConditionForm)) {
        filterPropertiesGrid.setVisible(false);
    }
}
Also used : AddConditionHelper(com.haulmont.cuba.gui.components.filter.AddConditionHelper) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) Logger(org.slf4j.Logger) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) MetaProperty(com.haulmont.chile.core.model.MetaProperty) LoggerFactory(org.slf4j.LoggerFactory) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Collectors(java.util.stream.Collectors) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) GroupConditionDescriptor(com.haulmont.cuba.gui.components.filter.descriptor.GroupConditionDescriptor) GroupType(com.haulmont.cuba.gui.components.filter.GroupType) Inject(javax.inject.Inject) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper) com.haulmont.cuba.gui.components.filter.condition(com.haulmont.cuba.gui.components.filter.condition) WindowParam(com.haulmont.cuba.gui.WindowParam) Node(com.haulmont.bali.datastruct.Node) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) ClientConfig(com.haulmont.cuba.client.ClientConfig) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Entity(com.haulmont.cuba.core.entity.Entity) Node(com.haulmont.bali.datastruct.Node) AddConditionHelper(com.haulmont.cuba.gui.components.filter.AddConditionHelper) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper)

Example 3 with BooleanUtils.isTrue

use of org.apache.commons.lang3.BooleanUtils.isTrue in project syncope by apache.

the class UserDataBinderImpl method getUserTO.

@Transactional(readOnly = true)
@Override
public UserTO getUserTO(final User user, final boolean details) {
    UserTO userTO = new UserTO();
    BeanUtils.copyProperties(user, userTO, IGNORE_PROPERTIES);
    userTO.setSuspended(BooleanUtils.isTrue(user.isSuspended()));
    if (user.getSecurityQuestion() != null) {
        userTO.setSecurityQuestion(user.getSecurityQuestion().getKey());
    }
    Map<VirSchema, List<String>> virAttrValues = details ? virAttrHandler.getValues(user) : Collections.<VirSchema, List<String>>emptyMap();
    fillTO(userTO, user.getRealm().getFullPath(), user.getAuxClasses(), user.getPlainAttrs(), derAttrHandler.getValues(user), virAttrValues, userDAO.findAllResources(user), details);
    if (details) {
        // dynamic realms
        userTO.getDynRealms().addAll(userDAO.findDynRealms(user.getKey()));
        // roles
        userTO.getRoles().addAll(user.getRoles().stream().map(Entity::getKey).collect(Collectors.toList()));
        // dynamic roles
        userTO.getDynRoles().addAll(userDAO.findDynRoles(user.getKey()).stream().map(Entity::getKey).collect(Collectors.toList()));
        // privileges
        userTO.getPrivileges().addAll(userDAO.findAllRoles(user).stream().flatMap(role -> role.getPrivileges().stream()).map(Entity::getKey).collect(Collectors.toSet()));
        // relationships
        userTO.getRelationships().addAll(user.getRelationships().stream().map(relationship -> getRelationshipTO(relationship.getType().getKey(), relationship.getRightEnd())).collect(Collectors.toList()));
        // memberships
        userTO.getMemberships().addAll(user.getMemberships().stream().map(membership -> {
            return getMembershipTO(user.getPlainAttrs(membership), derAttrHandler.getValues(user, membership), virAttrHandler.getValues(user, membership), membership);
        }).collect(Collectors.toList()));
        // dynamic memberships
        userTO.getDynMemberships().addAll(userDAO.findDynGroups(user.getKey()).stream().map(group -> {
            return new MembershipTO.Builder().group(group.getKey(), group.getName()).build();
        }).collect(Collectors.toList()));
    }
    return userTO;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SecurityQuestionDAO(org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO) Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Entity(org.apache.syncope.core.persistence.api.entity.Entity) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) UserDataBinder(org.apache.syncope.core.provisioning.api.data.UserDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Role(org.apache.syncope.core.persistence.api.entity.Role) Collection(java.util.Collection) Resource(javax.annotation.Resource) Set(java.util.Set) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Group(org.apache.syncope.core.persistence.api.entity.group.Group) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) BeanUtils(org.apache.syncope.core.spring.BeanUtils) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) HashSet(java.util.HashSet) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) Encryptor(org.apache.syncope.core.spring.security.Encryptor) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) AccessTokenDAO(org.apache.syncope.core.persistence.api.dao.AccessTokenDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) Transactional(org.springframework.transaction.annotation.Transactional) Entity(org.apache.syncope.core.persistence.api.entity.Entity) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) UserTO(org.apache.syncope.common.lib.to.UserTO) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with BooleanUtils.isTrue

use of org.apache.commons.lang3.BooleanUtils.isTrue in project cuba by cuba-platform.

the class ScheduledTaskBrowser method init.

@Override
public void init(Map<String, Object> params) {
    tasksTable.addAction(CreateAction.create(tasksTable));
    tasksTable.addAction(EditAction.create(tasksTable));
    tasksTable.addAction(RemoveAction.create(tasksTable));
    Action editAction = tasksTable.getActionNN(EditAction.ACTION_ID);
    editAction.setEnabled(false);
    Action removeAction = tasksTable.getActionNN(RemoveAction.ACTION_ID);
    removeAction.setEnabled(false);
    activateBtn.setAction(new BaseAction("activate").withCaption(getMessage("activate")).withHandler(e -> {
        Set<ScheduledTask> tasks = tasksTable.getSelected();
        service.setActive(tasks, !BooleanUtils.isTrue(tasks.iterator().next().getActive()));
        tasksDs.refresh();
    }));
    activateBtn.setEnabled(false);
    ShowExecutionsAction showExecutionsAction = new ShowExecutionsAction();
    tasksTable.addAction(showExecutionsAction);
    ExecuteOnceAction executeOnceAction = new ExecuteOnceAction();
    tasksTable.addAction(executeOnceAction);
    tasksDs.addItemChangeListener(e -> {
        ScheduledTask singleSelected = tasksTable.getSingleSelected();
        Set<ScheduledTask> selected = tasksTable.getSelected().stream().filter(Objects::nonNull).collect(Collectors.toSet());
        boolean isSingleSelected = selected.size() == 1;
        boolean enableEdit = singleSelected != null && !BooleanUtils.isTrue(singleSelected.getActive());
        editAction.setEnabled(enableEdit);
        removeAction.setEnabled(checkAllTasksAreNotActive(selected));
        activateBtn.setEnabled(checkAllTasksHaveSameStatus(selected));
        if (singleSelected == null) {
            activateBtn.setCaption(getMessage("activate"));
        } else {
            activateBtn.setCaption(BooleanUtils.isTrue(singleSelected.getActive()) ? getMessage("deactivate") : getMessage("activate"));
        }
        showExecutionsAction.setEnabled(isSingleSelected);
        executeOnceAction.setEnabled(isSingleSelected && enableEdit);
    });
}
Also used : ScheduledTask(com.haulmont.cuba.core.entity.ScheduledTask) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) BooleanUtils(org.apache.commons.lang3.BooleanUtils) HashMap(java.util.HashMap) Subscribe(com.haulmont.cuba.gui.screen.Subscribe) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Objects(java.util.Objects) Screens(com.haulmont.cuba.gui.Screens) Map(java.util.Map) RunTaskOnceException(com.haulmont.cuba.core.global.RunTaskOnceException) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) com.haulmont.cuba.gui.components.actions(com.haulmont.cuba.gui.components.actions) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) SchedulingService(com.haulmont.cuba.core.app.SchedulingService) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Set(java.util.Set) ScheduledTask(com.haulmont.cuba.core.entity.ScheduledTask)

Example 5 with BooleanUtils.isTrue

use of org.apache.commons.lang3.BooleanUtils.isTrue in project cuba by cuba-platform.

the class DynamicAttributesManager method loadAttributeValues.

protected List<CategoryAttributeValue> loadAttributeValues(MetaClass metaClass, List<Object> entityIds) {
    List<CategoryAttributeValue> attributeValues = new ArrayList<>();
    try (Transaction tx = persistence.getTransaction()) {
        EntityManager em = persistence.getEntityManager();
        View view = new View(viewRepository.getView(CategoryAttributeValue.class, View.LOCAL), null, false).addProperty("categoryAttribute", new View(viewRepository.getView(CategoryAttribute.class, View.LOCAL), null, false).addProperty("category").addProperty("defaultEntity", viewRepository.getView(ReferenceToEntity.class, View.LOCAL)));
        TypedQuery<CategoryAttributeValue> query;
        if (HasUuid.class.isAssignableFrom(metaClass.getJavaClass())) {
            query = em.createQuery(format("select cav from sys$CategoryAttributeValue cav where cav.entity.%s in :ids and cav.parent is null", referenceToEntitySupport.getReferenceIdPropertyName(metaClass)), CategoryAttributeValue.class);
        } else {
            query = em.createQuery(format("select cav from sys$CategoryAttributeValue cav where cav.entity.%s in :ids " + "and cav.categoryAttribute.categoryEntityType = :entityType and cav.parent is null", referenceToEntitySupport.getReferenceIdPropertyName(metaClass)), CategoryAttributeValue.class);
            query.setParameter("entityType", metaClass.getName());
        }
        query.setParameter("ids", entityIds);
        query.setView(view);
        List<CategoryAttributeValue> resultList = query.getResultList();
        List<CategoryAttributeValue> cavsOfEntityType = resultList.stream().filter(cav -> cav.getObjectEntityValueId() != null).collect(Collectors.toList());
        List<CategoryAttributeValue> cavsOfCollectionType = resultList.stream().filter(cav -> BooleanUtils.isTrue(cav.getCategoryAttribute().getIsCollection())).collect(Collectors.toList());
        if (cavsOfCollectionType.isEmpty()) {
            loadEntityValues(cavsOfEntityType);
            attributeValues.addAll(resultList);
        } else {
            List<CategoryAttributeValue> cavsOfCollectionTypeWithChildren = reloadCategoryAttributeValuesWithChildren(cavsOfCollectionType);
            // add nested collection values to the cavsOfEntityType collection, because this collection will later be
            // used for loading entity values
            cavsOfCollectionTypeWithChildren.stream().filter(cav -> cav.getCategoryAttribute().getDataType() == PropertyType.ENTITY && cav.getChildValues() != null).forEach(cav -> cavsOfEntityType.addAll(cav.getChildValues()));
            loadEntityValues(cavsOfEntityType);
            cavsOfCollectionTypeWithChildren.stream().filter(cav -> cav.getChildValues() != null).forEach(cav -> {
                List<Object> value = cav.getChildValues().stream().filter(c -> c.getDeleteTs() == null).map(CategoryAttributeValue::getValue).collect(Collectors.toList());
                cav.setTransientCollectionValue(value);
            });
            attributeValues.addAll(resultList.stream().filter(cav -> !cavsOfCollectionTypeWithChildren.contains(cav)).collect(Collectors.toList()));
            attributeValues.addAll(cavsOfCollectionTypeWithChildren);
        }
        tx.commit();
    }
    attributeValues = attributeValues.stream().filter(attr -> attr.getDeleteTs() == null).collect(Collectors.toList());
    return attributeValues;
}
Also used : java.util(java.util) ClusterListenerAdapter(com.haulmont.cuba.core.app.ClusterListenerAdapter) Persistence(com.haulmont.cuba.core.Persistence) LoggerFactory(org.slf4j.LoggerFactory) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Multimap(com.google.common.collect.Multimap) MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionUtils(org.apache.commons.collections4.CollectionUtils) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) TypedQuery(com.haulmont.cuba.core.TypedQuery) HashMultimap(com.google.common.collect.HashMultimap) com.haulmont.cuba.core.entity(com.haulmont.cuba.core.entity) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) EntityManager(com.haulmont.cuba.core.EntityManager) ReentrantLock(java.util.concurrent.locks.ReentrantLock) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Serializable(java.io.Serializable) ClusterManagerAPI(com.haulmont.cuba.core.app.ClusterManagerAPI) Component(org.springframework.stereotype.Component) EntityOp(com.haulmont.cuba.security.entity.EntityOp) Transaction(com.haulmont.cuba.core.Transaction) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction)

Aggregations

Collectors (java.util.stream.Collectors)5 BooleanUtils (org.apache.commons.lang3.BooleanUtils)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 Inject (javax.inject.Inject)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 java.util (java.util)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 Node (com.haulmont.bali.datastruct.Node)1