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