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.api.component.EditComponent.java
/** * * //w w w. j a v a 2 s . co m * * @param uriInfo URI(InstanceNos??) * @param farmNo ? * @param componentNo ??? * @param diskSize * @param comment * @param customParam1 1(Puppet) * @param customParam2 2(Puppet) * @param customParam3 3(Puppet) * @return EditComponentResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public EditComponentResponse editComponent(@Context UriInfo uriInfo, @QueryParam(PARAM_NAME_FARM_NO) String farmNo, @QueryParam(PARAM_NAME_COMPONENT_NO) String componentNo, @QueryParam(PARAM_NAME_DISK_SIZE) String diskSize, @QueryParam(PARAM_NAME_COMMENT) String comment, @QueryParam(PARAM_NAME_CUSTOM_PARAM_1) String customParam1, @QueryParam(PARAM_NAME_CUSTOM_PARAM_2) String customParam2, @QueryParam(PARAM_NAME_CUSTOM_PARAM_3) String customParam3) { EditComponentResponse response = new EditComponentResponse(); try { // ? //FarmNo ApiValidate.validateFarmNo(farmNo); //ComponentNo ApiValidate.validateComponentNo(componentNo); //??? Component component = componentDao.read(Long.parseLong(componentNo)); if (component == null || BooleanUtils.isTrue(component.getLoadBalancer())) { // ?????? ??? ??? throw new AutoApplicationException("EAPI-100000", "Component", PARAM_NAME_COMPONENT_NO, componentNo); } if (BooleanUtils.isFalse(component.getFarmNo().equals(Long.parseLong(farmNo)))) { //??????? throw new AutoApplicationException("EAPI-100022", "Component", farmNo, PARAM_NAME_COMPONENT_NO, componentNo); } //Component?????ComponentInstance? List<ComponentInstance> componentInstances = componentInstanceDao .readByComponentNo(Long.parseLong(componentNo)); //ComponentStatus? ComponentStatus status = getComponentStatus(componentInstances); if (ComponentStatus.STOPPED != status) { // ????????? throw new AutoApplicationException("EAPI-100015", componentNo); } //DiskSize ApiValidate.validateDiskSize(diskSize); //Comments ApiValidate.validateComment(comment); //customParam1 ApiValidate.validateCustomParam1(customParam1); //customParam2 ApiValidate.validateCustomParam2(customParam2); //customParam3 ApiValidate.validateCustomParam3(customParam3); // componentService.updateComponent(Long.parseLong(componentNo), comment, Integer.parseInt(diskSize), customParam1, customParam2, customParam3); 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:de.hybris.platform.acceleratorservices.cronjob.SiteMapMediaJob.java
@Override public PerformResult perform(final SiteMapMediaCronJobModel cronJob) { final List<MediaModel> siteMapMedias = new ArrayList<MediaModel>(); final CMSSiteModel contentSite = cronJob.getContentSite(); getCmsSiteService().setCurrentSite(contentSite); // set the catalog version for the current session getActivateBaseSiteInSession().activate(contentSite); final SiteMapConfigModel siteMapConfig = contentSite.getSiteMapConfig(); final Collection<SiteMapPageModel> siteMapPages = siteMapConfig.getSiteMapPages(); for (final SiteMapPageModel siteMapPage : siteMapPages) { final List<File> siteMapFiles = new ArrayList<File>(); final SiteMapPageEnum pageType = siteMapPage.getCode(); final SiteMapGenerator generator = this.getGeneratorForSiteMapPage(pageType); if (BooleanUtils.isTrue(siteMapPage.getActive()) && generator != null) { final List models = generator.getData(contentSite); final Integer MAX_SITEMAP_LIMIT = cronJob.getSiteMapUrlLimitPerFile(); if (models.size() > MAX_SITEMAP_LIMIT.intValue()) { final List<List> modelsList = splitUpTheListIfExceededLimit(models, MAX_SITEMAP_LIMIT); for (int modelIndex = 0; modelIndex < modelsList.size(); modelIndex++) { generateSiteMapFiles(siteMapFiles, contentSite, generator, siteMapConfig, modelsList.get(modelIndex), pageType, Integer.valueOf(modelIndex)); }/*from w w w .ja va2 s . c o m*/ } else { generateSiteMapFiles(siteMapFiles, contentSite, generator, siteMapConfig, models, pageType, null); } } else { LOG.warn(String.format("Skipping SiteMap page %s active %s", siteMapPage.getCode(), siteMapPage.getActive())); } if (!siteMapFiles.isEmpty()) { for (final File siteMapFile : siteMapFiles) { siteMapMedias.add(createCatalogUnawareMediaModel(siteMapFile)); } } } if (!siteMapMedias.isEmpty()) { final Collection<MediaModel> existingSiteMaps = contentSite.getSiteMaps(); contentSite.setSiteMaps(siteMapMedias); modelService.save(contentSite); // clean up old sitemap medias if (CollectionUtils.isNotEmpty(existingSiteMaps)) { modelService.removeAll(existingSiteMaps); } } return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED); }
From source file:jp.primecloud.auto.tool.management.main.ConfigMain.java
public static void getPlatformNo(String platformName, String platformKind) { try {/*w ww .j av a2 s. c om*/ String platformSql = "SELECT * FROM PLATFORM"; List<Platform> platforms = SQLMain.selectExecuteWithResult(platformSql, Platform.class); if (platforms == null || platforms.isEmpty()) { System.out.println("NULL"); return; } for (Platform platform : platforms) { if (StringUtils.equals(platform.getPlatformName(), platformName)) { if (BooleanUtils.isNotTrue(platform.getSelectable())) { //??? System.out.println("DISABLE"); return; } String platformAwsSql = "SELECT * FROM PLATFORM_AWS WHERE PLATFORM_NO=" + platform.getPlatformNo(); List<PlatformAws> platformAwses = SQLMain.selectExecuteWithResult(platformAwsSql, PlatformAws.class); if ("ec2".equals(platformKind) && "aws".equals(platform.getPlatformType()) && BooleanUtils.isFalse(platformAwses.get(0).getEuca())) { System.out.println(platform.getPlatformNo().toString()); return; } else if ("vmware".equals(platformKind) && "vmware".equals(platform.getPlatformType())) { System.out.println(platform.getPlatformNo().toString()); return; } else if ("eucalyptus".equals(platformKind) && "aws".equals(platform.getPlatformType()) && BooleanUtils.isTrue(platformAwses.get(0).getEuca())) { System.out.println(platform.getPlatformNo().toString()); return; } else if ("nifty".equals(platformKind) && "nifty".equals(platform.getPlatformType())) { System.out.println(platform.getPlatformNo().toString()); return; } else if ("cloudstack".equals(platformKind) && "cloudstack".equals(platform.getPlatformType())) { System.out.println(platform.getPlatformNo().toString()); return; } else if ("vcloud".equals(platformKind) && "vcloud".equals(platform.getPlatformType())) { System.out.println(platform.getPlatformNo().toString()); return; } else if ("azure".equals(platformKind) && "azure".equals(platform.getPlatformType())) { System.out.println(platform.getPlatformNo().toString()); return; } else if ("openstack".equals(platformKind) && "openstack".equals(platform.getPlatformType())) { System.out.println(platform.getPlatformNo().toString()); return; } } } System.out.println("OTHER"); } catch (Exception e) { e.printStackTrace(); log.error(e.getMessage(), e); } }
From source file:com.haulmont.cuba.gui.app.core.categories.CategoryEditor.java
protected void initIsDefaultCheckbox() { isDefault.setValue(BooleanUtils.isTrue(category.getIsDefault())); isDefault.addValueChangeListener(e -> { if (Boolean.TRUE.equals(e.getValue())) { LoadContext<Category> lc = new LoadContext<>(Category.class).setView("category.defaultEdit"); lc.setQueryString(//from w w w . jav a 2 s. c o m "select c from sys$Category c where c.entityType = :entityType and not c.id = :id") .setParameter("entityType", category.getEntityType()).setParameter("id", category.getId()); List<Category> result = dataManager.loadList(lc); for (Category cat : result) { cat.setIsDefault(false); } CommitContext commitCtx = new CommitContext(result); dataManager.commit(commitCtx); category.setIsDefault(true); } else if (Boolean.FALSE.equals(e.getValue())) { category.setIsDefault(false); } }); }
From source file:com.haulmont.cuba.gui.app.core.scheduled.ScheduledTaskBrowser.java
protected boolean checkAllTasksHaveSameStatus(Set<ScheduledTask> tasks) { if (!tasks.isEmpty()) { boolean firstItemState = BooleanUtils.isTrue(tasks.iterator().next().getActive()); for (ScheduledTask task : tasks) { if (BooleanUtils.isTrue(task.getActive()) != firstItemState) { return false; }/*from w w w. java 2s. c o m*/ } return true; } else { return false; } }
From source file:com.redhat.rhn.frontend.action.multiorg.ExtGroupDetailAction.java
/** {@inheritDoc} */ @Override//w w w. j a v a2s . co m public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) { RequestContext ctx = new RequestContext(request); User user = ctx.getCurrentUser(); Long gid = ctx.getParamAsLong("gid"); UserExtGroup extGroup = null; if (gid != null) { ctx.copyParamToAttributes("gid"); extGroup = UserGroupFactory.lookupExtGroupById(gid); request.setAttribute("group", extGroup); } if (ctx.isSubmitted()) { DynaActionForm form = (DynaActionForm) formIn; ValidatorResult result = RhnValidationHelper.validate(this.getClass(), makeValidationMap(form), null, VALIDATION_XSD); if (!result.isEmpty()) { getStrutsDelegate().saveMessages(request, result); setupRoles(request, user, extGroup); return mapping.findForward(RhnHelper.DEFAULT_FORWARD); } String label = (String) form.get("extGroupLabel"); Boolean satAdm = (Boolean) form.get("role_satellite_admin"); Boolean orgAdm = (Boolean) form.get("role_org_admin"); String selectedRoles = (String) form.get("selected_regular_roles"); Set<Role> roles = new HashSet<Role>(); if (BooleanUtils.isTrue(satAdm)) { roles.add(RoleFactory.SAT_ADMIN); } if (BooleanUtils.isTrue(orgAdm)) { roles.add(RoleFactory.ORG_ADMIN); } else { for (String roleString : selectedRoles.split(" ")) { if (!StringUtils.isEmpty(roleString)) { roles.add(RoleFactory.lookupByLabel(roleString)); } } } if (extGroup == null) { extGroup = new UserExtGroup(); } if (!label.equals(extGroup.getLabel())) { if (UserGroupFactory.lookupExtGroupByLabel(label) != null) { createErrorMessage(request, "extgrouplabel.already.exists", label); setupRoles(request, user, extGroup); return mapping.findForward(RhnHelper.DEFAULT_FORWARD); } } extGroup.setLabel(label); extGroup.setRoles(roles); UserGroupFactory.save(extGroup); if (gid == null) { createSuccessMessage(request, "message.extgroup.created", label); } else { createSuccessMessage(request, "message.extgroup.updated", label); } return mapping.findForward("success"); } // not submitted setupRoles(request, user, extGroup); return mapping.findForward(RhnHelper.DEFAULT_FORWARD); }
From source file:jp.primecloud.auto.api.component.StopComponent.java
/** * * ?/*from www. j a v a2 s.co m*/ * * @param uriInfo URI(InstanceNo??) * @param farmNo ? * @param componentNo ??? * @param instanceNos ?(?) * @param isStopInstance ?? true:???false:??? * @return StopComponentResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public StopComponentResponse stopComponent(@Context UriInfo uriInfo, @QueryParam(PARAM_NAME_FARM_NO) String farmNo, @QueryParam(PARAM_NAME_COMPONENT_NO) String componentNo, @QueryParam(PARAM_NAME_INSTANCE_NOS) String instanceNos, @QueryParam(PARAM_NAME_IS_STOP_INSTANCE) String isStopInstance) { StopComponentResponse response = new StopComponentResponse(); try { // ? // FarmNo ApiValidate.validateFarmNo(farmNo); // ComponentNo ApiValidate.validateComponentNo(componentNo); // IsStopInstance ApiValidate.validateIsStopInstance(isStopInstance); // InstanceNo List<Long> instanceNoList = createInstanceNosToList(instanceNos); // ? Farm farm = farmDao.read(Long.parseLong(farmNo)); if (farm == null) { // ???? throw new AutoApplicationException("EAPI-100000", "Farm", PARAM_NAME_FARM_NO, farmNo); } // ? for (Long instanceNo : instanceNoList) { Instance instance = instanceDao.read(instanceNo); if (instance == null || BooleanUtils.isTrue(instance.getLoadBalancer())) { // ???? or ?? throw new AutoApplicationException("EAPI-100000", "Instance", PARAM_NAME_INSTANCE_NO, instanceNo); } } // ??? Component component = componentDao.read(Long.parseLong(componentNo)); if (component == null || BooleanUtils.isTrue(component.getLoadBalancer())) { // ?????? ??? ??? throw new AutoApplicationException("EAPI-100000", "Component", PARAM_NAME_COMPONENT_NO, componentNo); } // ??? for (Long instanceNo : instanceNoList) { ComponentInstance componentInstance = componentInstanceDao.read(Long.parseLong(componentNo), instanceNo); if (componentInstance == null) { // ?????? throw new AutoApplicationException("EAPI-100000", "ComponentInstance", PARAM_NAME_INSTANCE_NO, instanceNo); } } if (BooleanUtils.isFalse(component.getFarmNo().equals(Long.parseLong(farmNo)))) { //??????? throw new AutoApplicationException("EAPI-100022", "Component", farmNo, PARAM_NAME_COMPONENT_NO, componentNo); } // ? if (StringUtils.isEmpty(isStopInstance)) { processService.stopComponents(Long.parseLong(farmNo), Long.parseLong(componentNo), instanceNoList, false); } else { processService.stopComponents(Long.parseLong(farmNo), Long.parseLong(componentNo), instanceNoList, Boolean.parseBoolean(isStopInstance)); } 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:com.haulmont.cuba.web.gui.components.presentations.PresentationEditor.java
protected void initLayout() { ThemeConstants theme = App.getInstance().getThemeConstants(); VerticalLayout root = new VerticalLayout(); root.setWidthUndefined();// w w w . j a va 2s .c om root.setSpacing(true); setContent(root); messages = AppBeans.get(Messages.class); nameField = new TextField(messages.getMainMessage("PresentationsEditor.name")); nameField.setWidth(theme.get("cuba.web.PresentationEditor.name.width")); nameField.setValue(getPresentationCaption()); root.addComponent(nameField); autoSaveField = new CheckBox(); autoSaveField.setCaption(messages.getMainMessage("PresentationsEditor.autoSave")); autoSaveField.setValue(BooleanUtils.isTrue(presentation.getAutoSave())); root.addComponent(autoSaveField); defaultField = new CheckBox(); defaultField.setCaption(messages.getMainMessage("PresentationsEditor.default")); defaultField.setValue(presentation.getId().equals(component.getDefaultPresentationId())); root.addComponent(defaultField); if (allowGlobalPresentations) { globalField = new CheckBox(); globalField.setCaption(messages.getMainMessage("PresentationsEditor.global")); globalField.setValue(!isNew && presentation.getUser() == null); root.addComponent(globalField); } HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.setWidthUndefined(); root.addComponent(buttons); root.setComponentAlignment(buttons, Alignment.MIDDLE_LEFT); Button commitButton = new CubaButton(messages.getMainMessage("PresentationsEditor.save")); commitButton.addClickListener(event -> { if (validate()) { commit(); close(); } }); buttons.addComponent(commitButton); Button closeButton = new CubaButton(messages.getMainMessage("PresentationsEditor.close")); closeButton.addClickListener(event -> { close(); }); buttons.addComponent(closeButton); nameField.focus(); }
From source file:com.evolveum.midpoint.gui.api.util.FocusTabVisibleBehavior.java
@Override public boolean isVisible() { PrismObject obj = objectModel.getObject(); if (obj == null) { return true; }/* ww w . j a v a2 s. co m*/ QName type = obj.getDefinition().getTypeName(); Task task = WebModelServiceUtils.createSimpleTask(OPERATION_LOAD_GUI_CONFIGURATION, SecurityUtils.getPrincipalUser().getUser().asPrismObject(), getTaskManager()); OperationResult result = task.getResult(); AdminGuiConfigurationType config; try { config = getModelInteractionService().getAdminGuiConfiguration(task, result); } catch (ObjectNotFoundException | SchemaException e) { throw new SystemException("Cannot load GUI configuration: " + e.getMessage(), e); } // find all object form definitions for specified type, if there is none we'll show all default tabs List<ObjectFormType> forms = findObjectForm(config, type); if (forms.isEmpty()) { return true; } // we'll try to find includeDefault, if there is includeDefault=true, we can return true (all tabs visible) for (ObjectFormType form : forms) { if (BooleanUtils.isTrue(form.isIncludeDefaultForms())) { return true; } } for (ObjectFormType form : forms) { FormSpecificationType spec = form.getFormSpecification(); if (spec == null || StringUtils.isEmpty(spec.getPanelUri())) { continue; } if (ObjectUtils.equals(uiAuthorizationUrl, spec.getPanelUri())) { return true; } } return false; }
From source file:jp.primecloud.auto.api.instance.EditInstanceNifty.java
/** * * ?(Nifty)/*w w w. j ava 2 s.c om*/ * @param userName PCC?? * @param farmNo ? * @param instanceNo ? * @param instanceType * @param keyName ?? * @param comment * * @return EditInstanceNiftyResponse */ @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public EditInstanceNiftyResponse editInstanceNifty(@Context UriInfo uriInfo, @QueryParam(PARAM_NAME_USER) String userName, @QueryParam(PARAM_NAME_FARM_NO) String farmNo, @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo, @QueryParam(PARAM_NAME_INSTANCE_TYPE) String instanceType, @QueryParam(PARAM_NAME_KEY_NAME) String keyName, @QueryParam(PARAM_NAME_COMMENT) String comment) { EditInstanceNiftyResponse response = new EditInstanceNiftyResponse(); 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", "UserName", 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); } InstanceStatus status = InstanceStatus.fromStatus(instance.getStatus()); if (InstanceStatus.STOPPED != status) { // ??? throw new AutoApplicationException("EAPI-100014", 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()); } if (!PLATFORM_TYPE_NIFTY.equals(platform.getPlatformType())) { //?Nifty throw new AutoApplicationException("EAPI-100031", "Nifty", instanceNo, instance.getPlatformNo()); } // ? Image image = imageDao.read(instance.getImageNo()); if (image == null || image.getPlatformNo().equals(platform.getPlatformNo()) == false) { // ???? throw new AutoApplicationException("EAPI-100000", "Image", PARAM_NAME_IMAGE_NO, instance.getImageNo()); } // InstanceType ApiValidate.validateInstanceType(instanceType, true); if (checkInstanceType(platform, image, instanceType) == false) { // ????????? throw new AutoApplicationException("EAPI-000011", instance.getImageNo(), instanceType); } // KeyName ApiValidate.validateKeyName(keyName); Long keyPairNo = getKeyPairNo(user.getUserNo(), platform.getPlatformNo(), keyName); if (keyPairNo == null) { // ????? throw new AutoApplicationException("EAPI-000012", platform.getPlatformNo(), keyName); } // Comment ApiValidate.validateComment(comment); //(VMware)? instanceService.updateNiftyInstance(Long.parseLong(instanceNo), instance.getInstanceName(), comment, instanceType, keyPairNo); response.setSuccess(true); } catch (Throwable e) { String message = ""; if (StringUtils.isEmpty(e.getMessage())) { message = MessageUtils.getMessage("EAPI-000000"); } else { message = e.getMessage(); } log.error(message, e); response.setMessage(message); response.setSuccess(false); } return response; }