List of usage examples for org.apache.commons.collections4 MapUtils isNotEmpty
public static boolean isNotEmpty(final Map<?, ?> map)
From source file:org.openecomp.sdc.validation.impl.validators.HeatValidator.java
private static void validateEnvParametersMatchDefinedHeatParameterTypes(String envFile, Environment envContent, GlobalValidationContext globalContext, HeatOrchestrationTemplate heatOrchestrationTemplate) { Map<String, Parameter> heatParameters = heatOrchestrationTemplate.getParameters(); if (MapUtils.isNotEmpty(heatParameters) && MapUtils.isNotEmpty(envContent.getParameters())) { for (Map.Entry<String, Object> envEntry : envContent.getParameters().entrySet()) { String parameterName = envEntry.getKey(); Object parameterEnvValue = envEntry.getValue(); Parameter parameterFromHeatFile = heatParameters.get(parameterName); if (parameterFromHeatFile != null) { String parameterType = parameterFromHeatFile.getType(); if (!DefinedHeatParameterTypes.isEmptyValueInEnv(parameterEnvValue) && !DefinedHeatParameterTypes.isValueIsFromGivenType(parameterEnvValue, parameterType)) { globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder.getErrorWithParameters( Messages.PARAMETER_ENV_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(), parameterName)); }/* w w w . j a v a2 s .c o m*/ } } } }
From source file:org.openecomp.sdc.validation.impl.validators.HeatValidator.java
@SuppressWarnings("unchecked") private void getSecurityGroupsReferencedResourcesFromOutputs(Set<String> securityGroupsNamesFromOutputsMap, Map<String, Output> outputMap, Map<String, Resource> resourceMap) { if (MapUtils.isNotEmpty(outputMap)) { for (Map.Entry<String, Output> outputEntry : outputMap.entrySet()) { Object outputValue = outputEntry.getValue().getValue(); if (Objects.nonNull(outputValue) && outputValue instanceof Map) { String resourceName = (String) ((Map) outputValue) .get(ResourceReferenceFunctions.GET_RESOURCE.getFunction()); if (Objects.nonNull(resourceName)) { Resource resource = resourceMap.get(resourceName); if (Objects.nonNull(resource) && resource.getType().equals( HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource())) { securityGroupsNamesFromOutputsMap.add(outputEntry.getKey()); }/*w ww . j av a 2 s .co m*/ } } } } }
From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java
@Override public void uploadComponentMib(InputStream object, String filename, String vspId, String componentId, boolean isTrap, String user) { Version activeVersion = getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion(); ComponentArtifactEntity componentArtifactEntity; if (object == null) { throw new CoreException( new MibUploadErrorBuilder(Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()) .build());/*from w ww. ja v a 2 s .c o m*/ } else { byte[] uploadedFileData; Map<String, List<ErrorMessage>> errors = new HashMap<>(); try { uploadedFileData = FileUtils.toByteArray(object); validateMibZipContent(vspId, activeVersion, uploadedFileData, errors); if (MapUtils.isNotEmpty(errors)) { throw new CoreException( new MibUploadErrorBuilder(errors.values().iterator().next().get(0).getMessage()) .build()); } createArtifactInDatabase(vspId, activeVersion, filename, componentId, isTrap, uploadedFileData); } catch (Exception e0) { throw new CoreException(new MibUploadErrorBuilder(e0.getMessage()).build()); } } vendorSoftwareProductDao.updateVspLatestModificationTime(vspId, activeVersion); }
From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java
private MibUploadStatus setMibUploadStatusValues(ComponentArtifactEntity componentArtifactEntity) { MibUploadStatus mibUploadStatus = new MibUploadStatus(); Collection<ComponentArtifactEntity> artifactNames = componentArtifactDao .getArtifactNamesAndTypesForComponent(componentArtifactEntity); Map<ComponentArtifactType, String> artifactTypeToFilename = VendorSoftwareProductUtils .filterNonTrapOrPollArtifacts(artifactNames); if (MapUtils.isNotEmpty(artifactTypeToFilename)) { if (artifactTypeToFilename.containsKey(ComponentArtifactType.SNMP_TRAP)) { mibUploadStatus.setSnmpTrap(artifactTypeToFilename.get(ComponentArtifactType.SNMP_TRAP)); }//from w w w . j a va2 s .c o m if (artifactTypeToFilename.containsKey(ComponentArtifactType.SNMP_POLL)) { mibUploadStatus.setSnmpPoll(artifactTypeToFilename.get(ComponentArtifactType.SNMP_POLL)); } } return mibUploadStatus; }
From source file:org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl.java
private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version) { CompositionEntityDataManager compositionEntityDataManager = new CompositionEntityDataManager(); compositionEntityDataManager.addEntity(vendorSoftwareProductDao.getQuestionnaire(vspId, version), null); Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> nics = vendorSoftwareProductDao .listNicsByVsp(vspId, version); Map<String, List<String>> nicNamesByComponent = new HashMap<>(); for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nicEntity : nics) { compositionEntityDataManager.addEntity(nicEntity, null); Nic nic = nicEntity.getNicCompositionData(); if (nic != null && nic.getName() != null) { List<String> nicNames = nicNamesByComponent.get(nicEntity.getComponentId()); if (nicNames == null) { nicNames = new ArrayList<>(); nicNamesByComponent.put(nicEntity.getComponentId(), nicNames); }/*from w w w . j a v a2s .c om*/ nicNames.add(nic.getName()); } } Collection<ComponentEntity> components = vendorSoftwareProductDao.listComponentsQuestionnaire(vspId, version); components.stream() .forEach(component -> compositionEntityDataManager.addEntity(component, new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()), JsonUtil.json2Object(component.getQuestionnaireData(), Map.class)))); Map<CompositionEntityId, Collection<String>> errorsByEntityId = compositionEntityDataManager .validateEntitiesQuestionnaire(); if (MapUtils.isNotEmpty(errorsByEntityId)) { compositionEntityDataManager.buildTrees(); compositionEntityDataManager.addErrorsToTrees(errorsByEntityId); Collection<CompositionEntityValidationData> roots = compositionEntityDataManager.getTrees(); return new QuestionnaireValidationResult(roots.iterator().next()); } return null; }
From source file:org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse.java
/** * Sets upload data errors./* w ww. j av a 2s .c o m*/ * * @param uploadDataErrors the upload data errors */ public void setUploadDataErrors(Map<String, List<ErrorMessage>> uploadDataErrors) { this.uploadDataErrors = uploadDataErrors; if (MapUtils.isNotEmpty(uploadDataErrors)) { valid = false; } }
From source file:org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse.java
/** * Sets compilation errors./* www . j ava 2 s .c om*/ * * @param compilationErrors the compilation errors */ public void setCompilationErrors(Map<String, List<ErrorMessage>> compilationErrors) { this.compilationErrors = compilationErrors; if (MapUtils.isNotEmpty(compilationErrors)) { valid = false; } }
From source file:org.openecomp.sdc.vendorsoftwareproduct.util.VendorSoftwareProductUtils.java
/** * Load and translate template data translator output. * * @param fileNameContentMap the file name content map * @return the translator output//from w w w. ja v a2 s . co m */ public static TranslatorOutput loadAndTranslateTemplateData(FileContentHandler fileNameContentMap) { HeatToToscaTranslator heatToToscaTranslator = HeatToToscaTranslatorFactory.getInstance().createInterface(); InputStream fileContent = fileNameContentMap.getFileContent(AsdcCommon.MANIFEST_NAME); heatToToscaTranslator.addManifest(AsdcCommon.MANIFEST_NAME, FileUtils.toByteArray(fileContent)); fileNameContentMap.getFileList().stream().filter(fileName -> !(fileName.equals(AsdcCommon.MANIFEST_NAME))) .forEach(fileName -> heatToToscaTranslator.addFile(fileName, FileUtils.toByteArray(fileNameContentMap.getFileContent(fileName)))); Map<String, List<ErrorMessage>> errors = heatToToscaTranslator.validate(); if (MapUtils.isNotEmpty(MessageContainerUtil .getMessageByLevel(org.openecomp.sdc.datatypes.error.ErrorLevel.ERROR, errors))) { TranslatorOutput translatorOutput = new TranslatorOutput(); translatorOutput.setErrorMessages(errors); return translatorOutput; } InputStream structureFile = getHeatStructureTreeFile(fileNameContentMap); heatToToscaTranslator.addExternalArtifacts(AsdcCommon.HEAT_META, structureFile); return heatToToscaTranslator.translate(); }
From source file:org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManagerTest.java
@Test public void testEnrichModelInSubmit() { UniqueValueUtil.deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, "VSP_syb"); VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon.createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", vlm1Id, "icon", "category", "subCategory", "456", null), USER1);/* w ww . java2 s .c o m*/ String id = vspDetails.getId(); //upload file InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip"); UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.uploadFile(id, zis, USER1); //check in vendorSoftwareProductManager.checkin(id, USER1); //submit try { ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1); } catch (IOException e) { Assert.fail(); } VersionedVendorSoftwareProductInfo details = vendorSoftwareProductManager.getVspDetails(id, null, USER1); Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components = vendorSoftwareProductManager .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1); ToscaServiceModel model = (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() .getServiceModel(id, details.getVersionInfo().getActiveVersion()); Map<String, CapabilityDefinition> capabilities = new HashMap<>(); for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component : components) { model.getServiceTemplates().entrySet().stream() .filter(entryValue -> entryValue.getValue() != null && entryValue.getValue().getNode_types() != null && entryValue.getValue().getNode_types() .containsKey(component.getComponentCompositionData().getName())) .forEach(entryValue -> entryValue.getValue().getNode_types().values().stream() .filter(type -> MapUtils.isNotEmpty(type.getCapabilities())) .forEach(type -> type.getCapabilities().entrySet() .forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), entry.getValue())))); } Assert.assertNotNull(capabilities); }
From source file:org.openecomp.sdc.vendorsoftwareproduct.VSPFullTest.java
@Test public void testEnrichModelInSubmit() { UniqueValueUtil.deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, "VSP_FullTest"); String vlm1Id = vendorLicenseFacade.createVendorLicenseModel( VSPCommon.createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"), USER1).getId();/* w w w .j ava 2 s. co m*/ String entitlementPoolId = vendorLicenseFacade .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId(); org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity( vlm1Id, null, null); featureGroup.getEntitlementPoolIds().add(entitlementPoolId); String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId(); org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity licenseAgreement = new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity( vlm1Id, null, null); licenseAgreement.getFeatureGroupIds().add(featureGroupId); String licenseAgreementId = vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId(); vendorLicenseFacade.checkin(vlm1Id, USER1); vendorLicenseFacade.submit(vlm1Id, USER1); String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds()); Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components = uploadFullCompositionFile( vspId); //check in vendorSoftwareProductManager.checkin(vspId, USER1); //submit try { ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1); //Assert.assertTrue(result.isValid()); //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1); } catch (IOException e) { Assert.fail(); } VersionedVendorSoftwareProductInfo details = vendorSoftwareProductManager.getVspDetails(vspId, null, USER1); //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1); // writeFile(csar); ToscaServiceModel model = (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() .getServiceModel(vspId, details.getVersionInfo().getActiveVersion()); Map<String, CapabilityDefinition> capabilities = new HashMap<>(); for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component : components) { model.getServiceTemplates().entrySet().stream() .filter(entryValue -> entryValue.getValue() != null && entryValue.getValue().getNode_types() != null && entryValue.getValue().getNode_types() .containsKey(component.getComponentCompositionData().getName())) .forEach(entryValue -> entryValue.getValue().getNode_types().values().stream() .filter(type -> MapUtils.isNotEmpty(type.getCapabilities())) .forEach(type -> type.getCapabilities().entrySet() .forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), entry.getValue())))); } Assert.assertNotNull(capabilities); }