Example usage for org.apache.commons.lang BooleanUtils isTrue

List of usage examples for org.apache.commons.lang BooleanUtils isTrue

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils isTrue.

Prototype

public static boolean isTrue(Boolean bool) 

Source Link

Document

Checks if a Boolean value is true, handling null by returning false.

 BooleanUtils.isTrue(Boolean.TRUE)  = true BooleanUtils.isTrue(Boolean.FALSE) = false BooleanUtils.isTrue(null)          = false 

Usage

From source file:com.evolveum.midpoint.security.enforcer.impl.SecurityEnforcerImpl.java

private <O extends ObjectType> boolean matchesRoleRelation(PrismObject<O> object,
        ObjectReferenceType subjectRoleMembershipRef, RoleRelationObjectSpecificationType specRoleRelation,
        String autzHumanReadableDesc, String desc) throws SchemaException {
    if (!MiscSchemaUtil.compareRelation(specRoleRelation.getSubjectRelation(),
            subjectRoleMembershipRef.getRelation())) {
        return false;
    }//w  w w .ja  v a2  s . c om
    if (BooleanUtils.isTrue(specRoleRelation.isIncludeReferenceRole())
            && subjectRoleMembershipRef.getOid().equals(object.getOid())) {
        return true;
    }
    if (!BooleanUtils.isFalse(specRoleRelation.isIncludeMembers())) {
        if (!object.canRepresent(FocusType.class)) {
            return false;
        }
        for (ObjectReferenceType objectRoleMembershipRef : ((FocusType) object.asObjectable())
                .getRoleMembershipRef()) {
            if (!subjectRoleMembershipRef.getOid().equals(objectRoleMembershipRef.getOid())) {
                continue;
            }
            if (!MiscSchemaUtil.compareRelation(specRoleRelation.getObjectRelation(),
                    objectRoleMembershipRef.getRelation())) {
                continue;
            }
            return true;
        }
    }
    return false;
}

From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java

protected String getFilterCaption(FilterEntity filterEntity) {
    String name;/*from   ww w  .  j a v a 2s.  c  o  m*/
    if (filterEntity != null) {
        if (filterEntity.getCode() == null)
            name = InstanceUtils.getInstanceName(filterEntity);
        else {
            name = messages.getMainMessage(filterEntity.getCode());
        }
        AbstractSearchFolder folder = filterEntity.getFolder();
        if (folder != null) {
            if (!StringUtils.isBlank(folder.getTabName()))
                name = messages.getMainMessage(folder.getTabName());
            else if (!StringUtils.isBlank(folder.getName())) {
                name = messages.getMainMessage(folder.getName());
            }
            if (BooleanUtils.isTrue(filterEntity.getIsSet()))
                name = getMainMessage("filter.setPrefix") + " " + name;
            else
                name = getMainMessage("filter.folderPrefix") + " " + name;
        }
    } else
        name = "";
    return name;
}

From source file:com.evolveum.midpoint.provisioning.impl.ShadowManager.java

private PendingOperationType checkAndRecordPendingOperationBeforeExecution(ProvisioningContext ctx,
        PrismObject<ShadowType> repoShadow, ObjectDelta<ShadowType> proposedDelta, Task task,
        OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException,
        ConfigurationException, ExpressionEvaluationException {
    ResourceType resource = ctx.getResource();
    ResourceConsistencyType consistencyType = resource.getConsistency();
    if (consistencyType == null) {
        return null;
    }/*from  w w  w. ja  va 2 s.  c o m*/

    OptimisticLockingRunner<ShadowType, PendingOperationType> runner = new OptimisticLockingRunner.Builder<ShadowType, PendingOperationType>()
            .object(repoShadow).result(parentResult).repositoryService(repositoryService)
            .maxNumberOfAttempts(10).delayRange(20).build();

    try {

        return runner.run((object) -> {
            Boolean avoidDuplicateOperations = consistencyType.isAvoidDuplicateOperations();
            if (BooleanUtils.isTrue(avoidDuplicateOperations)) {
                PendingOperationType existingPendingOperation = findExistingPendingOperation(object,
                        proposedDelta, true);
                if (existingPendingOperation != null) {
                    LOGGER.debug("Found duplicate operation for {} of {}: {}", proposedDelta.getChangeType(),
                            object, existingPendingOperation);
                    return existingPendingOperation;
                }
            }

            if (ResourceTypeUtil.getRecordPendingOperations(resource) != RecordPendingOperationsType.ALL) {
                return null;
            }

            LOGGER.trace("Storing pending operation for {} of {}", proposedDelta.getChangeType(), object);
            addPendingOperationDelta(ctx, object, proposedDelta, null, object.getVersion(), parentResult);
            LOGGER.trace("Stored pending operation for {} of {}", proposedDelta.getChangeType(), object);

            // Yes, really return null. We are supposed to return conflicting operation (if found).
            // But in this case there is no conflict. This operation does not conflict with itself.
            return null;
        });

    } catch (ObjectAlreadyExistsException e) {
        // should not happen
        throw new SystemException(e);
    }

}

From source file:com.evolveum.midpoint.model.impl.controller.ModelInteractionServiceImpl.java

private <O extends ObjectType> void collectDeltasForGeneratedValuesIfNeeded(PrismObject<O> object,
        PolicyItemDefinitionType policyItemDefinition, Collection<PropertyDelta<?>> deltasToExecute,
        ItemPath path, PrismPropertyDefinition<?> itemDef, OperationResult result) throws SchemaException {

    Object value = policyItemDefinition.getValue();

    if (itemDef != null) {
        if (ProtectedStringType.COMPLEX_TYPE.equals(itemDef.getTypeName())) {
            ProtectedStringType pst = new ProtectedStringType();
            pst.setClearValue((String) value);
            value = pst;/*from  w ww  .j a v a2  s . co m*/
        } else if (PolyStringType.COMPLEX_TYPE.equals(itemDef.getTypeName())) {
            value = new PolyString((String) value);
        }
    }
    if (object == null && isExecute(policyItemDefinition)) {
        LOGGER.warn(
                "Cannot apply generated changes and cannot execute them becasue there is no target object specified.");
        result.recordFatalError(
                "Cannot apply generated changes and cannot execute them becasue there is no target object specified.");
        return;
    }
    if (object != null) {
        PropertyDelta<?> propertyDelta = PropertyDelta.createModificationReplaceProperty(path,
                object.getDefinition(), value);
        propertyDelta.applyTo(object); // in bulk actions we need to modify original objects - hope that REST is OK with this
        if (BooleanUtils.isTrue(policyItemDefinition.isExecute())) {
            deltasToExecute.add(propertyDelta);
        }
    }

}

From source file:jp.primecloud.auto.service.impl.InstanceServiceImpl.java

protected Long createInstance(Long farmNo, String instanceName, Long platformNo, String comment, Long imageNo) {
    // ?/*from w  ww .  j  av a2s .c o  m*/
    if (farmNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "farmNo");
    }
    if (instanceName == null || instanceName.length() == 0) {
        throw new AutoApplicationException("ECOMMON-000003", "instanceName");
    }
    if (platformNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "platformNo");
    }
    if (imageNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "imageNo");
    }

    // ??
    if (!Pattern.matches("^[0-9a-z]|[0-9a-z][0-9a-z-]*[0-9a-z]$", instanceName)) {
        throw new AutoApplicationException("ECOMMON-000012", "instanceName");
    }

    // ???
    Image image = imageDao.read(imageNo);
    Platform platform = platformDao.read(platformNo);
    if (platformNo.equals(image.getPlatformNo()) == false) {
        throw new AutoApplicationException("ESERVICE-000405", imageNo, platform.getPlatformName());
    }

    // TODO: ??

    // ?????
    Instance checkInstance = instanceDao.readByFarmNoAndInstanceName(farmNo, instanceName);
    if (checkInstance != null) {
        // ???????
        throw new AutoApplicationException("ESERVICE-000401", instanceName);
    }

    // ?????
    LoadBalancer checkLoadBalancer = loadBalancerDao.readByFarmNoAndLoadBalancerName(farmNo, instanceName);
    if (checkLoadBalancer != null) {
        // ????????
        throw new AutoApplicationException("ESERVICE-000417", instanceName);
    }

    // ??
    Farm farm = farmDao.read(farmNo);
    if (farm == null) {
        throw new AutoApplicationException("ESERVICE-000406", farmNo);
    }

    // fqdn???
    String fqdn = instanceName + "." + farm.getDomainName();
    if (fqdn.length() > 63) {
        throw new AutoApplicationException("ESERVICE-000418", fqdn);
    }

    // TODO: ??

    // VMware??Windows???VMware??????Windows????????
    // TODO: OS??
    if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())
            && StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)) {
        List<Instance> allInstances = instanceDao.readAll();
        for (Instance instance2 : allInstances) {
            if (StringUtils.equals(instanceName, instance2.getInstanceName())) {
                Platform platform2 = platformDao.read(instance2.getPlatformNo());
                if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform2.getPlatformType())) {
                    Image image2 = imageDao.read(instance2.getImageNo());
                    if (StringUtils.startsWithIgnoreCase(image2.getOs(), PCCConstant.OS_NAME_WIN)) {
                        // VMware?????Windows???
                        throw new AutoApplicationException("ESERVICE-000419", instanceName);
                    }
                }
            }
        }
    }

    // ??
    String instanceCode = passwordGenerator.generate(20);

    // ??
    Instance instance = new Instance();
    instance.setFarmNo(farmNo);
    instance.setInstanceName(instanceName);
    instance.setPlatformNo(platformNo);
    instance.setImageNo(imageNo);
    instance.setEnabled(false);
    instance.setComment(comment);
    instance.setFqdn(fqdn);
    instance.setInstanceCode(instanceCode);
    instance.setStatus(InstanceStatus.STOPPED.toString());
    instanceDao.create(instance);

    // TODO: OS??
    if (!StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)
            || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)
                    && PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType()))
            || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)
                    && PCCConstant.PLATFORM_TYPE_AZURE.equals(platform.getPlatformType()))
            || (StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)
                    && PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType()))) {
        // OpenStack?Puppet?????
        //if (!PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType())) {
        // Puppet??
        PuppetInstance puppetInstance = new PuppetInstance();
        puppetInstance.setInstanceNo(instance.getInstanceNo());
        puppetInstanceDao.create(puppetInstance);
        //}
    }

    Boolean useZabbix = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useZabbix"));
    if (BooleanUtils.isTrue(useZabbix)) {
        // Zabbix??
        ZabbixInstance zabbixInstance = new ZabbixInstance();
        zabbixInstance.setInstanceNo(instance.getInstanceNo());
        zabbixInstanceDao.create(zabbixInstance);
    }

    return instance.getInstanceNo();
}

From source file:com.evolveum.midpoint.model.impl.lens.LensUtil.java

private static <F extends ObjectType> void checkObjectPolicy(LensFocusContext<F> focusContext,
        ObjectPolicyConfigurationType objectPolicyConfigurationType)
        throws SchemaException, PolicyViolationException {
    if (objectPolicyConfigurationType == null) {
        return;/*ww w  .j  a v a  2 s.c om*/
    }
    PrismObject<F> focusObjectNew = focusContext.getObjectNew();
    ObjectDelta<F> focusDelta = focusContext.getDelta();

    for (PropertyConstraintType propertyConstraintType : objectPolicyConfigurationType
            .getPropertyConstraint()) {
        ItemPath itemPath = propertyConstraintType.getPath().getItemPath();
        if (BooleanUtils.isTrue(propertyConstraintType.isOidBound())) {
            if (focusDelta != null) {
                if (focusDelta.isAdd()) {
                    PrismProperty<Object> propNew = focusObjectNew.findProperty(itemPath);
                    if (propNew != null) {
                        // prop delta is OK, but it has to match
                        if (focusObjectNew.getOid() != null) {
                            if (!focusObjectNew.getOid().equals(propNew.getRealValue().toString())) {
                                throw new PolicyViolationException("Cannot set " + itemPath
                                        + " to a value different than OID in oid bound mode");
                            }
                        }
                    }
                } else {
                    PropertyDelta<Object> nameDelta = focusDelta.findPropertyDelta(itemPath);
                    if (nameDelta != null) {
                        if (nameDelta.isReplace()) {
                            Collection<PrismPropertyValue<Object>> valuesToReplace = nameDelta
                                    .getValuesToReplace();
                            if (valuesToReplace.size() == 1) {
                                String stringValue = valuesToReplace.iterator().next().getValue().toString();
                                if (focusContext.getOid().equals(stringValue)) {
                                    // This is OK. It is most likely a correction made by a recompute.
                                    continue;
                                }
                            }
                        }
                        throw new PolicyViolationException("Cannot change " + itemPath + " in oid bound mode");
                    }
                }
            }
        }
    }

    // Deprecated
    if (BooleanUtils.isTrue(objectPolicyConfigurationType.isOidNameBoundMode())) {
        if (focusDelta != null) {
            if (focusDelta.isAdd()) {
                PolyStringType namePolyType = focusObjectNew.asObjectable().getName();
                if (namePolyType != null) {
                    // name delta is OK, but it has to match
                    if (focusObjectNew.getOid() != null) {
                        if (!focusObjectNew.getOid().equals(namePolyType.getOrig())) {
                            throw new PolicyViolationException(
                                    "Cannot set name to a value different than OID in name-oid bound mode");
                        }
                    }
                }
            } else {
                PropertyDelta<Object> nameDelta = focusDelta.findPropertyDelta(FocusType.F_NAME);
                if (nameDelta != null) {
                    throw new PolicyViolationException("Cannot change name in name-oid bound mode");
                }
            }
        }
    }
}

From source file:com.evolveum.midpoint.model.impl.lens.AssignmentEvaluator.java

private boolean isAllowedByLimitations(AssignmentPathSegment segment, AssignmentType nextAssignment,
        EvaluationContext ctx) {//from  w  ww .  j  ava 2  s.c o  m
    AssignmentType currentAssignment = segment.getAssignment(ctx.evaluateOld);
    AssignmentSelectorType targetLimitation = currentAssignment.getLimitTargetContent();
    if (isDeputyDelegation(nextAssignment)) { // delegation of delegation
        if (targetLimitation == null) {
            return false;
        }
        return BooleanUtils.isTrue(targetLimitation.isAllowTransitive());
    } else {
        // As for the case of targetRef==null: we want to pass target-less assignments (focus mappings, policy rules etc)
        // from the delegator to delegatee. To block them we should use order constraints (but also for assignments?).
        return targetLimitation == null || nextAssignment.getTargetRef() == null
                || FocusTypeUtil.selectorMatches(targetLimitation, nextAssignment);
    }
}

From source file:jp.primecloud.auto.service.impl.ComponentServiceImpl.java

protected ComponentInstanceStatus getComponentInstanceStatus(Farm farm, ComponentInstance componentInstance,
        Instance instance) {//from   w  ww . ja  v  a  2s .c o  m
    // ????????
    ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
    if (BooleanUtils.isTrue(componentInstance.getEnabled())) {
        if (status == ComponentInstanceStatus.STOPPED) {
            InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
            if (instanceStatus == InstanceStatus.WARNING) {
                // ?Waring??????Warning??
                return ComponentInstanceStatus.WARNING;
            } else if (BooleanUtils.isTrue(farm.getScheduled())) {
                // ??????Starting??
                return ComponentInstanceStatus.STARTING;
            }
        } else if (status == ComponentInstanceStatus.RUNNING
                && BooleanUtils.isTrue(componentInstance.getConfigure())) {
            if (BooleanUtils.isTrue(farm.getScheduled())) {
                // ???Running??????Configuring??
                return ComponentInstanceStatus.CONFIGURING;
            }
        }
    } else {
        if (status == ComponentInstanceStatus.RUNNING || status == ComponentInstanceStatus.WARNING) {
            if (BooleanUtils.isTrue(farm.getScheduled())) {
                // ??????Stopping??
                return ComponentInstanceStatus.STOPPING;
            }
        }
    }
    return status;
}

From source file:com.evolveum.midpoint.testing.rest.TestAbstractRestService.java

@Test
public void test610ModifyPasswordForceChange() throws Exception {
    final String TEST_NAME = "test610ModifyPasswordForceChange";
    displayTestTitle(this, TEST_NAME);

    WebClient client = prepareClient();/*w w w  .  ja  va 2  s  .c o  m*/
    client.path("/users/" + USER_DARTHADDER_OID);

    getDummyAuditService().clear();

    TestUtil.displayWhen(TEST_NAME);
    Response response = client.post(getRequestFile(MODIFICATION_FORCE_PASSWORD_CHANGE));

    TestUtil.displayThen(TEST_NAME);
    displayResponse(response);
    traceResponse(response);

    assertEquals("Expected 204 but got " + response.getStatus(), 204, response.getStatus());

    display("Audit", getDummyAuditService());
    getDummyAuditService().assertRecords(4);
    getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
    getDummyAuditService().assertHasDelta(1, ChangeType.MODIFY, UserType.class);

    TestUtil.displayWhen(TEST_NAME);
    response = client.get();

    TestUtil.displayThen(TEST_NAME);
    displayResponse(response);

    assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus());
    UserType userDarthadder = response.readEntity(UserType.class);
    CredentialsType credentials = userDarthadder.getCredentials();
    assertNotNull("No credentials in user. Something is wrong.", credentials);
    PasswordType passwordType = credentials.getPassword();
    assertNotNull("No password defined for user. Something is wrong.", passwordType);
    assertNotNull("No value for password defined for user. Something is wrong.", passwordType.getValue());
    assertTrue(BooleanUtils.isTrue(passwordType.isForceChange()));
}

From source file:jp.primecloud.auto.service.impl.ComponentServiceImpl.java

/**
 * {@inheritDoc}//from   w  ww. j av a  2 s  .  c  o m
 */
@Override
public Collection<Object> checkAttachDisk(Long farmNo, Long componentNo, String instanceName,
        String notSelectedItem, Collection<Object> moveList) {

    List<InstanceDto> instances = instanceService.getInstances(farmNo);
    for (InstanceDto instance : instances) {
        if (StringUtils.equals(instanceName, instance.getInstance().getInstanceName())) {
            //TODO CLOUD BRANCHING
            if (instance.getAwsVolumes() != null) {
                // AwsVolume?
                for (AwsVolume awsVolume : instance.getAwsVolumes()) {
                    if (componentNo.equals(awsVolume.getComponentNo())) {
                        if (StringUtils.isNotEmpty(awsVolume.getInstanceId())) {
                            // ????????
                            moveList.add(notSelectedItem);
                        }
                        break;
                    }
                }
            } else if (instance.getVmwareDisks() != null) {
                // VmwareDisk?
                for (VmwareDisk vmwareDisk : instance.getVmwareDisks()) {
                    if (componentNo.equals(vmwareDisk.getComponentNo())) {
                        if (BooleanUtils.isTrue(vmwareDisk.getAttached())) {
                            // ????????
                            moveList.add(notSelectedItem);
                        }
                        break;
                    }
                }
            } else if (instance.getCloudstackVolumes() != null) {
                // CloudstackVolume?
                for (CloudstackVolume cloudstackVolume : instance.getCloudstackVolumes()) {
                    if (componentNo.equals(cloudstackVolume.getComponentNo())) {
                        if (StringUtils.isNotEmpty(cloudstackVolume.getInstanceId())) {
                            // ????????
                            moveList.add(notSelectedItem);
                        }
                        break;
                    }
                }
            } else if (instance.getVcloudDisks() != null) {
                // VcloudDisk?
                for (VcloudDisk vcloudDisk : instance.getVcloudDisks()) {
                    if (componentNo.equals(vcloudDisk.getComponentNo())) {
                        if (BooleanUtils.isTrue(vcloudDisk.getAttached())) {
                            if (InstanceStatus
                                    .fromStatus(instance.getInstance().getStatus()) != InstanceStatus.STOPPED) {
                                // ????????
                                moveList.add(notSelectedItem);
                            }
                        }
                        break;
                    }
                }
            } else if (instance.getAzureDisks() != null) {
                // AzureDisk?
                for (AzureDisk azureDisk : instance.getAzureDisks()) {
                    if (componentNo.equals(azureDisk.getComponentNo())) {
                        if (StringUtils.isNotEmpty(azureDisk.getInstanceName())) {
                            if (InstanceStatus
                                    .fromStatus(instance.getInstance().getStatus()) != InstanceStatus.STOPPED) {
                                // ????????
                                moveList.add(notSelectedItem);
                            }
                        }
                        break;
                    }
                }
            } else if (instance.getNiftyVolumes() != null) {
                // NiftyVolume?
                for (NiftyVolume niftyVolume : instance.getNiftyVolumes()) {
                    if (componentNo.equals(niftyVolume.getComponentNo())) {
                        if (StringUtils.isNotEmpty(niftyVolume.getInstanceId())) {
                            // ????????
                            moveList.add(notSelectedItem);
                        }
                        break;
                    }
                }
            } else if (instance.getOpenstackVolumes() != null) {
                // OpenstackVolume?
                for (OpenstackVolume openstackVolume : instance.getOpenstackVolumes()) {
                    if (componentNo.equals(openstackVolume.getComponentNo())) {
                        if (StringUtils.isNotEmpty(openstackVolume.getInstanceId())) {
                            // ????????
                            moveList.add(notSelectedItem);
                        }
                        break;
                    }
                }
            }
        }
    }

    return moveList;
}