List of usage examples for org.apache.commons.lang BooleanUtils isTrue
public static boolean isTrue(Boolean bool)
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
From source file:org.openmrs.module.clinicalsummary.io.DownloadSummariesTask.java
/** * Method that will be called to process the summary collection file. Download process will create one zipped and encrypted collection of summary * files.//from w ww . java 2s . c o m * <p/> * this.passphrase = password; * * @throws Exception */ protected final void processSummaries() throws Exception { // TODO: The better approach would be to create zip file and then encrypt it. // And then Content of the zip file: // * Zipped file of summary files and sql file // * Sample file to be used for decryption testing String zipFilename = StringUtils.join(Arrays.asList(filename, TaskConstants.FILE_TYPE_ZIP), "."); File zipFile = new File(TaskUtils.getZippedOutputPath(), zipFilename); ZipOutputStream zipOutStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile))); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -1); Date cutOffDate = null; if (BooleanUtils.isTrue(partial)) { cutOffDate = calendar.getTime(); } File inputPath = TaskUtils.getSummaryOutputPath(); File[] files = inputPath.listFiles(); if (files != null) { for (File file : files) { processStream(zipOutStream, inputPath.getAbsolutePath(), file, cutOffDate); } } zipOutStream.close(); String encryptedFilename = StringUtils.join(Arrays.asList(filename, TaskConstants.FILE_TYPE_ENCRYPTED), "."); File encryptedOutFile = new File(TaskUtils.getEncryptedOutputPath(), encryptedFilename); ZipOutputStream encryptedZipOutStream = new ZipOutputStream( new BufferedOutputStream(new FileOutputStream(encryptedOutFile))); int count; byte[] data; // add the 16 bytes init vector for the cipher into the output stream String secretFilename = StringUtils.join(Arrays.asList(filename, TaskConstants.FILE_TYPE_SECRET), "."); ZipEntry ivZipEntry = new ZipEntry(secretFilename); encryptedZipOutStream.putNextEntry(ivZipEntry); // write the 16 bytes init vector for the cipher into the output stream AlgorithmParameters params = cipher.getParameters(); byte[] initVector = params.getParameterSpec(IvParameterSpec.class).getIV(); encryptedZipOutStream.write(initVector); // add the sample file entry String sampleFilename = StringUtils.join(Arrays.asList(filename, TaskConstants.FILE_TYPE_SAMPLE), "."); ZipEntry sampleZipEntry = new ZipEntry(sampleFilename); encryptedZipOutStream.putNextEntry(sampleZipEntry); // write the sample file data = new byte[TaskConstants.BUFFER_SIZE]; String sampleText = "This is sample text inside encrypted document. " + "If you see this text, that means your decryption parameters is correct"; InputStream inStream = new ByteArrayInputStream(sampleText.getBytes()); CipherInputStream sampleCipherInStream = new CipherInputStream(inStream, cipher); while ((count = sampleCipherInStream.read(data, 0, TaskConstants.BUFFER_SIZE)) != -1) { encryptedZipOutStream.write(data, 0, count); } sampleCipherInStream.close(); // add the zipped summaries ZipEntry zipEntry = new ZipEntry(zipFile.getName()); encryptedZipOutStream.putNextEntry(zipEntry); // write the zipped summaries data = new byte[TaskConstants.BUFFER_SIZE]; InputStream zipInStream = new BufferedInputStream(new FileInputStream(zipFile)); CipherInputStream zipCipherInStream = new CipherInputStream(zipInStream, cipher); while ((count = zipCipherInStream.read(data, 0, TaskConstants.BUFFER_SIZE)) != -1) { encryptedZipOutStream.write(data, 0, count); } zipCipherInStream.close(); encryptedZipOutStream.close(); }
From source file:org.openmrs.module.clinicalsummary.rule.reminder.anc.tetanus.FirstTetanusBoosterReminderRule.java
@Override protected Result processCachedReminder(final String displayedReminderText) { Result result = new Result(); TetanusBoosterReminderCacheInstance cacheInstance = TetanusBoosterReminderCacheInstance.getInstance(); if (BooleanUtils.isTrue(cacheInstance.getReminder(TOKEN))) result.add(new Result(displayedReminderText)); return result; }
From source file:org.openmrs.module.clinicalsummary.rule.reminder.anc.tetanus.RecordTetanusBoosterReminderRule.java
/** * @see org.openmrs.logic.Rule#eval(org.openmrs.logic.LogicContext, Integer, java.util.Map) *///from w w w . j a v a2s.c o m @Override protected Result processCachedReminder(final String displayedReminderText) { Result result = new Result(); TetanusBoosterReminderCacheInstance cacheInstance = TetanusBoosterReminderCacheInstance.getInstance(); if (BooleanUtils.isTrue(cacheInstance.getReminder(TOKEN))) result.add(new Result(displayedReminderText)); return result; }
From source file:org.openmrs.module.clinicalsummary.web.controller.download.DownloadSummariesController.java
@RequestMapping(method = RequestMethod.POST) public void processSubmit(final @RequestParam(required = true, value = "password") String password, final @RequestParam(required = false, value = "partial") Boolean partial, final ModelMap map) { if (Context.isAuthenticated()) { // prepare the page elements preparePage(map);//from w w w . ja v a 2 s. c o m // start the download process String filename = WebUtils.prepareFilename(); if (BooleanUtils.isTrue(partial)) filename = "Partial_" + filename; SummariesTaskInstance.getInstance().startDownloading(password, filename, partial); } }
From source file:org.osaf.cosmo.eim.schema.BaseApplicatorTestCase.java
/** */ protected void checkBooleanValue(EimRecordField field, Boolean value) { Integer v = BooleanUtils.isTrue(value) ? new Integer(1) : new Integer(0); checkIntegerValue(field, v);//from www .j a va2 s. c o m }
From source file:org.osaf.cosmo.eim.schema.BaseGeneratorTestCase.java
/** */ protected void checkBooleanField(EimRecordField field, String expectedName, Boolean expectedValue) { Integer i = BooleanUtils.isTrue(expectedValue) ? new Integer(1) : new Integer(0); checkIntegerField(field, expectedName, i); }
From source file:org.osaf.cosmo.eim.schema.contentitem.ContentItemGenerator.java
/** * Copies contentItem properties and attributes into a contentItem * record./*www.j a va 2 s . c o m*/ */ public List<EimRecord> generateRecords() { ContentItem contentItem = (ContentItem) getItem(); EimRecord record = new EimRecord(getPrefix(), getNamespace()); record.addKeyField(new TextField(FIELD_UUID, contentItem.getUid())); if (isMissingAttribute("displayName")) { record.addField(generateMissingField(new TextField(FIELD_TITLE, null))); } else { record.addField(new TextField(FIELD_TITLE, contentItem.getDisplayName())); } String ts = TriageStatusFormat.getInstance(getItem().getFactory()).format(contentItem.getTriageStatus()); // missing TriageStatus ends up as empty string instead of null if (isModification() && "".equals(ts)) { record.addField(generateMissingField(new TextField(FIELD_TRIAGE, null))); } else { record.addField(new TextField(FIELD_TRIAGE, ts)); } if (isMissingAttribute("sent")) { record.addField(generateMissingField(new IntegerField(FIELD_HAS_BEEN_SENT, null))); } else { boolean sent = BooleanUtils.isTrue(contentItem.getSent()); record.addField(new IntegerField(FIELD_HAS_BEEN_SENT, sent)); } if (isMissingAttribute("needsReply")) { record.addField(generateMissingField(new IntegerField(FIELD_NEEDS_REPLY, null))); } else { boolean needsReply = BooleanUtils.isTrue(contentItem.getNeedsReply()); record.addField(new IntegerField(FIELD_NEEDS_REPLY, needsReply)); } Date d = contentItem.getClientCreationDate(); BigDecimal createdOn = d != null ? new BigDecimal(d.getTime() / 1000) : null; record.addField(new DecimalField(FIELD_CREATED_ON, createdOn, DIGITS_TIMESTAMP, DEC_TIMESTAMP)); record.addFields(generateUnknownFields()); ArrayList<EimRecord> records = new ArrayList<EimRecord>(); records.add(record); return records; }
From source file:org.osaf.cosmo.eim.schema.ItemTranslator.java
/** * Generates a recordset from the item and its stamps, including * records for only those stamps that have been modified since the * given timestamp.//from w w w . j a va 2 s. c o m * * If the item is not active, simply marks the recordset deleted * and returns. */ public EimRecordSet generateRecords(long timestamp) { EimRecordSet recordset = new EimRecordSet(); recordset.setUuid(item.getUid()); // If item is an occurrence, then we only need an // occurrence generator if (item instanceof NoteOccurrence) { recordset.addRecords(occurrenceGenerator.generateRecords()); return recordset; } if (!BooleanUtils.isTrue(item.getIsActive())) { recordset.setDeleted(true); return recordset; } recordset.addRecords(contentItemGenerator.generateRecords()); recordset.addRecords(modifiedByGenerator.generateRecords()); if (item instanceof NoteItem) { recordset.addRecords(noteGenerator.generateRecords()); recordset.addRecords(eventGenerator.generateRecords(timestamp)); recordset.addRecords(alarmGenerator.generateRecords(timestamp)); recordset.addRecords(taskGenerator.generateRecords(timestamp)); recordset.addRecords(messageGenerator.generateRecords(timestamp)); } recordset.addRecords(unknownGenerator.generateRecords()); return recordset; }
From source file:org.osaf.cosmo.eim.schema.text.TriageStatusFormat.java
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { if (obj == null) return toAppendTo; if (!(obj instanceof TriageStatus)) throw new IllegalArgumentException("object not a TriageStatus"); TriageStatus ts = (TriageStatus) obj; int begin = -1; int end = -1; Integer code = ts.getCode();/* w w w . ja v a2 s . co m*/ if (code != null) // validate that this is a known code; throws // IllegalArgumentException if not TriageStatusUtil.label(code); else code = new Integer(-1); if (pos.getField() == CODE_FIELD) begin = toAppendTo.length(); toAppendTo.append(code); if (pos.getField() == CODE_FIELD) end = toAppendTo.length() - 1; toAppendTo.append(" "); BigDecimal rank = ts.getRank(); if (rank == null) rank = BigDecimal.ZERO; rank.setScale(2); if (pos.getField() == RANK_FIELD) begin = toAppendTo.length(); toAppendTo.append(rank); if (pos.getField() == RANK_FIELD) end = toAppendTo.length() - 1; toAppendTo.append(" "); String autoTriage = BooleanUtils.isTrue(ts.getAutoTriage()) ? AUTOTRIAGE_ON : AUTOTRIAGE_OFF; if (pos.getField() == AUTOTRIAGE_FIELD) begin = toAppendTo.length(); toAppendTo.append(autoTriage); if (pos.getField() == AUTOTRIAGE_FIELD) end = toAppendTo.length() - 1; if (pos != null) { pos.setBeginIndex(begin); pos.setEndIndex(end); } return toAppendTo; }
From source file:org.pentaho.di.trans.steps.getrepositorynames.GetRepositoryNames.java
@SuppressWarnings("deprecation") private List<RepositoryElementMetaInterface> getRepositoryObjects() throws KettleException { try {/*from w w w . j av a 2 s . c o m*/ // The repository is available in the parent transformation metadata // Repository repository = getTransMeta().getRepository(); // Now populate the list... // List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>(); if (repository instanceof RepositoryExtended) { RepositoryExtended extendedRep = (RepositoryExtended) repository; for (int i = 0; i < meta.getDirectory().length; i++) { String directoryPath = environmentSubstitute(meta.getDirectory()[i]); String filter = null; // by default we look for current level int depth = 0; if (meta.getObjectTypeSelection().areTransformationsSelected()) { filter = "*.ktr"; } if (meta.getObjectTypeSelection().areJobsSelected()) { // if we have selected the job and transformation than we have applied filter with both condition filter = Utils.isEmpty(filter) ? "*.kjb" : filter + "|*.kjb"; } // should include unlimited subfolder if (meta.getIncludeSubFolders()[i]) { depth = -1; } RepositoryDirectoryInterface directory = extendedRep.loadRepositoryDirectoryTree(directoryPath, filter, depth, BooleanUtils.isTrue(repository.getUserInfo().isAdmin()), false, false); list.addAll(getRepositoryObjects(directory, environmentSubstitute(meta.getNameMask()[i]), environmentSubstitute(meta.getExcludeNameMask()[i]))); } } else { // Get the repository directory tree. // RepositoryDirectoryInterface tree = repository.loadRepositoryDirectoryTree(); // Loop over the directories and add the discovered objects to the list... // for (int i = 0; i < meta.getDirectory().length; i++) { RepositoryDirectoryInterface dir = tree .findDirectory(environmentSubstitute(meta.getDirectory()[i])); if (dir != null) { List<RepositoryElementMetaInterface> objects = getRepositoryObjects(repository, dir, meta.getIncludeSubFolders()[i], environmentSubstitute(meta.getNameMask()[i]), environmentSubstitute(meta.getExcludeNameMask()[i])); list.addAll(objects); } } } return list; } catch (Exception e) { throw new KettleException("Unable to get the list of repository objects from the repository", e); } }