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:jp.primecloud.auto.service.impl.InstanceServiceImpl.java
/** * {@inheritDoc}/*from w w w . jav a 2s . c o m*/ */ @Override public InstanceStatus getInstanceStatus(Instance instance) { // ????? InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus()); if (BooleanUtils.isTrue(instance.getEnabled())) { if (instanceStatus == InstanceStatus.STOPPED) { instance.setStatus(InstanceStatus.STARTING.toString()); } } else { if (instanceStatus == InstanceStatus.RUNNING || instanceStatus == InstanceStatus.WARNING) { instance.setStatus(InstanceStatus.STOPPING.toString()); } } // ??? // ? ? ?? // Running Coodinating Configuring // Running Warning Warning instanceStatus = InstanceStatus.fromStatus(instance.getStatus()); InstanceCoodinateStatus insCoodiStatus = InstanceCoodinateStatus.fromStatus(instance.getCoodinateStatus()); // ?(Running)???(Coodinating)Configuring? if (instanceStatus == InstanceStatus.RUNNING && insCoodiStatus == InstanceCoodinateStatus.COODINATING) { instance.setStatus(InstanceStatus.CONFIGURING.toString()); // ?(Running)???(Warning)Warning? } else if (instanceStatus == InstanceStatus.RUNNING && insCoodiStatus == InstanceCoodinateStatus.WARNING) { instance.setStatus(InstanceStatus.WARNING.toString()); } return InstanceStatus.fromStatus(instance.getStatus()); }
From source file:org.apache.cocoon.template.instruction.Out.java
public Event execute(final XMLConsumer consumer, ExpressionContext expressionContext, ExecutionContext executionContext, MacroContext macroContext, Event startEvent, Event endEvent) throws SAXException { Object val; try {/*from w w w . j av a2 s . c o m*/ val = this.compiledExpression.getNode(expressionContext); boolean stripRoot = BooleanUtils.toBoolean(this.stripRoot); //TODO: LG, I do not see a good way to do this. if (BooleanUtils.isTrue(this.xmlize)) { if (val instanceof Node || val instanceof Node[] || val instanceof XMLizable) Invoker.executeNode(consumer, val, stripRoot); else { ServiceManager serviceManager = executionContext.getServiceManager(); SAXParser parser = null; try { parser = (SAXParser) serviceManager.lookup(SAXParser.ROLE); InputSource source = new InputSource(new ByteArrayInputStream(val.toString().getBytes())); IncludeXMLConsumer includeConsumer = new IncludeXMLConsumer(consumer); includeConsumer.setIgnoreRootElement(stripRoot); parser.parse(source, includeConsumer); } finally { serviceManager.release(parser); } } } else Invoker.executeNode(consumer, val, stripRoot); } catch (Exception e) { throw new SAXParseException(e.getMessage(), getLocation(), e); } return getNext(); }
From source file:org.apache.ctakes.jdl.data.loader.CsvLoader.java
/** * @param jdlConnection// www . j a v a 2s .c o m * the jdlConnection to manage */ @Override public final void dataInsert(final JdlConnection jdlConnection) { String sql = getSqlInsert(loader); if (log.isInfoEnabled()) log.info(sql); Number ncommit = loader.getCommit(); int rs = (loader.getSkip() == null) ? 0 : loader.getSkip().intValue(); PreparedStatement preparedStatement = null; try { jdlConnection.setAutoCommit(false); // String[][] values = parser.getAllValues(); preparedStatement = jdlConnection.getOpenConnection().prepareStatement(sql); boolean leftoversToCommit = false; // for (int r = rs; r < values.length; r++) { String[] row = null; int r = 0; do { row = parser.getLine(); if (row == null) break; if (r < rs) { r++; continue; } r++; try { int cs = 0; // columns to skip int ce = 0; // columns from external int c = 0; // PreparedStatement preparedStatement = jdlConnection // .getOpenConnection().prepareStatement(sql); // if (ncommit == null) { // jdlConnection.setAutoCommit(true); // } else { // jdlConnection.setAutoCommit(false); // } for (Column column : loader.getColumn()) { if (BooleanUtils.isTrue(column.isSkip())) { cs++; } else { c++; Object value = column.getConstant(); ce++; if (value == null) { if (column.getSeq() != null) { value = r + column.getSeq().intValue(); } else { // value = values[r][c + cs - ce]; value = row[c + cs - ce]; ce--; } } if (value == null || (value instanceof String && ((String) value).length() == 0)) preparedStatement.setObject(c, null); else { // if there is a formatter, parse the string if (this.formatMap.containsKey(column.getName())) { try { preparedStatement.setObject(c, this.formatMap.get(column.getName()).parseObject((String) value)); } catch (Exception e) { System.err.println("Could not format '" + value + "' for column " + column.getName() + " on line " + r); e.printStackTrace(System.err); throw new RuntimeException(e); } } else { preparedStatement.setObject(c, value); } } } } preparedStatement.addBatch(); leftoversToCommit = true; // preparedStatement.executeBatch(); // executeBatch(preparedStatement); // if (!jdlConnection.isAutoCommit() // && (r % ncommit.intValue() == 0)) { if (r % ncommit.intValue() == 0) { preparedStatement.executeBatch(); jdlConnection.commitConnection(); leftoversToCommit = false; log.info("inserted " + ncommit.intValue() + " rows"); } } catch (SQLException e) { // e.printStackTrace(); throw new RuntimeException(e); } } while (row != null); if (leftoversToCommit) { preparedStatement.executeBatch(); jdlConnection.commitConnection(); leftoversToCommit = false; } log.info("inserted " + (r - rs) + " rows total"); } catch (InstantiationException e) { log.error("", e); } catch (IllegalAccessException e) { log.error("", e); } catch (ClassNotFoundException e) { log.error("", e); } catch (IOException e) { log.error("", e); } catch (SQLException e) { throw new RuntimeException(e); } finally { if (preparedStatement != null) { try { preparedStatement.close(); } catch (Exception e) { } } } // try { // if (!jdlConnection.isAutoCommit()) { // jdlConnection.commitConnection(); // } // jdlConnection.closeConnection(); // } catch (SQLException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } }
From source file:org.apache.maven.shared.release.DefaultReleaseManager.java
private void prepare(ReleasePrepareRequest prepareRequest, ReleaseResult result) throws ReleaseExecutionException, ReleaseFailureException { updateListener(prepareRequest.getReleaseManagerListener(), "prepare", GOAL_START); ReleaseDescriptor config;//from w w w .java2 s. c o m if (BooleanUtils.isNotFalse(prepareRequest.getResume())) { config = loadReleaseDescriptor(prepareRequest.getReleaseDescriptor(), prepareRequest.getReleaseManagerListener()); } else { config = prepareRequest.getReleaseDescriptor(); } // Later, it would be a good idea to introduce a proper workflow tool so that the release can be made up of a // more flexible set of steps. String completedPhase = config.getCompletedPhase(); int index = preparePhases.indexOf(completedPhase); for (int idx = 0; idx <= index; idx++) { updateListener(prepareRequest.getReleaseManagerListener(), preparePhases.get(idx), PHASE_SKIP); } if (index == preparePhases.size() - 1) { logInfo(result, "Release preparation already completed. You can now continue with release:perform, " + "or start again using the -Dresume=false flag"); } else if (index >= 0) { logInfo(result, "Resuming release from phase '" + preparePhases.get(index + 1) + "'"); } // start from next phase for (int i = index + 1; i < preparePhases.size(); i++) { String name = preparePhases.get(i); ReleasePhase phase = releasePhases.get(name); if (phase == null) { throw new ReleaseExecutionException("Unable to find phase '" + name + "' to execute"); } updateListener(prepareRequest.getReleaseManagerListener(), name, PHASE_START); ReleaseResult phaseResult = null; try { if (BooleanUtils.isTrue(prepareRequest.getDryRun())) { phaseResult = phase.simulate(config, prepareRequest.getReleaseEnvironment(), prepareRequest.getReactorProjects()); } else { phaseResult = phase.execute(config, prepareRequest.getReleaseEnvironment(), prepareRequest.getReactorProjects()); } } finally { if (result != null && phaseResult != null) { result.appendOutput(phaseResult.getOutput()); } } config.setCompletedPhase(name); try { configStore.write(config); } catch (ReleaseDescriptorStoreException e) { // TODO: rollback? throw new ReleaseExecutionException("Error writing release properties after completing phase", e); } updateListener(prepareRequest.getReleaseManagerListener(), name, PHASE_END); } updateListener(prepareRequest.getReleaseManagerListener(), "prepare", GOAL_END); }
From source file:org.apache.maven.shared.release.DefaultReleaseManager.java
private void perform(ReleasePerformRequest performRequest, ReleaseResult result) throws ReleaseExecutionException, ReleaseFailureException { updateListener(performRequest.getReleaseManagerListener(), "perform", GOAL_START); ReleaseDescriptor releaseDescriptor = loadReleaseDescriptor(performRequest.getReleaseDescriptor(), performRequest.getReleaseManagerListener()); for (String name : performPhases) { ReleasePhase phase = releasePhases.get(name); if (phase == null) { throw new ReleaseExecutionException("Unable to find phase '" + name + "' to execute"); }//from ww w . j a va 2s . c o m updateListener(performRequest.getReleaseManagerListener(), name, PHASE_START); ReleaseResult phaseResult = null; try { if (BooleanUtils.isTrue(performRequest.getDryRun())) { phaseResult = phase.simulate(releaseDescriptor, performRequest.getReleaseEnvironment(), performRequest.getReactorProjects()); } else { phaseResult = phase.execute(releaseDescriptor, performRequest.getReleaseEnvironment(), performRequest.getReactorProjects()); } } finally { if (result != null && phaseResult != null) { result.appendOutput(phaseResult.getOutput()); } } updateListener(performRequest.getReleaseManagerListener(), name, PHASE_END); } if (BooleanUtils.isNotFalse(performRequest.getClean())) { // call release:clean so that resume will not be possible anymore after a perform clean(releaseDescriptor, performRequest.getReleaseManagerListener(), performRequest.getReactorProjects()); } updateListener(performRequest.getReleaseManagerListener(), "perform", GOAL_END); }
From source file:org.apache.maven.shared.release.DefaultReleaseManager.java
/** {@inheritDoc} */ public void branch(ReleaseBranchRequest branchRequest) throws ReleaseExecutionException, ReleaseFailureException { ReleaseDescriptor releaseDescriptor = loadReleaseDescriptor(branchRequest.getReleaseDescriptor(), branchRequest.getReleaseManagerListener()); updateListener(branchRequest.getReleaseManagerListener(), "branch", GOAL_START); boolean dryRun = BooleanUtils.isTrue(branchRequest.getDryRun()); for (String name : branchPhases) { ReleasePhase phase = releasePhases.get(name); if (phase == null) { throw new ReleaseExecutionException("Unable to find phase '" + name + "' to execute"); }/*w ww . j a v a 2 s. c om*/ updateListener(branchRequest.getReleaseManagerListener(), name, PHASE_START); if (dryRun) { phase.simulate(releaseDescriptor, branchRequest.getReleaseEnvironment(), branchRequest.getReactorProjects()); } else // getDryRun is null or FALSE { phase.execute(releaseDescriptor, branchRequest.getReleaseEnvironment(), branchRequest.getReactorProjects()); } updateListener(branchRequest.getReleaseManagerListener(), name, PHASE_END); } if (!dryRun) { clean(releaseDescriptor, branchRequest.getReleaseManagerListener(), branchRequest.getReactorProjects()); } updateListener(branchRequest.getReleaseManagerListener(), "branch", GOAL_END); }
From source file:org.apache.myfaces.custom.convertStringUtils.StringUtilsConverter.java
private String format(String val, boolean duringOutput) throws ConverterException { String str;/*from w w w. j a v a 2 s.c o m*/ if (BooleanUtils.isTrue(trim)) { str = val.trim(); } else { str = val; } // Any decorations first if (StringUtils.isNotEmpty(format)) { if ("uppercase".equalsIgnoreCase(format)) { str = StringUtils.upperCase(str); } else if ("lowercase".equalsIgnoreCase(format)) { str = StringUtils.lowerCase(str); } else if ("capitalize".equalsIgnoreCase(format)) { str = WordUtils.capitalizeFully(str); } else { throw new ConverterException("Invalid format '" + format + "'"); } } boolean appendEllipses = ((duringOutput) && ((null != appendEllipsesDuringOutput) && (appendEllipsesDuringOutput.booleanValue()))) || ((false == duringOutput) && ((null != appendEllipsesDuringInput) && (appendEllipsesDuringInput.booleanValue()))); if (appendEllipses) { // See if we need to abbreviate/truncate this string if (null != maxLength && maxLength.intValue() > 4) { str = StringUtils.abbreviate(str, maxLength.intValue()); } } else { // See if we need to truncate this string if (null != maxLength) { str = str.substring(0, maxLength.intValue()); } } return str; }
From source file:org.apache.qpid.server.security.access.config.RuleSet.java
/** * Check if a configuration property is set. */ protected boolean isSet(String key) { return BooleanUtils.isTrue(_config.get(key)); }
From source file:org.apache.sqoop.connector.jdbc.oracle.OracleJdbcExtractor.java
private String getSelectQuery(FromJobConfig jobConfig, ImmutableContext context) { boolean consistentRead = BooleanUtils.isTrue(jobConfig.consistentRead); long consistentReadScn = context.getLong(OracleJdbcConnectorConstants.ORACLE_IMPORT_CONSISTENT_READ_SCN, 0L);/*w w w . j a va2s .c om*/ if (consistentRead && consistentReadScn == 0L) { throw new RuntimeException("Could not get SCN for consistent read."); } StringBuilder query = new StringBuilder(); if (this.dbInputSplit.getDataChunks() == null) { String errMsg = String.format("The %s does not contain any data-chunks, within %s.", this.dbInputSplit.getClass().getName(), OracleUtilities.getCurrentMethodName()); throw new RuntimeException(errMsg); } OracleUtilities.OracleTableImportWhereClauseLocation whereClauseLocation = OracleUtilities .getTableImportWhereClauseLocation(jobConfig); int numberOfDataChunks = this.dbInputSplit.getNumberOfDataChunks(); for (int idx = 0; idx < numberOfDataChunks; idx++) { OracleDataChunk dataChunk = this.dbInputSplit.getDataChunks().get(idx); if (idx > 0) { query.append("UNION ALL \n"); } query.append(getColumnNamesClause(tableColumns, dataChunk.getId(), jobConfig)) // <- SELECT clause .append("\n"); query.append(" FROM ").append(table.toString()).append(" "); if (consistentRead) { query.append("AS OF SCN ").append(consistentReadScn).append(" "); } query.append(getPartitionClauseForDataChunk(this.dbInputSplit, idx)).append(" t").append("\n"); query.append(" WHERE (").append(getWhereClauseForDataChunk(this.dbInputSplit, idx)).append(")\n"); // If the user wants the WHERE clause applied to each data-chunk... if (whereClauseLocation == OracleUtilities.OracleTableImportWhereClauseLocation.SUBSPLIT) { String conditions = jobConfig.conditions; if (conditions != null && conditions.length() > 0) { query.append(" AND (").append(conditions).append(")\n"); } } } // If the user wants the WHERE clause applied to the whole split... if (whereClauseLocation == OracleUtilities.OracleTableImportWhereClauseLocation.SPLIT) { String conditions = jobConfig.conditions; if (conditions != null && conditions.length() > 0) { // Insert a "select everything" line at the start of the SQL query... query.insert(0, getColumnNamesClause(tableColumns, null, jobConfig) + " FROM (\n"); // ...and then apply the WHERE clause to all the UNIONed sub-queries... query.append(")\n").append("WHERE\n").append(conditions).append("\n"); } } LOG.info("SELECT QUERY = \n" + query.toString()); return query.toString(); }
From source file:org.apache.sqoop.connector.jdbc.oracle.OracleJdbcFromInitializer.java
@Override public void initialize(InitializerContext context, LinkConfiguration linkConfiguration, FromJobConfiguration jobConfiguration) { super.initialize(context, linkConfiguration, jobConfiguration); LOG.debug("Running Oracle JDBC connector FROM initializer"); try {//from w w w . j a va 2 s .c o m if (OracleQueries.isTableAnIndexOrganizedTable(connection, table)) { if (OracleUtilities.getOraOopOracleDataChunkMethod( jobConfiguration.fromJobConfig) != OracleUtilities.OracleDataChunkMethod.PARTITION) { throw new RuntimeException( String.format( "Cannot process this Sqoop" + " connection, as the Oracle table %s is an" + " index-organized table. If the table is" + " partitioned, set the data chunk method to " + OracleUtilities.OracleDataChunkMethod.PARTITION + ".", table.toString())); } } } catch (SQLException e) { throw new RuntimeException(String.format( "Unable to determine whether the Oracle table %s is an" + "index-organized table.", table.toString()), e); } if (BooleanUtils.isTrue(jobConfiguration.fromJobConfig.consistentRead)) { Long scn = jobConfiguration.fromJobConfig.consistentReadScn; if (scn == null || scn.equals(Long.valueOf(0L))) { try { scn = OracleQueries.getCurrentScn(connection); } catch (SQLException e) { throw new RuntimeException("Unable to determine SCN of database.", e); } } context.getContext().setLong(OracleJdbcConnectorConstants.ORACLE_IMPORT_CONSISTENT_READ_SCN, scn); LOG.info("Performing a consistent read using SCN: " + scn); } }