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:jp.primecloud.auto.service.impl.LoadBalancerServiceImpl.java

/**
 * {@inheritDoc}//from   w ww  . j a  va 2s . co  m
 */
@Override
public void disableInstances(Long loadBalancerNo, List<Long> instanceNos) {
    // ?
    if (loadBalancerNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "loadBalancerNo");
    }
    if (instanceNos == null) {
        throw new AutoApplicationException("ECOMMON-000003", "instanceNos");
    }

    // ???
    LoadBalancer loadBalancer = loadBalancerDao.read(loadBalancerNo);
    if (loadBalancer == null) {
        // ??????
        throw new AutoApplicationException("ESERVICE-000603", loadBalancerNo);
    }

    // ???
    List<Long> tmpInstanceNos = new ArrayList<Long>();
    for (Long instanceNo : instanceNos) {
        if (!tmpInstanceNos.contains(instanceNo)) {
            tmpInstanceNos.add(instanceNo);
        }
    }
    instanceNos = tmpInstanceNos;

    // ??
    List<Instance> instances = instanceDao.readInInstanceNos(instanceNos);
    if (instanceNos.size() != instances.size()) {
        tmpInstanceNos = new ArrayList<Long>(instanceNos);
        for (Instance instance : instances) {
            tmpInstanceNos.remove(instance.getInstanceNo());
        }
        if (tmpInstanceNos.size() > 0) {
            throw new AutoApplicationException("ESERVICE-000621", tmpInstanceNos.iterator().next());
        }
    }

    // ????
    List<ComponentInstance> componentInstances = componentInstanceDao
            .readByComponentNo(loadBalancer.getComponentNo());
    for (Instance instance : instances) {
        boolean contain = false;
        for (ComponentInstance componentInstance : componentInstances) {
            if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) {
                continue;
            }
            if (componentInstance.getInstanceNo().equals(instance.getInstanceNo())) {
                contain = true;
                break;
            }
        }
        if (!contain) {
            // ???????????
            Component component = componentDao.read(loadBalancer.getComponentNo());
            throw new AutoApplicationException("ESERVICE-000622", instance.getInstanceName(),
                    component.getComponentName());
        }
    }

    // ???
    List<LoadBalancerInstance> lbInstances = loadBalancerInstanceDao.readByLoadBalancerNo(loadBalancerNo);
    Map<Long, LoadBalancerInstance> lbInstanceMap = new HashMap<Long, LoadBalancerInstance>();
    for (LoadBalancerInstance lbInstance : lbInstances) {
        lbInstanceMap.put(lbInstance.getInstanceNo(), lbInstance);
    }

    // ??
    for (Instance instance : instances) {
        // ???????
        LoadBalancerInstance lbInstance = lbInstanceMap.remove(instance.getInstanceNo());

        if (lbInstance == null) {
            // ??????
            continue;
        }

        // ????
        if (BooleanUtils.isTrue(lbInstance.getEnabled())) {
            lbInstance.setEnabled(false);
            loadBalancerInstanceDao.update(lbInstance);
        }
    }

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

    // ??
    Farm farm = farmDao.read(loadBalancer.getFarmNo());
    if (BooleanUtils.isNotTrue(farm.getScheduled())) {
        farm.setScheduled(true);
        farmDao.update(farm);
    }
}

From source file:jp.primecloud.auto.ui.WinServerEdit.java

private void initData() {
    // ??/*from   w  w  w  .  j a  v  a2s.co m*/
    // TODO: ?????
    InstanceService instanceService = BeanContext.getBean(InstanceService.class);
    this.instance = instanceService.getInstance(instanceNo);

    //LB????
    this.isLoadBalancer = BooleanUtils.isTrue(instance.getInstance().getLoadBalancer());

    // ??
    // TODO: ????
    Long imageNo = instance.getInstance().getImageNo();
    List<PlatformDto> platforms = instanceService.getPlatforms(ViewContext.getUserNo());
    for (PlatformDto platformDto : platforms) {
        if (instance.getInstance().getPlatformNo().equals(platformDto.getPlatform().getPlatformNo())) {
            this.platformDto = platformDto;
            for (ImageDto image : platformDto.getImages()) {
                if (imageNo.equals(image.getImage().getImageNo())) {
                    this.image = image;
                    break;
                }
            }
            break;
        }
    }

    Platform platform = platformDto.getPlatform();
    String platformType = platform.getPlatformType();
    // TODO CLOUD BRANCHING
    if (PCCConstant.PLATFORM_TYPE_AWS.equals(platformType)) {
        PlatformAws platformAws = platformDto.getPlatformAws();
        // ?
        // TODO: ????
        IaasDescribeService describeService = BeanContext.getBean(IaasDescribeService.class);
        //
        List<KeyPairDto> infos = describeService.getKeyPairs(ViewContext.getUserNo(), platform.getPlatformNo());
        keyPairs = new ArrayList<String>();
        for (KeyPairDto info : infos) {
            keyPairs.add(info.getKeyName());
        }

        //
        securityGroups = new ArrayList<String>();
        List<SecurityGroupDto> groups;
        if (platformAws.getEuca() == false && platformAws.getVpc()) {
            groups = describeService.getSecurityGroups(ViewContext.getUserNo(), platform.getPlatformNo(),
                    platformAws.getVpcId());
        } else {
            groups = describeService.getSecurityGroups(ViewContext.getUserNo(), platform.getPlatformNo(), null);
        }
        for (SecurityGroupDto group : groups) {
            securityGroups.add(group.getGroupName());
        }

        //
        instanceTypes = new ArrayList<String>();
        for (String instanceType : image.getImageAws().getInstanceTypes().split(",")) {
            instanceTypes.add(instanceType.trim());
        }

        //
        zones = describeService.getAvailabilityZones(ViewContext.getUserNo(), platform.getPlatformNo());
        if (platformAws.getEuca() == false && platformAws.getVpc() == false) {
            //EC2 VPC????????????????
            zones.add(0, new ZoneDto());
        }

        //?
        if (platformAws.getEuca() == false && platformAws.getVpc()) {
            subnets = describeService.getSubnets(ViewContext.getUserNo(), platform.getPlatformNo(),
                    platformAws.getVpcId());
        }

        //ElasticIp
        elasticIps = new ArrayList<AddressDto>();
        List<AddressDto> addresses = describeService.getAddresses(ViewContext.getUserNo(),
                platform.getPlatformNo());
        for (AddressDto address : addresses) {
            elasticIps.add(address);
        }

    } else if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platformType)) {
        // VMware?
        // TODO: ????
        VmwareDescribeService vmwareDescribeService = BeanContext.getBean(VmwareDescribeService.class);
        vmwareKeyPairs = vmwareDescribeService.getKeyPairs(ViewContext.getUserNo(), platform.getPlatformNo());
        keyPairs = new ArrayList<String>();
        for (VmwareKeyPair vmwareKeyPair : vmwareKeyPairs) {
            keyPairs.add(vmwareKeyPair.getKeyName());
        }

        List<ComputeResource> computeResources = vmwareDescribeService
                .getComputeResources(platform.getPlatformNo());
        clusters = new ArrayList<String>();
        for (ComputeResource computeResource : computeResources) {
            clusters.add(computeResource.getName());
        }

        instanceTypes = new ArrayList<String>();
        for (String instanceType : image.getImageVmware().getInstanceTypes().split(",")) {
            instanceTypes.add(instanceType.trim());
        }
    } else if (PCCConstant.PLATFORM_TYPE_NIFTY.equals(platformType)) {
        // Nifty?
        // TODO: ????
        NiftyDescribeService niftyDescribeService = BeanContext.getBean(NiftyDescribeService.class);
        niftyKeyPairs = niftyDescribeService.getKeyPairs(ViewContext.getUserNo(), platform.getPlatformNo());
        keyPairs = new ArrayList<String>();
        for (NiftyKeyPair niftyKeyPair : niftyKeyPairs) {
            keyPairs.add(niftyKeyPair.getKeyName());
        }

        instanceTypes = new ArrayList<String>();
        for (String instanceType : image.getImageNifty().getInstanceTypes().split(",")) {
            instanceTypes.add(instanceType.trim());
        }
    } else if (PCCConstant.PLATFORM_TYPE_CLOUDSTACK.equals(platformType)) {
        // CloudStack?
        // ?
        // TODO: ????
        IaasDescribeService describeService = BeanContext.getBean(IaasDescribeService.class);
        List<KeyPairDto> infos = describeService.getKeyPairs(ViewContext.getUserNo(), platform.getPlatformNo());
        keyPairs = new ArrayList<String>();
        for (KeyPairDto info : infos) {
            keyPairs.add(info.getKeyName());
        }

        networks = new ArrayList<String>();
        for (String network : platformDto.getPlatformCloudstack().getNetworkId().split(",")) {
            networks.add(network);
        }

        securityGroups = new ArrayList<String>();
        if (StringUtils.isEmpty(instance.getCloudstackInstance().getNetworkid())) {
            List<SecurityGroupDto> groups = describeService.getSecurityGroups(ViewContext.getUserNo(),
                    platform.getPlatformNo(), null);
            for (SecurityGroupDto group : groups) {
                securityGroups.add(group.getGroupName());
            }
        }

        instanceTypes = new ArrayList<String>();
        for (String instanceType : image.getImageCloudstack().getInstanceTypes().split(",")) {
            instanceTypes.add(instanceType.trim());
        }

        zones = describeService.getAvailabilityZones(ViewContext.getUserNo(), platform.getPlatformNo());

        elasticIps = new ArrayList<AddressDto>();
        List<AddressDto> addresses = describeService.getAddresses(ViewContext.getUserNo(),
                platform.getPlatformNo());
        for (AddressDto address : addresses) {
            elasticIps.add(address);
        }

    } else if (PCCConstant.PLATFORM_TYPE_VCLOUD.equals(platformType)) {
        // VCloud?
        IaasDescribeService describeService = BeanContext.getBean(IaasDescribeService.class);
        //StorageType
        storageTypes = describeService.getStorageTypes(ViewContext.getUserNo(), platform.getPlatformNo());

        //KeyPair
        vcloudKeyPairs = describeService.getKeyPairs(ViewContext.getUserNo(), platform.getPlatformNo());

        //InstanceType
        instanceTypes = new ArrayList<String>();
        for (String instanceType : image.getImageVcloud().getInstanceTypes().split(",")) {
            instanceTypes.add(instanceType.trim());
        }

        //DataDisk
        deleteDataDisks = new ArrayList<DataDiskDto>();
        dataDisks = new ArrayList<DataDiskDto>();
        List<VcloudDisk> vcloudDisks = instance.getVcloudDisks();
        for (VcloudDisk vcloudDisk : vcloudDisks) {
            if (BooleanUtils.isTrue(vcloudDisk.getDataDisk())) {
                DataDiskDto diskDto = new DataDiskDto();
                diskDto.setDiskNo(vcloudDisk.getDiskNo());
                diskDto.setDiskSize(vcloudDisk.getSize());
                diskDto.setUnitNo(vcloudDisk.getUnitNo());
                dataDisks.add(diskDto);
            }
        }

        //Network
        List<NetworkDto> networkDtos = describeService.getNetworks(ViewContext.getUserNo(),
                platform.getPlatformNo());
        networkMap = new HashMap<String, NetworkDto>();
        for (NetworkDto networkDto : networkDtos) {
            networkMap.put(networkDto.getNetworkName(), networkDto);
        }

        //InstanceNetwork
        instanceNetworks = new ArrayList<InstanceNetworkDto>();
        List<VcloudInstanceNetwork> tmpInstanceNetworks = this.instance.getVcloudInstanceNetworks();
        for (VcloudInstanceNetwork instanceNetwork : tmpInstanceNetworks) {
            InstanceNetworkDto instanceNetworkDto = new InstanceNetworkDto();
            instanceNetworkDto.setNetworkNo(instanceNetwork.getNetworkNo());
            instanceNetworkDto.setNetworkName(instanceNetwork.getNetworkName());
            instanceNetworkDto.setNew(false);
            instanceNetworkDto.setDelete(false);
            instanceNetworkDto.setIpMode(instanceNetwork.getIpMode());
            instanceNetworkDto.setIpAddress(instanceNetwork.getIpAddress());
            instanceNetworkDto.setRequired(networkMap.get(instanceNetwork.getNetworkName()).isPcc());
            instanceNetworkDto.setPrimary(BooleanUtils.isTrue(instanceNetwork.getIsPrimary()));
            instanceNetworks.add(instanceNetworkDto);
        }

    } else if (PCCConstant.PLATFORM_TYPE_AZURE.equals(platformType)) {
        // Azure?
        PlatformAzure platformAzure = platformDto.getPlatformAzure();
        // ?
        IaasDescribeService describeService = BeanContext.getBean(IaasDescribeService.class);

        instanceTypes = new ArrayList<String>();
        for (String instanceType : image.getImageAzure().getInstanceTypes().split(",")) {
            instanceTypes.add(instanceType.trim());
        }
        // ?
        availabilitySets = new ArrayList<String>();
        for (String availabilitySet : platformAzure.getAvailabilitySets().split(",")) {
            availabilitySets.add(availabilitySet.trim());
        }
        //?
        subnets = describeService.getAzureSubnets(ViewContext.getUserNo(), platform.getPlatformNo(),
                platformAzure.getNetworkName());

    } else if (PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platformType)) {
        // ?
        IaasDescribeService describeService = BeanContext.getBean(IaasDescribeService.class);
        //instanceTypes
        instanceTypes = new ArrayList<String>();
        for (String instanceType : image.getImageOpenstack().getInstanceTypes().split(",")) {
            //ID????????????
            instanceTypes.add(instanceType.trim());
        }
        // Availablility Zone
        zones = describeService.getAvailabilityZones(ViewContext.getUserNo(), platform.getPlatformNo());

        //
        securityGroups = new ArrayList<String>();
        List<SecurityGroupDto> groups;
        groups = describeService.getSecurityGroups(ViewContext.getUserNo(), platform.getPlatformNo(), null);
        for (SecurityGroupDto group : groups) {
            securityGroups.add(group.getGroupName());
        }

        //
        List<KeyPairDto> infos = describeService.getKeyPairs(ViewContext.getUserNo(), platform.getPlatformNo());
        keyPairs = new ArrayList<String>();
        for (KeyPairDto info : infos) {
            keyPairs.add(info.getKeyName());
        }

    }

    // ?????
    componentNos = new ArrayList<Long>();
    List<ComponentInstanceDto> componentInstances = instance.getComponentInstances();
    for (ComponentInstanceDto componentInstance : componentInstances) {
        if (BooleanUtils.isTrue(componentInstance.getComponentInstance().getAssociate())) {
            componentNos.add(componentInstance.getComponentInstance().getComponentNo());
        }
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java

protected String generateDefaultCellStyle(Object itemId, Object propertyId, MetaPropertyPath propertyPath) {
    String style = null;// ww w . ja  v a2s .c  o  m

    Column column = getColumn(propertyId.toString());
    if (column != null) {
        final String isLink = column.getXmlDescriptor() == null ? null
                : column.getXmlDescriptor().attributeValue("link");

        if (propertyPath.getRange().isClass()) {
            if (StringUtils.isNotEmpty(isLink) && Boolean.valueOf(isLink)) {
                style = "c-table-cell-link";
            }
        } else if (propertyPath.getRange().isDatatype()) {
            if (StringUtils.isNotEmpty(isLink) && Boolean.valueOf(isLink)) {
                style = "c-table-cell-link";
            } else if (column.getMaxTextLength() != null) {
                Entity item = getDatasource().getItemNN(itemId);
                Object value = item.getValueEx(propertyId.toString());
                String stringValue;
                if (value instanceof String) {
                    stringValue = item.getValueEx(propertyId.toString());
                } else {
                    if (DynamicAttributesUtils.isDynamicAttribute(propertyPath.getMetaProperty())) {
                        stringValue = DynamicAttributesUtils
                                .getDynamicAttributeValueAsString(propertyPath.getMetaProperty(), value);
                    } else {
                        stringValue = value == null ? null : value.toString();
                    }
                }
                if (column.getMaxTextLength() != null) {
                    boolean isMultiLineCell = StringUtils.contains(stringValue, "\n");
                    if ((stringValue != null
                            && stringValue.length() > column.getMaxTextLength() + MAX_TEXT_LENGTH_GAP)
                            || isMultiLineCell) {
                        style = "c-table-cell-textcut";
                    } else {
                        // use special marker stylename
                        style = "c-table-clickable-text";
                    }
                }
            }
        }
    }

    if (propertyPath.getRangeJavaClass() == Boolean.class) {
        Entity item = datasource.getItem(itemId);
        if (item != null) {
            Boolean value = item.getValueEx(propertyId.toString());
            if (BooleanUtils.isTrue(value)) {
                style = "boolean-cell boolean-cell-true";
            } else {
                style = "boolean-cell boolean-cell-false";
            }
        }
    }
    return style;
}

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

@Override
public PersonneDto creerPersonnePhysiqueGestionVivier(PersonneDto personneDto,
        List<BeneficiaireDto> listeBeneficiaire, AdresseDto adresse, EmailDto email, TelephoneDto telephone) {
    // On dtermine s'il s'agit d'un vivier ou d'un prospect
    final RapportDto rapport = new RapportDto();
    TelephoneDto telephoneFixeDto = null;
    TelephoneDto telephonePortableDto = null;
    if (telephone != null && telephone.getNature() != null) {
        if (squareMappingService.getIdNatureTelephoneFixe().equals(telephone.getNature().getIdentifiant())) {
            telephoneFixeDto = telephone;
        } else if (squareMappingService.getIdNatureMobilePrive()
                .equals(telephone.getNature().getIdentifiant())) {
            telephonePortableDto = telephone;
        }/*from  w w  w .ja  va 2 s . c  om*/
    }
    validationPersonneUtil.verifierContrainteCreationProspect(personneDto, email, adresse, telephoneFixeDto,
            telephonePortableDto, rapport);
    final IdentifiantLibelleDto naturePersonne = new IdentifiantLibelleDto();
    if (rapport.getEnErreur()) {
        // Vivier
        naturePersonne.setIdentifiant(squareMappingService.getIdNaturePersonneVivier());
    } else {
        // Prospect
        naturePersonne.setIdentifiant(squareMappingService.getIdNaturePersonneProspect());
    }
    personneDto.setNaturePersonne(naturePersonne);

    // On mappe les coordonnes en objet du modle
    Adresse adressePrincipale = null;
    Email emailPersonnel = null;
    Telephone telephoneFixe = null;
    Telephone telephonePortable = null;
    if (adresse != null) {
        adressePrincipale = mapperAdressePourCreation(adresse);
    }
    if (email != null) {
        emailPersonnel = mapperEmailPourCreation(email);
    }
    if (telephoneFixeDto != null) {
        telephoneFixe = mapperTelephonePourCreation(telephoneFixeDto);
    }
    if (telephonePortableDto != null) {
        telephonePortable = mapperTelephonePourCreation(telephonePortableDto);
    }
    final PersonnePhysique personnePrincipale = mapperPersonnePourCreation(personneDto, adressePrincipale,
            emailPersonnel, telephoneFixe, telephonePortable);
    personnePhysiqueDao.creerPersonnePhysique(personnePrincipale);

    // cration des bnficiaires
    if (listeBeneficiaire != null && listeBeneficiaire.size() > 0) {
        Long idConjoint = null;
        for (BeneficiaireDto beneficiaireDto : listeBeneficiaire) {
            // si le benef ne remplit pas au moins un des champs, on en tient pas compte
            if (!validationPersonneUtil.verifierContrainteBeneficiaireVivier(beneficiaireDto)) {
                continue;
            }
            final RapportDto rapportBeneficiaire = new RapportDto();
            final List<BeneficiaireDto> listeBenef = new ArrayList<BeneficiaireDto>();
            listeBenef.add(beneficiaireDto);
            validationPersonneUtil.verifierContrainteCreationBeneficiaires(listeBenef, rapportBeneficiaire);
            final IdentifiantLibelleDto natureBeneficiaire = new IdentifiantLibelleDto();
            if (rapport.getEnErreur() || rapportBeneficiaire.getEnErreur()) {
                // Bnficiaire Vivier
                natureBeneficiaire.setIdentifiant(squareMappingService.getIdNaturePersonneBeneficiaireVivier());
            } else {
                // Bnficiaire Prospect
                natureBeneficiaire
                        .setIdentifiant(squareMappingService.getIdNaturePersonneBeneficiaireProspect());
            }
            final PersonneDto beneficiairePersonneDto = mapperBeneficiaireEnPersonneDto(beneficiaireDto,
                    personnePrincipale);
            beneficiairePersonneDto.setNaturePersonne(natureBeneficiaire);
            final PersonnePhysique beneficiaire = mapperPersonnePourCreation(beneficiairePersonneDto,
                    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);

            // Si le bnficiaire est le conjoint, on rcupre son id.
            if (type.getId().equals(squareMappingService.getIdTypeRelationConjoint())) {
                idConjoint = beneficiaire.getId();
            }
            // 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())) {
                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));
                }
            }
        }
    }

    return rechercherPersonneParIdentifiant(personnePrincipale.getId());
}

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

/**
 * {@inheritDoc}//  w  w  w .  j  a  v  a2  s .  c o m
 */
@Override
public void detachDataDisk(Long instanceNo, Long diskNo) {
    // ?
    if (instanceNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "instanceNo");
    }

    // ??
    Instance instance = instanceDao.read(instanceNo);
    if (instance == null) {
        throw new AutoApplicationException("ESERVICE-000403", instanceNo);
    }

    //?
    if (InstanceStatus.fromStatus(instance.getStatus()) != InstanceStatus.STOPPED
            && InstanceStatus.fromStatus(instance.getStatus()) != InstanceStatus.RUNNING) {
        //??? or ????
        throw new AutoApplicationException("ESERVICE-000429", instance.getInstanceName());
    }

    //IaasGateWay?
    VcloudDisk vcloudDisk = vcloudDiskDao.read(diskNo);
    if (BooleanUtils.isTrue(vcloudDisk.getAttached())) {
        //???????????
        Farm farm = farmDao.read(instance.getFarmNo());
        IaasGatewayWrapper gateway = iaasGatewayFactory.createIaasGateway(farm.getUserNo(),
                instance.getPlatformNo());
        // ?
        // VCloud??DiskNo
        gateway.deleteVolume(String.valueOf(vcloudDisk.getDiskNo()));
    }

    //
    vcloudDiskDao.delete(vcloudDisk);
}

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

@Override
public AdresseCreationDto ajouterNouvelleAdresse(Long idPersonne, AdresseDto adresseDto,
        Boolean impacterFamille) {
    final RapportDto rapport = new RapportDto();
    if (adresseDto == null) {
        throw new BusinessException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_ADRESSE_DTO_NULL));
    }//from w  w w. j av  a 2 s  .c  om
    // Rcupration de la personne en base.
    final Personne personnePrincipale = personneDao.rechercherPersonneParId(idPersonne);
    if (personnePrincipale == null) {
        throw new BusinessException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PERSONNE_INEXISTANTE));
    }
    // Recherche de l'adresse principale actuelle
    final AdresseCriteresRechercheDto criteresRechercheAdressePrincipale = new AdresseCriteresRechercheDto();
    criteresRechercheAdressePrincipale.setIdPersonne(personnePrincipale.getId());
    criteresRechercheAdressePrincipale.setIdNature(squareMappingService.getIdNatureAdressePrincipale());
    criteresRechercheAdressePrincipale.setActive(true);
    final List<Adresse> listAdressesPrincipales = adresseDao
            .rechercherAdresseParCritere(criteresRechercheAdressePrincipale);
    Adresse adressePrincipaleEnCours = new Adresse();
    boolean plusQueAdressePrincipale = false;
    boolean choixPasserEnSecondaire = false;
    if (listAdressesPrincipales != null && listAdressesPrincipales.size() > 0) {
        adressePrincipaleEnCours = listAdressesPrincipales.get(0);
    }
    final Long idNatureAdressePrincipale = squareMappingService.getIdNatureAdressePrincipale();
    final Long idNatureAdresseSecondaire = squareMappingService.getIdNatureAdresseSecondaire();
    final AdresseNature natureAdressePrincipale = adresseNatureDao
            .rechercheAdresseNatureParId(idNatureAdressePrincipale);
    final AdresseNature natureAdresseSecondaire = adresseNatureDao
            .rechercheAdresseNatureParId(idNatureAdresseSecondaire);
    // Si l'adresse  ajouter est une adresse principale et est diffrente de l'adresse principale actuelle
    if (adresseDto.getNature() != null
            && adresseDto.getNature().getIdentifiant().equals(idNatureAdressePrincipale)
            && adressePrincipaleEnCours.getId() != null
            && !adressePrincipaleEnCours.getId().equals(adresseDto.getIdentifiant())) {
        // Est ce que l'adresse  ajouter doit remplacer l'adresse principale actuelle?
        choixPasserEnSecondaire = BooleanUtils.isTrue(adresseDto.getChoixPasserEnSecondaire());
        plusQueAdressePrincipale = true;
    }
    // Si aucune date de dbut n'est renseigne pour l'adresse
    if (adresseDto.getDateDebut() == null) {
        // On initialise la date de dbut de l'adresse  la date courante
        adresseDto.setDateDebut(Calendar.getInstance());
    }
    // Vrification des champs obligatoires de l'adresse  ajouter
    controlerAdresse(rapport, adresseDto, 0);
    if (Boolean.TRUE.equals(rapport.getEnErreur())) {
        RapportUtil.logRapport(rapport, logger);
        throw new ControleIntegriteException(rapport);
    }
    // On recherche les membres de la famille de la personne
    final Set<Personne> famille = getFamille(personnePrincipale);
    // Si le flag qui indique si l'on doit ajouter la nouvelle adresse aux bnficiaires n'est pas spcifi
    // Si la personne a une famille, on lve une exception car le flag impacterBeneficiaires doit tre renseign
    // pour dterminer si il faut ajouter l'adresse aux membres de la famille de la personne
    if (impacterFamille == null && famille.size() > 0) {
        throw new ConfirmationImpacterFamilleException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.CONFIRMATION_IMPACTER_FAMILLE,
                        new String[] { String.valueOf(famille.size()) }));
    }
    final AdresseCreationDto adresseCree = new AdresseCreationDto();
    final Set<Personne> personnes = new LinkedHashSet<Personne>();
    personnes.add(personnePrincipale);
    if (BooleanUtils.isTrue(impacterFamille)) {
        // On ajoute la famille
        personnes.addAll(famille);
    }
    adresseCree.setIdAdressesModifiees(new ArrayList<Long>());
    final Adresse adresse = creerOuMettreAJourAdresse(personnes, adresseDto, impacterFamille);
    if (adresseDto.getIdentifiant() == null) {
        adresseCree.setIdAdresseCree(adresse.getId());
    }
    // si le rapport n'est pas en erreur, on met  jour l'adresse principale
    if (plusQueAdressePrincipale) {
        if (choixPasserEnSecondaire) {
            // On passe l'adresse principale actuelle en adresse secondaire
            adressePrincipaleEnCours.setNature(natureAdresseSecondaire);
        } else {
            // On remplace l'adresse principale actuelle par l'adresse  ajouter
            // On met donc fin  l'adresse principale actuelle en spcifiant la date de fin  J-1 de la date de dbut de la nouvelle adresse
            final Calendar dateFinAdressePrincipale = adresseDto.getDateDebut();
            dateFinAdressePrincipale.add(Calendar.DAY_OF_MONTH, -1);
            adressePrincipaleEnCours.setDateFin(dateFinAdressePrincipale);
            // Si la date de fin de l'action principal est inferieur  la date de debut
            if (adressePrincipaleEnCours.getDateFin().compareTo(adressePrincipaleEnCours.getDateDebut()) < 0
                    && dateFinAdressePrincipale.get(Calendar.DAY_OF_MONTH) < adressePrincipaleEnCours
                            .getDateDebut().get(Calendar.DAY_OF_MONTH)) {
                adressePrincipaleEnCours.getDateFin().add(Calendar.DAY_OF_MONTH, +1);
            }
        }
        adresseCree.getIdAdressesModifiees().add(adressePrincipaleEnCours.getId());
    }

    /*
     * // Un contact devra avoir au moins une adresse principal criteresRechercheAdressePrincipale = new AdresseCriteresRechercheDto();
     * criteresRechercheAdressePrincipale.setIdPersonne(personne.getId());
     * criteresRechercheAdressePrincipale.setIdNature(squareMappingService.getIdNatureAdressePrincipale()); long nbPrimaires =
     * adresseDao.rechercherIdAdressesParCriteres(criteresRechercheAdressePrincipale).size(); if (nbPrimaires == 0) { throw new
     * BusinessException(messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_AUCUNE_ADRESSE_PRINCIPALE)); } else if (nbPrimaires > 1) { throw new
     * BusinessException(messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_ADRESSE_PRINCIPALE_DUPLIQUEE)); }
     */

    // 2.13 Une date de fin ne pourra etre mise sur une adresse principale que s'il existe une adresse secondaire.
    // Dans ce cas l'adresse principal deviendra automatiquement secondaire et l'adresse secondaire deviendra principale
    Adresse adressePrincipale = null;
    Adresse adresseSecondaire = null;
    for (Adresse adresseParcourue : personnePrincipale.getAdresses()) {
        if (adresseParcourue.getNature().getId().equals(idNatureAdressePrincipale)) {
            adressePrincipale = adresseParcourue;
        }
        if (adresseParcourue.getNature().getId().equals(idNatureAdresseSecondaire)
                && adresseParcourue.getDateFin() == null) {
            adresseSecondaire = adresseParcourue;
        }
    }
    if (adressePrincipale != null && adressePrincipale.getDateFin() != null && adresseSecondaire != null) {
        // Changement adresse principale adresse secondaire
        adressePrincipale.setNature(natureAdresseSecondaire);
        adresseSecondaire.setNature(natureAdressePrincipale);
        // Enregistrement des adresses
        final AdresseDto adresseDtoPrincipal = mapperDozerBean.map(adressePrincipale, AdresseDto.class);
        final AdresseDto adresseDtoSecondaire = mapperDozerBean.map(adresseSecondaire, AdresseDto.class);
        creerOuMettreAJourAdresse(personnes, adresseDtoPrincipal, impacterFamille);
        creerOuMettreAJourAdresse(personnes, adresseDtoSecondaire, impacterFamille);
        if (!adresseCree.getIdAdressesModifiees().contains(adressePrincipale.getId())) {
            adresseCree.getIdAdressesModifiees().add(adressePrincipale.getId());
        }
        if (!adresseCree.getIdAdressesModifiees().contains(adresseSecondaire.getId())) {
            adresseCree.getIdAdressesModifiees().add(adresseSecondaire.getId());
        }

    }

    controlerPersonneAUneAdressePrincipale(personnePrincipale);

    // si il s'agit d'une personne physique et vivier ou bnficiaire vivier, on transforme en prospect ou bnficiaire prospect
    final PersonnePhysique personnePhysique = personnePhysiqueDao.rechercherPersonneParId(idPersonne);
    boolean vivierToProspect = false;
    boolean hasNaturePersonneChanged = false;
    Long idNaturePersonnePhysique = null;
    final Long idNaturePersonneVivier = squareMappingService.getIdNaturePersonneVivier();
    final Long idNaturePersonneBeneficiaireVivier = squareMappingService
            .getIdNaturePersonneBeneficiaireVivier();
    String ancienneNaturePersonne = "";
    String nouvelleNaturePersonne = "";
    if (personnePhysique != null && personnePhysique.getNature() != null) {
        if (idNaturePersonneVivier.equals(personnePhysique.getNature().getId())
                && validationPersonneUtil.verifierContrainteProspect(personnePhysique)) {
            idNaturePersonnePhysique = squareMappingService.getIdNaturePersonneProspect();
            vivierToProspect = true;
            hasNaturePersonneChanged = true;
            ancienneNaturePersonne = personnePhysique.getNature().getLibelle();
        } else if (idNaturePersonneBeneficiaireVivier.equals(personnePhysique.getNature())
                && validationPersonneUtil.verifierContrainteBeneficiaireProspect(personnePhysique)) {
            idNaturePersonnePhysique = squareMappingService.getIdNaturePersonneBeneficiaireProspect();
            hasNaturePersonneChanged = true;
            ancienneNaturePersonne = personnePhysique.getNature().getLibelle();
        }
        if (idNaturePersonnePhysique != null) {
            final PersonnePhysiqueNature naturePersonne = personnePhysiqueNatureDao
                    .rechercherPersonnePhysiqueParId(idNaturePersonnePhysique);
            if (naturePersonne != null) {
                nouvelleNaturePersonne = naturePersonne.getLibelle();
            }
            personnePhysique.setNature(naturePersonne);
        }
    }

    // si la personne est passe de vivier  prospect et qu'elle a des bnficiaires vivier,
    // on essaye de les passer en bnficiaire prospect si c'est possible
    if (vivierToProspect && famille != null && famille.size() > 0) {
        for (Personne beneficiaire : famille) {
            final PersonnePhysique beneficiairePhysique = (PersonnePhysique) beneficiaire;
            if (beneficiairePhysique.getNature() != null
                    && idNaturePersonneBeneficiaireVivier.equals(beneficiairePhysique.getNature().getId())
                    && validationPersonneUtil.verifierContrainteBeneficiaireProspect(beneficiairePhysique)) {
                final PersonnePhysiqueNature naturePersonne = personnePhysiqueNatureDao
                        .rechercherPersonnePhysiqueParId(
                                squareMappingService.getIdNaturePersonneBeneficiaireProspect());
                beneficiairePhysique.setNature(naturePersonne);
            }
        }
    }

    adresseCree.setHasNaturePersonneChanged(hasNaturePersonneChanged);
    adresseCree.setAncienneNaturePersonne(ancienneNaturePersonne);
    adresseCree.setNouvelleNaturePersonne(nouvelleNaturePersonne);
    return adresseCree;
}

From source file:jp.primecloud.auto.ui.WinServerEdit.java

private void okButtonClick(ClickEvent event) {
    // ?/*from  w w  w.ja  v  a2  s .c om*/
    String comment = (String) basicTab.commentField.getValue();
    String keyName = null;
    Long keyNo = null;
    String groupName = null;
    String serverSize = null;
    String network = null;
    String cluster = null;
    ZoneDto zoneDto = null;
    String zoneName = null;
    String zoneId = null;
    SubnetDto subnetDto = null;
    String subnetId = null;
    String privateIp = null;
    AddressDto address = null;
    VmwareAddressDto vmwareAddressDto = null;
    Long storageTypeNo = null;
    List<InstanceNetworkDto> instanceNetworkDtos = null;
    String availabilitySet = null;

    // TODO: ?
    try {
        basicTab.commentField.validate();
    } catch (InvalidValueException e) {
        DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), e.getMessage());
        getApplication().getMainWindow().addWindow(dialog);
        return;
    }
    // TODO CLOUD BRANCHING
    if (PCCConstant.PLATFORM_TYPE_AWS.equals(platformDto.getPlatform().getPlatformType())) {
        PlatformAws platformAws = platformDto.getPlatformAws();
        // ?
        keyName = (String) awsDetailTab.keySelect.getValue();
        groupName = (String) awsDetailTab.grpSelect.getValue();
        serverSize = (String) awsDetailTab.sizeSelect.getValue();

        if (platformAws.getEuca() == false && platformAws.getVpc()) {
            subnetDto = (SubnetDto) awsDetailTab.subnetSelect.getValue();
            if (subnetDto != null) {
                subnetId = subnetDto.getSubnetId();
                zoneName = subnetDto.getZoneid();
            }
            privateIp = (String) awsDetailTab.privateIpField.getValue();
        } else {
            zoneDto = (ZoneDto) awsDetailTab.zoneSelect.getValue();
            if (zoneDto != null) {
                zoneName = zoneDto.getZoneName();
            }
            privateIp = (String) awsDetailTab.privateIpField.getValue();
        }
        address = (AddressDto) awsDetailTab.elasticIpSelect.getValue();

        // TODO: ?
        try {
            awsDetailTab.sizeSelect.validate();
            awsDetailTab.keySelect.validate();
            awsDetailTab.zoneSelect.validate();
            if (awsDetailTab.grpSelect.isEnabled()) {
                awsDetailTab.grpSelect.validate();
            }
            if (platformAws.getEuca() == false && platformAws.getVpc()) {
                awsDetailTab.subnetSelect.validate();
                awsDetailTab.privateIpField.validate();
            }
            awsDetailTab.elasticIpSelect.validate();
        } catch (InvalidValueException e) {
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), e.getMessage());
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }

        //??IP??
        if (platformAws.getEuca() == false && platformAws.getVpc() && StringUtils.isNotEmpty(privateIp)) {
            String[] cidr = subnetDto.getCidrBlock().split("/");
            Subnet subnet = new Subnet(cidr[0], Integer.parseInt(cidr[1]));
            String subnetIp = cidr[0];
            //AWS(VPC)??3????IP??IP
            for (int i = 0; i < 3; i++) {
                subnetIp = Subnet.getNextAddress(subnetIp);
                subnet.addReservedIp(subnetIp);
            }
            if (subnet.isScorp(privateIp) == false) {
                //??????
                String message = ViewMessages.getMessage("IUI-000109", subnet.getAvailableMinIp(),
                        subnet.getAvailableMaxIp());
                DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
                getApplication().getMainWindow().addWindow(dialog);
                return;
            }
        }

        //??????ElasticIP??????????????????
        if (!awsDetailTab.NULL_ADDRESS.equals(address) && null != address.getInstanceNo()) {
            if (null == instance.getAwsAddress()
                    || !instance.getAwsAddress().getAddressNo().equals(address.getAddressNo())) {
                String message = ViewMessages.getMessage("IUI-000064");
                DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
                getApplication().getMainWindow().addWindow(dialog);
                return;
            }
        }

    } else if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platformDto.getPlatform().getPlatformType())) {
        // ?
        keyName = (String) vmwareDetailTab.keySelect.getValue();
        cluster = (String) vmwareDetailTab.clusterSelect.getValue();
        serverSize = (String) vmwareDetailTab.sizeSelect.getValue();

        Boolean isStaticipSelected = false;
        if (vmwareEditIpTab != null) {
            isStaticipSelected = (Boolean) vmwareEditIpTab.ipOptionGroup
                    .isSelected(ViewProperties.getCaption("field.staticIp"));
            if (BooleanUtils.isTrue(isStaticipSelected)) {
                String ipAddress = (String) vmwareEditIpTab.ipAddressField.getValue();
                String subnetMask = (String) vmwareEditIpTab.subnetMaskField.getValue();
                String defaultGateway = (String) vmwareEditIpTab.defaultGatewayField.getValue();

                vmwareAddressDto = new VmwareAddressDto();
                vmwareAddressDto.setIpAddress(ipAddress);
                vmwareAddressDto.setSubnetMask(subnetMask);
                vmwareAddressDto.setDefaultGateway(defaultGateway);
            }
        }

        // TODO: ?
        try {
            vmwareDetailTab.keySelect.validate();
            vmwareDetailTab.clusterSelect.validate();
            vmwareDetailTab.sizeSelect.validate();
            if (BooleanUtils.isTrue(isStaticipSelected)) {
                vmwareEditIpTab.ipAddressField.validate();
                vmwareEditIpTab.subnetMaskField.validate();
                vmwareEditIpTab.defaultGatewayField.validate();
            }
        } catch (InvalidValueException e) {
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), e.getMessage());
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_NIFTY.equals(platformDto.getPlatform().getPlatformType())) {
        // ?
        keyName = (String) niftyDetailTab.keySelect.getValue();
        serverSize = (String) niftyDetailTab.sizeSelect.getValue();

        // TODO: ?
        try {
            niftyDetailTab.keySelect.validate();
            niftyDetailTab.sizeSelect.validate();
        } catch (InvalidValueException e) {
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), e.getMessage());
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_CLOUDSTACK.equals(platformDto.getPlatform().getPlatformType())) {
        // ?
        network = (String) cloudStackDetailTab.networkSelect.getValue();
        keyName = (String) cloudStackDetailTab.keySelect.getValue();
        groupName = (String) cloudStackDetailTab.grpSelect.getValue();
        serverSize = (String) cloudStackDetailTab.sizeSelect.getValue();
        zoneDto = (ZoneDto) cloudStackDetailTab.zoneSelect.getValue();
        if (zoneDto != null) {
            zoneId = zoneDto.getZoneId();
        }
        address = (AddressDto) cloudStackDetailTab.elasticIpSelect.getValue();

        // TODO: ?
        try {
            cloudStackDetailTab.sizeSelect.validate();
            cloudStackDetailTab.zoneSelect.validate();
            cloudStackDetailTab.elasticIpSelect.validate();
        } catch (InvalidValueException e) {
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), e.getMessage());
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }

        //??????ElasticIP??????????????????
        if (!cloudStackDetailTab.NULL_ADDRESS.equals(address) && null != address.getInstanceNo()) {
            if (null == instance.getCloudstackAddress()
                    || !instance.getCloudstackAddress().getAddressNo().equals(address.getAddressNo())) {
                String message = ViewMessages.getMessage("IUI-000064");
                DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
                getApplication().getMainWindow().addWindow(dialog);
                return;
            }
        }
    } else if (PCCConstant.PLATFORM_TYPE_VCLOUD.equals(platformDto.getPlatform().getPlatformType())) {
        // ?
        storageTypeNo = (Long) vcloudDetailTab.storageTypeSelect.getValue();
        keyNo = (Long) vcloudDetailTab.keySelect.getValue();
        serverSize = (String) vcloudDetailTab.sizeSelect.getValue();

        // ?
        try {
            vcloudDetailTab.storageTypeSelect.validate();
            vcloudDetailTab.keySelect.validate();
            vcloudDetailTab.sizeSelect.validate();
        } catch (InvalidValueException e) {
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), e.getMessage());
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_AZURE.equals(platformDto.getPlatform().getPlatformType())) {
        // ?
        serverSize = (String) azureDetailTab.sizeSelect.getValue();
        availabilitySet = (String) azureDetailTab.availabilitySetSelect.getValue();
        subnetDto = (SubnetDto) azureDetailTab.subnetSelect.getValue();
        if (subnetDto != null) {
            subnetId = subnetDto.getSubnetId();
        }

        // ?
        try {
            azureDetailTab.sizeSelect.validate();
            azureDetailTab.subnetSelect.validate();
        } catch (InvalidValueException e) {
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), e.getMessage());
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platformDto.getPlatform().getPlatformType())) {
        // ?
        serverSize = (String) openStackDetailTab.sizeSelect.getValue();
        groupName = (String) openStackDetailTab.grpSelect.getValue();
        keyName = (String) openStackDetailTab.keySelect.getValue();
        zoneDto = (ZoneDto) openStackDetailTab.zoneSelect.getValue();
        if (zoneDto != null) {
            zoneName = zoneDto.getZoneName();
        }

        // ?
        try {
            openStackDetailTab.sizeSelect.validate();
        } catch (InvalidValueException e) {
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), e.getMessage());
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    }

    //
    AutoApplication aapl = (AutoApplication) apl;
    aapl.doOpLog("SERVER", "Edit Server", instanceNo, null, null, null);

    // ?
    InstanceService instanceService = BeanContext.getBean(InstanceService.class);

    // TODO CLOUD BRANCHING
    if (PCCConstant.PLATFORM_TYPE_AWS.equals(platformDto.getPlatform().getPlatformType())) {
        // AWS?
        try {
            Long addressNo = address.getAddressNo();
            instanceService.updateAwsInstance(instanceNo, instance.getInstance().getInstanceName(), comment,
                    keyName, serverSize, groupName, zoneName, addressNo, subnetId, privateIp);
        } catch (AutoApplicationException e) {
            String message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platformDto.getPlatform().getPlatformType())) {
        // VMware?
        VmwareKeyPair selectedKeyPair = null;
        for (VmwareKeyPair vmwareKeyPair : vmwareKeyPairs) {
            if (vmwareKeyPair.getKeyName().equals(keyName)) {
                selectedKeyPair = vmwareKeyPair;
                break;
            }
        }

        try {
            instanceService.updateVmwareInstance(instanceNo, instance.getInstance().getInstanceName(), comment,
                    serverSize, cluster, null, selectedKeyPair.getKeyNo(), vmwareAddressDto);
        } catch (AutoApplicationException e) {
            String message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_NIFTY.equals(platformDto.getPlatform().getPlatformType())) {
        // Nifty?
        NiftyKeyPair selectedKeyPair = null;
        for (NiftyKeyPair niftyKeyPair : niftyKeyPairs) {
            if (niftyKeyPair.getKeyName().equals(keyName)) {
                selectedKeyPair = niftyKeyPair;
                break;
            }
        }

        try {
            instanceService.updateNiftyInstance(instanceNo, instance.getInstance().getInstanceName(), comment,
                    serverSize, selectedKeyPair.getKeyNo());
        } catch (AutoApplicationException e) {
            String message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_CLOUDSTACK.equals(platformDto.getPlatform().getPlatformType())) {
        //CloudStack?
        try {
            Long addressNo = address.getAddressNo();
            instanceService.updateCloudstackInstance(instanceNo, instance.getInstance().getInstanceName(),
                    comment, keyName, serverSize, groupName, zoneId, addressNo);
        } catch (AutoApplicationException e) {
            String message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }

    } else if (PCCConstant.PLATFORM_TYPE_VCLOUD.equals(platformDto.getPlatform().getPlatformType())) {
        //VCloud?
        try {
            instanceService.updateVcloudInstance(instanceNo, instance.getInstance().getInstanceName(), comment,
                    storageTypeNo, keyNo, serverSize, instanceNetworks);
        } catch (AutoApplicationException e) {
            String message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_AZURE.equals(platformDto.getPlatform().getPlatformType())) {
        //Azure?
        try {
            instanceService.updateAzureInstance(instanceNo, instance.getInstance().getInstanceName(), comment,
                    serverSize, availabilitySet, subnetId);
        } catch (AutoApplicationException e) {
            String message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    } else if (PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platformDto.getPlatform().getPlatformType())) {
        //OpenStack?
        try {
            instanceService.updateOpenStackInstance(instanceNo, instance.getInstance().getInstanceName(),
                    comment, serverSize, zoneName, groupName, keyName);
        } catch (AutoApplicationException e) {
            String message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
            DialogConfirm dialog = new DialogConfirm(ViewProperties.getCaption("dialog.error"), message);
            getApplication().getMainWindow().addWindow(dialog);
            return;
        }
    }

    // ???
    if (componentNos != null && attachService) {
        instanceService.associateComponents(instanceNo, componentNos);
    }

    // ??
    close();
}

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

@Override
public TelephoneDto creerOuMettreAJourTelephone(Long idPersonne, TelephoneDto telephoneDto,
        Boolean impacterFamille, Boolean forcerDesactivationEservices) {
    final RapportDto rapport = new RapportDto();

    if (idPersonne == null) {
        throw new BusinessException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PERSONNE_NULL));
    }/*ww  w  . ja  v a  2 s.  c  o  m*/

    // Rcupration de la personne en base.
    final Personne personnePrincipale = personneDao.rechercherPersonneParId(idPersonne);
    if (personnePrincipale == null) {
        throw new BusinessException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PERSONNE_INEXISTANTE));
    }

    final Set<Personne> personnes = new LinkedHashSet<Personne>();
    // On recherche les membres de la famille de la personne
    final Set<Personne> famille = getFamille(personnePrincipale);
    // Si le flag qui indique si l'on doit ajouter la nouvelle adresse aux bnficiaires n'est pas spcifi
    // Si la personne a une famille, on lve une exception car le flag impacterBeneficiaires doit tre renseign
    // pour dterminer si il faut ajouter l'adresse aux membres de la famille de la personne
    if (impacterFamille == null && famille.size() > 0) {
        throw new ConfirmationImpacterFamilleException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.CONFIRMATION_IMPACTER_FAMILLE,
                        new String[] { String.valueOf(famille.size()) }));
    }
    personnes.add(personnePrincipale);
    if (BooleanUtils.isTrue(impacterFamille)) {
        // On ajoute les membres de la famille  la liste des personnes concernes par la cration de nouvelles coordonnes
        personnes.addAll(famille);
    }
    final Calendar maintenant = Calendar.getInstance();

    // Traitement du tlphone
    final boolean numeroRenseigne = StringUtils.isNotBlank(telephoneDto.getNumero());
    boolean isTelephoneModifie = false;
    if (telephoneDto.getId() != null) {
        // On rcupre le tlphone  mettre  jour  partir de la base de donnes
        final Telephone telephoneAMaj = telephoneDao.rechercherTelephoneParId(telephoneDto.getId());
        // Si on recoit un id ici, mais que le numro n'est pas renseign, il faut supprimer le tlphone correspondant
        // Note : on ne supprime pas tous les tlphones car d'autres peuvent exister mais ne pas tre affichs dans Square
        if (!numeroRenseigne) {
            // Si il faut impacter toute la famille, ou que le tlphone est li  la personne principale uniquement
            if (BooleanUtils.isTrue(impacterFamille) || telephoneAMaj.getPersonnes().size() == 1) {
                // On supprime le tlphone
                supprimerTelephone(telephoneAMaj, maintenant);
            } else {
                // On enlve le tlphone de la liste des tlphones de la personne principale
                personnePrincipale.removeTelephone(telephoneAMaj);
                // on verifie si la personne est le porteur
                if (telephoneAMaj.getPorteurUid() != null
                        && telephoneAMaj.getPorteurUid().equals(personnePrincipale.getId())) {
                    // on supprime l'identifiant externe et le porteur du telephone restant sur la famille
                    telephoneAMaj.setIdentifiantExterieur(null);
                    telephoneAMaj.setPorteurUid(null);
                }
            }
            if (personnePrincipale instanceof PersonnePhysique && ((PersonnePhysique) personnePrincipale)
                    .getNature().getId().equals(squareMappingService.getIdNaturePersonneAdherent())) {
                // on verifie si la personne possede l'eservice
                final List<Long> optionsSouscrites = adherentService
                        .getListeIdsTypesOptionsSouscrites(personnePrincipale.getId());
                boolean possedeEserviceTelephone = false;
                for (Long idTypeOption : optionsSouscrites) {
                    if (idTypeOption.equals(adherentMappingService.getIdTypeOptionEnvoiSms())) {
                        possedeEserviceTelephone = true;
                        break;
                    }
                }

                if (possedeEserviceTelephone && !BooleanUtils.isTrue(forcerDesactivationEservices)) {
                    throw new ConfirmationDesactivationEserviceException(messageSourceUtil
                            .get(PersonneKeyUtil.MESSAGE_CONFIRMATION_DESACTIVATION_ESERVICE_TELEPHONE));
                } else if (possedeEserviceTelephone) {
                    adherentService.desactiverOptionsEnvoiParTelephone(personnePrincipale.getId());
                }
            }
        } else {
            // Sinon on dtermine si le tlphone a t modifi
            isTelephoneModifie = isTelephoneModifie(telephoneAMaj, telephoneDto);
            // Si le tlphone existe et a t modifi, et qu'il ne faut pas impacter la famille
            if (BooleanUtils.isFalse(impacterFamille) && isTelephoneModifie
                    && telephoneAMaj.getPersonnes().size() > 1) {
                // on supprime le telephone de la personne
                personnePrincipale.removeTelephone(telephoneAMaj);
                // on supprime l'identifiant pour crer un nouveau telephone
                telephoneDto.setId(null);
                // on verifie si la personne est le porteur
                if (telephoneAMaj.getPorteurUid() != null
                        && telephoneAMaj.getPorteurUid().equals(personnePrincipale.getId())) {
                    // on supprime l'identifiant externe et le porteur du telephone restant sur la famille (pas de synchro aia)
                    telephoneAMaj.setIdentifiantExterieur(null);
                    telephoneAMaj.setPorteurUid(null);
                } else {
                    // On supprime l'identifiant externe afin de ne pas synchroniser avec aia
                    telephoneDto.setIdext(null);
                }
            }
        }
    }
    if (numeroRenseigne) {
        controlerTelephone(rapport, telephoneDto, 0);
        if (!rapport.getEnErreur()) {
            final Telephone telephone = creerOuMettreAJourTelephone(personnes, telephoneDto, impacterFamille);
            if (telephone.getId() == null) {
                // On rattache le tlphone  la personne principale
                personnePrincipale.addTelephone(telephone);
                if (BooleanUtils.isTrue(impacterFamille)) {
                    // On rattache aussi le tlphone aux membres de sa famille
                    for (Personne personne : famille) {
                        personne.addTelephone(telephone);
                    }
                }
            }
        }
    }

    if (Boolean.TRUE.equals(rapport.getEnErreur())) {
        RapportUtil.logRapport(rapport, logger);
        throw new ControleIntegriteException(rapport);
    }

    // si il s'agit d'une personne physique et vivier ou bnficiaire vivier, on transforme en prospect ou bnficiaire prospect
    final PersonnePhysique personnePhysique = personnePhysiqueDao
            .rechercherPersonneParId(personnePrincipale.getId());
    boolean vivierToProspect = false;
    Long idNaturePersonnePhysique = null;
    final Long idNaturePersonneVivier = squareMappingService.getIdNaturePersonneVivier();
    final Long idNaturePersonneBeneficiaireVivier = squareMappingService
            .getIdNaturePersonneBeneficiaireVivier();
    if (personnePhysique != null && personnePhysique.getNature() != null) {
        if (idNaturePersonneVivier.equals(personnePhysique.getNature().getId())
                && validationPersonneUtil.verifierContrainteProspect(personnePhysique)) {
            idNaturePersonnePhysique = squareMappingService.getIdNaturePersonneProspect();
            vivierToProspect = true;
        } else if (idNaturePersonneBeneficiaireVivier.equals(personnePhysique.getNature())
                && validationPersonneUtil.verifierContrainteBeneficiaireProspect(personnePhysique)) {
            idNaturePersonnePhysique = squareMappingService.getIdNaturePersonneBeneficiaireProspect();
        }
        if (idNaturePersonnePhysique != null) {
            final PersonnePhysiqueNature naturePersonne = personnePhysiqueNatureDao
                    .rechercherPersonnePhysiqueParId(idNaturePersonnePhysique);
            personnePhysique.setNature(naturePersonne);
        }
    }

    // si la personne est passe de vivier  prospect et qu'elle a des bnficiaires vivier,
    // on essaye de les passer en bnficiaire prospect si c'est possible
    if (vivierToProspect && famille != null && famille.size() > 0) {
        for (Personne beneficiaire : famille) {
            final PersonnePhysique beneficiairePhysique = (PersonnePhysique) beneficiaire;
            if (beneficiairePhysique.getNature() != null
                    && idNaturePersonneBeneficiaireVivier.equals(beneficiairePhysique.getNature().getId())
                    && validationPersonneUtil.verifierContrainteBeneficiaireProspect(beneficiairePhysique)) {
                final PersonnePhysiqueNature naturePersonne = personnePhysiqueNatureDao
                        .rechercherPersonnePhysiqueParId(
                                squareMappingService.getIdNaturePersonneBeneficiaireProspect());
                beneficiairePhysique.setNature(naturePersonne);
            }
        }
    }

    // Rcupration du tlphone cr ou modifi pour le retourner
    final CritereRechercheTelephone critereTel = new CritereRechercheTelephone();
    final Set<Long> idsPersonnes = new HashSet<Long>();
    idsPersonnes.add(idPersonne);
    critereTel.setIdsPersonnes(idsPersonnes);
    final List<TelephoneDto> telephones = mapperDozerBean
            .mapList(telephoneDao.rechercherTelephoneParCritere(critereTel), TelephoneDto.class);
    for (TelephoneDto telephoneTrouve : telephones) {
        if (telephoneTrouve.getNumero().equals(telephoneDto.getNumero())) {
            return telephoneTrouve;
        }
    }

    // Si tlphone non trouv, on retourne un tlphone vide
    final TelephoneDto telephoneVide = new TelephoneDto();
    return telephoneVide;
}

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

@Override
public EmailDto creerOuMettreAJourEmail(Long idPersonne, EmailDto emailDto, Boolean impacterFamille,
        Boolean forcerDesactivationEservices) {
    final RapportDto rapport = new RapportDto();

    if (idPersonne == null) {
        throw new BusinessException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PERSONNE_NULL));
    }/*from   w  ww. j av  a 2 s  .  c  om*/

    // Rcupration de la personne en base.
    final Personne personnePrincipale = personneDao.rechercherPersonneParId(idPersonne);
    if (personnePrincipale == null) {
        throw new BusinessException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.MESSAGE_ERREUR_PERSONNE_INEXISTANTE));
    }

    final Set<Personne> personnes = new LinkedHashSet<Personne>();
    // On recherche les membres de la famille de la personne
    final Set<Personne> famille = getFamille(personnePrincipale);
    // Si le flag qui indique si l'on doit ajouter la nouvelle adresse aux bnficiaires n'est pas spcifi
    // Si la personne a une famille, on lve une exception car le flag impacterBeneficiaires doit tre renseign
    // pour dterminer si il faut ajouter l'adresse aux membres de la famille de la personne
    if (impacterFamille == null && famille.size() > 0) {
        throw new ConfirmationImpacterFamilleException(
                messageSourceUtil.get(PersonnePhysiqueKeyUtil.CONFIRMATION_IMPACTER_FAMILLE,
                        new String[] { String.valueOf(famille.size()) }));
    }
    personnes.add(personnePrincipale);
    if (BooleanUtils.isTrue(impacterFamille)) {
        // On ajoute les membres de la famille  la liste des personnes concernes par la cration de nouvelles coordonnes
        personnes.addAll(famille);
    }
    final Calendar maintenant = Calendar.getInstance();

    // Traitement de l'email
    final boolean adresseEmailRenseignee = StringUtils.isNotBlank(emailDto.getAdresse());
    boolean isEmailModifie = false;

    if (emailDto.getIdentifiant() != null) {
        // On rcupre l'email  mettre  jour  partir de la base de donnes
        final Email emailAMaj = emailDao.rechercherEmailParId(emailDto.getIdentifiant());
        // Si on recoit un id ici, mais que les infos ne sont pas renseignes, il faut supprimer le tlphone correspondant
        // Note : on ne supprime pas tous les tlphones car d'autres peuvent exister mais ne pas tre affichs dans Square
        if (!adresseEmailRenseignee) {
            // Si il faut impacter toute la famille, ou que l'email est li  la personne principale uniquement
            if (BooleanUtils.isTrue(impacterFamille) || emailAMaj.getPersonnes().size() == 1) {
                // On supprime l'email
                supprimerEmail(emailAMaj, maintenant);
            } else {
                // On enlve le tlphone de la liste des tlphones de la personne principale
                personnePrincipale.removeEmail(emailAMaj);
                // on verifie si la personne est le porteur
                if (emailAMaj.getPorteurUid() != null
                        && emailAMaj.getPorteurUid().equals(personnePrincipale.getId())) {
                    // on supprime l'identifiant externe et le porteur de l'email restant sur la famille
                    emailAMaj.setIdentifiantExterieur(null);
                    emailAMaj.setPorteurUid(null);
                }
            }
            if (personnePrincipale instanceof PersonnePhysique && ((PersonnePhysique) personnePrincipale)
                    .getNature().getId().equals(squareMappingService.getIdNaturePersonneAdherent())) {
                // on verifie si la personne possede l'eservice
                final List<Long> optionsSouscrites = adherentService
                        .getListeIdsTypesOptionsSouscrites(personnePrincipale.getId());
                boolean possedeEserviceTelephone = false;
                for (Long idTypeOption : optionsSouscrites) {
                    if (idTypeOption.equals(adherentMappingService.getIdTypeOptionEnvoiMutuellementEmail())
                            || idTypeOption.equals(
                                    adherentMappingService.getIdTypeOptionEnvoiRelevesPrestationEmail())) {
                        possedeEserviceTelephone = true;
                        break;
                    }
                }

                if (possedeEserviceTelephone && !BooleanUtils.isTrue(forcerDesactivationEservices)) {
                    throw new ConfirmationDesactivationEserviceException(messageSourceUtil
                            .get(PersonneKeyUtil.MESSAGE_CONFIRMATION_DESACTIVATION_ESERVICE_EMAIL));
                } else if (possedeEserviceTelephone) {
                    adherentService.desactiverOptionsEnvoiParEmail(personnePrincipale.getId());
                }
            }
        } else {
            // Sinon on dtermine si l'email a t modifi
            isEmailModifie = isEmailModifie(emailAMaj, emailDto);
            // Si le tlphone existe et a t modifi, et qu'il ne faut pas impacter la famille
            if (BooleanUtils.isFalse(impacterFamille) && isEmailModifie
                    && emailAMaj.getPersonnes().size() > 1) {
                // on supprime l'email de la personne
                personnePrincipale.removeEmail(emailAMaj);
                // on supprime l'identifiant pour crer un nouvel email
                emailDto.setIdentifiant(null);
                // on verifie si la personne est le porteur
                if (emailAMaj.getPorteurUid() != null
                        && emailAMaj.getPorteurUid().equals(personnePrincipale.getId())) {
                    // on supprime l'identifiant externe et le porteur de l'email restant sur la famille (pas de synchro aia)
                    emailAMaj.setIdentifiantExterieur(null);
                    emailAMaj.setPorteurUid(null);
                } else {
                    // On supprime l'identifiant externe afin de ne pas synchroniser avec aia
                    emailDto.setIdext(null);
                }
            }
        }
    }
    if (adresseEmailRenseignee) {
        controlerEmail(rapport, emailDto, 0);
        if (!rapport.getEnErreur()) {
            final Email email = creerOuMettreAJourEmail(personnes, emailDto, impacterFamille);
            // Si c'est un nouvel email
            if (email.getId() == null) {
                // On rattache le nouvel email  la personne principale
                personnePrincipale.addEMail(email);
                if (BooleanUtils.isTrue(impacterFamille)) {
                    // On rattache aussi le nouvel email aux membres de sa famille
                    for (Personne personne : famille) {
                        personne.addEMail(email);
                    }
                }
            }
        }
    }

    if (Boolean.TRUE.equals(rapport.getEnErreur())) {
        RapportUtil.logRapport(rapport, logger);
        throw new ControleIntegriteException(rapport);
    }

    // si il s'agit d'une personne physique et vivier ou bnficiaire vivier, on transforme en prospect ou bnficiaire prospect
    final PersonnePhysique personnePhysique = personnePhysiqueDao
            .rechercherPersonneParId(personnePrincipale.getId());
    boolean vivierToProspect = false;
    Long idNaturePersonnePhysique = null;
    final Long idNaturePersonneVivier = squareMappingService.getIdNaturePersonneVivier();
    final Long idNaturePersonneBeneficiaireVivier = squareMappingService
            .getIdNaturePersonneBeneficiaireVivier();
    if (personnePhysique != null && personnePhysique.getNature() != null) {
        if (idNaturePersonneVivier.equals(personnePhysique.getNature().getId())
                && validationPersonneUtil.verifierContrainteProspect(personnePhysique)) {
            idNaturePersonnePhysique = squareMappingService.getIdNaturePersonneProspect();
            vivierToProspect = true;
        } else if (idNaturePersonneBeneficiaireVivier.equals(personnePhysique.getNature())
                && validationPersonneUtil.verifierContrainteBeneficiaireProspect(personnePhysique)) {
            idNaturePersonnePhysique = squareMappingService.getIdNaturePersonneBeneficiaireProspect();
        }
        if (idNaturePersonnePhysique != null) {
            final PersonnePhysiqueNature naturePersonne = personnePhysiqueNatureDao
                    .rechercherPersonnePhysiqueParId(idNaturePersonnePhysique);
            personnePhysique.setNature(naturePersonne);
        }
    }

    // si la personne est passe de vivier  prospect et qu'elle a des bnficiaires vivier,
    // on essaye de les passer en bnficiaire prospect si c'est possible
    if (vivierToProspect && famille != null && famille.size() > 0) {
        for (Personne beneficiaire : famille) {
            final PersonnePhysique beneficiairePhysique = (PersonnePhysique) beneficiaire;
            if (beneficiairePhysique.getNature() != null
                    && idNaturePersonneBeneficiaireVivier.equals(beneficiairePhysique.getNature().getId())
                    && validationPersonneUtil.verifierContrainteBeneficiaireProspect(beneficiairePhysique)) {
                final PersonnePhysiqueNature naturePersonne = personnePhysiqueNatureDao
                        .rechercherPersonnePhysiqueParId(
                                squareMappingService.getIdNaturePersonneBeneficiaireProspect());
                beneficiairePhysique.setNature(naturePersonne);
            }
        }
    }

    // Rcupration de l'email cr ou modifi pour le retourner
    final CritereRechercheEmail critereEmail = new CritereRechercheEmail();
    final Set<Long> idsPersonnes = new HashSet<Long>();
    idsPersonnes.add(idPersonne);
    critereEmail.setIdsPersonnes(idsPersonnes);
    final List<EmailDto> emails = mapperDozerBean.mapList(emailDao.rechercherEmailParCritere(critereEmail),
            EmailDto.class);
    for (EmailDto emailTrouve : emails) {
        if (emailTrouve.getAdresse().equals(emailDto.getAdresse())) {
            return emailTrouve;
        }
    }

    // Si email non trouv, on retourne un email vide
    final EmailDto emailVide = new EmailDto();
    return emailVide;
}

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

/**
 * {@inheritDoc}// ww  w.  j a  va 2 s .  c  o  m
 */
@Override
public void associateComponents(Long instanceNo, List<Long> componentNos) {
    // ?
    if (instanceNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "instanceNo");
    }
    if (componentNos == null) {
        throw new AutoApplicationException("ECOMMON-000003", "componentNos");
    }

    // ??
    Instance instance = instanceDao.read(instanceNo);
    if (instance == null) {
        throw new AutoApplicationException("ESERVICE-000403", instanceNo);
    }

    // ?????
    List<Long> tmpComponentNos = new ArrayList<Long>();
    for (Long componentNo : componentNos) {
        if (!tmpComponentNos.contains(componentNo)) {
            tmpComponentNos.add(componentNo);
        }
    }
    componentNos = tmpComponentNos;

    // ????
    List<Component> components = componentDao.readInComponentNos(componentNos);
    if (componentNos.size() != components.size()) {
        for (Component component : components) {
            componentNos.remove(component.getComponentNo());
        }
        if (componentNos.size() > 0) {
            throw new AutoApplicationException("ESERVICE-000409", componentNos.iterator().next());
        }
    }

    // MySQL?Master???????
    List<InstanceConfig> instanceConfigs = instanceConfigDao.readByInstanceNo(instanceNo);
    for (InstanceConfig instanceConfig : instanceConfigs) {
        if (MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO.equals(instanceConfig.getConfigName())) {
            if (StringUtils.isEmpty(instanceConfig.getConfigValue())
                    && !componentNos.contains(instanceConfig.getComponentNo())) {
                // MySQL?Master?????????
                throw new AutoApplicationException("ESERVICE-000414", instance.getInstanceName());
            }
        }
    }

    // ????
    List<Component> allComponents = componentDao.readByFarmNo(instance.getFarmNo());
    List<ComponentInstance> componentInstances = componentInstanceDao.readByInstanceNo(instanceNo);
    for (Component component : allComponents) {
        // ?????????
        ComponentInstance componentInstance = null;
        for (ComponentInstance tmpComponentInstance : componentInstances) {
            if (component.getComponentNo().equals(tmpComponentInstance.getComponentNo())) {
                componentInstance = tmpComponentInstance;
                break;
            }
        }

        if (componentNos.contains(component.getComponentNo())) {
            // ??????
            if (componentInstance == null) {
                // ????????
                componentInstance = new ComponentInstance();
                componentInstance.setComponentNo(component.getComponentNo());
                componentInstance.setInstanceNo(instanceNo);
                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(),
                                componentInstance.getComponentNo());
                    }

                    /******************************************************************
                     * ???????
                     * ??VCLOUDUSiZE?????
                     ******************************************************************/
                    List<VcloudDisk> vdisks = vcloudDiskDao.readByInstanceNo(instance.getInstanceNo());
                    for (VcloudDisk disk : vdisks) {
                        if (component.getComponentNo().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);
                    }
                }
            }
        }
    }

    for (Component component : components) {
        ComponentType componentType = componentTypeDao.read(component.getComponentTypeNo());

        // MySQL?????Master/Slave?
        if (MySQLConstants.COMPONENT_TYPE_NAME.equals(componentType.getComponentTypeName())) {
            InstanceConfig instanceConfig = instanceConfigDao.readByInstanceNoAndComponentNoAndConfigName(
                    instanceNo, component.getComponentNo(), MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO);
            if (instanceConfig == null) {
                // Master??
                Long masterInstanceNo = null;
                List<InstanceConfig> configs = instanceConfigDao.readByComponentNo(component.getComponentNo());
                for (InstanceConfig config : configs) {
                    if (MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO.equals(config.getConfigName())) {
                        if (StringUtils.isEmpty(config.getConfigValue())) {
                            masterInstanceNo = config.getInstanceNo();
                            break;
                        }
                    }
                }

                // Master???????Master????Slave??
                instanceConfig = new InstanceConfig();
                instanceConfig.setInstanceNo(instanceNo);
                instanceConfig.setComponentNo(component.getComponentNo());
                instanceConfig.setConfigName(MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO);
                if (masterInstanceNo == null) {
                    instanceConfig.setConfigValue(null);
                } else {
                    instanceConfig.setConfigValue(masterInstanceNo.toString());
                }
                instanceConfigDao.create(instanceConfig);
            }
        }
    }

    // 
    StringBuilder names = new StringBuilder();
    for (Component component : components) {
        names.append(component.getComponentName()).append(",");
    }
    if (names.length() > 0) {
        names.deleteCharAt(names.length() - 1);
    }
    Farm farm = farmDao.read(instance.getFarmNo());
    eventLogger.log(EventLogLevel.DEBUG, farm.getFarmNo(), farm.getFarmName(), null, null, instanceNo,
            instance.getInstanceName(), "InstanceAssociateComponent", null, instance.getPlatformNo(),
            new Object[] { names.toString() });
}