List of usage examples for org.apache.commons.lang BooleanUtils toString
public static String toString(boolean bool, String trueString, String falseString)
Converts a boolean to a String returning one of the input Strings.
BooleanUtils.toString(true, "true", "false") = "true" BooleanUtils.toString(false, "true", "false") = "false"
From source file:org.fao.geonet.kernel.XmlSerializer.java
/** * Insert Metadata into the database.//from ww w. j a v a2s .co m * * @param dbms a dbms * @param metadata the metadata to insert * @return the metadata ID * @throws SQLException */ public static Integer insertMetadata(Dbms dbms, Metadata metadata) throws SQLException { if (resolveXLinks()) { Processor.removeXLink(metadata.getData()); } fixCR(metadata.getData()); String date = new ISODate().toString(); if (metadata.getCreateDate() == null) { metadata.setCreateDate(date); } if (metadata.getChangeDate() == null) { metadata.setChangeDate(date); } metadata.setLocalImportDate(date); metadata.setId(SerialFactory.getSerial(dbms, "Metadata")); List<String> fields = new ArrayList<String>(); fields.addAll( Arrays.asList("id", "uuid", "schemaId", "isTemplate", "isHarvested", "createDate", "changeDate", "data", "title", "root", "datapolicy", "category", "localImportDate", "importProcess")); Boolean isHarvested = !metadata.getSource().getProcessType().equals(ProcessType.LOCAL); List<Serializable> args = new ArrayList<Serializable>(); args.add(metadata.getId()); args.add(metadata.getUrn()); args.add(metadata.getSchema()); args.add("n"); args.add(BooleanUtils.toString(isHarvested, "y", "n")); args.add(metadata.getCreateDate()); args.add(metadata.getChangeDate()); args.add(Xml.getString(metadata.getData())); args.add(metadata.getTitle()); args.add(metadata.getData().getQualifiedName()); args.add(metadata.getDataPolicy().getId()); args.add(metadata.getCategory().getId()); args.add(metadata.getLocalImportDate()); args.add(metadata.getSource().getProcessType().toString()); String source = null; if (metadata.getSource() instanceof SiteSource) { // Handle owner String owner = ((SiteSource) metadata.getSource()).getUserName(); fields.add("owner"); args.add(owner); source = ((SiteSource) metadata.getSource()).getSourceId(); } else { HarvestingSource harvestingSource = (HarvestingSource) metadata.getSource(); // Add the harvesting task ID. fields.add("harvestingTask"); args.add(harvestingSource.getHarvestingTask().getId()); // If not null, add the harvesting URI for some specific harvesters. if (StringUtils.isNotBlank(harvestingSource.getHarvestingURI())) { fields.add("harvestUri"); args.add(harvestingSource.getHarvestingURI()); } source = harvestingSource.getHarvestingTask().getUuid(); } // Finally add the source fields.add("source"); args.add(source); // Dynamically builds values for the query. String[] fieldsArray = new String[fields.size()]; Arrays.fill(fieldsArray, "?"); // Build the query using Joiner. String query = "INSERT INTO Metadata (" + Joiner.on(",").join(fields) + ") VALUES(" + Joiner.on(",").join(fieldsArray) + ")"; // Execute query dbms.execute(query, args.toArray()); return metadata.getId(); }
From source file:org.fao.geonet.kernel.XmlSerializer.java
/** * Description goes here.//from w w w . ja va 2 s . c om * @param template */ public static Integer insertTemplate(Dbms dbms, Template template) throws Exception { if (resolveXLinks()) { Processor.removeXLink(template.getData()); } fixCR(template.getData()); String date = new ISODate().toString(); if (template.getCreateDate() == null) { template.setCreateDate(date); } if (template.getChangeDate() == null) { template.setChangeDate(date); } template.setId(SerialFactory.getSerial(dbms, "Metadata")); List<String> fields = new ArrayList<String>(); fields.addAll(Arrays.asList("id", "uuid", "schemaId", "isTemplate", "isHarvested", "createDate", "changeDate", "data", "title", "root", "displayorder", "importProcess", "datapolicy")); Boolean isHarvested = !template.getSource().getProcessType().equals(ProcessType.LOCAL); List<Serializable> args = new ArrayList<Serializable>(); args.add(template.getId()); args.add(template.getUrn()); args.add(template.getSchema()); args.add(BooleanUtils.toString(template.isSubTemplate(), "s", "y")); args.add(BooleanUtils.toString(isHarvested, "y", "n")); args.add(template.getCreateDate()); args.add(template.getChangeDate()); args.add(Xml.getString(template.getData())); args.add(template.getTitle()); args.add(template.getData().getQualifiedName()); args.add(template.getDisplayOrder()); args.add(template.getSource().getProcessType().toString()); args.add(template.getDataPolicy().getId()); String source = null; if (template.getSource() instanceof SiteSource) { // Handle owner String owner = ((SiteSource) template.getSource()).getUserName(); fields.add("owner"); args.add(owner); source = ((SiteSource) template.getSource()).getSourceId(); } else { HarvestingSource harvestingSource = (HarvestingSource) template.getSource(); // Add the harvesting task ID. fields.add("harvestingTask"); args.add(harvestingSource.getHarvestingTask().getId()); // If not null, add the harvesting URI for some specific harvesters. if (StringUtils.isNotBlank(harvestingSource.getHarvestingURI())) { fields.add("harvestUri"); args.add(harvestingSource.getHarvestingURI()); } source = harvestingSource.getHarvestingTask().getUuid(); } // Finally add the source fields.add("source"); args.add(source); // Dynamically builds values for the query. String[] fieldsArray = new String[fields.size()]; Arrays.fill(fieldsArray, "?"); // Build the query using Joiner. String query = "INSERT INTO Metadata (" + Joiner.on(",").join(fields) + ") VALUES(" + Joiner.on(",").join(fieldsArray) + ")"; // Execute query dbms.execute(query, args.toArray()); return template.getId(); }
From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java
/** * Gets the value of a checkbox./*from w w w. ja v a2 s . c o m*/ * * @param element the located parent element */ private final String getCheckbox(final WebElement element) { return BooleanUtils.toString(element.isSelected(), "on", "off"); }
From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java
/** * Gets the value of a radio button./*from ww w. jav a 2 s. c o m*/ * * @param locator the id, name, title, or link name of the element to set depending on the value of {@code exact} * @param exact whether the locator should match exactly */ private final String getRadio(final WebElement element) { return BooleanUtils.toString(element.isSelected(), "on", "off"); }
From source file:org.sinekartads.dto.domain.VerifyDTO.java
public void extractedToString(Boolean extracted) { this.extracted = BooleanUtils.toString(extracted, "true", "false"); }
From source file:org.talend.dataprep.transformation.actions.common.AbstractCompareAction.java
/** * * @param comparisonRequest/*ww w. j ava2s.c om*/ * @return transforming boolean to <code>true</code> or <code>false</code> as String in case of #doCompare returning * #ERROR_COMPARE_RESULT the label #ERROR_COMPARE_RESULT_LABEL is returned */ public String toStringCompareResult(ComparisonRequest comparisonRequest) { boolean booleanResult; try { final int result = doCompare(comparisonRequest); if (result == ERROR_COMPARE_RESULT) { return ERROR_COMPARE_RESULT_LABEL; } booleanResult = compareResultToBoolean(result, comparisonRequest.mode); } catch (NumberFormatException e) { LOGGER.debug("Unable to compare values '{}' ", comparisonRequest, e); return ERROR_COMPARE_RESULT_LABEL; } return BooleanUtils.toString(booleanResult, Boolean.TRUE.toString(), Boolean.FALSE.toString()); }