下面列出了org.apache.commons.lang3.EnumUtils#isValidEnum ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
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;
}
/**
* 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;
}
/**
* 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!");
}
}
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);
}
}
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);
}
}
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);
}
}
/**
* Checks if string price granularity is valid type.
*/
private static boolean isValidStringPriceGranularityType(String stringPriceGranularity) {
return EnumUtils.isValidEnum(PriceGranularityType.class, stringPriceGranularity);
}
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;
}
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());
}
}
public static boolean exists(String val) {
return EnumUtils.isValidEnum(FeatureCode.class, val);
}
public static boolean isValidUnitSpec(String unit) {
if (EnumUtils.isValidEnum(TimeUnit.class, unit) || EnumUtils.isValidEnum(DateTimeTransformUnit.class, unit)) {
return true;
}
return false;
}
/**
* 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;
}
private boolean isValidTemplateType(String templateType) {
return EnumUtils.isValidEnum(TemplateMgtConstants.TemplateType.class, templateType);
}
private boolean isValidTemplateType(String templateType) {
return EnumUtils.isValidEnum(TemplateMgtConstants.TemplateType.class, templateType);
}