本文整理汇总了Java中org.easyrec.model.core.web.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.easyrec.model.core.web包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatResponse
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
/**
* This method takes an object and creates a <code>Response</code> object
* out of it which will be returned. If <code>messages</code> contains error
* messages they will be send back instead.
* The format of the <code>Response</code>
* depends on the <code>responseType</code>.
* Supported types are <code>application/xml</code> and <code>application/json</code>
*
* @param respondData an object which will be returned as a
* <code>Response</code> object
* @param messages a list of <code>Message</code> objects which contain
* error messages of the API request
* @param callback if set and responseType is json the result will be returned
* via this javascript callback function (optional)
* @return a <code>Response</code> object containing the <code>responseData</code>
* in the format defined with <code>responseType</code>
*/
private Response formatResponse(Object respondData,
List<Message> messages,
String serviceName,
String callback) {
//handle error messages if existing
if (messages.size() > 0) {
throw new EasyRecException(messages, serviceName, WS.RESPONSE_TYPE_JSON, callback);
}
if (respondData instanceof List) {
respondData = new ResponseSuccessMessage(serviceName, (List<SuccessMessage>) respondData);
}
//convert respondData to Respond object
if (callback != null) {
return Response.ok(new JSONPObject(callback, respondData),
WS.RESPONSE_TYPE_JSCRIPT).build();
} else {
return Response.ok(respondData, WS.RESPONSE_TYPE_JSON).build();
}
}
示例2: checkParameters
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
/**
* This method checks if the <code>apiKey, tenantID, itemID</code> and <code>itemType</code>
* is not null or an empty string. If this is not the case the corresponding error message is
* added to the <code>messages</code> list.
*
* @param apiKey the apiKey which will be checked
* @param tenantID the tenantID which will be checked
* @param itemID the itemID which will be checked
* @param itemType the itemType which will be checked
* @param messages a <code>List<Message></code> where the error messages are appended
* @return returns <code>true</code> if all parameters are positively checked and
* <code>false</code> otherwise
*/
private boolean checkParameters(String apiKey, String tenantID,
String itemID, String itemType, List<Message> messages) {
boolean result = true;
if (Strings.isNullOrEmpty(apiKey)) {
messages.add(MSG.PROFILE_NO_API_KEY);
result = false;
}
if (Strings.isNullOrEmpty(tenantID)) {
messages.add(MSG.PROFILE_NO_TENANT_ID);
result = false;
}
if (Strings.isNullOrEmpty(itemID)) {
messages.add(MSG.ITEM_NO_ID);
result = false;
}
if (Strings.isNullOrEmpty(itemType)) {
messages.add(MSG.PROFILE_NO_ITEM_TYPE);
result = false;
}
return result;
}
示例3: checkItemType
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
private String checkItemType(String itemType, Integer coreTenantId, @Nullable String defaultValue, List<Message> messages) {
if (itemType != null)
itemType = CharMatcher.WHITESPACE.trimFrom(itemType);
if (Strings.isNullOrEmpty(itemType))
return defaultValue;
else
try {
typeMappingService.getIdOfItemType(coreTenantId, itemType, true);
return itemType;
} catch (IllegalArgumentException ex) {
messages.add(MSG.OPERATION_FAILED.append(String.format(" itemType %s not found for tenant", itemType)));
return null;
}
}
示例4: checkParameters
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
/**
* This method checks if the <code>apiKey, tenantID, itemID</code> and <code>itemType</code>
* is not null or an empty string. If this is not the case the corresponding error message is
* added to the <code>messages</code> list.
*
* @param apiKey the apiKey which will be checked
* @param tenantID the tenantID which will be checked
* @param itemID the itemID which will be checked
* @param itemType the itemType which will be checked
* @param messages a <code>List<Message></code> where the error messages are appended
* @return returns <code>true</code> if all parameters are positively checked and
* <code>false</code> otherwise
*/
private boolean checkParameters(String apiKey, String tenantID,
String itemID, String itemType, List<Message> messages) {
boolean result = true;
if (apiKey == null || apiKey.equals("")) {
messages.add(MSG.PROFILE_NO_API_KEY);
result = false;
}
if (tenantID == null || tenantID.equals("")) {
messages.add(MSG.PROFILE_NO_TENANT_ID);
result = false;
}
if (itemID == null || itemID.equals("")) {
messages.add(MSG.ITEM_NO_ID);
result = false;
}
if (itemType == null || itemType.equals("")) {
messages.add(MSG.PROFILE_NO_ITEM_TYPE);
result = false;
}
return result;
}
示例5: create
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
/**
* This static functions creates a MVC Object with a messageblock.
* A messageblock may be displayed to a user after filling in a form
* and list the error he has made.
*
*
*/
public static ModelAndView create(ModelAndView mav, List<Message> messages, String action, String title) {
mav.setViewName(DEFAULT_VIEW_NAME);
mav.addObject("messages", messages);
mav.addObject("action", action);
mav.addObject("title", title);
return mav;
}
示例6: createSingle
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
/**
* This static functions creates a MVC Object with a messageblock
* that contains a single message.
* A messageblock may be displayed to a user after filling in a form
* and list the error he has made.
*
*
*/
public static ModelAndView createSingle(ModelAndView mav, Message message, String action, String title) {
mav.setViewName(DEFAULT_VIEW_NAME);
List<Message> messages = new ArrayList<Message>();
messages.add(message);
mav.addObject("messages", messages);
mav.addObject("action", action);
mav.addObject("title", title);
return mav;
}
示例7: GeneratorResponse
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
public GeneratorResponse(Message message, String action, PluginId pluginId) {
if (message.getClass().equals(ErrorMessage.class))
errorMessage = (ErrorMessage) message;
else
successMessage = (SuccessMessage) message;
this.action = action;
this.pluginId = pluginId;
}
示例8: EasyRecException
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
public EasyRecException(List<Message> messages, String action, String type, String callback) {
//GenericEntity<List<Message>> entity = new GenericEntity<List<Message>>(messages) {};
super(callback != null ?
Response.ok(new JSONPObject(callback, messagesToArray(messages)),
WS.RESPONSE_TYPE_JSCRIPT).build() :
Response.ok(messagesToArray(messages), type).build());
}
示例9: toXMLString
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
private static String toXMLString(List<Message> messages, String action) {
StringBuilder mb = new StringBuilder().append(EASYREC_EXCEPTION_ACTION_BEGIN).append(action)
.append(EASYREC_EXCEPTION_ACTION_END);
for (Message m : messages) {
mb.append(EASYREC_EXCEPTION_ERROR_BEGIN).append(m.getCode()).append(EASYREC_EXCEPTION_ERROR_MIDDLE)
.append(m.getDescription()).append(EASYREC_EXCEPTION_ERROR_END);
}
mb.append(EASYREC_EXCEPTION_END);
return mb.toString();
}
示例10: storeProfileInternal
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
private Response storeProfileInternal(String apiKey, String tenantID, String itemID, String itemType, String profile) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_STORE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
if (checkParameters(apiKey, tenantID, itemID, itemType, errorMessages) &&
checkParameterProfile(profile, errorMessages)) {
Integer coreTenantID = operatorDAO.getTenantId(apiKey, tenantID);
if (coreTenantID == null)
errorMessages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
else {
if (profileService.storeProfile(coreTenantID, itemID, itemType, profile))
responseObject.add(MSG.PROFILE_SAVED);
else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
}
} catch (IllegalArgumentException illegalArgumentException) {
if (illegalArgumentException.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
} catch (RuntimeException runtimeException) {
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_STORE, null);
mon.stop();
return response;
}
示例11: storeItemWithProfileInternal
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
private Response storeItemWithProfileInternal(String apiKey, String tenantID, String itemID, String itemType,
String itemDescription, String itemUrl, String itemImageUrl, String profile) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_STORE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantID);
if (checkParameters(coreTenantId, itemID, itemDescription, itemUrl, errorMessages) && checkParameterProfile(profile, errorMessages)) {
itemType = checkItemType(itemType, coreTenantId, Item.DEFAULT_STRING_ITEM_TYPE, errorMessages);
if (itemType != null) {
itemDAO.insertOrUpdate(coreTenantId, itemID, itemType, itemDescription, itemUrl, itemImageUrl);
if (profileService.storeProfile(coreTenantId, itemID, itemType, profile))
responseObject.add(MSG.PROFILE_SAVED);
else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
}
} catch (IllegalArgumentException illegalArgumentException) {
if (illegalArgumentException.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
} catch (RuntimeException runtimeException) {
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_STORE, null);
mon.stop();
return response;
}
示例12: pushFieldInternal
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
private Response pushFieldInternal(String apiKey, String tenantID, String itemID, String itemType, String path, String value) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_FIELD_STORE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
if (checkParameters(apiKey, tenantID, itemID, itemType, errorMessages) &&
checkParameterValue(value, errorMessages)) {
Integer coreTenantID = operatorDAO.getTenantId(apiKey, tenantID);
if (coreTenantID == null)
errorMessages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
else {
if (profileService.pushToArrayField(
coreTenantID, itemID, itemType,
path, value))
responseObject.add(MSG.PROFILE_FIELD_SAVED);
else
errorMessages.add(MSG.PROFILE_FIELD_NOT_SAVED);
}
}
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
if (e.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else {
errorMessages.add(MSG.PROFILE_FIELD_NOT_SAVED.append(e.getMessage()));
}
} else {
errorMessages.add(MSG.OPERATION_FAILED.append(
"Exception: " + e.getMessage()));
}
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_FIELD_PUSH, null);
mon.stop();
return response;
}
示例13: toXMLString
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
private static String toXMLString(List<Message> messages, String action) {
StringBuilder mb = new StringBuilder().append(EASYREC_EXCEPTION_ACTION_BEGIN).append(action)
.append(EASYREC_EXCEPTION_ACTION_END);
for (Message m : messages) {
mb.append(EASYREC_EXCEPTION_ERROR_BEGIN).append(m.getCode()).append(EASYREC_EXCEPTION_ERROR_MIDDLE)
.append(m.getDescription()).append(EASYREC_EXCEPTION_ERROR_END);
}
mb.append(EASYREC_EXCEPTION_END);
return mb.toString();
}
示例14: formatResponse
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
/**
* This method takes an object and creates a <code>Response</code> object
* out of it which will be returned. If <code>messages</code> contains error
* messages they will be send back instead.
* The format of the <code>Response</code>
* depends on the <code>responseType</code>.
* Supported types are <code>application/xml</code> and <code>application/json</code>
*
* @param respondData an object which will be returned as a
* <code>Response</code> object
* @param messages a list of <code>Message</code> objects which contain
* error messages of the API request
* @param responseType defines the format of the <code>Response</code> object
* @param callback if set and responseType is json the result will be returned
* via this javascript callback function (optional)
* @return a <code>Response</code> object containing the <code>responseData</code>
* in the format defined with <code>responseType</code>
*/
private Response formatResponse(Object respondData,
List<Message> messages,
String serviceName,
String responseType,
String callback) {
//handle error messages if existing
if (messages.size() > 0) {
if ((WS.RESPONSE_TYPE_PATH_JSON.equals(responseType)))
throw new EasyRecException(messages, serviceName, WS.RESPONSE_TYPE_JSON, callback);
else
throw new EasyRecException(messages, serviceName);
}
if (respondData instanceof List) {
respondData = new ResponseSuccessMessage(serviceName, (List<SuccessMessage>) respondData);
}
//convert respondData to Respond object
if (WS.RESPONSE_TYPE_PATH_JSON.equals(responseType)) {
if (callback != null) {
return Response.ok(new JSONPObject(callback, respondData),
WS.RESPONSE_TYPE_JSCRIPT).build();
} else {
return Response.ok(respondData, WS.RESPONSE_TYPE_JSON).build();
}
} else if (WS.RESPONSE_TYPE_PATH_XML.equals(responseType)) {
return Response.ok(respondData, WS.RESPONSE_TYPE_XML).build();
} else {
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
}
}
示例15: create
import org.easyrec.model.core.web.Message; //导入依赖的package包/类
/**
* This static functions creates a MVC Object with a messageblock.
* A messageblock may be displayed to a user after filling in a form
* and list the error he has made.
*
* @return
*/
public static ModelAndView create(ModelAndView mav, List<Message> messages, String action, String title) {
mav.setViewName(DEFAULT_VIEW_NAME);
mav.addObject("messages", messages);
mav.addObject("action", action);
mav.addObject("title", title);
return mav;
}