本文整理汇总了Java中com.sun.jersey.api.json.JSONWithPadding类的典型用法代码示例。如果您正苦于以下问题:Java JSONWithPadding类的具体用法?Java JSONWithPadding怎么用?Java JSONWithPadding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONWithPadding类属于com.sun.jersey.api.json包,在下文中一共展示了JSONWithPadding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setZNode
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@PUT
@Produces( { MediaType.APPLICATION_JSON, "application/javascript",
MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response setZNode(
@PathParam("path") String path,
@QueryParam("callback") String callback,
@DefaultValue("-1") @QueryParam("version") String versionParam,
@DefaultValue("base64") @QueryParam("dataformat") String dataformat,
@DefaultValue("false") @QueryParam("null") String setNull,
@Context UriInfo ui, byte[] data) throws InterruptedException,
KeeperException {
ensurePathNotNull(path);
int version;
try {
version = Integer.parseInt(versionParam);
} catch (NumberFormatException e) {
throw new WebApplicationException(Response.status(
Response.Status.BAD_REQUEST).entity(
new ZError(ui.getRequestUri().toString(), path
+ " bad version " + versionParam)).build());
}
if (setNull.equals("true")) {
data = null;
}
Stat stat = zk.setData(path, data, version);
ZStat zstat = new ZStat(path, ui.getAbsolutePath().toString(), null,
null, stat.getCzxid(), stat.getMzxid(), stat.getCtime(), stat
.getMtime(), stat.getVersion(), stat.getCversion(),
stat.getAversion(), stat.getEphemeralOwner(), stat
.getDataLength(), stat.getNumChildren(), stat
.getPzxid());
return Response.status(Response.Status.OK).entity(
new JSONWithPadding(zstat, callback)).build();
}
示例2: wrapContentIfNeccessary
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
public static Object wrapContentIfNeccessary(String callback,
final String responseType, final Object content) {
if (responseType.equals(MediaTypeHelper.APPLICATION_X_JAVASCRIPT)) {
return new JSONWithPadding(content, callback);
}
return content;
}
示例3: filter
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@Override
public BroadcastAction filter(String broadcasterId, AtmosphereResource resource, Object originalMessage, Object message) {
final HttpServletRequest request = resource.getRequest();
ResponseTypeHelper responseTypeHelper = new ResponseTypeHelper();
String responseType = responseTypeHelper.getResponseType(request);
try {
Object responseObject = responseType.equals(MediaTypeHelper.APPLICATION_X_JAVASCRIPT) ?
new JSONWithPadding(message, responseTypeHelper.getQueryParam(request, "callback")) : message;
return new BroadcastAction(
ACTION.CONTINUE, Response.ok(responseObject, responseType).build());
} catch (Exception e) {
logger.error(e.getMessage());
return new BroadcastAction(ACTION.ABORT, message);
}
}
示例4: EasyRecException
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的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 JSONWithPadding(messagesToArray(messages), callback),
WS.RESPONSE_TYPE_JSCRIPT).build() :
Response.ok(messagesToArray(messages), type).build());
}
示例5: formatResponse
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的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 jason 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 JSONWithPadding(respondData, callback),
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();
}
}
示例6: formatResponse
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的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 jason 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.JSON_PATH.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.JSON_PATH.equals(responseType)) {
if (callback != null) {
return Response.ok(new JSONWithPadding(respondData, callback),
WS.RESPONSE_TYPE_JSCRIPT).build();
} else {
return Response.ok(respondData, WS.RESPONSE_TYPE_JSON).build();
}
} else if (WS.XML_PATH.equals(responseType)) {
return Response.ok(respondData, WS.RESPONSE_TYPE_XML).build();
} else {
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
}
}
示例7: createZNode
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@POST
@Produces( { MediaType.APPLICATION_JSON, "application/javascript",
MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response createZNode(
@PathParam("path") String path,
@QueryParam("callback") String callback,
@DefaultValue("create") @QueryParam("op") String op,
@QueryParam("name") String name,
@DefaultValue("base64") @QueryParam("dataformat") String dataformat,
@DefaultValue("false") @QueryParam("null") String setNull,
@DefaultValue("false") @QueryParam("sequence") String sequence,
@DefaultValue("false") @QueryParam("ephemeral") String ephemeral,
@Context UriInfo ui, byte[] data) throws InterruptedException,
KeeperException {
ensurePathNotNull(path);
if (path.equals("/")) {
path += name;
} else {
path += "/" + name;
}
if (!op.equals("create")) {
throw new WebApplicationException(Response.status(
Response.Status.BAD_REQUEST).entity(
new ZError(ui.getRequestUri().toString(), path
+ " bad operaton " + op)).build());
}
if (setNull.equals("true")) {
data = null;
}
CreateMode createMode;
if (sequence.equals("true")) {
if (ephemeral.equals("false")) {
createMode = CreateMode.PERSISTENT_SEQUENTIAL;
} else {
createMode = CreateMode.EPHEMERAL_SEQUENTIAL;
}
} else if (ephemeral.equals("false")) {
createMode = CreateMode.PERSISTENT;
} else {
createMode = CreateMode.EPHEMERAL;
}
String newPath = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);
URI uri = ui.getAbsolutePathBuilder().path(newPath).build();
return Response.created(uri).entity(
new JSONWithPadding(new ZPath(newPath, ui.getAbsolutePath()
.toString()))).build();
}
示例8: view
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@GET
@Path("/view")
public Response view(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId, @QueryParam("userid") String userId,
@QueryParam("sessionid") String sessionId, @QueryParam("itemid") String itemId,
@QueryParam("itemdescription") String itemDescription, @QueryParam("itemurl") String itemUrl,
@QueryParam("itemimageurl") String itemImageUrl, @QueryParam("actiontime") String actionTime,
@QueryParam("itemtype") String itemType, @QueryParam("callback") String callback)
throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_VIEW);
// Collect a List of messages for the user to understand,
// what went wrong (e.g. Wrong API key).
List<Message> messages = new ArrayList<Message>();
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
RemoteTenant r = remoteTenantDAO.get(coreTenantId);
// if (r.isMaxActionLimitExceeded()) {
// messages.add(Message.MAXIMUM_ACTIONS_EXCEEDED);
// }
checkParams(coreTenantId, itemId, itemDescription, itemUrl, sessionId, messages);
Date actionDate = null;
if (actionTime != null) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
actionDate = MyUtils.dateFormatCheck(actionTime, dateFormatter);
if (actionDate == null)
messages.add(MSG.DATE_PARSE);
}
if (messages.size() > 0) {
if ((WS.JSON_PATH.equals(type)))
throw new EasyRecException(messages, WS.ACTION_VIEW, WS.RESPONSE_TYPE_JSON, callback);
else
throw new EasyRecException(messages, WS.ACTION_VIEW);
}
itemType = checkItemType(itemType, type, coreTenantId, tenantId, WS.ACTION_VIEW, callback);
Session session = new Session(sessionId, request.getRemoteAddr());
Item item = shopRecommenderService.viewItem(r, userId, itemId, itemType, itemDescription,
itemUrl, itemImageUrl, actionDate, session);
ResponseItem respItem = new ResponseItem(tenantId, WS.ACTION_VIEW, userId, sessionId, null, item);
mon.stop();
if (WS.JSON_PATH.equals(type)) {
if (callback != null)
return Response.ok(new JSONWithPadding(respItem, callback), WS.RESPONSE_TYPE_JSCRIPT)
.build();
else
return Response.ok(respItem, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(respItem, WS.RESPONSE_TYPE_XML).build();
}
示例9: rate
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@GET
@Path("/rate")
public Response rate(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId, @QueryParam("userid") String userId,
@QueryParam("sessionid") String sessionId, @QueryParam("itemid") String itemId,
@QueryParam("ratingvalue") String ratingValue,
@QueryParam("itemdescription") String itemDescription, @QueryParam("itemurl") String itemUrl,
@QueryParam("itemimageurl") String itemImageUrl, @QueryParam("actiontime") String actionTime,
@QueryParam("itemtype") String itemType, @QueryParam("callback") String callback)
throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_RATE);
// Collect a List of messages for the user to understand,
// what went wrong (e.g. Wrong API key).
List<Message> messages = new ArrayList<Message>();
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
RemoteTenant r = remoteTenantDAO.get(coreTenantId);
// if (r.isMaxActionLimitExceeded()) {
// messages.add(Message.MAXIMUM_ACTIONS_EXCEEDED);
// }
checkParams(coreTenantId, itemId, itemDescription, itemUrl, sessionId, messages);
Date actionDate = null;
if (actionTime != null) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
actionDate = MyUtils.dateFormatCheck(actionTime, dateFormatter);
if (actionDate == null)
messages.add(MSG.DATE_PARSE);
}
Integer rateValue = -1;
try {
rateValue = Integer.valueOf(ratingValue);
if (coreTenantId != null && (rateValue < tenantService.getTenantById(coreTenantId).getRatingRangeMin() ||
rateValue > tenantService.getTenantById(coreTenantId).getRatingRangeMax()))
throw new Exception();
} catch (Exception e) {
messages.add(MSG.ITEM_INVALID_RATING_VALUE);
}
if (messages.size() > 0) {
if ((WS.JSON_PATH.equals(type)))
throw new EasyRecException(messages, WS.ACTION_RATE, WS.RESPONSE_TYPE_JSON, callback);
else
throw new EasyRecException(messages, WS.ACTION_RATE);
}
itemType = checkItemType(itemType, type, coreTenantId, tenantId, WS.ACTION_RATE, callback);
Session session = new Session(sessionId, request.getRemoteAddr());
Item item = shopRecommenderService.rateItem(r, userId, itemId, itemType, itemDescription,
itemUrl, itemImageUrl, rateValue, actionDate, session);
ResponseItem respItem = new ResponseItem(tenantId, WS.ACTION_RATE, userId, sessionId, ratingValue, item);
mon.stop();
if (WS.JSON_PATH.equals(type)) {
if (callback != null)
return Response.ok(new JSONWithPadding(respItem, callback), WS.RESPONSE_TYPE_JSCRIPT).build();
else
return Response.ok(respItem, WS.RESPONSE_TYPE_JSON).build();
} else {
return Response.ok(respItem, WS.RESPONSE_TYPE_XML).build();
}
}
示例10: buy
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@GET
@Path("/buy")
public Response buy(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId, @QueryParam("userid") String userId,
@QueryParam("sessionid") String sessionId, @QueryParam("itemid") String itemId,
@QueryParam("itemdescription") String itemDescription, @QueryParam("itemurl") String itemUrl,
@QueryParam("itemimageurl") String itemImageUrl, @QueryParam("actiontime") String actionTime,
@QueryParam("itemtype") String itemType, @QueryParam("callback") String callback)
throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_BUY);
// Collect a List of messages for the user to understand,
// what went wrong (e.g. Wrong API key).
List<Message> messages = new ArrayList<Message>();
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
RemoteTenant r = remoteTenantDAO.get(coreTenantId);
// if (r.isMaxActionLimitExceeded()) {
// messages.add(Message.MAXIMUM_ACTIONS_EXCEEDED);
// }
checkParams(coreTenantId, itemId, itemDescription, itemUrl, sessionId, messages);
Date actionDate = null;
if (actionTime != null) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
actionDate = MyUtils.dateFormatCheck(actionTime, dateFormatter);
if (actionDate == null)
messages.add(MSG.DATE_PARSE);
}
if (messages.size() > 0) {
if ((WS.JSON_PATH.equals(type)))
throw new EasyRecException(messages, WS.ACTION_BUY, WS.RESPONSE_TYPE_JSON, callback);
else
throw new EasyRecException(messages, WS.ACTION_BUY);
}
itemType = checkItemType(itemType, type, coreTenantId, tenantId, WS.ACTION_BUY, callback);
Session session = new Session(sessionId, request.getRemoteAddr());
Item item = shopRecommenderService.purchaseItem(r, userId, itemId, itemType, itemDescription,
itemUrl, itemImageUrl, actionDate, session);
ResponseItem respItem = new ResponseItem(tenantId, WS.ACTION_BUY, userId, sessionId, null, item);
mon.stop();
if (WS.JSON_PATH.equals(type)) {
if (callback != null)
return Response.ok(new JSONWithPadding(respItem, callback), WS.RESPONSE_TYPE_JSCRIPT).build();
else
return Response.ok(respItem, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(respItem, WS.RESPONSE_TYPE_XML).build();
}
示例11: otherUsersAlsoViewed
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@GET
@Path("/otherusersalsoviewed")
public Response otherUsersAlsoViewed(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId, @QueryParam("userid") String userId,
@QueryParam("sessionid") String sessionId, @QueryParam("itemid") String itemId,
@QueryParam("numberOfResults") Integer numberOfResults,
@QueryParam("itemtype") String itemType,
@QueryParam("requesteditemtype") String requestedItemType,
@QueryParam("callback") String callback,
@QueryParam("withProfile") @DefaultValue("false") boolean withProfile) throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_ALSO_VIEWED);
Recommendation rec = null;
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
if (coreTenantId == null)
exceptionResponse(WS.ACTION_OTHER_USERS_ALSO_VIEWED, MSG.TENANT_WRONG_TENANT_APIKEY, type, callback);
RemoteTenant r = remoteTenantDAO.get(coreTenantId);
if (r.isMaxActionLimitExceeded())
exceptionResponse(WS.ACTION_OTHER_USERS_ALSO_VIEWED, MSG.MAXIMUM_ACTIONS_EXCEEDED, type, callback);
itemType = checkItemType(itemType, type, coreTenantId, tenantId, WS.ACTION_OTHER_USERS_ALSO_VIEWED, callback);
requestedItemType = checkItemType(requestedItemType, type, coreTenantId, tenantId, WS.ACTION_OTHER_USERS_ALSO_VIEWED, callback, null);
Session session = new Session(sessionId, request);
try {
if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS))
numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
rec = shopRecommenderService.alsoViewedItems(coreTenantId, userId, itemId, itemType, requestedItemType,
session, numberOfResults);
//added by FK on 2012-12-18 for adding profile data to recommendations.
if (withProfile) {
addProfileDataToItems(rec);
}
} catch (EasyRecRestException sre) {
exceptionResponse(WS.ACTION_OTHER_USERS_ALSO_VIEWED, sre.getMessageObject(), type,
callback);
}
mon.stop();
if (WS.JSON_PATH.equals(type)) {
if (callback != null)
return Response.ok(new JSONWithPadding(rec, callback), WS.RESPONSE_TYPE_JSCRIPT).build();
else
return Response.ok(rec, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(rec, WS.RESPONSE_TYPE_XML).build();
}
示例12: recommendationsForUser
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@GET
@Path("/recommendationsforuser")
public Response recommendationsForUser(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId, @QueryParam("userid") String userId,
@QueryParam("numberOfResults") Integer numberOfResults,
@QueryParam("requesteditemtype") String requestedItemType,
@QueryParam("callback") String callback,
@QueryParam("actiontype") @DefaultValue(TypeMappingService.ACTION_TYPE_VIEW) String actiontype,
@QueryParam("withProfile") @DefaultValue("false") boolean withProfile)
throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_RECS_FOR_USER);
Recommendation rec = null;
Session session = new Session(null, request);
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
if (coreTenantId == null)
exceptionResponse(WS.ACTION_RECOMMENDATIONS_FOR_USER, MSG.TENANT_WRONG_TENANT_APIKEY, type, callback);
RemoteTenant remoteTenant = remoteTenantDAO.get(coreTenantId);
if (remoteTenant.isMaxActionLimitExceeded())
exceptionResponse(WS.ACTION_RECOMMENDATIONS_FOR_USER, MSG.MAXIMUM_ACTIONS_EXCEEDED, type, callback);
if (Strings.isNullOrEmpty(userId))
exceptionResponse(WS.ACTION_RECOMMENDATIONS_FOR_USER, MSG.USER_NO_ID, type, callback);
requestedItemType = checkItemType(requestedItemType, type, coreTenantId, tenantId, WS.ACTION_RECOMMENDATIONS_FOR_USER, callback, null);
if (typeMappingService.getIdOfActionType(coreTenantId, actiontype) == null) {
exceptionResponse(WS.ACTION_RECOMMENDATIONS_FOR_USER, MSG.OPERATION_FAILED.append(String.format(" actionType %s not found for tenant %s", actiontype, tenantId)), type, callback);
}
if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS))
numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
if (rec == null || rec.getRecommendedItems().isEmpty()) {
try {
rec = shopRecommenderService.itemsBasedOnActionHistory(coreTenantId, userId, session, actiontype, null, WS.ACTION_HISTORY_DEPTH, null,
requestedItemType, numberOfResults);
//added by FK on 2012-12-18 for adding profile data to recommendations.
if (withProfile) {
addProfileDataToItems(rec);
}
} catch (EasyRecRestException sre) {
exceptionResponse(WS.ACTION_RECOMMENDATIONS_FOR_USER, sre.getMessageObject(), type, callback);
}
}
mon.stop();
if (WS.JSON_PATH.equals(type)) {
if (callback != null)
return Response.ok(new JSONWithPadding(rec, callback), WS.RESPONSE_TYPE_JSCRIPT).build();
else
return Response.ok(rec, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(rec, WS.RESPONSE_TYPE_XML).build();
}
示例13: actionHistoryForUser
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@GET
@Path("/actionhistoryforuser")
public Response actionHistoryForUser(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId, @QueryParam("userid") String userId,
@QueryParam("numberOfResults") Integer numberOfResults,
@QueryParam("requesteditemtype") String requestedItemType,
@QueryParam("callback") String callback,
@QueryParam("actiontype") @DefaultValue(TypeMappingService.ACTION_TYPE_VIEW) String actiontype)
throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_ACTIONHISTORY);
Recommendation rec = null;
Session session = new Session(null, request);
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
if (coreTenantId == null)
exceptionResponse(WS.ACTION_HISTORY, MSG.TENANT_WRONG_TENANT_APIKEY, type, callback);
RemoteTenant remoteTenant = remoteTenantDAO.get(coreTenantId);
if (remoteTenant.isMaxActionLimitExceeded())
exceptionResponse(WS.ACTION_HISTORY, MSG.MAXIMUM_ACTIONS_EXCEEDED, type, callback);
if (Strings.isNullOrEmpty(userId))
exceptionResponse(WS.ACTION_HISTORY, MSG.USER_NO_ID, type, callback);
requestedItemType = checkItemType(requestedItemType, type, coreTenantId, tenantId, WS.ACTION_HISTORY, callback, null);
if (typeMappingService.getIdOfActionType(coreTenantId, actiontype) == null) {
exceptionResponse(WS.ACTION_HISTORY, MSG.OPERATION_FAILED.append(String.format(" actionType %s not found for tenant %s", actiontype, tenantId)), type, callback);
}
if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS))
numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
if (rec == null || rec.getRecommendedItems().isEmpty()) {
try {
rec = shopRecommenderService.actionHistory(coreTenantId, userId, session, actiontype, requestedItemType, numberOfResults + 5, numberOfResults); // +5 to compensate for inactive items
} catch (EasyRecRestException sre) {
exceptionResponse(WS.ACTION_HISTORY, sre.getMessageObject(), type, callback);
}
}
mon.stop();
if (WS.JSON_PATH.equals(type)) {
if (callback != null)
return Response.ok(new JSONWithPadding(rec, callback), WS.RESPONSE_TYPE_JSCRIPT).build();
else
return Response.ok(rec, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(rec, WS.RESPONSE_TYPE_XML).build();
}
示例14: otherUsersAlsoBought
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@GET
@Path("/otherusersalsobought")
public Response otherUsersAlsoBought(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId, @QueryParam("userid") String userId,
@QueryParam("sessionid") String sessionId, @QueryParam("itemid") String itemId,
@QueryParam("numberOfResults") Integer numberOfResults,
@QueryParam("itemtype") String itemType,
@QueryParam("requesteditemtype") String requestedItemType,
@QueryParam("callback") String callback,
@QueryParam("withProfile") @DefaultValue("false") boolean withProfile)
throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_ALSO_BOUGHT);
Recommendation rec = null;
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
if (coreTenantId == null)
exceptionResponse(WS.ACTION_OTHER_USERS_ALSO_BOUGHT, MSG.TENANT_WRONG_TENANT_APIKEY, type, callback);
RemoteTenant r = remoteTenantDAO.get(coreTenantId);
if (r.isMaxActionLimitExceeded())
exceptionResponse(WS.ACTION_OTHER_USERS_ALSO_BOUGHT, MSG.MAXIMUM_ACTIONS_EXCEEDED, type, callback);
itemType = checkItemType(itemType, type, coreTenantId, tenantId, WS.ACTION_OTHER_USERS_ALSO_BOUGHT, callback);
requestedItemType = checkItemType(requestedItemType, type, coreTenantId, tenantId, WS.ACTION_OTHER_USERS_ALSO_BOUGHT, callback, null);
Session session = new Session(sessionId, request);
try {
if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS))
numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
rec = shopRecommenderService.alsoBoughtItems(coreTenantId, userId, itemId, itemType, requestedItemType,
session, numberOfResults);
//added by FK on 2012-12-18 for adding profile data to recommendations.
if (withProfile) {
addProfileDataToItems(rec);
}
} catch (EasyRecRestException sre) {
exceptionResponse(WS.ACTION_OTHER_USERS_ALSO_BOUGHT, sre.getMessageObject(), type, callback);
}
mon.stop();
if (WS.JSON_PATH.equals(type)) {
if (callback != null)
return Response.ok(new JSONWithPadding(rec, callback), WS.RESPONSE_TYPE_JSCRIPT).build();
else
return Response.ok(rec, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(rec, WS.RESPONSE_TYPE_XML).build();
}
示例15: itemsRatedGoodByOtherUsers
import com.sun.jersey.api.json.JSONWithPadding; //导入依赖的package包/类
@GET
@Path("/itemsratedgoodbyotherusers")
public Response itemsRatedGoodByOtherUsers(@PathParam("type") String type, @QueryParam("apikey") String apiKey,
@QueryParam("tenantid") String tenantId,
@QueryParam("userid") String userId,
@QueryParam("sessionid") String sessionId,
@QueryParam("itemid") String itemId,
@QueryParam("numberOfResults") Integer numberOfResults,
@QueryParam("itemtype") String itemType,
@QueryParam("requesteditemtype") String requestedItemType,
@QueryParam("callback") String callback,
@QueryParam("withProfile") @DefaultValue("false") boolean withProfile) throws EasyRecException {
Monitor mon = MonitorFactory.start(JAMON_REST_ALSO_RATED);
Recommendation rec = null;
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantId);
if (coreTenantId == null)
exceptionResponse(WS.ACTION_ITEMS_RATED_GOOD_BY_OTHER_USERS, MSG.TENANT_WRONG_TENANT_APIKEY, type,
callback);
RemoteTenant r = remoteTenantDAO.get(coreTenantId);
if (r.isMaxActionLimitExceeded())
exceptionResponse(WS.ACTION_ITEMS_RATED_GOOD_BY_OTHER_USERS, MSG.MAXIMUM_ACTIONS_EXCEEDED, type, callback);
itemType = checkItemType(itemType, type, coreTenantId, tenantId, WS.ACTION_ITEMS_RATED_GOOD_BY_OTHER_USERS, callback);
requestedItemType = checkItemType(requestedItemType, type, coreTenantId, tenantId, WS.ACTION_ITEMS_RATED_GOOD_BY_OTHER_USERS, callback, null);
Session session = new Session(sessionId, request);
try {
if ((numberOfResults == null) || (numberOfResults > WS.DEFAULT_NUMBER_OF_RESULTS))
numberOfResults = WS.DEFAULT_NUMBER_OF_RESULTS;
rec = shopRecommenderService.alsoGoodRatedItems(coreTenantId, userId, itemId, itemType, requestedItemType,
session, numberOfResults);
//added by FK on 2012-12-18 for adding profile data to recommendations.
if (withProfile) {
addProfileDataToItems(rec);
}
} catch (EasyRecRestException sre) {
exceptionResponse(WS.ACTION_ITEMS_RATED_GOOD_BY_OTHER_USERS, sre.getMessageObject(),
type, callback);
}
mon.stop();
if (WS.JSON_PATH.equals(type)) {
if (callback != null)
return Response.ok(new JSONWithPadding(rec, callback), WS.RESPONSE_TYPE_JSCRIPT).build();
else
return Response.ok(rec, WS.RESPONSE_TYPE_JSON).build();
} else
return Response.ok(rec, WS.RESPONSE_TYPE_XML).build();
}