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

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

Introduction

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

Prototype

public static boolean isTrue(Boolean bool) 

Source Link

Document

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 

Usage

From source file:com.haulmont.ext.web.ui.CauseGIBDD.CauseGIBDDBrowser.java

private void initAfterSetLookup(boolean isLookup) {
    final User user = UserSessionClient.getUserSession().getCurrentOrSubstitutedUser();
    SplitPanel splitPanel = getComponent("split");
    splitPanel.setSplitPosition(100);//www .j  a va 2 s. com
    splitPanel.setLocked(true);
    if (isLookup) {
        docsTable.setMultiSelect(false);
    } else if (!isTemplate) {
        //            final HashMap<UUID, com.vaadin.ui.Component> statesMap = new HashMap<UUID, com.vaadin.ui.Component>();
        final CardService cardService = ServiceLocator.lookup(CardService.NAME);
        addLocStateColumn();

        resolutionsFrame = getComponent("resolutionsFrame");
        resolutionsFrame.init();

        cardTreeFrame = getComponent("cardTreeFrame");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("card", null);
        cardTreeFrame.init(params);

        showResolutions = getComponent(HIDE_RESOLUTIONS);
        final SplitPanel split = getComponent("split");
        showResolutions.addListener(new ValueListener() {
            public void valueChanged(Object source, String property, Object prevValue, Object value) {
                boolean showResolutionsValue = BooleanUtils.isTrue((Boolean) value);
                int pos = (!showResolutionsValue ? 100 : 60);
                split.setSplitPosition(pos);
                split.setLocked(!showResolutionsValue);

                Card card = (Card) docsTable.getSingleSelected();
                if (showResolutionsValue && card != null) {
                    String currentTab = tabsheet.getTab().getName();
                    if (currentTab.equals("resolutionsTab"))
                        resolutionsFrame.setCard(card);
                    if (currentTab.equals("hierarchyTab"))
                        cardTreeFrame.setCard(card);
                }
            }
        });

        String value = getSettings().get(HIDE_RESOLUTIONS).attributeValue("value");
        showResolutions.setValue(value == null ? false : BooleanUtils.toBoolean(value));
    } else {
        SplitPanel split = getComponent("split");
        split.setSplitPosition(100);
        split.setLocked(true);
    }
}

From source file:com.square.core.service.implementations.PersonnePhysiqueServiceImplementation.java

/**
 * Implmentation du service de cration d'une personne.
 * @param personneDto la personne  crer ou  mettre  jour.
 * @param listeBeneficiaire la liste des beneficiaires.
 * @param coordonnees coordonnes de la personne.
 * @return PersonneDto la personne cre./*ww w. ja v  a 2 s . co  m*/
 * @author mlamine - SCUB
 */
public PersonneDto creerPersonnePhysique(PersonneDto personneDto, List<BeneficiaireDto> listeBeneficiaire,
        CoordonneesDto coordonnees) {
    final RapportDto rapport = new RapportDto();
    Adresse adressePrincipale = null;
    Email emailPersonnel = null;
    Telephone telephoneFixe = null;
    Telephone telephonePortable = null;

    // Contrle des champs obligatoires
    if (personneDto == null) {
        throw new BusinessException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PERSONNE_DTO_NULL));
    }
    // Rcupration de la personne en base si l'identifiant est renseign (doublon)
    boolean assureSelectionneParmiDoublon = false;
    PersonnePhysique personnePrincipale = null;
    if (personneDto.getIdentifiant() != null) {
        personnePrincipale = personnePhysiqueDao.rechercherPersonneParId(personneDto.getIdentifiant());
        adressePrincipale = getAdressePersonne(personnePrincipale,
                squareMappingService.getIdNatureAdressePrincipale());
        emailPersonnel = getEmailPersonne(personnePrincipale, squareMappingService.getIdNatureEmailPersonnel());
        telephoneFixe = getTelephonePersonne(personnePrincipale,
                squareMappingService.getIdNatureTelephoneFixe());
        telephonePortable = getTelephonePersonne(personnePrincipale,
                squareMappingService.getIdNatureMobilePrive());
        if (personnePrincipale != null) {
            assureSelectionneParmiDoublon = true;
        } else {
            throw new BusinessException(messageSourceUtil
                    .get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PERSONNE_ASSURE_SELECTIONNE_INEXISTANTE));
        }
    }

    EmailDto emailDto = null;
    AdresseDto adresseDto = null;
    TelephoneDto telephoneFixeDto = null;
    TelephoneDto telephonePortableDto = null;
    if (coordonnees.getTelephones() != null && coordonnees.getTelephones().size() >= 1
            && coordonnees.getTelephones().get(0) != null
            && StringUtils.isNotBlank(coordonnees.getTelephones().get(0).getNumero())) {
        telephoneFixeDto = coordonnees.getTelephones().get(0);
    }
    if (coordonnees.getTelephones() != null && coordonnees.getTelephones().size() >= 2
            && coordonnees.getTelephones().get(1) != null
            && StringUtils.isNotBlank(coordonnees.getTelephones().get(1).getNumero())) {
        telephonePortableDto = coordonnees.getTelephones().get(1);
    }
    if (coordonnees.getEmails() != null && !coordonnees.getEmails().isEmpty()
            && coordonnees.getEmails().get(0) != null
            && StringUtils.isNotBlank(coordonnees.getEmails().get(0).getAdresse())) {
        emailDto = coordonnees.getEmails().get(0);
    }
    if (coordonnees.getAdresses() != null) {
        for (AdresseDto adresse : coordonnees.getAdresses()) {
            if (adresse != null) {
                adresseDto = adresse;
                break;
            }
        }
    }

    // Pas de contrle si l'assur est slectionn parmi un doublon
    if (!assureSelectionneParmiDoublon) {
        // Controle sur les adresses
        if (adresseDto == null) {
            throw new BusinessException(
                    messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_ADRESSE_DTO_NULL));
        }
        validationPersonneUtil.verifierContrainteCreationProspect(personneDto, emailDto, adresseDto,
                telephoneFixeDto, telephonePortableDto, rapport);
    }
    if (listeBeneficiaire != null) {
        validationPersonneUtil.verifierContrainteCreationBeneficiaires(listeBeneficiaire, rapport);
    }

    // Les controles sont termins, suite du processus :
    if (rapport.getEnErreur()) {
        RapportUtil.logRapport(rapport, logger);
        throw new ControleIntegriteException(rapport);
    }
    // On mappe les coordonnes en objet du modle
    if (adresseDto != null) {
        adressePrincipale = mapperAdressePourCreation(adresseDto);
    }
    if (emailDto != null) {
        emailPersonnel = mapperEmailPourCreation(emailDto);
    }
    if (telephoneFixeDto != null) {
        telephoneFixe = mapperTelephonePourCreation(telephoneFixeDto);
    }
    if (telephonePortableDto != null) {
        telephonePortable = mapperTelephonePourCreation(telephonePortableDto);
    }

    // On cr la personne principale si l'assur n'a pas t slectionn parmi les doublons
    if (!assureSelectionneParmiDoublon) {
        personnePrincipale = mapperPersonnePourCreation(personneDto, adressePrincipale, emailPersonnel,
                telephoneFixe, telephonePortable);
        // Cration de la personne
        personnePhysiqueDao.creerPersonnePhysique(personnePrincipale);
    }
    // On cr les bnficiaires un par un
    if (listeBeneficiaire != null) {
        Long idConjoint = null;
        for (int i = 0; i < listeBeneficiaire.size(); i++) {
            final BeneficiaireDto beneficiaireDto = listeBeneficiaire.get(i);
            PersonnePhysique beneficiaire = null;
            // Rcupration du bnficiaire si slectionn parmi un doublon
            boolean beneficiaireSelectionneParmiDoublon = false;
            if (beneficiaireDto.getIdentifiant() != null) {
                beneficiaire = personnePhysiqueDao.rechercherPersonneParId(beneficiaireDto.getIdentifiant());
                if (beneficiaire != null) {
                    beneficiaireSelectionneParmiDoublon = true;
                } else {
                    throw new BusinessException(messageSourceUtil.get(
                            PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PERSONNE_BENEFICIAIRE_SELECTIONNE_INEXISTANTE));
                }
            }
            // Recopie des informations de l'adhrent principal & copie des infos du bnficiaire s'il n'est pas slectionn parmi les doublons
            if (!beneficiaireSelectionneParmiDoublon) {
                beneficiaire = mapperPersonnePourCreation(
                        mapperBeneficiaireEnPersonneDto(beneficiaireDto, personnePrincipale), adressePrincipale,
                        emailPersonnel, telephoneFixe, telephonePortable);
                // Cration du bnficiaire
                personnePhysiqueDao.creerPersonnePhysique(beneficiaire);
            }
            // On cr la relation entre la personne principale et le bnficiaire qui vient d'tre cr
            final RelationDto relation = new RelationDto();
            relation.setDateDebut(Calendar.getInstance());
            relation.setIdPersonnePrincipale(personnePrincipale.getId());
            relation.setIdPersonne(beneficiaire.getId());
            final RelationType type = relationTypeDao
                    .rechercherTypeRelationParId(beneficiaireDto.getTypeRelation().getIdentifiant());
            relation.setType(new IdentifiantLibelleDto(type.getId(), type.getLibelle()));
            personneService.creerRelation(relation);
            if (logger.isDebugEnabled()) {
                logger.debug(messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_INFO_RELATION_CREEE));
            }

            // Si le bnficiaire est le conjoint, on rcupre son id.
            if (type.getId().equals(squareMappingService.getIdTypeRelationConjoint())) {
                idConjoint = beneficiaire.getId();
                logger.fatal("*************** idConjoint enregistr: " + idConjoint);
            }
            // Si c'est un enfant on cre la relation avec le conjoint si cel a t choisi
            else if (type.getId().equals(squareMappingService.getIdTypeRelationEnfant()) && idConjoint != null
                    && BooleanUtils.isTrue(beneficiaireDto.getRattacherAuxParents())) {
                logger.fatal("*************** creation relation enfant conjoint");
                final RelationDto relationEnfantConjoint = new RelationDto();
                relationEnfantConjoint.setDateDebut(Calendar.getInstance());
                relationEnfantConjoint.setIdPersonnePrincipale(idConjoint);
                relationEnfantConjoint.setIdPersonne(beneficiaire.getId());
                relationEnfantConjoint.setType(new IdentifiantLibelleDto(type.getId(), type.getLibelle()));
                personneService.creerRelation(relationEnfantConjoint);
                if (logger.isDebugEnabled()) {
                    logger.debug(messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_INFO_RELATION_CREEE));
                }
            }
            logger.fatal("*************** idConjoint : " + idConjoint);
            logger.fatal("*************** beneficiaireDto.getRattacherAuxParents() : "
                    + beneficiaireDto.getRattacherAuxParents());
        }
    }
    return rechercherPersonneParIdentifiant(personnePrincipale.getId());
}

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

/**
 * {@inheritDoc}/* w  ww  . ja va  2 s  .c  om*/
 */
@Override
public void stopLoadBalancerListeners(Long farmNo, Long loadBalancerNo, List<Integer> loadBalancerPorts) {
    if (loadBalancerPorts.isEmpty()) {
        return;
    }

    // ??
    List<LoadBalancerListener> listeners = loadBalancerListenerDao.readByLoadBalancerNo(loadBalancerNo);
    for (LoadBalancerListener listener : listeners) {
        if (!loadBalancerPorts.contains(listener.getLoadBalancerPort())) {
            continue;
        }
        if (BooleanUtils.isTrue(listener.getEnabled()) || BooleanUtils.isNotTrue(listener.getConfigure())) {
            listener.setEnabled(false);
            listener.setConfigure(true);
            loadBalancerListenerDao.update(listener);
        }
    }

    // ???
    LoadBalancer loadBalancer = loadBalancerDao.read(loadBalancerNo);
    if (BooleanUtils.isNotTrue(loadBalancer.getConfigure())) {
        loadBalancer.setConfigure(true);
        loadBalancerDao.update(loadBalancer);
    }

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

From source file:jp.primecloud.auto.process.ProcessManager.java

protected boolean processStartLoadBalancer(final Farm farm) {
    // ???//w w  w  . j a  v  a 2  s.c o  m
    List<LoadBalancer> loadBalancers = new ArrayList<LoadBalancer>();
    List<LoadBalancer> allLoadBalancers = loadBalancerDao.readByFarmNo(farm.getFarmNo());
    for (LoadBalancer loadBalancer : allLoadBalancers) {
        if (BooleanUtils.isTrue(loadBalancer.getEnabled())) {
            loadBalancers.add(loadBalancer);
        }
    }

    // ??????
    if (loadBalancers.isEmpty()) {
        return true;
    }

    // ???
    boolean processing = false;
    List<Long> targetLoadBalancerNos = new ArrayList<Long>();
    for (LoadBalancer loadBalancer : loadBalancers) {
        LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus());

        if (status != LoadBalancerStatus.RUNNING && status != LoadBalancerStatus.WARNING) {
            processing = true;

            if (status == LoadBalancerStatus.STOPPED) {
                targetLoadBalancerNos.add(loadBalancer.getLoadBalancerNo());
            }
        }
    }

    // ??????
    if (!targetLoadBalancerNos.isEmpty()) {
        final User user = userDao.read(farm.getUserNo());
        for (final Long loadBalancerNo : targetLoadBalancerNos) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    LoggingUtils.setUserNo(user.getMasterUser());
                    LoggingUtils.setUserName(user.getUsername());
                    LoggingUtils.setFarmNo(farm.getFarmNo());
                    LoggingUtils.setFarmName(farm.getFarmName());
                    LoggingUtils.setLoginUserNo(user.getUserNo());
                    try {
                        loadBalancerProcess.start(loadBalancerNo);
                    } catch (MultiCauseException ignore) {
                    } catch (Throwable e) {
                        log.error(e.getMessage(), e);

                        // 
                        eventLogger.error("SystemError", new Object[] { e.getMessage() });
                    } finally {
                        LoggingUtils.removeContext();
                    }
                }
            };
            executorService.execute(runnable);
        }
    }

    // ??????
    if (processing) {
        return false;
    }

    return true;
}

From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java

/**
 * Sets filter entity, creates condition editor components and applies filter if necessary
 *//* w w  w .  ja v a  2  s . c o m*/
@Override
public void setFilterEntity(FilterEntity filterEntity) {
    this.filterEntity = filterEntity;
    conditions = filterParser.getConditions(filter, filterEntity.getXml());
    prevConditions = conditions;
    initialConditions = conditions.toConditionsList();

    for (AbstractCondition condition : initialConditions) {
        if (!suitableCondition(condition)) {
            String message = String.format(getMainMessage("filter.inappropriate.filter"),
                    filterEntity.getName(), datasource.getMetaClass().getName());

            windowManager.showNotification(message, Frame.NotificationType.HUMANIZED);
            setFilterEntity(adHocFilter);
            break;
        }

        condition.addListener(new AbstractCondition.Listener() {
            @Override
            public void captionChanged() {
            }

            @Override
            public void paramChanged(Param oldParam, Param newParam) {
                updateFilterModifiedIndicator();
            }
        });
    }

    // If there are window parameters named as filter parameters, assign values to the corresponding
    // filter params. Together with passing a filter code in 'filter' window parameter it allows to open an
    // arbitrary filter with parameters regardless of a user defined default filter.
    Window window = ComponentsHelper.getWindow(filter);
    for (AbstractCondition condition : conditions.toConditionsList()) {
        if (condition.getParam() != null) {
            for (Map.Entry<String, Object> entry : window.getContext().getParams().entrySet()) {
                if (entry.getKey().equals(condition.getParam().getName()))
                    condition.getParam().parseValue((String) entry.getValue());
            }
        }
    }

    saveInitialFilterState();

    if (filtersLookupDisplayed) {
        filtersLookupListenerEnabled = false;
        filtersLookup.setValue(filterEntity);
        filtersLookupListenerEnabled = true;
    }

    setFilterActionsEnabled();
    setFilterActionsVisible();
    fillConditionsLayout(ConditionsFocusType.FIRST);
    if (delayedFocus) {
        delayedFocus = false;
        requestFocus();
    } else {
        requestFocusToParamEditComponent();
    }

    setConditionsLayoutVisible(true);

    if (BooleanUtils.isTrue(filterEntity.getIsSet())
            || (filterEntity.getFolder() != null && BooleanUtils.isNotFalse(filterEntity.getApplyDefault()))) {
        apply(true);
    }

    for (Filter.FilterEntityChangeListener listener : filterEntityChangeListeners) {
        listener.filterEntityChanged(filterEntity);
    }

    updateWindowCaption();
}

From source file:com.wineaccess.winepermit.WinePermitHelper.java

/**
 * @param sellInAltStatesModel//w  w  w  .j ava  2s .  c o m
 * @param string 
 */
private void validateSellInAltModel(SellInAltStatesModel sellInAltStatesModel, String wineId) {

    Boolean isOptionSelectedKachinaAlt = BooleanUtils
            .toBoolean(sellInAltStatesModel.getIsOptionSelectedKachinaAlt());
    OptionSelectedAltStates optionSelectedAltStates = sellInAltStatesModel.getOptionSelectedAltStates();
    Boolean isOptionSelectedNoPermit = BooleanUtils.toBoolean(sellInAltStatesModel.getIsSelectedNoPermit());
    Boolean isSelectedAltStates = BooleanUtils.toBoolean(sellInAltStatesModel.getIsSelected());

    if (BooleanUtils.isTrue(isSelectedAltStates) && BooleanUtils.isNotTrue(isOptionSelectedKachinaAlt)
            && optionSelectedAltStates == null && BooleanUtils.isNotTrue(isOptionSelectedNoPermit)) {
        response.addError(
                new WineaccessError(SystemErrorCode.PERMIT_NO_OPTION_SELECTED_WINE_LICENCES_ERROR_WINE,
                        SystemErrorCode.PERMIT_NO_OPTION_SELECTED_WINE_LICENCES_ERROR_WINE_TEXT));
    } else if ((BooleanUtils.isTrue(isOptionSelectedKachinaAlt) && optionSelectedAltStates != null)
            || BooleanUtils.isTrue(isOptionSelectedKachinaAlt) && BooleanUtils.isTrue(isOptionSelectedNoPermit)
            || BooleanUtils.isTrue(isOptionSelectedNoPermit) && optionSelectedAltStates != null) {
        response.addError(new WineaccessError(SystemErrorCode.PERMIT_MORE_THAN_ONE_OPTION_SELECTED_ERROR_WINE,
                SystemErrorCode.PERMIT_MORE_THAN_ONE_OPTION_SELECTED_ERROR_WINE_TEXT));
    } else {
        if (optionSelectedAltStates != null) {
            validateoptionSelectedAltstates(optionSelectedAltStates, wineId);
        } else if (sellInAltStatesModel.getOptionSelectedNoPermit() != null)
            validateoptionSelectedNoPermit(isOptionSelectedNoPermit,
                    sellInAltStatesModel.getOptionSelectedNoPermit(), wineId);
        else {
            if (BooleanUtils.isTrue(isOptionSelectedNoPermit))
                response.addError(new WineaccessError(SystemErrorCode.WINE_PERMIT_SELECT_VALUE_NO_PERMIT,
                        SystemErrorCode.WINE_PERMIT_SELECT_VALUE_NO_PERMIT_TEXT));
        }
    }

}

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

/**
 * {@inheritDoc}/*w w  w .  ja  va 2 s  .  c  om*/
 */
@Override
public List<InstanceDto> getInstances(Long farmNo) {
    // ?
    List<Instance> instances = new ArrayList<Instance>();
    List<Instance> allInstances = instanceDao.readByFarmNo(farmNo);
    for (Instance instance : allInstances) {
        // ???
        if (BooleanUtils.isTrue(instance.getLoadBalancer())) {
            continue;
        }
        instances.add(instance);
    }

    // ????
    List<Long> instanceNos = new ArrayList<Long>();
    for (Instance instance : instances) {
        instanceNos.add(instance.getInstanceNo());
    }

    // ZabbixInstance?
    List<ZabbixInstance> zabbixInstances = zabbixInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, ZabbixInstance> zabbixInstanceMap = new LinkedHashMap<Long, ZabbixInstance>();
    for (ZabbixInstance zabbixInstance : zabbixInstances) {
        zabbixInstanceMap.put(zabbixInstance.getInstanceNo(), zabbixInstance);
    }

    // ?
    List<Platform> platforms = platformDao.readAll();
    Map<Long, Platform> platformMap = new LinkedHashMap<Long, Platform>();
    for (Platform platform : platforms) {
        platformMap.put(platform.getPlatformNo(), platform);
    }

    // ?
    List<Image> images = imageDao.readAll();
    Map<Long, Image> imageMap = new LinkedHashMap<Long, Image>();
    for (Image image : images) {
        imageMap.put(image.getImageNo(), image);
    }

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

    // ???
    Map<Long, Component> componentMap = new HashMap<Long, Component>();
    Set<Long> componentNos = new HashSet<Long>();
    for (ComponentInstance componentInstance : tmpComponentInstances) {
        componentNos.add(componentInstance.getComponentNo());
    }
    List<Component> components = componentDao.readInComponentNos(componentNos);
    for (Component component : components) {
        componentMap.put(component.getComponentNo(), component);
    }

    // TODO CLOUD BRANCHING
    // AWS 
    // AWS?
    List<PlatformAws> platformAwss = platformAwsDao.readAll();
    Map<Long, PlatformAws> platformAwsMap = new LinkedHashMap<Long, PlatformAws>();
    for (PlatformAws platformAws : platformAwss) {
        platformAwsMap.put(platformAws.getPlatformNo(), platformAws);
    }

    // AWS?
    List<ImageAws> imageAwss = imageAwsDao.readAll();
    Map<Long, ImageAws> imageAwsMap = new LinkedHashMap<Long, ImageAws>();
    for (ImageAws imageAws : imageAwss) {
        imageAwsMap.put(imageAws.getImageNo(), imageAws);
    }

    // AWS?
    List<AwsInstance> awsInstances = awsInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, AwsInstance> awsInstanceMap = new LinkedHashMap<Long, AwsInstance>();
    for (AwsInstance awsInstance : awsInstances) {
        awsInstanceMap.put(awsInstance.getInstanceNo(), awsInstance);
    }

    // AWS?
    Farm farm = farmDao.read(farmNo);
    List<AwsAddress> awsAddresses = awsAddressDao.readByUserNo(farm.getUserNo());
    Map<Long, AwsAddress> awsAddressMap = new LinkedHashMap<Long, AwsAddress>();
    for (AwsAddress awsAddress : awsAddresses) {
        if (awsAddress.getInstanceNo() != null) {
            awsAddressMap.put(awsAddress.getInstanceNo(), awsAddress);
        }
    }

    // AWS?
    List<AwsVolume> farmAwsVolumes = awsVolumeDao.readByFarmNo(farmNo);
    Map<Long, List<AwsVolume>> awsVolumesMap = new LinkedHashMap<Long, List<AwsVolume>>();
    for (AwsVolume awsVolume : farmAwsVolumes) {
        Long instanceNo = awsVolume.getInstanceNo();
        if (instanceNo != null) {
            List<AwsVolume> awsVolumes = awsVolumesMap.get(instanceNo);
            if (awsVolumes == null) {
                awsVolumes = new ArrayList<AwsVolume>();
                awsVolumesMap.put(instanceNo, awsVolumes);
            }
            awsVolumes.add(awsVolume);
        }
    }

    // AWS??
    List<AwsCertificate> awsCertificates = awsCertificateDao.readByUserNo(farm.getUserNo());
    Map<Long, AwsCertificate> awsCertificateMap = new LinkedHashMap<Long, AwsCertificate>();
    for (AwsCertificate awsCertificate : awsCertificates) {
        awsCertificateMap.put(awsCertificate.getPlatformNo(), awsCertificate);
    }

    // CloudStack 
    // CloudStack?
    List<PlatformCloudstack> platformCloudstacks = platformCloudstackDao.readAll();
    Map<Long, PlatformCloudstack> platformCloudstackMap = new LinkedHashMap<Long, PlatformCloudstack>();
    for (PlatformCloudstack platformCloudstack : platformCloudstacks) {
        platformCloudstackMap.put(platformCloudstack.getPlatformNo(), platformCloudstack);
    }

    // CloudStack?
    List<ImageCloudstack> imageCloudstacks = imageCloudstackDao.readAll();
    Map<Long, ImageCloudstack> imageCloudstackMap = new LinkedHashMap<Long, ImageCloudstack>();
    for (ImageCloudstack imageCloudstack : imageCloudstacks) {
        imageCloudstackMap.put(imageCloudstack.getImageNo(), imageCloudstack);
    }

    // CloudStack?
    List<CloudstackInstance> cloudstackInstances = cloudstackInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, CloudstackInstance> cloudstackInstanceMap = new LinkedHashMap<Long, CloudstackInstance>();
    for (CloudstackInstance cloudstackInstance : cloudstackInstances) {
        cloudstackInstanceMap.put(cloudstackInstance.getInstanceNo(), cloudstackInstance);
    }

    // CloudStack?
    List<CloudstackAddress> cloudstackAddresses = cloudstackAddressDao.readByAccount(farm.getUserNo());
    Map<Long, CloudstackAddress> cloudstackAddressMap = new LinkedHashMap<Long, CloudstackAddress>();
    for (CloudstackAddress cloudstackAddress : cloudstackAddresses) {
        if (cloudstackAddress.getInstanceNo() != null) {
            cloudstackAddressMap.put(cloudstackAddress.getInstanceNo(), cloudstackAddress);
        }
    }

    // CloudStack?
    List<CloudstackVolume> farmCloudstackVolumes = cloudstackVolumeDao.readByFarmNo(farmNo);
    Map<Long, List<CloudstackVolume>> cloudstackVolumesMap = new LinkedHashMap<Long, List<CloudstackVolume>>();
    for (CloudstackVolume cloudstackVolume : farmCloudstackVolumes) {
        Long instanceNo = cloudstackVolume.getInstanceNo();
        if (instanceNo != null) {
            List<CloudstackVolume> cloudstackVolumes = cloudstackVolumesMap.get(instanceNo);
            if (cloudstackVolumes == null) {
                cloudstackVolumes = new ArrayList<CloudstackVolume>();
                cloudstackVolumesMap.put(instanceNo, cloudstackVolumes);
            }
            cloudstackVolumes.add(cloudstackVolume);
        }
    }

    // VMware 
    // VMWare?
    List<PlatformVmware> platformVmwares = platformVmwareDao.readAll();
    Map<Long, PlatformVmware> platformVmwareMap = new LinkedHashMap<Long, PlatformVmware>();
    for (PlatformVmware platformVmware : platformVmwares) {
        platformVmwareMap.put(platformVmware.getPlatformNo(), platformVmware);
    }

    // VMware?
    List<ImageVmware> imageVmwares = imageVmwareDao.readAll();
    Map<Long, ImageVmware> imageVmwareMap = new LinkedHashMap<Long, ImageVmware>();
    for (ImageVmware imageVmware : imageVmwares) {
        imageVmwareMap.put(imageVmware.getImageNo(), imageVmware);
    }

    // VMware?
    List<VmwareInstance> vmwareInstances = vmwareInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, VmwareInstance> vmwareInstanceMap = new LinkedHashMap<Long, VmwareInstance>();
    for (VmwareInstance vmwareInstance : vmwareInstances) {
        vmwareInstanceMap.put(vmwareInstance.getInstanceNo(), vmwareInstance);
    }

    // VMwareAddress?
    Map<Long, VmwareAddress> vmwareAddressMap = new LinkedHashMap<Long, VmwareAddress>();
    List<VmwareAddress> vmwareAddresses = vmwareAddressDao.readByUserNo(farm.getUserNo());
    for (VmwareAddress vmwareAddress : vmwareAddresses) {
        if (vmwareAddress.getInstanceNo() != null) {
            vmwareAddressMap.put(vmwareAddress.getInstanceNo(), vmwareAddress);
        }
    }

    // VMware?
    Map<Long, VmwareKeyPair> vmwareKeyPairMap = new LinkedHashMap<Long, VmwareKeyPair>();
    if (!vmwareInstanceMap.isEmpty()) {
        List<VmwareKeyPair> vmwareKeyPairs = vmwareKeyPairDao.readByUserNo(farm.getUserNo());
        for (VmwareKeyPair vmwareKeyPair : vmwareKeyPairs) {
            vmwareKeyPairMap.put(vmwareKeyPair.getKeyNo(), vmwareKeyPair);
        }
    }

    // VMware?
    List<VmwareDisk> farmVmwareDisks = vmwareDiskDao.readByFarmNo(farmNo);
    Map<Long, List<VmwareDisk>> vmwareDisksMap = new LinkedHashMap<Long, List<VmwareDisk>>();
    for (VmwareDisk vmwareDisk : farmVmwareDisks) {
        Long instanceNo = vmwareDisk.getInstanceNo();
        if (instanceNo != null) {
            List<VmwareDisk> vmwareDisks = vmwareDisksMap.get(instanceNo);
            if (vmwareDisks == null) {
                vmwareDisks = new ArrayList<VmwareDisk>();
                vmwareDisksMap.put(instanceNo, vmwareDisks);
            }
            vmwareDisks.add(vmwareDisk);
        }
    }

    // Nifty 
    // Nifty?
    List<PlatformNifty> platformNifties = platformNiftyDao.readAll();
    Map<Long, PlatformNifty> platformNiftyMap = new LinkedHashMap<Long, PlatformNifty>();
    for (PlatformNifty platformNifty : platformNifties) {
        platformNiftyMap.put(platformNifty.getPlatformNo(), platformNifty);
    }

    // Nifty?
    List<ImageNifty> imageNifties = imageNiftyDao.readAll();
    Map<Long, ImageNifty> imageNiftyMap = new LinkedHashMap<Long, ImageNifty>();
    for (ImageNifty imageNifty : imageNifties) {
        imageNiftyMap.put(imageNifty.getImageNo(), imageNifty);
    }

    // Nifty?
    List<NiftyInstance> niftyInstances = niftyInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, NiftyInstance> niftyInstanceMap = new LinkedHashMap<Long, NiftyInstance>();
    for (NiftyInstance niftyInstance : niftyInstances) {
        niftyInstanceMap.put(niftyInstance.getInstanceNo(), niftyInstance);
    }

    // Nifty?
    Map<Long, NiftyKeyPair> niftyKeyPairMap = new LinkedHashMap<Long, NiftyKeyPair>();
    if (!niftyInstanceMap.isEmpty()) {
        List<NiftyKeyPair> niftyKeyPairs = niftyKeyPairDao.readByUserNo(farm.getUserNo());
        for (NiftyKeyPair niftyKeyPair : niftyKeyPairs) {
            niftyKeyPairMap.put(niftyKeyPair.getKeyNo(), niftyKeyPair);
        }
    }

    // Nifty?
    List<NiftyVolume> farmNiftyVolumes = niftyVolumeDao.readByFarmNo(farmNo);
    Map<Long, List<NiftyVolume>> niftyVolumesMap = new LinkedHashMap<Long, List<NiftyVolume>>();
    for (NiftyVolume niftyVolume : farmNiftyVolumes) {
        Long instanceNo = niftyVolume.getInstanceNo();
        if (instanceNo != null) {
            List<NiftyVolume> niftyVolumes = niftyVolumesMap.get(instanceNo);
            if (niftyVolumes == null) {
                niftyVolumes = new ArrayList<NiftyVolume>();
                niftyVolumesMap.put(instanceNo, niftyVolumes);
            }
            niftyVolumes.add(niftyVolume);
        }
    }

    // VCloud 
    // VCloudPlatform?
    List<PlatformVcloud> platformVclouds = platformVcloudDao.readAll();
    Map<Long, PlatformVcloud> platformVcloudMap = new LinkedHashMap<Long, PlatformVcloud>();
    for (PlatformVcloud platformVcloud : platformVclouds) {
        platformVcloudMap.put(platformVcloud.getPlatformNo(), platformVcloud);
    }

    // VCloudImage?
    List<ImageVcloud> imageVclouds = imageVcloudDao.readAll();
    Map<Long, ImageVcloud> imageVcloudMap = new LinkedHashMap<Long, ImageVcloud>();
    for (ImageVcloud imageVcloud : imageVclouds) {
        imageVcloudMap.put(imageVcloud.getImageNo(), imageVcloud);
    }

    // VCloudInstance?
    List<VcloudInstance> vcloudInstances = vcloudInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, VcloudInstance> vcloudInstanceMap = new LinkedHashMap<Long, VcloudInstance>();
    for (VcloudInstance vcloudInstance : vcloudInstances) {
        vcloudInstanceMap.put(vcloudInstance.getInstanceNo(), vcloudInstance);
    }

    // VCloudKeyPair?
    Map<Long, VcloudKeyPair> vcloudKeyPairMap = new LinkedHashMap<Long, VcloudKeyPair>();
    List<VcloudKeyPair> vcloudKeyPairs = vcloudKeyPairDao.readByUserNo(farm.getUserNo());
    for (VcloudKeyPair vcloudKeyPair : vcloudKeyPairs) {
        vcloudKeyPairMap.put(vcloudKeyPair.getKeyNo(), vcloudKeyPair);
    }

    // VCloudDisk?
    List<VcloudDisk> farmVcloudDisks = vcloudDiskDao.readByFarmNo(farmNo);
    Map<Long, List<VcloudDisk>> vcloudDiskMap = new LinkedHashMap<Long, List<VcloudDisk>>();
    for (VcloudDisk vcloudDisk : farmVcloudDisks) {
        Long instanceNo = vcloudDisk.getInstanceNo();
        if (instanceNo != null) {
            List<VcloudDisk> vcloudDisks = vcloudDiskMap.get(instanceNo);
            if (vcloudDisks == null) {
                vcloudDisks = new ArrayList<VcloudDisk>();
            }
            vcloudDisks.add(vcloudDisk);
            vcloudDiskMap.put(instanceNo, vcloudDisks);
        }
    }

    //VCloudNetwork?
    List<VcloudInstanceNetwork> allVcloudInstanceNetworks = vcloudInstanceNetworkDao.readByFarmNo(farmNo);
    Map<Long, List<VcloudInstanceNetwork>> vcloudInstanceNetworkMap = new LinkedHashMap<Long, List<VcloudInstanceNetwork>>();
    for (VcloudInstanceNetwork vcloudInstanceNetwork : allVcloudInstanceNetworks) {
        List<VcloudInstanceNetwork> instanceNetworks = vcloudInstanceNetworkMap
                .get(vcloudInstanceNetwork.getInstanceNo());
        if (instanceNetworks == null) {
            instanceNetworks = new ArrayList<VcloudInstanceNetwork>();
        }
        instanceNetworks.add(vcloudInstanceNetwork);
        vcloudInstanceNetworkMap.put(vcloudInstanceNetwork.getInstanceNo(), instanceNetworks);
    }

    //PlatformVcloudStorageType?
    List<PlatformVcloudStorageType> platformVcloudStorageTypes = platformVcloudStorageTypeDao.readAll();
    Map<Long, PlatformVcloudStorageType> platformVcloudStorageTypeMap = new LinkedHashMap<Long, PlatformVcloudStorageType>();
    for (PlatformVcloudStorageType platformVcloudStorageType : platformVcloudStorageTypes) {
        platformVcloudStorageTypeMap.put(platformVcloudStorageType.getStorageTypeNo(),
                platformVcloudStorageType);
    }

    // Azure 
    // Azure?
    List<PlatformAzure> platformAzures = platformAzureDao.readAll();
    Map<Long, PlatformAzure> platformAzureMap = new LinkedHashMap<Long, PlatformAzure>();
    for (PlatformAzure platformAzure : platformAzures) {
        platformAzureMap.put(platformAzure.getPlatformNo(), platformAzure);
    }

    // Azure?
    List<ImageAzure> imageAzures = imageAzureDao.readAll();
    Map<Long, ImageAzure> imageAzureMap = new LinkedHashMap<Long, ImageAzure>();
    for (ImageAzure imageAzure : imageAzures) {
        imageAzureMap.put(imageAzure.getImageNo(), imageAzure);
    }

    // Azure?
    List<AzureInstance> azureInstances = azureInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, AzureInstance> azureInstanceMap = new LinkedHashMap<Long, AzureInstance>();
    for (AzureInstance azureInstance : azureInstances) {
        azureInstanceMap.put(azureInstance.getInstanceNo(), azureInstance);
    }

    // Azure??   ??????????
    //        List<AzureSubnet> azureAddresses = azureSubnetDao.readByAccount(farm.getUserNo());
    //        Map<Long, AzureSubnet> azureAddressMap = new LinkedHashMap<Long, AzureSubnet>();
    //        for (CloudstackAddress azureAddress : azureAddresses) {
    //            if (azureAddress.getInstanceNo() != null) {
    //                cloudstackAddressMap.put(azureAddress.getInstanceNo(), azureAddress);
    //            }
    //        }

    // Azure?
    List<AzureDisk> farmAzureDisks = azureDiskDao.readByFarmNo(farmNo);
    Map<Long, List<AzureDisk>> azureDisksMap = new LinkedHashMap<Long, List<AzureDisk>>();
    for (AzureDisk azureDisk : farmAzureDisks) {
        Long instanceNo = azureDisk.getInstanceNo();
        if (instanceNo != null) {
            List<AzureDisk> azureDisks = azureDisksMap.get(instanceNo);
            if (azureDisks == null) {
                azureDisks = new ArrayList<AzureDisk>();
                azureDisksMap.put(instanceNo, azureDisks);
            }
            azureDisks.add(azureDisk);
        }
    }

    // OpenStack 
    // OpenStack?
    List<PlatformOpenstack> platformOpenstacks = platformOpenstackDao.readAll();
    Map<Long, PlatformOpenstack> platformOpenstackMap = new LinkedHashMap<Long, PlatformOpenstack>();
    for (PlatformOpenstack platformOpenstack : platformOpenstacks) {
        platformOpenstackMap.put(platformOpenstack.getPlatformNo(), platformOpenstack);
    }

    // OpenStack?
    List<ImageOpenstack> imageOpenstacks = imageOpenstackDao.readAll();
    Map<Long, ImageOpenstack> imageOpenstackMap = new LinkedHashMap<Long, ImageOpenstack>();
    for (ImageOpenstack imageOpenstack : imageOpenstacks) {
        imageOpenstackMap.put(imageOpenstack.getImageNo(), imageOpenstack);
    }

    // OpenStack?
    List<OpenstackInstance> openstackInstances = openstackInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, OpenstackInstance> openstackInstanceMap = new LinkedHashMap<Long, OpenstackInstance>();
    for (OpenstackInstance openstackInstance : openstackInstances) {
        openstackInstanceMap.put(openstackInstance.getInstanceNo(), openstackInstance);
    }

    // ????????
    List<InstanceDto> dtos = new ArrayList<InstanceDto>();
    for (Instance instance : instances) {
        ZabbixInstance zabbixInstance = zabbixInstanceMap.get(instance.getInstanceNo());

        PlatformDto platformDto = new PlatformDto();
        ImageDto imageDto = new ImageDto();

        Platform platform = platformMap.get(instance.getPlatformNo());
        platformDto.setPlatform(platform);

        Image image = imageMap.get(instance.getImageNo());
        imageDto.setImage(image);
        // TODO CLOUD BRANCHING
        if (PCCConstant.PLATFORM_TYPE_AWS.equals(platform.getPlatformType())) {
            platformDto.setPlatformAws(platformAwsMap.get(instance.getPlatformNo()));
            imageDto.setImageAws(imageAwsMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_CLOUDSTACK.equals(platform.getPlatformType())) {
            platformDto.setPlatformCloudstack(platformCloudstackMap.get(instance.getPlatformNo()));
            imageDto.setImageCloudstack(imageCloudstackMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())) {
            platformDto.setPlatformVmware(platformVmwareMap.get(instance.getPlatformNo()));
            imageDto.setImageVmware(imageVmwareMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_NIFTY.equals(platform.getPlatformType())) {
            platformDto.setPlatformNifty(platformNiftyMap.get(instance.getPlatformNo()));
            imageDto.setImageNifty(imageNiftyMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_VCLOUD.equals(platform.getPlatformType())) {
            platformDto.setPlatformVcloud(platformVcloudMap.get(instance.getPlatformNo()));
            imageDto.setImageVcloud(imageVcloudMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_AZURE.equals(platform.getPlatformType())) {
            platformDto.setPlatformAzure(platformAzureMap.get(instance.getPlatformNo()));
            imageDto.setImageAzure(imageAzureMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType())) {
            platformDto.setPlatformOpenstack(platformOpenstackMap.get(instance.getPlatformNo()));
            imageDto.setImageOpenstack(imageOpenstackMap.get(instance.getImageNo()));
        }

        List<InstanceConfig> instanceConfigs = instanceConfigDao.readByInstanceNo(instance.getInstanceNo());

        List<ComponentInstanceDto> componentInstances = new ArrayList<ComponentInstanceDto>();
        for (ComponentInstance componentInstance : componentInstanceMap.get(instance.getInstanceNo())) {
            ComponentInstanceDto componentInstanceDto = new ComponentInstanceDto();
            componentInstanceDto.setComponentInstance(componentInstance);

            Component component = componentMap.get(componentInstance.getComponentNo());
            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);
            componentInstances.add(componentInstanceDto);
        }

        // ?????
        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());
        }

        // ????????
        instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
        for (ComponentInstanceDto componentInstanceDto : componentInstances) {
            ComponentInstance componentInstance = componentInstanceDto.getComponentInstance();
            ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
            if (BooleanUtils.isTrue(componentInstance.getEnabled())) {
                if (status == ComponentInstanceStatus.STOPPED) {
                    if (instanceStatus == InstanceStatus.WARNING) {
                        // ?Waring??????Warning??
                        componentInstance.setStatus(ComponentInstanceStatus.WARNING.toString());
                    } else if (BooleanUtils.isTrue(farm.getScheduled())) {
                        componentInstance.setStatus(ComponentInstanceStatus.STARTING.toString());
                    }
                }
            } else {
                if (status == ComponentInstanceStatus.RUNNING || status == ComponentInstanceStatus.WARNING) {
                    if (BooleanUtils.isTrue(farm.getScheduled())) {
                        // ??????Stopping??
                        componentInstance.setStatus(ComponentInstanceStatus.STOPPING.toString());
                    }
                }
            }
        }

        AwsInstance awsInstance = awsInstanceMap.get(instance.getInstanceNo());
        AwsAddress awsAddress = awsAddressMap.get(instance.getInstanceNo());
        List<AwsVolume> awsVolumes = awsVolumesMap.get(instance.getInstanceNo());
        AwsCertificate awsCertificate = awsCertificateMap.get(instance.getPlatformNo());

        CloudstackInstance cloudstackInstance = cloudstackInstanceMap.get(instance.getInstanceNo());
        CloudstackAddress cloudstackAddress = cloudstackAddressMap.get(instance.getInstanceNo());
        List<CloudstackVolume> cloudstackVolumes = cloudstackVolumesMap.get(instance.getInstanceNo());

        VmwareInstance vmwareInstance = vmwareInstanceMap.get(instance.getInstanceNo());
        VmwareAddress vmwareAddress = vmwareAddressMap.get(instance.getInstanceNo());
        VmwareKeyPair vmwareKeyPair = null;
        if (vmwareInstance != null) {
            vmwareKeyPair = vmwareKeyPairMap.get(vmwareInstance.getKeyPairNo());
        }
        List<VmwareDisk> vmwareDisks = vmwareDisksMap.get(instance.getInstanceNo());

        NiftyInstance niftyInstance = niftyInstanceMap.get(instance.getInstanceNo());
        NiftyKeyPair niftyKeyPair = null;
        if (niftyInstance != null) {
            niftyKeyPair = niftyKeyPairMap.get(niftyInstance.getKeyPairNo());
        }
        List<NiftyVolume> niftyVolumes = niftyVolumesMap.get(instance.getInstanceNo());

        VcloudInstance vcloudInstance = vcloudInstanceMap.get(instance.getInstanceNo());
        VcloudKeyPair vcloudKeyPair = null;
        if (vcloudInstance != null) {
            vcloudKeyPair = vcloudKeyPairMap.get(vcloudInstance.getKeyPairNo());
        }
        List<VcloudDisk> vcloudDisks = vcloudDiskMap.get(instance.getInstanceNo());
        List<VcloudInstanceNetwork> vcloudInstanceNetworks = vcloudInstanceNetworkMap
                .get(instance.getInstanceNo());
        if (vcloudInstanceNetworks != null) {
            Collections.sort(vcloudInstanceNetworks, Comparators.COMPARATOR_VCLOUD_INSTANCE_NETWORK);
        }
        PlatformVcloudStorageType platformVcloudStorageType = null;
        if (vcloudInstance != null) {
            platformVcloudStorageType = platformVcloudStorageTypeMap.get(vcloudInstance.getStorageTypeNo());
        }

        AzureInstance azureInstance = azureInstanceMap.get(instance.getInstanceNo());
        List<AzureDisk> azureDisks = azureDisksMap.get(instance.getInstanceNo());

        OpenstackInstance openstackInstance = openstackInstanceMap.get(instance.getInstanceNo());

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

        InstanceDto dto = new InstanceDto();
        dto.setInstance(instance);
        dto.setZabbixInstance(zabbixInstance);
        dto.setPlatform(platformDto);
        dto.setImage(imageDto);
        dto.setInstanceConfigs(instanceConfigs);
        dto.setComponentInstances(componentInstances);

        dto.setAwsInstance(awsInstance);
        dto.setAwsAddress(awsAddress);
        dto.setAwsVolumes(awsVolumes);
        dto.setAwsCertificate(awsCertificate);

        dto.setCloudstackInstance(cloudstackInstance);
        dto.setCloudstackAddress(cloudstackAddress);
        dto.setCloudstackVolumes(cloudstackVolumes);

        dto.setVmwareInstance(vmwareInstance);
        dto.setVmwareAddress(vmwareAddress);
        dto.setVmwareKeyPair(vmwareKeyPair);
        dto.setVmwareDisks(vmwareDisks);

        dto.setNiftyInstance(niftyInstance);
        dto.setNiftyKeyPair(niftyKeyPair);
        dto.setNiftyVolumes(niftyVolumes);

        dto.setVcloudInstance(vcloudInstance);
        dto.setVcloudKeyPair(vcloudKeyPair);
        dto.setVcloudDisks(vcloudDisks);
        dto.setVcloudInstanceNetworks(vcloudInstanceNetworks);
        dto.setPlatformVcloudStorageType(platformVcloudStorageType);

        dto.setAzureInstance(azureInstance);
        dto.setAzureDisks(azureDisks);

        dto.setOpenstackInstance(openstackInstance);

        dtos.add(dto);
    }

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

    return dtos;
}

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

/**
 * {@inheritDoc}/*from w ww  .ja v  a 2 s  .  c om*/
 */
protected void doAssociate(Long componentNo, List<Long> instanceNos) {
    Component component = componentDao.read(componentNo);

    // ????
    List<Instance> allInstances = instanceDao.readByFarmNo(component.getFarmNo());
    List<ComponentInstance> componentInstances = componentInstanceDao.readByComponentNo(componentNo);
    for (Instance instance : allInstances) {
        // ???????
        ComponentInstance componentInstance = null;
        for (ComponentInstance tmpComponentInstance : componentInstances) {
            if (instance.getInstanceNo().equals(tmpComponentInstance.getInstanceNo())) {
                componentInstance = tmpComponentInstance;
                break;
            }
        }

        if (instanceNos.contains(instance.getInstanceNo())) {
            // ??????
            if (componentInstance == null) {
                // ????????
                componentInstance = new ComponentInstance();
                componentInstance.setComponentNo(componentNo);
                componentInstance.setInstanceNo(instance.getInstanceNo());
                componentInstance.setAssociate(true);
                componentInstance.setEnabled(false);
                componentInstance.setStatus(ComponentInstanceStatus.STOPPED.toString());
                componentInstanceDao.create(componentInstance);
            } else {
                // ???????
                if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) {
                    componentInstance.setAssociate(true);
                    componentInstanceDao.update(componentInstance);
                }
            }
        } else {
            // ????????
            if (componentInstance != null) {
                // ????
                ComponentInstanceStatus status = ComponentInstanceStatus
                        .fromStatus(componentInstance.getStatus());
                if (status == ComponentInstanceStatus.STOPPED) {
                    // Zabbix???
                    if (zabbixInstanceDao.countByInstanceNo(componentInstance.getInstanceNo()) > 0) {
                        zabbixHostProcess.removeTemplate(componentInstance.getInstanceNo(), componentNo);
                    }

                    /******************************************************************
                     * ???????
                     * ??VCLOUDUSiZE?????
                     ******************************************************************/
                    List<VcloudDisk> vdisks = vcloudDiskDao.readByInstanceNo(instance.getInstanceNo());
                    for (VcloudDisk disk : vdisks) {
                        if (componentNo.equals(disk.getComponentNo())) {
                            //componentNo????????
                            Farm farm = farmDao.read(instance.getFarmNo());
                            IaasGatewayWrapper gateway = iaasGatewayFactory.createIaasGateway(farm.getUserNo(),
                                    instance.getPlatformNo());
                            try {
                                gateway.deleteVolume(String.valueOf(disk.getDiskNo()));
                            } catch (AutoException ignore) {
                                // ??????????????
                            }
                            //
                            vcloudDiskDao.delete(disk);
                        }
                    }

                    // ???????????
                    componentInstanceDao.delete(componentInstance);
                } else {
                    // ??
                    if (BooleanUtils.isTrue(componentInstance.getAssociate())) {
                        componentInstance.setAssociate(false);
                        componentInstanceDao.update(componentInstance);
                    }
                }
            }
        }
    }

    ComponentType componentType = componentTypeDao.read(component.getComponentTypeNo());

    // MySQL?????Master?Slave?
    if (MySQLConstants.COMPONENT_TYPE_NAME.equals(componentType.getComponentTypeName())) {
        // Master/Slave??
        Long masterInstanceNo = null;
        Set<Long> slaveInstanceNos = new LinkedHashSet<Long>();
        List<InstanceConfig> instanceConfigs = instanceConfigDao.readByComponentNo(componentNo);
        for (InstanceConfig instanceConfig : instanceConfigs) {
            if (MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO.equals(instanceConfig.getConfigName())) {
                if (StringUtils.isEmpty(instanceConfig.getConfigValue())) {
                    masterInstanceNo = instanceConfig.getInstanceNo();
                } else {
                    slaveInstanceNos.add(instanceConfig.getInstanceNo());
                }
            }
        }

        // Master?????????Master??
        if (masterInstanceNo == null && instanceNos.size() > 0) {
            masterInstanceNo = instanceNos.get(0);

            InstanceConfig instanceConfig = new InstanceConfig();
            instanceConfig.setInstanceNo(masterInstanceNo);
            instanceConfig.setComponentNo(componentNo);
            instanceConfig.setConfigName(MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO);
            instanceConfig.setConfigValue(null);
            instanceConfigDao.create(instanceConfig);
        }

        // Master/Slave??????Slave??
        if (masterInstanceNo != null) {
            for (Long instanceNo : instanceNos) {
                if (!instanceNo.equals(masterInstanceNo) && !slaveInstanceNos.contains(instanceNo)) {
                    InstanceConfig instanceConfig = new InstanceConfig();
                    instanceConfig.setInstanceNo(instanceNo);
                    instanceConfig.setComponentNo(componentNo);
                    instanceConfig.setConfigName(MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO);
                    instanceConfig.setConfigValue(masterInstanceNo.toString());
                    instanceConfigDao.create(instanceConfig);
                }
            }
        }
    }
}

From source file:com.evolveum.midpoint.model.impl.lens.projector.focus.ObjectTemplateProcessor.java

private <F extends FocusType, T extends FocusType> void collectAutoassignMappings(LensContext<F> context,
        List<FocalMappingSpec> mappings, Task task, OperationResult result)
        throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException,
        PolicyViolationException, SecurityViolationException, ConfigurationException, CommunicationException {

    if (!autoassignEnabled(context.getSystemConfiguration())) {
        return;/* ww w.j  a va  2  s  .c om*/
    }

    ObjectQuery query = QueryBuilder.queryFor(AbstractRoleType.class, prismContext)
            .item(SchemaConstants.PATH_AUTOASSIGN_ENABLED).eq(true).build();

    ResultHandler<AbstractRoleType> handler = (role, objectResult) -> {
        AutoassignSpecificationType autoassign = role.asObjectable().getAutoassign();
        if (autoassign == null) {
            return true;
        }
        if (!BooleanUtils.isTrue(autoassign.isEnabled())) {
            return true;
        }
        FocalAutoassignSpecificationType focalAutoassignSpec = autoassign.getFocus();
        if (focalAutoassignSpec == null) {
            return true;
        }
        for (AutoassignMappingType autoMapping : focalAutoassignSpec.getMapping()) {
            AutoassignMappingType mapping = autoMapping.clone();
            setMappingTarget(mapping, SchemaConstants.PATH_ASSIGNMENT.asItemPathType());
            mappings.add(new FocalMappingSpec(mapping, role.asObjectable()));
            LOGGER.trace("Collected autoassign mapping {} from {}", mapping.getName(), role);
        }
        return true;
    };
    cacheRepositoryService.searchObjectsIterative(AbstractRoleType.class, query, handler,
            GetOperationOptions.createReadOnlyCollection(), false, result);
}

From source file:gov.nih.nci.cabig.caaers.api.impl.SafetyReportServiceImpl.java

@Transactional(readOnly = false)
public void initiateSafetyReportAction(EvaluateAndInitiateInputMessage evaluateInputMessage,
        SaveAndEvaluateAEsOutputMessage response, EvaluateAndInitiateOutputMessage retVal,
        AdverseEventReportingPeriod repPeriod) {

    RecommendedActions withdrawAction = null;
    RecommendedActions createAction = null;
    RecommendedActions amendAction = null;

    boolean explicitWithdraw = false;
    boolean replace = false;
    boolean withdraw = false;
    boolean create = false;
    boolean amend = false;

    ExpeditedAdverseEventReport aeSrcReport = evaluateAndInitiateReportConverter.convert(evaluateInputMessage,
            repPeriod, response);//from  w  ww  .j a  v a 2  s  . c o  m
    ValidationErrors errors = new ValidationErrors();
    List<RecommendedActions> recActions = response.getRecommendedActions();

    //explicit withdraw request ?
    if (BooleanUtils.isTrue(evaluateInputMessage.isWithdrawReport())) {

        explicitWithdraw = true;
        if (!recActions.isEmpty()) {
            final RecommendedActions action = recActions.get(0);
            action.setAction("Withdraw");
            action.setActionText("Withdraw the " + action.getReport());
            action.setDue("Never");
            action.setDueDate(null);
            response.getRecommendedActions().clear();
            response.getRecommendedActions().add(action);
        }

    } else {
        //not an explicit withdraw, so perform all the recommendations
        amendAction = findRecommendedActions(recActions, ActionType.AMEND);
        createAction = findRecommendedActions(recActions, ActionType.CREATE);
        withdrawAction = findRecommendedActions(recActions, ActionType.WITHDRAW);

        withdraw = withdrawAction != null;
        amend = amendAction != null;
        create = createAction != null;
        replace = create && withdraw;

        if (replace) {
            aeSrcReport.removeReport(withdrawAction.getReport());
        } else if (amend && create) {
            aeSrcReport.removeReport(amendAction.getReport());
        }
    }

    //CAAERS-7414 - always respond with a report-id
    String caseNumber = aeSrcReport.getExternalId();
    if (!explicitWithdraw && StringUtils.isEmpty(caseNumber)) {
        caseNumber = generateSafetyReportId();
        aeSrcReport.setExternalId(caseNumber);
        for (Report report : aeSrcReport.getReports())
            report.setCaseNumber(caseNumber);
    }
    retVal.setReportId(caseNumber);

    //perform the recomended action
    CaaersServiceResponseWrapper caaersServiceResponseWrapper = Helper.createResponseWrapper();
    if (!response.getRecommendedActions().isEmpty()) {

        initiateSafetyReportAction(aeSrcReport, caaersServiceResponseWrapper, errors);
        //are there errors ?
        if (errors.getErrorCount() > 0) {
            throw new CaaersValidationException(errors.toString());
        }
    }

    //update the amendment number if the report is amendable.
    for (RecommendedActions action : recActions) {
        if (StringUtils.equalsIgnoreCase(action.getAction(), "Create")) {
            action.setStatus("In process");
        }
        String due = (String) caaersServiceResponseWrapper
                .getAdditionalInfo(action.getReport() + "_displayDue");
        String dueDate = (String) caaersServiceResponseWrapper.getAdditionalInfo(action.getReport() + "_due");
        if (StringUtils.isNotEmpty(due))
            action.setDue(due);
        if (StringUtils.isNotEmpty(dueDate))
            action.setDueDate(dueDate);
        Boolean amendable = (Boolean) caaersServiceResponseWrapper
                .getAdditionalInfo(action.getReport() + "_amendable");
        String strAmendmentNumber = (String) caaersServiceResponseWrapper
                .getAdditionalInfo(action.getReport() + "_amendmentNumber");
        BigInteger amendmentNumber = NumberUtils.isNumber(strAmendmentNumber)
                ? new BigInteger(strAmendmentNumber)
                : null;
        if (BooleanUtils.isTrue(amendable)) {
            action.setAmendmentNumber(amendmentNumber);
        }
    }

}