Java Code Examples for org.apache.commons.lang3.EnumUtils#isValidEnum()
The following examples show how to use
org.apache.commons.lang3.EnumUtils#isValidEnum() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CgmesModelTripleStore.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Override public void add(String context, String type, PropertyBags objects) { String contextName = EnumUtils.isValidEnum(CgmesSubset.class, context) ? contextNameFor(CgmesSubset.valueOf(context)) : context; try { if (type.equals(CgmesNames.FULL_MODEL)) { tripleStore.add(contextName, mdNamespace(), type, objects); } else { tripleStore.add(contextName, cimNamespace, type, objects); } } catch (TripleStoreException x) { String msg = String.format("Adding objects of type %s to context %s", type, context); throw new CgmesModelException(msg, x); } }
Example 2
Source File: Utils.java From Java-Library with MIT License | 5 votes |
private static ApiError checkQueryParams(String query) { if (!EnumUtils.isValidEnum(QueryParams.class, query)) { return Utils.convertToApiError(setError("Please provide a proper query, refer to the documentation for more information", 14)); } return null; }
Example 3
Source File: LancamentoController.java From ponto-inteligente-api with MIT License | 5 votes |
/** * Converte um LancamentoDto para uma entidade Lancamento. * * @param lancamentoDto * @param result * @return Lancamento * @throws ParseException */ private Lancamento converterDtoParaLancamento(LancamentoDto lancamentoDto, BindingResult result) throws ParseException { Lancamento lancamento = new Lancamento(); if (lancamentoDto.getId().isPresent()) { Optional<Lancamento> lanc = this.lancamentoService.buscarPorId(lancamentoDto.getId().get()); if (lanc.isPresent()) { lancamento = lanc.get(); } else { result.addError(new ObjectError("lancamento", "Lançamento não encontrado.")); } } else { lancamento.setFuncionario(new Funcionario()); lancamento.getFuncionario().setId(lancamentoDto.getFuncionarioId()); } lancamento.setDescricao(lancamentoDto.getDescricao()); lancamento.setLocalizacao(lancamentoDto.getLocalizacao()); lancamento.setData(this.dateFormat.parse(lancamentoDto.getData())); if (EnumUtils.isValidEnum(TipoEnum.class, lancamentoDto.getTipo())) { lancamento.setTipo(TipoEnum.valueOf(lancamentoDto.getTipo())); } else { result.addError(new ObjectError("tipo", "Tipo inválido.")); } return lancamento; }
Example 4
Source File: ConfigValidator.java From J-Kinopoisk2IMDB with Apache License 2.0 | 5 votes |
/** * Checks the mode string * * @throws IllegalArgumentException If not valid */ private void checkMode() { val mode = config.getString("mode"); if (!EnumUtils.isValidEnum(MovieHandler.Type.class, mode)) { throw new IllegalArgumentException("mode is not valid!"); } }
Example 5
Source File: DateTimeFormatUnitSpec.java From incubator-pinot with Apache License 2.0 | 5 votes |
public DateTimeFormatUnitSpec(String unit) { if (!isValidUnitSpec(unit)) { throw new IllegalArgumentException("Unit must belong to enum TimeUnit or DateTimeTransformUnit"); } if (EnumUtils.isValidEnum(TimeUnit.class, unit)) { _timeUnit = TimeUnit.valueOf(unit); } if (EnumUtils.isValidEnum(DateTimeTransformUnit.class, unit)) { _dateTimeTransformUnit = DateTimeTransformUnit.valueOf(unit); } }
Example 6
Source File: RoleFavoritesServiceImpl.java From wecube-platform with Apache License 2.0 | 4 votes |
private void saveFavoritesRoleBinding(String collectId, FavoritesDto favoritesDto) throws WecubeCoreException { Map<String, List<String>> permissionToRoleMap = favoritesDto.getPermissionToRole(); if (null == permissionToRoleMap) { throw new WecubeCoreException("There is no favorites to role with permission mapping found."); } String errorMsg; for (Map.Entry<String, List<String>> permissionToRoleListEntry : permissionToRoleMap.entrySet()) { String permissionStr = permissionToRoleListEntry.getKey(); // check if key is empty or NULL if (StringUtils.isEmpty(permissionStr)) { errorMsg = "The permission key should not be empty or NULL"; log.error(errorMsg); throw new WecubeCoreException(errorMsg); } // check key is valid permission enum if (!EnumUtils.isValidEnum(ProcRoleBindingEntity.permissionEnum.class, permissionStr)) { errorMsg = "The request's key is not valid as a permission."; log.error(errorMsg); throw new WecubeCoreException(errorMsg); } List<String> roleIdList = permissionToRoleListEntry.getValue(); // check if roleIdList is NULL if (null == roleIdList) { errorMsg = String.format("The value of permission: [%s] should not be NULL", permissionStr); log.error(errorMsg); throw new WecubeCoreException(errorMsg); } // when permission is MGMT and roleIdList is empty, then it is // invalid if (ProcRoleBindingEntity.permissionEnum.MGMT.toString().equals(permissionStr) && roleIdList.isEmpty()) { errorMsg = "At least one role with MGMT role should be declared."; log.error(errorMsg); throw new WecubeCoreException(errorMsg); } batchSaveRoleFavorites(collectId, roleIdList, permissionStr); } }
Example 7
Source File: WorkflowProcDefService.java From wecube-platform with Apache License 2.0 | 4 votes |
private void saveProcRoleBinding(String procId, ProcDefInfoDto procDefInfoDto) throws WecubeCoreException { Map<String, List<String>> permissionToRoleMap = procDefInfoDto.getPermissionToRole(); if (null == permissionToRoleMap) { throw new WecubeCoreException("There is no process to role with permission mapping found."); } String errorMsg; for (Map.Entry<String, List<String>> permissionToRoleListEntry : permissionToRoleMap.entrySet()) { String permissionStr = permissionToRoleListEntry.getKey(); // check if key is empty or NULL if (StringUtils.isEmpty(permissionStr)) { errorMsg = "The permission key should not be empty or NULL"; log.error(errorMsg); throw new WecubeCoreException(errorMsg); } // check key is valid permission enum if (!EnumUtils.isValidEnum(ProcRoleBindingEntity.permissionEnum.class, permissionStr)) { errorMsg = "The request's key is not valid as a permission."; log.error(errorMsg); throw new WecubeCoreException(errorMsg); } List<String> roleIdList = permissionToRoleListEntry.getValue(); // check if roleIdList is NULL if (null == roleIdList) { errorMsg = String.format("The value of permission: [%s] should not be NULL", permissionStr); log.error(errorMsg); throw new WecubeCoreException(errorMsg); } // when permission is MGMT and roleIdList is empty, then it is // invalid if (ProcRoleBindingEntity.permissionEnum.MGMT.toString().equals(permissionStr) && roleIdList.isEmpty()) { errorMsg = "At least one role with MGMT role should be declared."; log.error(errorMsg); throw new WecubeCoreException(errorMsg); } processRoleService.batchSaveData(procId, roleIdList, permissionStr); } }
Example 8
Source File: PriceGranularity.java From prebid-server-java with Apache License 2.0 | 4 votes |
/** * Checks if string price granularity is valid type. */ private static boolean isValidStringPriceGranularityType(String stringPriceGranularity) { return EnumUtils.isValidEnum(PriceGranularityType.class, stringPriceGranularity); }
Example 9
Source File: RolesServiceImpl.java From pulsar-manager with Apache License 2.0 | 4 votes |
public Map<String, String> validateRoleInfoEntity(RoleInfoEntity roleInfoEntity) { Map<String, String> validateResult = Maps.newHashMap(); if (StringUtils.isBlank(roleInfoEntity.getRoleName())) { validateResult.put("error", "Role name cannot be empty"); return validateResult; } if (StringUtils.isBlank(roleInfoEntity.getResourceName())) { validateResult.put("error", "Resource name cannot be empty"); return validateResult; } if (!(pattern.matcher(roleInfoEntity.getRoleName()).matches())) { validateResult.put("error", "Role name is illegal"); return validateResult; } if (!(pattern.matcher(roleInfoEntity.getResourceName()).matches())) { validateResult.put("error", "Resource Name is illegal"); return validateResult; } if (!EnumUtils.isValidEnum(ResourceType.class, roleInfoEntity.getResourceType())) { validateResult.put("error", "Resource type is illegal"); return validateResult; } if (ResourceType.TENANTS.name().equals(roleInfoEntity.getResourceType())) { Optional<TenantEntity> tenantEntity = tenantsRepository.findByTenantId(roleInfoEntity.getResourceId()); if (!tenantEntity.isPresent()) { validateResult.put("error", "Tenant no exist, please check"); return validateResult; } } if (ResourceType.NAMESPACES.name().equals(roleInfoEntity.getResourceType())) { Optional<NamespaceEntity> namespaceEntity = namespacesRepository.findByNamespaceId( roleInfoEntity.getResourceId()); if (!namespaceEntity.isPresent()) { validateResult.put("error", "Namespace no exist, please check"); return validateResult; } } Set<String> resourceVerbs = new HashSet<>( Arrays.asList(roleInfoEntity.getResourceVerbs().split(VERBS_SEPARATOR))); for (String verb : resourceVerbs) { if (!EnumUtils.isValidEnum(ResourceVerbs.class, verb)) { validateResult.put("error", "Verb " + verb + "does not belong to this class, Optional (ADMIN, PRODUCE, CONSUME, FUNCTION)"); return validateResult; } } ResourceType resourceType = ResourceType.valueOf(roleInfoEntity.getResourceType()); if (resourceType != ResourceType.NAMESPACES && resourceType != ResourceType.ALL) { if (resourceType == ResourceType.TOPICS) { if (resourceVerbs.contains(ResourceVerbs.ADMIN.name())) { validateResult.put("error", "admin should not be excluded for resources of type topic"); return validateResult; } } if (resourceVerbs.contains(ResourceVerbs.PRODUCE.name()) || resourceVerbs.contains(ResourceVerbs.CONSUME.name()) || resourceVerbs.contains(ResourceVerbs.FUNCTION.name())) { validateResult.put("error", "Type " + resourceType + " include not supported verbs"); return validateResult; } } validateResult.put("message", "Role validate success"); return validateResult; }
Example 10
Source File: StudentEditService.java From zhcet-web with Apache License 2.0 | 4 votes |
private static <E extends Enum<E>> void checkMemberShip(Class<E> enumClass, String string, String label, String identifier) { if (!EnumUtils.isValidEnum(enumClass, string)) { log.warn("Tried to save student with invalid status {} {}", identifier, string); throw new IllegalArgumentException("Invalid " + label + " : " + string + ". Must be within " + EnumUtils.getEnumMap(enumClass).keySet()); } }
Example 11
Source File: CustomLuceneGeoGazetteerComparator.java From lucene-geo-gazetteer with Apache License 2.0 | 4 votes |
public static boolean exists(String val) { return EnumUtils.isValidEnum(FeatureCode.class, val); }
Example 12
Source File: DateTimeFormatUnitSpec.java From incubator-pinot with Apache License 2.0 | 4 votes |
public static boolean isValidUnitSpec(String unit) { if (EnumUtils.isValidEnum(TimeUnit.class, unit) || EnumUtils.isValidEnum(DateTimeTransformUnit.class, unit)) { return true; } return false; }
Example 13
Source File: RfLintParser.java From analysis-model with MIT License | 3 votes |
/** * Determines the RfLintSeverity based on the provided character. * * @param violationSeverity * The character presentiting the violation severity * * @return An instance of RfLintSeverity matching the character. `WARNING` as the default if the severity * character is not valid. */ public static RfLintSeverity fromCharacter(final char violationSeverity) { if (EnumUtils.isValidEnum(RfLintSeverity.class, String.valueOf(violationSeverity))) { return RfLintSeverity.valueOf(String.valueOf(violationSeverity)); } return WARNING; }
Example 14
Source File: ConfigStoreBasedTemplateHandler.java From carbon-identity-framework with Apache License 2.0 | 2 votes |
private boolean isValidTemplateType(String templateType) { return EnumUtils.isValidEnum(TemplateMgtConstants.TemplateType.class, templateType); }
Example 15
Source File: TemplateManagerImpl.java From carbon-identity-framework with Apache License 2.0 | 2 votes |
private boolean isValidTemplateType(String templateType) { return EnumUtils.isValidEnum(TemplateMgtConstants.TemplateType.class, templateType); }