Java Code Examples for org.apache.commons.lang3.EnumUtils#getEnum()

The following examples show how to use org.apache.commons.lang3.EnumUtils#getEnum() . 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: EnumExcelConverter.java    From easyexcel-utils with Apache License 2.0 6 votes vote down vote up
@Override
public Enum convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
    String cellDataStr = cellData.getStringValue();

    EnumFormat annotation = contentProperty.getField().getAnnotation(EnumFormat.class);
    Class enumClazz = annotation.value();
    String[] fromExcel = annotation.fromExcel();
    String[] toJavaEnum = annotation.toJavaEnum();

    Enum anEnum = null;
    if (ArrayUtils.isNotEmpty(fromExcel) && ArrayUtils.isNotEmpty(toJavaEnum)) {
        Assert.isTrue(fromExcel.length == toJavaEnum.length, "fromExcel 与 toJavaEnum 的长度必须相同");
        for (int i = 0; i < fromExcel.length; i++) {
            if (Objects.equals(fromExcel[i], cellDataStr)) {
                anEnum = EnumUtils.getEnum(enumClazz, toJavaEnum[i]);
            }
        }
    } else {
        anEnum = EnumUtils.getEnum(enumClazz, cellDataStr);
    }

    Assert.notNull(anEnum, "枚举值不合法");
    return anEnum;
}
 
Example 2
Source File: ActionCopy.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String attachmentId, String referenceTypeString,
		String reference, Integer scale) throws Exception {
	ActionResult<Wo> result = new ActionResult<>();
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Business business = new Business(emc);
		ReferenceType referenceType = EnumUtils.getEnum(ReferenceType.class, referenceTypeString);
		if (null == referenceType) {
			throw new ExceptionInvalidReferenceType(referenceTypeString);
		}
		if (StringUtils.isEmpty(reference)) {
			throw new ExceptionEmptyReference(reference);
		}
		Attachment attachment = emc.find(attachmentId, Attachment.class);
		if (null == attachment) {
			throw new ExceptionAttachmentNotExisted(attachmentId);
		}
		if (effectivePerson.isNotManager() && effectivePerson.isNotPerson(attachment.getPerson())) {
			throw new ExceptionAttachmentAccessDenied(effectivePerson.getDistinguishedName(), attachment.getName(),
					attachment.getId());
		}
		String id = this.copy(effectivePerson, business, referenceType, reference, attachment, scale);
		Wo wo = new Wo();
		wo.setId(id);
		return result;
	}
}
 
Example 3
Source File: FileRemoveQueue.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(Map<String, String> map) throws Exception {
	String reference = map.get(REFERENCE);
	String referenceTypeString = map.get(REFERENCETYPE);
	ReferenceType referenceType = EnumUtils.getEnum(ReferenceType.class, referenceTypeString);
	if (StringUtils.isEmpty(reference) || (null == referenceType)) {
		logger.warn("接收到无效的删除文件请求, referenceType: {}, reference: {}.", referenceTypeString, reference);
	} else {
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			Business business = new Business(emc);
			List<String> ids = business.file().listWithReferenceTypeWithReference(referenceType, reference);
			for (File o : emc.list(File.class, ids)) {
				StorageMapping mapping = ThisApplication.context().storageMappings().get(File.class,
						o.getStorage());
				if (null == mapping) {
					throw new ExceptionStorageMappingNotExisted(o.getStorage());
				} else {
					o.deleteContent(mapping);
					emc.beginTransaction(File.class);
					emc.remove(o);
					emc.commit();
				}
			}
		}
	}
}
 
Example 4
Source File: EventPushParser.java    From wechat-mp-sdk with Apache License 2.0 6 votes vote down vote up
@Override
public Reply parse(Push push) {
    if (!(push instanceof EventPush)) {
        return null;
    }

    EventPush eventPush = (EventPush) push;
    String event = eventPush.getEvent();

    EventPushType eventPushType = EnumUtils.getEnum(EventPushType.class, StringUtils.upperCase(event));
    Validate.notNull(eventPushType, "don't-support-%s-event-push", event);

    // TODO please custom it.
    if (eventPushType == EventPushType.SUBSCRIBE) {
        Reply reply = ReplyUtil.parseReplyDetailWarpper(ReplyUtil.getDummyTextReplyDetailWarpper());
        return ReplyUtil.buildReply(reply, eventPush);
    }

    return null;
}
 
Example 5
Source File: ActionListWithReferenceTypeWithReference.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String referenceTypeString, String reference)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Business business = new Business(emc);
		ReferenceType referenceType = EnumUtils.getEnum(ReferenceType.class, referenceTypeString);
		if (null == referenceType) {
			throw new ExceptionInvalidReferenceType(referenceTypeString);
		}
		if (StringUtils.isEmpty(reference)) {
			throw new ExceptionEmptyReference(reference);
		}
		List<String> ids = business.file().listWithReferenceTypeWithReference(referenceType, reference);
		List<Wo> wos = Wo.copier.copy(emc.list(File.class, ids));
		wos = wos.stream().sorted(Comparator.comparing(File::getName, Comparator.nullsLast(String::compareTo)))
				.collect(Collectors.toList());
		result.setData(wos);
		return result;
	}
}
 
Example 6
Source File: ActionCopy.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String attachmentId, String referenceTypeString,
		String reference, Integer scale) throws Exception {
	ActionResult<Wo> result = new ActionResult<>();
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		Business business = new Business(emc);
		ReferenceType referenceType = EnumUtils.getEnum(ReferenceType.class, referenceTypeString);
		if (null == referenceType) {
			throw new ExceptionInvalidReferenceType(referenceTypeString);
		}
		if (StringUtils.isEmpty(reference)) {
			throw new ExceptionEmptyReference(reference);
		}
		Attachment attachment = emc.find(attachmentId, Attachment.class);
		if (null == attachment) {
			throw new ExceptionAttachmentNotExisted(attachmentId);
		}
		if (effectivePerson.isNotManager() && effectivePerson.isNotPerson(attachment.getPerson())) {
			throw new ExceptionAttachmentAccessDenied(effectivePerson.getDistinguishedName(), attachment.getName(),
					attachment.getId());
		}
		String id = this.copy(effectivePerson, business, referenceType, reference, attachment, scale);
		Wo wo = new Wo();
		wo.setId(id);
		return result;
	}
}
 
Example 7
Source File: FileRemoveQueue.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(Map<String, String> map) throws Exception {
	String reference = map.get(REFERENCE);
	String referenceTypeString = map.get(REFERENCETYPE);
	ReferenceType referenceType = EnumUtils.getEnum(ReferenceType.class, referenceTypeString);
	if (StringUtils.isEmpty(reference) || (null == referenceType)) {
		logger.warn("接收到无效的删除文件请求, referenceType: {}, reference: {}.", referenceTypeString, reference);
	} else {
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			Business business = new Business(emc);
			List<String> ids = business.file().listWithReferenceTypeWithReference(referenceType, reference);
			for (File o : emc.list(File.class, ids)) {
				StorageMapping mapping = ThisApplication.context().storageMappings().get(File.class,
						o.getStorage());
				if (null == mapping) {
					throw new ExceptionStorageMappingNotExisted(o.getStorage());
				} else {
					o.deleteContent(mapping);
					emc.beginTransaction(File.class);
					emc.remove(o);
					emc.commit();
				}
			}
		}
	}
}
 
Example 8
Source File: ActionListWithReferenceTypeWithReference.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String referenceTypeString, String reference)
		throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
		ActionResult<List<Wo>> result = new ActionResult<>();
		Business business = new Business(emc);
		ReferenceType referenceType = EnumUtils.getEnum(ReferenceType.class, referenceTypeString);
		if (null == referenceType) {
			throw new ExceptionInvalidReferenceType(referenceTypeString);
		}
		if (StringUtils.isEmpty(reference)) {
			throw new ExceptionEmptyReference(reference);
		}
		List<String> ids = business.file().listWithReferenceTypeWithReference(referenceType, reference);
		List<Wo> wos = Wo.copier.copy(emc.list(File.class, ids));
		wos = wos.stream().sorted(Comparator.comparing(File::getName, Comparator.nullsLast(String::compareTo)))
				.collect(Collectors.toList());
		result.setData(wos);
		return result;
	}
}
 
Example 9
Source File: ServerStoreModel.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
public Observable<RxDocumentServiceResponse> processMessage(RxDocumentServiceRequest request) {
    String requestConsistencyLevelHeaderValue = request.getHeaders().get(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL);

    request.requestContext.originalRequestConsistencyLevel = null;

    if (!Strings.isNullOrEmpty(requestConsistencyLevelHeaderValue)) {
        ConsistencyLevel requestConsistencyLevel;

        if ((requestConsistencyLevel = EnumUtils.getEnum(ConsistencyLevel.class, requestConsistencyLevelHeaderValue)) == null) {
            return Observable.error(new BadRequestException(
                String.format(
                    RMResources.InvalidHeaderValue,
                    requestConsistencyLevelHeaderValue,
                    HttpConstants.HttpHeaders.CONSISTENCY_LEVEL)));
        }

        request.requestContext.originalRequestConsistencyLevel = requestConsistencyLevel;
    }

    if (ReplicatedResourceClient.isMasterResource(request.getResourceType())) {
        request.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Strong.toString());
    }

    Single<RxDocumentServiceResponse> response = this.storeClient.processMessageAsync(request);
    return response.toObservable();
}
 
Example 10
Source File: ConfigurationFieldModelConverter.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
public final Map<String, ConfigurationFieldModel> convertToConfigurationFieldModelMap(FieldModel fieldModel) throws AlertDatabaseConstraintException {
    ConfigContextEnum context = EnumUtils.getEnum(ConfigContextEnum.class, fieldModel.getContext());
    String descriptorName = fieldModel.getDescriptorName();
    DescriptorKey descriptorKey = descriptorMap.getDescriptorKey(descriptorName).orElseThrow(() -> new AlertDatabaseConstraintException("Could not find a Descriptor with the name: " + descriptorName));

    List<DefinedFieldModel> fieldsForContext = descriptorAccessor.getFieldsForDescriptor(descriptorKey, context);
    Map<String, ConfigurationFieldModel> configurationModels = new HashMap<>();
    for (DefinedFieldModel definedField : fieldsForContext) {
        fieldModel.getFieldValueModel(definedField.getKey())
            .flatMap(fieldValueModel -> convertFromDefinedFieldModel(definedField, fieldValueModel.getValues(), fieldValueModel.isSet()))
            .ifPresent(configurationFieldModel -> configurationModels.put(configurationFieldModel.getFieldKey(), configurationFieldModel));
    }

    return configurationModels;
}
 
Example 11
Source File: RoundExpressionProcessor.java    From vividus with Apache License 2.0 5 votes vote down vote up
public RoundingMode getRoundingMode()
{
    if (roundingMode == null)
    {
        return value.charAt(0) == '-' ? RoundingMode.HALF_DOWN : RoundingMode.HALF_UP;
    }
    return EnumUtils.getEnum(RoundingMode.class, roundingMode.toUpperCase());
}
 
Example 12
Source File: KeycloakOAuthFactory.java    From apiman with Apache License 2.0 4 votes vote down vote up
private static OAuth2FlowType toEnum(String flowType) {
    return EnumUtils.getEnum(OAuth2FlowType.class, flowType.toUpperCase());
}
 
Example 13
Source File: ActionUpload.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String referenceType, String reference, Integer scale,
		byte[] bytes, FormDataContentDisposition disposition) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
			ByteArrayInputStream in = new ByteArrayInputStream(bytes)) {
		ActionResult<Wo> result = new ActionResult<>();
		ReferenceType type = EnumUtils.getEnum(ReferenceType.class, referenceType);
		StorageMapping mapping = ThisApplication.context().storageMappings().random(File.class);
		if (null == mapping) {
			throw new ExceptionAllocateStorageMaaping();
		}
		/** 由于这里需要根据craeteTime创建path,先进行赋值,再进行校验,最后保存 */
		/** 禁止不带扩展名的文件上传 */
		/** 文件名编码转换 */
		String fileName = new String(disposition.getFileName().getBytes(DefaultCharset.charset_iso_8859_1),
				DefaultCharset.charset);
		fileName = FilenameUtils.getName(fileName);

		if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) {
			throw new ExceptionEmptyExtension(fileName);
		}
		File file = new File(mapping.getName(), fileName, effectivePerson.getDistinguishedName(), type, reference);
		emc.check(file, CheckPersistType.all);
		if ((scale > 0) && ArrayUtils.contains(IMAGE_EXTENSIONS, file.getExtension())) {
			/** 如果是需要压缩的附件 */
			try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
				BufferedImage image = ImageIO.read(in);
				if (image.getWidth() > scale) {
					/** 图像的实际大小比scale大的要进行压缩 */
					BufferedImage scalrImage = Scalr.resize(image, Method.QUALITY, Mode.FIT_TO_WIDTH, scale);
					ImageIO.write(scalrImage, file.getExtension(), baos);
				} else {
					/** 图像的实际大小比scale小,保存原图不进行压缩 */
					ImageIO.write(image, file.getExtension(), baos);
				}
				try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
					file.saveContent(mapping, bais, fileName);
				}
			}
		} else {
			file.saveContent(mapping, in, fileName);
		}
		emc.beginTransaction(File.class);
		emc.persist(file);
		emc.commit();
		ApplicationCache.notify(File.class);
		Wo wo = new Wo();
		wo.setId(file.getId());
		result.setData(wo);
		return result;
	}
}
 
Example 14
Source File: ActionUploadOctetStream.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String referenceType, String reference, Integer scale,
		byte[] bytes) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
			ByteArrayInputStream in = new ByteArrayInputStream(bytes)) {
		ActionResult<Wo> result = new ActionResult<>();
		ReferenceType type = EnumUtils.getEnum(ReferenceType.class, referenceType);
		StorageMapping mapping = ThisApplication.context().storageMappings().random(File.class);
		if (null == mapping) {
			throw new ExceptionAllocateStorageMaaping();
		}
		String fileName = "image.jpg";
		File file = new File(mapping.getName(), fileName, effectivePerson.getDistinguishedName(), type, reference);
		emc.check(file, CheckPersistType.all);
		if ((scale > 0) && ArrayUtils.contains(IMAGE_EXTENSIONS, file.getExtension())) {
			/** 如果是需要压缩的附件 */
			try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
				BufferedImage image = ImageIO.read(in);
				if (image.getWidth() > scale) {
					/** 图像的实际大小比scale大的要进行压缩 */
					BufferedImage scalrImage = Scalr.resize(image, Method.QUALITY, Mode.FIT_TO_WIDTH, scale);
					ImageIO.write(scalrImage, file.getExtension(), baos);
				} else {
					/** 图像的实际大小比scale小,保存原图不进行压缩 */
					ImageIO.write(image, file.getExtension(), baos);
				}
				try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
					file.saveContent(mapping, bais, fileName);
				}
			}
		} else {
			file.saveContent(mapping, in, fileName);
		}
		emc.beginTransaction(File.class);
		emc.persist(file);
		emc.commit();
		ApplicationCache.notify(File.class);
		Wo wo = new Wo();
		wo.setId(file.getId());
		result.setData(wo);
		return result;
	}
}
 
Example 15
Source File: ActionUploadCallback.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo<WoObject>> execute(EffectivePerson effectivePerson, String referenceType, String reference,
		Integer scale, String callback, byte[] bytes, FormDataContentDisposition disposition) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
			ByteArrayInputStream in = new ByteArrayInputStream(bytes)) {
		ActionResult<Wo<WoObject>> result = new ActionResult<>();
		ReferenceType type = EnumUtils.getEnum(ReferenceType.class, referenceType);
		StorageMapping mapping = ThisApplication.context().storageMappings().random(File.class);
		if (null == mapping) {
			throw new ExceptionAllocateStorageMaapingCallback(callback);
		}
		/** 由于这里需要根据craeteTime创建path,先进行赋值,再进行校验,最后保存 */
		/** 禁止不带扩展名的文件上传 */
		/** 文件名编码转换 */
		String fileName = new String(disposition.getFileName().getBytes(DefaultCharset.charset_iso_8859_1),
				DefaultCharset.charset);
		fileName = FilenameUtils.getName(fileName);
		if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) {
			throw new ExceptionEmptyExtensionCallback(callback, fileName);
		}
		File file = new File(mapping.getName(), fileName, effectivePerson.getDistinguishedName(), type, reference);
		emc.check(file, CheckPersistType.all);
		if ((scale > 0) && ArrayUtils.contains(IMAGE_EXTENSIONS, file.getExtension())) {
			/** 如果是需要压缩的附件 */
			try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
				BufferedImage image = ImageIO.read(in);
				if (image.getWidth() > scale) {
					/** 图像的实际大小比scale大的要进行压缩 */
					BufferedImage scalrImage = Scalr.resize(image, Method.QUALITY, Mode.FIT_TO_WIDTH, scale);
					ImageIO.write(scalrImage, file.getExtension(), baos);
				} else {
					/** 图像的实际大小比scale小,保存原图不进行压缩 */
					ImageIO.write(image, file.getExtension(), baos);
				}
				try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
					file.saveContent(mapping, bais, fileName);
				}
			}
		} else {
			file.saveContent(mapping, in, fileName);
		}
		emc.beginTransaction(File.class);
		emc.persist(file);
		emc.commit();
		ApplicationCache.notify(File.class);
		WoObject woObject = new WoObject();
		woObject.setId(file.getId());
		Wo<WoObject> wo = new Wo<>(callback, woObject);
		result.setData(wo);
		return result;
	}
}
 
Example 16
Source File: ActionUpload.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
ActionResult<Wo> execute(EffectivePerson effectivePerson, String referenceType, String reference, Integer scale,
		byte[] bytes, FormDataContentDisposition disposition) throws Exception {
	try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
			ByteArrayInputStream in = new ByteArrayInputStream(bytes)) {
		ActionResult<Wo> result = new ActionResult<>();
		ReferenceType type = EnumUtils.getEnum(ReferenceType.class, referenceType);
		StorageMapping mapping = ThisApplication.context().storageMappings().random(File.class);
		if (null == mapping) {
			throw new ExceptionAllocateStorageMaaping();
		}
		/** 由于这里需要根据craeteTime创建path,先进行赋值,再进行校验,最后保存 */
		/** 禁止不带扩展名的文件上传 */
		/** 文件名编码转换 */
		String fileName = new String(disposition.getFileName().getBytes(DefaultCharset.charset_iso_8859_1),
				DefaultCharset.charset);
		fileName = FilenameUtils.getName(fileName);

		if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) {
			throw new ExceptionEmptyExtension(fileName);
		}
		File file = new File(mapping.getName(), fileName, effectivePerson.getDistinguishedName(), type, reference);
		emc.check(file, CheckPersistType.all);
		if ((scale > 0) && ArrayUtils.contains(IMAGE_EXTENSIONS, file.getExtension())) {
			/** 如果是需要压缩的附件 */
			try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
				BufferedImage image = ImageIO.read(in);
				if (image.getWidth() > scale) {
					/** 图像的实际大小比scale大的要进行压缩 */
					BufferedImage scalrImage = Scalr.resize(image, Method.QUALITY, Mode.FIT_TO_WIDTH, scale);
					ImageIO.write(scalrImage, file.getExtension(), baos);
				} else {
					/** 图像的实际大小比scale小,保存原图不进行压缩 */
					ImageIO.write(image, file.getExtension(), baos);
				}
				try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
					file.saveContent(mapping, bais, fileName);
				}
			}
		} else {
			file.saveContent(mapping, in, fileName);
		}
		emc.beginTransaction(File.class);
		emc.persist(file);
		emc.commit();
		ApplicationCache.notify(File.class);
		Wo wo = new Wo();
		wo.setId(file.getId());
		result.setData(wo);
		return result;
	}
}
 
Example 17
Source File: FileModel.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
OnParseError fromName(String name)
{
    return EnumUtils.getEnum(OnParseError.class, StringUtils.upperCase(name));
}
 
Example 18
Source File: DescriptorProcessor.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
public Optional<TestAction> retrieveTestAction(FieldModel fieldModel) {
    ConfigContextEnum descriptorContext = EnumUtils.getEnum(ConfigContextEnum.class, fieldModel.getContext());
    return retrieveTestAction(fieldModel.getDescriptorName(), descriptorContext);
}
 
Example 19
Source File: DescriptorProcessor.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
public Optional<ApiAction> retrieveApiAction(String descriptorName, String context) {
    ConfigContextEnum descriptorContext = EnumUtils.getEnum(ConfigContextEnum.class, context);
    return retrieveConfigurationAction(descriptorName).map(configurationAction -> configurationAction.getApiAction(descriptorContext));
}
 
Example 20
Source File: AuthFactory.java    From apiman with Apache License 2.0 4 votes vote down vote up
public static AuthType getType(String name) {
    return EnumUtils.getEnum(AuthType.class, name.toUpperCase());
}