Example usage for org.apache.commons.lang BooleanUtils isNotTrue

List of usage examples for org.apache.commons.lang BooleanUtils isNotTrue

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils isNotTrue.

Prototype

public static boolean isNotTrue(Boolean bool) 

Source Link

Document

Checks if a Boolean value is not true, handling null by returning true.

 BooleanUtils.isNotTrue(Boolean.TRUE)  = false BooleanUtils.isNotTrue(Boolean.FALSE) = true BooleanUtils.isNotTrue(null)          = true 

Usage

From source file:jp.primecloud.auto.process.lb.ComponentLoadBalancerProcess.java

public void configure(Long loadBalancerNo) {
    LoadBalancer loadBalancer = loadBalancerDao.read(loadBalancerNo);

    if (log.isInfoEnabled()) {
        log.info(//  w  w  w .  j  a  v a2  s .co m
                MessageUtils.getMessage("IPROCESS-200205", loadBalancerNo, loadBalancer.getLoadBalancerName()));
    }

    ComponentLoadBalancer componentLoadBalancer = componentLoadBalancerDao.read(loadBalancerNo);

    // ???????????
    List<Long> instanceNos = getInstanceNos(loadBalancerNo);

    try {
        // ???????
        if (BooleanUtils.isNotTrue(loadBalancer.getEnabled())) {
            List<ZabbixInstance> zabbixInstances = zabbixInstanceDao.readInInstanceNos(instanceNos);
            for (ZabbixInstance zabbixInstance : zabbixInstances) {
                zabbixHostProcess.stopTemplate(zabbixInstance.getInstanceNo(),
                        componentLoadBalancer.getComponentNo());
            }
        }

        // ?
        puppetLoadBalancerProcess.configure(loadBalancerNo, componentLoadBalancer.getComponentNo(),
                instanceNos);

        // ??????
        if (BooleanUtils.isTrue(loadBalancer.getEnabled())) {
            List<ZabbixInstance> zabbixInstances = zabbixInstanceDao.readInInstanceNos(instanceNos);
            for (ZabbixInstance zabbixInstance : zabbixInstances) {
                zabbixHostProcess.startTemplate(zabbixInstance.getInstanceNo(),
                        componentLoadBalancer.getComponentNo());
            }
        }
    } catch (RuntimeException e) {
        loadBalancer = loadBalancerDao.read(loadBalancerNo);

        // ?
        List<LoadBalancerListener> listeners = loadBalancerListenerDao.readByLoadBalancerNo(loadBalancerNo);
        for (LoadBalancerListener listener : listeners) {
            LoadBalancerListenerStatus status;
            if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(listener.getEnabled())) {
                status = LoadBalancerListenerStatus.WARNING;
            } else {
                status = LoadBalancerListenerStatus.STOPPED;
            }

            if (status != LoadBalancerListenerStatus.fromStatus(listener.getStatus())
                    || BooleanUtils.isTrue(listener.getConfigure())) {
                listener.setStatus(status.toString());
                listener.setConfigure(false);
                loadBalancerListenerDao.update(listener);
            }
        }

        // ??
        List<LoadBalancerInstance> lbInstances = loadBalancerInstanceDao.readByLoadBalancerNo(loadBalancerNo);
        List<Long> targetInstanceNos = new ArrayList<Long>();
        for (LoadBalancerInstance lbInstance : lbInstances) {
            targetInstanceNos.add(lbInstance.getInstanceNo());
        }
        List<Instance> targetInstances = instanceDao.readInInstanceNos(targetInstanceNos);
        Map<Long, Instance> targetInstanceMap = new HashMap<Long, Instance>();
        for (Instance targetInstance : targetInstances) {
            targetInstanceMap.put(targetInstance.getInstanceNo(), targetInstance);
        }

        for (LoadBalancerInstance lbInstance : lbInstances) {
            LoadBalancerInstanceStatus status;
            Instance targetInstance = targetInstanceMap.get(lbInstance.getInstanceNo());
            if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(lbInstance.getEnabled())
                    && BooleanUtils.isTrue(targetInstance.getEnabled())) {
                status = LoadBalancerInstanceStatus.WARNING;
            } else {
                status = LoadBalancerInstanceStatus.STOPPED;
            }

            if (status != LoadBalancerInstanceStatus.fromStatus(lbInstance.getStatus())) {
                lbInstance.setStatus(status.toString());
                loadBalancerInstanceDao.update(lbInstance);
            }
        }

        throw e;
    }

    // ?
    List<LoadBalancerListener> listeners = loadBalancerListenerDao.readByLoadBalancerNo(loadBalancerNo);
    for (LoadBalancerListener listener : listeners) {
        LoadBalancerListenerStatus status;
        if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(listener.getEnabled())) {
            status = LoadBalancerListenerStatus.RUNNING;
        } else {
            status = LoadBalancerListenerStatus.STOPPED;
        }

        if (status != LoadBalancerListenerStatus.fromStatus(listener.getStatus())
                || BooleanUtils.isTrue(listener.getConfigure())) {
            listener.setStatus(status.toString());
            listener.setConfigure(false);
            loadBalancerListenerDao.update(listener);
        }
    }

    // ??
    List<LoadBalancerInstance> lbInstances = loadBalancerInstanceDao.readByLoadBalancerNo(loadBalancerNo);
    List<Long> targetInstanceNos = new ArrayList<Long>();
    for (LoadBalancerInstance lbInstance : lbInstances) {
        targetInstanceNos.add(lbInstance.getInstanceNo());
    }
    List<Instance> targetInstances = instanceDao.readInInstanceNos(targetInstanceNos);
    Map<Long, Instance> targetInstanceMap = new HashMap<Long, Instance>();
    for (Instance targetInstance : targetInstances) {
        targetInstanceMap.put(targetInstance.getInstanceNo(), targetInstance);
    }

    for (LoadBalancerInstance lbInstance : lbInstances) {
        LoadBalancerInstanceStatus status;
        Instance targetInstance = targetInstanceMap.get(lbInstance.getInstanceNo());
        if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(lbInstance.getEnabled())
                && BooleanUtils.isTrue(targetInstance.getEnabled())) {
            status = LoadBalancerInstanceStatus.RUNNING;
        } else {
            status = LoadBalancerInstanceStatus.STOPPED;
        }

        if (status != LoadBalancerInstanceStatus.fromStatus(lbInstance.getStatus())) {
            lbInstance.setStatus(status.toString());
            loadBalancerInstanceDao.update(lbInstance);
        }
    }

    if (log.isInfoEnabled()) {
        log.info(
                MessageUtils.getMessage("IPROCESS-200206", loadBalancerNo, loadBalancer.getLoadBalancerName()));
    }
}

From source file:jp.primecloud.auto.api.lb.EditLoadBalancerAutoScaling.java

/**
 *
 * ?  // w w w.  ja  v a2 s  . co m
 *
 * @param userName ??
 * @param farmNo ?
 * @param loadBalancerNo ??
 * @param enabled /
 * @param platformNo ?
 * @param imageNo ?
 * @param instanceType 
 * @param namingRule ?(????)
 * @param idleTimeMax CPU(%)
 * @param idleTimeMin CPU(%)
 * @param continueLimit ()
 * @param addCount ?(?)
 * @param delCount ?(?)
 *
 * @return EditLoadBalancerAutoScalingResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public EditLoadBalancerAutoScalingResponse editLoadBalancer(@QueryParam(PARAM_NAME_USER) String userName,
        @QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo,
        @QueryParam(PARAM_NAME_ENABLED) String enabled, @QueryParam(PARAM_NAME_PLATFORM_NO) String platformNo,
        @QueryParam(PARAM_NAME_IMAGE_NO) String imageNo,
        @QueryParam(PARAM_NAME_INSTANCE_TYPE) String instanceType,
        @QueryParam(PARAM_NAME_NAMING_RULE) String namingRule,
        @QueryParam(PARAM_NAME_IDLE_TIME_MAX) String idleTimeMax,
        @QueryParam(PARAM_NAME_IDLE_TIME_MIN) String idleTimeMin,
        @QueryParam(PARAM_NAME_CONTINUE_LIMIT) String continueLimit,
        @QueryParam(PARAM_NAME_ADD_COUNT) String addCount, @QueryParam(PARAM_NAME_DEL_COUNT) String delCount) {

    EditLoadBalancerAutoScalingResponse response = new EditLoadBalancerAutoScalingResponse();

    try {
        // ?
        // Key(??)
        ApiValidate.validateUser(userName);
        User user = userDao.readByUsername(userName);
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // LoadBalancerNo
        ApiValidate.validateLoadBalancerNo(loadBalancerNo);

        LoadBalancer loadBalancer = loadBalancerDao.read(Long.parseLong(loadBalancerNo));
        if (loadBalancer == null) {
            // ?????
            throw new AutoApplicationException("EAPI-100000", "LoadBalancer", PARAM_NAME_LOAD_BALANCER_NO,
                    loadBalancerNo);
        }
        if (!loadBalancer.getFarmNo().equals(Long.parseLong(farmNo))) {
            //??????
            throw new AutoApplicationException("EAPI-100022", "LoadBalancer", farmNo,
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo);
        }

        // Enabled
        ApiValidate.validateEnabled(enabled);

        if (Boolean.valueOf(enabled)) {
            //Enabled?true??
            //PlatformNo
            ApiValidate.validatePlatformNo(platformNo);

            //?
            Platform platform = platformDao.read(Long.parseLong(platformNo));
            if (platform == null) {
                //????
                throw new AutoApplicationException("EAPI-100000", "Platform", PARAM_NAME_PLATFORM_NO,
                        platformNo);
            }
            if (!platformService.isUseablePlatforms(user.getUserNo(), platform)
                    || BooleanUtils.isNotTrue(platform.getSelectable())) {
                //????? or ????
                throw new AutoApplicationException("EAPI-000020", "Platform", PARAM_NAME_PLATFORM_NO,
                        platformNo);
            }

            Platform lbPlatform = platformDao.read(loadBalancer.getPlatformNo());
            if (PLATFORM_TYPE_AWS.equals(lbPlatform.getPlatformType())) {
                PlatformAws platformAws = platformAwsDao.read(loadBalancer.getPlatformNo());
                if (!platformAws.getEuca() && platformAws.getVpc()) {
                    //??EC2+VPC??????
                    if (!lbPlatform.getPlatformNo().equals(platform.getPlatformNo())) {
                        throw new AutoApplicationException("EAPI-100036", loadBalancer.getLoadBalancerName(),
                                loadBalancer.getLoadBalancerNo(), platform.getPlatformNo());
                    }
                }
            }

            //ImageNo
            ApiValidate.validateImageNo(imageNo);
            Image image = imageDao.read(Long.parseLong(imageNo));
            if (image == null || !image.getPlatformNo().equals(platform.getPlatformNo())) {
                //???? or ?????
                throw new AutoApplicationException("EAPI-100000", "Image", PARAM_NAME_IMAGE_NO, imageNo);
            }
            if (BooleanUtils.isNotTrue(image.getSelectable())) {
                //???
                throw new AutoApplicationException("EAPI-000020", "Image", PARAM_NAME_IMAGE_NO, imageNo);
            }
            //InstanceType
            ApiValidate.validateInstanceType(instanceType, true);
            List<String> instanceTypes = getInstanceTypes(platform, image);
            if (!instanceTypes.contains(instanceType)) {
                // ?????????
                throw new AutoApplicationException("EAPI-000011", imageNo, instanceType);
            }
            //NamingRule
            ApiValidate.validateNamingRule(namingRule);
            namingRule = namingRule + "%d";
            //IdleTimeMax
            ApiValidate.validateIdleTimeMax(idleTimeMax);
            //IdleTimeMin
            ApiValidate.validateIdleTimeMin(idleTimeMin);
            //ContinueLimit
            ApiValidate.validateContinueLimit(continueLimit);
            //AddCount
            ApiValidate.validateAddCount(addCount);
            //DelCount
            ApiValidate.validateDelCount(delCount);
        }

        LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus());
        if (LoadBalancerStatus.WARNING == status) {
            // ? ? Warning
            throw new AutoApplicationException("EAPI-100025", loadBalancerNo);
        }

        // 
        if (Boolean.valueOf(enabled)) {
            //
            loadBalancerService.updateAutoScalingConf(loadBalancer.getFarmNo(), Long.parseLong(loadBalancerNo),
                    Long.parseLong(platformNo), Long.parseLong(imageNo), instanceType,
                    Boolean.parseBoolean(enabled) ? 1 : 0, namingRule, Long.parseLong(idleTimeMax),
                    Long.parseLong(idleTimeMin), Long.parseLong(continueLimit), Long.parseLong(addCount),
                    Long.parseLong(delCount));
        } else {
            //
            AutoScalingConf autoScalingConf = autoScalingConfDao.read(Long.parseLong(loadBalancerNo));
            loadBalancerService.updateAutoScalingConf(loadBalancer.getFarmNo(), Long.parseLong(loadBalancerNo),
                    autoScalingConf.getPlatformNo(), autoScalingConf.getImageNo(),
                    autoScalingConf.getInstanceType(), Boolean.parseBoolean(enabled) ? 1 : 0,
                    autoScalingConf.getNamingRule(), autoScalingConf.getIdleTimeMax(),
                    autoScalingConf.getIdleTimeMin(), autoScalingConf.getContinueLimit(),
                    autoScalingConf.getAddCount(), autoScalingConf.getDelCount());
        }

        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.gui.app.core.categories.CategoryAttrsFrame.java

protected void initDefaultValueColumn() {
    categoryAttrsTable.addGeneratedColumn("defaultValue", new Table.ColumnGenerator<CategoryAttribute>() {
        @Override//w  ww.  ja  va 2  s  . com
        public Component generateCell(CategoryAttribute attribute) {
            String defaultValue = "";

            if (BooleanUtils.isNotTrue(attribute.getIsEntity())) {
                PropertyType dataType = attribute.getDataType();
                switch (dataType) {
                case DATE:
                    Date date = attribute.getDefaultDate();
                    if (date != null) {
                        String dateTimeFormat = Datatypes.getFormatStringsNN(userSessionSource.getLocale())
                                .getDateTimeFormat();
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateTimeFormat);
                        defaultValue = simpleDateFormat.format(date);
                    } else if (BooleanUtils.isTrue(attribute.getDefaultDateIsCurrent())) {
                        defaultValue = getMessage("currentDate");
                    }
                    break;
                case BOOLEAN:
                    Boolean b = attribute.getDefaultBoolean();
                    if (b != null)
                        defaultValue = BooleanUtils.isTrue(b) ? getMessage("msgTrue") : getMessage("msgFalse");
                    break;
                default:
                    if (attribute.getDefaultValue() != null)
                        defaultValue = attribute.getDefaultValue().toString();
                }
            } else {
                Class entityClass = attribute.getJavaClassForEntity();
                if (entityClass != null) {
                    defaultValue = "";
                    if (attribute.getObjectDefaultEntityId() != null) {
                        MetaClass metaClass = metadata.getClassNN(entityClass);
                        LoadContext<Entity> lc = new LoadContext<>(entityClass).setView(View.MINIMAL);
                        String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass);
                        lc.setQueryString(format("select e from %s e where e.%s = :entityId",
                                metaClass.getName(), pkName))
                                .setParameter("entityId", attribute.getObjectDefaultEntityId());
                        Entity entity = dataManager.load(lc);
                        if (entity != null) {
                            defaultValue = InstanceUtils.getInstanceName(entity);
                        }
                    }
                } else {
                    defaultValue = getMessage("entityNotFound");
                }
            }

            Label defaultValueLabel = factory.createComponent(Label.class);
            defaultValueLabel.setValue(defaultValue);
            return defaultValueLabel;
        }
    });
}

From source file:jp.primecloud.auto.process.lb.PuppetLoadBalancerProcess.java

protected void configureInstance(Long loadBalancerNo, Long componentNo, Long instanceNo,
        Map<String, Object> rootMap) {
    LoadBalancer loadBalancer = loadBalancerDao.read(loadBalancerNo);
    Component component = componentDao.read(componentNo);
    Instance instance = instanceDao.read(instanceNo);

    // /*from   w  ww  .  j a va  2s.c  om*/
    Map<String, Object> instanceMap = createInstanceMap(instanceNo);
    rootMap.putAll(instanceMap);

    // 
    ComponentType componentType = componentTypeDao.read(component.getComponentTypeNo());
    File manifestFile = new File(manifestDir, instance.getFqdn() + "." + component.getComponentName() + ".pp");

    // ?
    restoreManifest(manifestFile);

    // ????
    String digest = getFileDigest(manifestFile, "UTF-8");

    // ??????????
    if (digest == null && BooleanUtils.isNotTrue(loadBalancer.getEnabled())) {
        return;
    }

    // ??
    String templateName = "loadBalancer_" + componentType.getComponentTypeName() + ".ftl";
    generateManifest(templateName, rootMap, manifestFile, "UTF-8");

    // ?????
    if (digest != null) {
        String newDigest = getFileDigest(manifestFile, "UTF-8");
        if (digest.equals(newDigest)) {
            // ?????
            if (log.isDebugEnabled()) {
                log.debug(MessageUtils.format("Not changed manifest.(file={0})", manifestFile.getName()));
            }
            return;
        }
    }

    // Puppet?
    try {
        runPuppet(instance, component);
    } finally {
        if (BooleanUtils.isTrue(loadBalancer.getEnabled())) {
            // ??
            backupManifest(manifestFile);
        } else {
            // ?
            deleteManifest(manifestFile);
        }
    }
}

From source file:com.haulmont.cuba.web.app.folders.FolderEditWindow.java

public FolderEditWindow(boolean adding, Folder folder, Presentations presentations, Runnable commitHandler) {
    this.folder = folder;
    this.commitHandler = commitHandler;

    messages = AppBeans.get(Messages.NAME);
    messagesPack = AppConfig.getMessagesPack();
    userSessionSource = AppBeans.get(UserSessionSource.NAME);
    Configuration configuration = AppBeans.get(Configuration.NAME);
    clientConfig = configuration.getConfig(ClientConfig.class);

    setCaption(adding ? getMessage("folders.folderEditWindow.adding") : getMessage("folders.folderEditWindow"));

    ThemeConstants theme = App.getInstance().getThemeConstants();
    setWidthUndefined();//from w  ww.j  ava2s.c  om
    setResizable(false);

    int[] modifiers = { ShortcutAction.ModifierKey.CTRL };
    addAction(new ShortcutListener("commit", com.vaadin.event.ShortcutAction.KeyCode.ENTER, modifiers) {
        @Override
        public void handleAction(Object sender, Object target) {
            commit();
        }
    });

    layout = new VerticalLayout();
    layout.setWidthUndefined();
    layout.setSpacing(true);

    setContent(layout);
    setModal(true);
    center();

    String fieldWidth = theme.get("cuba.web.FolderEditWindow.field.width");

    nameField = new TextField();
    nameField.setRequired(true);
    nameField.setCaption(getMessage("folders.folderEditWindow.nameField"));
    nameField.setWidth(fieldWidth);
    nameField.setValue(folder.getName());
    nameField.focus();
    layout.addComponent(nameField);

    tabNameField = new TextField();
    tabNameField.setCaption(getMessage("folders.folderEditWindow.tabNameField"));
    tabNameField.setWidth(fieldWidth);
    tabNameField.setValue(StringUtils.trimToEmpty(folder.getTabName()));
    layout.addComponent(tabNameField);

    parentSelect = new ComboBox();
    parentSelect.setCaption(getMessage("folders.folderEditWindow.parentSelect"));
    parentSelect.setWidth(fieldWidth);
    parentSelect.setNullSelectionAllowed(true);
    fillParentSelect();
    parentSelect.setValue(folder.getParent());
    layout.addComponent(parentSelect);

    if (folder instanceof SearchFolder) {
        if (presentations != null) {
            presentation = new ComboBox();
            presentation.setCaption(getMessage("folders.folderEditWindow.presentation"));
            presentation.setWidth(fieldWidth);
            presentation.setNullSelectionAllowed(true);
            fillPresentations(presentations);
            presentation.setValue(((SearchFolder) folder).getPresentation());
            layout.addComponent(presentation);
        } else if (((SearchFolder) folder).getPresentation() != null) {
            selectedPresentationField = new TextField();
            selectedPresentationField.setWidth(fieldWidth);
            selectedPresentationField.setCaption(getMessage("folders.folderEditWindow.presentation"));
            selectedPresentationField.setValue(((SearchFolder) folder).getPresentation().getName());
            selectedPresentationField.setEnabled(false);
            layout.addComponent(selectedPresentationField);
        }
    }

    sortOrderField = new TextField();
    sortOrderField.setCaption(getMessage("folders.folderEditWindow.sortOrder"));
    sortOrderField.setWidth(fieldWidth);
    sortOrderField.setValue(folder.getSortOrder() == null ? "" : folder.getSortOrder().toString());
    layout.addComponent(sortOrderField);

    if (userSessionSource.getUserSession().isSpecificPermitted("cuba.gui.searchFolder.global")
            && folder instanceof SearchFolder && BooleanUtils.isNotTrue(((SearchFolder) folder).getIsSet())) {
        globalCb = new CubaCheckBox(getMessage("folders.folderEditWindow.global"));
        globalCb.setValue(((SearchFolder) folder).getUser() == null);
        layout.addComponent(globalCb);
    }

    applyDefaultCb = new CubaCheckBox(getMessage("folders.folderEditWindow.applyDefault"));
    applyDefaultCb.setValue(BooleanUtils.isTrue(((AbstractSearchFolder) folder).getApplyDefault()));
    applyDefaultCb.setVisible(clientConfig.getGenericFilterManualApplyRequired()
            && folder instanceof SearchFolder && BooleanUtils.isNotTrue(((SearchFolder) folder).getIsSet()));
    layout.addComponent(applyDefaultCb);

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setMargin(new MarginInfo(true, false, false, false));
    buttonsLayout.setSpacing(true);
    layout.addComponent(buttonsLayout);

    okBtn = new CubaButton(getMessage("actions.Ok"));
    okBtn.setIcon(WebComponentsHelper.getIcon("icons/ok.png"));
    okBtn.addStyleName(WebButton.ICON_STYLE);

    initButtonOkListener();
    buttonsLayout.addComponent(okBtn);

    cancelBtn = new CubaButton(getMessage("actions.Cancel"));
    cancelBtn.setIcon(WebComponentsHelper.getIcon("icons/cancel.png"));
    cancelBtn.addStyleName(WebButton.ICON_STYLE);
    cancelBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });
    buttonsLayout.addComponent(cancelBtn);

    if (AppUI.getCurrent().isTestMode()) {
        setCubaId("folderEditWindow");

        nameField.setCubaId("nameField");
        tabNameField.setCubaId("tabNameField");
        parentSelect.setCubaId("parentSelect");
        if (presentation != null) {
            presentation.setCubaId("presentationSelect");
        }
        sortOrderField.setCubaId("sortOrderField");
        if (selectedPresentationField != null) {
            selectedPresentationField.setCubaId("selectedPresentationField");
        }
        if (globalCb != null) {
            globalCb.setCubaId("globalCb");
        }
        applyDefaultCb.setCubaId("applyDefaultCb");
        okBtn.setCubaId("okBtn");
        cancelBtn.setCubaId("cancelBtn");
    }
}

From source file:jp.primecloud.auto.api.farm.CreateFarm.java

/**
 *
 * ??????//from   w  w  w  .  j a  v a  2 s  .c  o m
 *
 * @param userNo ?
 * @return ????
 */
private List<Long> getEnabledPlatformNos(Long userNo) {
    List<Long> platformNos = new ArrayList<Long>();
    List<Platform> platforms = platformDao.readAll();
    for (Platform platform : platforms) {
        if (!platformService.isUseablePlatforms(userNo, platform)
                || BooleanUtils.isNotTrue(platform.getSelectable())) {
            //????? or ???????????
            continue;
        }
        platformNos.add(platform.getPlatformNo());
    }
    return platformNos;
}

From source file:jp.primecloud.auto.service.impl.ProcessServiceImpl.java

/**
 * {@inheritDoc}/*  www.  j  a  va2  s .  com*/
 */
@Override
public void stopInstances(Long farmNo, List<Long> instanceNos) {
    // ??
    List<Instance> instances = instanceDao.readInInstanceNos(instanceNos);
    for (Instance instance : instances) {
        if (BooleanUtils.isTrue(instance.getEnabled())) {
            instance.setEnabled(false);
            instanceDao.update(instance);
        }
    }

    // ???????
    List<ComponentInstance> componentInstances = componentInstanceDao.readInInstanceNos(instanceNos);
    for (ComponentInstance componentInstance : componentInstances) {
        if (BooleanUtils.isTrue(componentInstance.getEnabled())
                || BooleanUtils.isNotTrue(componentInstance.getConfigure())) {
            componentInstance.setEnabled(false);
            componentInstance.setConfigure(true);
            componentInstanceDao.update(componentInstance);
        }
    }

    // ????
    scheduleFarm(farmNo);
}

From source file:jp.primecloud.auto.service.impl.ComponentServiceImpl.java

/**
 * {@inheritDoc}/*w w w . ja  v a  2 s.  c o  m*/
 */
@Override
public List<ComponentDto> getComponents(Long farmNo) {
    // ???
    List<Component> components = new ArrayList<Component>();
    List<Component> allComponents = componentDao.readByFarmNo(farmNo);
    for (Component component : allComponents) {
        // ???
        if (BooleanUtils.isTrue(component.getLoadBalancer())) {
            continue;
        }
        components.add(component);
    }

    // ????
    List<Long> componentNos = new ArrayList<Long>();
    for (Component component : components) {
        componentNos.add(component.getComponentNo());
    }

    // ??????
    Map<Long, List<ComponentInstance>> componentInstanceMap = new LinkedHashMap<Long, List<ComponentInstance>>();
    for (Long componentNo : componentNos) {
        componentInstanceMap.put(componentNo, new ArrayList<ComponentInstance>());
    }
    List<ComponentInstance> tmpComponentInstances = componentInstanceDao.readInComponentNos(componentNos);
    for (ComponentInstance componentInstance : tmpComponentInstances) {
        // ?????????
        if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) {
            ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
            if (status == ComponentInstanceStatus.STOPPED) {
                continue;
            }
        }
        componentInstanceMap.get(componentInstance.getComponentNo()).add(componentInstance);
    }

    Farm farm = farmDao.read(farmNo);
    List<Instance> instances = instanceDao.readByFarmNo(farmNo);
    Map<Long, Instance> instanceMap = new HashMap<Long, Instance>();
    for (Instance instance : instances) {
        instanceMap.put(instance.getInstanceNo(), instance);
    }
    List<ComponentDto> dtos = new ArrayList<ComponentDto>();
    for (Component component : components) {
        ComponentType componentType = componentTypeDao.read(component.getComponentTypeNo());
        List<InstanceConfig> instanceConfigs = instanceConfigDao.readByComponentNo(component.getComponentNo());
        List<ComponentConfig> componentConfigs = componentConfigDao
                .readByComponentNo(component.getComponentNo());
        List<ComponentInstance> componentInstances = componentInstanceMap.get(component.getComponentNo());
        List<ComponentInstanceDto> componentInstanceDtos = new ArrayList<ComponentInstanceDto>();

        // ???????
        for (ComponentInstance componentInstance : componentInstances) {
            Instance instance = instanceMap.get(componentInstance.getInstanceNo());
            ComponentInstanceStatus status = getComponentInstanceStatus(farm, componentInstance, instance);
            componentInstance.setStatus(status.toString());
        }

        // ????
        ComponentStatus componentStatus = getComponentStatus(componentInstances);

        // DTO??URL?
        for (ComponentInstance componentInstance : componentInstances) {
            ComponentInstanceDto componentInstanceDto = new ComponentInstanceDto();
            componentInstanceDto.setComponentInstance(componentInstance);
            Instance instance = instanceMap.get(componentInstance.getInstanceNo());

            //                for (Instance tmpInstance : instances) {
            //                    if (componentInstance.getInstanceNo().equals(tmpInstance.getInstanceNo())) {
            //                        instance = tmpInstance;
            //                        break;
            //                    }
            //                }

            String url;
            Boolean showPublicIp = BooleanUtils.toBooleanObject(Config.getProperty("ui.showPublicIp"));
            if (BooleanUtils.isTrue(showPublicIp)) {
                //ui.showPublicIp = true ???URL?PublicIp
                url = createUrl(instance.getPublicIp(), component.getComponentTypeNo());
            } else {
                //ui.showPublicIp = false ???URL?PrivateIp
                url = createUrl(instance.getPrivateIp(), component.getComponentTypeNo());
            }

            componentInstanceDto.setUrl(url);
            componentInstanceDtos.add(componentInstanceDto);
        }
        //            // TODO: ????????
        //            for (ComponentInstanceDto componentInstanceDto : componentInstances) {
        //                ComponentInstance componentInstance = componentInstanceDto.getComponentInstance();
        //                ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
        //                if (BooleanUtils.isTrue(componentInstance.getEnabled())) {
        //                    if (status == ComponentInstanceStatus.STOPPED) {
        //                        Instance instance = instanceMap.get(componentInstance.getInstanceNo());
        //                        InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
        //                        if (instanceStatus == InstanceStatus.WARNING) {
        //                            // ?Waring??????Warning??
        //                            componentInstance.setStatus(ComponentInstanceStatus.WARNING.toString());
        //                        } else if (BooleanUtils.isTrue(farm.getScheduled())) {
        //                            // ??????Starting??
        //                            componentInstance.setStatus(ComponentInstanceStatus.STARTING.toString());
        //                        }
        //                    } else if (status == ComponentInstanceStatus.RUNNING
        //                            && BooleanUtils.isTrue(componentInstance.getConfigure())) {
        //                        if (BooleanUtils.isTrue(farm.getScheduled())) {
        //                            // ???Running??????Configuring??
        //                            componentInstance.setStatus(ComponentInstanceStatus.CONFIGURING.toString());
        //                        }
        //                    }
        //                } else {
        //                    if (status == ComponentInstanceStatus.RUNNING || status == ComponentInstanceStatus.WARNING) {
        //                        if (BooleanUtils.isTrue(farm.getScheduled())) {
        //                            // ??????Stopping??
        //                            componentInstance.setStatus(ComponentInstanceStatus.STOPPING.toString());
        //                        }
        //                    }
        //                }
        //            }

        //            // ????
        //            ComponentStatus componentStatus;
        //            Set<ComponentInstanceStatus> statuses = new HashSet<ComponentInstanceStatus>();
        //            for (ComponentInstanceDto componentInstanceDto : componentInstances) {
        //                statuses.add(ComponentInstanceStatus
        //                        .fromStatus(componentInstanceDto.getComponentInstance().getStatus()));
        //            }
        //            if (statuses.contains(ComponentInstanceStatus.WARNING)) {
        //                componentStatus = ComponentStatus.WARNING;
        //            } else if (statuses.contains(ComponentInstanceStatus.CONFIGURING)) {
        //                componentStatus = ComponentStatus.CONFIGURING;
        //            } else if (statuses.contains(ComponentInstanceStatus.RUNNING)) {
        //                if (statuses.contains(ComponentInstanceStatus.STARTING)) {
        //                    componentStatus = ComponentStatus.CONFIGURING;
        //                } else if (statuses.contains(ComponentInstanceStatus.STOPPING)) {
        //                    componentStatus = ComponentStatus.CONFIGURING;
        //                } else {
        //                    componentStatus = ComponentStatus.RUNNING;
        //                }
        //            } else if (statuses.contains(ComponentInstanceStatus.STARTING)) {
        //                componentStatus = ComponentStatus.STARTING;
        //            } else if (statuses.contains(ComponentInstanceStatus.STOPPING)) {
        //                componentStatus = ComponentStatus.STOPPING;
        //            } else {
        //                componentStatus = ComponentStatus.STOPPED;
        //            }

        // 
        Collections.sort(componentInstanceDtos, Comparators.COMPARATOR_COMPONENT_INSTANCE_DTO);

        ComponentDto dto = new ComponentDto();
        dto.setComponent(component);
        dto.setComponentType(componentType);
        dto.setComponentConfigs(componentConfigs);
        dto.setComponentInstances(componentInstanceDtos);
        dto.setInstanceConfigs(instanceConfigs);
        dto.setStatus(componentStatus.toString());
        dtos.add(dto);
    }

    // 
    Collections.sort(dtos, Comparators.COMPARATOR_COMPONENT_DTO);

    return dtos;
}

From source file:de.hybris.platform.ytelcoacceleratorstorefront.controllers.pages.payment.SilentOrderPostMockController.java

@RequestMapping(value = "/handle-form-post", method = RequestMethod.POST)
public String handleFormPost(@Valid final SopPaymentDetailsForm form, final BindingResult bindingResult,
        @RequestParam("targetArea") final String targetArea, @RequestParam("editMode") final Boolean editMode,
        @RequestParam("paymentInfoId") final String paymentInfoId,
        final RedirectAttributes redirectAttributes) {
    getSopPaymentDetailsValidator().validate(form, bindingResult);
    if (bindingResult.hasErrors()) {
        redirectAttributes.addFlashAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER,
                Collections.singletonList("checkout.error.paymentmethod.formentry.invalid"));
        redirectAttributes.addFlashAttribute(
                "org.springframework.validation.BindingResult.sopPaymentDetailsForm", bindingResult);
        redirectAttributes.addFlashAttribute("sopPaymentDetailsForm", bindingResult.getTarget());

        return Boolean.TRUE.equals(editMode) ? REDIRECT_URL_EDIT_PAYMENT_DETAILS + paymentInfoId
                : REDIRECT_URL_ADD_PAYMENT_METHOD + targetArea;

    } else {// www.  ja v  a  2  s.  c o  m
        final String authorizationRequestId = (String) getSessionService()
                .getAttribute("authorizationRequestId");
        final String authorizationRequestToken = (String) getSessionService()
                .getAttribute("authorizationRequestToken");

        try {
            if (BooleanUtils.isTrue(editMode)) {
                final CCPaymentInfoData ccPaymentInfoData = setupCCPaymentInfoData(form, paymentInfoId);
                if (null != ccPaymentInfoData) {
                    final CCPaymentInfoData result = getSubscriptionFacade()
                            .changePaymentMethod(ccPaymentInfoData, null, true, null);

                    // enrich result data with form data, which is not provided from the facade call
                    result.setId(paymentInfoId);
                    result.getBillingAddress()
                            .setTitleCode(ccPaymentInfoData.getBillingAddress().getTitleCode());
                    result.setStartMonth(ccPaymentInfoData.getStartMonth());
                    result.setStartYear(ccPaymentInfoData.getStartYear());
                    result.setIssueNumber(ccPaymentInfoData.getIssueNumber());

                    getUserFacade().updateCCPaymentInfo(result);

                    if (form.getMakeAsDefault().booleanValue()) {
                        getUserFacade().setDefaultPaymentInfo(result);
                    }

                    redirectAttributes.addFlashAttribute(GlobalMessages.CONF_MESSAGES_HOLDER,
                            Collections.singletonList("text.account.paymentDetails.editSuccessful"));
                } else {
                    redirectAttributes.addFlashAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER,
                            Collections.singletonList("text.account.paymentDetails.nonExisting.error"));
                }
            } else {
                final SubscriptionPaymentData result = getSubscriptionFacade().finalizeTransaction(
                        authorizationRequestId, authorizationRequestToken,
                        createPaymentDetailsMap(form, targetArea));

                final CCPaymentInfoData newPaymentSubscription = getSubscriptionFacade()
                        .createPaymentSubscription(result.getParameters());

                // enrich result data with form data, which is not provided from the facade call
                if (BooleanUtils.isNotTrue(form.getNewBillingAddress())
                        && null != getCheckoutFacade().getCheckoutCart()
                        && null != getCheckoutFacade().getCheckoutCart().getDeliveryAddress()) {
                    newPaymentSubscription.getBillingAddress().setTitleCode(
                            getCheckoutFacade().getCheckoutCart().getDeliveryAddress().getTitleCode());
                } else if (null != form.getBillingAddress()) {
                    newPaymentSubscription.getBillingAddress()
                            .setTitleCode(form.getBillingAddress().getTitleCode());
                }

                newPaymentSubscription.setStartMonth(form.getStartMonth());
                newPaymentSubscription.setStartYear(form.getStartYear());
                newPaymentSubscription.setIssueNumber(form.getIssueNumber());
                newPaymentSubscription.setSaved(true);

                getUserFacade().updateCCPaymentInfo(newPaymentSubscription);

                if (form.getMakeAsDefault().booleanValue()) {
                    getUserFacade().setDefaultPaymentInfo(newPaymentSubscription);
                }

                getCheckoutFacade().setPaymentDetails(newPaymentSubscription.getId());

                redirectAttributes.addFlashAttribute(GlobalMessages.CONF_MESSAGES_HOLDER,
                        Collections.singletonList("text.account.paymentDetails.addSuccessful"));
            }
        } catch (final SubscriptionFacadeException e) {
            LOG.error("Creating a new payment method failed", e);
            redirectAttributes.addFlashAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER,
                    Collections.singletonList("checkout.multi.paymentMethod.addPaymentDetails.incomplete"));
            return REDIRECT_URL_ADD_PAYMENT_METHOD + targetArea;
        }
    }

    if (StringUtils.equals(targetArea, "multiCheckoutArea")) {
        return REDIRECT_URL_SUMMARY;
    }

    return REDIRECT_URL_PAYMENT_INFO;
}

From source file:jp.primecloud.auto.api.farm.CreateFarm.java

/**
 *
 * ??????/*from  w ww .j  a v  a 2 s.  co m*/
 *
 * @return ????
 */
private List<Long> getEnabledImageNos() {
    List<Long> imageNos = new ArrayList<Long>();
    List<Image> images = imageDao.readAll();
    for (Image image : images) {
        if (BooleanUtils.isNotTrue(image.getSelectable())) {
            //???????????????
            continue;
        }
        imageNos.add(image.getImageNo());
    }
    return imageNos;
}