Example usage for org.apache.commons.collections4 CollectionUtils isEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isEmpty.

Prototype

public static boolean isEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is empty.

Usage

From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl.java

private void manageNovaServerNetwork(String heatFileName, ServiceTemplate serviceTemplate,
        HeatOrchestrationTemplate heatOrchestrationTemplate, Resource resource, String translatedId,
        TranslationContext context, NodeTemplate novaNodeTemplate) {

    if (resource.getProperties() == null) {
        return;/*from  w w w.  j  av  a  2 s.  c o m*/
    }
    List<Map<String, Object>> heatNetworkList = (List<Map<String, Object>>) resource.getProperties()
            .get("networks");

    if (CollectionUtils.isEmpty(heatNetworkList)) {
        return;
    }

    for (Map<String, Object> heatNetwork : heatNetworkList) {
        getOrTranslatePortTemplate(heatFileName, heatOrchestrationTemplate,
                heatNetwork.get(Constants.PORT_PROPERTY_NAME), serviceTemplate, translatedId, context,
                novaNodeTemplate);
    }

}

From source file:org.openecomp.sdc.validation.impl.util.HeatValidationService.java

/**
 * Loop over output map and validate get attr from nested.
 *
 * @param fileName                  the file name
 * @param outputMap                 the output map
 * @param heatOrchestrationTemplate the heat orchestration template
 * @param globalContext             the global context
 *//*from w  w  w  .j a v  a  2s .co m*/
@SuppressWarnings("unchecked")
public static void loopOverOutputMapAndValidateGetAttrFromNested(String fileName, Map<String, Output> outputMap,
        HeatOrchestrationTemplate heatOrchestrationTemplate, GlobalValidationContext globalContext) {
    for (Output output : outputMap.values()) {
        Object outputValue = output.getValue();
        if (outputValue != null && outputValue instanceof Map) {
            Map<String, Object> outputValueMap = (Map<String, Object>) outputValue;
            List<String> getAttrValue = (List<String>) outputValueMap
                    .get(ResourceReferenceFunctions.GET_ATTR.getFunction());
            if (!CollectionUtils.isEmpty(getAttrValue)) {
                String resourceName = getAttrValue.get(0);
                String propertyName = getAttrValue.get(1);
                String resourceType = getResourceTypeFromResourcesMap(resourceName, heatOrchestrationTemplate);

                if (Objects.nonNull(resourceType) && HeatValidationService.isNestedResource(resourceType)) {
                    Map<String, Output> nestedOutputMap;
                    HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
                    try {
                        nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject(
                                globalContext.getFileContent(resourceType), HeatOrchestrationTemplate.class);
                    } catch (Exception e0) {
                        return;
                    }
                    nestedOutputMap = nestedHeatOrchestrationTemplate.getOutputs();

                    if (MapUtils.isEmpty(nestedOutputMap) || !nestedOutputMap.containsKey(propertyName)) {
                        globalContext.addMessage(fileName, ErrorLevel.ERROR,
                                ErrorMessagesFormatBuilder.getErrorWithParameters(
                                        Messages.GET_ATTR_NOT_FOUND.getErrorMessage(), propertyName,
                                        resourceName));
                    }
                }
            }
        }
    }
}

From source file:org.openecomp.sdc.validation.impl.util.ResourceValidationHeatValidator.java

/**
 * Validate resource type.//from www. ja  v  a 2  s .com
 *
 * @param fileName                               the file name
 * @param baseFileName                           the base file name
 * @param securityGroupsNamesFromBaseFileOutputs the security groups names from base file outputs
 * @param heatOrchestrationTemplate              the heat orchestration template
 * @param globalContext                          the global context
 */
public static void validateResourceType(String fileName, String baseFileName,
        Set<String> securityGroupsNamesFromBaseFileOutputs, HeatOrchestrationTemplate heatOrchestrationTemplate,
        GlobalValidationContext globalContext) {
    Map<String, Resource> resourceMap = heatOrchestrationTemplate.getResources() == null ? new HashMap<>()
            : heatOrchestrationTemplate.getResources();
    Map<String, Integer> numberOfVisitsInPort = new HashMap<>();
    Set<String> resourcesNames = resourceMap.keySet();
    Set<String> sharedResourcesFromOutputMap = getSharedResourcesNamesFromOutputs(fileName,
            heatOrchestrationTemplate.getOutputs(), globalContext);
    boolean isBaseFile = baseFileName != null && fileName.equals(baseFileName);

    Map<HeatResourcesTypes, List<String>> resourceTypeToNamesListMap = HeatResourcesTypes
            .getListForResourceType(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE,
                    HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE,
                    HeatResourcesTypes.CONTRAIL_NETWORK_RULE_RESOURCE_TYPE);

    initResourceTypeListWithItsResourcesNames(fileName, resourceTypeToNamesListMap, resourceMap,
            sharedResourcesFromOutputMap, globalContext);
    initVisitedPortsMap(fileName, resourceMap, numberOfVisitsInPort, globalContext);

    for (Map.Entry<String, Resource> resourceEntry : resourceMap.entrySet()) {
        String resourceType = resourceEntry.getValue().getType();
        validateSecurityGroupsFromBaseOutput(fileName, resourceEntry, isBaseFile,
                securityGroupsNamesFromBaseFileOutputs, globalContext);
        checkResourceDependsOn(fileName, resourceEntry.getValue(), resourcesNames, globalContext);

        if (Objects.isNull(resourceType)) {
            globalContext.addMessage(fileName, ErrorLevel.WARNING,
                    ErrorMessagesFormatBuilder.getErrorWithParameters(
                            Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null", resourceEntry.getKey()));
        } else {
            HeatResourcesTypes heatResourceType = HeatResourcesTypes.findByHeatResource(resourceType);

            if (heatResourceType != null) {
                switch (heatResourceType) {
                case NOVA_SERVER_RESOURCE_TYPE:
                    validateNovaServerResourceType(fileName, resourceEntry, numberOfVisitsInPort,
                            resourceTypeToNamesListMap.get(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE),
                            heatOrchestrationTemplate, globalContext);
                    break;

                case NOVA_SERVER_GROUP_RESOURCE_TYPE:
                    validateNovaServerGroupPolicy(fileName, resourceEntry, globalContext);
                    break;

                case RESOURCE_GROUP_RESOURCE_TYPE:
                    validateResourceGroupType(fileName, resourceEntry, globalContext);
                    break;

                case NEUTRON_PORT_RESOURCE_TYPE:
                    validateNeutronPortType(fileName, resourceEntry, resourceTypeToNamesListMap
                            .get(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE), globalContext);
                    break;

                case CONTRAIL_NETWORK_ATTACH_RULE_RESOURCE_TYPE:
                    validateContrailAttachPolicyType(resourceEntry, resourceTypeToNamesListMap
                            .get(HeatResourcesTypes.CONTRAIL_NETWORK_RULE_RESOURCE_TYPE));
                    break;
                default:
                }
            } else {
                if (HeatValidationService.isNestedResource(resourceType)) {
                    handleNestedResourceType(fileName, resourceEntry.getKey(), resourceEntry.getValue(),
                            globalContext);
                }
            }
        }
    }

    checkForEmptyResourceNamesInMap(fileName, CollectionUtils.isEmpty(securityGroupsNamesFromBaseFileOutputs),
            resourceTypeToNamesListMap, globalContext);
    handleOrphanPorts(fileName, numberOfVisitsInPort, globalContext);
}

From source file:org.openecomp.sdc.validation.impl.util.ResourceValidationHeatValidator.java

private static boolean isSharedResource(String resourceName, Set<String> sharedResourcesFromOutputMap) {
    return !CollectionUtils.isEmpty(sharedResourcesFromOutputMap)
            && sharedResourcesFromOutputMap.contains(resourceName);
}

From source file:org.openecomp.sdc.validation.impl.validators.HeatValidator.java

@Override
public void validate(GlobalValidationContext globalContext) {

    ManifestContent manifestContent;// www  .  j a  v  a 2  s  .co m
    try {
        manifestContent = checkValidationPreCondition(globalContext);
    } catch (Exception e0) {
        return;
    }
    String baseFileName;
    Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
    Map<String, FileData> fileEnvMap = ManifestUtil.getFileAndItsEnv(manifestContent);
    Set<String> baseFiles = ManifestUtil.getBaseFiles(manifestContent);
    Set<String> securityGroupsNamesFromBaseFileOutputs;
    Set<String> artifacts = new HashSet<>();

    baseFileName = CollectionUtils.isEmpty(baseFiles) ? null : baseFiles.iterator().next();
    securityGroupsNamesFromBaseFileOutputs = baseFileName == null ? null
            : checkForBaseFilePortsExistenceAndReturnSecurityGroupNamesFromOutputsIfNot(baseFileName,
                    globalContext);

    globalContext.getFiles().stream().filter(fileName -> FileData.isHeatFile(fileTypeMap.get(fileName)))
            .forEach(fileName -> validate(fileName,
                    fileEnvMap.get(fileName) == null ? null : fileEnvMap.get(fileName).getFile(),
                    baseFileName == null ? null : baseFileName, artifacts,
                    securityGroupsNamesFromBaseFileOutputs, globalContext));

    Set<String> manifestArtifacts = ManifestUtil.getArtifacts(manifestContent);

    globalContext.getFiles().stream()
            .filter(fileName -> manifestArtifacts.contains(fileName) && !artifacts.contains(fileName))
            .forEach(fileName -> globalContext.addMessage(fileName, ErrorLevel.WARNING,
                    Messages.ARTIFACT_FILE_NOT_REFERENCED.getErrorMessage()));

    ResourceValidationHeatValidator.handleNotEmptyResourceNamesList(baseFileName,
            securityGroupsNamesFromBaseFileOutputs, "SecurityGroup", globalContext);

}

From source file:org.openecomp.sdc.validation.utils.ValidationConfigurationManager.java

/**
 * Init validators list./*  ww w.  java2  s . co m*/
 *
 * @return the list
 */
public static List<Validator> initValidators() {
    synchronized (validators) {
        if (CollectionUtils.isEmpty(validators)) {
            InputStream validationConfigurationJson = FileUtils.getFileInputStream(VALIDATION_CONFIGURATION);
            ValidationConfiguration validationConfiguration = JsonUtil.json2Object(validationConfigurationJson,
                    ValidationConfiguration.class);
            List<ValidatorConfiguration> conf = validationConfiguration.getValidatorConfigurationList();
            conf.stream().filter(ValidatorConfiguration::isEnableInd).forEachOrdered(
                    validatorConfiguration -> validators.add(validatorInit(validatorConfiguration)));
        }
    }
    return validators;
}

From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java

private static List<ErrorCode> validateCompletedVendorSoftwareProduct(VspDetails vspDetails,
        UploadDataEntity uploadData, Object serviceModel) {
    List<ErrorCode> errros = new ArrayList<>();

    if (vspDetails.getName() == null) {
        errros.add(createMissingMandatoryFieldError("name"));
    }/*w ww  .j  av  a  2 s . com*/
    if (vspDetails.getDescription() == null) {
        errros.add(createMissingMandatoryFieldError("description"));
    }
    if (vspDetails.getVendorId() == null) {
        errros.add(createMissingMandatoryFieldError("vendor Id"));
    }
    if (vspDetails.getVlmVersion() == null) {
        errros.add(
                createMissingMandatoryFieldError("licensing version (in the format of: {integer}.{integer})"));
    }
    if (vspDetails.getCategory() == null) {
        errros.add(createMissingMandatoryFieldError("category"));
    }
    if (vspDetails.getSubCategory() == null) {
        errros.add(createMissingMandatoryFieldError("sub category"));
    }
    if (vspDetails.getLicenseAgreement() == null) {
        errros.add(createMissingMandatoryFieldError("license agreement"));
    }
    if (CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
        errros.add(createMissingMandatoryFieldError("feature groups"));
    }
    if (uploadData == null || uploadData.getContentData() == null || serviceModel == null) {
        errros.add(new VendorSoftwareProductInvalidErrorBuilder(vspDetails.getId(), vspDetails.getVersion())
                .build());
    }

    return errros.isEmpty() ? null : errros;
}

From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java

private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version,
        ToscaServiceModel serviceModel) {
    Collection<ComponentEntity> components = listComponents(vendorSoftwareProductId, version);
    if (serviceModel == null) {
        return null;
    }//  ww  w  .  j a v a  2s .co m
    if (CollectionUtils.isEmpty(components)) {
        enrichedServiceModelDao.storeServiceModel(vendorSoftwareProductId, version, serviceModel);
        return null;
    }
    EnrichmentManager<ToscaServiceModel> enrichmentManager = EnrichmentManagerFactory.getInstance()
            .createInterface();
    enrichmentManager.initInput(vendorSoftwareProductId, version);
    enrichmentManager.addModel(serviceModel);

    ComponentInfo componentInfo = new ComponentInfo();
    Map<String, List<ErrorMessage>> compileErrors = new HashMap<>();
    CompilationUtil.addMonitoringInfo(componentInfo, compileErrors);
    for (ComponentEntity componentEntity : components) {
        ComponentInfo currentEntityComponentInfo = new ComponentInfo();
        currentEntityComponentInfo.setCeilometerInfo(componentInfo.getCeilometerInfo());
        CompilationUtil.addMibInfo(vendorSoftwareProductId, version, componentEntity,
                currentEntityComponentInfo, compileErrors);
        enrichmentManager.addEntityInput(componentEntity.getComponentCompositionData().getName(),
                currentEntityComponentInfo);

    }
    Map<String, List<ErrorMessage>> enrichErrors;
    enrichErrors = enrichmentManager.enrich();
    enrichedServiceModelDao.storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel());
    if (enrichErrors != null) {
        compileErrors.putAll(enrichErrors);
    }

    vendorSoftwareProductDao.updateVspLatestModificationTime(vendorSoftwareProductId, version);

    return compileErrors;
}

From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java

private Collection<ErrorCode> validateLicensingData(VspDetails vspDetails) {
    if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null
            || vspDetails.getLicenseAgreement() == null
            || CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) {
        return null;
    }/*from ww w  . ja  v a2  s .c om*/
    return vendorLicenseFacade.validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(),
            vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups());
}

From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java

@Override
public CompositionEntityValidationData updateNetwork(NetworkEntity network, String user) {
    Version activeVersion = getVersionInfo(network.getVspId(), VersionableEntityAction.Write, user)
            .getActiveVersion();/*w ww. j  a  v  a 2 s.com*/
    network.setVersion(activeVersion);
    NetworkEntity retrieved = getNetwork(network.getVspId(), activeVersion, network.getId());

    NetworkCompositionSchemaInput schemaInput = new NetworkCompositionSchemaInput();
    schemaInput.setManual(isManual(network.getVspId(), activeVersion));
    schemaInput.setNetwork(retrieved.getNetworkCompositionData());

    CompositionEntityValidationData validationData = CompositionEntityDataManager.validateEntity(network,
            SchemaTemplateContext.composition, schemaInput);
    if (CollectionUtils.isEmpty(validationData.getErrors())) {
        vendorSoftwareProductDao.updateNetwork(network);
    }

    vendorSoftwareProductDao.updateVspLatestModificationTime(network.getVspId(), activeVersion);

    return validationData;
}