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:com.opengamma.language.view.ViewPrimitiveCycleValueFunction.java
@Override protected Object invokeImpl(SessionContext sessionContext, Object[] parameters) throws AsynchronousExecution { ViewComputationResultModel resultModel = (ViewComputationResultModel) parameters[0]; UniqueId targetId = (UniqueId) parameters[1]; Triple<String, String, ValueProperties> requirement = ValueRequirementUtils .parseRequirement((String) parameters[2]); String notAvailableValue = (String) parameters[3]; boolean flattenValue = BooleanUtils.isTrue((Boolean) parameters[4]); ComputationTargetSpecification target = new ComputationTargetSpecification(ComputationTargetType.PRIMITIVE, targetId);/*from w w w . ja va 2 s . c om*/ return invoke(resultModel, requirement.getFirst(), new ValueRequirement(requirement.getSecond(), target, requirement.getThird()), notAvailableValue, flattenValue); }
From source file:jp.primecloud.auto.api.instance.DescribeInstance.java
/** * * ??// w ww. ja v a 2s . com * @param userName ?? * @param farmNo ? * @param instanceNo ? * * @return DescribeInstanceResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public DescribeInstanceResponse describeInstance(@QueryParam(PARAM_NAME_USER) String userName, @QueryParam(PARAM_NAME_FARM_NO) String farmNo, @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) { DescribeInstanceResponse response = new DescribeInstanceResponse(); try { // ? //Key ApiValidate.validateUser(userName); //FarmNo ApiValidate.validateFarmNo(farmNo); // InstanceNo ApiValidate.validateInstanceNo(instanceNo); //? User user = userDao.readByUsername(userName); if (user == null) { // ???? throw new AutoApplicationException("EAPI-100000", "User", PARAM_NAME_USER, userName); } // ?? Instance instance = instanceDao.read(Long.parseLong(instanceNo)); if (instance == null || BooleanUtils.isTrue(instance.getLoadBalancer())) { // ???? or ?? throw new AutoApplicationException("EAPI-100000", "Instance", PARAM_NAME_INSTANCE_NO, instanceNo); } if (BooleanUtils.isFalse(instance.getFarmNo().equals(Long.parseLong(farmNo)))) { //????? throw new AutoApplicationException("EAPI-100022", "Instance", farmNo, PARAM_NAME_INSTANCE_NO, instanceNo); } //? Platform platform = platformDao.read(instance.getPlatformNo()); if (platform == null) { // ???? throw new AutoApplicationException("EAPI-100000", "Platform", PARAM_NAME_PLATFORM_NO, instance.getPlatformNo()); } // response = new DescribeInstanceResponse(instance); // TODO CLOUD BRANCHING if (PLATFORM_TYPE_AWS.equals(platform.getPlatformType())) { //AWS PlatformAws platformAws = platformAwsDao.read(instance.getPlatformNo()); AwsInstance awsInstance = awsInstanceDao.read(Long.parseLong(instanceNo)); if (awsInstance == null) { // AWS???? throw new AutoApplicationException("EAPI-100000", "AwsInstance", PARAM_NAME_INSTANCE_NO, instanceNo); } AwsInstanceResponse awsResponse = new AwsInstanceResponse(awsInstance); //SUBNET? if (StringUtils.isNotEmpty(awsInstance.getSubnetId())) { List<SubnetDto> subnets = iaasDescribeService.getSubnets(user.getUserNo(), platform.getPlatformNo(), platformAws.getVpcId()); for (SubnetDto subnet : subnets) { if (subnet.getSubnetId().equals(awsInstance.getSubnetId())) { awsResponse.setSubnet(subnet.getCidrBlock()); break; } } } //AWS response.setAws(awsResponse); } else if (PLATFORM_TYPE_CLOUDSTACK.equals(platform.getPlatformType())) { //CloudStack CloudstackInstance cloudstackInstance = cloudstackInstanceDao.read(Long.parseLong(instanceNo)); if (cloudstackInstance == null) { // CloudStack???? throw new AutoApplicationException("EAPI-100000", "CloudstackInstance", PARAM_NAME_INSTANCE_NO, instanceNo); } //CloudStack response.setCloudstack(new CloudstackInstanceResponse(cloudstackInstance)); } else if (PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())) { //VMWare VmwareInstance vmwareInstance = vmwareInstanceDao.read(Long.parseLong(instanceNo)); if (vmwareInstance == null) { // VMWare???? throw new AutoApplicationException("EAPI-100000", "VmwareInstance", PARAM_NAME_INSTANCE_NO, instanceNo); } VmwareInstanceResponse vmResponse = new VmwareInstanceResponse(vmwareInstance); //VMWARE_ADDRESS? VmwareAddress vmwareAddress = vmwareAddressDao.readByInstanceNo(Long.parseLong(instanceNo)); if (vmwareAddress != null && BooleanUtils.isTrue(vmwareAddress.getEnabled())) { vmResponse.setIsStaticIp(true); vmResponse.setSubnetMask(vmwareAddress.getSubnetMask()); vmResponse.setDefaultGateway(vmwareAddress.getDefaultGateway()); } else { vmResponse.setIsStaticIp(false); } //VMWARE_KEYPAIR? List<VmwareKeyPair> keyPairs = vmwareDescribeService.getKeyPairs(user.getUserNo(), instance.getPlatformNo()); for (VmwareKeyPair keyPair : keyPairs) { if (keyPair.getKeyNo().equals(vmwareInstance.getKeyPairNo())) { vmResponse.setKeyName(keyPair.getKeyName()); break; } } //VMWare response.setVmware(vmResponse); } else if (PLATFORM_TYPE_NIFTY.equals(platform.getPlatformType())) { //Nifty NiftyInstance niftyInstance = niftyInstanceDao.read(Long.parseLong(instanceNo)); if (niftyInstance == null) { // /Nifty???? throw new AutoApplicationException("EAPI-100000", "NiftyInstance", PARAM_NAME_INSTANCE_NO, instanceNo); } NiftyInstanceResponse niftyResponse = new NiftyInstanceResponse(niftyInstance); //NIFTY_KEYPAIR? List<NiftyKeyPair> keyPairs = niftyDescribeService.getKeyPairs(user.getUserNo(), instance.getPlatformNo()); for (NiftyKeyPair keyPair : keyPairs) { if (keyPair.getKeyNo().equals(niftyInstance.getKeyPairNo())) { niftyResponse.setKeyName(keyPair.getKeyName()); break; } } //Nifty response.setNifty(niftyResponse); } else if (PLATFORM_TYPE_VCLOUD.equals(platform.getPlatformType())) { //VCLOUD_INSTANCE VcloudInstance vcloudInstance = vcloudInstanceDao.read(Long.parseLong(instanceNo)); if (vcloudInstance == null) { // VMWare???? throw new AutoApplicationException("EAPI-100000", "VcloudInstance", PARAM_NAME_INSTANCE_NO, instanceNo); } VcloudInstanceResponse vcloudInstanceResponse = new VcloudInstanceResponse(vcloudInstance); //PLATFORM_VCLOUD_STORAGE_TYPE? List<PlatformVcloudStorageType> storageTypes = platformVcloudStorageTypeDao .readByPlatformNo(platform.getPlatformNo()); for (PlatformVcloudStorageType storageType : storageTypes) { if (storageType.getStorageTypeNo().equals(vcloudInstance.getStorageTypeNo())) { vcloudInstanceResponse.setStorageTypeName(storageType.getStorageTypeName()); break; } } //VCLOUD_KEYPAIR? List<KeyPairDto> keyPairs = iaasDescribeService.getKeyPairs(user.getUserNo(), instance.getPlatformNo()); for (KeyPairDto keyPair : keyPairs) { if (keyPair.getKeyNo().equals(vcloudInstance.getKeyPairNo())) { vcloudInstanceResponse.setKeyName(keyPair.getKeyName()); break; } } // VCloudNetwork? List<VcloudInstanceNetwork> vcloudInstanceNetworks = vcloudInstanceNetworkDao .readByInstanceNo(Long.parseLong(instanceNo)); for (VcloudInstanceNetwork vcloudInstanceNetwork : vcloudInstanceNetworks) { // VCloudNetwork VcloudInstanceNetworkResponse vcloudInstanceNetworkResponse = new VcloudInstanceNetworkResponse( vcloudInstanceNetwork); // if (BooleanUtils.isTrue(vcloudInstanceNetwork.getIsPrimary())) { vcloudInstanceNetworkResponse.setIsPrimary(true); } else { vcloudInstanceNetworkResponse.setIsPrimary(false); } vcloudInstanceResponse.addVcloudNetwok(vcloudInstanceNetworkResponse); } //VCloud response.setVcloud(vcloudInstanceResponse); } else if (PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType())) { //OpenStack OpenstackInstance openstackInstance = openstackInstanceDao.read(Long.parseLong(instanceNo)); if (openstackInstance == null) { // OpenStack???? throw new AutoApplicationException("EAPI-100000", "OpenstackInstance", PARAM_NAME_INSTANCE_NO, instanceNo); } //OpenStack response.setOpenstack(new OpenstackInstanceResponse(openstackInstance)); } else if (PLATFORM_TYPE_AZURE.equals(platform.getPlatformType())) { //Azure AzureInstance azureInstance = azureInstanceDao.read(Long.parseLong(instanceNo)); if (azureInstance == null) { // Azure???? throw new AutoApplicationException("EAPI-100000", "AzureInstance", PARAM_NAME_INSTANCE_NO, instanceNo); } //Azure response.setAzure(new AzureInstanceResponse(azureInstance)); } response.setSuccess(true); } catch (Throwable e) { String message = ""; if (e instanceof AutoException || e instanceof AutoApplicationException) { message = e.getMessage(); } else { message = MessageUtils.getMessage("EAPI-000000"); } log.error(message, e); response.setMessage(message); response.setSuccess(false); } return response; }
From source file:jp.primecloud.auto.component.windows.process.WindowsComponentProcess.java
@Override protected void configureInstances(final Long componentNo, final ComponentProcessContext context, final boolean start, List<Long> instanceNos) { Component component = componentDao.read(componentNo); List<Instance> instances = instanceDao.readInInstanceNos(instanceNos); Map<Long, Instance> instanceMap = new HashMap<Long, Instance>(); for (Instance instance : instances) { instanceMap.put(instance.getInstanceNo(), instance); }//from w ww .ja v a2 s . c o m List<ComponentInstance> componentInstances = componentInstanceDao.readByComponentNo(componentNo); Map<Long, ComponentInstance> componentInstanceMap = new HashMap<Long, ComponentInstance>(); for (ComponentInstance componentInstance : componentInstances) { componentInstanceMap.put(componentInstance.getInstanceNo(), componentInstance); } // ??????????? if (!start) { List<Long> tmpInstanceNos = new ArrayList<Long>(); for (Long instanceNo : instanceNos) { ComponentInstance componentInstance = componentInstanceMap.get(instanceNo); ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus()); if (status == ComponentInstanceStatus.STOPPED) { // ?? if (BooleanUtils.isTrue(componentInstance.getConfigure())) { componentInstance.setConfigure(false); componentInstanceDao.update(componentInstance); } } else { tmpInstanceNos.add(instanceNo); } } instanceNos = tmpInstanceNos; } if (instanceNos.isEmpty()) { return; } for (Long instanceNo : instanceNos) { ComponentInstance componentInstance = componentInstanceMap.get(instanceNo); ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus()); // if (start) { if (status == ComponentInstanceStatus.RUNNING) { status = ComponentInstanceStatus.CONFIGURING; } else { status = ComponentInstanceStatus.STARTING; } } else { status = ComponentInstanceStatus.STOPPING; } componentInstance.setStatus(status.toString()); componentInstanceDao.update(componentInstance); // if (BooleanUtils.isTrue(componentInstance.getConfigure())) { Instance instance = instanceMap.get(instanceNo); if (status == ComponentInstanceStatus.STARTING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentStart", null); } else if (status == ComponentInstanceStatus.CONFIGURING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentReload", null); } else if (status == ComponentInstanceStatus.STOPPING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentStop", null); } } } // ?? final Map<String, Object> rootMap = createComponentMap(componentNo, context, start); // List<Callable<Void>> callables = new ArrayList<Callable<Void>>(); final Map<String, Object> loggingContext = LoggingUtils.getContext(); for (final Long instanceNo : instanceNos) { Callable<Void> callable = new Callable<Void>() { @Override public Void call() throws Exception { LoggingUtils.setContext(loggingContext); try { doConfigureInstance(componentNo, context, start, instanceNo, rootMap); } catch (Exception e) { log.error(e.getMessage(), e); // eventLogger.error("SystemError", new Object[] { e.getMessage() }); throw e; } finally { LoggingUtils.removeContext(); } return null; } }; callables.add(callable); } try { List<Future<Void>> futures = executorService.invokeAll(callables); // ??? List<Throwable> throwables = new ArrayList<Throwable>(); for (Future<Void> future : futures) { try { future.get(); } catch (ExecutionException e) { throwables.add(e.getCause()); } catch (InterruptedException ignore) { } } // ?? if (throwables.size() > 0) { throw new MultiCauseException(throwables.toArray(new Throwable[throwables.size()])); } } catch (InterruptedException e) { } }
From source file:de.hybris.platform.acceleratorfacades.order.impl.DefaultAcceleratorCheckoutFacade.java
@Override public boolean isExpressCheckoutEnabledForStore() { if (getBaseStoreService().getCurrentBaseStore() != null) { return BooleanUtils.isTrue(getBaseStoreService().getCurrentBaseStore().getExpressCheckoutEnabled()); }/*from w w w. j a va 2 s. com*/ return false; }
From source file:com.redhat.rhn.frontend.xmlrpc.configchannel.XmlRpcConfigChannelHelper.java
/** * Creates a NEW path(file/directory) with the given path or updates an existing path * with the given contents in a given channel. * @param loggedInUser logged in user/* w ww. jav a 2 s .c o m*/ * @param channel the config channel who holds the file. * @param path the path of the given text file. * @param type the config file type * @param data a map containing properties pertaining to the given path.. * for directory paths - 'data' will hold values for -> * owner, group, permissions, revision, selinux_ctx * for file paths - 'data' will hold values for-> * contents, owner, group, permissions, selinux_ctx * macro-start-delimiter, macro-end-delimiter, revision * for symlinks paths - 'data' will hold values for-> * target_path, revision, selinux_ctx * @return returns the new created or updated config revision.. */ public ConfigRevision createOrUpdatePath(User loggedInUser, ConfigChannel channel, String path, ConfigFileType type, Map<String, Object> data) { ConfigFileData form; if (ConfigFileType.file().equals(type)) { try { if (BooleanUtils.isTrue((Boolean) data.get(ConfigRevisionSerializer.BINARY))) { byte[] content = Base64 .decodeBase64(((String) data.get(ConfigRevisionSerializer.CONTENTS)).getBytes("UTF-8")); if (content != null) { form = new BinaryFileData(new ByteArrayInputStream(content), content.length); } else { form = new BinaryFileData(new ByteArrayInputStream(new byte[0]), 0); } } else { // TEXT FILE String content; if (BooleanUtils.isTrue((Boolean) data.get(ConfigRevisionSerializer.CONTENTS_ENC64))) { content = new String( Base64.decodeBase64( ((String) data.get(ConfigRevisionSerializer.CONTENTS)).getBytes("UTF-8")), "UTF-8"); } else { content = (String) data.get(ConfigRevisionSerializer.CONTENTS); } form = new TextFileData(content); } } catch (UnsupportedEncodingException e) { String msg = "Following errors were encountered " + "when creating the config file.\n" + e.getMessage(); throw new FaultException(1023, "ConfgFileError", msg); } String startDelim = (String) data.get(ConfigRevisionSerializer.MACRO_START); String stopDelim = (String) data.get(ConfigRevisionSerializer.MACRO_END); if (!StringUtils.isBlank(startDelim)) { form.setMacroStart(startDelim); } if (!StringUtils.isBlank(stopDelim)) { form.setMacroEnd(stopDelim); } } else if (ConfigFileType.symlink().equals(type)) { form = new SymlinkData((String) data.get(ConfigRevisionSerializer.TARGET_PATH)); } else { form = new DirectoryData(); } form.setPath(path); if (!ConfigFileType.symlink().equals(type)) { form.setOwner((String) data.get(ConfigRevisionSerializer.OWNER)); form.setGroup((String) data.get(ConfigRevisionSerializer.GROUP)); form.setPermissions((String) data.get(ConfigRevisionSerializer.PERMISSIONS)); } String selinux = (String) data.get(ConfigRevisionSerializer.SELINUX_CTX); form.setSelinuxCtx(selinux == null ? "" : selinux); if (data.containsKey(ConfigRevisionSerializer.REVISION)) { form.setRevNumber(String.valueOf(data.get(ConfigRevisionSerializer.REVISION))); } ConfigFileBuilder helper = ConfigFileBuilder.getInstance(); try { return helper.createOrUpdate(form, loggedInUser, channel); } catch (ValidatorException ve) { String msg = "Following errors were encountered " + "when creating the config file.\n" + ve.getMessage(); throw new FaultException(1023, "ConfgFileError", msg); } catch (IOException ie) { String msg = "Error encountered when saving the config file. " + "Please retry. " + ie.getMessage(); throw new FaultException(1024, "ConfgFileError", msg); } }
From source file:de.hybris.platform.catalog.job.diff.impl.ProductPriceDiffFinder.java
/** * Returns true if product price difference should be done. */// www . j av a 2 s . co m private boolean shouldProcess(final CompareCatalogVersionsCronJobModel cronJobModel) { return BooleanUtils.isTrue(cronJobModel.getSearchPriceDifferences()); }
From source file:com.evolveum.midpoint.web.component.data.paging.NavigatorPanel.java
private void initFirst() { WebMarkupContainer first = new WebMarkupContainer(ID_FIRST); first.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() { @Override/*from ww w. j av a 2 s . c o m*/ public String getObject() { return isFirstEnabled() ? "" : "disabled"; } })); add(first); AjaxLink firstLink = new AjaxLink(ID_FIRST_LINK) { @Override public void onClick(AjaxRequestTarget target) { firstPerformed(target); } }; firstLink.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return BooleanUtils.isTrue(showPageListingModel.getObject()) && isFirstEnabled(); } }); first.add(firstLink); }
From source file:com.iorga.webappwatcher.watcher.RetentionLogWritingWatcher.java
protected void sendMailForEvent(final RetentionLogWritingEvent event) { log.info("Trying to send a mail for event " + event); new Thread(new Runnable() { @Override/*from w w w. j av a2 s.c om*/ public void run() { if (StringUtils.isEmpty(getMailSmtpHost()) || getMailSmtpPort() == null) { // no configuration defined, exiting log.error("Either SMTP host or port was not defined, not sending that mail"); return; } // example from http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ final Properties props = new Properties(); props.put("mail.smtp.host", getMailSmtpHost()); props.put("mail.smtp.port", getMailSmtpPort()); final Boolean auth = getMailSmtpAuth(); Authenticator authenticator = null; if (BooleanUtils.isTrue(auth)) { props.put("mail.smtp.auth", "true"); authenticator = new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(getMailSmtpUsername(), getMailSmtpPassword()); } }; } if (StringUtils.equalsIgnoreCase(getMailSmtpSecurityType(), "SSL")) { props.put("mail.smtp.socketFactory.port", getMailSmtpPort()); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); } else if (StringUtils.equalsIgnoreCase(getMailSmtpSecurityType(), "TLS")) { props.put("mail.smtp.starttls.enable", "true"); } final Session session = Session.getDefaultInstance(props, authenticator); try { final MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(getMailFrom())); message.setRecipients(RecipientType.TO, InternetAddress.parse(getMailTo())); message.setSubject(event.getReason()); if (event.getContext() != null) { final StringBuilder contextText = new StringBuilder(); for (final Entry<String, Object> contextEntry : event.getContext().entrySet()) { contextText.append(contextEntry.getKey()).append(" = ").append(contextEntry.getValue()) .append("\n"); } message.setText(contextText.toString()); } else { message.setText("Context null"); } Transport.send(message); } catch (final MessagingException e) { log.error("Problem while sending a mail", e); } } }, RetentionLogWritingWatcher.class.getSimpleName() + ":sendMailer").start(); // send mail in an async way }
From source file:jp.primecloud.auto.process.ProcessManager.java
protected void unscheduled(Long farmNo) { Farm farm = farmDao.read(farmNo);/*from w w w .ja va2 s . c o m*/ if (BooleanUtils.isTrue(farm.getScheduled())) { farm.setScheduled(false); farmDao.update(farm); } }
From source file:com.opengamma.web.portfolio.WebPortfoliosResource.java
private FlexiBean createSearchResultData(PagingRequest pr, PortfolioSearchSortOrder sort, String name, List<String> portfolioIdStrs, List<String> nodeIdStrs, Boolean includeHidden) { FlexiBean out = createRootData();/*from w w w . j ava 2s .c o m*/ PortfolioSearchRequest searchRequest = new PortfolioSearchRequest(); searchRequest.setPagingRequest(pr); searchRequest.setSortOrder(sort); searchRequest.setName(StringUtils.trimToNull(name)); searchRequest.setDepth(1); // see PLAT-1733, also, depth is set to 1 for knowing # of childNodes for UI tree searchRequest.setIncludePositions(true); // initially false because of PLAT-2012, now true for portfolio tree if (BooleanUtils.isTrue(includeHidden)) { searchRequest.setVisibility(DocumentVisibility.HIDDEN); } for (String portfolioIdStr : portfolioIdStrs) { searchRequest.addPortfolioObjectId(ObjectId.parse(portfolioIdStr)); } for (String nodeIdStr : nodeIdStrs) { searchRequest.addNodeObjectId(ObjectId.parse(nodeIdStr)); } out.put("searchRequest", searchRequest); if (data().getUriInfo().getQueryParameters().size() > 0) { PortfolioSearchResult searchResult = data().getPortfolioMaster().search(searchRequest); out.put("searchResult", searchResult); out.put("paging", new WebPaging(searchResult.getPaging(), data().getUriInfo())); } return out; }