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

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

Introduction

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

Prototype

public static boolean toBoolean(String str) 

Source Link

Document

Converts a String to a boolean (optimised for performance).

'true', 'on' or 'yes' (case insensitive) will return true.

Usage

From source file:org.openmrs.module.clinicalsummary.task.DateCreatedReminderProcessor.java

public void processReminder() {
    // location is clustered, clusters are separated by comma
    String clusterNames = Context.getAdministrationService()
            .getGlobalProperty(TaskParameters.LOCATION_GROUP_LIST);
    if (clusterNames != null) {
        String[] clusterName = StringUtils.split(clusterNames, TaskParameters.CLUSTER_SEPARATOR);
        String processorCounter = Context.getAdministrationService()
                .getGlobalProperty(TaskParameters.PROCESSOR_COUNTER);
        // start with the first cluster (offset = 0) when the counter is not a number
        Integer clusterOffset = NumberUtils.toInt(processorCounter, 0);
        if (clusterOffset >= 0 && clusterOffset < ArrayUtils.getLength(clusterName)) {
            String initProperty = Context.getAdministrationService()
                    .getGlobalProperty(TaskParameters.PROCESSOR_INITIALIZED);
            String currentCluster = clusterName[clusterOffset];
            // check whether all cluster have been initialized or not
            Boolean initialized = BooleanUtils.toBoolean(initProperty);

            Cohort cohort;/*from   w  w  w  .j  a v a 2  s  .co  m*/
            String[] locationIds = StringUtils.split(currentCluster);
            for (int i = 0; i < ArrayUtils.getLength(locationIds); i++) {
                log.info("Processing location with id: " + locationIds[i]);
                // default return to -1 because no such location with id -1
                Location location = Context.getLocationService()
                        .getLocation(NumberUtils.toInt(locationIds[i], -1));
                if (!initialized) {
                    cohort = Context.getService(CoreService.class).getDateCreatedCohort(location, null, null);
                } else {
                    // regenerate when there's new obs
                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.DATE, -(clusterName.length + 1));
                    Date date = calendar.getTime();
                    cohort = Context.getService(CoreService.class).getDateCreatedCohort(location, date,
                            new Date());
                }

                evaluate(cohort);
            }
        }
    }
}

From source file:org.openmrs.module.clinicalsummary.task.OrderedObsProcessor.java

public void processObservations() {
    // location is clustered, clusters are separated by comma
    String clusterNames = Context.getAdministrationService()
            .getGlobalProperty(TaskParameters.LOCATION_GROUP_LIST);
    if (clusterNames != null) {
        String[] clusterName = StringUtils.split(clusterNames, TaskParameters.CLUSTER_SEPARATOR);
        String processorCounter = Context.getAdministrationService()
                .getGlobalProperty(TaskParameters.PROCESSOR_COUNTER);
        // start with the first cluster (offset = 0) when the counter is not a number
        Integer clusterOffset = NumberUtils.toInt(processorCounter, 0);
        if (clusterOffset >= 0 && clusterOffset < ArrayUtils.getLength(clusterName)) {
            String initProperty = Context.getAdministrationService()
                    .getGlobalProperty(TaskParameters.PROCESSOR_INITIALIZED);
            String currentCluster = clusterName[clusterOffset];
            // check whether all cluster have been initialized or not
            Boolean initialized = BooleanUtils.toBoolean(initProperty);

            Cohort cohort;/*from  w  ww.j  av  a 2 s.  c  om*/
            String[] locationIds = StringUtils.split(currentCluster);
            for (int i = 0; i < ArrayUtils.getLength(locationIds); i++) {
                log.info("Processing location with id: " + locationIds[i]);
                // default return to -1 because no such location with id -1
                Location location = Context.getLocationService()
                        .getLocation(NumberUtils.toInt(locationIds[i], -1));
                if (!initialized) {
                    cohort = Context.getService(CoreService.class).getDateCreatedCohort(location, null, null);
                } else {
                    // regenerate when there's new obs
                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.DATE, -(clusterName.length + 1));
                    Date date = calendar.getTime();

                    cohort = Context.getService(CoreService.class).getDateCreatedCohort(location, date,
                            new Date());
                }

                // this processing is similar with the flow-sheet processing but we also include the duplicate processing here
                CoreService coreService = Context.getService(CoreService.class);

                for (Map<String, List<String>> parameter : parameters) {
                    // process each parameter
                    List<String> conceptNames = parameter.get(EvaluableConstants.OBS_CONCEPT);
                    List<String> valueCodedNames = parameter.get(EvaluableConstants.OBS_VALUE_CODED);
                    if (CollectionUtils.isNotEmpty(conceptNames)
                            && CollectionUtils.isNotEmpty(valueCodedNames)) {

                        // prepare the concept restriction
                        Collection<OpenmrsObject> concepts = new ArrayList<OpenmrsObject>();
                        for (String conceptName : conceptNames) {
                            Concept concept = CacheUtils.getConcept(conceptName);
                            if (concept != null)
                                concepts.add(concept);
                        }

                        // test ordered concept
                        Concept testOrderedConcept = CacheUtils.getConcept(TaskParameters.TESTS_ORDERED);
                        Collection<OpenmrsObject> testedConcepts = new ArrayList<OpenmrsObject>();
                        testedConcepts.add(testOrderedConcept);

                        // prepare the value coded restriction
                        Collection<OpenmrsObject> valueCodeds = new ArrayList<OpenmrsObject>();
                        for (String valueCodedName : valueCodedNames) {
                            Concept concept = CacheUtils.getConcept(valueCodedName);
                            if (concept != null)
                                valueCodeds.add(concept);
                        }

                        Map<String, Collection<OpenmrsObject>> restrictions = new HashMap<String, Collection<OpenmrsObject>>();
                        for (Integer patientId : cohort.getMemberIds()) {
                            // search for the results
                            restrictions.put(EvaluableConstants.OBS_CONCEPT, concepts);
                            List<Obs> testResultObservations = coreService.getPatientObservations(patientId,
                                    restrictions, new FetchRestriction());
                            // remove and then save the duplicates
                            testResultObservations = stripDuplicate(testResultObservations);

                            // search for the tests
                            restrictions.put(EvaluableConstants.OBS_CONCEPT, testedConcepts);
                            restrictions.put(EvaluableConstants.OBS_VALUE_CODED, valueCodeds);
                            List<Obs> testOrderedObservations = coreService.getPatientObservations(patientId,
                                    restrictions, new FetchRestriction());
                            // remove and then save the duplicates
                            testOrderedObservations = stripDuplicate(testOrderedObservations);

                            // try to pair the obs and then save the un-pair-able obs
                            pair(testOrderedObservations, testResultObservations);
                        }
                    }
                }
            }
        }
    }
}

From source file:org.openmrs.module.clinicalsummary.task.ReturnDateEvaluatorProcessor.java

public void processSummary() {
    // remove the concept cache every night
    CacheUtils.clearConceptCache();//from   ww  w  .ja  v a 2 s. co  m
    CacheUtils.clearEncounterTypeCache();
    // location is clustered, clusters are separated by comma
    String clusterNames = Context.getAdministrationService()
            .getGlobalProperty(TaskParameters.LOCATION_GROUP_LIST);
    if (clusterNames != null) {
        String[] clusterName = StringUtils.split(clusterNames, TaskParameters.CLUSTER_SEPARATOR);
        String processorCounter = Context.getAdministrationService()
                .getGlobalProperty(TaskParameters.PROCESSOR_COUNTER);
        // start with the first cluster (offset = 0) when the counter is not a number
        Integer clusterOffset = NumberUtils.toInt(processorCounter, 0);
        if (clusterOffset >= 0 && clusterOffset < ArrayUtils.getLength(clusterName)) {
            String initProperty = Context.getAdministrationService()
                    .getGlobalProperty(TaskParameters.PROCESSOR_INITIALIZED);
            String currentCluster = clusterName[clusterOffset];
            // check whether all cluster have been initialized or not
            Boolean initialized = BooleanUtils.toBoolean(initProperty);

            Cohort cohort;
            String[] locationIds = StringUtils.split(currentCluster);
            for (int i = 0; i < ArrayUtils.getLength(locationIds); i++) {
                log.info("Processing location with id: " + locationIds[i]);
                // default return to -1 because no such location with id -1
                Location location = Context.getLocationService()
                        .getLocation(NumberUtils.toInt(locationIds[i], -1));
                if (!initialized) {
                    cohort = Context.getService(CoreService.class).getReturnDateCohort(location, null, null);
                } else {
                    // regenerate when there's new obs
                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.DATE, clusterName.length * 5);
                    Date date = calendar.getTime();
                    cohort = Context.getService(CoreService.class).getReturnDateCohort(location, new Date(),
                            date);
                }

                evaluate(cohort);
            }
        }
    }
}

From source file:org.openmrs.module.clinicalsummary.task.ReturnDateReminderProcessor.java

public void processReminder() {
    // location is clustered, clusters are separated by comma
    String clusterNames = Context.getAdministrationService()
            .getGlobalProperty(TaskParameters.LOCATION_GROUP_LIST);
    if (clusterNames != null) {
        String[] clusterName = StringUtils.split(clusterNames, TaskParameters.CLUSTER_SEPARATOR);
        String processorCounter = Context.getAdministrationService()
                .getGlobalProperty(TaskParameters.PROCESSOR_COUNTER);
        // start with the first cluster (offset = 0) when the counter is not a number
        Integer clusterOffset = NumberUtils.toInt(processorCounter, 0);
        if (clusterOffset >= 0 && clusterOffset < ArrayUtils.getLength(clusterName)) {
            String initProperty = Context.getAdministrationService()
                    .getGlobalProperty(TaskParameters.PROCESSOR_INITIALIZED);
            String currentCluster = clusterName[clusterOffset];
            // check whether all cluster have been initialized or not
            Boolean initialized = BooleanUtils.toBoolean(initProperty);

            Cohort cohort;// w ww  . ja  v a2  s  . c o m
            String[] locationIds = StringUtils.split(currentCluster);
            for (int i = 0; i < ArrayUtils.getLength(locationIds); i++) {
                log.info("Processing location with id: " + locationIds[i]);
                // default return to -1 because no such location with id -1
                Location location = Context.getLocationService()
                        .getLocation(NumberUtils.toInt(locationIds[i], -1));
                if (!initialized) {
                    cohort = Context.getService(CoreService.class).getDateCreatedCohort(location, null, null);
                } else {
                    // regenerate when there's new obs
                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.DATE, clusterName.length * 2);
                    Date date = calendar.getTime();
                    cohort = Context.getService(CoreService.class).getReturnDateCohort(location, new Date(),
                            date);
                }

                evaluate(cohort);
            }
        }
    }
}

From source file:org.openmrs.module.visitdocumentsui.VisitDocumentsContext.java

protected Boolean getBooleanByGlobalProperty(String globalPropertyName) {
    String globalProperty = administrationService.getGlobalProperty(globalPropertyName);
    return BooleanUtils.toBoolean(globalProperty);
}

From source file:org.osaf.cosmo.calendar.ICalDate.java

private void parseAnyTime(String str) {
    anytime = BooleanUtils.toBoolean(str);
}

From source file:org.osaf.cosmo.eim.eimml.EimmlStreamReader.java

private EimRecordSet readNextRecordSet() throws EimmlStreamException, XMLStreamException {
    // finish stream on </collection>
    if (xmlReader.isEndElement() && xmlReader.getName().equals(QN_COLLECTION))
        return null;

    // begin at <recordset>
    if (!(xmlReader.isStartElement() && xmlReader.getName().equals(QN_RECORDSET)))
        throw new EimmlValidationException(
                "Expected start element " + QN_RECORDSET + " but got " + xmlReader.getName());

    EimRecordSet recordset = new EimRecordSet();

    for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
        QName attr = xmlReader.getAttributeName(i);
        //             if (log.isDebugEnabled())
        //                 log.debug("read attr: " + attr);
        String value = xmlReader.getAttributeValue(i);
        if (attr.equals(QN_UUID)) {
            if (StringUtils.isBlank(value))
                throw new EimmlValidationException("Recordset element requires " + ATTR_UUID + " attribute");
            recordset.setUuid(value);//from  ww  w . j  a va2s . co  m
        } else if (attr.equals(QN_DELETED)) {
            if (BooleanUtils.toBoolean(value))
                recordset.setDeleted(true);
        } else {
            log.warn("skipped unrecognized recordset attribute " + attr);
        }
    }

    // move to next <record> or </recordset>
    nextTag();

    while (xmlReader.hasNext()) {
        // complete on </recordset>
        if (xmlReader.isEndElement() && xmlReader.getName().equals(QN_RECORDSET))
            break;

        EimRecord record = readNextRecord();
        if (record == null)
            throw new EimmlValidationException("Expected another record");

        recordset.addRecord(record);

        // move to next <record> or </recordset>
        nextTag();
    }

    // move to next <recordset> or </collection>
    nextTag();

    return recordset;
}

From source file:org.osaf.cosmo.eim.eimml.EimmlStreamReader.java

private EimRecord readNextRecord() throws EimmlStreamException, XMLStreamException {
    // begin at <record>
    if (!(xmlReader.isStartElement() && xmlReader.getLocalName().equals(EL_RECORD)))
        throw new EimmlValidationException(
                "Expected start element " + EL_RECORD + " but got " + xmlReader.getName());

    EimRecord record = new EimRecord();

    record.setPrefix(xmlReader.getPrefix());
    record.setNamespace(xmlReader.getNamespaceURI());

    for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
        QName attr = xmlReader.getAttributeName(i);
        //             if (log.isDebugEnabled())
        //                 log.debug("read attr: " + attr);
        if (attr.equals(QN_DELETED))
            record.setDeleted(true);/*from   w w  w.jav a2 s .  co  m*/
        else
            log.warn("skipped unrecognized record attribute " + attr);
    }

    // move to next field element or </record>
    nextTag();

    while (xmlReader.hasNext()) {
        // complete on </record>
        if (xmlReader.isEndElement() && xmlReader.getLocalName().equals(EL_RECORD))
            break;

        if (!xmlReader.isStartElement())
            throw new EimmlValidationException("Expected field element but got " + xmlReader.getName());

        String name = xmlReader.getLocalName();

        boolean isKey = BooleanUtils.toBoolean(xmlReader.getAttributeValue(NS_CORE, ATTR_KEY));
        boolean isEmpty = BooleanUtils.toBoolean(xmlReader.getAttributeValue(null, ATTR_EMPTY));
        boolean isMissing = BooleanUtils.toBoolean(xmlReader.getAttributeValue(null, ATTR_MISSING));
        String type = xmlReader.getAttributeValue(NS_CORE, ATTR_TYPE);
        if (StringUtils.isBlank(type))
            throw new EimmlValidationException(
                    xmlReader.getName() + " element requires " + ATTR_TYPE + " attribute");

        String text = xmlReader.getElementText();
        if (isEmpty) {
            if (!(type.equals(TYPE_TEXT) || type.equals(TYPE_CLOB) || type.equals(TYPE_BLOB)))
                throw new EimmlValidationException(
                        "Invalid empty attribute on field element " + xmlReader.getName());
            if (text != null)
                //                     if (log.isDebugEnabled())
                //                         log.debug("emptying non-null text for field " + xmlReader.getName());
                text = "";
        } else if (text.equals(""))
            text = null;

        EimRecordField field = null;
        if (type.equals(TYPE_BYTES)) {
            byte[] value = EimmlTypeConverter.toBytes(text);
            field = new BytesField(name, value);
        } else if (type.equals(TYPE_TEXT)) {
            String value = EimmlTypeConverter.toText(text, documentEncoding);
            field = new TextField(name, value);
        } else if (type.equals(TYPE_BLOB)) {
            InputStream value = EimmlTypeConverter.toBlob(text);
            field = new BlobField(name, value);
        } else if (type.equals(TYPE_CLOB)) {
            Reader value = EimmlTypeConverter.toClob(text);
            field = new ClobField(name, value);
        } else if (type.equals(TYPE_INTEGER)) {
            Integer value = EimmlTypeConverter.toInteger(text);
            field = new IntegerField(name, value);
        } else if (type.equals(TYPE_DATETIME)) {
            Calendar value = EimmlTypeConverter.toDateTime(text);
            field = new DateTimeField(name, value);
        } else if (type.equals(TYPE_DECIMAL)) {
            BigDecimal value = EimmlTypeConverter.toDecimal(text);
            field = new DecimalField(name, value);
        } else {
            throw new EimmlValidationException("Unrecognized field type");
        }

        field.setMissing(isMissing);

        if (isKey)
            record.addKeyField(field);
        else
            record.addField(field);

        // move to next field element or </record>
        nextTag();
    }

    return record;
}

From source file:org.ovirt.engine.api.restapi.resource.BackendDiskAttachmentsResource.java

protected Response attachDiskToVm(AbstractBackendCollectionResource resource, DiskAttachment attachment,
        IResolver entityResolver) {// w w w. j a  va 2s.c  o m
    Guid diskId = Guid.createGuidFromStringDefaultEmpty(attachment.getDisk().getId());

    DiskVmElement dve = map(attachment);
    dve.getId().setVmId(vmId);
    dve.getId().setDeviceId(diskId);

    AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve);

    Disk disk = attachment.getDisk();

    boolean isDiskActive = false;
    if (attachment.isSetActive()) {
        isDiskActive = BooleanUtils.toBoolean(attachment.isActive());
    }
    params.setPlugUnPlug(isDiskActive);

    boolean isDiskReadOnly = false;
    if (disk.isSetReadOnly()) {
        isDiskReadOnly = BooleanUtils.toBoolean(disk.isReadOnly());
    }
    params.setReadOnly(isDiskReadOnly);

    if (disk.isSetSnapshot()) {
        validateParameters(disk, "snapshot.id");
        params.setSnapshotId(asGuid(disk.getSnapshot().getId()));
    }

    return resource.performCreate(VdcActionType.AttachDiskToVm, params, entityResolver);
}

From source file:org.pentaho.agilebi.modeler.models.annotations.AnnotationType.java

protected void attemptAutoConvertAndAssign(final Field field, final Object value) throws Exception {

    if (field == null) {
        return; // exit early
    }/*from  ww  w .  j  a  v  a  2  s . c o m*/

    if (value == null) {
        try {
            PropertyUtils.setProperty(this, field.getName(), value);
        } catch (Exception e) {
            // ignore
        }
        return; // exit early
    }

    if (value != null && ClassUtils.isAssignable(value.getClass(), field.getType(), true)) {
        PropertyUtils.setProperty(this, field.getName(), value);
    } else {

        try {
            if (ClassUtils.isAssignable(field.getType(), Boolean.class, true)) {
                PropertyUtils.setProperty(this, field.getName(), BooleanUtils.toBoolean(value.toString()));
                return;
            }

            if (ClassUtils.isAssignable(field.getType(), AggregationType.class, true)) {
                AggregationType type = AggregationType.valueOf(value.toString());
                if (type != null) {
                    PropertyUtils.setProperty(this, field.getName(), type);
                }
                return;
            }

            if (ClassUtils.isAssignable(field.getType(), ModelAnnotation.TimeType.class, true)) {
                ModelAnnotation.TimeType type = ModelAnnotation.TimeType.valueOf(value.toString());
                if (type != null) {
                    PropertyUtils.setProperty(this, field.getName(), type);
                }
                return;
            }

            if (ClassUtils.isAssignable(field.getType(), ModelAnnotation.GeoType.class, true)) {
                ModelAnnotation.GeoType type = ModelAnnotation.GeoType.valueOf(value.toString());
                if (type != null) {
                    PropertyUtils.setProperty(this, field.getName(), type);
                }
                return;
            }

            if (NumberUtils.isNumber(value.toString())) {
                Number number = NumberUtils.createNumber(value.toString());
                PropertyUtils.setProperty(this, field.getName(), number);
            }
        } catch (Exception e) {
            if (value == null || StringUtils.isBlank(value.toString())) {
                return; // do not log
            }
            // ignore error but log
            getLogger().warning("Unable to convert " + value.toString() + " in to " + field.getType());
        }
    }
}