use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class RestFilterParserTest method testInOperator.
@Test
public void testInOperator() throws Exception {
new StrictExpectations() {
{
RandomStringUtils.randomAlphabetic(anyInt);
result = "paramName1";
}
};
String data = readDataFromFile("data/restFilter5.json");
MetaClass metaClass = metadata.getClass("test$TestEntity");
RestFilterParseResult parseResult = restFilterParser.parse(data, metaClass);
String expectedJpqlWhere = "({E}.intField in :paramName1)";
assertEquals(expectedJpqlWhere, parseResult.getJpqlWhere());
Map<String, Object> queryParameters = parseResult.getQueryParameters();
List<Integer> param1Value = (List<Integer>) queryParameters.get("paramName1");
assertEquals(Arrays.asList(1, 2, 3), param1Value);
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class RestFilterParserTest method testParseSimpleFilter.
@Test
public void testParseSimpleFilter() throws Exception {
new StrictExpectations() {
{
RandomStringUtils.randomAlphabetic(anyInt);
result = "stringParamName";
RandomStringUtils.randomAlphabetic(anyInt);
result = "intParamName";
RandomStringUtils.randomAlphabetic(anyInt);
result = "booleanParamName";
}
};
String data = readDataFromFile("data/restFilter1.json");
MetaClass metaClass = metadata.getClass("test$TestEntity");
RestFilterParseResult parseResult = restFilterParser.parse(data, metaClass);
String expectedJpqlWhere = "({E}.stringField <> :stringParamName and " + "{E}.intField > :intParamName and " + "{E}.booleanField = :booleanParamName)";
assertEquals(expectedJpqlWhere, parseResult.getJpqlWhere());
Map<String, Object> queryParameters = parseResult.getQueryParameters();
assertEquals("stringValue", queryParameters.get("stringParamName"));
assertEquals(100, queryParameters.get("intParamName"));
assertEquals(true, queryParameters.get("booleanParamName"));
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class DeletePolicyHandler method recognizeRelatedEntityMetaClass.
@Nullable
protected MetaClass recognizeRelatedEntityMetaClass(String message) {
Matcher matcher = getPattern().matcher(message);
if (matcher.find()) {
String entityName = matcher.group(2);
if (!StringUtils.isEmpty(entityName)) {
MetaClass metaClass = metadata.getClass(entityName);
if (metaClass != null) {
MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalMetaClass(metaClass);
metaClass = originalMetaClass != null ? originalMetaClass : metaClass;
}
return metaClass;
}
}
return null;
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class DeletePolicyHandler method doHandle.
protected void doHandle(String message, WindowManager windowManager) {
String caption = null;
String notificationMessage = null;
MetaClass deletedEntityMetaClass = recognizeDeletedEntityMetaClass(message);
if (deletedEntityMetaClass != null) {
String customCaptionKey = String.format("deletePolicy.caption.%s", deletedEntityMetaClass.getName());
String customCaption = messages.getMainMessage(customCaptionKey);
if (!customCaptionKey.equals(customCaption)) {
caption = customCaption;
}
String customMessageKey = String.format("deletePolicy.references.message.%s", deletedEntityMetaClass.getName());
String customMessage = messages.getMainMessage(customMessageKey);
if (!customMessageKey.equals(customMessage)) {
notificationMessage = customMessage;
}
}
if (StringUtils.isEmpty(caption)) {
caption = messages.getMainMessage("deletePolicy.caption");
}
if (StringUtils.isEmpty(notificationMessage)) {
MetaClass metaClass = recognizeRelatedEntityMetaClass(message);
if (metaClass != null) {
String localizedEntityName = messages.getTools().getEntityCaption(metaClass);
String referencesMessage = messages.getMainMessage("deletePolicy.references.message");
notificationMessage = String.format(referencesMessage, localizedEntityName);
}
}
windowManager.showNotification(caption, notificationMessage, Frame.NotificationType.ERROR);
}
use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.
the class RowLevelSecurityExceptionHandler method doHandle.
@Override
protected void doHandle(String className, String message, @Nullable Throwable throwable, WindowManager windowManager) {
try {
Messages messages = AppBeans.get(Messages.NAME);
String userCaption = null;
String userMessage = null;
if (throwable != null) {
// noinspection ThrowableResultOfMethodCallIgnored
Throwable rootCause = ExceptionUtils.getRootCause(throwable);
RowLevelSecurityException exception = null;
if (throwable instanceof RowLevelSecurityException) {
exception = (RowLevelSecurityException) throwable;
} else if (rootCause instanceof RowLevelSecurityException) {
exception = (RowLevelSecurityException) rootCause;
}
if (exception != null) {
String entity = exception.getEntity();
MetaClass entityClass = AppBeans.get(Metadata.NAME, Metadata.class).getClassNN(entity);
String entityCaption = messages.getTools().getEntityCaption(entityClass);
ExtendedEntities extendedEntities = AppBeans.get(ExtendedEntities.NAME);
MetaClass mainMetaClass = extendedEntities.getOriginalOrThisMetaClass(entityClass);
String originalEntity = mainMetaClass.getName();
String entityName = originalEntity.split("\\$")[1];
ConstraintOperationType operationType = exception.getOperationType();
if (operationType != null) {
ConstraintLocalizationService service = AppBeans.get(ConstraintLocalizationService.NAME);
LocalizedConstraintMessage localizedMessage = service.findLocalizedConstraintMessage(originalEntity, operationType);
if (localizedMessage != null) {
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
Locale locale = userSessionSource.getLocale();
String localeCode = messages.getTools().localeToString(locale);
userCaption = localizedMessage.getLocalizedCaption(localeCode);
userMessage = localizedMessage.getLocalizedMessage(localeCode);
}
String operationId = operationType.getId();
if (StringUtils.isEmpty(userCaption)) {
String customCaptionKey = String.format("rowLevelSecurity.caption.%s.%s", entityName, operationId);
String customCaption = messages.getMainMessage(customCaptionKey);
if (!customCaptionKey.equals(customCaption)) {
userCaption = customCaption;
}
}
if (StringUtils.isEmpty(userMessage)) {
String customMessageKey = String.format("rowLevelSecurity.entityAndOperationMessage.%s.%s", entityName, operationId);
String customMessage = messages.getMainMessage(customMessageKey);
if (!customMessageKey.equals(customMessage)) {
userMessage = customMessage;
} else {
userMessage = messages.formatMainMessage("rowLevelSecurity.entityAndOperationMessage", messages.getMessage(operationType), entityCaption);
}
}
} else {
String customCaptionKey = String.format("rowLevelSecurity.caption.%s", entityName);
String customCaption = messages.getMainMessage(customCaptionKey);
if (!customCaptionKey.equals(customCaption)) {
userCaption = customCaption;
}
String customMessageKey = String.format("rowLevelSecurity.entityMessage.%s", entityName);
String customMessage = messages.getMainMessage(customMessageKey);
if (!customMessageKey.equals(customMessage)) {
userMessage = customMessage;
} else {
userMessage = messages.formatMainMessage("rowLevelSecurity.entityMessage", entityCaption);
}
}
}
}
if (StringUtils.isEmpty(userCaption)) {
userCaption = messages.getMainMessage("rowLevelSecurity.caption");
}
windowManager.showNotification(userCaption, userMessage, Frame.NotificationType.ERROR);
} catch (Throwable th) {
log.error("Unable to handle RowLevelSecurityException", throwable);
log.error("Exception in RowLevelSecurityExceptionHandler", th);
}
}
Aggregations